diff --git a/util/run_android_tests.go b/util/run_android_tests.go index b0a388f7d..be9e6c6f7 100644 --- a/util/run_android_tests.go +++ b/util/run_android_tests.go @@ -31,10 +31,20 @@ var ( device = flag.String("device", "", "Specifies the device or emulator. See adb's -s argument.") aarch64 = flag.Bool("aarch64", false, "Build the test runners for aarch64 instead of arm.") arm = flag.Int("arm", 7, "Which arm revision to build for.") + suite = flag.String("suite", "all", "Specifies the test suites to run (all, unit, or ssl).") allTestsArgs = flag.String("all-tests-args", "", "Specifies space-separated arguments to pass to all_tests.go") runnerArgs = flag.String("runner-args", "", "Specifies space-separated arguments to pass to ssl/test/runner") + jsonOutput = flag.String("json-output", "", "The file to output JSON results to.") ) +func enableUnitTests() bool { + return *suite == "all" || *suite == "unit" +} + +func enableSSLTests() bool { + return *suite == "all" || *suite == "ssl" +} + func adb(args ...string) error { if len(*device) > 0 { args = append([]string{"-s", *device}, args...) @@ -118,14 +128,14 @@ func copyFile(dst, src string) error { func main() { flag.Parse() - setWorkingDirectory() - tests, err := parseTestConfig("util/all_tests.json") - if err != nil { - fmt.Printf("Failed to parse input: %s\n", err) + if *suite == "all" && *jsonOutput != "" { + fmt.Printf("To use -json-output flag, select only one test suite with -suite.\n") os.Exit(1) } + setWorkingDirectory() + // Clear the target directory. if err := adb("shell", "rm -Rf /data/local/tmp/boringssl-tmp"); err != nil { fmt.Printf("Failed to clear target directory: %s\n", err) @@ -140,26 +150,56 @@ func main() { } defer os.RemoveAll(tmpDir) - seenBinary := make(map[string]struct{}) - binaries := []string{"ssl/test/bssl_shim"} - files := []string{ - "BUILDING.md", - "util/all_tests.json", - "ssl/test/runner/cert.pem", - "ssl/test/runner/channel_id_key.pem", - "ssl/test/runner/ecdsa_cert.pem", - "ssl/test/runner/ecdsa_key.pem", - "ssl/test/runner/key.pem", - } - for _, test := range tests { - if _, ok := seenBinary[test[0]]; !ok { - binaries = append(binaries, test[0]) - seenBinary[test[0]] = struct{}{} + var binaries, files []string + + if enableUnitTests() { + files = append(files, + "util/all_tests.json", + "BUILDING.md", + ) + + tests, err := parseTestConfig("util/all_tests.json") + if err != nil { + fmt.Printf("Failed to parse input: %s\n", err) + os.Exit(1) } - for _, arg := range test[1:] { - if strings.Contains(arg, "/") { - files = append(files, arg) + + seenBinary := make(map[string]struct{}) + for _, test := range tests { + if _, ok := seenBinary[test[0]]; !ok { + binaries = append(binaries, test[0]) + seenBinary[test[0]] = struct{}{} } + for _, arg := range test[1:] { + if strings.Contains(arg, "/") { + files = append(files, arg) + } + } + } + + fmt.Printf("Building all_tests...\n") + if err := goTool("build", "-o", filepath.Join(tmpDir, "util/all_tests"), "util/all_tests.go"); err != nil { + fmt.Printf("Error building all_tests.go: %s\n", err) + os.Exit(1) + } + } + + if enableSSLTests() { + binaries = append(binaries, "ssl/test/bssl_shim") + files = append(files, + "BUILDING.md", + "util/all_tests.json", + "ssl/test/runner/cert.pem", + "ssl/test/runner/channel_id_key.pem", + "ssl/test/runner/ecdsa_cert.pem", + "ssl/test/runner/ecdsa_key.pem", + "ssl/test/runner/key.pem", + ) + + fmt.Printf("Building runner...\n") + if err := goTool("test", "-c", "-o", filepath.Join(tmpDir, "ssl/test/runner/runner"), "./ssl/test/runner/"); err != nil { + fmt.Printf("Error building runner: %s\n", err) + os.Exit(1) } } @@ -179,33 +219,32 @@ func main() { } } - fmt.Printf("Building all_tests...\n") - if err := goTool("build", "-o", filepath.Join(tmpDir, "util/all_tests"), "util/all_tests.go"); err != nil { - fmt.Printf("Error building all_tests.go: %s\n", err) - os.Exit(1) - } - - fmt.Printf("Building runner...\n") - if err := goTool("test", "-c", "-o", filepath.Join(tmpDir, "ssl/test/runner/runner"), "./ssl/test/runner/"); err != nil { - fmt.Printf("Error building runner: %s\n", err) - os.Exit(1) - } - fmt.Printf("Uploading files...\n") if err := adb("push", "-p", tmpDir, "/data/local/tmp/boringssl-tmp"); err != nil { fmt.Printf("Failed to push runner: %s\n", err) os.Exit(1) } - fmt.Printf("Running unit tests...\n") - if err := adb("shell", fmt.Sprintf("cd /data/local/tmp/boringssl-tmp && ./util/all_tests %s", *allTestsArgs)); err != nil { - fmt.Printf("Failed to run unit tests: %s\n", err) - os.Exit(1) + if enableUnitTests() { + fmt.Printf("Running unit tests...\n") + if err := adb("shell", fmt.Sprintf("cd /data/local/tmp/boringssl-tmp && ./util/all_tests -json-output results.json %s", *allTestsArgs)); err != nil { + fmt.Printf("Failed to run unit tests: %s\n", err) + os.Exit(1) + } } - fmt.Printf("Running SSL tests...\n") - if err := adb("shell", fmt.Sprintf("cd /data/local/tmp/boringssl-tmp/ssl/test/runner && ./runner %s", *runnerArgs)); err != nil { - fmt.Printf("Failed to run SSL tests: %s\n", err) - os.Exit(1) + if enableSSLTests() { + fmt.Printf("Running SSL tests...\n") + if err := adb("shell", fmt.Sprintf("cd /data/local/tmp/boringssl-tmp/ssl/test/runner && ./runner -json-output ../../../results.json %s", *runnerArgs)); err != nil { + fmt.Printf("Failed to run SSL tests: %s\n", err) + os.Exit(1) + } + } + + if *jsonOutput != "" { + if err := adb("pull", "-p", "/data/local/tmp/boringssl-tmp/results.json", *jsonOutput); err != nil { + fmt.Printf("Failed to extract results.json: %s\n", err) + os.Exit(1) + } } }