From 89e120e74c8889db74d12d32ee0d74b8f2ed8ec6 Mon Sep 17 00:00:00 2001 From: Avimitin Date: Wed, 3 Apr 2024 04:35:56 +0800 Subject: [PATCH] Create test Signed-off-by: Avimitin --- .github/workflows/pr.yml | 250 ------------------------------------- .github/workflows/test.yml | 33 +++++ 2 files changed, 33 insertions(+), 250 deletions(-) delete mode 100644 .github/workflows/pr.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml deleted file mode 100644 index c42098114..000000000 --- a/.github/workflows/pr.yml +++ /dev/null @@ -1,250 +0,0 @@ -name: PR -on: [pull_request] -env: - USER: runner - -# Cancel the current workflow when new commit pushed -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number }} - cancel-in-progress: true - -jobs: - gen-test-plan: - name: "Generate test plan" - runs-on: [self-hosted, linux, nixos] - outputs: - testplan: ${{ steps.get-all-configs.outputs.out }} - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.sha }} - - id: "get-all-configs" - run: echo "out=$(nix run '.#ammonite' -- ./.github/scripts/ci.sc generateTestPlan)" > $GITHUB_OUTPUT - - build-emulators: - name: "Build Emulators" - needs: [gen-test-plan] - runs-on: [self-hosted, linux, nixos] - strategy: - fail-fast: false - matrix: ${{ fromJSON(needs.gen-test-plan.outputs.testplan) }} - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.sha }} - - name: "Build verilator emulator" - run: | - nix build '.#t1.${{ matrix.config }}.ip.emu' -L --no-link --cores 64 - - name: "Build all testcases" - run: | - # Build testcases with vlen 1024 and vlen 4096 - nix build ".#t1.${{ matrix.config }}.cases.all" --max-jobs auto -L --no-link --cores 64 - - gen-matrix: - name: "Prepare for running testcases" - needs: [build-emulators] - runs-on: [self-hosted, linux, nixos, "MEM:32"] - env: - RUNNERS: 70 - outputs: - ci-tests: ${{ steps.gen-matrix.outputs.matrix }} - steps: - # actions/checkout will use the "event" commit to checkout repository, - # which will lead to an unexpected issue that the "event" commit doesn't belongs to the repository, - # and causing the derivation build output cannot be cache correctly. - - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.sha }} - - id: gen-matrix - name: "Generate test matrix" - run: | - echo -n matrix= >> "$GITHUB_OUTPUT" - nix shell ".#ammonite" -c .github/scripts/ci.sc generateCiMatrix --runnersAmount "$RUNNERS" >> "$GITHUB_OUTPUT" - - build-trace-emulators: - name: "Build trace emulator" - needs: [gen-test-plan] - runs-on: [self-hosted, linux, nixos] - strategy: - fail-fast: false - matrix: ${{ fromJSON(needs.gen-test-plan.outputs.testplan) }} - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.sha }} - - name: "Build verilator emulator with trace" - run: nix build '.#t1.${{ matrix.config }}.ip.emu-trace' -L --no-link --cores 64 - - test-emit: - name: "Test elaborate" - runs-on: [self-hosted, linux, nixos] - strategy: - fail-fast: false - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.sha }} - - name: "Test elaborate" - run: | - configArray=( $(jq -r '.configs[]' configgen/all-configs.json) ) - for cfg in "${configArray[@]}"; do - echo "Building .#t1.${cfg}.ip.rtl" - if ! nix build ".#t1.${cfg}.ip.rtl" -L; then - failed_rtl_configs+=("${cfg}.ip") - fi - echo "Building .#t1.${cfg}.subsystem.rtl" - if ! nix build ".#t1.${cfg}.subsystem.rtl" -L; then - failed_rtl_configs+=("${cfg}.subsystem") - fi - done - if [ -n "${failed_rtl_configs[*]}" ]; then - echo -e "## Failed RTL\n" >> "$GITHUB_STEP_SUMMARY" - for cfg in "${failed_rtl_configs[@]}"; do - echo "* ${cfg}" >> $GITHUB_STEP_SUMMARY - done - printf "\n" >> $GITHUB_STEP_SUMMARY - fi - - run-testcases: - name: "Run testcases" - needs: [gen-matrix] - strategy: - fail-fast: false - matrix: ${{ fromJSON(needs.gen-matrix.outputs.ci-tests) }} - runs-on: [self-hosted, linux, nixos] - outputs: - result: ${{ steps.ci-run.outputs.result }} - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.sha }} - - name: "Run testcases" - id: ci-run - run: | - nix shell ".#ammonite" -c .github/scripts/ci.sc runTests --jobs "${{ matrix.jobs }}" \ - --resultDir test-results-$(head -c 10 /dev/urandom | base32) - - - uses: actions/upload-artifact@v4 - if: ${{ !cancelled() }} - with: - name: test-reports-${{ matrix.id }} - path: | - test-results-*/failed-tests.md - test-results-*/cycle-updates.md - test-results-*/*_cycle.json - - - uses: actions/upload-artifact@v4 - if: failure() - with: - name: failed-logs-${{ matrix.id }} - path: test-results-*/failed-logs - - gen-fail-wave-matrix: - name: "Generate matrix for re-testing failing tests" - if: ${{ !cancelled() }} - needs: [run-testcases] - runs-on: [self-hosted, linux, nixos] - outputs: - generate_wave: ${{ steps.generate-matrix.outputs.generate_wave }} - retry_tasks: ${{ steps.generate-matrix.outputs.retry_tasks }} - steps: - - uses: actions/download-artifact@v4 - with: - pattern: test-reports-* - merge-multiple: true - - id: generate-matrix - name: "Generate matrix" - run: | - touch all-fail-tests.txt - shopt -s nullglob - cat test-results-*/failed-tests.md > all-failed-tests.txt - retry=$(sed 's/\* //' all-failed-tests.txt | shuf -n3) # only retry last three failed - echo "build wave for: $retry" - if [ -n "$retry" ]; then - echo "generate_wave=true" >> "$GITHUB_OUTPUT" - echo -n "retry_tasks=" >> "$GITHUB_OUTPUT" - echo "$retry" | \ - jq -nR --indent 0 '{"include": [inputs | {"job": ., "id": (input_line_number)}]}' >> "$GITHUB_OUTPUT" - fi - - build-fail-wave: - name: "Generate wave for failing tests" - needs: [build-emulators, gen-fail-wave-matrix] - if: ${{ !cancelled() && needs.gen-fail-wave-matrix.outputs.generate_wave == 'true' }} - strategy: - fail-fast: false - matrix: ${{ fromJSON(needs.gen-fail-wave-matrix.outputs.retry_tasks) }} - runs-on: [self-hosted, linux, nixos] - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.sha }} - - name: "Run failed testcases" - run: | - nix shell ".#ammonite" -c .github/scripts/ci.sc runFailedTests --jobs "${{ matrix.job }}" - waveFile=$(find testrun -name 'wave.fst') - hierFile=$(find testrun -name 'wave.hier') - if [[ -z "$waveFile" || -n "$hierFile" ]]; then # when emulator failed, .hier is not merged into .fst - echo "Verilator doesn't generate wave correctly" - exit 1 - fi - mv "$waveFile" ./wave-${{ matrix.job }}.fst - - uses: actions/upload-artifact@v4 - with: - name: ${{ matrix.id }}-failed-tests-wave - path: 'wave-*.fst' - - report: - name: "Report CI result" - # Don't run report when: - # - user cancel ( we don't need report at this case ) - # - PR from outside repository ( we don't have permission to push commit into fork repository ) - if: ${{ !cancelled() && github.event.pull_request.head.repo.full_name == github.repository }} - needs: [run-testcases] - runs-on: [self-hosted, linux, nixos] - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - ref: ${{ github.head_ref }} - - uses: actions/download-artifact@v4 - with: - pattern: test-reports-* - merge-multiple: true - - name: "Print step summary" - run: | - echo -e "\n## Failed tests\n" >> $GITHUB_STEP_SUMMARY - shopt -s nullglob - cat test-results-*/failed-tests.md >> $GITHUB_STEP_SUMMARY - echo -e "\n## Cycle updates\n" >> $GITHUB_STEP_SUMMARY - shopt -s nullglob - cat test-results-*/cycle-updates.md >> $GITHUB_STEP_SUMMARY - - name: "Commit cycle updates" - run: | - nix shell ".#ammonite" -c .github/scripts/ci.sc mergeCycleData - git config user.name github-actions - git config user.email github-actions@github.com - changed_cases=$(git diff --name-only '.github/cases/**/default.json') - - if [ -n "$changed_cases" ]; then - echo "changed cases: $changed_cases" - git add '.github/cases/**/default.json' - git commit -m "[ci] update test case cycle data" - git push origin ${{ github.head_ref }} - else - echo "No cycle change detect" - fi - - uses: geekyeggo/delete-artifact@v4 - with: - # test-reports has been used, it can be deleted - name: test-reports-* - - clean-after-cancelled: - name: "Clean test reports [CANCELLED]" - if: ${{ cancelled() }} - runs-on: [self-hosted, linux, nixos] - needs: [run-testcases] - steps: - - uses: geekyeggo/delete-artifact@v4 - with: - name: test-reports-* diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..c85fae41e --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,33 @@ +name: Test Report +on: [pull_request] +env: + USER: runner + +# Cancel the current workflow when new commit pushed +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + always-success: + name: "I will always success" + runs-on: [self-hosted, linux, nixos] + steps: + - name: "Success" + run: echo "FOO BAR BAZ" + + get-report: + name: "Getting report" + if: ${{ success() }} + runs-on: [self-hosted, linux, nixos] + needs: [always-success] + steps: + - name: "Fetch report" + run: | + nix run nixpkgs#curl -- -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${{ secrets.T1_INHOUSE_PAT }}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "${{ secrets.T1_INHOUSE_URL }}" \ + -d '{"event_type":"ci_success","client_payload":{"commit_sha": "${{ github.event.pull_request.head.sha }}","pr_id": "${{ github.event.pull_request.number }}" }}'