From edf976b703be2f5149b9a8c6fe33d5bb3901ad82 Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Thu, 26 Feb 2026 11:01:43 +0100 Subject: [PATCH 1/2] ci: add qemu test --- .github/workflows/test-python.yml | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index 176328e6..fe87a840 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -1,4 +1,4 @@ -name: Test Python Packages +name: Target Tests on: pull_request: @@ -19,6 +19,32 @@ env: WOKWI_CLI_TOKEN: ${{ secrets.WOKWI_CLI_TOKEN }} jobs: + test-qemu: + timeout-minutes: 40 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.14" + - name: Install dependencies + run: | + sudo apt update && sudo apt install -y libgcrypt20 libglib2.0-0 libpixman-1-0 libsdl2-2.0-0 libslirp0 + pip install -U pip + export PIP_EXTRA_INDEX_URL="https://dl.espressif.com/pypi" + pip install cryptography --prefer-binary + pip install -r requirements.txt + bash foreach.sh install + - name: Download and install QEMU + run: | + wget https://github.com/espressif/qemu/releases/download/esp-develop-9.2.2-20250817/qemu-xtensa-softmmu-esp_develop_9.2.2_20250817-x86_64-linux-gnu.tar.xz + wget https://github.com/espressif/qemu/releases/download/esp-develop-9.2.2-20250817/qemu-riscv32-softmmu-esp_develop_9.2.2_20250817-x86_64-linux-gnu.tar.xz + tar -xf qemu-xtensa-softmmu-esp_develop_9.2.2_20250817-x86_64-linux-gnu.tar.xz + tar -xf qemu-riscv32-softmmu-esp_develop_9.2.2_20250817-x86_64-linux-gnu.tar.xz + echo "$PWD/qemu/bin" >> $GITHUB_PATH + - name: Run QEMU tests + run: pytest pytest-embedded-qemu/tests/test_qemu.py + test-python: timeout-minutes: 40 strategy: From cbdb6d63cff2005dcdf15f43fc3c5efa2c8c46a3 Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Thu, 26 Feb 2026 16:20:49 +0100 Subject: [PATCH 2/2] ci: combine coverage --- .github/workflows/report.yml | 65 +++++++++++++++++++++++++++++++ .github/workflows/test-python.yml | 53 ++++++++++++++++++------- 2 files changed, 103 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/report.yml diff --git a/.github/workflows/report.yml b/.github/workflows/report.yml new file mode 100644 index 00000000..4be5571a --- /dev/null +++ b/.github/workflows/report.yml @@ -0,0 +1,65 @@ +name: Report +on: + workflow_run: + workflows: + - Target Tests + types: + - completed + +permissions: + actions: read + checks: write + pull-requests: write + +jobs: + report: + runs-on: ubuntu-latest + steps: + - name: Download test results + uses: dawidd6/action-download-artifact@v16 + with: + workflow: ${{ github.event.workflow_run.workflow_id }} + run_id: ${{ github.event.workflow_run.id }} + name_is_regexp: true + name: "test-results-.*" + path: test-results + if_no_artifact_found: ignore + + - name: Read PR number + id: pr-number + run: | + PR_FILE=$(find test-results -name pr_number.txt | head -n 1) + if [ -n "$PR_FILE" ] && [ -f "$PR_FILE" ]; then + echo "PR_NUMBER=$(cat $PR_FILE)" >> $GITHUB_ENV + else + echo "No pr_number.txt found, skipping comment." + exit 0 + fi + + - name: Prepare multiple files string + if: env.PR_NUMBER != '' + id: generate-files + run: | + MULTIPLE_FILES="" + for xml_file in $(find test-results -name "pytest-*.xml"); do + dir_name=$(dirname "$xml_file") + # title from directory name test-results-qemu -> qemu + title=$(basename "$dir_name" | sed 's/^test-results-//') + # Capitalize first letter and replace hyphens with spaces + title=$(echo "$title" | awk '{print toupper(substr($0,1,1)) substr($0,2)}' | tr '-' ' ') + + cov_file=$(find "$dir_name" -name "coverage-*.xml" | head -n 1) + # Add to multiple files string + MULTIPLE_FILES="${MULTIPLE_FILES}${title}, ${cov_file}, ${xml_file}"$'\n' + done + + echo "FILES<> $GITHUB_OUTPUT + echo -e "$MULTIPLE_FILES" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + - name: Comment on PR + uses: MishaKav/pytest-coverage-comment@v1 + if: env.PR_NUMBER != '' && steps.generate-files.outputs.FILES != '' + with: + issue-number: ${{ env.PR_NUMBER }} + multiple-files: ${{ steps.generate-files.outputs.FILES }} diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index fe87a840..e824e611 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -7,8 +7,6 @@ on: - "*/pyproject.toml" - .github/workflows/test-python.yml - "!docs/**" - push: - branches: [main] # cancel jobs if new commit pushed concurrency: @@ -23,8 +21,8 @@ jobs: timeout-minutes: 40 runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 + - uses: actions/checkout@v6 + - uses: actions/setup-python@v6 with: python-version: "3.14" - name: Install dependencies @@ -42,8 +40,33 @@ jobs: tar -xf qemu-xtensa-softmmu-esp_develop_9.2.2_20250817-x86_64-linux-gnu.tar.xz tar -xf qemu-riscv32-softmmu-esp_develop_9.2.2_20250817-x86_64-linux-gnu.tar.xz echo "$PWD/qemu/bin" >> $GITHUB_PATH + + - name: Save PR number + run: echo ${{ github.event.number }} > pr_number.txt + - name: Run QEMU tests - run: pytest pytest-embedded-qemu/tests/test_qemu.py + run: | + pytest pytest-embedded-qemu/tests/test_qemu.py \ + --junitxml pytest-qemu.xml \ + --cov-report=xml:coverage-qemu.xml \ + --cov=pytest_embedded \ + --cov=pytest_embedded_arduino \ + --cov=pytest_embedded_idf \ + --cov=pytest_embedded_jtag \ + --cov=pytest_embedded_qemu \ + --cov=pytest_embedded_serial \ + --cov=pytest_embedded_serial_esp \ + --cov=pytest_embedded_wokwi \ + --cov=pytest_embedded_nuttx + - name: Upload test results + uses: actions/upload-artifact@v6 + if: always() + with: + name: test-results-qemu + path: | + pr_number.txt + pytest-qemu.xml + coverage-qemu.xml test-python: timeout-minutes: 40 @@ -74,11 +97,12 @@ jobs: bash foreach.sh install - name: Check ports run: ls -la /dev/ttyUSB* + - name: Run Tests with coverage run: | pytest \ - --junitxml=pytest.xml \ - --cov-report=term-missing \ + --junitxml=pytest-${{ matrix.python-version }}-${{ matrix.arch }}.xml \ + --cov-report=xml:coverage-${{ matrix.python-version }}-${{ matrix.arch }}.xml \ --cov=pytest_embedded \ --cov=pytest_embedded_arduino \ --cov=pytest_embedded_idf \ @@ -88,12 +112,11 @@ jobs: --cov=pytest_embedded_serial_esp \ --cov=pytest_embedded_wokwi \ --cov=pytest_embedded_nuttx - - name: Zip log files - if: failure() - run: | - zip -r logs.zip /tmp/pytest-embedded - - uses: actions/upload-artifact@v6 - if: failure() + - name: Upload test results + uses: actions/upload-artifact@v6 + if: always() with: - name: logs-${{ matrix.python-version }} - path: logs.zip + name: test-results-${{ matrix.python-version }}-${{ matrix.arch }} + path: | + pytest-${{ matrix.python-version }}-${{ matrix.arch }}.xml + coverage-${{ matrix.python-version }}-${{ matrix.arch }}.xml