From d93c3c2eff5e4c92d7740d82ff079a0ae51f60d9 Mon Sep 17 00:00:00 2001 From: Nicolas Lacasse Date: Wed, 6 Oct 2021 16:05:56 -0700 Subject: Wrap testing.MainStart to work around upcoming signature change. Go1.18 is changing the signature of testing.MainStart. To ensure compatibility, we wrap MainStart and different implementations for versions before/after Go1.18. PiperOrigin-RevId: 401362668 --- test/runtimes/runner/lib/BUILD | 6 ++++- .../runner/lib/go_test_dependency_go118.go | 27 ++++++++++++++++++++++ .../runner/lib/go_test_dependency_not_go118.go | 25 ++++++++++++++++++++ test/runtimes/runner/lib/lib.go | 22 ++++++++++++++++-- 4 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 test/runtimes/runner/lib/go_test_dependency_go118.go create mode 100644 test/runtimes/runner/lib/go_test_dependency_not_go118.go (limited to 'test') diff --git a/test/runtimes/runner/lib/BUILD b/test/runtimes/runner/lib/BUILD index d308f41b0..3491c535b 100644 --- a/test/runtimes/runner/lib/BUILD +++ b/test/runtimes/runner/lib/BUILD @@ -5,7 +5,11 @@ package(licenses = ["notice"]) go_library( name = "lib", testonly = 1, - srcs = ["lib.go"], + srcs = [ + "go_test_dependency_go118.go", + "go_test_dependency_not_go118.go", + "lib.go", + ], visibility = ["//test/runtimes/runner:__pkg__"], deps = [ "//pkg/log", diff --git a/test/runtimes/runner/lib/go_test_dependency_go118.go b/test/runtimes/runner/lib/go_test_dependency_go118.go new file mode 100644 index 000000000..d430e81c7 --- /dev/null +++ b/test/runtimes/runner/lib/go_test_dependency_go118.go @@ -0,0 +1,27 @@ +// Copyright 2021 The gVisor Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build go1.18 && go1.1 +// +build go1.18,go1.1 + +package lib + +import ( + "testing" +) + +// mainStart wraps testing.MainStart for Go release == 1.18. +func mainStart(tests []testing.InternalTest) *testing.M { + return testing.MainStart(testDeps{}, tests, nil, nil, nil) +} diff --git a/test/runtimes/runner/lib/go_test_dependency_not_go118.go b/test/runtimes/runner/lib/go_test_dependency_not_go118.go new file mode 100644 index 000000000..8b0b34c72 --- /dev/null +++ b/test/runtimes/runner/lib/go_test_dependency_not_go118.go @@ -0,0 +1,25 @@ +// Copyright 2021 The gVisor Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build !go1.18 && go1.1 +// +build !go1.18,go1.1 + +package lib + +import "testing" + +// mainStart wraps testing.MainStart for Go release < 1.18. +func mainStart(tests []testing.InternalTest) *testing.M { + return testing.MainStart(testDeps{}, tests, nil, nil) +} diff --git a/test/runtimes/runner/lib/lib.go b/test/runtimes/runner/lib/lib.go index d6b652897..d704f8895 100644 --- a/test/runtimes/runner/lib/lib.go +++ b/test/runtimes/runner/lib/lib.go @@ -21,6 +21,7 @@ import ( "fmt" "io" "os" + "reflect" "sort" "strings" "testing" @@ -63,8 +64,7 @@ func RunTests(lang, image, excludeFile string, batchSize int, timeout time.Durat fmt.Fprintf(os.Stderr, "%s\n", err.Error()) return 1 } - - m := testing.MainStart(testDeps{}, tests, nil, nil) + m := mainStart(tests) return m.Run() } @@ -197,3 +197,21 @@ func (f testDeps) ImportPath() string { return "" } func (f testDeps) StartTestLog(io.Writer) {} func (f testDeps) StopTestLog() error { return nil } func (f testDeps) SetPanicOnExit0(bool) {} +func (f testDeps) CoordinateFuzzing(time.Duration, int64, time.Duration, int64, int, []corpusEntry, []reflect.Type, string, string) error { + return nil +} +func (f testDeps) RunFuzzWorker(func(corpusEntry) error) error { return nil } +func (f testDeps) ReadCorpus(string, []reflect.Type) ([]corpusEntry, error) { return nil, nil } +func (f testDeps) CheckCorpus([]interface{}, []reflect.Type) error { return nil } +func (f testDeps) ResetCoverage() {} +func (f testDeps) SnapshotCoverage() {} + +// Copied from testing/fuzz.go. +type corpusEntry = struct { + Parent string + Name string + Data []byte + Values []interface{} + Generation int + IsSeed bool +} -- cgit v1.2.3