| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 const std::string command_line_flags( | 91 const std::string command_line_flags( |
| 92 base::android::ConvertJavaStringToUTF8(env, jcommand_line_flags)); | 92 base::android::ConvertJavaStringToUTF8(env, jcommand_line_flags)); |
| 93 ParseArgsFromString(command_line_flags, &args); | 93 ParseArgsFromString(command_line_flags, &args); |
| 94 | 94 |
| 95 std::vector<char*> argv; | 95 std::vector<char*> argv; |
| 96 int argc = ArgsToArgv(args, &argv); | 96 int argc = ArgsToArgv(args, &argv); |
| 97 | 97 |
| 98 // Fully initialize command line with arguments. | 98 // Fully initialize command line with arguments. |
| 99 base::CommandLine::ForCurrentProcess()->AppendArguments( | 99 base::CommandLine::ForCurrentProcess()->AppendArguments( |
| 100 base::CommandLine(argc, &argv[0]), false); | 100 base::CommandLine(argc, &argv[0]), false); |
| 101 const base::CommandLine& command_line = | 101 //const base::CommandLine& command_line = |
| 102 *base::CommandLine::ForCurrentProcess(); | 102 //*base::CommandLine::ForCurrentProcess(); |
| 103 | 103 |
| 104 base::FilePath stdout_file_path( | 104 base::FilePath stdout_file_path( |
| 105 base::android::ConvertJavaStringToUTF8(env, jstdout_file_path)); | 105 base::android::ConvertJavaStringToUTF8(env, jstdout_file_path)); |
| 106 | 106 |
| 107 // A few options, such "--gtest_list_tests", will just use printf directly | 107 // A few options, such "--gtest_list_tests", will just use printf directly |
| 108 // Always redirect stdout to a known file. | 108 // Always redirect stdout to a known file. |
| 109 unlink(stdout_file_path.value().c_str()); | 109 unlink(stdout_file_path.value().c_str()); |
| 110 if (jstdout_fifo) { | 110 if (jstdout_fifo) { |
| 111 if (!base::android::CreateFIFO(stdout_file_path, 0666)) { | 111 if (!base::android::CreateFIFO(stdout_file_path, 0666)) { |
| 112 AndroidLog(ANDROID_LOG_ERROR, "Failed to create fifo %s: %s\n", | 112 AndroidLog(ANDROID_LOG_ERROR, "Failed to create fifo %s: %s\n", |
| 113 stdout_file_path.value().c_str(), strerror(errno)); | 113 stdout_file_path.value().c_str(), strerror(errno)); |
| 114 exit(EXIT_FAILURE); | 114 exit(EXIT_FAILURE); |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 if (!base::android::RedirectStream(stdout, stdout_file_path, "w+")) { | 117 if (!base::android::RedirectStream(stdout, stdout_file_path, "w+")) { |
| 118 AndroidLog(ANDROID_LOG_ERROR, "Failed to redirect stream to file: %s: %s\n", | 118 AndroidLog(ANDROID_LOG_ERROR, "Failed to redirect stream to file: %s: %s\n", |
| 119 stdout_file_path.value().c_str(), strerror(errno)); | 119 stdout_file_path.value().c_str(), strerror(errno)); |
| 120 exit(EXIT_FAILURE); | 120 exit(EXIT_FAILURE); |
| 121 } | 121 } |
| 122 dup2(STDOUT_FILENO, STDERR_FILENO); | 122 dup2(STDOUT_FILENO, STDERR_FILENO); |
| 123 | 123 |
| 124 if (command_line.HasSwitch(switches::kWaitForDebugger)) { | 124 //if (command_line.HasSwitch(switches::kWaitForDebugger)) { |
| 125 AndroidLog(ANDROID_LOG_VERBOSE, | 125 //AndroidLog(ANDROID_LOG_VERBOSE, |
| 126 "Native test waiting for GDB because flag %s was supplied", | 126 //"Native test waiting for GDB because flag %s was supplied", |
| 127 switches::kWaitForDebugger); | 127 //switches::kWaitForDebugger); |
| 128 base::debug::WaitForDebugger(24 * 60 * 60, true); | 128 //base::debug::WaitForDebugger(24 * 60 * 60, true); |
| 129 } | 129 //} |
| 130 | 130 |
| 131 base::FilePath test_data_dir( | 131 base::FilePath test_data_dir( |
| 132 base::android::ConvertJavaStringToUTF8(env, jtest_data_dir)); | 132 base::android::ConvertJavaStringToUTF8(env, jtest_data_dir)); |
| 133 base::InitAndroidTestPaths(test_data_dir); | 133 base::InitAndroidTestPaths(test_data_dir); |
| 134 | 134 |
| 135 ScopedMainEntryLogger scoped_main_entry_logger; | 135 ScopedMainEntryLogger scoped_main_entry_logger; |
| 136 main(argc, &argv[0]); | 136 main(argc, &argv[0]); |
| 137 } | 137 } |
| 138 | 138 |
| 139 bool RegisterNativeTestJNI(JNIEnv* env) { | 139 bool RegisterNativeTestJNI(JNIEnv* env) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 152 sa.sa_sigaction = SignalHandler; | 152 sa.sa_sigaction = SignalHandler; |
| 153 sa.sa_flags = SA_SIGINFO; | 153 sa.sa_flags = SA_SIGINFO; |
| 154 | 154 |
| 155 for (unsigned int i = 0; kExceptionSignals[i] != -1; ++i) { | 155 for (unsigned int i = 0; kExceptionSignals[i] != -1; ++i) { |
| 156 sigaction(kExceptionSignals[i], &sa, &g_old_sa[kExceptionSignals[i]]); | 156 sigaction(kExceptionSignals[i], &sa, &g_old_sa[kExceptionSignals[i]]); |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 } // namespace android | 160 } // namespace android |
| 161 } // namespace testing | 161 } // namespace testing |
| OLD | NEW |