This repository has been archived by the owner on Jan 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestsuite.go
99 lines (86 loc) · 3.24 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
87
88
89
90
91
92
93
94
95
96
97
98
99
// 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 (
"bytes"
"fmt"
"io"
"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
}{
{"goreng/xgo:base", "base"},
// {"goreng/xgo:1.11.9", "go-1.11.9"},
// {"goreng/xgo:1.11.x", "go-1.11.x"},
// {"goreng/xgo:1.12.0", "go-1.12.0"},
// {"goreng/xgo:1.12.1", "go-1.12.1"},
// {"goreng/xgo:1.12.2", "go-1.12.2"},
// {"goreng/xgo:1.12.3", "go-1.12.3"},
{"goreng/xgo:1.12.4", "go-1.12.4"},
{"goreng/xgo:1.12.x", "go-1.12.x"},
{"goreng/xgo:latest", "go-latest"},
}
// 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/gythialy/xgo/tests/embedded_c", []string{"--dest", "build", "--targets", "windows/*,darwin/*,linux/*", "--pkg", "tests/embedded_c/main.go", "."}},
{"github.com/gythialy/xgo/tests/embedded_cpp", []string{"--dest", "build", "--targets", "windows/*,darwin/*,linux/*", "--pkg", "tests/embedded_cpp/main.go", "."}},
// {"github.com/gythialy/xgo/tests/mobilepkg", []string{"--targets", "android/*,ios/*",
// "-out", "mobilepkg", "--ldflags", "-w -s -X mobilepkg.Flag=success2"}},
// 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)...)...)
var stdBuffer bytes.Buffer
mw := io.MultiWriter(os.Stdout, &stdBuffer)
cmd.Stdout = mw
cmd.Stderr = mw
if err := cmd.Run(); err != nil {
log.Fatalf("Test #%d: cross compilation failed: %v", i, err)
fmt.Println(stdBuffer.String())
}
}
}