forked from karalabe/xgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testsuite.go
86 lines (73 loc) · 2.6 KB
/
testsuite.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Go CGO cross compiler
// Copyright (c) 2016 Péter Szilágyi. All rights reserved.
//
// Released under the MIT license.
// This is a manual test suite to run the cross compiler against various known
// projects, codebases and repositories to ensure at least a baseline guarantee
// that things work as they supposed to.
//
// Run as: go run testsuite.go
// +build ignore
package main
import (
"log"
"os"
"os/exec"
"path/filepath"
)
// layers defines all the docker layers needed for the final xgo image. The last
// one will be used to run the test suite against.
var layers = []struct {
tag string
dir string
}{
{"karalabe/xgo-base", "base"},
{"karalabe/xgo-1.6.2", "go-1.6.2"},
{"karalabe/xgo-1.6.x", "go-1.6.x"},
{"karalabe/xgo-latest", "go-latest"},
//{"karalabe/xgo-latest-ios", "go-latest-ios"}, // Non-public layer (XCode licensing)
}
// tests defaines all the input test cases and associated arguments the cross
// compiler should be ran for and with which arguments.
var tests = []struct {
path string
args []string
}{
// Tiny test cases to smoke test cross compilations
{"github.com/karalabe/xgo/tests/embedded_c", nil},
{"github.com/karalabe/xgo/tests/embedded_cpp", nil},
// Baseline projects to ensure minimal requirements
//{"github.com/project-iris/iris", nil}, // Deps failed, disable
{"github.com/ethereum/go-ethereum/cmd/geth", []string{"--branch", "develop"}},
// Third party projects using xgo, smoke test that they don't break
{"github.com/rwcarlsen/cyan/cmd/cyan", nil},
{"github.com/cockroachdb/cockroach", []string{"--targets", "darwin-10.11/amd64"}},
}
func main() {
// Retrieve the current working directory to locate the dockerfiles
pwd, err := os.Getwd()
if err != nil {
log.Fatalf("Failed to retrieve local working directory: %v", err)
}
if _, err := os.Stat(filepath.Join(pwd, "docker", "base")); err != nil {
log.Fatalf("Failed to locate docker image: %v", err)
}
// Assemble the multi-layered xgo docker image
for _, layer := range layers {
cmd := exec.Command("docker", "build", "--tag", layer.tag, filepath.Join(pwd, "docker", layer.dir))
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
log.Fatalf("Failed to build xgo layer: %v", err)
}
}
// Iterate over each of the test cases and run them
for i, test := range tests {
cmd := exec.Command("docker", append([]string{"run", "--entrypoint", "xgo", layers[len(layers)-1].tag, "-v"}, append(test.args, test.path)...)...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
log.Fatalf("Test #%d: cross compilation failed: %v", i, err)
}
}
}