diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-05-09 08:42:01 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-05-09 08:42:01 +0200 |
| commit | e8d62d0c21fa78504c492a1418b84cb2477e06fa (patch) | |
| tree | 5421801082758e837ae003eba4b563b2770ab683 /pkg | |
| parent | e97b06d3cef9296e9d0e827c42bccdd36b555986 (diff) | |
pkg/build: parallelize a test
Significanlty reduces execution time as it
runs lots of subprocesses.
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/build/linux_test.go | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/pkg/build/linux_test.go b/pkg/build/linux_test.go index a3fae056a..1088641e6 100644 --- a/pkg/build/linux_test.go +++ b/pkg/build/linux_test.go @@ -8,6 +8,8 @@ package build import ( "bytes" "os" + "strings" + "sync" "testing" "text/template" @@ -15,6 +17,7 @@ import ( ) func TestElfBinarySignature(t *testing.T) { + t.Parallel() enumerateFlags(t, nil, []string{"-g", "-O1", "-O2", "-no-pie", "-static"}) } @@ -24,18 +27,28 @@ func enumerateFlags(t *testing.T, flags, allFlags []string) { enumerateFlags(t, append(flags, allFlags[0]), allFlags[1:]) return } - t.Logf("testing: %+v", flags) - sign1 := sign(t, flags, false, false) - sign2 := sign(t, flags, false, true) - sign3 := sign(t, flags, true, false) - if sign1 != sign2 { - t.Errorf("signature has changed after a comment-only change") - } - if sign1 == sign3 { - t.Errorf("signature has not changed after a change") - } - - //func elfBinarySignature(bin string) (string, error) { + t.Run(strings.Join(flags, "-"), func(t *testing.T) { + t.Parallel() + sign1, sign2 := "", "" + var wg sync.WaitGroup + wg.Add(2) + go func() { + sign1 = sign(t, flags, false, false) + wg.Done() + }() + go func() { + sign2 = sign(t, flags, false, true) + wg.Done() + }() + sign3 := sign(t, flags, true, false) + wg.Wait() + if sign1 != sign2 { + t.Errorf("signature has changed after a comment-only change") + } + if sign1 == sign3 { + t.Errorf("signature has not changed after a change") + } + }) } func sign(t *testing.T, flags []string, changed, comment bool) string { |
