| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 va_end(args); | 65 va_end(args); |
| 66 } | 66 } |
| 67 | 67 |
| 68 } // namespace | 68 } // namespace |
| 69 | 69 |
| 70 static void RunTests(JNIEnv* env, | 70 static void RunTests(JNIEnv* env, |
| 71 const JavaParamRef<jobject>& obj, | 71 const JavaParamRef<jobject>& obj, |
| 72 const JavaParamRef<jstring>& jcommand_line_flags, | 72 const JavaParamRef<jstring>& jcommand_line_flags, |
| 73 const JavaParamRef<jstring>& jcommand_line_file_path, | 73 const JavaParamRef<jstring>& jcommand_line_file_path, |
| 74 const JavaParamRef<jstring>& jstdout_file_path, | 74 const JavaParamRef<jstring>& jstdout_file_path, |
| 75 jboolean jstdout_fifo, | |
| 76 const JavaParamRef<jobject>& app_context, | 75 const JavaParamRef<jobject>& app_context, |
| 77 const JavaParamRef<jstring>& jtest_data_dir) { | 76 const JavaParamRef<jstring>& jtest_data_dir) { |
| 78 // Command line initialized basically, will be fully initialized later. | 77 // Command line initialized basically, will be fully initialized later. |
| 79 static const char* const kInitialArgv[] = { "ChromeTestActivity" }; | 78 static const char* const kInitialArgv[] = { "ChromeTestActivity" }; |
| 80 base::CommandLine::Init(arraysize(kInitialArgv), kInitialArgv); | 79 base::CommandLine::Init(arraysize(kInitialArgv), kInitialArgv); |
| 81 | 80 |
| 82 std::vector<std::string> args; | 81 std::vector<std::string> args; |
| 83 | 82 |
| 84 const std::string command_line_file_path( | 83 const std::string command_line_file_path( |
| 85 base::android::ConvertJavaStringToUTF8(env, jcommand_line_file_path)); | 84 base::android::ConvertJavaStringToUTF8(env, jcommand_line_file_path)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 99 base::CommandLine::ForCurrentProcess()->AppendArguments( | 98 base::CommandLine::ForCurrentProcess()->AppendArguments( |
| 100 base::CommandLine(argc, &argv[0]), false); | 99 base::CommandLine(argc, &argv[0]), false); |
| 101 const base::CommandLine& command_line = | 100 const base::CommandLine& command_line = |
| 102 *base::CommandLine::ForCurrentProcess(); | 101 *base::CommandLine::ForCurrentProcess(); |
| 103 | 102 |
| 104 base::FilePath stdout_file_path( | 103 base::FilePath stdout_file_path( |
| 105 base::android::ConvertJavaStringToUTF8(env, jstdout_file_path)); | 104 base::android::ConvertJavaStringToUTF8(env, jstdout_file_path)); |
| 106 | 105 |
| 107 // A few options, such "--gtest_list_tests", will just use printf directly | 106 // A few options, such "--gtest_list_tests", will just use printf directly |
| 108 // Always redirect stdout to a known file. | 107 // Always redirect stdout to a known file. |
| 109 unlink(stdout_file_path.value().c_str()); | 108 if (!base::android::RedirectStream(stdout, stdout_file_path, "a+")) { |
| 110 if (jstdout_fifo) { | |
| 111 if (!base::android::CreateFIFO(stdout_file_path, 0666)) { | |
| 112 AndroidLog(ANDROID_LOG_ERROR, "Failed to create fifo %s: %s\n", | |
| 113 stdout_file_path.value().c_str(), strerror(errno)); | |
| 114 exit(EXIT_FAILURE); | |
| 115 } | |
| 116 } | |
| 117 if (!base::android::RedirectStream(stdout, stdout_file_path, "w+")) { | |
| 118 AndroidLog(ANDROID_LOG_ERROR, "Failed to redirect stream to file: %s: %s\n", | 109 AndroidLog(ANDROID_LOG_ERROR, "Failed to redirect stream to file: %s: %s\n", |
| 119 stdout_file_path.value().c_str(), strerror(errno)); | 110 stdout_file_path.value().c_str(), strerror(errno)); |
| 120 exit(EXIT_FAILURE); | 111 exit(EXIT_FAILURE); |
| 121 } | 112 } |
| 122 dup2(STDOUT_FILENO, STDERR_FILENO); | 113 dup2(STDOUT_FILENO, STDERR_FILENO); |
| 123 | 114 |
| 124 if (command_line.HasSwitch(switches::kWaitForDebugger)) { | 115 if (command_line.HasSwitch(switches::kWaitForDebugger)) { |
| 125 AndroidLog(ANDROID_LOG_VERBOSE, | 116 AndroidLog(ANDROID_LOG_VERBOSE, |
| 126 "Native test waiting for GDB because flag %s was supplied", | 117 "Native test waiting for GDB because flag %s was supplied", |
| 127 switches::kWaitForDebugger); | 118 switches::kWaitForDebugger); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 152 sa.sa_sigaction = SignalHandler; | 143 sa.sa_sigaction = SignalHandler; |
| 153 sa.sa_flags = SA_SIGINFO; | 144 sa.sa_flags = SA_SIGINFO; |
| 154 | 145 |
| 155 for (unsigned int i = 0; kExceptionSignals[i] != -1; ++i) { | 146 for (unsigned int i = 0; kExceptionSignals[i] != -1; ++i) { |
| 156 sigaction(kExceptionSignals[i], &sa, &g_old_sa[kExceptionSignals[i]]); | 147 sigaction(kExceptionSignals[i], &sa, &g_old_sa[kExceptionSignals[i]]); |
| 157 } | 148 } |
| 158 } | 149 } |
| 159 | 150 |
| 160 } // namespace android | 151 } // namespace android |
| 161 } // namespace testing | 152 } // namespace testing |
| OLD | NEW |