Skip to content

Commit 50f4bba

Browse files
authored
Run ISA tests in CI (riscv#134)
* test: Ignore generated XML output * run_tests: Build RVFI emulators too Can't run tests with them though as they're built for direct instruction injection (RVFI-DII) via an instruction stream over a network socket, not fetching instructions from memory, so this remains just a build test. * run_tests/run_fp_tests: Print summary and give meaningful exit code * run_tests/run_fp_tests: Include tests and failures in top-level XML entity * run_tests/run_fp_tests: Use failure not error for XML output The former is the standard tag for normal test failures, the latter is for catastrophic things like test harness errors. * Run ISA tests in CI
1 parent 1e3906f commit 50f4bba

File tree

5 files changed

+130
-28
lines changed

5 files changed

+130
-28
lines changed

.github/workflows/compile.yml

+18-8
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ jobs:
66
build:
77
runs-on: [ubuntu-18.04]
88
steps:
9-
- name: Install opam2
10-
run: |
11-
sudo add-apt-repository -y ppa:avsm/ppa
12-
sudo apt install -y opam zlib1g-dev pkg-config libgmp-dev z3
9+
- name: Add opam2 PPA
10+
run: sudo add-apt-repository -y ppa:avsm/ppa
11+
- name: Install packages
12+
run: sudo apt install -y opam zlib1g-dev pkg-config libgmp-dev z3 device-tree-compiler
1313
- name: Init opam
1414
run: opam init --disable-sandboxing -y
1515
- name: Install sail
@@ -18,7 +18,17 @@ jobs:
1818
uses: actions/checkout@HEAD
1919
with:
2020
submodules: true
21-
- name: Build RV32 simulators
22-
run: eval $(opam env) && make ARCH=RV32 -j2 csim rvfi osim
23-
- name: Build RV64 simulators
24-
run: eval $(opam env) && make ARCH=RV64 -j2 csim rvfi osim
21+
- name: Build and test simulators
22+
run: eval $(opam env) && test/run_tests.sh
23+
- name: Upload test results
24+
if: always()
25+
uses: actions/upload-artifact@v2
26+
with:
27+
name: tests.xml
28+
path: test/tests.xml
29+
- name: Upload event payload
30+
if: always()
31+
uses: actions/upload-artifact@v2
32+
with:
33+
name: event.json
34+
path: ${{ github.event_path }}

.github/workflows/test-results.yml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Publish test results
2+
3+
on:
4+
workflow_run:
5+
workflows: ["CI"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
publish-test-results:
11+
runs-on: ubuntu-latest
12+
if: github.event.workflow_run.conclusion != 'skipped'
13+
steps:
14+
- name: Download artifacts
15+
uses: actions/[email protected]
16+
with:
17+
script: |
18+
var fs = require('fs');
19+
var artifacts = await github.actions.listWorkflowRunArtifacts({
20+
owner: context.repo.owner,
21+
repo: context.repo.repo,
22+
run_id: ${{github.event.workflow_run.id }},
23+
});
24+
var matchArtifacts = artifacts.data.artifacts.filter((artifact) => {
25+
return artifact.name == 'tests.xml' || artifact.name == 'event.json'
26+
});
27+
var count = matchArtifacts.length;
28+
for (var i = 0; i < count; i++) {
29+
var matchArtifact = matchArtifacts[i];
30+
var download = await github.actions.downloadArtifact({
31+
owner: context.repo.owner,
32+
repo: context.repo.repo,
33+
artifact_id: matchArtifact.id,
34+
archive_format: 'zip',
35+
});
36+
var name = matchArtifact.name;
37+
var dest = name + '.zip'
38+
fs.writeFileSync('${{github.workspace}}/' + dest, Buffer.from(download.data));
39+
console.log("Downloaded", name, "as", dest);
40+
}
41+
- name: Extract test results
42+
run: unzip tests.xml.zip
43+
- name: Extract event payload
44+
run: unzip event.json.zip
45+
- name: Publish test results
46+
uses: EnricoMi/publish-unit-test-result-action@v1
47+
with:
48+
commit: ${{ github.event.workflow_run.head_sha }}
49+
event_file: event.json
50+
event_name: ${{ github.event.workflow_run.event }}
51+
files: tests.xml

test/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/tests.xml

test/run_fp_tests.sh

+19-10
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,41 @@ rm -f $DIR/tests.xml
1414

1515
pass=0
1616
fail=0
17-
XML=""
17+
all_pass=0
18+
all_fail=0
19+
SUITE_XML=""
20+
SUITES_XML=""
1821

1922
function green {
2023
(( pass += 1 ))
2124
printf "$1: ${GREEN}$2${NC}\n"
22-
XML+=" <testcase name=\"$1\"/>\n"
25+
SUITE_XML+=" <testcase name=\"$1\"/>\n"
2326
}
2427

2528
function yellow {
2629
(( fail += 1 ))
2730
printf "$1: ${YELLOW}$2${NC}\n"
28-
XML+=" <testcase name=\"$1\">\n <error message=\"$2\">$2</error>\n </testcase>\n"
31+
SUITE_XML+=" <testcase name=\"$1\">\n <failure message=\"$2\">$2</failure>\n </testcase>\n"
2932
}
3033

3134
function red {
3235
(( fail += 1 ))
3336
printf "$1: ${RED}$2${NC}\n"
34-
XML+=" <testcase name=\"$1\">\n <error message=\"$2\">$2</error>\n </testcase>\n"
37+
SUITE_XML+=" <testcase name=\"$1\">\n <failure message=\"$2\">$2</failure>\n </testcase>\n"
3538
}
3639

3740
function finish_suite {
3841
printf "$1: Passed ${pass} out of $(( pass + fail ))\n\n"
39-
XML=" <testsuite name=\"$1\" tests=\"$(( pass + fail ))\" failures=\"${fail}\" timestamp=\"$(date)\">\n$XML </testsuite>\n"
40-
printf "$XML" >> $DIR/tests.xml
41-
XML=""
42+
SUITES_XML+=" <testsuite name=\"$1\" tests=\"$(( pass + fail ))\" failures=\"${fail}\" timestamp=\"$(date)\">\n$SUITE_XML </testsuite>\n"
43+
SUITE_XML=""
44+
(( all_pass += pass )) || :
45+
(( all_fail += fail )) || :
4246
pass=0
4347
fail=0
4448
}
4549

4650
SAILLIBDIR="$DIR/../../lib/"
4751

48-
printf "<testsuites>\n" >> $DIR/tests.xml
49-
5052
cd $RISCVDIR
5153

5254
# Do 'make clean' to avoid cross-arch pollution.
@@ -85,4 +87,11 @@ for test in $DIR/riscv-tests/rv32u{f,d}*.elf $DIR/riscv-tests/rv32mi-p-csr.elf;
8587
done
8688
finish_suite "32-bit RISCV C tests"
8789

88-
printf "</testsuites>\n" >> $DIR/tests.xml
90+
printf "Passed ${all_pass} out of $(( all_pass + all_fail ))\n\n"
91+
XML="<testsuites tests=\"$(( all_pass + all_fail ))\" failures=\"${all_fail}\">\n$SUITES_XML</testsuites>\n"
92+
printf "$XML" > $DIR/tests.xml
93+
94+
if [ $all_fail -gt 0 ]
95+
then
96+
exit 1
97+
fi

test/run_tests.sh

+41-10
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,41 @@ rm -f $DIR/tests.xml
1414

1515
pass=0
1616
fail=0
17-
XML=""
17+
all_pass=0
18+
all_fail=0
19+
SUITE_XML=""
20+
SUITES_XML=""
1821

1922
function green {
2023
(( pass += 1 ))
2124
printf "$1: ${GREEN}$2${NC}\n"
22-
XML+=" <testcase name=\"$1\"/>\n"
25+
SUITE_XML+=" <testcase name=\"$1\"/>\n"
2326
}
2427

2528
function yellow {
2629
(( fail += 1 ))
2730
printf "$1: ${YELLOW}$2${NC}\n"
28-
XML+=" <testcase name=\"$1\">\n <error message=\"$2\">$2</error>\n </testcase>\n"
31+
SUITE_XML+=" <testcase name=\"$1\">\n <failure message=\"$2\">$2</failure>\n </testcase>\n"
2932
}
3033

3134
function red {
3235
(( fail += 1 ))
3336
printf "$1: ${RED}$2${NC}\n"
34-
XML+=" <testcase name=\"$1\">\n <error message=\"$2\">$2</error>\n </testcase>\n"
37+
SUITE_XML+=" <testcase name=\"$1\">\n <failure message=\"$2\">$2</failure>\n </testcase>\n"
3538
}
3639

3740
function finish_suite {
3841
printf "$1: Passed ${pass} out of $(( pass + fail ))\n\n"
39-
XML=" <testsuite name=\"$1\" tests=\"$(( pass + fail ))\" failures=\"${fail}\" timestamp=\"$(date)\">\n$XML </testsuite>\n"
40-
printf "$XML" >> $DIR/tests.xml
41-
XML=""
42+
SUITES_XML+=" <testsuite name=\"$1\" tests=\"$(( pass + fail ))\" failures=\"${fail}\" timestamp=\"$(date)\">\n$SUITE_XML </testsuite>\n"
43+
SUITE_XML=""
44+
(( all_pass += pass )) || :
45+
(( all_fail += fail )) || :
4246
pass=0
4347
fail=0
4448
}
4549

4650
SAILLIBDIR="$DIR/../../lib/"
4751

48-
printf "<testsuites>\n" >> $DIR/tests.xml
49-
5052
cd $RISCVDIR
5153

5254
# Do 'make clean' to avoid cross-arch pollution.
@@ -141,4 +143,33 @@ for test in $DIR/riscv-tests/rv64*.elf; do
141143
done
142144
finish_suite "64-bit RISCV C tests"
143145

144-
printf "</testsuites>\n" >> $DIR/tests.xml
146+
# Do 'make clean' to avoid cross-arch pollution.
147+
make clean
148+
149+
if ARCH=RV32 make c_emulator/riscv_rvfi_RV32;
150+
then
151+
green "Building 32-bit RISCV RVFI C emulator" "ok"
152+
else
153+
red "Building 32-bit RISCV RVFI C emulator" "fail"
154+
fi
155+
finish_suite "32-bit RISCV RVFI C tests"
156+
157+
# Do 'make clean' to avoid cross-arch pollution.
158+
make clean
159+
160+
if ARCH=RV64 make c_emulator/riscv_rvfi_RV64;
161+
then
162+
green "Building 64-bit RISCV RVFI C emulator" "ok"
163+
else
164+
red "Building 64-bit RISCV RVFI C emulator" "fail"
165+
fi
166+
finish_suite "64-bit RISCV RVFI C tests"
167+
168+
printf "Passed ${all_pass} out of $(( all_pass + all_fail ))\n\n"
169+
XML="<testsuites tests=\"$(( all_pass + all_fail ))\" failures=\"${all_fail}\">\n$SUITES_XML</testsuites>\n"
170+
printf "$XML" > $DIR/tests.xml
171+
172+
if [ $all_fail -gt 0 ]
173+
then
174+
exit 1
175+
fi

0 commit comments

Comments
 (0)