Skip to content

Commit 73bbf63

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 4e3b788 commit 73bbf63

4 files changed

Lines changed: 30 additions & 2 deletions

File tree

‎.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: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ func TestCompiler(t *testing.T) {
5555
runPlatTests("cortex-m-qemu", matches, t)
5656
})
5757

58+
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
59+
// Note: running only on Windows and macOS because Linux usually has an
60+
// outdated QEMU version that doesn't support RISC-V yet.
61+
t.Run("EmulatedHiFive1", func(t *testing.T) {
62+
runPlatTests("hifive1-qemu", matches, t)
63+
})
64+
}
65+
5866
if runtime.GOOS == "linux" {
5967
t.Run("ARMLinux", func(t *testing.T) {
6068
runPlatTests("arm--linux-gnueabihf", matches, t)
@@ -83,6 +91,11 @@ func runPlatTests(target string, matches []string, t *testing.T) {
8391
// run all tests on host
8492
case target == "cortex-m-qemu":
8593
// all tests are supported
94+
case target == "hifive1-qemu":
95+
if path == filepath.Join("testdata", "cgo")+string(filepath.Separator) {
96+
// CGo doesn't work yet for some reason.
97+
continue
98+
}
8699
default:
87100
// cross-compilation of cgo is not yet supported
88101
if path == filepath.Join("testdata", "cgo")+string(filepath.Separator) {
@@ -203,7 +216,11 @@ func runTest(path, target string, t *testing.T) {
203216
}
204217
close(runComplete)
205218

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

‎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)