From d6acbd0ea52772a5317080a840362e670d980272 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 11 Oct 2023 19:59:23 -0400 Subject: Add CodeQL Workflow for Code Security Analysis Add CodeQL Workflow for Code Security Analysis This pull request introduces a CodeQL workflow to enhance the security analysis of our repository. CodeQL is a powerful static analysis tool that helps identify and mitigate security vulnerabilities in our codebase. By integrating this workflow into our GitHub Actions, we can proactively identify and address potential issues before they become security threats. We added a new CodeQL workflow file (.github/workflows/codeql.yml) that - Runs on every push and pull request to the main branch. - Excludes queries with a high false positive rate or low-severity findings. - Does not display results for third-party code, focusing only on our own codebase. Testing: To validate the functionality of this workflow, we have run several test scans on the codebase and reviewed the results. The workflow successfully compiles the project, identifies issues, and provides actionable insights while reducing noise by excluding certain queries and third-party code. Deployment: Once this pull request is merged, the CodeQL workflow will be active and automatically run on every push and pull request to the main branch. To view the results of these code scans, please follow these steps: 1. Under the repository name, click on the Security tab. 2. In the left sidebar, click Code scanning alerts. Additional Information: - You can further customize the workflow to adapt to your specific needs by modifying the workflow file. - For more information on CodeQL and how to interpret its results, refer to the GitHub documentation and the CodeQL documentation. Signed-off-by: Brian --- .github/workflows/codeql-buildscript.sh | 5 ++ .github/workflows/codeql.yml | 123 ++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 .github/workflows/codeql-buildscript.sh create mode 100644 .github/workflows/codeql.yml (limited to '.github') diff --git a/.github/workflows/codeql-buildscript.sh b/.github/workflows/codeql-buildscript.sh new file mode 100644 index 000000000..5b52f4d80 --- /dev/null +++ b/.github/workflows/codeql-buildscript.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +FAMILY=stm32l4 +python3 tools/get_family_deps.py $FAMILY +python3 tools/build_family.py $FAMILY diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 000000000..eaa9599bd --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,123 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ "main", "master" ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ "main", "master" ] + schedule: + - cron: '28 21 * * 0' + +jobs: + analyze: + name: Analyze + # Runner size impacts CodeQL analysis time. To learn more, please see: + # - https://gh.io/recommended-hardware-resources-for-running-codeql + # - https://gh.io/supported-runners-and-hardware-resources + # - https://gh.io/using-larger-runners + # Consider using larger runners for possible analysis time improvements. + runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-20.04' }} + timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'cpp' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ] + # Use only 'java' to analyze code written in Java, Kotlin or both + # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + submodules: recursive + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + queries: security-and-quality + + + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). + # If this step fails, then you should remove it and run the build manually (see below) + #- name: Autobuild + # uses: github/codeql-action/autobuild@v2 + + # â„šī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + - run: | + ./.github/workflows/codeql-buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}" + upload: false + id: step1 + + # Filter out rules with low severity or high false positve rate + # Also filter out warnings in third-party code + - name: Filter out unwanted errors and warnings + uses: advanced-security/filter-sarif@v1 + with: + patterns: | + -**:cpp/path-injection + -**:cpp/world-writable-file-creation + -**:cpp/poorly-documented-function + -**:cpp/potentially-dangerous-function + -**:cpp/use-of-goto + -**:cpp/integer-multiplication-cast-to-long + -**:cpp/comparison-with-wider-type + -**:cpp/leap-year/* + -**:cpp/ambiguously-signed-bit-field + -**:cpp/suspicious-pointer-scaling + -**:cpp/suspicious-pointer-scaling-void + -**:cpp/unsigned-comparison-zero + -**/third*party/** + -**/3rd*party/** + -**/external/** + input: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif + output: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif + + - name: Upload SARIF + uses: github/codeql-action/upload-sarif@v2 + with: + sarif_file: ${{ steps.step1.outputs.sarif-output }} + category: "/language:${{matrix.language}}" + + - name: Archive CodeQL results + uses: actions/upload-artifact@v3 + with: + name: codeql-results + path: ${{ steps.step1.outputs.sarif-output }} + retention-days: 5 \ No newline at end of file -- cgit v1.3.1 From b8ae3d55d4103c89b0b3465f5b3ec4c99484b0a1 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 18 Oct 2023 16:50:07 -0400 Subject: Add CodeQL Workflow for Code Security Analysis Add CodeQL Workflow for Code Security Analysis This pull request introduces a CodeQL workflow to enhance the security analysis of our repository. CodeQL is a powerful static analysis tool that helps identify and mitigate security vulnerabilities in our codebase. By integrating this workflow into our GitHub Actions, we can proactively identify and address potential issues before they become security threats. We added a new CodeQL workflow file (.github/workflows/codeql.yml) that - Runs on every pull request (functionality to run on every push to main branches is included as a comment for convenience). - Runs daily. - Excludes queries with a high false positive rate or low-severity findings. - Does not display results for git submodules, focusing only on our own codebase. Testing: To validate the functionality of this workflow, we have run several test scans on the codebase and reviewed the results. The workflow successfully compiles the project, identifies issues, and provides actionable insights while reducing noise by excluding certain queries and third-party code. Deployment: Once this pull request is merged, the CodeQL workflow will be active and automatically run on every push and pull request to the main branch. To view the results of these code scans, please follow these steps: 1. Under the repository name, click on the Security tab. 2. In the left sidebar, click Code scanning alerts. Additional Information: - You can further customize the workflow to adapt to your specific needs by modifying the workflow file. - For more information on CodeQL and how to interpret its results, refer to the GitHub documentation and the CodeQL documentation (https://codeql.github.com/ and https://codeql.github.com/docs/). Signed-off-by: Brian --- .github/workflows/codeql.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to '.github') diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index eaa9599bd..213c59a92 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -14,11 +14,10 @@ name: "CodeQL" on: push: branches: [ "main", "master" ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ "main", "master" ] schedule: - - cron: '28 21 * * 0' + - cron: '0 0 * * *' + pull_request: + branches: '*' jobs: analyze: @@ -50,6 +49,11 @@ jobs: with: submodules: recursive + - name: arm-none-eabi-gcc GNU Arm Embedded Toolchain + uses: carlosperate/arm-none-eabi-gcc-action@v1.6.0 + with: + release: '10.3-2021.10' + # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v2 -- cgit v1.3.1 From 3cc82d656e3620bfc940b396afa36895aa22aa7b Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 20 Oct 2023 01:02:27 -0400 Subject: Add CodeQL Workflow for Code Security Analysis Add CodeQL Workflow for Code Security Analysis This pull request introduces a CodeQL workflow to enhance the security analysis of our repository. CodeQL is a powerful static analysis tool that helps identify and mitigate security vulnerabilities in our codebase. By integrating this workflow into our GitHub Actions, we can proactively identify and address potential issues before they become security threats. We added a new CodeQL workflow file (.github/workflows/codeql.yml) that - Runs on every pull request (functionality to run on every push to main branches is included as a comment for convenience). - Runs daily. - Excludes queries with a high false positive rate or low-severity findings. - Does not display results for git submodules, focusing only on our own codebase. Testing: To validate the functionality of this workflow, we have run several test scans on the codebase and reviewed the results. The workflow successfully compiles the project, identifies issues, and provides actionable insights while reducing noise by excluding certain queries and third-party code. Deployment: Once this pull request is merged, the CodeQL workflow will be active and automatically run on every push and pull request to the main branch. To view the results of these code scans, please follow these steps: 1. Under the repository name, click on the Security tab. 2. In the left sidebar, click Code scanning alerts. Additional Information: - You can further customize the workflow to adapt to your specific needs by modifying the workflow file. - For more information on CodeQL and how to interpret its results, refer to the GitHub documentation and the CodeQL documentation (https://codeql.github.com/ and https://codeql.github.com/docs/). Signed-off-by: Brian --- .github/workflows/fail_on_error.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 .github/workflows/fail_on_error.py (limited to '.github') diff --git a/.github/workflows/fail_on_error.py b/.github/workflows/fail_on_error.py new file mode 100755 index 000000000..29791742b --- /dev/null +++ b/.github/workflows/fail_on_error.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 + +import json +import sys + +# Return whether SARIF file contains error-level results +def codeql_sarif_contain_error(filename): + with open(filename, 'r') as f: + s = json.load(f) + + for run in s.get('runs', []): + rules_metadata = run['tool']['driver']['rules'] + if not rules_metadata: + rules_metadata = run['tool']['extensions'][0]['rules'] + + for res in run.get('results', []): + if 'ruleIndex' in res: + rule_index = res['ruleIndex'] + elif 'rule' in res and 'index' in res['rule']: + rule_index = res['rule']['index'] + else: + continue + try: + rule_level = rules_metadata[rule_index]['defaultConfiguration']['level'] + except IndexError as e: + print(e, rule_index, len(rules_metadata)) + else: + if rule_level == 'error': + return True + return False + +if __name__ == "__main__": + if codeql_sarif_contain_error(sys.argv[1]): + sys.exit(1) -- cgit v1.3.1 From 490343b4d3e58afdba67f6a530c3b5aef2a36cf9 Mon Sep 17 00:00:00 2001 From: Brian Date: Sun, 29 Oct 2023 15:28:27 -0400 Subject: Add CodeQL Workflow for Code Security Analysis Add CodeQL Workflow for Code Security Analysis This pull request introduces a CodeQL workflow to enhance the security analysis of our repository. CodeQL is a powerful static analysis tool that helps identify and mitigate security vulnerabilities in our codebase. By integrating this workflow into our GitHub Actions, we can proactively identify and address potential issues before they become security threats. We added a new CodeQL workflow file (.github/workflows/codeql.yml) that - Runs on every pull request (functionality to run on every push to main branches is included as a comment for convenience). - Runs daily. - Excludes queries with a high false positive rate or low-severity findings. - Does not display results for git submodules, focusing only on our own codebase. Testing: To validate the functionality of this workflow, we have run several test scans on the codebase and reviewed the results. The workflow successfully compiles the project, identifies issues, and provides actionable insights while reducing noise by excluding certain queries and third-party code. Deployment: Once this pull request is merged, the CodeQL workflow will be active and automatically run on every push and pull request to the main branch. To view the results of these code scans, please follow these steps: 1. Under the repository name, click on the Security tab. 2. In the left sidebar, click Code scanning alerts. Additional Information: - You can further customize the workflow to adapt to your specific needs by modifying the workflow file. - For more information on CodeQL and how to interpret its results, refer to the GitHub documentation and the CodeQL documentation (https://codeql.github.com/ and https://codeql.github.com/docs/). Signed-off-by: Brian --- .github/workflows/codeql.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to '.github') diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 213c59a92..56454f22f 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -12,8 +12,8 @@ name: "CodeQL" on: - push: - branches: [ "main", "master" ] + # push: + # branches: [ "main", "master" ] schedule: - cron: '0 0 * * *' pull_request: -- cgit v1.3.1 From e54a2c4f3c65551e091cdc79acff5f3aa607cff3 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 23 Nov 2023 11:46:39 +0700 Subject: rename build_family.py to build_make.py --- .github/workflows/build_aarch64.yml | 2 +- .github/workflows/build_arm.yml | 2 +- .github/workflows/build_msp430.yml | 2 +- .github/workflows/build_renesas.yml | 2 +- .github/workflows/build_riscv.yml | 2 +- .github/workflows/build_win_mac.yml | 2 +- tools/build_family.py | 80 ------------------------------------- tools/build_make.py | 80 +++++++++++++++++++++++++++++++++++++ 8 files changed, 86 insertions(+), 86 deletions(-) delete mode 100644 tools/build_family.py create mode 100644 tools/build_make.py (limited to '.github') diff --git a/.github/workflows/build_aarch64.yml b/.github/workflows/build_aarch64.yml index 6ac7ad015..8a91ee630 100644 --- a/.github/workflows/build_aarch64.yml +++ b/.github/workflows/build_aarch64.yml @@ -73,7 +73,7 @@ jobs: run: python3 tools/get_deps.py ${{ matrix.family }} - name: Build - run: python3 tools/build_family.py ${{ matrix.family }} + run: python3 tools/build_make.py ${{ matrix.family }} - name: Linker Map run: | diff --git a/.github/workflows/build_arm.yml b/.github/workflows/build_arm.yml index 171c1fec3..402b89e0a 100644 --- a/.github/workflows/build_arm.yml +++ b/.github/workflows/build_arm.yml @@ -66,7 +66,7 @@ jobs: run: python3 tools/get_deps.py ${{ matrix.family }} - name: Build - run: python3 tools/build_family.py ${{ matrix.family }} + run: python3 tools/build_make.py ${{ matrix.family }} - name: Linker Map run: | diff --git a/.github/workflows/build_msp430.yml b/.github/workflows/build_msp430.yml index c62056940..60c5feef3 100644 --- a/.github/workflows/build_msp430.yml +++ b/.github/workflows/build_msp430.yml @@ -71,7 +71,7 @@ jobs: run: python3 tools/get_deps.py ${{ matrix.family }} - name: Build - run: python3 tools/build_family.py ${{ matrix.family }} + run: python3 tools/build_make.py ${{ matrix.family }} - name: Linker Map run: | diff --git a/.github/workflows/build_renesas.yml b/.github/workflows/build_renesas.yml index 66b98a71b..1cc4f8132 100644 --- a/.github/workflows/build_renesas.yml +++ b/.github/workflows/build_renesas.yml @@ -71,7 +71,7 @@ jobs: run: python3 tools/get_deps.py ${{ matrix.family }} - name: Build - run: python3 tools/build_family.py ${{ matrix.family }} + run: python3 tools/build_make.py ${{ matrix.family }} - name: Linker Map run: | diff --git a/.github/workflows/build_riscv.yml b/.github/workflows/build_riscv.yml index 8ec549072..dfc6b672f 100644 --- a/.github/workflows/build_riscv.yml +++ b/.github/workflows/build_riscv.yml @@ -72,7 +72,7 @@ jobs: run: python3 tools/get_deps.py ${{ matrix.family }} - name: Build - run: python3 tools/build_family.py ${{ matrix.family }} + run: python3 tools/build_make.py ${{ matrix.family }} - name: Linker Map run: | diff --git a/.github/workflows/build_win_mac.yml b/.github/workflows/build_win_mac.yml index cb879a705..f6a42cf0a 100644 --- a/.github/workflows/build_win_mac.yml +++ b/.github/workflows/build_win_mac.yml @@ -51,4 +51,4 @@ jobs: run: python3 tools/get_deps.py stm32f4 - name: Build - run: python3 tools/build_family.py stm32f4 stm32f411disco + run: python3 tools/build_make.py stm32f4 stm32f411disco diff --git a/tools/build_family.py b/tools/build_family.py deleted file mode 100644 index cd9884313..000000000 --- a/tools/build_family.py +++ /dev/null @@ -1,80 +0,0 @@ -import os -import sys -import time -from multiprocessing import Pool - -import build_utils - -SUCCEEDED = "\033[32msucceeded\033[0m" -FAILED = "\033[31mfailed\033[0m" -SKIPPED = "\033[33mskipped\033[0m" - -build_separator = '-' * 106 - -make_iar_option = 'TOOLCHAIN=iar' - -def filter_with_input(mylist): - if len(sys.argv) > 1: - input_args = list(set(mylist).intersection(sys.argv)) - if len(input_args) > 0: - mylist[:] = input_args - - -def build_family(example, family, make_option): - all_boards = [] - for entry in os.scandir("hw/bsp/{}/boards".format(family)): - if entry.is_dir() and entry.name != 'pico_sdk': - all_boards.append(entry.name) - filter_with_input(all_boards) - all_boards.sort() - - with Pool(processes=os.cpu_count()) as pool: - pool_args = list((map(lambda b, e=example, o=make_option: [e, b, o], all_boards))) - result = pool.starmap(build_utils.build_example, pool_args) - # sum all element of same index (column sum) - return list(map(sum, list(zip(*result)))) - - -if __name__ == '__main__': - # IAR CC - if make_iar_option not in sys.argv: - make_iar_option = '' - - # If examples are not specified in arguments, build all - all_examples = [] - for d in os.scandir("examples"): - if d.is_dir() and 'cmake' not in d.name: - for entry in os.scandir(d.path): - if entry.is_dir() and 'cmake' not in entry.name and entry.name != 'build_system': - all_examples.append(d.name + '/' + entry.name) - filter_with_input(all_examples) - all_examples.sort() - - # If family are not specified in arguments, build all - all_families = [] - for entry in os.scandir("hw/bsp"): - if entry.is_dir() and os.path.isdir(entry.path + "/boards") and entry.name != 'espressif': - all_families.append(entry.name) - filter_with_input(all_families) - all_families.sort() - - print(build_separator) - print(build_utils.build_format.format('Example', 'Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM')) - total_time = time.monotonic() - - # succeeded, failed, skipped - total_result = [0, 0, 0] - for example in all_examples: - print(build_separator) - for family in all_families: - fret = build_family(example, family, make_iar_option) - if len(fret) == len(total_result): - total_result = [total_result[i] + fret[i] for i in range(len(fret))] - - total_time = time.monotonic() - total_time - print(build_separator) - print("Build Summary: {} {}, {} {}, {} {} and took {:.2f}s".format(total_result[0], SUCCEEDED, total_result[1], - FAILED, total_result[2], SKIPPED, total_time)) - print(build_separator) - - sys.exit(total_result[1]) diff --git a/tools/build_make.py b/tools/build_make.py new file mode 100644 index 000000000..cd9884313 --- /dev/null +++ b/tools/build_make.py @@ -0,0 +1,80 @@ +import os +import sys +import time +from multiprocessing import Pool + +import build_utils + +SUCCEEDED = "\033[32msucceeded\033[0m" +FAILED = "\033[31mfailed\033[0m" +SKIPPED = "\033[33mskipped\033[0m" + +build_separator = '-' * 106 + +make_iar_option = 'TOOLCHAIN=iar' + +def filter_with_input(mylist): + if len(sys.argv) > 1: + input_args = list(set(mylist).intersection(sys.argv)) + if len(input_args) > 0: + mylist[:] = input_args + + +def build_family(example, family, make_option): + all_boards = [] + for entry in os.scandir("hw/bsp/{}/boards".format(family)): + if entry.is_dir() and entry.name != 'pico_sdk': + all_boards.append(entry.name) + filter_with_input(all_boards) + all_boards.sort() + + with Pool(processes=os.cpu_count()) as pool: + pool_args = list((map(lambda b, e=example, o=make_option: [e, b, o], all_boards))) + result = pool.starmap(build_utils.build_example, pool_args) + # sum all element of same index (column sum) + return list(map(sum, list(zip(*result)))) + + +if __name__ == '__main__': + # IAR CC + if make_iar_option not in sys.argv: + make_iar_option = '' + + # If examples are not specified in arguments, build all + all_examples = [] + for d in os.scandir("examples"): + if d.is_dir() and 'cmake' not in d.name: + for entry in os.scandir(d.path): + if entry.is_dir() and 'cmake' not in entry.name and entry.name != 'build_system': + all_examples.append(d.name + '/' + entry.name) + filter_with_input(all_examples) + all_examples.sort() + + # If family are not specified in arguments, build all + all_families = [] + for entry in os.scandir("hw/bsp"): + if entry.is_dir() and os.path.isdir(entry.path + "/boards") and entry.name != 'espressif': + all_families.append(entry.name) + filter_with_input(all_families) + all_families.sort() + + print(build_separator) + print(build_utils.build_format.format('Example', 'Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM')) + total_time = time.monotonic() + + # succeeded, failed, skipped + total_result = [0, 0, 0] + for example in all_examples: + print(build_separator) + for family in all_families: + fret = build_family(example, family, make_iar_option) + if len(fret) == len(total_result): + total_result = [total_result[i] + fret[i] for i in range(len(fret))] + + total_time = time.monotonic() - total_time + print(build_separator) + print("Build Summary: {} {}, {} {}, {} {} and took {:.2f}s".format(total_result[0], SUCCEEDED, total_result[1], + FAILED, total_result[2], SKIPPED, total_time)) + print(build_separator) + + sys.exit(total_result[1]) -- cgit v1.3.1 From 00484d18a5b89eb3a0e7cc138f34142f3464016d Mon Sep 17 00:00:00 2001 From: Brian <89487381+b4yuan@users.noreply.github.com> Date: Mon, 27 Nov 2023 12:14:38 -0500 Subject: Update codeql-buildscript.sh Update script name --- .github/workflows/codeql-buildscript.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to '.github') diff --git a/.github/workflows/codeql-buildscript.sh b/.github/workflows/codeql-buildscript.sh index 5b52f4d80..38d3714c1 100644 --- a/.github/workflows/codeql-buildscript.sh +++ b/.github/workflows/codeql-buildscript.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash FAMILY=stm32l4 -python3 tools/get_family_deps.py $FAMILY +python3 tools/get_deps.py $FAMILY python3 tools/build_family.py $FAMILY -- cgit v1.3.1 From 0a4d92a71e8b25daedc8cf4a388dd9abd2539419 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 28 Nov 2023 18:27:40 +0700 Subject: update hil for pi4 to use new hil_test.py --- .github/workflows/cmake_arm.yml | 43 +++++------------------------------------ hw/bsp/family_support.cmake | 16 +++++++++++++++ hw/bsp/rp2040/family.cmake | 2 ++ test/hil/hil_pi4.json | 11 +++++++++++ test/hil/hil_test.py | 40 ++++++++++++++++++++++++++++++-------- 5 files changed, 66 insertions(+), 46 deletions(-) create mode 100644 test/hil/hil_pi4.json (limited to '.github') diff --git a/.github/workflows/cmake_arm.yml b/.github/workflows/cmake_arm.yml index e57c297d7..d2a551699 100644 --- a/.github/workflows/cmake_arm.yml +++ b/.github/workflows/cmake_arm.yml @@ -105,15 +105,14 @@ jobs: # --------------------------------------- # Hardware in the loop (HIL) - # Current self-hosted instance is running on an RPI4 with - # - pico + pico-probe connected via USB - # - pico-probe is /dev/ttyACM0 + # Current self-hosted instance is running on an RPI4. + # For attached hardware checkout hil_pi4.json # --------------------------------------- hw-rp2040-test: # run only with hathach's commit due to limited resource on RPI4 if: github.repository_owner == 'hathach' needs: build-arm - runs-on: [self-hosted, Linux, ARM64, rp2040] + runs-on: [self-hosted, rp2040, hardware-in-the-loop] steps: - name: Clean workspace @@ -127,38 +126,6 @@ jobs: with: name: rp2040 - - name: Create flash.sh + - name: Test on actual hardware (hardware in the loop) run: | - echo > flash.sh 'cmdout=$(openocd -f "interface/cmsis-dap.cfg" -f "target/rp2040.cfg" -c "adapter speed 5000" -c "program $1 reset exit")' - echo >> flash.sh 'if (( $? )) ; then echo $cmdout ; fi' - chmod +x flash.sh - - - name: Test cdc_dual_ports - run: | - ./flash.sh cdc_dual_ports.elf - while (! ([ -e /dev/ttyACM1 ] && [ -e /dev/ttyACM2 ])) && [ $SECONDS -le 10 ]; do :; done - test -e /dev/ttyACM1 && echo "ttyACM1 exists" - test -e /dev/ttyACM2 && echo "ttyACM2 exists" - - - name: Test cdc_msc - run: | - ./flash.sh cdc_msc.elf - readme='/media/pi/TinyUSB MSC/README.TXT' - while (! ([ -e /dev/ttyACM1 ] && [ -f "$readme" ])) && [ $SECONDS -le 10 ]; do :; done - test -e /dev/ttyACM1 && echo "ttyACM1 exists" - test -f "$readme" && echo "$readme exists" - cat "$readme" - - - name: Test dfu - run: | - ./flash.sh dfu.elf - while (! (dfu-util -l | grep "Found DFU")) && [ $SECONDS -le 10 ]; do :; done - dfu-util -d cafe -a 0 -U dfu0 - dfu-util -d cafe -a 1 -U dfu1 - grep "TinyUSB DFU! - Partition 0" dfu0 - grep "TinyUSB DFU! - Partition 1" dfu1 - - - name: Test dfu_runtime - run: | - ./flash.sh dfu_runtime.elf - while (! (dfu-util -l | grep "Found Runtime")) && [ $SECONDS -le 10 ]; do :; done + python3 test/hil/hil_test.py hil_pi4.json diff --git a/hw/bsp/family_support.cmake b/hw/bsp/family_support.cmake index 930237fea..bd072e89d 100644 --- a/hw/bsp/family_support.cmake +++ b/hw/bsp/family_support.cmake @@ -395,6 +395,22 @@ function(family_flash_stlink TARGET) endfunction() +# Add flash openocd target +function(family_flash_openocd TARGET CLI_OPTIONS) + if (NOT DEFINED OPENOCD) + set(OPENOCD openocd) + endif () + + separate_arguments(CLI_OPTIONS_LIST UNIX_COMMAND ${CLI_OPTIONS}) + + # note skip verify since it has issue with rp2040 + add_custom_target(${TARGET}-openocd + DEPENDS ${TARGET} + COMMAND ${OPENOCD} ${CLI_OPTIONS_LIST} -c "program $ reset exit" + VERBATIM + ) +endfunction() + # Add flash pycod target function(family_flash_pyocd TARGET) if (NOT DEFINED PYOC) diff --git a/hw/bsp/rp2040/family.cmake b/hw/bsp/rp2040/family.cmake index 53e2add56..77d8029d9 100644 --- a/hw/bsp/rp2040/family.cmake +++ b/hw/bsp/rp2040/family.cmake @@ -12,6 +12,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/pico_sdk_import.cmake) # include basic family CMake functionality set(FAMILY_MCUS RP2040) set(JLINK_DEVICE rp2040_m0_0) +set(OPENOCD_OPTION "-f interface/cmsis-dap.cfg -f target/rp2040.cfg -c \"adapter speed 5000\"") include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake) @@ -158,6 +159,7 @@ function(family_configure_target TARGET RTOS) pico_enable_stdio_uart(${TARGET} 1) target_link_libraries(${TARGET} PUBLIC pico_stdlib pico_bootsel_via_double_reset tinyusb_board${RTOS_SUFFIX} tinyusb_additions) + family_flash_openocd(${TARGET} ${OPENOCD_OPTION}) family_flash_jlink(${TARGET}) endfunction() diff --git a/test/hil/hil_pi4.json b/test/hil/hil_pi4.json new file mode 100644 index 000000000..86bae3154 --- /dev/null +++ b/test/hil/hil_pi4.json @@ -0,0 +1,11 @@ +{ + "boards": [ + { + "name": "raspberry_pi_pico", + "uid": "E6614864D35DAE36", + "debugger": "openocd", + "debugger_sn": "E6614103E78E8324", + "debugger_args": "-f interface/cmsis-dap.cfg -f target/rp2040.cfg -c \"adapter speed 5000\"" + } + ] +} diff --git a/test/hil/hil_test.py b/test/hil/hil_test.py index 6bcde36c6..06640a470 100644 --- a/test/hil/hil_test.py +++ b/test/hil/hil_test.py @@ -38,6 +38,7 @@ def get_serial_dev(id, product, ifnum): return f'/dev/serial/by-id/usb-TinyUSB_{product}_{id}-if{ifnum:02d}' +# Currently not used, left as reference def get_disk_dev(id, lun): # get usb disk by id return f'/dev/disk/by-id/usb-TinyUSB_Mass_Storage_{id}-0:{lun}' @@ -59,10 +60,22 @@ def flash_jlink(sn, dev, firmware): assert ret.returncode == 0, 'Flash failed\n' + stdout +def flash_openocd(sn, args, firmware): + + ret = subprocess.run(f'openocd {args} -c "program {firmware} reset exit"', + shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + stdout = ret.stdout.decode() + assert ret.returncode == 0, 'Flash failed\n' + stdout + + +# ------------------------------------------------------------- +# Tests +# ------------------------------------------------------------- def test_board_test(id): # Dummy test pass + def test_cdc_dual_ports(id): port1 = get_serial_dev(id, "TinyUSB_Device", 0) port2 = get_serial_dev(id, "TinyUSB_Device", 2) @@ -99,12 +112,22 @@ def test_cdc_dual_ports(id): def test_cdc_msc(id): port = get_serial_dev(id, "TinyUSB_Device", 0) - file = f'/media/blkUSB_{id[-8:]}.02/README.TXT' + file_list = [f'/media/blkUSB_{id[-8:]}.02/README.TXT', f'/media/{os.getenv("USER")}/TinyUSB MSC/README.TXT'] # Wait device enum timeout = 10 while timeout: - if os.path.exists(port) and os.path.isfile(file): + f_found = False + if os.path.exists(port): + for file in file_list: + if os.path.isfile(file): + f_found = True + f = open(file, 'rb') + data = f.read() + break + + if f_found: break + time.sleep(1) timeout = timeout - 1 @@ -112,7 +135,6 @@ def test_cdc_msc(id): # Echo test ser1 = serial.Serial(port) - ser1.timeout = 1 str = b"test_str" @@ -121,9 +143,6 @@ def test_cdc_msc(id): assert ser1.read(100) == str, 'CDC wrong data' # Block test - f = open(file, 'rb') - data = f.read() - readme = \ b"This is tinyusb's MassStorage Class demo.\r\n\r\n\ If you find any bugs or get any questions, feel free to file an\r\n\ @@ -131,6 +150,7 @@ issue at github.com/hathach/tinyusb" assert data == readme, 'MSC wrong data' + def test_dfu(id): # Wait device enum timeout = 10 @@ -211,11 +231,13 @@ if __name__ == '__main__': # all possible tests, board_test is last to disable board's usb all_tests = [ - 'cdc_dual_ports', 'cdc_msc', 'dfu', 'dfu_runtime', 'hid_boot_interface', 'board_test' + 'cdc_dual_ports', 'cdc_msc', 'dfu', 'dfu_runtime', 'hid_boot_interface', + 'board_test' ] for board in config['boards']: print(f'Testing board:{board["name"]}') + debugger = board['debugger'].lower() # default to all tests if 'tests' in board: @@ -240,8 +262,10 @@ if __name__ == '__main__': print(f'Cannot find firmware file for {test}') sys.exit(-1) - if board['debugger'].lower() == 'jlink': + if debugger == 'jlink': flash_jlink(board['debugger_sn'], board['cpu'], elf) + elif debugger == 'openocd': + flash_openocd(board['debugger_sn'], board['debugger_args'], elf) else: # ToDo pass -- cgit v1.3.1 From b45ad57c50d13af1d2ee9e1cc2342feac4ea676d Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 28 Nov 2023 23:02:26 +0700 Subject: spare checkout test/hil and correct hil_pi4 uuid --- .github/workflows/cmake_arm.yml | 5 +++++ test/hil/hil_pi4.json | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to '.github') diff --git a/.github/workflows/cmake_arm.yml b/.github/workflows/cmake_arm.yml index d2a551699..f4b93cec7 100644 --- a/.github/workflows/cmake_arm.yml +++ b/.github/workflows/cmake_arm.yml @@ -121,6 +121,11 @@ jobs: rm -rf "${{ github.workspace }}" mkdir -p "${{ github.workspace }}" + - name: Checkout test/hil + uses: actions/checkout@v3 + with: + sparse-checkout: test/hil + - name: Download rp2040 Artifacts uses: actions/download-artifact@v3 with: diff --git a/test/hil/hil_pi4.json b/test/hil/hil_pi4.json index 86bae3154..18ac12bc4 100644 --- a/test/hil/hil_pi4.json +++ b/test/hil/hil_pi4.json @@ -2,9 +2,9 @@ "boards": [ { "name": "raspberry_pi_pico", - "uid": "E6614864D35DAE36", + "uid": "E6614103E72C1D2F", "debugger": "openocd", - "debugger_sn": "E6614103E78E8324", + "debugger_sn": "E6614C311B764A37", "debugger_args": "-f interface/cmsis-dap.cfg -f target/rp2040.cfg -c \"adapter speed 5000\"" } ] -- cgit v1.3.1 From 83840041a86d3893dc66e9a39cdace78158da011 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 29 Nov 2023 17:09:52 +0700 Subject: update esp32 to also be supported by hil test test run locally well --- .github/workflows/build_esp.yml | 2 +- examples/device/audio_4_channel_mic/skip.txt | 1 + examples/device/audio_test/skip.txt | 1 + examples/device/audio_test_multi_rate/skip.txt | 1 + examples/device/board_test/src/tusb_config.h | 5 ++ examples/device/cdc_msc/skip.txt | 1 + examples/device/cdc_msc_freertos/src/msc_disk.c | 8 +- examples/device/dfu/skip.txt | 1 + examples/device/dynamic_configuration/skip.txt | 1 + examples/device/msc_dual_lun/skip.txt | 1 + examples/device/net_lwip_webserver/skip.txt | 1 + examples/device/uac2_headset/skip.txt | 1 + examples/device/usbtmc/skip.txt | 1 + examples/device/video_capture/skip.txt | 1 + .../espressif/boards/espressif_s3_devkitc/board.h | 8 ++ hw/bsp/espressif/boards/family.c | 7 ++ test/hil/hil_test.py | 90 +++++++++++++++------- tools/build_esp32.py | 1 + 18 files changed, 99 insertions(+), 33 deletions(-) (limited to '.github') diff --git a/.github/workflows/build_esp.yml b/.github/workflows/build_esp.yml index 897616f09..4568695c2 100644 --- a/.github/workflows/build_esp.yml +++ b/.github/workflows/build_esp.yml @@ -32,7 +32,7 @@ jobs: # ESP32-S2 - 'espressif_kaluga_1' # ESP32-S3 - - 'espressif_s3_devkitm' + - 'espressif_s3_devkitc' steps: - name: Setup Python diff --git a/examples/device/audio_4_channel_mic/skip.txt b/examples/device/audio_4_channel_mic/skip.txt index 3c42a96d9..157605df1 100644 --- a/examples/device/audio_4_channel_mic/skip.txt +++ b/examples/device/audio_4_channel_mic/skip.txt @@ -2,3 +2,4 @@ mcu:SAMD11 mcu:SAME5X mcu:SAMG family:broadcom_64bit +family:espressif diff --git a/examples/device/audio_test/skip.txt b/examples/device/audio_test/skip.txt index 1ee86a485..65b137814 100644 --- a/examples/device/audio_test/skip.txt +++ b/examples/device/audio_test/skip.txt @@ -1,3 +1,4 @@ mcu:SAMD11 mcu:SAME5X mcu:SAMG +family:espressif diff --git a/examples/device/audio_test_multi_rate/skip.txt b/examples/device/audio_test_multi_rate/skip.txt index 1ee86a485..65b137814 100644 --- a/examples/device/audio_test_multi_rate/skip.txt +++ b/examples/device/audio_test_multi_rate/skip.txt @@ -1,3 +1,4 @@ mcu:SAMD11 mcu:SAME5X mcu:SAMG +family:espressif diff --git a/examples/device/board_test/src/tusb_config.h b/examples/device/board_test/src/tusb_config.h index 2c2eb5280..1a27cc87f 100644 --- a/examples/device/board_test/src/tusb_config.h +++ b/examples/device/board_test/src/tusb_config.h @@ -48,6 +48,11 @@ #define CFG_TUSB_OS OPT_OS_NONE #endif +// Espressif IDF requires "freertos/" prefix in include path +#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) +#define CFG_TUSB_OS_INC_PATH freertos/ +#endif + // This example only test LED & GPIO, disable both device and host stack #define CFG_TUD_ENABLED 0 #define CFG_TUH_ENABLED 0 diff --git a/examples/device/cdc_msc/skip.txt b/examples/device/cdc_msc/skip.txt index eadb6e74a..833fd072c 100644 --- a/examples/device/cdc_msc/skip.txt +++ b/examples/device/cdc_msc/skip.txt @@ -1 +1,2 @@ mcu:SAMD11 +family:espressif diff --git a/examples/device/cdc_msc_freertos/src/msc_disk.c b/examples/device/cdc_msc_freertos/src/msc_disk.c index 9520dfec1..c8a04bb74 100644 --- a/examples/device/cdc_msc_freertos/src/msc_disk.c +++ b/examples/device/cdc_msc_freertos/src/msc_disk.c @@ -184,7 +184,7 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buff uint8_t const* addr = msc_disk[lba] + offset; memcpy(buffer, addr, bufsize); - return bufsize; + return (int32_t) bufsize; } // Callback invoked when received WRITE10 command. @@ -203,7 +203,7 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* (void) lba; (void) offset; (void) buffer; #endif - return bufsize; + return (int32_t) bufsize; } // Callback invoked when received an SCSI command not in built-in list below @@ -237,14 +237,14 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, { if(in_xfer) { - memcpy(buffer, response, resplen); + memcpy(buffer, response, (size_t) resplen); }else { // SCSI output } } - return resplen; + return (int32_t) resplen; } #endif diff --git a/examples/device/dfu/skip.txt b/examples/device/dfu/skip.txt index 9ac346bad..9dde06c30 100644 --- a/examples/device/dfu/skip.txt +++ b/examples/device/dfu/skip.txt @@ -1,2 +1,3 @@ mcu:TM4C123 mcu:BCM2835 +family:espressif diff --git a/examples/device/dynamic_configuration/skip.txt b/examples/device/dynamic_configuration/skip.txt index eadb6e74a..833fd072c 100644 --- a/examples/device/dynamic_configuration/skip.txt +++ b/examples/device/dynamic_configuration/skip.txt @@ -1 +1,2 @@ mcu:SAMD11 +family:espressif diff --git a/examples/device/msc_dual_lun/skip.txt b/examples/device/msc_dual_lun/skip.txt index 47e561cf0..a9e3a99b1 100644 --- a/examples/device/msc_dual_lun/skip.txt +++ b/examples/device/msc_dual_lun/skip.txt @@ -1,2 +1,3 @@ mcu:SAMD11 mcu:MKL25ZXX +family:espressif diff --git a/examples/device/net_lwip_webserver/skip.txt b/examples/device/net_lwip_webserver/skip.txt index e3a726a2b..75aa2ef14 100644 --- a/examples/device/net_lwip_webserver/skip.txt +++ b/examples/device/net_lwip_webserver/skip.txt @@ -9,3 +9,4 @@ family:broadcom_64bit family:broadcom_32bit board:curiosity_nano board:frdm_kl25z +family:espressif diff --git a/examples/device/uac2_headset/skip.txt b/examples/device/uac2_headset/skip.txt index 70d8e8838..a2a76af0e 100644 --- a/examples/device/uac2_headset/skip.txt +++ b/examples/device/uac2_headset/skip.txt @@ -5,3 +5,4 @@ mcu:SAMD11 mcu:SAME5X mcu:SAMG board:stm32l052dap52 +family:espressif diff --git a/examples/device/usbtmc/skip.txt b/examples/device/usbtmc/skip.txt index a43106cf0..ccff857ac 100644 --- a/examples/device/usbtmc/skip.txt +++ b/examples/device/usbtmc/skip.txt @@ -1 +1,2 @@ mcu:BCM2835 +family:espressif diff --git a/examples/device/video_capture/skip.txt b/examples/device/video_capture/skip.txt index 5898664a2..db64cc639 100644 --- a/examples/device/video_capture/skip.txt +++ b/examples/device/video_capture/skip.txt @@ -1,3 +1,4 @@ mcu:MSP430x5xx mcu:NUC121 mcu:SAMD11 +family:espressif diff --git a/hw/bsp/espressif/boards/espressif_s3_devkitc/board.h b/hw/bsp/espressif/boards/espressif_s3_devkitc/board.h index fe33b5c43..a319fbc61 100644 --- a/hw/bsp/espressif/boards/espressif_s3_devkitc/board.h +++ b/hw/bsp/espressif/boards/espressif_s3_devkitc/board.h @@ -36,6 +36,14 @@ #define BUTTON_PIN 0 #define BUTTON_STATE_ACTIVE 0 +// SPI for USB host shield +#define MAX3421_SPI_HOST SPI2_HOST +#define MAX3421_SCK_PIN 39 +#define MAX3421_MOSI_PIN 42 +#define MAX3421_MISO_PIN 21 +#define MAX3421_CS_PIN 15 +#define MAX3421_INTR_PIN 14 + #ifdef __cplusplus } #endif diff --git a/hw/bsp/espressif/boards/family.c b/hw/bsp/espressif/boards/family.c index 2029295dc..c32ccbc84 100644 --- a/hw/bsp/espressif/boards/family.c +++ b/hw/bsp/espressif/boards/family.c @@ -28,6 +28,7 @@ #include "board.h" #include "esp_rom_gpio.h" +#include "esp_mac.h" #include "hal/gpio_ll.h" #include "hal/usb_hal.h" #include "soc/usb_periph.h" @@ -149,6 +150,12 @@ static void configure_pins(usb_hal_context_t* usb) { // Board porting API //--------------------------------------------------------------------+ +size_t board_get_unique_id(uint8_t id[], size_t max_len) { + // use factory default MAC as serial ID + esp_efuse_mac_get_default(id); + return 6; +} + void board_led_write(bool state) { #ifdef NEOPIXEL_PIN strip->set_pixel(strip, 0, (state ? 0x88 : 0x00), 0x00, 0x00); diff --git a/test/hil/hil_test.py b/test/hil/hil_test.py index 5f8425549..c90cf363c 100644 --- a/test/hil/hil_test.py +++ b/test/hil/hil_test.py @@ -31,13 +31,21 @@ import time import serial import subprocess import json +import glob ENUM_TIMEOUT = 10 +# get usb serial by id def get_serial_dev(id, vendor_str, product_str, ifnum): - # get usb serial by id - return f'/dev/serial/by-id/usb-{vendor_str}_{product_str}_{id}-if{ifnum:02d}' + if vendor_str and product_str: + # known vendor and product + return f'/dev/serial/by-id/usb-{vendor_str}_{product_str}_{id}-if{ifnum:02d}' + else: + # just use id: mostly for cp210x/ftdi debugger + pattern = f'/dev/serial/by-id/usb-*_{id}-if{ifnum:02d}*' + port_list = glob.glob(pattern) + return port_list[0] # Currently not used, left as reference @@ -92,23 +100,35 @@ def read_disk_file(id, fname): # ------------------------------------------------------------- # Flash with debugger # ------------------------------------------------------------- -def flash_jlink(sn, dev, firmware): +def flash_jlink(board, firmware): script = ['halt', 'r', f'loadfile {firmware}', 'r', 'go', 'exit'] - f = open('flash.jlink', 'w') - f.writelines(f'{s}\n' for s in script) - f.close() - ret = subprocess.run(f'JLinkExe -USB {sn} -device {dev} -if swd -JTAGConf -1,-1 -speed auto -NoGui 1 -ExitOnError 1 -CommandFile flash.jlink', - shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - stdout = ret.stdout.decode() + with open('flash.jlink', 'w') as f: + f.writelines(f'{s}\n' for s in script) + ret = subprocess.run( + f'JLinkExe -USB {board["debugger_sn"]} -device {board["cpu"]} -if swd -JTAGConf -1,-1 -speed auto -NoGui 1 -ExitOnError 1 -CommandFile flash.jlink', + shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) os.remove('flash.jlink') - assert ret.returncode == 0, 'Flash failed\n' + stdout + return ret -def flash_openocd(sn, args, firmware): - ret = subprocess.run(f'openocd {args} -c "program {firmware} reset exit"', - shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - stdout = ret.stdout.decode() - assert ret.returncode == 0, 'Flash failed\n' + stdout +def flash_openocd(board, firmware): + ret = subprocess.run( + f'openocd -c "adapter serial {board["debugger_sn"]}" {board["debugger_args"]} -c "program {firmware} reset exit"', + shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + return ret + + +def flash_esptool(board, firmware): + port = get_serial_dev(board["debugger_sn"], None, None, 0) + dir = os.path.dirname(firmware) + with open(f'{dir}/config.env') as f: + IDF_TARGET = json.load(f)['IDF_TARGET'] + with open(f'{dir}/flash_args') as f: + flash_args = f.read().strip().replace('\n', ' ') + command = (f'esptool.py --chip {IDF_TARGET} -p {port} {board["debugger_args"]} ' + f'--before=default_reset --after=hard_reset write_flash {flash_args}') + ret = subprocess.run(command, shell=True, cwd=dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + return ret # ------------------------------------------------------------- @@ -160,12 +180,16 @@ issue at github.com/hathach/tinyusb" assert data == readme, 'MSC wrong data' +def test_cdc_msc_freertos(id): + test_cdc_msc(id) + + def test_dfu(id): # Wait device enum timeout = ENUM_TIMEOUT while timeout: ret = subprocess.run(f'dfu-util -l', - shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout = ret.stdout.decode() if f'serial="{id}"' in stdout and 'Found DFU: [cafe:4000]' in stdout: break @@ -190,10 +214,10 @@ def test_dfu(id): assert ret.returncode == 0, 'Upload failed' with open('dfu0') as f: - assert 'Hello world from TinyUSB DFU! - Partition 0' in f.read(), 'Wrong uploaded data' + assert 'Hello world from TinyUSB DFU! - Partition 0' in f.read(), 'Wrong uploaded data' with open('dfu1') as f: - assert 'Hello world from TinyUSB DFU! - Partition 1' in f.read(), 'Wrong uploaded data' + assert 'Hello world from TinyUSB DFU! - Partition 1' in f.read(), 'Wrong uploaded data' os.remove('dfu0') os.remove('dfu1') @@ -204,7 +228,7 @@ def test_dfu_runtime(id): timeout = ENUM_TIMEOUT while timeout: ret = subprocess.run(f'dfu-util -l', - shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout = ret.stdout.decode() if f'serial="{id}"' in stdout and 'Found Runtime: [cafe:4000]' in stdout: break @@ -229,6 +253,14 @@ def test_hid_boot_interface(id): assert timeout, 'Device not available' +def test_hid_composite_freertos(id): + # TODO implement later + pass + + +# ------------------------------------------------------------- +# Main +# ------------------------------------------------------------- if __name__ == '__main__': if len(sys.argv) != 2: print('Usage:') @@ -238,10 +270,9 @@ if __name__ == '__main__': with open(f'{os.path.dirname(__file__)}/{sys.argv[1]}') as f: config = json.load(f) - # all possible tests, board_test is last to disable board's usb + # all possible tests all_tests = [ 'cdc_dual_ports', 'cdc_msc', 'dfu', 'dfu_runtime', 'hid_boot_interface', - 'board_test' ] for board in config['boards']: @@ -254,6 +285,9 @@ if __name__ == '__main__': else: test_list = all_tests + # board_test is added last to disable board's usb + test_list.append('board_test') + # remove skip_tests if 'tests_skip' in board: for skip in board['tests_skip']: @@ -278,13 +312,13 @@ if __name__ == '__main__': print(f'Cannot find firmware file for {test}') sys.exit(-1) - if debugger == 'jlink': - flash_jlink(board['debugger_sn'], board['cpu'], elf) - elif debugger == 'openocd': - flash_openocd(board['debugger_sn'], board['debugger_args'], elf) - else: - # ToDo - pass print(f' {test} ...', end='') + + # flash firmware + ret = locals()[f'flash_{debugger}'](board, elf) + assert ret.returncode == 0, 'Flash failed\n' + ret.stdout.decode() + + # run test locals()[f'test_{test}'](board['uid']) + print('OK') diff --git a/tools/build_esp32.py b/tools/build_esp32.py index 1f73d3b22..951467c23 100644 --- a/tools/build_esp32.py +++ b/tools/build_esp32.py @@ -30,6 +30,7 @@ def filter_with_input(mylist): # Build all examples if not specified all_examples = [entry.replace('examples/', '') for entry in glob.glob("examples/*/*_freertos")] filter_with_input(all_examples) +all_examples.append('device/board_test') all_examples.sort() # Build all boards if not specified -- cgit v1.3.1 From fe4bb4020756b6146cfd7d4b5d639a1d4e5801f1 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 29 Nov 2023 17:22:33 +0700 Subject: fix pre-commit typo --- .github/workflows/codeql.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to '.github') diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 56454f22f..2fc7a8582 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -89,7 +89,7 @@ jobs: upload: false id: step1 - # Filter out rules with low severity or high false positve rate + # Filter out rules with low severity or high false positive rate # Also filter out warnings in third-party code - name: Filter out unwanted errors and warnings uses: advanced-security/filter-sarif@v1 @@ -124,4 +124,4 @@ jobs: with: name: codeql-results path: ${{ steps.step1.outputs.sarif-output }} - retention-days: 5 \ No newline at end of file + retention-days: 5 -- cgit v1.3.1 From 0504192fb7b15144b62e397d3e10c73c465ced67 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 29 Nov 2023 22:30:58 +0700 Subject: update buildscript --- .github/workflows/codeql-buildscript.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to '.github') diff --git a/.github/workflows/codeql-buildscript.sh b/.github/workflows/codeql-buildscript.sh index 38d3714c1..35e029922 100644 --- a/.github/workflows/codeql-buildscript.sh +++ b/.github/workflows/codeql-buildscript.sh @@ -2,4 +2,4 @@ FAMILY=stm32l4 python3 tools/get_deps.py $FAMILY -python3 tools/build_family.py $FAMILY +python3 tools/build_make.py $FAMILY -- cgit v1.3.1 From 66b9bd52d685eb7995f7d770ee01095966c2d880 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 30 Nov 2023 11:38:54 +0700 Subject: minor tweak to codeql.yml --- .github/workflows/codeql.yml | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to '.github') diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 2fc7a8582..dec071753 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -12,12 +12,24 @@ name: "CodeQL" on: - # push: - # branches: [ "main", "master" ] + push: + branches: [ 'master' ] + paths: + - 'src/**' + - 'examples/**' + - 'lib/**' + - 'hw/**' + - '.github/workflows/codeql.yml' + pull_request: + branches: [ 'master' ] + paths: + - 'src/**' + - 'examples/**' + - 'lib/**' + - 'hw/**' + - '.github/workflows/codeql.yml' schedule: - cron: '0 0 * * *' - pull_request: - branches: '*' jobs: analyze: @@ -27,8 +39,8 @@ jobs: # - https://gh.io/supported-runners-and-hardware-resources # - https://gh.io/using-larger-runners # Consider using larger runners for possible analysis time improvements. - runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-20.04' }} - timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} + runs-on: ubuntu-latest + timeout-minutes: 360 permissions: actions: read contents: read @@ -37,22 +49,20 @@ jobs: strategy: fail-fast: false matrix: - language: [ 'cpp' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ] - # Use only 'java' to analyze code written in Java, Kotlin or both - # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both + language: [ 'c-cpp' ] + # CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ] + # Use only 'java-kotlin' to analyze code written in Java, Kotlin or both + # Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support steps: - name: Checkout repository uses: actions/checkout@v3 - with: - submodules: recursive - - name: arm-none-eabi-gcc GNU Arm Embedded Toolchain - uses: carlosperate/arm-none-eabi-gcc-action@v1.6.0 + - name: Install ARM GCC + uses: carlosperate/arm-none-eabi-gcc-action@v1 with: - release: '10.3-2021.10' + release: '11.2-2022.02' # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL -- cgit v1.3.1