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 10 matching lines...) Expand all Loading... |
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 "gtest/gtest.h" | 27 #include "gtest/gtest.h" |
28 #include "jni/NativeTestActivity_jni.h" | 28 #include "jni/NativeTestActivity_jni.h" |
29 #include "testing/android/native_test/native_test_util.h" | 29 #include "testing/android/native_test/native_test_util.h" |
30 | 30 |
31 using testing::native_test_util::ArgsToArgv; | |
32 using testing::native_test_util::ParseArgsFromCommandLineFile; | |
33 using testing::native_test_util::ParseArgsFromString; | |
34 using testing::native_test_util::ScopedMainEntryLogger; | |
35 | |
36 // The main function of the program to be wrapped as a test apk. | 31 // The main function of the program to be wrapped as a test apk. |
37 extern int main(int argc, char** argv); | 32 extern int main(int argc, char** argv); |
38 | 33 |
| 34 namespace testing { |
| 35 namespace android { |
| 36 |
39 namespace { | 37 namespace { |
40 | 38 |
41 // The test runner script writes the command line file in | 39 // The test runner script writes the command line file in |
42 // "/data/local/tmp". | 40 // "/data/local/tmp". |
43 static const char kCommandLineFilePath[] = | 41 static const char kCommandLineFilePath[] = |
44 "/data/local/tmp/chrome-native-tests-command-line"; | 42 "/data/local/tmp/chrome-native-tests-command-line"; |
45 | 43 |
46 const char kLogTag[] = "chromium"; | 44 const char kLogTag[] = "chromium"; |
47 const char kCrashedMarker[] = "[ CRASHED ]\n"; | 45 const char kCrashedMarker[] = "[ CRASHED ]\n"; |
48 | 46 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // A few options, such "--gtest_list_tests", will just use printf directly | 114 // A few options, such "--gtest_list_tests", will just use printf directly |
117 // Always redirect stdout to a known file. | 115 // Always redirect stdout to a known file. |
118 unlink(stdout_file_path.value().c_str()); | 116 unlink(stdout_file_path.value().c_str()); |
119 if (jstdout_fifo) { | 117 if (jstdout_fifo) { |
120 if (!base::android::CreateFIFO(stdout_file_path, 0666)) { | 118 if (!base::android::CreateFIFO(stdout_file_path, 0666)) { |
121 AndroidLog(ANDROID_LOG_ERROR, "Failed to create fifo %s: %s\n", | 119 AndroidLog(ANDROID_LOG_ERROR, "Failed to create fifo %s: %s\n", |
122 stdout_file_path.value().c_str(), strerror(errno)); | 120 stdout_file_path.value().c_str(), strerror(errno)); |
123 exit(EXIT_FAILURE); | 121 exit(EXIT_FAILURE); |
124 } | 122 } |
125 } | 123 } |
126 if (!base::android::RedirectStream(stdout, stdout_file_path, "w")) { | 124 if (!base::android::RedirectStream(stdout, stdout_file_path, "w+")) { |
127 AndroidLog(ANDROID_LOG_ERROR, "Failed to redirect stream to file: %s: %s\n", | 125 AndroidLog(ANDROID_LOG_ERROR, "Failed to redirect stream to file: %s: %s\n", |
128 stdout_file_path.value().c_str(), strerror(errno)); | 126 stdout_file_path.value().c_str(), strerror(errno)); |
129 exit(EXIT_FAILURE); | 127 exit(EXIT_FAILURE); |
130 } | 128 } |
131 dup2(STDOUT_FILENO, STDERR_FILENO); | 129 dup2(STDOUT_FILENO, STDERR_FILENO); |
132 | 130 |
133 if (command_line.HasSwitch(switches::kWaitForDebugger)) { | 131 if (command_line.HasSwitch(switches::kWaitForDebugger)) { |
134 AndroidLog(ANDROID_LOG_VERBOSE, | 132 AndroidLog(ANDROID_LOG_VERBOSE, |
135 "Native test waiting for GDB because flag %s was supplied", | 133 "Native test waiting for GDB because flag %s was supplied", |
136 switches::kWaitForDebugger); | 134 switches::kWaitForDebugger); |
137 base::debug::WaitForDebugger(24 * 60 * 60, false); | 135 base::debug::WaitForDebugger(24 * 60 * 60, false); |
138 } | 136 } |
139 | 137 |
140 ScopedMainEntryLogger scoped_main_entry_logger; | 138 ScopedMainEntryLogger scoped_main_entry_logger; |
141 main(argc, &argv[0]); | 139 main(argc, &argv[0]); |
142 } | 140 } |
143 | 141 |
144 bool RegisterNativeTestJNI(JNIEnv* env) { | 142 bool RegisterNativeTestJNI(JNIEnv* env) { |
145 return RegisterNativesImpl(env); | 143 return RegisterNativesImpl(env); |
146 } | 144 } |
147 | 145 |
148 | |
149 // TODO(nileshagrawal): now that we're using FIFO, test scripts can detect EOF. | 146 // TODO(nileshagrawal): now that we're using FIFO, test scripts can detect EOF. |
150 // Remove the signal handlers. | 147 // Remove the signal handlers. |
151 void InstallHandlers() { | 148 void InstallHandlers() { |
152 struct sigaction sa; | 149 struct sigaction sa; |
153 memset(&sa, 0, sizeof(sa)); | 150 memset(&sa, 0, sizeof(sa)); |
154 | 151 |
155 sa.sa_sigaction = SignalHandler; | 152 sa.sa_sigaction = SignalHandler; |
156 sa.sa_flags = SA_SIGINFO; | 153 sa.sa_flags = SA_SIGINFO; |
157 | 154 |
158 for (unsigned int i = 0; kExceptionSignals[i] != -1; ++i) { | 155 for (unsigned int i = 0; kExceptionSignals[i] != -1; ++i) { |
159 sigaction(kExceptionSignals[i], &sa, &g_old_sa[kExceptionSignals[i]]); | 156 sigaction(kExceptionSignals[i], &sa, &g_old_sa[kExceptionSignals[i]]); |
160 } | 157 } |
161 } | 158 } |
| 159 |
| 160 } // namespace android |
| 161 } // namespace testing |
OLD | NEW |