Skip to content

Commit c2d5b02

Browse files
committed
riscv: run tests in QEMU
These tests should make sure that things that work now won't break in the future.
1 parent e40559e commit c2d5b02

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

.circleci/config.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ commands:
246246
llvm-build
247247
- run:
248248
name: "Test TinyGo"
249-
command: make test
249+
command: |
250+
make gen-device-sifive # needed for testing
251+
make test
250252
- run:
251253
name: "Build TinyGo release"
252254
command: |

azure-pipelines.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
script: |
5353
export PATH="/c/Go1.13/bin:$PATH:./llvm-build/bin:/c/Program Files/qemu"
5454
unset GOROOT
55+
make gen-device-sifive # needed for testing
5556
make test
5657
- task: Bash@3
5758
displayName: Build TinyGo release tarball

main_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ func TestCompiler(t *testing.T) {
5555
runPlatTests("cortex-m-qemu", matches, t)
5656
})
5757

58+
if runtime.GOOS != "linux" {
59+
t.Run("EmulatedHiFive1", func(t *testing.T) {
60+
runPlatTests("hifive1-qemu", matches, t)
61+
})
62+
}
63+
5864
if runtime.GOOS == "linux" {
5965
t.Run("ARMLinux", func(t *testing.T) {
6066
runPlatTests("arm--linux-gnueabihf", matches, t)
@@ -83,6 +89,11 @@ func runPlatTests(target string, matches []string, t *testing.T) {
8389
// run all tests on host
8490
case target == "cortex-m-qemu":
8591
// all tests are supported
92+
case target == "hifive1-qemu":
93+
if path == filepath.Join("testdata", "cgo")+string(filepath.Separator) {
94+
// CGo doesn't work yet for some reason.
95+
continue
96+
}
8697
default:
8798
// cross-compilation of cgo is not yet supported
8899
if path == filepath.Join("testdata", "cgo")+string(filepath.Separator) {
@@ -203,7 +214,11 @@ func runTest(path, target string, t *testing.T) {
203214
}
204215
close(runComplete)
205216

206-
if ranTooLong {
217+
if ranTooLong && target != "hifive1-qemu" {
218+
// Note: the hifive1-qemu exception is here because QEMU does
219+
// not yet include the SiFive test finisher used to exit tests.
220+
// https://github.com/sifive/riscv-qemu/commit/0eec372a36b7237caf16ec7c7646a202faba5fdb
221+
// It's a crude hack, but it makes RISC-V testable.
207222
stdout.WriteString("--- test ran too long, terminating...\n")
208223
}
209224

src/runtime/runtime_fe310_qemu.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ var timestamp timeUnit
1515
func abort() {
1616
// Signal a successful exit.
1717
testExit.Set(0x5555)
18+
19+
// Note: the SiFive test finisher does not seem to be implemented in QEMU
20+
// 4.2 (but is included in the SiFive build of QEMU). And while the above
21+
// write somehow results in exiting the process on Windows, that's not the
22+
// case on macOS. Therefore, make sure to halt the process with an endless
23+
// loop.
24+
for {
25+
}
1826
}
1927

2028
func ticks() timeUnit {

0 commit comments

Comments
 (0)