main, travis: add qemu to run tests in
This makes sure we'll catch bugs that occur only on ARM hardware.
Этот коммит содержится в:
родитель
3289dd7134
коммит
aee9eb413e
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://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
|
- 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 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
|
- sudo ln -s /usr/bin/clang-7 /usr/local/bin/cc # work around missing -no-pie in old GCC version
|
||||||
|
|
||||||
install:
|
install:
|
||||||
|
|
35
main_test.go
35
main_test.go
|
@ -31,14 +31,22 @@ func TestCompiler(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
|
t.Log("running tests on the host...")
|
||||||
for _, path := range matches {
|
for _, path := range matches {
|
||||||
t.Run(path, func(t *testing.T) {
|
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.
|
// Get the expected output for this test.
|
||||||
txtpath := path[:len(path)-3] + ".txt"
|
txtpath := path[:len(path)-3] + ".txt"
|
||||||
f, err := os.Open(txtpath)
|
f, err := os.Open(txtpath)
|
||||||
|
@ -52,7 +60,7 @@ func runTest(path, tmpdir string, t *testing.T) {
|
||||||
|
|
||||||
// Build the test binary.
|
// Build the test binary.
|
||||||
binary := filepath.Join(tmpdir, "test")
|
binary := filepath.Join(tmpdir, "test")
|
||||||
err = Build(path, binary, "", false, false, false, "")
|
err = Build(path, binary, target, false, false, false, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Log("failed to build:", err)
|
t.Log("failed to build:", err)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
@ -60,10 +68,29 @@ func runTest(path, tmpdir string, t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the test.
|
// 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{}
|
stdout := &bytes.Buffer{}
|
||||||
cmd.Stdout = stdout
|
cmd.Stdout = stdout
|
||||||
|
if target != "" {
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
}
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
|
if _, ok := err.(*exec.ExitError); ok && target != "" {
|
||||||
|
err = nil // workaround for QEMU
|
||||||
|
}
|
||||||
|
|
||||||
// putchar() prints CRLF, convert it to LF.
|
// putchar() prints CRLF, convert it to LF.
|
||||||
actual := bytes.Replace(stdout.Bytes(), []byte{'\r', '\n'}, []byte{'\n'}, -1)
|
actual := bytes.Replace(stdout.Bytes(), []byte{'\r', '\n'}, []byte{'\n'}, -1)
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче