Skip to content

Commit

Permalink
Cleanup and Add new remote example
Browse files Browse the repository at this point in the history
  • Loading branch information
soumeh01 committed Oct 24, 2024
1 parent 504c8dc commit 3a1e9a1
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 80 deletions.
23 changes: 19 additions & 4 deletions test/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,26 @@
from pathlib import Path
import subprocess
import re
# import os
import os
import fnmatch

def glob_files_in_directory(directory:str, pattern: str, recursive: bool):
yaml_files = glob.glob(directory + '/**/' + pattern, recursive=recursive)
return yaml_files
def glob_files_in_directory(directory: str, pattern: str, recursive: bool, ignore_dir: str = None):
matched_files = []

# Use os.walk to iterate over the directory
for root, dirs, files in os.walk(directory):
# If ignore_dir is specified, filter out directories to ignore
if ignore_dir:
dirs[:] = [d for d in dirs if d != ignore_dir]

# Use glob to match files in the current root directory
matched_files.extend(glob.glob(os.path.join(root, pattern)))

# If not recursive, break after the first iteration (top-level)
if not recursive:
break

return matched_files

def get_parent_directory_name(file_path:str):
parent_dir = Path(file_path).parent
Expand Down
52 changes: 0 additions & 52 deletions test/pack_example_tests.robot
Original file line number Diff line number Diff line change
Expand Up @@ -34,55 +34,3 @@ Test packs examples
${file}= Normalize Path ${file}
Run Csolution Project ${file} ${expect}
END
Run Csolution Project
[Arguments] ${input_file} ${expect} ${args}=@{EMPTY}
${contexts}= Get Contexts From Project ${input_file} ${expect} ${args}
${filcontexts}= Convert And Filter Contexts ${contexts}
@{args_ex} Create List @{args} @{filcontexts}

${res_cbuildgen}= Run Keyword And Ignore Error
... Build Example With cbuildgen ${input_file} ${expect} ${args_ex}
${res_cbuild2cmake}= Run Keyword And Ignore Error
... Build Example with cbuild2cmake ${input_file} ${expect} ${args_ex}
# Check the result of the first run
${success}= Set Variable ${res_cbuildgen[0]}
${message}= Set Variable ${res_cbuildgen[1]}
Run Keyword If '${success}' == 'PASS' Log cbuildgen ran successfully
... ELSE Log cbuildgen failed with message: ${message}
# Check the result of the second run
${success}= Set Variable ${res_cbuild2cmake[0]}
${message}= Set Variable ${res_cbuild2cmake[1]}
Run Keyword If '${success}' == 'PASS' Log cbuild2cmake ran successfully
... ELSE Log cbuild2cmake failed with message: ${message}
Should Be Equal ${res_cbuildgen[0]} ${res_cbuild2cmake[0]} build status doesn't match
${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}${/}${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
# 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
# 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
RETURN ${context_list_args}
6 changes: 3 additions & 3 deletions test/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
|windows-amd64|NXP::LPCXpresso55S69_BSP.18.0.0|955.02 s|Pack Example Tests|
|windows-amd64|Hello_FRDM-K32L3A6|35.11 s|Remote Example Tests|
|windows-amd64|Hello_LPCXpresso55S69|30.37 s|Remote Example Tests|
|windows-amd64|Blinky_NUCLEO-G0B1RE|27.52 s|Remote Example Tests|
|windows-amd64|Csolution-examples|27.52 s|Remote Example Tests|
|windows-amd64|keil-studio-get-started|8.24 s|Remote Example Tests|
|windows-amd64|Hello_AVH|65.48 s|Remote Example Tests|
|linux-amd64|Validate build-asm Example|8.28 s|Local Example Tests|
Expand All @@ -43,7 +43,7 @@
|linux-amd64|NXP::LPCXpresso55S69_BSP.18.0.0|754.88 s|Pack Example Tests|
|linux-amd64|Hello_FRDM-K32L3A6|13.17 s|Remote Example Tests|
|linux-amd64|Hello_LPCXpresso55S69|10.68 s|Remote Example Tests|
|linux-amd64|Blinky_NUCLEO-G0B1RE|14.93 s|Remote Example Tests|
|linux-amd64|Csolution-examples|14.93 s|Remote Example Tests|
|linux-amd64|keil-studio-get-started|3.92 s|Remote Example Tests|
|linux-amd64|Hello_AVH|27.26 s|Remote Example Tests|
|darwin-amd64|Validate build-asm Example|10.46 s|Local Example Tests|
Expand All @@ -61,6 +61,6 @@
|darwin-amd64|NXP::LPCXpresso55S69_BSP.18.0.0|1559.94 s|Pack Example Tests|
|darwin-amd64|Hello_FRDM-K32L3A6|26.55 s|Remote Example Tests|
|darwin-amd64|Hello_LPCXpresso55S69|22.71 s|Remote Example Tests|
|darwin-amd64|Blinky_NUCLEO-G0B1RE|28.29 s|Remote Example Tests|
|darwin-amd64|Csolution-examples|28.29 s|Remote Example Tests|
|darwin-amd64|keil-studio-get-started|9.56 s|Remote Example Tests|
|darwin-amd64|Hello_AVH|61.67 s|Remote Example Tests|
2 changes: 1 addition & 1 deletion test/remote_example_tests.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*** Test Cases ***;${github_url};${cbuildgen_expect};${cbuild2cmake_expect};[Tags];[Documentation]
Hello_FRDM-K32L3A6;https://github.com/Arm-Examples/Hello_FRDM-K32L3A6;${0};${0};;
Hello_LPCXpresso55S69;https://github.com/Arm-Examples/Hello_LPCXpresso55S69;${0};${0};;
Blinky_NUCLEO-G0B1RE;https://github.com/Arm-Examples/Blinky_NUCLEO-G0B1RE;${0};${1};;This example doesn't work with cbuild2cmake as sysmbols are defined multiple times
Csolution-examples;https://github.com/OPen-CMSIS-Pack/csolution-examples;${0};${0};;
keil-studio-get-started;https://github.com/Arm-Examples/keil-studio-get-started;${0};${0};;
Hello_AVH;https://github.com/Arm-Examples/Hello_AVH;${0};${0};;
9 changes: 7 additions & 2 deletions test/remote_example_tests.robot
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ Test github examples
[Arguments] ${github_url} ${cbuildgen_expect} ${cbuild2cmake_expect}
${dest_dir}= Get Destination Path ${github_url}
Checkout GitHub Repository ${github_url} ${dest_dir}
${files} Glob Files In Directory ${dest_dir} *.csolution.* ${True}
${files} Glob Files In Directory ${dest_dir} *.csolution.* ${True} Templates
FOR ${file} IN @{files}
Build Remote CSolution Example ${file} ${cbuildgen_expect} ${cbuild2cmake_expect}
END
# Build Remote CSolution Example
# [Arguments] ${input_file} ${cbuildgen_expect} ${cbuild2cmake_expect} ${args}=@{EMPTY}
# ${result}= Build CSolution Example ${input_file} ${cbuildgen_expect} ${cbuild2cmake_expect} ${args}
# Should Be True ${result}
Build Remote CSolution Example
[Arguments] ${input_file} ${cbuildgen_expect} ${cbuild2cmake_expect} ${args}=@{EMPTY}
${result}= Build CSolution Example ${input_file} ${cbuildgen_expect} ${cbuild2cmake_expect} ${args}
${result}= Run Csolution Project ${input_file} ${cbuildgen_expect} ${args}
Should Be True ${result}
71 changes: 53 additions & 18 deletions test/resources/exec.resource
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Get Contexts From Project
[Arguments] ${input_file} ${expect} ${args}=@{EMPTY}
${parent_path}= Get Parent Directory Path ${input_file}

${result} Run Process csolution list contexts ${input_File}
${result} Run Process csolution list contexts --yml-order ${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
Expand All @@ -81,23 +81,6 @@ Build CSolution Example
RETURN ${True}
END

# ${res_cbuild2cmake}= Run Keyword And Ignore Error Build Example With cbuild2cmake ${input_file} ${cbuild2cmake_expect} ${args}
# ${res_cbuildgen}= Run Keyword And Ignore Error Build Example With cbuildgen ${input_file} ${cbuildgen_expect} ${args}

# # Check the result of the first run
# ${success}= Set Variable ${res_cbuildgen[0]}
# ${message}= Set Variable ${res_cbuildgen[1]}
# Run Keyword If '${success}' == 'PASS' Log cbuildgen ran successfully
# ... ELSE Log cbuildgen failed with message: ${message}

# # Check the result of the second run
# ${success}= Set Variable ${res_cbuild2cmake[0]}
# ${message}= Set Variable ${res_cbuild2cmake[1]}
# Run Keyword If '${success}' == 'PASS' Log cbuild2cmake ran successfully
# ... ELSE Log cbuild2cmake failed with message: ${message}

# Should Be Equal ${res_cbuildgen[0]} ${res_cbuild2cmake[0]} build status doesn't match

${parent_path}= Get Parent Directory Path ${input_file}
${result}= Run Keyword And Return
... Compare Elf Information ${input_file}
Expand All @@ -112,3 +95,55 @@ Checkout GitHub Repository
Log ${result.stdout}
Log ${result.stderr}
Should Be Equal As Integers ${result.rc} ${0}

Run Csolution Project
[Arguments] ${input_file} ${expect} ${args}=@{EMPTY}
${contexts}= Get Contexts From Project ${input_file} ${expect} ${args}
${filcontexts}= Convert And Filter Contexts ${contexts}
@{args_ex} Create List @{args} @{filcontexts}

${res_cbuildgen}= Run Keyword And Ignore Error
... Build Example With cbuildgen ${input_file} ${expect} ${args_ex}
${res_cbuild2cmake}= Run Keyword And Ignore Error
... Build Example with cbuild2cmake ${input_file} ${expect} ${args_ex}

# Check the result of the first run
${success}= Set Variable ${res_cbuildgen[0]}
${message}= Set Variable ${res_cbuildgen[1]}
Run Keyword If '${success}' == 'PASS' Log cbuildgen ran successfully
... ELSE Log cbuildgen failed with message: ${message}

# Check the result of the second run
${success}= Set Variable ${res_cbuild2cmake[0]}
${message}= Set Variable ${res_cbuild2cmake[1]}
Run Keyword If '${success}' == 'PASS' Log cbuild2cmake ran successfully
... ELSE Log cbuild2cmake failed with message: ${message}

Should Be Equal ${res_cbuildgen[0]} ${res_cbuild2cmake[0]} build status doesn't match
${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}${/}${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

# 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

# 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

RETURN ${context_list_args}

0 comments on commit 3a1e9a1

Please sign in to comment.