Text file src/cmd/go/testdata/script/test_race_install_cgo.txt

     1  # Tests Issue #10500
     2  
     3  [!race] skip
     4  
     5  env GOBIN=$WORK/bin
     6  go install m/mtime m/sametime
     7  
     8  go tool -n cgo
     9  cp stdout cgopath.txt
    10  exec $GOBIN/mtime cgopath.txt # get the mtime of the file whose name is in cgopath.txt
    11  cp 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  
    18  exec $GOBIN/mtime cgopath.txt # get the mtime of the file whose name is in cgopath.txt
    19  cp stdout cgotime_after.txt
    20  exec $GOBIN/sametime cgotime_before.txt cgotime_after.txt
    21  
    22  -- go.mod --
    23  module m
    24  
    25  go 1.16
    26  -- mtime/mtime.go --
    27  package main
    28  
    29  import (
    30  	"encoding/json"
    31  	"fmt"
    32  	"os"
    33  	"strings"
    34  )
    35  
    36  func 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 --
    54  package main
    55  
    56  import (
    57  	"encoding/json"
    58  	"fmt"
    59  	"os"
    60  	"time"
    61  )
    62  
    63  
    64  func 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  }
    92  

View as plain text