Add default behavior for gtest runner.

PiperOrigin-RevId: 297009116
This commit is contained in:
Adin Scannell
2020-02-24 17:29:34 -08:00
committed by gVisor bot
parent 93626a28e4
commit 160d5751ab
3 changed files with 24 additions and 11 deletions
+4 -4
View File
@@ -29,7 +29,7 @@ syscall_test(
)
syscall_test(
size = "large",
size = "enormous",
test = "//test/perf/linux:getdents_benchmark",
)
@@ -39,7 +39,7 @@ syscall_test(
)
syscall_test(
size = "large",
size = "enormous",
test = "//test/perf/linux:gettid_benchmark",
)
@@ -87,7 +87,7 @@ syscall_test(
)
syscall_test(
size = "large",
size = "enormous",
test = "//test/perf/linux:signal_benchmark",
)
@@ -102,7 +102,7 @@ syscall_test(
)
syscall_test(
size = "large",
size = "enormous",
add_overlay = True,
test = "//test/perf/linux:unlink_benchmark",
)
+1 -1
View File
@@ -141,7 +141,7 @@ void BM_GetdentsNewFD(benchmark::State& state) {
state.SetItemsProcessed(state.iterations());
}
BENCHMARK(BM_GetdentsNewFD)->Range(1, 1 << 16)->UseRealTime();
BENCHMARK(BM_GetdentsNewFD)->Range(1, 1 << 12)->UseRealTime();
} // namespace
+19 -6
View File
@@ -43,6 +43,10 @@ type TestCase struct {
// Name is the name of this individual test.
Name string
// all indicates that this will run without flags. This takes
// precendence over benchmark below.
all bool
// benchmark indicates that this is a benchmark. In this case, the
// suite will be empty, and we will use the appropriate test and
// benchmark flags.
@@ -57,6 +61,9 @@ func (tc TestCase) FullName() string {
// Args returns arguments to be passed when invoking the test.
func (tc TestCase) Args() []string {
if tc.all {
return []string{} // No arguments.
}
if tc.benchmark {
return []string{
fmt.Sprintf("%s=^$", filterTestFlag),
@@ -81,11 +88,16 @@ func ParseTestCases(testBin string, benchmarks bool, extraArgs ...string) ([]Tes
cmd := exec.Command(testBin, args...)
out, err := cmd.Output()
if err != nil {
exitErr, ok := err.(*exec.ExitError)
if !ok {
return nil, fmt.Errorf("could not enumerate gtest tests: %v", err)
}
return nil, fmt.Errorf("could not enumerate gtest tests: %v\nstderr:\n%s", err, exitErr.Stderr)
// We failed to list tests with the given flags. Just
// return something that will run the binary with no
// flags, which should execute all tests.
return []TestCase{
TestCase{
Suite: "Default",
Name: "All",
all: true,
},
}, nil
}
// Parse test output.
@@ -114,7 +126,6 @@ func ParseTestCases(testBin string, benchmarks bool, extraArgs ...string) ([]Tes
Suite: suite,
Name: name,
})
}
// Finished?
@@ -127,6 +138,8 @@ func ParseTestCases(testBin string, benchmarks bool, extraArgs ...string) ([]Tes
cmd = exec.Command(testBin, args...)
out, err = cmd.Output()
if err != nil {
// We were able to enumerate tests above, but not benchmarks?
// We requested them, so we return an error in this case.
exitErr, ok := err.(*exec.ExitError)
if !ok {
return nil, fmt.Errorf("could not enumerate gtest benchmarks: %v", err)