...
1# Tests Issue #10500
2
3[!race] skip
4
5env GOBIN=$WORK/bin
6go install m/mtime m/sametime
7
8go tool -n cgo
9cp stdout cgopath.txt
10exec $GOBIN/mtime cgopath.txt # get the mtime of the file whose name is in cgopath.txt
11cp stdout cgotime_before.txt
12
13 # For this test, we don't actually care whether 'go test -race -i' succeeds.
14 # It may fail if GOROOT is read-only (perhaps it was installed as root).
15 # We only care that it does not overwrite cmd/cgo regardless.
16? go test -race -i runtime/race
17
18exec $GOBIN/mtime cgopath.txt # get the mtime of the file whose name is in cgopath.txt
19cp stdout cgotime_after.txt
20exec $GOBIN/sametime cgotime_before.txt cgotime_after.txt
21
22-- go.mod --
23module m
24
25go 1.16
26-- mtime/mtime.go --
27package main
28
29import (
30 "encoding/json"
31 "fmt"
32 "os"
33 "strings"
34)
35
36func main() {
37 b, err := os.ReadFile(os.Args[1])
38 if err != nil {
39 fmt.Fprintln(os.Stderr, err)
40 os.Exit(1)
41 }
42 filename := strings.TrimSpace(string(b))
43 info, err := os.Stat(filename)
44 if err != nil {
45 fmt.Fprintln(os.Stderr, err)
46 os.Exit(1)
47 }
48 if err := json.NewEncoder(os.Stdout).Encode(info.ModTime()); err != nil {
49 fmt.Fprintln(os.Stderr, err)
50 os.Exit(1)
51 }
52}
53-- sametime/sametime.go --
54package main
55
56import (
57 "encoding/json"
58 "fmt"
59 "os"
60 "time"
61)
62
63
64func main() {
65 var t1 time.Time
66 b1, err := os.ReadFile(os.Args[1])
67 if err != nil {
68 fmt.Fprintln(os.Stderr, err)
69 os.Exit(1)
70 }
71 if err := json.Unmarshal(b1, &t1); err != nil {
72 fmt.Fprintln(os.Stderr, err)
73 os.Exit(1)
74 }
75
76 var t2 time.Time
77 b2, err := os.ReadFile(os.Args[2])
78 if err != nil {
79 fmt.Fprintln(os.Stderr, err)
80 os.Exit(1)
81 }
82 if err := json.Unmarshal(b2, &t2); err != nil {
83 fmt.Fprintln(os.Stderr, err)
84 os.Exit(1)
85 }
86
87 if !t1.Equal(t2) {
88 fmt.Fprintf(os.Stderr, "time in %v (%v) is not the same as time in %v (%v)", os.Args[1], t1, os.Args[2], t2)
89 os.Exit(1)
90 }
91}
View as plain text