1 # "go test -c -test.bench=XXX errors" should not hang.
2 # "go test -c" should also produce reproducible binaries.
3 # "go test -c" should also appear to write a new binary every time,
4 # even if it's really just updating the mtime on an existing up-to-date binary.
5
6 [gccgo] skip
7 [short] skip
8
9 # Install some commands to compare mtimes
10 env GOBIN=$WORK/tmp/bin
11 go install m/now m/mtime m/before
12
13 # Initial builds
14 go test -c -test.bench=XXX errors
15 go test -c -o errors2.test errors
16 cmp errors.test$GOEXE errors2.test # // errors2.test has no exeSuffix because -o above doesn't have it
17
18 # Check errors.test mtime is updated
19 exec $GOBIN/now
20 cp stdout start_time.txt
21 go test -x -c -test.bench=XXX errors
22 ! stderr '[\\/]link|gccgo' # make sure up-to-date test binary is not relinked
23 exec $GOBIN/mtime errors.test$GOEXE
24 cp stdout errors1_mod_time.txt
25 exec $GOBIN/before start_time.txt errors1_mod_time.txt
26 rm start_time.txt errors1_mod_time.txt
27
28 # Check errors2.test mtime is updated
29 exec $GOBIN/now
30 cp stdout start_time.txt
31 go test -x -c -o errors2.test errors
32 ! stderr '[\\/]link|gccgo' # make sure up-to-date test binary is not relinked
33 exec $GOBIN/mtime errors2.test
34 cp stdout errors2_mod_time.txt
35 exec $GOBIN/before start_time.txt errors2_mod_time.txt
36
37 -- go.mod --
38 module m
39
40 go 1.16
41 -- now/now.go --
42 // Writes time.Now() to a file
43 package main
44
45 import (
46 "encoding/json"
47 "fmt"
48 "os"
49 "time"
50 )
51
52 func main() {
53 if err := json.NewEncoder(os.Stdout).Encode(time.Now()); err != nil {
54 fmt.Fprintln(os.Stderr, err)
55 os.Exit(1)
56 }
57 }
58 -- mtime/mtime.go --
59 package main
60
61 import (
62 "encoding/json"
63 "fmt"
64 "os"
65 )
66
67 func main() {
68 info, err := os.Stat(os.Args[1])
69 if err != nil {
70 fmt.Fprintln(os.Stderr, err)
71 os.Exit(1)
72 }
73 if err := json.NewEncoder(os.Stdout).Encode(info.ModTime()); err != nil {
74 fmt.Fprintln(os.Stderr, err)
75 os.Exit(1)
76 }
77 }
78 -- before/before.go --
79 package main
80
81 import (
82 "encoding/json"
83 "fmt"
84 "os"
85 "time"
86 )
87
88 func truncateLike(t, p time.Time) time.Time {
89 nano := p.UnixNano()
90 d := 1 * time.Nanosecond
91 for nano%int64(d) == 0 && d < 1*time.Second {
92 d *= 10
93 }
94 for nano%int64(d) == 0 && d < 2*time.Second {
95 d *= 2
96 }
97 return t.Truncate(d)
98 }
99
100 func main() {
101 var t1 time.Time
102 b1, err := os.ReadFile(os.Args[1])
103 if err != nil {
104 fmt.Fprintln(os.Stderr, err)
105 os.Exit(1)
106 }
107 if err := json.Unmarshal(b1, &t1); err != nil {
108 fmt.Fprintln(os.Stderr, err)
109 os.Exit(1)
110 }
111
112 var t2 time.Time
113 b2, err := os.ReadFile(os.Args[2])
114 if err != nil {
115 fmt.Fprintln(os.Stderr, err)
116 os.Exit(1)
117 }
118 if err := json.Unmarshal(b2, &t2); err != nil {
119 fmt.Fprintln(os.Stderr, err)
120 os.Exit(1)
121 }
122
123 t1 = truncateLike(t1, t2)
124 if !t1.Before(t2) {
125 fmt.Fprintf(os.Stderr, "time in %v (%v) is not before time in %v (%v)", os.Args[1], t1, os.Args[2], t2)
126 os.Exit(1)
127 }
128 }
129
View as plain text