Skip to content

Commit

Permalink
[ci] save offline check result in nix
Browse files Browse the repository at this point in the history
Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin committed Jul 18, 2024
1 parent ec9d62b commit 8d81c6d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ jobs:
ref: ${{ github.head_ref }}
- name: "Print step summary"
run: |
nix run ".#ci-helper" -- postCI --cycle-update-file-path ./cycle-update.md
nix run ".#ci-helper" -- postCI --failed-tests-file-path ./failed-tests.md --cycle-update-file-path ./cycle-update.md
cat ./failed-tests.md >> $GITHUB_STEP_SUMMARY
cat ./cycle-update.md >> $GITHUB_STEP_SUMMARY
- name: "Commit cycle updates"
run: |
Expand Down
49 changes: 29 additions & 20 deletions script/ci/src/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ object Main:

val testResultPath =
try
os.Path(nixResolvePath(s".#t1.$config.cases.$caseName.emu-result"))
os.Path(
nixResolvePath(
s".#t1.$config.cases.$caseName.emu-result.with-offline"
)
)
catch
case _ =>
Logger.error(s"Emulation for config $config, case $caseName fail")
Expand All @@ -179,24 +183,10 @@ object Main:
Logger.fatal("Got error from emulation, exiting CI")

Logger.info("Checking RTL event with offline difftest")
val handle = os
.proc(
"nix",
"run",
".#t1-helper",
"--",
"difftest",
"--config",
config,
"--case-attr",
caseName,
"--log-level",
"ERROR"
)
.call(stdout = os.Inherit, stderr = os.Inherit, check = false)
val testSuccess = handle.exitCode == 0
val testSuccess =
os.read(testResultPath / "offline-check-status").trim() == "0"
if !testSuccess then
Logger.error(s"$caseName run failed")
Logger.error(s"Offline check for $caseName ($config) failed")
allFailedTest :+ s"t1.$config.cases.$caseName"
else allFailedTest
end findFailedTests
Expand Down Expand Up @@ -252,11 +242,21 @@ object Main:
// * collect and report cycle update
@main
def postCI(
@arg(
name = "failed-tests-file-path",
doc = "specify the failed tests markdown file output path"
) failedTestsFilePath: String,
@arg(
name = "cycle-update-file-path",
doc = "specify the cycle update markdown file output path"
) cycleUpdateFilePath: String
) =
val failedTestsFile = os.Path(failedTestsFilePath, os.pwd)
os.write.over(failedTestsFile, "## Failed Tests\n")

val cycleUpdateRecordFile = os.Path(cycleUpdateFilePath, os.pwd)
os.write.over(cycleUpdateRecordFile, "## Cycle Update\n")

os.walk(os.pwd / ".github" / "cases")
.filter(_.last == "default.json")
.foreach: file =>
Expand All @@ -267,9 +267,18 @@ object Main:
val emuResultPath =
os.Path(nixResolvePath(s".#t1.$config.cases._allEmuResult"))

Logger.info("Collecting failed tests")
os.walk(emuResultPath)
.filter(path => path.last == "offline-check-status")
.filter(path => os.read(path).trim() != "0")
.map(path => {
val caseName = path.segments.toSeq.reverse.drop(1).head
val journal = os.read(path / os.up / "offline-check-journal")
os.write.append(failedTestsFile, s"* ${config} - ${caseName}\n")
os.write.append(failedTestsFile, s"```text\n${journal}\n```\n")
})

Logger.info("Collecting cycle update info")
val cycleUpdateRecordFile = os.Path(cycleUpdateFilePath, os.pwd)
os.write.over(cycleUpdateRecordFile, "## Cycle Update\n")
val perfCycleRegex = raw"total_cycles:\s(\d+)".r
val allCycleUpdates = os
.walk(emuResultPath)
Expand Down
4 changes: 3 additions & 1 deletion tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ let
(caseDrv: ''
_caseOutDir=$out/${caseDrv.pname}
mkdir -p "$_caseOutDir"
cp ${caseDrv.emu-result}/perf.txt "$_caseOutDir"/
cp ${caseDrv.emu-result.with-offline}/perf.txt "$_caseOutDir"/
cp ${caseDrv.emu-result.with-offline}/offline-check-status "$_caseOutDir"/
cp ${caseDrv.emu-result.with-offline}/offline-check-journal "$_caseOutDir"/
'')
allCases);
in
Expand Down
12 changes: 12 additions & 0 deletions tests/make-emu-result.nix
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ let
fi
'';
});

passthru.with-offline = self.overrideAttrs (old: {
preInstall = ''
set +e
"${difftest}/bin/offline" \
--elf-file ${testCase}/bin/${testCase.pname}.elf \
--log-file $out/rtl-event.jsonl \
--log-level ERROR 2>&1 > $out/offline-check-journal
printf "$?" > $out/offline-check-status
set -e
'';
});
};
in
self

0 comments on commit 8d81c6d

Please sign in to comment.