Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: testing/android/native_test_launcher.cc

Issue 10579040: APK-based unittests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.
(...skipping 23 matching lines...) Expand all
34 34
35 #if defined(REGISTER_CONTENT_UNITTESTS_JNI) 35 #if defined(REGISTER_CONTENT_UNITTESTS_JNI)
36 #include "content/app/android/content_jni_registrar.h" 36 #include "content/app/android/content_jni_registrar.h"
37 #endif 37 #endif
38 38
39 // The main function of the program to be wrapped as a test apk. 39 // The main function of the program to be wrapped as a test apk.
40 extern int main(int argc, char** argv); 40 extern int main(int argc, char** argv);
41 41
42 namespace { 42 namespace {
43 43
44 void log_write(int level, const char* msg) {
45 __android_log_write(level, "chromium", msg);
46 }
47
44 // The list of signals which are considered to be crashes. 48 // The list of signals which are considered to be crashes.
45 const int kExceptionSignals[] = { 49 const int kExceptionSignals[] = {
46 SIGSEGV, SIGABRT, SIGFPE, SIGILL, SIGBUS, -1 50 SIGSEGV, SIGABRT, SIGFPE, SIGILL, SIGBUS, -1
47 }; 51 };
48 52
49 struct sigaction g_old_sa[NSIG]; 53 struct sigaction g_old_sa[NSIG];
50 54
51 // This function runs in a compromised context. It should not allocate memory. 55 // This function runs in a compromised context. It should not allocate memory.
52 void SignalHandler(int sig, siginfo_t *info, void *reserved) 56 void SignalHandler(int sig, siginfo_t *info, void *reserved)
53 { 57 {
54 // Output the crash marker. 58 // Output the crash marker.
55 __android_log_write(ANDROID_LOG_ERROR, "chromium", "[ CRASHED ]"); 59 log_write(ANDROID_LOG_ERROR, "[ CRASHED ]");
56 g_old_sa[sig].sa_sigaction(sig, info, reserved); 60 g_old_sa[sig].sa_sigaction(sig, info, reserved);
57 } 61 }
58 62
59 void InstallHandlers() { 63 void InstallHandlers() {
60 struct sigaction sa; 64 struct sigaction sa;
61 memset(&sa, 0, sizeof(sa)); 65 memset(&sa, 0, sizeof(sa));
62 66
63 sa.sa_sigaction = SignalHandler; 67 sa.sa_sigaction = SignalHandler;
64 sa.sa_flags = SA_SIGINFO; 68 sa.sa_flags = SA_SIGINFO;
65 69
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 ::testing::TestEventListeners& listeners = 128 ::testing::TestEventListeners& listeners =
125 ::testing::UnitTest::GetInstance()->listeners(); 129 ::testing::UnitTest::GetInstance()->listeners();
126 // Adds a listener to the end. Google Test takes the ownership. 130 // Adds a listener to the end. Google Test takes the ownership.
127 listeners.Append(this); 131 listeners.Append(this);
128 } 132 }
129 133
130 void AndroidLogPrinter::OnTestProgramStart( 134 void AndroidLogPrinter::OnTestProgramStart(
131 const ::testing::UnitTest& unit_test) { 135 const ::testing::UnitTest& unit_test) {
132 std::string msg = StringPrintf("[ START ] %d", 136 std::string msg = StringPrintf("[ START ] %d",
133 unit_test.test_to_run_count()); 137 unit_test.test_to_run_count());
134 LOG(ERROR) << msg; 138 log_write(ANDROID_LOG_VERBOSE, msg.c_str());
135 } 139 }
136 140
137 void AndroidLogPrinter::OnTestStart(const ::testing::TestInfo& test_info) { 141 void AndroidLogPrinter::OnTestStart(const ::testing::TestInfo& test_info) {
138 std::string msg = StringPrintf("[ RUN ] %s.%s", 142 std::string msg = StringPrintf("[ RUN ] %s.%s",
139 test_info.test_case_name(), test_info.name()); 143 test_info.test_case_name(), test_info.name());
140 LOG(ERROR) << msg; 144 log_write(ANDROID_LOG_VERBOSE, msg.c_str());
141 } 145 }
142 146
143 void AndroidLogPrinter::OnTestPartResult( 147 void AndroidLogPrinter::OnTestPartResult(
144 const ::testing::TestPartResult& test_part_result) { 148 const ::testing::TestPartResult& test_part_result) {
145 std::string msg = StringPrintf( 149 std::string msg = StringPrintf(
146 "%s in %s:%d\n%s\n", 150 "%s in %s:%d\n%s\n",
147 test_part_result.failed() ? "*** Failure" : "Success", 151 test_part_result.failed() ? "*** Failure" : "Success",
148 test_part_result.file_name(), 152 test_part_result.file_name(),
149 test_part_result.line_number(), 153 test_part_result.line_number(),
150 test_part_result.summary()); 154 test_part_result.summary());
151 LOG(ERROR) << msg; 155 log_write(ANDROID_LOG_VERBOSE, msg.c_str());
152 } 156 }
153 157
154 void AndroidLogPrinter::OnTestEnd(const ::testing::TestInfo& test_info) { 158 void AndroidLogPrinter::OnTestEnd(const ::testing::TestInfo& test_info) {
155 std::string msg = StringPrintf("%s %s.%s", 159 std::string msg = StringPrintf("%s %s.%s",
156 test_info.result()->Failed() ? "[ FAILED ]" : "[ OK ]", 160 test_info.result()->Failed() ? "[ FAILED ]" : "[ OK ]",
157 test_info.test_case_name(), test_info.name()); 161 test_info.test_case_name(), test_info.name());
158 LOG(ERROR) << msg; 162 log_write(ANDROID_LOG_VERBOSE, msg.c_str());
159 } 163 }
160 164
161 void AndroidLogPrinter::OnTestProgramEnd( 165 void AndroidLogPrinter::OnTestProgramEnd(
162 const ::testing::UnitTest& unit_test) { 166 const ::testing::UnitTest& unit_test) {
163 std::string msg = StringPrintf("[ END ] %d", 167 std::string msg = StringPrintf("[ END ] %d",
164 unit_test.successful_test_count()); 168 unit_test.successful_test_count());
165 LOG(ERROR) << msg; 169 log_write(ANDROID_LOG_VERBOSE, msg.c_str());
166 } 170 }
167 171
168 } // namespace 172 } // namespace
169 173
170 // This method is called on a separate java thread so that we won't trigger 174 // This method is called on a separate java thread so that we won't trigger
171 // an ANR. 175 // an ANR.
172 static void RunTests(JNIEnv* env, 176 static void RunTests(JNIEnv* env,
173 jobject obj, 177 jobject obj,
174 jstring jfiles_dir, 178 jstring jfiles_dir,
175 jobject app_context) { 179 jobject app_context) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 InstallHandlers(); 227 InstallHandlers();
224 228
225 base::android::InitVM(vm); 229 base::android::InitVM(vm);
226 JNIEnv* env = base::android::AttachCurrentThread(); 230 JNIEnv* env = base::android::AttachCurrentThread();
227 if (!RegisterNativesImpl(env)) { 231 if (!RegisterNativesImpl(env)) {
228 return -1; 232 return -1;
229 } 233 }
230 234
231 return JNI_VERSION_1_4; 235 return JNI_VERSION_1_4;
232 } 236 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698