From 45bb6c82a930097152dab5903d2fd92f22d3287c Mon Sep 17 00:00:00 2001 From: Christophe Favergeon Date: Tue, 25 Jun 2024 11:04:38 +0200 Subject: [PATCH] Added github action to test CPP API --- .github/workflows/runcpptest.yaml | 82 +++++++++++++++++++ dsppp/.gitignore | 3 + .../RTE_Components.h | 2 +- dsppp/allocator.h | 3 + dsppp/run_all.py | 68 +++++++++++---- dsppp/test.cbuild-pack.yml | 10 +-- dsppp/test_config.h | 1 + dsppp/tests/bench.h | 10 ++- 8 files changed, 152 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/runcpptest.yaml diff --git a/.github/workflows/runcpptest.yaml b/.github/workflows/runcpptest.yaml new file mode 100644 index 00000000..e3a14a39 --- /dev/null +++ b/.github/workflows/runcpptest.yaml @@ -0,0 +1,82 @@ +name: Compile and Run +on: + workflow_dispatch: + pull_request: + branches: [main] + push: + branches: [main] + +permissions: + actions: read + security-events: write + +jobs: + CI_test_run: + strategy: + fail-fast: false + matrix: + compiler: [AC6, CLANG, GCC] + core: [M0, M4, M55] + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Python 3.10 + uses: actions/setup-python@v5 + with: + python-version: '3.10' + + - name: Install system packages + run: | + sudo add-apt-repository ppa:deadsnakes/ppa + sudo apt-get install libpython3.9 libtinfo5 + + - name: Activate vcpkg + uses: ARM-software/cmsis-actions/vcpkg@v1 + with: + cache: "-${{ matrix.compiler }}-${{ matrix.core }}" + + - name: Activate Arm tool license + uses: ARM-software/cmsis-actions/armlm@v1 + + - name: Prepare framework + run: | + cd dsppp + echo "Create missing folders" + mkdir AC6_results + mkdir CLANG_results + mkdir GCC_results + + echo "Install missing python packages" + pip install -r ../Testing/requirements.txt + + + + echo "Load missing pack" + csolution list packs -s test.csolution.yml -m > required_packs.txt + + cat required_packs.txt + cpackget add -a -f required_packs.txt + + - name: Execute + run: | + cd dsppp + echo "Running tests" + + python runall.py -t -g ${{ matrix.compiler }} -c ${{ matrix.core }} -avh $AVH_FVP_PLUGINS/../bin + + - name: Upload test report + uses: actions/upload-artifact@v4 + with: + name: test-report_${{ matrix.compiler }}_${{ matrix.core }} + path: ${{ matrix.compiler }}_results/errors_${{ matrix.compiler }}.txt + + + - name: Check error + run: | + cd dsppp + + echo "Checking output..." + test "$(cat ${{ matrix.compiler }}_results/errors_${{ matrix.compiler }}.txt | wc -l)" -eq 0 diff --git a/dsppp/.gitignore b/dsppp/.gitignore index 0cd7f9a8..fb43d9d3 100644 --- a/dsppp/.gitignore +++ b/dsppp/.gitignore @@ -11,3 +11,6 @@ run_*.bat ac6_results/ gcc_results/ clang_results/ +AC6_results/ +GCC_results/ +CLANG_results/ diff --git a/dsppp/RTE/_Release_VHT-Corstone-300/RTE_Components.h b/dsppp/RTE/_Release_VHT-Corstone-300/RTE_Components.h index c326941f..f63182ac 100644 --- a/dsppp/RTE/_Release_VHT-Corstone-300/RTE_Components.h +++ b/dsppp/RTE/_Release_VHT-Corstone-300/RTE_Components.h @@ -1,6 +1,6 @@ /* * CSOLUTION generated file: DO NOT EDIT! - * Generated by: csolution version 2.2.1 + * Generated by: csolution version 2.4.0 * * Project: 'test.Release+VHT-Corstone-300' * Target: 'Release+VHT-Corstone-300' diff --git a/dsppp/allocator.h b/dsppp/allocator.h index 61e95006..05146b62 100644 --- a/dsppp/allocator.h +++ b/dsppp/allocator.h @@ -8,11 +8,14 @@ // Allocator for temporaries +// But when in test mode (like in github action), malloc allocator is used instead +#if !defined(TESTMODE) #if defined(POOL_ALLOCATOR) #define TMP_ALLOC pool_allocator #else #define TMP_ALLOC stat_allocator #endif +#endif #include diff --git a/dsppp/run_all.py b/dsppp/run_all.py index 50299044..42c00151 100644 --- a/dsppp/run_all.py +++ b/dsppp/run_all.py @@ -5,6 +5,7 @@ import subprocess import sys import mps3run +from os import environ from colorama import init,Fore, Back, Style @@ -91,9 +92,16 @@ def run(args,mustPrint=False,dumpStdErr=True,timeout=20,printCmd=False): parser.add_argument('-d', action='store_true', help="Dry run") parser.add_argument('-g', nargs='?',type = str, default="AC6",help="AC6 / CLANG / GCC") parser.add_argument('-u', nargs='?',type = str, default="L85986697A",help="Debug UUID") +parser.add_argument('-t', action='store_true', help="Enable test mode") +parser.add_argument('-avh', nargs='?',type = str, default="C:/Keil_v5/ARM/avh-fvp/bin/models", help="AVH folder") args = parser.parse_args() +GHACTION = False + +if "AVH_FVP_PLUGINS" in os.environ: + GHACTION = True + init() if args.a: @@ -111,13 +119,13 @@ def run(args,mustPrint=False,dumpStdErr=True,timeout=20,printCmd=False): def results(): if args.g == "AC6": - return("ac6_results") + return("AC6_results") if args.g == "GCC": - return("gcc_results") + return("GCC_results") if args.g == "CLANG": - return("clang_results") + return("CLANG_results") print(f"Compiler {args.g} not known") exit(1) @@ -144,9 +152,15 @@ def cmd_args(): else: ext = ".elf" -fvp = {"M55":"C:\\Keil_v5\\ARM\\VHT\\VHT_Corstone_SSE-300_Ethos-U55.exe", - "M4":"C:\\Keil_v5\\ARM\\VHT\\VHT_MPS2_Cortex-M4.exe", - "M0":"C:\\Keil_v5\\ARM\\VHT\\VHT_MPS2_Cortex-M0plus.exe"} +fvpWin = {"M55":"FVP_Corstone_SSE-300_Ethos-U55.exe", + "M4":"FVP_MPS2_Cortex-M4.exe", + "M0":"FVP_MPS2_Cortex-M0plus.exe"} + +fvpUnix = {"M55":"FVP_Corstone_SSE-300_Ethos-U55", + "M4":"FVP_MPS2_Cortex-M4", + "M0":"FVP_MPS2_Cortex-M0plus"} + +AVHROOT = args.avh TESTS=["DOT_TEST", "VECTOR_TEST", @@ -184,15 +198,19 @@ def is_only_test(n,i): ] # Restricted tests for debugging -#TESTS=["DOT_TEST","VECTOR_TEST"] -#DATATYPES=["F32_DT"] -#MODE = ["STATIC_TEST"] +TESTS=["DOT_TEST","VECTOR_TEST"] +DATATYPES=["F32_DT"] +MODE = ["STATIC_TEST"] all_tests = list(itertools.product(TESTS,DATATYPES,MODE)) ALLOC = "#define POOL_ALLOCATOR" +TESTMODE = "" +if args.t: + TESTMODE = "#define TESTMODE" + if args.a: # Stat allocator enabled and we do stats on VHT CS300 only ALLOC = "//#define POOL_ALLOCATOR" @@ -206,6 +224,7 @@ def is_only_test(n,i): HEADER = f"""#ifndef TEST_CONFIG_H #define TEST_CONFIG_H +{TESTMODE} {ALLOC} {BENCH} @@ -295,7 +314,19 @@ def runVHT(test_name,test,err,subtest): exe = "cpu0=" + out_path() else: exe = out_path() - res=run([fvp[core],"-f",config,"-a",exe]) + + if AVHROOT: + avhAttempt = os.path.join(AVHROOT,fvpWin[core]) + if os.path.exists(avhAttempt): + avh = avhAttempt + + avhAttempt = os.path.join(AVHROOT,fvpUnix[core]) + if os.path.exists(avhAttempt): + avh = avhAttempt + else: + avh = avhUnixExe[core] + + res=run([avh,"-f",config,"-a",exe]) if not is_error(res,test_name,err): process_result(test_name,test,res.msg,subtest) @@ -340,7 +371,7 @@ def runATest(test,file_err,nb,NB_MAX,current_nb_axf,nb_axf,first=True,subtest=No nb_axf = nb_axf + 1 print(f"Number of axf to test = {nb_axf}") -with open(os.path.join(results(),"errors.txt"),"w") as err: +with open(os.path.join(results(),f"errors_{args.c}.txt"),"w") as err: # Generate include for allocations if args.a or args.i: with open(os.path.join("allocation","all.h"),"w") as fh: @@ -382,10 +413,11 @@ def runATest(test,file_err,nb,NB_MAX,current_nb_axf,nb_axf,first=True,subtest=No nb = nb + 1 -if ERROR_OCCURED: - printError("Error in tests:") - for n in all_errors: - printError(n) - sys.exit("Error occurred") -else: - sys.exit(0) +if not GHACTION: + if ERROR_OCCURED: + printError("Error in tests:") + for n in all_errors: + printError(n) + sys.exit("Error occurred") + else: + sys.exit(0) diff --git a/dsppp/test.cbuild-pack.yml b/dsppp/test.cbuild-pack.yml index 0f3c7dcf..4ffc655f 100644 --- a/dsppp/test.cbuild-pack.yml +++ b/dsppp/test.cbuild-pack.yml @@ -1,17 +1,17 @@ cbuild-pack: resolved-packs: - resolved-pack: ARM::CMSIS@6.0.0 - selected-by: + selected-by-pack: - ARM::CMSIS@6.0.0 - resolved-pack: ARM::CMSIS-Compiler@2.0.0 - selected-by: + selected-by-pack: - ARM::CMSIS-Compiler@2.0.0 - resolved-pack: ARM::CMSIS-DSP@1.15.0 - selected-by: + selected-by-pack: - ARM::CMSIS-DSP@1.15.0 - resolved-pack: ARM::Cortex_DFP@1.0.0 - selected-by: + selected-by-pack: - ARM::Cortex_DFP@1.0.0 - resolved-pack: ARM::V2M_MPS3_SSE_300_BSP@1.4.0 - selected-by: + selected-by-pack: - ARM::V2M_MPS3_SSE_300_BSP@1.4.0 diff --git a/dsppp/test_config.h b/dsppp/test_config.h index 9349fbb8..6323c703 100644 --- a/dsppp/test_config.h +++ b/dsppp/test_config.h @@ -1,6 +1,7 @@ #ifndef TEST_CONFIG_H #define TEST_CONFIG_H + #define POOL_ALLOCATOR //#define ONLY_BENCHMARKS diff --git a/dsppp/tests/bench.h b/dsppp/tests/bench.h index b045ddee..db038336 100644 --- a/dsppp/tests/bench.h +++ b/dsppp/tests/bench.h @@ -23,10 +23,14 @@ extern uint32_t start_time; extern uint32_t stop_time; extern uint32_t cycle_count; -#if defined(HOST) +#if defined(HOST) || defined(TESTMODE) #define INIT_SYSTICK -#define START_CYCLE_MEASUREMENT -#define STOP_CYCLE_MEASUREMENT +#define START_CYCLE_MEASUREMENT \ + start_time = 0; +#define STOP_CYCLE_MEASUREMENT \ + stop_time = 0; \ + cycle_count = start_time - stop_time; \ + printf ("Cycle count = %d\r\n",(int)cycle_count); #else #define INIT_SYSTICK \ SysTick->CTRL=0; \