| 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 logcat) markers identifying the | 6 // android application. It outputs (to logcat) markers identifying the |
| 7 // START/END/CRASH of the test suite, FAILURE/SUCCESS of individual tests etc. | 7 // START/END/CRASH of the test suite, FAILURE/SUCCESS of individual tests etc. |
| 8 // These markers are read by the test runner script to generate test results. | 8 // These markers are read by the test runner script to generate test results. |
| 9 // It injects an event listener in gtest to detect various test stages and | 9 // It injects an event listener in gtest to detect various test stages and |
| 10 // installs signal handlers to detect crashes. | 10 // 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 #include <stdio.h> | 14 #include <stdio.h> |
| 15 | 15 |
| 16 #include "base/android/jni_android.h" | 16 #include "base/android/jni_android.h" |
| 17 #include "base/android/jni_string.h" | 17 #include "base/android/jni_string.h" |
| 18 #include "base/android/locale_utils.h" | 18 #include "base/android/locale_utils.h" |
| 19 #include "base/android/path_utils.h" | 19 #include "base/android/path_utils.h" |
| 20 #include "base/android/scoped_java_ref.h" | 20 #include "base/android/scoped_java_ref.h" |
| 21 #include "base/at_exit.h" | 21 #include "base/at_exit.h" |
| 22 #include "base/command_line.h" | 22 #include "base/command_line.h" |
| 23 #include "base/file_path.h" | 23 #include "base/file_path.h" |
| 24 #include "base/file_util.h" | 24 #include "base/file_util.h" |
| 25 #include "base/logging.h" | 25 #include "base/logging.h" |
| 26 #include "base/stringprintf.h" | 26 #include "base/stringprintf.h" |
| 27 #include "base/string_tokenizer.h" | 27 #include "base/string_tokenizer.h" |
| 28 #include "base/string_util.h" | 28 #include "base/string_util.h" |
| 29 #include "base/test/test_support_android.h" | |
| 30 #include "gtest/gtest.h" | 29 #include "gtest/gtest.h" |
| 31 #include "testing/android/jni/chrome_native_test_activity_jni.h" | 30 #include "testing/android/jni/chrome_native_test_activity_jni.h" |
| 32 | 31 |
| 33 // 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. |
| 34 extern int main(int argc, char** argv); | 33 extern int main(int argc, char** argv); |
| 35 | 34 |
| 36 namespace { | 35 namespace { |
| 37 | 36 |
| 38 // The list of signals which are considered to be crashes. | 37 // The list of signals which are considered to be crashes. |
| 39 const int kExceptionSignals[] = { | 38 const int kExceptionSignals[] = { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 CommandLine::Init(arraysize(kInitialArgv), kInitialArgv); | 172 CommandLine::Init(arraysize(kInitialArgv), kInitialArgv); |
| 174 | 173 |
| 175 // Set the application context in base. | 174 // Set the application context in base. |
| 176 base::android::ScopedJavaLocalRef<jobject> scoped_context( | 175 base::android::ScopedJavaLocalRef<jobject> scoped_context( |
| 177 env, env->NewLocalRef(app_context)); | 176 env, env->NewLocalRef(app_context)); |
| 178 base::android::InitApplicationContext(scoped_context); | 177 base::android::InitApplicationContext(scoped_context); |
| 179 | 178 |
| 180 base::android::RegisterLocaleUtils(env); | 179 base::android::RegisterLocaleUtils(env); |
| 181 base::android::RegisterPathUtils(env); | 180 base::android::RegisterPathUtils(env); |
| 182 | 181 |
| 183 InitAndroidTest(); | |
| 184 | |
| 185 FilePath files_dir(base::android::ConvertJavaStringToUTF8(env, jfiles_dir)); | 182 FilePath files_dir(base::android::ConvertJavaStringToUTF8(env, jfiles_dir)); |
| 186 // A few options, such "--gtest_list_tests", will just use printf directly | 183 // A few options, such "--gtest_list_tests", will just use printf directly |
| 187 // and won't use the "AndroidLogPrinter". Redirect stdout to a known file. | 184 // and won't use the "AndroidLogPrinter". Redirect stdout to a known file. |
| 188 FilePath stdout_path(files_dir.Append(FilePath("stdout.txt"))); | 185 FilePath stdout_path(files_dir.Append(FilePath("stdout.txt"))); |
| 189 freopen(stdout_path.value().c_str(), "w", stdout); | 186 freopen(stdout_path.value().c_str(), "w", stdout); |
| 190 | 187 |
| 191 std::vector<std::string> args; | 188 std::vector<std::string> args; |
| 192 ParseArgsFromCommandLineFile(&args); | 189 ParseArgsFromCommandLineFile(&args); |
| 193 | 190 |
| 194 // We need to pass in a non-const char**. | 191 // We need to pass in a non-const char**. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 209 InstallHandlers(); | 206 InstallHandlers(); |
| 210 | 207 |
| 211 base::android::InitVM(vm); | 208 base::android::InitVM(vm); |
| 212 JNIEnv* env = base::android::AttachCurrentThread(); | 209 JNIEnv* env = base::android::AttachCurrentThread(); |
| 213 if (!RegisterNativesImpl(env)) { | 210 if (!RegisterNativesImpl(env)) { |
| 214 return -1; | 211 return -1; |
| 215 } | 212 } |
| 216 | 213 |
| 217 return JNI_VERSION_1_4; | 214 return JNI_VERSION_1_4; |
| 218 } | 215 } |
| OLD | NEW |