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

Unified Diff: testing/android/native_test/main_runner.cc

Issue 2611323002: Relanding "Multiprocess test client: Android child process launcher rework." (Closed)
Patch Set: Addressed nyquist@'s comment + sync Created 3 years, 11 months 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
« no previous file with comments | « testing/android/native_test/main_runner.h ('k') | testing/android/native_test/native_test_launcher.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: testing/android/native_test/main_runner.cc
diff --git a/testing/android/native_test/main_runner.cc b/testing/android/native_test/main_runner.cc
new file mode 100644
index 0000000000000000000000000000000000000000..629721f79a4c6da703a166a3992ed48776120b13
--- /dev/null
+++ b/testing/android/native_test/main_runner.cc
@@ -0,0 +1,56 @@
+// Copyright 2017 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 <vector>
+
+#include "base/android/jni_array.h"
+#include "base/logging.h"
+#include "base/posix/global_descriptors.h"
+#include "jni/MainRunner_jni.h"
+
+extern int main(int argc, char** argv);
+
+namespace testing {
+namespace android {
+
+bool RegisterMainRunnerJni(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+static jint RunMain(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jclass>& jcaller,
+ const base::android::JavaParamRef<jobjectArray>& command_line,
+ const base::android::JavaParamRef<jintArray>& fds_to_map_keys,
+ const base::android::JavaParamRef<jintArray>& fds_to_map_fds) {
+ // Guards against process being reused.
+ // In most cases, running main again will cause problems (static variables,
+ // singletons, lazy instances won't be in the same state as a clean run).
+ static bool alreadyRun = false;
+ CHECK(!alreadyRun);
+ alreadyRun = true;
+
+ std::vector<int> keys;
+ base::android::JavaIntArrayToIntVector(env, fds_to_map_keys, &keys);
+ std::vector<int> fds;
+ base::android::JavaIntArrayToIntVector(env, fds_to_map_fds, &fds);
+ CHECK_EQ(keys.size(), fds.size());
+
+ for (size_t i = 0; i < keys.size(); i++) {
+ base::GlobalDescriptors::GetInstance()->Set(keys[i], fds[i]);
+ }
+
+ std::vector<std::string> cpp_command_line;
+ AppendJavaStringArrayToStringVector(env, command_line, &cpp_command_line);
+
+ std::vector<char*> c_command_line;
+ for (auto& entry : cpp_command_line) {
+ c_command_line.push_back(&entry[0]);
+ }
+
+ return main(c_command_line.size(), &c_command_line[0]);
+}
+
+} // namespace android
+} // namespace testing
« no previous file with comments | « testing/android/native_test/main_runner.h ('k') | testing/android/native_test/native_test_launcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698