main, travis: add qemu to run tests in

This makes sure we'll catch bugs that occur only on ARM hardware.
Этот коммит содержится в:
Ayke van Laethem 2018-10-08 20:24:07 +02:00
родитель 3289dd7134
коммит aee9eb413e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: E97FF5335DFDFDED
2 изменённых файлов: 32 добавлений и 5 удалений

Просмотреть файл

@ -8,7 +8,7 @@ before_install:
- echo "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-7 main" | sudo tee -a /etc/apt/sources.list
- echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu trusty main" | sudo tee -a /etc/apt/sources.list
- sudo apt-get update -qq
- sudo apt-get install llvm-7-dev clang-7 gcc-arm-none-eabi --allow-unauthenticated -y
- sudo apt-get install llvm-7-dev clang-7 gcc-arm-none-eabi qemu-system-arm --allow-unauthenticated -y
- sudo ln -s /usr/bin/clang-7 /usr/local/bin/cc # work around missing -no-pie in old GCC version
install:

Просмотреть файл

@ -31,14 +31,22 @@ func TestCompiler(t *testing.T) {
}
defer os.RemoveAll(tmpdir)
t.Log("running tests on the host...")
for _, path := range matches {
t.Run(path, func(t *testing.T) {
runTest(path, tmpdir, t)
runTest(path, tmpdir, "", t)
})
}
t.Log("running tests on the qemu target...")
for _, path := range matches {
t.Run(path, func(t *testing.T) {
runTest(path, tmpdir, "qemu", t)
})
}
}
func runTest(path, tmpdir string, t *testing.T) {
func runTest(path, tmpdir string, target string, t *testing.T) {
// Get the expected output for this test.
txtpath := path[:len(path)-3] + ".txt"
f, err := os.Open(txtpath)
@ -52,7 +60,7 @@ func runTest(path, tmpdir string, t *testing.T) {
// Build the test binary.
binary := filepath.Join(tmpdir, "test")
err = Build(path, binary, "", false, false, false, "")
err = Build(path, binary, target, false, false, false, "")
if err != nil {
t.Log("failed to build:", err)
t.Fail()
@ -60,10 +68,29 @@ func runTest(path, tmpdir string, t *testing.T) {
}
// Run the test.
cmd := exec.Command(binary)
var cmd *exec.Cmd
if target == "" {
cmd = exec.Command(binary)
} else {
spec, err := LoadTarget(target)
if err != nil {
t.Fatal("failed to load target spec:", err)
}
if len(spec.Emulator) == 0 {
t.Fatal("no emulator available for target:", target)
}
args := append(spec.Emulator[1:], binary)
cmd = exec.Command(spec.Emulator[0], args...)
}
stdout := &bytes.Buffer{}
cmd.Stdout = stdout
if target != "" {
cmd.Stderr = os.Stderr
}
err = cmd.Run()
if _, ok := err.(*exec.ExitError); ok && target != "" {
err = nil // workaround for QEMU
}
// putchar() prints CRLF, convert it to LF.
actual := bytes.Replace(stdout.Bytes(), []byte{'\r', '\n'}, []byte{'\n'}, -1)