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

Side by Side Diff: testing/android/native_test_launcher.cc

Issue 723343002: Update from https://crrev.com/304121 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
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 // This class sets up the environment for running the native tests inside an 5 // This class sets up the environment for running the native tests inside an
6 // android application. It outputs (to a fifo) markers identifying the 6 // android application. It outputs (to a fifo) markers identifying the
7 // START/PASSED/CRASH of the test suite, FAILURE/SUCCESS of individual tests, 7 // START/PASSED/CRASH of the test suite, FAILURE/SUCCESS of individual tests,
8 // etc. 8 // etc.
9 // These markers are read by the test runner script to generate test results. 9 // These markers are read by the test runner script to generate test results.
10 // It installs signal handlers to detect crashes. 10 // It installs signal handlers to detect crashes.
(...skipping 12 matching lines...) Expand all
23 #include "base/files/file_path.h" 23 #include "base/files/file_path.h"
24 #include "base/files/file_util.h" 24 #include "base/files/file_util.h"
25 #include "base/logging.h" 25 #include "base/logging.h"
26 #include "base/strings/stringprintf.h" 26 #include "base/strings/stringprintf.h"
27 #include "gtest/gtest.h" 27 #include "gtest/gtest.h"
28 #include "jni/ChromeNativeTestActivity_jni.h" 28 #include "jni/ChromeNativeTestActivity_jni.h"
29 #include "testing/android/native_test_util.h" 29 #include "testing/android/native_test_util.h"
30 30
31 using testing::native_test_util::ArgsToArgv; 31 using testing::native_test_util::ArgsToArgv;
32 using testing::native_test_util::ParseArgsFromCommandLineFile; 32 using testing::native_test_util::ParseArgsFromCommandLineFile;
33 using testing::native_test_util::ParseArgsFromString;
33 using testing::native_test_util::ScopedMainEntryLogger; 34 using testing::native_test_util::ScopedMainEntryLogger;
34 35
35 // The main function of the program to be wrapped as a test apk. 36 // The main function of the program to be wrapped as a test apk.
36 extern int main(int argc, char** argv); 37 extern int main(int argc, char** argv);
37 38
38 namespace { 39 namespace {
39 40
40 // These two command line flags are supported for DumpRenderTree, which needs 41 // These two command line flags are supported for DumpRenderTree, which needs
41 // three fifos rather than a combined one: one for stderr, stdin and stdout. 42 // three fifos rather than a combined one: one for stderr, stdin and stdout.
42 const char kSeparateStderrFifo[] = "separate-stderr-fifo"; 43 const char kSeparateStderrFifo[] = "separate-stderr-fifo";
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 111
111 AndroidLog(ANDROID_LOG_ERROR, "Failed to redirect stream to file: %s: %s\n", 112 AndroidLog(ANDROID_LOG_ERROR, "Failed to redirect stream to file: %s: %s\n",
112 path.value().c_str(), strerror(errno)); 113 path.value().c_str(), strerror(errno));
113 exit(EXIT_FAILURE); 114 exit(EXIT_FAILURE);
114 } 115 }
115 116
116 } // namespace 117 } // namespace
117 118
118 static void RunTests(JNIEnv* env, 119 static void RunTests(JNIEnv* env,
119 jobject obj, 120 jobject obj,
121 jstring jcommand_line_flags,
122 jstring jcommand_line_file_path,
120 jstring jfiles_dir, 123 jstring jfiles_dir,
121 jobject app_context) { 124 jobject app_context) {
122 base::AtExitManager exit_manager; 125 base::AtExitManager exit_manager;
123 126
124 // Command line initialized basically, will be fully initialized later. 127 // Command line initialized basically, will be fully initialized later.
125 static const char* const kInitialArgv[] = { "ChromeTestActivity" }; 128 static const char* const kInitialArgv[] = { "ChromeTestActivity" };
126 CommandLine::Init(arraysize(kInitialArgv), kInitialArgv); 129 CommandLine::Init(arraysize(kInitialArgv), kInitialArgv);
127 130
128 // Set the application context in base. 131 // Set the application context in base.
129 base::android::ScopedJavaLocalRef<jobject> scoped_context( 132 base::android::ScopedJavaLocalRef<jobject> scoped_context(
130 env, env->NewLocalRef(app_context)); 133 env, env->NewLocalRef(app_context));
131 base::android::InitApplicationContext(env, scoped_context); 134 base::android::InitApplicationContext(env, scoped_context);
132 base::android::RegisterJni(env); 135 base::android::RegisterJni(env);
133 136
134 std::vector<std::string> args; 137 std::vector<std::string> args;
135 ParseArgsFromCommandLineFile(kCommandLineFilePath, &args); 138
139 const std::string command_line_file_path(
140 base::android::ConvertJavaStringToUTF8(env, jcommand_line_file_path));
141 if (command_line_file_path.empty())
142 ParseArgsFromCommandLineFile(kCommandLineFilePath, &args);
143 else
144 ParseArgsFromCommandLineFile(command_line_file_path.c_str(), &args);
145
146 const std::string command_line_flags(
147 base::android::ConvertJavaStringToUTF8(env, jcommand_line_flags));
148 ParseArgsFromString(command_line_flags, &args);
136 149
137 std::vector<char*> argv; 150 std::vector<char*> argv;
138 int argc = ArgsToArgv(args, &argv); 151 int argc = ArgsToArgv(args, &argv);
139 152
140 // Fully initialize command line with arguments. 153 // Fully initialize command line with arguments.
141 CommandLine::ForCurrentProcess()->AppendArguments( 154 CommandLine::ForCurrentProcess()->AppendArguments(
142 CommandLine(argc, &argv[0]), false); 155 CommandLine(argc, &argv[0]), false);
143 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 156 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
144 157
145 base::FilePath files_dir( 158 base::FilePath files_dir(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 InstallHandlers(); 204 InstallHandlers();
192 205
193 base::android::InitVM(vm); 206 base::android::InitVM(vm);
194 JNIEnv* env = base::android::AttachCurrentThread(); 207 JNIEnv* env = base::android::AttachCurrentThread();
195 if (!RegisterNativesImpl(env)) { 208 if (!RegisterNativesImpl(env)) {
196 return -1; 209 return -1;
197 } 210 }
198 211
199 return JNI_VERSION_1_4; 212 return JNI_VERSION_1_4;
200 } 213 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698