From e33cbe524ac06fd43831bb456c828405e871c841 Mon Sep 17 00:00:00 2001 From: Avimitin Date: Tue, 3 Sep 2024 13:45:23 +0800 Subject: [PATCH] [ci] add cycle update support Signed-off-by: Avimitin --- .github/workflows/t1rocket.yml | 15 +++++ .github/workflows/vcs.yml | 22 ++++++- .github/workflows/verilator.yml | 15 +++++ nix/t1/default.nix | 2 +- nix/t1/{t1rocket/default.nix => t1rocket.nix} | 16 ++--- nix/t1/t1rocket/verilated-c-lib.nix | 62 ------------------- script/ci/src/Main.scala | 21 +++---- script/emu/src/Main.scala | 5 +- 8 files changed, 70 insertions(+), 88 deletions(-) rename nix/t1/{t1rocket/default.nix => t1rocket.nix} (88%) delete mode 100644 nix/t1/t1rocket/verilated-c-lib.nix diff --git a/.github/workflows/t1rocket.yml b/.github/workflows/t1rocket.yml index d00d04f1f..653853901 100644 --- a/.github/workflows/t1rocket.yml +++ b/.github/workflows/t1rocket.yml @@ -106,4 +106,19 @@ jobs: --cycle-update-file-path ./cycle-update.md \ --emu-type vcs cat ./failed-tests.md >> $GITHUB_STEP_SUMMARY + echo >> $GITHUB_STEP_SUMMARY cat ./cycle-update.md >> $GITHUB_STEP_SUMMARY + - name: "Commit cycle updates" + run: | + git config user.name github-actions + git config user.email github-actions@github.com + changed_cases=$(git diff --name-only '.github/**/default.json') + + if [ -n "$changed_cases" ]; then + echo "changed cases: $changed_cases" + git add '.github/**/default.json' + git commit -m "[ci] update test case cycle data" + git push origin ${{ github.head_ref }} + else + echo "No cycle change detect" + fi diff --git a/.github/workflows/vcs.yml b/.github/workflows/vcs.yml index 75751d78d..47de5fc28 100644 --- a/.github/workflows/vcs.yml +++ b/.github/workflows/vcs.yml @@ -100,6 +100,24 @@ jobs: ref: ${{ github.head_ref }} - name: "Print step summary" run: | - nix run ".#ci-helper" -- postCI --failed-tests-file-path ./failed-tests.md --emu-type vcs --cycle-update-file-path ./cycle-update.md - cat ./failed-tests.md >> $GITHUB_STEP_SUMMARY + nix run ".#ci-helper" -- postCI \ + --cycle-update-file-path ./cycle-update.md \ + --failed-tests-file-path ./failed-tests.md \ + --emu-type vcs cat ./cycle-update.md >> $GITHUB_STEP_SUMMARY + echo >> $GITHUB_STEP_SUMMARY + cat ./failed-tests.md >> $GITHUB_STEP_SUMMARY + - name: "Commit cycle updates" + run: | + git config user.name github-actions + git config user.email github-actions@github.com + changed_cases=$(git diff --name-only '.github/**/default.json') + + if [ -n "$changed_cases" ]; then + echo "changed cases: $changed_cases" + git add '.github/**/default.json' + git commit -m "[ci] update test case cycle data" + git push origin ${{ github.head_ref }} + else + echo "No cycle change detect" + fi diff --git a/.github/workflows/verilator.yml b/.github/workflows/verilator.yml index 6785f7009..cfe7eb774 100644 --- a/.github/workflows/verilator.yml +++ b/.github/workflows/verilator.yml @@ -108,4 +108,19 @@ jobs: --failed-tests-file-path ./failed-tests.md \ --cycle-update-file-path ./cycle-update.md cat ./failed-tests.md >> $GITHUB_STEP_SUMMARY + echo >> $GITHUB_STEP_SUMMARY cat ./cycle-update.md >> $GITHUB_STEP_SUMMARY + - name: "Commit cycle updates" + run: | + git config user.name github-actions + git config user.email github-actions@github.com + changed_cases=$(git diff --name-only '.github/**/default.json') + + if [ -n "$changed_cases" ]; then + echo "changed cases: $changed_cases" + git add '.github/**/default.json' + git commit -m "[ci] update test case cycle data" + git push origin ${{ github.head_ref }} + else + echo "No cycle change detect" + fi diff --git a/nix/t1/default.nix b/nix/t1/default.nix index cc03bccc2..01c91d11c 100644 --- a/nix/t1/default.nix +++ b/nix/t1/default.nix @@ -87,7 +87,7 @@ lib.makeScope newScope # Grouped emulator packages # --------------------------------------------------------------------------------- # Nix specification for t1rocket (with rocket-chip as Scalar core) emulator - t1rocket = t1Scope.callPackage ./t1rocket { }; + t1rocket = t1Scope.callPackage ./t1rocket.nix { }; # Nix specification for rocket (rocket-chip only) emulator rocketv = t1Scope.callPackage ../../rocketemu { }; diff --git a/nix/t1/t1rocket/default.nix b/nix/t1/t1rocket.nix similarity index 88% rename from nix/t1/t1rocket/default.nix rename to nix/t1/t1rocket.nix index 15c2a82d9..9a35a7bb7 100644 --- a/nix/t1/t1rocket/default.nix +++ b/nix/t1/t1rocket.nix @@ -11,15 +11,15 @@ { ip = lib.makeScope newScope (scope: { - cases = scope.callPackage ../../../tests { }; - run = scope.callPackage ../run { configName = "t1rocket"; }; + cases = scope.callPackage ../../tests { }; + run = scope.callPackage ./run { configName = "t1rocket"; }; mlirbc = chisel-to-mlirbc { outputName = "t1rocketemu-parsed.mlirbc"; elaboratorArgs = [ "t1rocketemu" "--t1rocket-config" - "${../../../t1rocketemu/configs/default.json}" + "${../../t1rocketemu/configs/default.json}" ]; }; @@ -41,7 +41,7 @@ ]; }; - makeDPI = scope.callPackage ../../../difftest { }; + makeDPI = scope.callPackage ../../difftest { }; verilator-dpi-lib = scope.makeDPI { outputName = "t1rocket-verilator-dpi-lib"; buildType = "t1rocket"; @@ -72,7 +72,7 @@ ]; }; - offline-checker = scope.callPackage ../../../t1rocketemu/offline { }; + offline-checker = scope.callPackage ../../t1rocketemu/offline { }; vcs-dpi-lib = scope.makeDPI { outputName = "t1rocket-vcs-dpi-lib"; @@ -87,12 +87,12 @@ }; vcs-emu = sv-to-vcs-simulator { - mainProgram = "t1-vcs-simulator"; + mainProgram = "t1rocket-vcs-simulator"; rtl = scope.rtl; vcsLinkLibs = [ "${scope.vcs-dpi-lib}/lib/libdpi_t1rocket.a" ]; }; vcs-emu-trace = sv-to-vcs-simulator { - mainProgram = "t1-vcs-trace-simulator"; + mainProgram = "t1rocket-vcs-trace-simulator"; rtl = scope.rtl; enableTrace = true; vcsLinkLibs = [ "${scope.vcs-dpi-lib-trace}/lib/libdpi_t1rocket.a" ]; @@ -112,7 +112,7 @@ throw "Invalid vlen extension `${ext}` specify, expect Zvl{N}b"; # TODO: designConfig should be read from OM - designConfig = with builtins; (fromJSON (readFile ../../../t1rocketemu/configs/default.json)).parameter; + designConfig = with builtins; (fromJSON (readFile ../../t1rocketemu/configs/default.json)).parameter; # TODO: We should have a type define, to keep t1 and t1rocket feeds same `rtlDesignMetadata` data structure. rtlDesignMetadata = rec { diff --git a/nix/t1/t1rocket/verilated-c-lib.nix b/nix/t1/t1rocket/verilated-c-lib.nix deleted file mode 100644 index 97d1310fd..000000000 --- a/nix/t1/t1rocket/verilated-c-lib.nix +++ /dev/null @@ -1,62 +0,0 @@ -{ lib -, stdenv -, rtl -, verilator -, enableTrace ? true -, zlib -}: - -stdenv.mkDerivation { - name = "t1rocket-verilated"; - - src = rtl; - - nativeBuildInputs = [ verilator ]; - - propagatedBuildInputs = [ zlib ]; - - buildPhase = '' - runHook preBuild - - echo "[nix] running verilator" - verilator \ - ${lib.optionalString enableTrace "--trace-fst"} \ - --cc \ - --timing \ - --threads 8 \ - --threads-max-mtasks 8000 \ - -O1 \ - -F filelist.f \ - --top TestBench - - echo "[nix] building verilated C lib" - - # backup srcs - mkdir -p $out/share - cp -r obj_dir $out/share/verilated_src - - rm $out/share/verilated_src/*.dat - - # We can't use -C here because VTestBench.mk is generated with relative path - cd obj_dir - make -j "$NIX_BUILD_CORES" -f VTestBench.mk libVTestBench - - runHook postBuild - ''; - - hardeningDisable = [ "fortify" ]; - - passthru = { - inherit enableTrace; - }; - - installPhase = '' - runHook preInstall - - mkdir -p $out/include $out/lib - cp *.h $out/include - cp *.a $out/lib - - runHook postInstall - ''; -} diff --git a/script/ci/src/Main.scala b/script/ci/src/Main.scala index 9a50df237..127c6d497 100644 --- a/script/ci/src/Main.scala +++ b/script/ci/src/Main.scala @@ -213,7 +213,7 @@ object Main: @arg( name = "cycle-update-file-path", doc = "specify the cycle update markdown file output path" - ) cycleUpdateFilePath: Option[String], + ) cycleUpdateFilePath: String, @arg( name = "emu-type", doc = "Specify emulation type" @@ -226,11 +226,10 @@ object Main: val failedTestsFile = os.Path(failedTestsFilePath, os.pwd) os.write.over(failedTestsFile, "## Failed Tests\n") - if cycleUpdateFilePath.nonEmpty then - os.write.over( - os.Path(cycleUpdateFilePath.get, os.pwd), - "## Cycle Update\n" - ) + os.write.over( + os.Path(cycleUpdateFilePath, os.pwd), + "## Cycle Update\n" + ) os.walk(os.pwd / ".github" / caseDir) .filter(_.last == "default.json") @@ -261,15 +260,11 @@ object Main: if cycleUpdateFilePath.nonEmpty then Logger.info("Collecting cycle update info") - val perfCycleRegex = raw"total_cycles:\s(\d+)".r val allCycleUpdates = os .walk(emuResultPath) - .filter(path => path.last == "perf.txt") + .filter(path => path.last == "perf.json") .map(path => { - val cycle = os.read.lines(path).head match - case perfCycleRegex(cycle) => cycle.toInt - case _ => - throw new Exception("perf.txt file is not format as expected") + val cycle = ujson.read(os.read(path)).obj("total_cycles").num.toInt val caseName = path.segments.toSeq.reverse.drop(1).head (caseName, cycle, cycleRecord.obj(caseName).num.toInt) }) @@ -282,7 +277,7 @@ object Main: else s"* 🐢 $caseName($config): $oldCycle -> $newCycle" os.write.append( - os.Path(cycleUpdateFilePath.get, os.pwd), + os.Path(cycleUpdateFilePath, os.pwd), allCycleUpdates.mkString("\n") + "\n" ) diff --git a/script/emu/src/Main.scala b/script/emu/src/Main.scala index 1f15325da..0836dd71b 100644 --- a/script/emu/src/Main.scala +++ b/script/emu/src/Main.scala @@ -229,7 +229,7 @@ object Main: zstdProc.join(-1) driverProc.join(-1) if zstdProc.exitCode() != 0 then Logger.fatal("fail to compress data") - if driverProc.exitCode() != 0 then Logger.fatal("fail to compress data") + if driverProc.exitCode() != 0 then Logger.fatal("online driver run failed") val statePath = outputPath / "driver-state.json" os.write( @@ -322,7 +322,8 @@ object Main: ) Logger.info(s"Running offline checker: ${driverArgs.mkString(" ")}") - os.proc(driverArgs).call(stdout = os.Inherit, stderr = os.Inherit) + val ret = os.proc(driverArgs).call(stdout = os.Inherit, stderr = os.Inherit, check = false) + if (ret.exitCode != 0) then Logger.fatal("offline checker run failed") end offline def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args)