diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 10b5b02..a229452 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -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() diff --git a/test/lib/utils.py b/test/lib/utils.py index 2cffa0d..8432c52 100644 --- a/test/lib/utils.py +++ b/test/lib/utils.py @@ -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) @@ -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) diff --git a/test/pack_example_tests.csv b/test/pack_example_tests.csv index e457d12..96a440c 100644 --- a/test/pack_example_tests.csv +++ b/test/pack_example_tests.csv @@ -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};; \ No newline at end of file +NXP::MIMXRT1060-EVKB_BSP.18.0.0;NXP::MIMXRT1060-EVKB_BSP@18.0.0;${0};; \ No newline at end of file diff --git a/test/pack_example_tests.robot b/test/pack_example_tests.robot index 7795385..ea78969 100644 --- a/test/pack_example_tests.robot +++ b/test/pack_example_tests.robot @@ -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 @@ -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} diff --git a/test/resources/utils.resource b/test/resources/utils.resource index f2a311a..3c6eecf 100644 --- a/test/resources/utils.resource +++ b/test/resources/utils.resource @@ -3,23 +3,25 @@ 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 @@ -27,24 +29,60 @@ Global Teardown 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 @@ -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 @@ -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 @@ -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} \ No newline at end of file