-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpurego_test.go
67 lines (60 loc) · 1.82 KB
/
purego_test.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
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package crypto_test
import (
"go/build"
"internal/testenv"
"log"
"os"
"os/exec"
"strings"
"testing"
)
// TestPureGoTag checks that when built with the purego build tag, crypto
// packages don't require any assembly. This is used by alternative compilers
// such as TinyGo. See also the "crypto/...:purego" test in cmd/dist, which
// ensures the packages build correctly.
func TestPureGoTag(t *testing.T) {
cmd := exec.Command(testenv.GoToolPath(t), "list", "-e", "crypto/...", "math/big")
cmd.Env = append(cmd.Env, "GOOS=linux")
cmd.Stderr = os.Stderr
out, err := cmd.Output()
if err != nil {
log.Fatalf("loading package list: %v\n%s", err, out)
}
pkgs := strings.Split(strings.TrimSpace(string(out)), "\n")
cmd = exec.Command(testenv.GoToolPath(t), "tool", "dist", "list")
cmd.Stderr = os.Stderr
out, err = cmd.Output()
if err != nil {
log.Fatalf("loading architecture list: %v\n%s", err, out)
}
allGOARCH := make(map[string]bool)
for _, pair := range strings.Split(strings.TrimSpace(string(out)), "\n") {
GOARCH := strings.Split(pair, "/")[1]
allGOARCH[GOARCH] = true
}
for _, pkgName := range pkgs {
if strings.Contains(pkgName, "/boring") {
continue
}
for GOARCH := range allGOARCH {
context := build.Context{
GOOS: "linux", // darwin has custom assembly
GOARCH: GOARCH,
GOROOT: testenv.GOROOT(t),
Compiler: build.Default.Compiler,
BuildTags: []string{"purego", "math_big_pure_go"},
}
pkg, err := context.Import(pkgName, "", 0)
if err != nil {
t.Fatal(err)
}
if len(pkg.SFiles) == 0 {
continue
}
t.Errorf("package %s has purego assembly files on %s: %v", pkgName, GOARCH, pkg.SFiles)
}
}
}