Skip to content

Commit

Permalink
Test pack examples
Browse files Browse the repository at this point in the history
  • Loading branch information
soumeh01 committed Jul 23, 2024
1 parent f982ca6 commit 3725ad7
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ jobs:
--variable TEST_ENV_FILE:test-env-${{ matrix.target }}-${{ matrix.arch }}.md \
--consolewidth=150 --settag ${{ matrix.target }}-${{ matrix.arch }} \
--name ${{ matrix.target }}-${{ matrix.arch }} \
./test
./test/pack_example_tests.robot
- name: Archieve test results
if: always()
Expand Down
33 changes: 32 additions & 1 deletion test/lib/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import glob
from pathlib import Path
import shutil
# import stat
import subprocess
import re
# import os

def glob_files_in_directory(directory:str, pattern: str, recursive: bool):
yaml_files = glob.glob(directory + '/**/' + pattern, recursive=recursive)
Expand Down Expand Up @@ -37,3 +38,33 @@ def write_test_environment(test_env_file:str):
# Write tool version info
with open(test_env_file, "w") as file:
file.write(markdown_content)

# def insert_at_front(lst, item):
# """
# Inserts an item at the front of the list.

# :param lst: List to insert the item into
# :param item: Item to insert
# :return: Modified list with the item inserted at the front
# """
# lst.insert(0, item)
# return lst

# def remove_read_only(path):
# # Remove read-only attribute on a file or directory
# def onerror(func, path, exc_info):
# # Is the error an access error?
# if not os.access(path, os.W_OK):
# os.chmod(path, stat.S_IWUSR)
# func(path)
# else:
# raise

# if os.path.isdir(path):
# for root, dirs, files in os.walk(path):
# for dir in dirs:
# os.chmod(os.path.join(root, dir), stat.S_IWUSR | stat.S_IREAD)
# for file in files:
# os.chmod(os.path.join(root, file), stat.S_IWUSR | stat.S_IREAD)
# else:
# os.chmod(path, stat.S_IWUSR | stat.S_IREAD)
2 changes: 1 addition & 1 deletion test/pack_example_tests.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
NXP::LPCXpresso55S69_BSP.18.0.0;NXP::LPCXpresso55S69_BSP@18.0.0;${0};;
NXP::LPCXpresso55S69_USB_Examples.1.0.0;NXP::LPCXpresso55S69_USB_Examples@1.0.0;${0};;
NXP::FRDM-K32L3A6_BSP.18.0.0;NXP::FRDM-K32L3A6_BSP@18.0.0;${0};;
NXP::MIMXRT1060-EVKB_BSP.18.0.0;NXP::MIMXRT1060-EVKB_BSP.18.0.0;${0};;
NXP::MIMXRT1060-EVKB_BSP.18.0.0;NXP::MIMXRT1060-EVKB_BSP@18.0.0;${0};;
53 changes: 50 additions & 3 deletions test/pack_example_tests.robot
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Documentation Tests to compile & execute remote csolution examples
Suite Setup Global Setup
Suite Teardown Global Teardown
Library lib${/}utils.py
Library BuiltIn
Library String
Library Collections
Library lib${/}elf_compare.py
Expand All @@ -13,28 +14,74 @@ Resource resources${/}utils.resource
Test Template Test packs examples
*** Variables ***
${context_string} ${EMPTY}
*** Test Cases ***
Test pack example ${pack_id} and expect ${expect} Default UserData
*** Keywords ***
Test packs examples
[Arguments] ${pack_id} ${expect}
${pack_root_dir}= Set Variable ${TEST_DATA_DIR}${/}${Local_Pack_Root_Dir}${/}
${pack_root_dir}= Join And Normalize Path ${TEST_DATA_DIR} ${Local_Pack_Root_Dir}
Create Directory ${pack_root_dir}
Cpackget Init ${pack_root_dir}
Cpackget Install Pack ${pack_id} ${pack_root_dir}
Change Directory Permissions ${pack_root_dir}
${files} Glob Files In Directory ${pack_root_dir} *.csolution.* ${True}
FOR ${file} IN @{files}
${file}= Normalize Path ${file}
Run Csolution Project ${file} ${expect}
END
Run Csolution Project
[Arguments] ${input_file} ${expect} ${args}=@{EMPTY}
Run Project With cbuildgen ${input_file} ${expect} ${args}
${contexts}= Get Contexts From Project ${input_file} ${expect} ${args}
${filcontexts}= Convert And Filter Contexts ${contexts}
Log Many ${args}
Log Many ${filcontexts}
# Append To List ${args} ${filcontexts}
@{MERGED_LIST} Create List @{args} @{filcontexts}
Log Many ${MERGED_LIST}
Run Project With cbuildgen ${input_file} ${expect} ${MERGED_LIST}
Run Project with cbuild2cmake ${input_file} ${expect} ${args}
${parent_path}= Get Parent Directory Path ${input_file}
${result}= Run Keyword And Return
... Compare Elf Information ${input_file}
... ${parent_path}${/}${Out_Dir}${/}${Default_Out_Dir}
... ${parent_path}${/}${Out_Dir}${/}${Default_Out_Dir}
... ${parent_path}${/}${Default_Out_Dir}
Should Be True ${result}
Convert And Filter Contexts
[Documentation] Example test to convert a string to an array, filter it, and join it
[Arguments] ${all_contexts}
@{lines}= Split String ${all_contexts} \n
Log ${lines}
# Filter out items containing '+iar'
@{filtered_lines}= Create List
FOR ${line} IN @{lines}
log ${line}
${result}= Run Keyword And Return Status Should Contain ${line} iar
Run Keyword If ${result}==False Append To List ${filtered_lines} ${line}
END
Log Many ${filtered_lines}
# # Prefix remaining items with '-c ' and join them
# ${context_string}= Set Variable ${EMPTY}
# FOR ${line} IN @{filtered_lines}
# Append To List
# ${context_string}= Evaluate "-c ${line} ${context_string}"
# END
# Log Many ${context_string}
# RETURN ${context_string}
# Prefix remaining items with '-c ' and join them
@{context_list_args}= Create List
FOR ${line} IN @{filtered_lines}
Append To List ${context_list_args} -c ${line}
END
Log Many ${context_list_args}
RETURN ${context_list_args}
95 changes: 83 additions & 12 deletions test/resources/utils.resource
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,86 @@ Documentation A collection of commonly used keywords across multiple test sui
Library BuiltIn
Library Collections
Library Process
Library String
Library OperatingSystem
Library ..${/}lib${/}utils.py
Resource global.resource

*** Variables ***
${TEST_ENV_FILE} test_env.md
${RESULT} ${EMPTY}

*** Keywords ***
Global Setup
${parent_dir}= Join Path ${CURDIR} ..
${src_dir}= Join Path ${parent_dir} ${Data}
${parent_dir}= Join And Normalize Path ${CURDIR} ..
${src_dir}= Join And Normalize Path ${parent_dir} ${Data}
${dest_dir}= Get Test Data Directory
Set Global Variable ${TEST_DATA_DIR} ${dest_dir}
Copy Directory ${src_dir} ${dest_dir}
${output_file_path} Get Output File Path
${parent_path}= Get Parent Directory Path ${output_file_path}
${test_env_file}= Join Path ${parent_path} ${TEST_ENV_FILE}
${test_env_file}= Join And Normalize Path ${parent_path} ${TEST_ENV_FILE}
Write Test Environment ${test_env_file}

Global Teardown
Remove Directory with Content ${TEST_DATA_DIR}

Get Test Data Directory
[Documentation] Retrieve the directory path for test input data
${parent_dir}= Join Path ${CURDIR} ..
${test_data_dir}= Join Path ${parent_dir} ${Build}
${parent_dir}= Join And Normalize Path ${CURDIR} ..
${test_data_dir}= Join And Normalize Path ${parent_dir} ${Build}
RETURN ${test_data_dir}

Run Program1
[Documentation] Run specified executable with arguments
[Arguments] ${exe_path} ${command}
${result} Run Process ${exe_path} ${command}
... shell=True stdout=${CURDIR}/stdout.txt
${ret_code}= Set Variable If ${result.rc} == ${0} ${result.rc} ${1}
Log Output String ${result.stdout}
RETURN ${ret_code}

Run Program
[Documentation] Run specified executable with arguments
[Arguments] ${exe_path} ${command} ${input_File} @{args}
${result} Run Process ${exe_path} ${command} ${input_File} @{args}
... shell=True stdout=${CURDIR}/stdout.txt
${ret_code}= Set Variable If ${result.rc} == ${0} ${result.rc} ${1}
Log Output String ${result.stdout}
RETURN

Run Program2
[Documentation] Run specified executable with arguments
[Arguments] ${exe_path} ${input_File} @{args}
Log Many ${exe_path}
Log Many ${input_file}
Log Many ${args}
${result} Run Process ${exe_path} ${input_File} @{args}
... shell=True stdout=${CURDIR}/stdout.txt
${ret_code}= Set Variable If ${result.rc} == ${0} ${result.rc} ${1}
Log Output String ${result.stdout}
RETURN ${ret_code}
RETURN

# Run cbuild
# [Documentation] Run cbuild with specified arguments
# [Arguments] ${cmdline_args}=@{EMPTY}
# Append To List ${cmdline_args} -p -r --update-rte
# Log Many ${cmdline_args}
# ${str_args}= Convert List To Single String ${cmdline_args}
# Log Many ${str_args}
# ${ret_code}= Run Program cbuild ${str_args}
# RETURN ${ret_code}

Run cbuild
[Documentation] Run cbuild with specified arguments
[Arguments] ${input_file} ${args}=@{EMPTY}
[Arguments] ${input_file} ${command} ${args}=@{EMPTY}
Append To List ${args} -p -r --update-rte
${ret_code}= Run Program cbuild ${input_file} @{args}
Log Many ${command}
Log Many ${input_file}
Log Many ${args}
${ret_code}= Run Keyword If '${command}' == '${EMPTY}' Run Program2 cbuild ${input_file} @{args}
... ELSE Run Program cbuild ${command} ${input_file} @{args}
# ${ret_code}= Run Program cbuild ${command} ${input_file} @{args}
RETURN ${ret_code}

Change Directory Permissions
Expand All @@ -56,6 +94,7 @@ Change Directory Permissions
Remove Directory with Content
[Documentation] Remove directory and its content from target directory
[Arguments] ${target_dir}
${target_dir}= Normalize Path ${target_dir}
Change Directory Permissions ${target_dir}
Remove Directory ${target_dir} recursive=${True}
Wait Until Removed ${target_dir} timeout=5 seconds
Expand All @@ -72,15 +111,18 @@ Run Project with cbuildgen
[Documentation] Run the csolution project with cbuildgen
[Arguments] ${input_file} ${expect} ${args}=@{EMPTY}
${parent_path}= Get Parent Directory Path ${input_file}
${ex_args}= Append Additional Arguments ${args} --output ${parent_path}${/}${Out_Dir} --cbuildgen
${ret_code}= Run cbuild ${input_file} ${ex_args}
${output_dir}= Normalize Path ${parent_path}${/}${Out_Dir}
Append To List ${args} --output ${output_dir} --cbuildgen
# ${args}= Insert At Front ${args} ${input_file}
${ret_code}= Run cbuild ${input_file} ${EMPTY} ${args}
Should Be Equal ${ret_code} ${expect} msg=Unexpected status returned by cbuildgen execution

Run Project With cbuild2cmake
[Documentation] Run the csolution project with cbuild2cmake
[Arguments] ${input_file} ${expect} ${args}=@{EMPTY}
${ex_args}= Append Additional Arguments ${args} --cbuild2cmake
${ret_code}= Run cbuild ${input_file} ${ex_args}
Append To List ${args} --cbuild2cmake
${args}= Insert At Front ${args} ${input_file}
${ret_code}= Run cbuild ${input_file} ${empty} ${args}
Should Be Equal ${ret_code} ${expect} msg=Unexpected status returned by cbuild2cmake execution

Append Additional Arguments
Expand Down Expand Up @@ -118,3 +160,32 @@ Cpackget Install Pack
... -R ${pack_root_dir}
... --agree-embedded-license --force-reinstall
RETURN ${ret_code}

Get Contexts From Project
[Documentation] Run the csolution project with cbuildgen
[Arguments] ${input_file} ${expect} ${args}=@{EMPTY}
${parent_path}= Get Parent Directory Path ${input_file}
${result} Run Process csolution list contexts ${input_File}
... -q shell=True stdout=${CURDIR}/stdout.txt
${ret_code}= Set Variable If ${result.rc} == ${0} ${result.rc} ${1}
Should Be Equal ${ret_code} ${expect} msg=Unexpected status returned by list context command
RETURN ${result.stdout}

Convert List To Single String
[Arguments] ${LIST}
${RESULT}= Set Variable ${EMPTY}
FOR ${element} IN @{LIST}
${RESULT}= Evaluate ${element} ${RESULT}
END
RETURN ${RESULT}

Join And Normalize Path
[Arguments] ${prefixPath} ${suffixPath}
${resultPath}= Join Path ${prefixPath} ${suffixPath}
${resultPath}= Normalize Path ${resultPath}
RETURN ${resultPath}

Normalize Path
[Arguments] ${Path}
${resultPath}= Replace String ${Path} \\ /
RETURN ${resultPath}

0 comments on commit 3725ad7

Please sign in to comment.