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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // The list of signals which are considered to be crashes. | 43 // The list of signals which are considered to be crashes. |
44 const int kExceptionSignals[] = { | 44 const int kExceptionSignals[] = { |
45 SIGSEGV, SIGABRT, SIGFPE, SIGILL, SIGBUS, -1 | 45 SIGSEGV, SIGABRT, SIGFPE, SIGILL, SIGBUS, -1 |
46 }; | 46 }; |
47 | 47 |
48 struct sigaction g_old_sa[NSIG]; | 48 struct sigaction g_old_sa[NSIG]; |
49 | 49 |
50 // This function runs in a compromised context. It should not allocate memory. | 50 // This function runs in a compromised context. It should not allocate memory. |
51 void SignalHandler(int sig, siginfo_t* info, void* reserved) { | 51 void SignalHandler(int sig, siginfo_t* info, void* reserved) { |
52 // Output the crash marker. | 52 // Output the crash marker. |
53 write(STDOUT_FILENO, kCrashedMarker, sizeof(kCrashedMarker)); | 53 write(STDOUT_FILENO, kCrashedMarker, sizeof(kCrashedMarker) - 1); |
54 g_old_sa[sig].sa_sigaction(sig, info, reserved); | 54 g_old_sa[sig].sa_sigaction(sig, info, reserved); |
55 } | 55 } |
56 | 56 |
57 // Writes printf() style string to Android's logger where |priority| is one of | 57 // Writes printf() style string to Android's logger where |priority| is one of |
58 // the levels defined in <android/log.h>. | 58 // the levels defined in <android/log.h>. |
59 void AndroidLog(int priority, const char* format, ...) { | 59 void AndroidLog(int priority, const char* format, ...) { |
60 va_list args; | 60 va_list args; |
61 va_start(args, format); | 61 va_start(args, format); |
62 __android_log_vprint(priority, kLogTag, format, args); | 62 __android_log_vprint(priority, kLogTag, format, args); |
63 va_end(args); | 63 va_end(args); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 sa.sa_sigaction = SignalHandler; | 150 sa.sa_sigaction = SignalHandler; |
151 sa.sa_flags = SA_SIGINFO; | 151 sa.sa_flags = SA_SIGINFO; |
152 | 152 |
153 for (unsigned int i = 0; kExceptionSignals[i] != -1; ++i) { | 153 for (unsigned int i = 0; kExceptionSignals[i] != -1; ++i) { |
154 sigaction(kExceptionSignals[i], &sa, &g_old_sa[kExceptionSignals[i]]); | 154 sigaction(kExceptionSignals[i], &sa, &g_old_sa[kExceptionSignals[i]]); |
155 } | 155 } |
156 } | 156 } |
157 | 157 |
158 } // namespace android | 158 } // namespace android |
159 } // namespace testing | 159 } // namespace testing |
OLD | NEW |