aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/test_race_install_cgo.txt
blob: 3f4eb90e3f66e72b48cc52106ea8a9868706e8c9 (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Tests Issue #10500

[!race] skip

[!darwin] ! stale cmd/cgo  # The darwin builders are spuriously stale; see #33598.

env GOBIN=$WORK/bin
go install m/mtime m/sametime

go tool -n cgo
cp stdout cgopath.txt
exec $GOBIN/mtime cgopath.txt # get the mtime of the file whose name is in cgopath.txt
cp stdout cgotime_before.txt

 # For this test, we don't actually care whether 'go test -race -i' succeeds.
 # It may fail if GOROOT is read-only (perhaps it was installed as root).
 # We only care that it does not overwrite cmd/cgo regardless.
? go test -race -i runtime/race

exec $GOBIN/mtime cgopath.txt # get the mtime of the file whose name is in cgopath.txt
cp stdout cgotime_after.txt
exec $GOBIN/sametime cgotime_before.txt cgotime_after.txt

-- go.mod --
module m

go 1.16
-- mtime/mtime.go --
package main

import (
	"encoding/json"
	"fmt"
	"os"
	"strings"
)

func main() {
	b, err := os.ReadFile(os.Args[1])
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	filename := strings.TrimSpace(string(b))
	info, err := os.Stat(filename)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	if err := json.NewEncoder(os.Stdout).Encode(info.ModTime()); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}
-- sametime/sametime.go --
package main

import (
	"encoding/json"
	"fmt"
	"os"
	"time"
)


func main() {
	var t1 time.Time
	b1, err := os.ReadFile(os.Args[1])
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	if err := json.Unmarshal(b1, &t1); err != nil  {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	var t2 time.Time
	b2, err := os.ReadFile(os.Args[2])
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	if err := json.Unmarshal(b2, &t2); err != nil  {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	if !t1.Equal(t2) {
		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)
		os.Exit(1)
	}
}