| 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. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 struct sigaction g_old_sa[NSIG]; | 54 struct sigaction g_old_sa[NSIG]; |
| 55 | 55 |
| 56 // This function runs in a compromised context. It should not allocate memory. | 56 // This function runs in a compromised context. It should not allocate memory. |
| 57 void SignalHandler(int sig, siginfo_t* info, void* reserved) { | 57 void SignalHandler(int sig, siginfo_t* info, void* reserved) { |
| 58 // Output the crash marker. | 58 // Output the crash marker. |
| 59 write(STDOUT_FILENO, kCrashedMarker, sizeof(kCrashedMarker)); | 59 write(STDOUT_FILENO, kCrashedMarker, sizeof(kCrashedMarker)); |
| 60 g_old_sa[sig].sa_sigaction(sig, info, reserved); | 60 g_old_sa[sig].sa_sigaction(sig, info, reserved); |
| 61 } | 61 } |
| 62 | 62 |
| 63 // TODO(nileshagrawal): now that we're using FIFO, test scripts can detect EOF. | |
| 64 // Remove the signal handlers. | |
| 65 void InstallHandlers() { | |
| 66 struct sigaction sa; | |
| 67 memset(&sa, 0, sizeof(sa)); | |
| 68 | |
| 69 sa.sa_sigaction = SignalHandler; | |
| 70 sa.sa_flags = SA_SIGINFO; | |
| 71 | |
| 72 for (unsigned int i = 0; kExceptionSignals[i] != -1; ++i) { | |
| 73 sigaction(kExceptionSignals[i], &sa, &g_old_sa[kExceptionSignals[i]]); | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 // Writes printf() style string to Android's logger where |priority| is one of | 63 // Writes printf() style string to Android's logger where |priority| is one of |
| 78 // the levels defined in <android/log.h>. | 64 // the levels defined in <android/log.h>. |
| 79 void AndroidLog(int priority, const char* format, ...) { | 65 void AndroidLog(int priority, const char* format, ...) { |
| 80 va_list args; | 66 va_list args; |
| 81 va_start(args, format); | 67 va_start(args, format); |
| 82 __android_log_vprint(priority, kLogTag, format, args); | 68 __android_log_vprint(priority, kLogTag, format, args); |
| 83 va_end(args); | 69 va_end(args); |
| 84 } | 70 } |
| 85 | 71 |
| 86 } // namespace | 72 } // namespace |
| 87 | 73 |
| 88 static void RunTests(JNIEnv* env, | 74 static void RunTests(JNIEnv* env, |
| 89 jobject obj, | 75 jobject obj, |
| 90 jstring jcommand_line_flags, | 76 jstring jcommand_line_flags, |
| 91 jstring jcommand_line_file_path, | 77 jstring jcommand_line_file_path, |
| 92 jstring jstdout_file_path, | 78 jstring jstdout_file_path, |
| 93 jboolean jstdout_fifo, | 79 jboolean jstdout_fifo, |
| 94 jobject app_context) { | 80 jobject app_context) { |
| 95 base::AtExitManager exit_manager; | |
| 96 | |
| 97 // Command line initialized basically, will be fully initialized later. | 81 // Command line initialized basically, will be fully initialized later. |
| 98 static const char* const kInitialArgv[] = { "ChromeTestActivity" }; | 82 static const char* const kInitialArgv[] = { "ChromeTestActivity" }; |
| 99 base::CommandLine::Init(arraysize(kInitialArgv), kInitialArgv); | 83 base::CommandLine::Init(arraysize(kInitialArgv), kInitialArgv); |
| 100 | 84 |
| 101 // Set the application context in base. | 85 // Set the application context in base. |
| 102 base::android::ScopedJavaLocalRef<jobject> scoped_context( | 86 base::android::ScopedJavaLocalRef<jobject> scoped_context( |
| 103 env, env->NewLocalRef(app_context)); | 87 env, env->NewLocalRef(app_context)); |
| 104 base::android::InitApplicationContext(env, scoped_context); | 88 base::android::InitApplicationContext(env, scoped_context); |
| 105 base::android::RegisterJni(env); | 89 base::android::RegisterJni(env); |
| 106 | 90 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 AndroidLog(ANDROID_LOG_VERBOSE, | 134 AndroidLog(ANDROID_LOG_VERBOSE, |
| 151 "Native test waiting for GDB because flag %s was supplied", | 135 "Native test waiting for GDB because flag %s was supplied", |
| 152 switches::kWaitForDebugger); | 136 switches::kWaitForDebugger); |
| 153 base::debug::WaitForDebugger(24 * 60 * 60, false); | 137 base::debug::WaitForDebugger(24 * 60 * 60, false); |
| 154 } | 138 } |
| 155 | 139 |
| 156 ScopedMainEntryLogger scoped_main_entry_logger; | 140 ScopedMainEntryLogger scoped_main_entry_logger; |
| 157 main(argc, &argv[0]); | 141 main(argc, &argv[0]); |
| 158 } | 142 } |
| 159 | 143 |
| 160 // This is called by the VM when the shared library is first loaded. | 144 bool RegisterNativeTestJNI(JNIEnv* env) { |
| 161 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { | 145 return RegisterNativesImpl(env); |
| 162 // Install signal handlers to detect crashes. | 146 } |
| 163 InstallHandlers(); | |
| 164 | 147 |
| 165 base::android::InitVM(vm); | 148 |
| 166 JNIEnv* env = base::android::AttachCurrentThread(); | 149 // TODO(nileshagrawal): now that we're using FIFO, test scripts can detect EOF. |
| 167 if (!RegisterNativesImpl(env)) { | 150 // Remove the signal handlers. |
| 168 return -1; | 151 void InstallHandlers() { |
| 152 struct sigaction sa; |
| 153 memset(&sa, 0, sizeof(sa)); |
| 154 |
| 155 sa.sa_sigaction = SignalHandler; |
| 156 sa.sa_flags = SA_SIGINFO; |
| 157 |
| 158 for (unsigned int i = 0; kExceptionSignals[i] != -1; ++i) { |
| 159 sigaction(kExceptionSignals[i], &sa, &g_old_sa[kExceptionSignals[i]]); |
| 169 } | 160 } |
| 170 | |
| 171 return JNI_VERSION_1_4; | |
| 172 } | 161 } |
| OLD | NEW |