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 // 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. |
11 | 11 |
12 #include <android/log.h> | 12 #include <android/log.h> |
13 #include <signal.h> | 13 #include <signal.h> |
14 | 14 |
15 #include "base/android/base_jni_registrar.h" | 15 #include "base/android/base_jni_registrar.h" |
16 #include "base/android/context_utils.h" | 16 #include "base/android/context_utils.h" |
17 #include "base/android/fifo_utils.h" | 17 #include "base/android/fifo_utils.h" |
18 #include "base/android/jni_string.h" | 18 #include "base/android/jni_string.h" |
19 #include "base/android/scoped_java_ref.h" | 19 #include "base/android/scoped_java_ref.h" |
20 #include "base/at_exit.h" | 20 #include "base/at_exit.h" |
21 #include "base/base_switches.h" | 21 #include "base/base_switches.h" |
22 #include "base/command_line.h" | 22 #include "base/command_line.h" |
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 "base/test/test_support_android.h" |
27 #include "gtest/gtest.h" | 28 #include "gtest/gtest.h" |
28 #include "jni/NativeTest_jni.h" | 29 #include "jni/NativeTest_jni.h" |
29 #include "testing/android/native_test/native_test_util.h" | 30 #include "testing/android/native_test/native_test_util.h" |
30 | 31 |
31 // The main function of the program to be wrapped as a test apk. | 32 // The main function of the program to be wrapped as a test apk. |
32 extern int main(int argc, char** argv); | 33 extern int main(int argc, char** argv); |
33 | 34 |
34 namespace testing { | 35 namespace testing { |
35 namespace android { | 36 namespace android { |
36 | 37 |
(...skipping 26 matching lines...) Expand all Loading... |
63 } | 64 } |
64 | 65 |
65 } // namespace | 66 } // namespace |
66 | 67 |
67 static void RunTests(JNIEnv* env, | 68 static void RunTests(JNIEnv* env, |
68 const JavaParamRef<jobject>& obj, | 69 const JavaParamRef<jobject>& obj, |
69 const JavaParamRef<jstring>& jcommand_line_flags, | 70 const JavaParamRef<jstring>& jcommand_line_flags, |
70 const JavaParamRef<jstring>& jcommand_line_file_path, | 71 const JavaParamRef<jstring>& jcommand_line_file_path, |
71 const JavaParamRef<jstring>& jstdout_file_path, | 72 const JavaParamRef<jstring>& jstdout_file_path, |
72 jboolean jstdout_fifo, | 73 jboolean jstdout_fifo, |
73 const JavaParamRef<jobject>& app_context) { | 74 const JavaParamRef<jobject>& app_context, |
| 75 const JavaParamRef<jstring>& jtest_data_dir) { |
74 // Command line initialized basically, will be fully initialized later. | 76 // Command line initialized basically, will be fully initialized later. |
75 static const char* const kInitialArgv[] = { "ChromeTestActivity" }; | 77 static const char* const kInitialArgv[] = { "ChromeTestActivity" }; |
76 base::CommandLine::Init(arraysize(kInitialArgv), kInitialArgv); | 78 base::CommandLine::Init(arraysize(kInitialArgv), kInitialArgv); |
77 | 79 |
78 std::vector<std::string> args; | 80 std::vector<std::string> args; |
79 | 81 |
80 const std::string command_line_file_path( | 82 const std::string command_line_file_path( |
81 base::android::ConvertJavaStringToUTF8(env, jcommand_line_file_path)); | 83 base::android::ConvertJavaStringToUTF8(env, jcommand_line_file_path)); |
82 if (command_line_file_path.empty()) | 84 if (command_line_file_path.empty()) |
83 args.push_back("_"); | 85 args.push_back("_"); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 } | 119 } |
118 dup2(STDOUT_FILENO, STDERR_FILENO); | 120 dup2(STDOUT_FILENO, STDERR_FILENO); |
119 | 121 |
120 if (command_line.HasSwitch(switches::kWaitForDebugger)) { | 122 if (command_line.HasSwitch(switches::kWaitForDebugger)) { |
121 AndroidLog(ANDROID_LOG_VERBOSE, | 123 AndroidLog(ANDROID_LOG_VERBOSE, |
122 "Native test waiting for GDB because flag %s was supplied", | 124 "Native test waiting for GDB because flag %s was supplied", |
123 switches::kWaitForDebugger); | 125 switches::kWaitForDebugger); |
124 base::debug::WaitForDebugger(24 * 60 * 60, false); | 126 base::debug::WaitForDebugger(24 * 60 * 60, false); |
125 } | 127 } |
126 | 128 |
| 129 base::FilePath test_data_dir( |
| 130 base::android::ConvertJavaStringToUTF8(env, jtest_data_dir)); |
| 131 base::InitAndroidTestPaths(test_data_dir); |
| 132 |
127 ScopedMainEntryLogger scoped_main_entry_logger; | 133 ScopedMainEntryLogger scoped_main_entry_logger; |
128 main(argc, &argv[0]); | 134 main(argc, &argv[0]); |
129 } | 135 } |
130 | 136 |
131 bool RegisterNativeTestJNI(JNIEnv* env) { | 137 bool RegisterNativeTestJNI(JNIEnv* env) { |
132 if (!base::android::RegisterJni(env)) { | 138 if (!base::android::RegisterJni(env)) { |
133 return false; | 139 return false; |
134 } | 140 } |
135 return RegisterNativesImpl(env); | 141 return RegisterNativesImpl(env); |
136 } | 142 } |
137 | 143 |
138 // TODO(nileshagrawal): now that we're using FIFO, test scripts can detect EOF. | 144 // TODO(nileshagrawal): now that we're using FIFO, test scripts can detect EOF. |
139 // Remove the signal handlers. | 145 // Remove the signal handlers. |
140 void InstallHandlers() { | 146 void InstallHandlers() { |
141 struct sigaction sa; | 147 struct sigaction sa; |
142 memset(&sa, 0, sizeof(sa)); | 148 memset(&sa, 0, sizeof(sa)); |
143 | 149 |
144 sa.sa_sigaction = SignalHandler; | 150 sa.sa_sigaction = SignalHandler; |
145 sa.sa_flags = SA_SIGINFO; | 151 sa.sa_flags = SA_SIGINFO; |
146 | 152 |
147 for (unsigned int i = 0; kExceptionSignals[i] != -1; ++i) { | 153 for (unsigned int i = 0; kExceptionSignals[i] != -1; ++i) { |
148 sigaction(kExceptionSignals[i], &sa, &g_old_sa[kExceptionSignals[i]]); | 154 sigaction(kExceptionSignals[i], &sa, &g_old_sa[kExceptionSignals[i]]); |
149 } | 155 } |
150 } | 156 } |
151 | 157 |
152 } // namespace android | 158 } // namespace android |
153 } // namespace testing | 159 } // namespace testing |
OLD | NEW |