David Benjamin | af18cdd | 2016-04-23 01:40:03 -0400 | [diff] [blame] | 1 | // Copyright (c) 2016, 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 |
David Benjamin | 0d1b096 | 2016-08-01 09:50:57 -0400 | [diff] [blame] | 13 | // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
David Benjamin | af18cdd | 2016-04-23 01:40:03 -0400 | [diff] [blame] | 14 | |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 15 | package main |
| 16 | |
| 17 | import ( |
David Benjamin | 9351266 | 2020-01-12 10:43:04 -0500 | [diff] [blame] | 18 | "bufio" |
David Benjamin | ed9c8fc | 2016-06-08 09:40:32 -0400 | [diff] [blame] | 19 | "bytes" |
David Benjamin | 9351266 | 2020-01-12 10:43:04 -0500 | [diff] [blame] | 20 | "errors" |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 21 | "flag" |
| 22 | "fmt" |
| 23 | "io" |
| 24 | "io/ioutil" |
| 25 | "os" |
| 26 | "os/exec" |
| 27 | "path/filepath" |
David Benjamin | 9351266 | 2020-01-12 10:43:04 -0500 | [diff] [blame] | 28 | "runtime" |
David Benjamin | ed9c8fc | 2016-06-08 09:40:32 -0400 | [diff] [blame] | 29 | "strconv" |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 30 | "strings" |
David Benjamin | aadb463 | 2020-01-16 18:25:37 -0500 | [diff] [blame] | 31 | |
| 32 | "boringssl.googlesource.com/boringssl/util/testconfig" |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 33 | ) |
| 34 | |
| 35 | var ( |
| 36 | buildDir = flag.String("build-dir", "build", "Specifies the build directory to push.") |
David Benjamin | 00b1069 | 2016-05-19 00:13:22 -0400 | [diff] [blame] | 37 | adbPath = flag.String("adb", "adb", "Specifies the adb binary to use. Defaults to looking in PATH.") |
David Benjamin | 9351266 | 2020-01-12 10:43:04 -0500 | [diff] [blame] | 38 | ndkPath = flag.String("ndk", "", "Specifies the path to the NDK installation. Defaults to detecting from the build directory.") |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 39 | device = flag.String("device", "", "Specifies the device or emulator. See adb's -s argument.") |
David Benjamin | 9351266 | 2020-01-12 10:43:04 -0500 | [diff] [blame] | 40 | abi = flag.String("abi", "", "Specifies the Android ABI to use when building Go tools. Defaults to detecting from the build directory.") |
| 41 | apiLevel = flag.Int("api-level", 0, "Specifies the Android API level to use when building Go tools. Defaults to detecting from the build directory.") |
David Benjamin | 8de8b3d | 2016-05-12 23:07:47 -0400 | [diff] [blame] | 42 | suite = flag.String("suite", "all", "Specifies the test suites to run (all, unit, or ssl).") |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 43 | allTestsArgs = flag.String("all-tests-args", "", "Specifies space-separated arguments to pass to all_tests.go") |
| 44 | runnerArgs = flag.String("runner-args", "", "Specifies space-separated arguments to pass to ssl/test/runner") |
David Benjamin | 8de8b3d | 2016-05-12 23:07:47 -0400 | [diff] [blame] | 45 | jsonOutput = flag.String("json-output", "", "The file to output JSON results to.") |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 46 | ) |
| 47 | |
David Benjamin | 8de8b3d | 2016-05-12 23:07:47 -0400 | [diff] [blame] | 48 | func enableUnitTests() bool { |
| 49 | return *suite == "all" || *suite == "unit" |
| 50 | } |
| 51 | |
| 52 | func enableSSLTests() bool { |
| 53 | return *suite == "all" || *suite == "ssl" |
| 54 | } |
| 55 | |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 56 | func adb(args ...string) error { |
| 57 | if len(*device) > 0 { |
| 58 | args = append([]string{"-s", *device}, args...) |
| 59 | } |
David Benjamin | 00b1069 | 2016-05-19 00:13:22 -0400 | [diff] [blame] | 60 | cmd := exec.Command(*adbPath, args...) |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 61 | cmd.Stdout = os.Stdout |
| 62 | cmd.Stderr = os.Stderr |
| 63 | return cmd.Run() |
| 64 | } |
| 65 | |
David Benjamin | ed9c8fc | 2016-06-08 09:40:32 -0400 | [diff] [blame] | 66 | func adbShell(shellCmd string) (int, error) { |
| 67 | var args []string |
| 68 | if len(*device) > 0 { |
| 69 | args = append([]string{"-s", *device}, args...) |
| 70 | } |
| 71 | args = append(args, "shell") |
| 72 | |
| 73 | const delimiter = "___EXIT_CODE___" |
| 74 | |
| 75 | // Older versions of adb and Android do not preserve the exit |
| 76 | // code, so work around this. |
| 77 | // https://code.google.com/p/android/issues/detail?id=3254 |
| 78 | shellCmd += "; echo " + delimiter + " $?" |
| 79 | args = append(args, shellCmd) |
| 80 | |
| 81 | cmd := exec.Command(*adbPath, args...) |
| 82 | stdout, err := cmd.StdoutPipe() |
| 83 | if err != nil { |
| 84 | return 0, err |
| 85 | } |
| 86 | cmd.Stderr = os.Stderr |
| 87 | if err := cmd.Start(); err != nil { |
| 88 | return 0, err |
| 89 | } |
| 90 | |
| 91 | var stdoutBytes bytes.Buffer |
| 92 | for { |
| 93 | var buf [1024]byte |
| 94 | n, err := stdout.Read(buf[:]) |
| 95 | stdoutBytes.Write(buf[:n]) |
| 96 | os.Stdout.Write(buf[:n]) |
| 97 | if err != nil { |
| 98 | break |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | if err := cmd.Wait(); err != nil { |
| 103 | return 0, err |
| 104 | } |
| 105 | |
| 106 | stdoutStr := stdoutBytes.String() |
| 107 | idx := strings.LastIndex(stdoutStr, delimiter) |
| 108 | if idx < 0 { |
| 109 | return 0, fmt.Errorf("Could not find delimiter in output.") |
| 110 | } |
| 111 | |
| 112 | return strconv.Atoi(strings.TrimSpace(stdoutStr[idx+len(delimiter):])) |
| 113 | } |
| 114 | |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 115 | func goTool(args ...string) error { |
| 116 | cmd := exec.Command("go", args...) |
| 117 | cmd.Stdout = os.Stdout |
| 118 | cmd.Stderr = os.Stderr |
| 119 | |
David Benjamin | 1147be0 | 2016-05-19 13:23:11 -0400 | [diff] [blame] | 120 | cmd.Env = os.Environ() |
David Benjamin | 9351266 | 2020-01-12 10:43:04 -0500 | [diff] [blame] | 121 | |
| 122 | // The NDK includes the host platform in the toolchain path. |
| 123 | var ndkOS, ndkArch string |
| 124 | switch runtime.GOOS { |
| 125 | case "linux": |
| 126 | ndkOS = "linux" |
| 127 | default: |
| 128 | return fmt.Errorf("unknown host OS: %q", runtime.GOOS) |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 129 | } |
David Benjamin | 9351266 | 2020-01-12 10:43:04 -0500 | [diff] [blame] | 130 | switch runtime.GOARCH { |
| 131 | case "amd64": |
| 132 | ndkArch = "x86_64" |
| 133 | default: |
| 134 | return fmt.Errorf("unknown host architecture: %q", runtime.GOARCH) |
| 135 | } |
| 136 | ndkHost := ndkOS + "-" + ndkArch |
| 137 | |
| 138 | // Use the NDK's target-prefixed clang wrappers, so cgo gets the right |
| 139 | // flags. See https://developer.android.com/ndk/guides/cmake#android_abi for |
| 140 | // Android ABIs. |
| 141 | var targetPrefix string |
| 142 | switch *abi { |
| 143 | case "armeabi-v7a", "armeabi-v7a with NEON": |
| 144 | targetPrefix = fmt.Sprintf("armv7a-linux-androideabi%d-", *apiLevel) |
| 145 | cmd.Env = append(cmd.Env, "GOARCH=arm") |
| 146 | cmd.Env = append(cmd.Env, "GOARM=7") |
| 147 | case "arm64-v8a": |
| 148 | targetPrefix = fmt.Sprintf("aarch64-linux-android%d-", *apiLevel) |
| 149 | cmd.Env = append(cmd.Env, "GOARCH=arm64") |
| 150 | default: |
| 151 | fmt.Errorf("unknown Android ABI: %q", *abi) |
| 152 | } |
| 153 | |
| 154 | // Go's Android support requires cgo and compilers from the NDK. See |
| 155 | // https://golang.org/misc/android/README, though note CC_FOR_TARGET only |
| 156 | // works when building Go itself. go build only looks at CC. |
| 157 | cmd.Env = append(cmd.Env, "CGO_ENABLED=1") |
| 158 | cmd.Env = append(cmd.Env, "GOOS=android") |
| 159 | toolchainDir := filepath.Join(*ndkPath, "toolchains", "llvm", "prebuilt", ndkHost, "bin") |
| 160 | cmd.Env = append(cmd.Env, fmt.Sprintf("CC=%s", filepath.Join(toolchainDir, targetPrefix+"clang"))) |
| 161 | cmd.Env = append(cmd.Env, fmt.Sprintf("CXX=%s", filepath.Join(toolchainDir, targetPrefix+"clang++"))) |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 162 | return cmd.Run() |
| 163 | } |
| 164 | |
| 165 | // setWorkingDirectory walks up directories as needed until the current working |
| 166 | // directory is the top of a BoringSSL checkout. |
| 167 | func setWorkingDirectory() { |
| 168 | for i := 0; i < 64; i++ { |
| 169 | if _, err := os.Stat("BUILDING.md"); err == nil { |
| 170 | return |
| 171 | } |
| 172 | os.Chdir("..") |
| 173 | } |
| 174 | |
| 175 | panic("Couldn't find BUILDING.md in a parent directory!") |
| 176 | } |
| 177 | |
David Benjamin | 9351266 | 2020-01-12 10:43:04 -0500 | [diff] [blame] | 178 | func detectOptionsFromCMake() error { |
| 179 | if len(*ndkPath) != 0 && len(*abi) != 0 && *apiLevel != 0 { |
| 180 | // No need to parse options from CMake. |
| 181 | return nil |
| 182 | } |
| 183 | |
| 184 | cmakeCache, err := os.Open(filepath.Join(*buildDir, "CMakeCache.txt")) |
| 185 | if err != nil { |
| 186 | return err |
| 187 | } |
| 188 | defer cmakeCache.Close() |
| 189 | |
| 190 | cmakeVars := make(map[string]string) |
| 191 | scanner := bufio.NewScanner(cmakeCache) |
| 192 | for scanner.Scan() { |
| 193 | line := scanner.Text() |
| 194 | if idx := strings.IndexByte(line, '#'); idx >= 0 { |
| 195 | line = line[:idx] |
| 196 | } |
| 197 | if idx := strings.Index(line, "//"); idx >= 0 { |
| 198 | line = line[:idx] |
| 199 | } |
| 200 | // The syntax for each line is KEY:TYPE=VALUE. |
| 201 | equals := strings.IndexByte(line, '=') |
| 202 | if equals < 0 { |
| 203 | continue |
| 204 | } |
| 205 | name := line[:equals] |
| 206 | value := line[equals+1:] |
| 207 | if idx := strings.IndexByte(name, ':'); idx >= 0 { |
| 208 | name = name[:idx] |
| 209 | } |
| 210 | cmakeVars[name] = value |
| 211 | } |
| 212 | if err := scanner.Err(); err != nil { |
| 213 | return err |
| 214 | } |
| 215 | |
| 216 | if len(*ndkPath) == 0 { |
David Benjamin | f50a8a7 | 2020-01-13 18:14:07 -0500 | [diff] [blame] | 217 | if ndk, ok := cmakeVars["ANDROID_NDK"]; ok { |
| 218 | *ndkPath = ndk |
| 219 | } else if toolchainFile, ok := cmakeVars["CMAKE_TOOLCHAIN_FILE"]; ok { |
| 220 | // The toolchain is at build/cmake/android.toolchain.cmake under the NDK. |
| 221 | *ndkPath = filepath.Dir(filepath.Dir(filepath.Dir(toolchainFile))) |
| 222 | } else { |
| 223 | return errors.New("Neither CMAKE_TOOLCHAIN_FILE nor ANDROID_NDK found in CMakeCache.txt") |
David Benjamin | 9351266 | 2020-01-12 10:43:04 -0500 | [diff] [blame] | 224 | } |
| 225 | fmt.Printf("Detected NDK path %q from CMakeCache.txt.\n", *ndkPath) |
| 226 | } |
| 227 | if len(*abi) == 0 { |
| 228 | var ok bool |
| 229 | if *abi, ok = cmakeVars["ANDROID_ABI"]; !ok { |
| 230 | return errors.New("ANDROID_ABI not found in CMakeCache.txt") |
| 231 | } |
| 232 | fmt.Printf("Detected ABI %q from CMakeCache.txt.\n", *abi) |
| 233 | } |
| 234 | if *apiLevel == 0 { |
| 235 | apiLevelStr, ok := cmakeVars["ANDROID_NATIVE_API_LEVEL"] |
| 236 | if !ok { |
| 237 | return errors.New("ANDROID_NATIVE_API_LEVEL not found in CMakeCache.txt") |
| 238 | } |
| 239 | var err error |
| 240 | if *apiLevel, err = strconv.Atoi(apiLevelStr); err != nil { |
| 241 | return fmt.Errorf("error parsing ANDROID_NATIVE_API_LEVEL: %s", err) |
| 242 | } |
| 243 | fmt.Printf("Detected API level %d from CMakeCache.txt.\n", *apiLevel) |
| 244 | } |
| 245 | return nil |
| 246 | } |
| 247 | |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 248 | func copyFile(dst, src string) error { |
| 249 | srcFile, err := os.Open(src) |
| 250 | if err != nil { |
| 251 | return err |
| 252 | } |
| 253 | defer srcFile.Close() |
| 254 | |
| 255 | srcInfo, err := srcFile.Stat() |
| 256 | if err != nil { |
| 257 | return err |
| 258 | } |
| 259 | |
| 260 | dir := filepath.Dir(dst) |
| 261 | if err := os.MkdirAll(dir, 0777); err != nil { |
| 262 | return err |
| 263 | } |
| 264 | |
| 265 | dstFile, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY, srcInfo.Mode()) |
| 266 | if err != nil { |
| 267 | return err |
| 268 | } |
| 269 | defer dstFile.Close() |
| 270 | |
| 271 | _, err = io.Copy(dstFile, srcFile) |
| 272 | return err |
| 273 | } |
| 274 | |
| 275 | func main() { |
| 276 | flag.Parse() |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 277 | |
David Benjamin | 8de8b3d | 2016-05-12 23:07:47 -0400 | [diff] [blame] | 278 | if *suite == "all" && *jsonOutput != "" { |
| 279 | fmt.Printf("To use -json-output flag, select only one test suite with -suite.\n") |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 280 | os.Exit(1) |
| 281 | } |
| 282 | |
David Benjamin | 8de8b3d | 2016-05-12 23:07:47 -0400 | [diff] [blame] | 283 | setWorkingDirectory() |
David Benjamin | 9351266 | 2020-01-12 10:43:04 -0500 | [diff] [blame] | 284 | if err := detectOptionsFromCMake(); err != nil { |
| 285 | fmt.Printf("Error reading options from CMake: %s.\n", err) |
| 286 | os.Exit(1) |
| 287 | } |
David Benjamin | 8de8b3d | 2016-05-12 23:07:47 -0400 | [diff] [blame] | 288 | |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 289 | // Clear the target directory. |
| 290 | if err := adb("shell", "rm -Rf /data/local/tmp/boringssl-tmp"); err != nil { |
| 291 | fmt.Printf("Failed to clear target directory: %s\n", err) |
| 292 | os.Exit(1) |
| 293 | } |
| 294 | |
| 295 | // Stage everything in a temporary directory. |
| 296 | tmpDir, err := ioutil.TempDir("", "boringssl-android") |
| 297 | if err != nil { |
| 298 | fmt.Printf("Error making temporary directory: %s\n", err) |
| 299 | os.Exit(1) |
| 300 | } |
| 301 | defer os.RemoveAll(tmpDir) |
| 302 | |
David Benjamin | 8de8b3d | 2016-05-12 23:07:47 -0400 | [diff] [blame] | 303 | var binaries, files []string |
| 304 | |
| 305 | if enableUnitTests() { |
| 306 | files = append(files, |
| 307 | "util/all_tests.json", |
| 308 | "BUILDING.md", |
| 309 | ) |
| 310 | |
David Benjamin | aadb463 | 2020-01-16 18:25:37 -0500 | [diff] [blame] | 311 | tests, err := testconfig.ParseTestConfig("util/all_tests.json") |
David Benjamin | 8de8b3d | 2016-05-12 23:07:47 -0400 | [diff] [blame] | 312 | if err != nil { |
| 313 | fmt.Printf("Failed to parse input: %s\n", err) |
| 314 | os.Exit(1) |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 315 | } |
David Benjamin | 8de8b3d | 2016-05-12 23:07:47 -0400 | [diff] [blame] | 316 | |
| 317 | seenBinary := make(map[string]struct{}) |
| 318 | for _, test := range tests { |
David Benjamin | aadb463 | 2020-01-16 18:25:37 -0500 | [diff] [blame] | 319 | if _, ok := seenBinary[test.Cmd[0]]; !ok { |
| 320 | binaries = append(binaries, test.Cmd[0]) |
| 321 | seenBinary[test.Cmd[0]] = struct{}{} |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 322 | } |
David Benjamin | aadb463 | 2020-01-16 18:25:37 -0500 | [diff] [blame] | 323 | for _, arg := range test.Cmd[1:] { |
David Benjamin | 8de8b3d | 2016-05-12 23:07:47 -0400 | [diff] [blame] | 324 | if strings.Contains(arg, "/") { |
| 325 | files = append(files, arg) |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | fmt.Printf("Building all_tests...\n") |
| 331 | if err := goTool("build", "-o", filepath.Join(tmpDir, "util/all_tests"), "util/all_tests.go"); err != nil { |
| 332 | fmt.Printf("Error building all_tests.go: %s\n", err) |
| 333 | os.Exit(1) |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | if enableSSLTests() { |
| 338 | binaries = append(binaries, "ssl/test/bssl_shim") |
| 339 | files = append(files, |
| 340 | "BUILDING.md", |
David Benjamin | 8de8b3d | 2016-05-12 23:07:47 -0400 | [diff] [blame] | 341 | "ssl/test/runner/cert.pem", |
| 342 | "ssl/test/runner/channel_id_key.pem", |
David Benjamin | 218f51b | 2017-02-27 16:41:47 -0500 | [diff] [blame] | 343 | "ssl/test/runner/ecdsa_p224_cert.pem", |
| 344 | "ssl/test/runner/ecdsa_p224_key.pem", |
David Benjamin | 0c22295 | 2016-07-12 15:08:24 -0400 | [diff] [blame] | 345 | "ssl/test/runner/ecdsa_p256_cert.pem", |
| 346 | "ssl/test/runner/ecdsa_p256_key.pem", |
| 347 | "ssl/test/runner/ecdsa_p384_cert.pem", |
| 348 | "ssl/test/runner/ecdsa_p384_key.pem", |
| 349 | "ssl/test/runner/ecdsa_p521_cert.pem", |
| 350 | "ssl/test/runner/ecdsa_p521_key.pem", |
David Benjamin | 0ef8c7b | 2017-04-06 11:48:59 -0400 | [diff] [blame] | 351 | "ssl/test/runner/ed25519_cert.pem", |
| 352 | "ssl/test/runner/ed25519_key.pem", |
David Benjamin | 8de8b3d | 2016-05-12 23:07:47 -0400 | [diff] [blame] | 353 | "ssl/test/runner/key.pem", |
David Benjamin | 7944a9f | 2016-07-12 22:27:01 -0400 | [diff] [blame] | 354 | "ssl/test/runner/rsa_1024_cert.pem", |
| 355 | "ssl/test/runner/rsa_1024_key.pem", |
David Benjamin | e8b554d | 2016-11-15 10:43:13 +0900 | [diff] [blame] | 356 | "ssl/test/runner/rsa_chain_cert.pem", |
| 357 | "ssl/test/runner/rsa_chain_key.pem", |
| 358 | "util/all_tests.json", |
David Benjamin | 8de8b3d | 2016-05-12 23:07:47 -0400 | [diff] [blame] | 359 | ) |
| 360 | |
| 361 | fmt.Printf("Building runner...\n") |
| 362 | if err := goTool("test", "-c", "-o", filepath.Join(tmpDir, "ssl/test/runner/runner"), "./ssl/test/runner/"); err != nil { |
| 363 | fmt.Printf("Error building runner: %s\n", err) |
| 364 | os.Exit(1) |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | |
David Benjamin | 7458ded | 2019-10-11 17:05:20 -0400 | [diff] [blame] | 368 | var libraries []string |
| 369 | if _, err := os.Stat(filepath.Join(*buildDir, "crypto/libcrypto.so")); err == nil { |
| 370 | libraries = []string{ |
| 371 | "libboringssl_gtest.so", |
| 372 | "crypto/libcrypto.so", |
| 373 | "decrepit/libdecrepit.so", |
| 374 | "ssl/libssl.so", |
| 375 | } |
| 376 | } else if !os.IsNotExist(err) { |
| 377 | fmt.Printf("Failed to stat crypto/libcrypto.so: %s\n", err) |
| 378 | os.Exit(1) |
| 379 | } |
| 380 | |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 381 | fmt.Printf("Copying test binaries...\n") |
| 382 | for _, binary := range binaries { |
| 383 | if err := copyFile(filepath.Join(tmpDir, "build", binary), filepath.Join(*buildDir, binary)); err != nil { |
| 384 | fmt.Printf("Failed to copy %s: %s\n", binary, err) |
| 385 | os.Exit(1) |
| 386 | } |
| 387 | } |
| 388 | |
David Benjamin | 7458ded | 2019-10-11 17:05:20 -0400 | [diff] [blame] | 389 | var envPrefix string |
| 390 | if len(libraries) > 0 { |
| 391 | fmt.Printf("Copying libraries...\n") |
| 392 | for _, library := range libraries { |
| 393 | // Place all the libraries in a common directory so they |
| 394 | // can be passed to LD_LIBRARY_PATH once. |
| 395 | if err := copyFile(filepath.Join(tmpDir, "build", "lib", filepath.Base(library)), filepath.Join(*buildDir, library)); err != nil { |
| 396 | fmt.Printf("Failed to copy %s: %s\n", library, err) |
| 397 | os.Exit(1) |
| 398 | } |
| 399 | } |
| 400 | envPrefix = "env LD_LIBRARY_PATH=/data/local/tmp/boringssl-tmp/build/lib " |
| 401 | } |
| 402 | |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 403 | fmt.Printf("Copying data files...\n") |
| 404 | for _, file := range files { |
| 405 | if err := copyFile(filepath.Join(tmpDir, file), file); err != nil { |
| 406 | fmt.Printf("Failed to copy %s: %s\n", file, err) |
| 407 | os.Exit(1) |
| 408 | } |
| 409 | } |
| 410 | |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 411 | fmt.Printf("Uploading files...\n") |
| 412 | if err := adb("push", "-p", tmpDir, "/data/local/tmp/boringssl-tmp"); err != nil { |
| 413 | fmt.Printf("Failed to push runner: %s\n", err) |
| 414 | os.Exit(1) |
| 415 | } |
| 416 | |
David Benjamin | ed9c8fc | 2016-06-08 09:40:32 -0400 | [diff] [blame] | 417 | var unitTestExit int |
David Benjamin | 8de8b3d | 2016-05-12 23:07:47 -0400 | [diff] [blame] | 418 | if enableUnitTests() { |
| 419 | fmt.Printf("Running unit tests...\n") |
David Benjamin | 7458ded | 2019-10-11 17:05:20 -0400 | [diff] [blame] | 420 | unitTestExit, err = adbShell(fmt.Sprintf("cd /data/local/tmp/boringssl-tmp && %s./util/all_tests -json-output results.json %s", envPrefix, *allTestsArgs)) |
David Benjamin | ed9c8fc | 2016-06-08 09:40:32 -0400 | [diff] [blame] | 421 | if err != nil { |
David Benjamin | 8de8b3d | 2016-05-12 23:07:47 -0400 | [diff] [blame] | 422 | fmt.Printf("Failed to run unit tests: %s\n", err) |
| 423 | os.Exit(1) |
| 424 | } |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 425 | } |
| 426 | |
David Benjamin | ed9c8fc | 2016-06-08 09:40:32 -0400 | [diff] [blame] | 427 | var sslTestExit int |
David Benjamin | 8de8b3d | 2016-05-12 23:07:47 -0400 | [diff] [blame] | 428 | if enableSSLTests() { |
| 429 | fmt.Printf("Running SSL tests...\n") |
David Benjamin | 7458ded | 2019-10-11 17:05:20 -0400 | [diff] [blame] | 430 | sslTestExit, err = adbShell(fmt.Sprintf("cd /data/local/tmp/boringssl-tmp/ssl/test/runner && %s./runner -json-output ../../../results.json %s", envPrefix, *runnerArgs)) |
David Benjamin | ed9c8fc | 2016-06-08 09:40:32 -0400 | [diff] [blame] | 431 | if err != nil { |
David Benjamin | 8de8b3d | 2016-05-12 23:07:47 -0400 | [diff] [blame] | 432 | fmt.Printf("Failed to run SSL tests: %s\n", err) |
| 433 | os.Exit(1) |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | if *jsonOutput != "" { |
| 438 | if err := adb("pull", "-p", "/data/local/tmp/boringssl-tmp/results.json", *jsonOutput); err != nil { |
| 439 | fmt.Printf("Failed to extract results.json: %s\n", err) |
| 440 | os.Exit(1) |
| 441 | } |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 442 | } |
David Benjamin | ed9c8fc | 2016-06-08 09:40:32 -0400 | [diff] [blame] | 443 | |
| 444 | if unitTestExit != 0 { |
| 445 | os.Exit(unitTestExit) |
| 446 | } |
| 447 | |
| 448 | if sslTestExit != 0 { |
| 449 | os.Exit(sslTestExit) |
| 450 | } |
David Benjamin | f945952d | 2016-03-07 15:30:26 -0500 | [diff] [blame] | 451 | } |