mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-01 22:57:29 -04:00
unix: generate darwinTests per GOARCH and enabled darwin/arm64 test
Change-Id: I1c5bb166f6971f83890a08413aa8b35fe23a0c04 Reviewed-on: https://go-review.googlesource.com/c/sys/+/357069 Trust: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
committed by
Ian Lance Taylor
parent
e0b2ad06fe
commit
cbcd623f20
+53
-3
@@ -15,12 +15,13 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const ptrsize = 8 // Pointer size. All supported platforms are 64-bit.
|
||||
|
||||
func writeASMFile(in string, fileName string, buildTags string) {
|
||||
func writeASMFile(in string, fileName string, buildTags string) map[string]bool {
|
||||
trampolines := map[string]bool{}
|
||||
|
||||
var out bytes.Buffer
|
||||
@@ -51,6 +52,48 @@ func writeASMFile(in string, fileName string, buildTags string) {
|
||||
if err != nil {
|
||||
log.Fatalf("can't write %s: %s", fileName, err)
|
||||
}
|
||||
|
||||
return trampolines
|
||||
}
|
||||
|
||||
const darwinTestTemplate = `// go run mkasm_darwin.go %s
|
||||
// Code generated by the command above; DO NOT EDIT.
|
||||
|
||||
//go:build darwin && go1.12
|
||||
// +build darwin,go1.12
|
||||
|
||||
package unix
|
||||
|
||||
// All the _trampoline functions in zsyscall_darwin_%s.s.
|
||||
var darwinTests = [...]darwinTest{
|
||||
%s}
|
||||
`
|
||||
|
||||
func writeDarwinTest(trampolines map[string]bool, fileName, arch string) {
|
||||
// sort trampolines
|
||||
sorted := make([]string, len(trampolines))
|
||||
i := 0
|
||||
for trampoline := range trampolines {
|
||||
sorted[i] = trampoline
|
||||
i++
|
||||
}
|
||||
sort.Slice(sorted, func(i, j int) bool { return sorted[i] < sorted[j] })
|
||||
|
||||
var out bytes.Buffer
|
||||
|
||||
const prefix = "libc_"
|
||||
for _, trampoline := range sorted {
|
||||
fmt.Fprintf(&out, fmt.Sprintf("\t{%q, %s_trampoline_addr},\n", strings.TrimPrefix(trampoline, prefix), trampoline))
|
||||
}
|
||||
lines := out.String()
|
||||
|
||||
out.Reset()
|
||||
fmt.Fprintf(&out, darwinTestTemplate, strings.Join(os.Args[1:], " "), arch, lines)
|
||||
|
||||
err := ioutil.WriteFile(fileName, out.Bytes(), 0644)
|
||||
if err != nil {
|
||||
log.Fatalf("can't write %s: %s", fileName, err)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -69,7 +112,7 @@ func main() {
|
||||
}
|
||||
in := string(in1) + string(in2) + string(in3)
|
||||
|
||||
writeASMFile(in, fmt.Sprintf("zsyscall_darwin_%s.s", arch), "go1.12")
|
||||
trampolines := writeASMFile(in, fmt.Sprintf("zsyscall_darwin_%s.s", arch), "go1.12")
|
||||
|
||||
in1, err = ioutil.ReadFile("syscall_darwin.1_13.go")
|
||||
if err != nil {
|
||||
@@ -82,5 +125,12 @@ func main() {
|
||||
|
||||
in = string(in1) + string(in2)
|
||||
|
||||
writeASMFile(in, fmt.Sprintf("zsyscall_darwin_%s.1_13.s", arch), "go1.13")
|
||||
trampolines2 := writeASMFile(in, fmt.Sprintf("zsyscall_darwin_%s.1_13.s", arch), "go1.13")
|
||||
|
||||
// merge trampolines
|
||||
for trampoline := range trampolines2 {
|
||||
trampolines[trampoline] = true
|
||||
}
|
||||
|
||||
writeDarwinTest(trampolines, fmt.Sprintf("darwin_%s_test.go", arch), arch)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user