| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/test/multiprocess_test.h" | 5 #include "base/test/multiprocess_test.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/android/context_utils.h" | |
| 11 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| 12 #include "base/android/jni_array.h" | 11 #include "base/android/jni_array.h" |
| 13 #include "base/android/scoped_java_ref.h" | 12 #include "base/android/scoped_java_ref.h" |
| 14 #include "base/base_switches.h" | 13 #include "base/base_switches.h" |
| 15 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 16 #include "base/logging.h" | 15 #include "base/logging.h" |
| 17 #include "jni/MainReturnCodeResult_jni.h" | 16 #include "jni/MainReturnCodeResult_jni.h" |
| 18 #include "jni/MultiprocessTestClientLauncher_jni.h" | 17 #include "jni/MultiprocessTestClientLauncher_jni.h" |
| 19 | 18 |
| 20 namespace base { | 19 namespace base { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 47 base::android::ToJavaIntArray(env, fd_fds)); | 46 base::android::ToJavaIntArray(env, fd_fds)); |
| 48 | 47 |
| 49 CommandLine command_line(base_command_line); | 48 CommandLine command_line(base_command_line); |
| 50 if (!command_line.HasSwitch(switches::kTestChildProcess)) { | 49 if (!command_line.HasSwitch(switches::kTestChildProcess)) { |
| 51 command_line.AppendSwitchASCII(switches::kTestChildProcess, procname); | 50 command_line.AppendSwitchASCII(switches::kTestChildProcess, procname); |
| 52 } | 51 } |
| 53 | 52 |
| 54 android::ScopedJavaLocalRef<jobjectArray> j_argv = | 53 android::ScopedJavaLocalRef<jobjectArray> j_argv = |
| 55 android::ToJavaArrayOfStrings(env, command_line.argv()); | 54 android::ToJavaArrayOfStrings(env, command_line.argv()); |
| 56 jint pid = android::Java_MultiprocessTestClientLauncher_launchClient( | 55 jint pid = android::Java_MultiprocessTestClientLauncher_launchClient( |
| 57 env, android::GetApplicationContext(), j_argv, fds); | 56 env, j_argv, fds); |
| 58 | 57 |
| 59 SpawnChildResult result; | 58 SpawnChildResult result; |
| 60 result.process = Process(pid); | 59 result.process = Process(pid); |
| 61 return result; | 60 return result; |
| 62 } | 61 } |
| 63 | 62 |
| 64 bool WaitForMultiprocessTestChildExit(const Process& process, | 63 bool WaitForMultiprocessTestChildExit(const Process& process, |
| 65 TimeDelta timeout, | 64 TimeDelta timeout, |
| 66 int* exit_code) { | 65 int* exit_code) { |
| 67 JNIEnv* env = android::AttachCurrentThread(); | 66 JNIEnv* env = android::AttachCurrentThread(); |
| 68 DCHECK(env); | 67 DCHECK(env); |
| 69 | 68 |
| 70 base::android::ScopedJavaLocalRef<jobject> result_code = | 69 base::android::ScopedJavaLocalRef<jobject> result_code = |
| 71 android::Java_MultiprocessTestClientLauncher_waitForMainToReturn( | 70 android::Java_MultiprocessTestClientLauncher_waitForMainToReturn( |
| 72 env, android::GetApplicationContext(), process.Pid(), | 71 env, process.Pid(), static_cast<int32_t>(timeout.InMilliseconds())); |
| 73 static_cast<int32_t>(timeout.InMilliseconds())); | |
| 74 if (result_code.is_null() || | 72 if (result_code.is_null() || |
| 75 Java_MainReturnCodeResult_hasTimedOut(env, result_code)) { | 73 Java_MainReturnCodeResult_hasTimedOut(env, result_code)) { |
| 76 return false; | 74 return false; |
| 77 } | 75 } |
| 78 if (exit_code) { | 76 if (exit_code) { |
| 79 *exit_code = Java_MainReturnCodeResult_getReturnCode(env, result_code); | 77 *exit_code = Java_MainReturnCodeResult_getReturnCode(env, result_code); |
| 80 } | 78 } |
| 81 return true; | 79 return true; |
| 82 } | 80 } |
| 83 | 81 |
| 84 bool TerminateMultiProcessTestChild(const Process& process, | 82 bool TerminateMultiProcessTestChild(const Process& process, |
| 85 int exit_code, | 83 int exit_code, |
| 86 bool wait) { | 84 bool wait) { |
| 87 JNIEnv* env = android::AttachCurrentThread(); | 85 JNIEnv* env = android::AttachCurrentThread(); |
| 88 DCHECK(env); | 86 DCHECK(env); |
| 89 | 87 |
| 90 return android::Java_MultiprocessTestClientLauncher_terminate( | 88 return android::Java_MultiprocessTestClientLauncher_terminate( |
| 91 env, android::GetApplicationContext(), process.Pid(), exit_code, wait); | 89 env, process.Pid(), exit_code, wait); |
| 92 } | 90 } |
| 93 | 91 |
| 94 } // namespace base | 92 } // namespace base |
| OLD | NEW |