Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3765)

Unified Diff: base/test/android/multiprocess_test_client_service.cc

Issue 2549363004: Multiprocess test client: Android child process launcher rework. (Closed)
Patch Set: Fixed tests Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/test/android/multiprocess_test_client_service.cc
diff --git a/base/test/android/multiprocess_test_client_service.cc b/base/test/android/multiprocess_test_client_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..50063a9e5b8546d6ff2da70603286afa82bc41e7
--- /dev/null
+++ b/base/test/android/multiprocess_test_client_service.cc
@@ -0,0 +1,68 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/test/android/multiprocess_test_client_service.h"
+
+#include "base/android/jni_array.h"
+#include "base/files/scoped_file.h"
+#include "base/logging.h"
+#include "base/native_library.h"
+#include "base/posix/global_descriptors.h"
+#include "base/test/android/android_main_function_thunk.h"
+#include "jni/MultiprocessTestClientService_jni.h"
+
+namespace base {
+namespace android {
+
+AndroidMainFunctionThunk::MainFuntion g_main_function = nullptr;
+AndroidMainFunctionThunk::AndroidMainFunctionThunk(MainFuntion main_function) {
+ g_main_function = main_function;
+}
+
+bool RegisterMultiprocessTestClientServiceJni(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+// static
+void RunMain(JNIEnv* env,
+ const base::android::JavaParamRef<_jobject*>& jcaller,
+ const base::android::JavaParamRef<jobjectArray>& command_line,
+ const base::android::JavaParamRef<jintArray>& fds_to_map_ids,
+ const base::android::JavaParamRef<jintArray>& fds_to_map_fds) {
+ // Guards against process being reused.
+ // Static variables, singletons, lazy instances make running code again in the
+ // same child process difficult.
+ static bool alreadyRun = false;
+ CHECK(!alreadyRun);
+ alreadyRun = true;
+
+ std::vector<std::string> cpp_command_line;
+ AppendJavaStringArrayToStringVector(env, command_line, &cpp_command_line);
+
+ std::vector<int> fd_ids;
+ base::android::JavaIntArrayToIntVector(env, fds_to_map_ids, &fd_ids);
+ std::vector<int> fd_fds;
+ base::android::JavaIntArrayToIntVector(env, fds_to_map_fds, &fd_fds);
+ DCHECK(fd_ids.size() == fd_fds.size());
+
+ std::vector<base::ScopedFD> fd_scoped_fds;
+ for (size_t i = 0; i < fd_ids.size(); i++) {
+ base::GlobalDescriptors::GetInstance()->Set(fd_ids[i], fd_fds[i]);
+ }
+ std::vector<char*> c_command_line;
+ for (auto& entry : cpp_command_line) {
+ c_command_line.push_back(&entry[0]);
+ }
+
+ // If you hit this CHECK, it means you are using a multiprocess test and not
+ // defining an AndroidMainFunctionThunk to point to your main in your main cc
+ // file (typically run_all_tests.cc).
+ CHECK(g_main_function);
+ int result = g_main_function(c_command_line.size(), &c_command_line[0]);
+
+ Java_MultiprocessTestClientService_setMainReturnValue(env, jcaller, result);
+}
+
+} // namespace android
+} // namespace base

Powered by Google App Engine
This is Rietveld 408576698