-
Notifications
You must be signed in to change notification settings - Fork 17.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/go: convert TestIssue6480 to the script framework
This one's a bit complex and required writing support go programs within the test script. Part of converting all tests to script framework to improve test parallelism. Updates #36320 Updates #17751 Change-Id: I9e91225b20b1b043f032b77a55c5825cb9d9a4b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/214292 Reviewed-by: Jay Conrod <[email protected]>
- Loading branch information
Showing
2 changed files
with
125 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# "go test -c -test.bench=XXX errors" should not hang. | ||
# "go test -c" should also produce reproducible binaries. | ||
# "go test -c" should also appear to write a new binary every time, | ||
# even if it's really just updating the mtime on an existing up-to-date binary. | ||
|
||
[gccgo] skip | ||
[short] skip | ||
|
||
# Install some commands to compare mtimes | ||
env GOBIN=$WORK/tmp/bin | ||
go install now mtime before | ||
|
||
# Initial builds | ||
go test -c -test.bench=XXX errors | ||
go test -c -o errors2.test errors | ||
cmp errors.test$GOEXE errors2.test # // errors2.test has no exeSuffix because -o above doesn't have it | ||
|
||
# Check errors.test mtime is updated | ||
exec $GOBIN/now | ||
cp stdout start_time.txt | ||
go test -x -c -test.bench=XXX errors | ||
! stderr '[\\/]link|gccgo' # make sure up-to-date test binary is not relinked | ||
exec $GOBIN/mtime errors.test$GOEXE | ||
cp stdout errors1_mod_time.txt | ||
exec $GOBIN/before start_time.txt errors1_mod_time.txt | ||
rm start_time.txt errors1_mod_time.txt | ||
|
||
# Check errors2.test mtime is updated | ||
exec $GOBIN/now | ||
cp stdout start_time.txt | ||
go test -x -c -o errors2.test errors | ||
! stderr '[\\/]link|gccgo' # make sure up-to-date test binary is not relinked | ||
exec $GOBIN/mtime errors2.test | ||
cp stdout errors2_mod_time.txt | ||
exec $GOBIN/before start_time.txt errors2_mod_time.txt | ||
|
||
-- now/now.go -- | ||
// Writes time.Now() to a file | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"time" | ||
) | ||
|
||
func main() { | ||
if err := json.NewEncoder(os.Stdout).Encode(time.Now()); err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
} | ||
-- mtime/mtime.go -- | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
func main() { | ||
info, err := os.Stat(os.Args[1]) | ||
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) | ||
} | ||
} | ||
-- before/before.go -- | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"time" | ||
) | ||
|
||
func truncateLike(t, p time.Time) time.Time { | ||
nano := p.UnixNano() | ||
d := 1 * time.Nanosecond | ||
for nano%int64(d) == 0 && d < 1*time.Second { | ||
d *= 10 | ||
} | ||
for nano%int64(d) == 0 && d < 2*time.Second { | ||
d *= 2 | ||
} | ||
return t.Truncate(d) | ||
} | ||
|
||
func main() { | ||
var t1 time.Time | ||
b1, err := ioutil.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 := ioutil.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) | ||
} | ||
|
||
t1 = truncateLike(t1, t2) | ||
if !t1.Before(t2) { | ||
fmt.Fprintf(os.Stderr, "time in %v (%v) is not before time in %v (%v)", os.Args[1], t1, os.Args[2], t2) | ||
os.Exit(1) | ||
} | ||
} |