Fix cross-Linux setup on non-amd64 arches

In that case, an emulator is needed for amd64, and tests should be run
for amd64 as a _cross_ test.
Этот коммит содержится в:
Elliott Sales de Andrade 2022-02-06 23:26:25 -05:00 коммит произвёл Ayke
родитель ac7e370c72
коммит 010cc13e9e
2 изменённых файлов: 35 добавлений и 23 удалений

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

@ -317,11 +317,20 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
if goarch != runtime.GOARCH { if goarch != runtime.GOARCH {
// Some educated guesses as to how to invoke helper programs. // Some educated guesses as to how to invoke helper programs.
spec.GDB = []string{"gdb-multiarch"} spec.GDB = []string{"gdb-multiarch"}
if goarch == "arm" && goos == "linux" { if goos == "linux" {
spec.Emulator = []string{"qemu-arm"} switch goarch {
} case "386":
if goarch == "arm64" && goos == "linux" { // amd64 can _usually_ run 32-bit programs, so skip the emulator in that case.
spec.Emulator = []string{"qemu-aarch64"} if runtime.GOARCH != "amd64" {
spec.Emulator = []string{"qemu-i386"}
}
case "amd64":
spec.Emulator = []string{"qemu-x86_64"}
case "arm":
spec.Emulator = []string{"qemu-arm"}
case "arm64":
spec.Emulator = []string{"qemu-aarch64"}
}
} }
} }
if goos != runtime.GOOS { if goos != runtime.GOOS {

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

@ -31,6 +31,13 @@ const TESTDATA = "testdata"
var testTarget = flag.String("target", "", "override test target") var testTarget = flag.String("target", "", "override test target")
var supportedLinuxArches = map[string]string{
"AMD64Linux": "linux/amd64",
"X86Linux": "linux/386",
"ARMLinux": "linux/arm/6",
"ARM64Linux": "linux/arm64",
}
var sema = make(chan struct{}, runtime.NumCPU()) var sema = make(chan struct{}, runtime.NumCPU())
func TestBuild(t *testing.T) { func TestBuild(t *testing.T) {
@ -180,18 +187,14 @@ func TestBuild(t *testing.T) {
}) })
if runtime.GOOS == "linux" { if runtime.GOOS == "linux" {
t.Run("X86Linux", func(t *testing.T) { for name, osArch := range supportedLinuxArches {
t.Parallel() options := optionsFromOSARCH(osArch, sema)
runPlatTests(optionsFromOSARCH("linux/386", sema), tests, t) if options.GOARCH != runtime.GOARCH { // Native architecture already run above.
}) t.Run(name, func(t *testing.T) {
t.Run("ARMLinux", func(t *testing.T) { runPlatTests(options, tests, t)
t.Parallel() })
runPlatTests(optionsFromOSARCH("linux/arm/6", sema), tests, t) }
}) }
t.Run("ARM64Linux", func(t *testing.T) {
t.Parallel()
runPlatTests(optionsFromOSARCH("linux/arm64", sema), tests, t)
})
t.Run("WebAssembly", func(t *testing.T) { t.Run("WebAssembly", func(t *testing.T) {
t.Parallel() t.Parallel()
runPlatTests(optionsFromTarget("wasm", sema), tests, t) runPlatTests(optionsFromTarget("wasm", sema), tests, t)
@ -475,12 +478,12 @@ func TestTest(t *testing.T) {
} }
if !testing.Short() { if !testing.Short() {
if runtime.GOOS == "linux" { if runtime.GOOS == "linux" {
targs = append(targs, for name, osArch := range supportedLinuxArches {
// Linux options := optionsFromOSARCH(osArch, sema)
targ{"X86Linux", optionsFromOSARCH("linux/386", sema)}, if options.GOARCH != runtime.GOARCH { // Native architecture already run above.
targ{"ARMLinux", optionsFromOSARCH("linux/arm/6", sema)}, targs = append(targs, targ{name, options})
targ{"ARM64Linux", optionsFromOSARCH("linux/arm64", sema)}, }
) }
} }
targs = append(targs, targs = append(targs,