Skip to content

RISC-V tests in QEMU #765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ commands:
llvm-build
- run:
name: "Test TinyGo"
command: make test
command: |
make gen-device-sifive # needed for testing
make test
- run:
name: "Build TinyGo release"
command: |
Expand Down
1 change: 1 addition & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
script: |
export PATH="/c/Go1.13/bin:$PATH:./llvm-build/bin:/c/Program Files/qemu"
unset GOROOT
make gen-device-sifive # needed for testing
make test
- task: Bash@3
displayName: Build TinyGo release tarball
Expand Down
16 changes: 15 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ func TestCompiler(t *testing.T) {
runPlatTests("cortex-m-qemu", matches, t)
})

if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
// Note: running only on Windows and macOS because Linux usually has an
// outdated QEMU version that doesn't support RISC-V yet.
t.Run("EmulatedHiFive1", func(t *testing.T) {
runPlatTests("hifive1-qemu", matches, t)
})
}

if runtime.GOOS == "linux" {
t.Run("ARMLinux", func(t *testing.T) {
runPlatTests("arm--linux-gnueabihf", matches, t)
Expand Down Expand Up @@ -84,6 +92,8 @@ func runPlatTests(target string, matches []string, t *testing.T) {
// run all tests on host
case target == "cortex-m-qemu":
// all tests are supported
case target == "hifive1-qemu":
// all tests are supported
default:
// cross-compilation of cgo is not yet supported
if path == filepath.Join("testdata", "cgo")+string(filepath.Separator) {
Expand Down Expand Up @@ -204,7 +214,11 @@ func runTest(path, target string, t *testing.T) {
}
close(runComplete)

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

Expand Down
10 changes: 10 additions & 0 deletions src/runtime/runtime_fe310_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package runtime

import (
"device/riscv"
"runtime/volatile"
"unsafe"
)
Expand All @@ -17,4 +18,13 @@ var timestamp timeUnit
func abort() {
// Signal a successful exit.
testExit.Set(0x5555)

// Note: the SiFive test finisher does not seem to be implemented in QEMU
// 4.2 (but is included in the SiFive build of QEMU). And while the above
// write somehow results in exiting the process on Windows, that's not the
// case on macOS. Therefore, make sure to halt the process with an endless
// loop.
for {
riscv.Asm("wfi")
}
}
4 changes: 3 additions & 1 deletion targets/riscv.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"goos": "linux",
"goarch": "arm",
"build-tags": ["tinygo.riscv", "baremetal", "linux", "arm"],
"compiler": "clang",
"gc": "conservative",
"compiler": "clang",
"linker": "ld.lld",
Expand All @@ -13,7 +14,8 @@
"-mabi=ilp32",
"-Os",
"-Werror",
"-nostdinc",
"-nostdlibinc",
"-Wno-macro-redefined",
"-fno-exceptions", "-fno-unwind-tables",
"-ffunction-sections", "-fdata-sections"
],
Expand Down