Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015, Google Inc. |
| 2 | * |
| 3 | * Permission to use, copy, modify, and/or distribute this software for any |
| 4 | * purpose with or without fee is hereby granted, provided that the above |
| 5 | * copyright notice and this permission notice appear in all copies. |
| 6 | * |
| 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ |
| 14 | |
| 15 | package main |
| 16 | |
| 17 | import ( |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 18 | "bufio" |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 19 | "bytes" |
| 20 | "encoding/json" |
Robert Sloan | c9abfe4 | 2018-11-26 12:19:07 -0800 | [diff] [blame^] | 21 | "errors" |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 22 | "flag" |
| 23 | "fmt" |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 24 | "math/rand" |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 25 | "os" |
| 26 | "os/exec" |
| 27 | "path" |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 28 | "runtime" |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 29 | "strconv" |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 30 | "strings" |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 31 | "sync" |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 32 | "syscall" |
Robert Sloan | c9abfe4 | 2018-11-26 12:19:07 -0800 | [diff] [blame^] | 33 | |
| 34 | "boringssl.googlesource.com/boringssl/util/testresult" |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 35 | ) |
| 36 | |
| 37 | // TODO(davidben): Link tests with the malloc shim and port -malloc-test to this runner. |
| 38 | |
| 39 | var ( |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 40 | useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind") |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 41 | useCallgrind = flag.Bool("callgrind", false, "If true, run code under valgrind to generate callgrind traces.") |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 42 | useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb") |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 43 | useSDE = flag.Bool("sde", false, "If true, run BoringSSL code under Intel's SDE for each supported chip") |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 44 | sdePath = flag.String("sde-path", "sde", "The path to find the sde binary.") |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 45 | buildDir = flag.String("build-dir", "build", "The build directory to run the tests from.") |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 46 | numWorkers = flag.Int("num-workers", runtime.NumCPU(), "Runs the given number of workers when testing.") |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 47 | jsonOutput = flag.String("json-output", "", "The file to output JSON results to.") |
| 48 | mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.") |
| 49 | mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask each test to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.") |
Robert Sloan | c9abfe4 | 2018-11-26 12:19:07 -0800 | [diff] [blame^] | 50 | simulateARMCPUs = flag.Bool("simulate-arm-cpus", simulateARMCPUsDefault(), "If true, runs tests simulating different ARM CPUs.") |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 51 | ) |
| 52 | |
Robert Sloan | c9abfe4 | 2018-11-26 12:19:07 -0800 | [diff] [blame^] | 53 | func simulateARMCPUsDefault() bool { |
| 54 | return runtime.GOOS == "linux" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") |
| 55 | } |
| 56 | |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 57 | type test struct { |
Robert Sloan | 4562e9d | 2017-10-02 10:26:51 -0700 | [diff] [blame] | 58 | args []string |
| 59 | shard, numShards int |
Robert Sloan | c9abfe4 | 2018-11-26 12:19:07 -0800 | [diff] [blame^] | 60 | // cpu, if not empty, contains a code to simulate. For SDE, run `sde64 |
| 61 | // -help` to get a list of these codes. For ARM, see gtest_main.cc for |
| 62 | // the supported values. |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 63 | cpu string |
| 64 | } |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 65 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 66 | type result struct { |
| 67 | Test test |
| 68 | Passed bool |
| 69 | Error error |
| 70 | } |
| 71 | |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 72 | // sdeCPUs contains a list of CPU code that we run all tests under when *useSDE |
| 73 | // is true. |
| 74 | var sdeCPUs = []string{ |
| 75 | "p4p", // Pentium4 Prescott |
| 76 | "mrm", // Merom |
| 77 | "pnr", // Penryn |
| 78 | "nhm", // Nehalem |
| 79 | "wsm", // Westmere |
| 80 | "snb", // Sandy Bridge |
| 81 | "ivb", // Ivy Bridge |
| 82 | "hsw", // Haswell |
| 83 | "bdw", // Broadwell |
| 84 | "skx", // Skylake Server |
| 85 | "skl", // Skylake Client |
| 86 | "cnl", // Cannonlake |
| 87 | "knl", // Knights Landing |
| 88 | "slt", // Saltwell |
| 89 | "slm", // Silvermont |
| 90 | "glm", // Goldmont |
Robert Sloan | fe7cd21 | 2017-08-07 09:03:39 -0700 | [diff] [blame] | 91 | "knm", // Knights Mill |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 92 | } |
| 93 | |
Robert Sloan | c9abfe4 | 2018-11-26 12:19:07 -0800 | [diff] [blame^] | 94 | var armCPUs = []string{ |
| 95 | "none", // No support for any ARM extensions. |
| 96 | "neon", // Support for NEON. |
| 97 | "crypto", // Support for NEON and crypto extensions. |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd { |
David Benjamin | 7c0d06c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 101 | valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"} |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 102 | if dbAttach { |
| 103 | valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p") |
| 104 | } |
| 105 | valgrindArgs = append(valgrindArgs, path) |
| 106 | valgrindArgs = append(valgrindArgs, args...) |
| 107 | |
| 108 | return exec.Command("valgrind", valgrindArgs...) |
| 109 | } |
| 110 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 111 | func callgrindOf(path string, args ...string) *exec.Cmd { |
| 112 | valgrindArgs := []string{"-q", "--tool=callgrind", "--dump-instr=yes", "--collect-jumps=yes", "--callgrind-out-file=" + *buildDir + "/callgrind/callgrind.out.%p"} |
| 113 | valgrindArgs = append(valgrindArgs, path) |
| 114 | valgrindArgs = append(valgrindArgs, args...) |
| 115 | |
| 116 | return exec.Command("valgrind", valgrindArgs...) |
| 117 | } |
| 118 | |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 119 | func gdbOf(path string, args ...string) *exec.Cmd { |
| 120 | xtermArgs := []string{"-e", "gdb", "--args"} |
| 121 | xtermArgs = append(xtermArgs, path) |
| 122 | xtermArgs = append(xtermArgs, args...) |
| 123 | |
| 124 | return exec.Command("xterm", xtermArgs...) |
| 125 | } |
| 126 | |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 127 | func sdeOf(cpu, path string, args ...string) *exec.Cmd { |
Robert Sloan | b6d070c | 2017-07-24 08:40:01 -0700 | [diff] [blame] | 128 | sdeArgs := []string{"-" + cpu} |
| 129 | // The kernel's vdso code for gettimeofday sometimes uses the RDTSCP |
| 130 | // instruction. Although SDE has a -chip_check_vsyscall flag that |
| 131 | // excludes such code by default, it does not seem to work. Instead, |
| 132 | // pass the -chip_check_exe_only flag which retains test coverage when |
| 133 | // statically linked and excludes the vdso. |
| 134 | if cpu == "p4p" || cpu == "pnr" || cpu == "mrm" || cpu == "slt" { |
| 135 | sdeArgs = append(sdeArgs, "-chip_check_exe_only") |
| 136 | } |
| 137 | sdeArgs = append(sdeArgs, "--", path) |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 138 | sdeArgs = append(sdeArgs, args...) |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 139 | return exec.Command(*sdePath, sdeArgs...) |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 140 | } |
| 141 | |
Robert Sloan | c9abfe4 | 2018-11-26 12:19:07 -0800 | [diff] [blame^] | 142 | var ( |
| 143 | errMoreMallocs = errors.New("child process did not exhaust all allocation calls") |
| 144 | errTestSkipped = errors.New("test was skipped") |
| 145 | ) |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 146 | |
| 147 | func runTestOnce(test test, mallocNumToFail int64) (passed bool, err error) { |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 148 | prog := path.Join(*buildDir, test.args[0]) |
| 149 | args := test.args[1:] |
Robert Sloan | c9abfe4 | 2018-11-26 12:19:07 -0800 | [diff] [blame^] | 150 | if *simulateARMCPUs && test.cpu != "" { |
| 151 | args = append([]string{"--cpu=" + test.cpu}, args...) |
| 152 | } |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 153 | var cmd *exec.Cmd |
| 154 | if *useValgrind { |
| 155 | cmd = valgrindOf(false, prog, args...) |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 156 | } else if *useCallgrind { |
| 157 | cmd = callgrindOf(prog, args...) |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 158 | } else if *useGDB { |
| 159 | cmd = gdbOf(prog, args...) |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 160 | } else if *useSDE { |
| 161 | cmd = sdeOf(test.cpu, prog, args...) |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 162 | } else { |
| 163 | cmd = exec.Command(prog, args...) |
| 164 | } |
Robert Sloan | 5d62578 | 2017-02-13 09:55:39 -0800 | [diff] [blame] | 165 | var outBuf bytes.Buffer |
| 166 | cmd.Stdout = &outBuf |
| 167 | cmd.Stderr = &outBuf |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 168 | if mallocNumToFail >= 0 { |
| 169 | cmd.Env = os.Environ() |
| 170 | cmd.Env = append(cmd.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10)) |
| 171 | if *mallocTestDebug { |
| 172 | cmd.Env = append(cmd.Env, "MALLOC_ABORT_ON_FAIL=1") |
| 173 | } |
| 174 | cmd.Env = append(cmd.Env, "_MALLOC_CHECK=1") |
| 175 | } |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 176 | |
| 177 | if err := cmd.Start(); err != nil { |
| 178 | return false, err |
| 179 | } |
| 180 | if err := cmd.Wait(); err != nil { |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 181 | if exitError, ok := err.(*exec.ExitError); ok { |
Robert Sloan | c9abfe4 | 2018-11-26 12:19:07 -0800 | [diff] [blame^] | 182 | switch exitError.Sys().(syscall.WaitStatus).ExitStatus() { |
| 183 | case 88: |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 184 | return false, errMoreMallocs |
Robert Sloan | c9abfe4 | 2018-11-26 12:19:07 -0800 | [diff] [blame^] | 185 | case 89: |
| 186 | fmt.Print(string(outBuf.Bytes())) |
| 187 | return false, errTestSkipped |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 188 | } |
| 189 | } |
Robert Sloan | 5d62578 | 2017-02-13 09:55:39 -0800 | [diff] [blame] | 190 | fmt.Print(string(outBuf.Bytes())) |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 191 | return false, err |
| 192 | } |
| 193 | |
| 194 | // Account for Windows line-endings. |
Robert Sloan | 5d62578 | 2017-02-13 09:55:39 -0800 | [diff] [blame] | 195 | stdout := bytes.Replace(outBuf.Bytes(), []byte("\r\n"), []byte("\n"), -1) |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 196 | |
| 197 | if bytes.HasSuffix(stdout, []byte("PASS\n")) && |
| 198 | (len(stdout) == 5 || stdout[len(stdout)-6] == '\n') { |
| 199 | return true, nil |
| 200 | } |
David Benjamin | f31229b | 2017-01-25 14:08:15 -0500 | [diff] [blame] | 201 | |
| 202 | // Also accept a googletest-style pass line. This is left here in |
| 203 | // transition until the tests are all converted and this script made |
| 204 | // unnecessary. |
| 205 | if bytes.Contains(stdout, []byte("\n[ PASSED ]")) { |
| 206 | return true, nil |
| 207 | } |
| 208 | |
Robert Sloan | 5d62578 | 2017-02-13 09:55:39 -0800 | [diff] [blame] | 209 | fmt.Print(string(outBuf.Bytes())) |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 210 | return false, nil |
| 211 | } |
| 212 | |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 213 | func runTest(test test) (bool, error) { |
| 214 | if *mallocTest < 0 { |
| 215 | return runTestOnce(test, -1) |
| 216 | } |
| 217 | |
| 218 | for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ { |
| 219 | if passed, err := runTestOnce(test, mallocNumToFail); err != errMoreMallocs { |
| 220 | if err != nil { |
| 221 | err = fmt.Errorf("at malloc %d: %s", mallocNumToFail, err) |
| 222 | } |
| 223 | return passed, err |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 228 | // setWorkingDirectory walks up directories as needed until the current working |
| 229 | // directory is the top of a BoringSSL checkout. |
| 230 | func setWorkingDirectory() { |
| 231 | for i := 0; i < 64; i++ { |
| 232 | if _, err := os.Stat("BUILDING.md"); err == nil { |
| 233 | return |
| 234 | } |
| 235 | os.Chdir("..") |
| 236 | } |
| 237 | |
| 238 | panic("Couldn't find BUILDING.md in a parent directory!") |
| 239 | } |
| 240 | |
| 241 | func parseTestConfig(filename string) ([]test, error) { |
| 242 | in, err := os.Open(filename) |
| 243 | if err != nil { |
| 244 | return nil, err |
| 245 | } |
| 246 | defer in.Close() |
| 247 | |
| 248 | decoder := json.NewDecoder(in) |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 249 | var testArgs [][]string |
| 250 | if err := decoder.Decode(&testArgs); err != nil { |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 251 | return nil, err |
| 252 | } |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 253 | |
| 254 | var result []test |
| 255 | for _, args := range testArgs { |
| 256 | result = append(result, test{args: args}) |
| 257 | } |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 258 | return result, nil |
| 259 | } |
| 260 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 261 | func worker(tests <-chan test, results chan<- result, done *sync.WaitGroup) { |
| 262 | defer done.Done() |
| 263 | for test := range tests { |
| 264 | passed, err := runTest(test) |
| 265 | results <- result{test, passed, err} |
| 266 | } |
| 267 | } |
| 268 | |
Robert Sloan | 4562e9d | 2017-10-02 10:26:51 -0700 | [diff] [blame] | 269 | func (t test) shortName() string { |
| 270 | return t.args[0] + t.shardMsg() + t.cpuMsg() |
| 271 | } |
| 272 | |
| 273 | func (t test) longName() string { |
| 274 | return strings.Join(t.args, " ") + t.cpuMsg() |
| 275 | } |
| 276 | |
| 277 | func (t test) shardMsg() string { |
| 278 | if t.numShards == 0 { |
| 279 | return "" |
| 280 | } |
| 281 | |
| 282 | return fmt.Sprintf(" [shard %d/%d]", t.shard+1, t.numShards) |
| 283 | } |
| 284 | |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 285 | func (t test) cpuMsg() string { |
| 286 | if len(t.cpu) == 0 { |
| 287 | return "" |
| 288 | } |
| 289 | |
| 290 | return fmt.Sprintf(" (for CPU %q)", t.cpu) |
| 291 | } |
| 292 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 293 | func (t test) getGTestShards() ([]test, error) { |
| 294 | if *numWorkers == 1 || len(t.args) != 1 { |
| 295 | return []test{t}, nil |
| 296 | } |
| 297 | |
| 298 | // Only shard the three GTest-based tests. |
| 299 | if t.args[0] != "crypto/crypto_test" && t.args[0] != "ssl/ssl_test" && t.args[0] != "decrepit/decrepit_test" { |
| 300 | return []test{t}, nil |
| 301 | } |
| 302 | |
| 303 | prog := path.Join(*buildDir, t.args[0]) |
| 304 | cmd := exec.Command(prog, "--gtest_list_tests") |
| 305 | var stdout bytes.Buffer |
| 306 | cmd.Stdout = &stdout |
| 307 | if err := cmd.Start(); err != nil { |
| 308 | return nil, err |
| 309 | } |
| 310 | if err := cmd.Wait(); err != nil { |
| 311 | return nil, err |
| 312 | } |
| 313 | |
| 314 | var group string |
| 315 | var tests []string |
| 316 | scanner := bufio.NewScanner(&stdout) |
| 317 | for scanner.Scan() { |
| 318 | line := scanner.Text() |
| 319 | |
| 320 | // Remove the parameter comment and trailing space. |
| 321 | if idx := strings.Index(line, "#"); idx >= 0 { |
| 322 | line = line[:idx] |
| 323 | } |
| 324 | line = strings.TrimSpace(line) |
| 325 | if len(line) == 0 { |
| 326 | continue |
| 327 | } |
| 328 | |
| 329 | if line[len(line)-1] == '.' { |
| 330 | group = line |
| 331 | continue |
| 332 | } |
| 333 | |
| 334 | if len(group) == 0 { |
| 335 | return nil, fmt.Errorf("found test case %q without group", line) |
| 336 | } |
| 337 | tests = append(tests, group+line) |
| 338 | } |
| 339 | |
| 340 | const testsPerShard = 20 |
| 341 | if len(tests) <= testsPerShard { |
| 342 | return []test{t}, nil |
| 343 | } |
| 344 | |
| 345 | // Slow tests which process large test vector files tend to be grouped |
| 346 | // together, so shuffle the order. |
| 347 | shuffled := make([]string, len(tests)) |
| 348 | perm := rand.Perm(len(tests)) |
| 349 | for i, j := range perm { |
| 350 | shuffled[i] = tests[j] |
| 351 | } |
| 352 | |
| 353 | var shards []test |
| 354 | for i := 0; i < len(shuffled); i += testsPerShard { |
| 355 | n := len(shuffled) - i |
| 356 | if n > testsPerShard { |
| 357 | n = testsPerShard |
| 358 | } |
| 359 | shard := t |
| 360 | shard.args = []string{shard.args[0], "--gtest_filter=" + strings.Join(shuffled[i:i+n], ":")} |
Robert Sloan | 4562e9d | 2017-10-02 10:26:51 -0700 | [diff] [blame] | 361 | shard.shard = len(shards) |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 362 | shards = append(shards, shard) |
| 363 | } |
| 364 | |
Robert Sloan | 4562e9d | 2017-10-02 10:26:51 -0700 | [diff] [blame] | 365 | for i := range shards { |
| 366 | shards[i].numShards = len(shards) |
| 367 | } |
| 368 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 369 | return shards, nil |
| 370 | } |
| 371 | |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 372 | func main() { |
| 373 | flag.Parse() |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 374 | setWorkingDirectory() |
| 375 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 376 | testCases, err := parseTestConfig("util/all_tests.json") |
Kenny Root | b849459 | 2015-09-25 02:29:14 +0000 | [diff] [blame] | 377 | if err != nil { |
| 378 | fmt.Printf("Failed to parse input: %s\n", err) |
| 379 | os.Exit(1) |
| 380 | } |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 381 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 382 | var wg sync.WaitGroup |
| 383 | tests := make(chan test, *numWorkers) |
| 384 | results := make(chan result, *numWorkers) |
| 385 | |
| 386 | for i := 0; i < *numWorkers; i++ { |
| 387 | wg.Add(1) |
| 388 | go worker(tests, results, &wg) |
| 389 | } |
| 390 | |
| 391 | go func() { |
| 392 | for _, test := range testCases { |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 393 | if *useSDE { |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 394 | // SDE generates plenty of tasks and gets slower |
| 395 | // with additional sharding. |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 396 | for _, cpu := range sdeCPUs { |
| 397 | testForCPU := test |
| 398 | testForCPU.cpu = cpu |
| 399 | tests <- testForCPU |
| 400 | } |
Robert Sloan | c9abfe4 | 2018-11-26 12:19:07 -0800 | [diff] [blame^] | 401 | } else if *simulateARMCPUs { |
| 402 | // This mode is run instead of the default path, |
| 403 | // so also include the native flow. |
| 404 | tests <- test |
| 405 | for _, cpu := range armCPUs { |
| 406 | testForCPU := test |
| 407 | testForCPU.cpu = cpu |
| 408 | tests <- testForCPU |
| 409 | } |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 410 | } else { |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 411 | shards, err := test.getGTestShards() |
| 412 | if err != nil { |
| 413 | fmt.Printf("Error listing tests: %s\n", err) |
| 414 | os.Exit(1) |
| 415 | } |
| 416 | for _, shard := range shards { |
| 417 | tests <- shard |
| 418 | } |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 419 | } |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 420 | } |
| 421 | close(tests) |
| 422 | |
| 423 | wg.Wait() |
| 424 | close(results) |
| 425 | }() |
| 426 | |
Robert Sloan | c9abfe4 | 2018-11-26 12:19:07 -0800 | [diff] [blame^] | 427 | testOutput := testresult.NewResults() |
| 428 | var failed, skipped []test |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 429 | for testResult := range results { |
| 430 | test := testResult.Test |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 431 | args := test.args |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 432 | |
Robert Sloan | c9abfe4 | 2018-11-26 12:19:07 -0800 | [diff] [blame^] | 433 | if testResult.Error == errTestSkipped { |
| 434 | fmt.Printf("%s\n", test.longName()) |
| 435 | fmt.Printf("%s was skipped\n", args[0]) |
| 436 | skipped = append(skipped, test) |
| 437 | testOutput.AddSkip(test.longName()) |
| 438 | } else if testResult.Error != nil { |
Robert Sloan | 4562e9d | 2017-10-02 10:26:51 -0700 | [diff] [blame] | 439 | fmt.Printf("%s\n", test.longName()) |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 440 | fmt.Printf("%s failed to complete: %s\n", args[0], testResult.Error) |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 441 | failed = append(failed, test) |
Robert Sloan | c9abfe4 | 2018-11-26 12:19:07 -0800 | [diff] [blame^] | 442 | testOutput.AddResult(test.longName(), "CRASH") |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 443 | } else if !testResult.Passed { |
Robert Sloan | 4562e9d | 2017-10-02 10:26:51 -0700 | [diff] [blame] | 444 | fmt.Printf("%s\n", test.longName()) |
Robert Sloan | 4d1ac50 | 2017-02-06 08:36:14 -0800 | [diff] [blame] | 445 | fmt.Printf("%s failed to print PASS on the last line.\n", args[0]) |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 446 | failed = append(failed, test) |
Robert Sloan | c9abfe4 | 2018-11-26 12:19:07 -0800 | [diff] [blame^] | 447 | testOutput.AddResult(test.longName(), "FAIL") |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 448 | } else { |
Robert Sloan | 4562e9d | 2017-10-02 10:26:51 -0700 | [diff] [blame] | 449 | fmt.Printf("%s\n", test.shortName()) |
Robert Sloan | c9abfe4 | 2018-11-26 12:19:07 -0800 | [diff] [blame^] | 450 | testOutput.AddResult(test.longName(), "PASS") |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 451 | } |
| 452 | } |
| 453 | |
| 454 | if *jsonOutput != "" { |
Robert Sloan | c9abfe4 | 2018-11-26 12:19:07 -0800 | [diff] [blame^] | 455 | if err := testOutput.WriteToFile(*jsonOutput); err != nil { |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 456 | fmt.Fprintf(os.Stderr, "Error: %s\n", err) |
| 457 | } |
| 458 | } |
| 459 | |
Robert Sloan | c9abfe4 | 2018-11-26 12:19:07 -0800 | [diff] [blame^] | 460 | if len(skipped) > 0 { |
| 461 | fmt.Printf("\n%d of %d tests were skipped:\n", len(skipped), len(testCases)) |
| 462 | for _, test := range skipped { |
| 463 | fmt.Printf("\t%s%s\n", strings.Join(test.args, " "), test.cpuMsg()) |
| 464 | } |
| 465 | } |
| 466 | |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 467 | if len(failed) > 0 { |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 468 | fmt.Printf("\n%d of %d tests failed:\n", len(failed), len(testCases)) |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 469 | for _, test := range failed { |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 470 | fmt.Printf("\t%s%s\n", strings.Join(test.args, " "), test.cpuMsg()) |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 471 | } |
| 472 | os.Exit(1) |
| 473 | } |
| 474 | |
| 475 | fmt.Printf("\nAll tests passed!\n") |
| 476 | } |