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

Unified Diff: testing/android/native_test_launcher.cc

Issue 10310046: Detect crashes while running native tests in APK. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
« build/android/test_result.py ('K') | « build/android/test_result.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: testing/android/native_test_launcher.cc
diff --git a/testing/android/native_test_launcher.cc b/testing/android/native_test_launcher.cc
index 1555fbe476ad378f0aba4ffcf2e6a3e90c2d009b..a42c6ad446d41e16e99aa89e6b556f5f3d46aca0 100644
--- a/testing/android/native_test_launcher.cc
+++ b/testing/android/native_test_launcher.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
John Grabowski 2012/05/07 19:22:15 Add explicit doc on our model: catch signals and p
nilesh 2012/05/08 01:38:10 Done.
+#include <signal.h>
#include <stdio.h>
#include "base/android/jni_android.h"
@@ -25,6 +26,33 @@ extern int main(int argc, char** argv);
namespace {
+// The list of signals which we consider to be crashes. We rethrow the
Yaron 2012/05/07 19:22:19 Nit: Don't use "we" in comments.
nilesh 2012/05/08 01:38:10 Done.
+// signal after handling it.
+static const int kExceptionSignals[] = {
+ SIGSEGV, SIGABRT, SIGFPE, SIGILL, SIGBUS, -1
+};
+
+static struct sigaction old_sa[NSIG];
+
+void SignalHandler(int sig, siginfo_t *info, void *reserved)
+{
+ // Output the crash marker.
+ LOG(ERROR) << "[ CRASHED ]";
John Grabowski 2012/05/07 19:22:15 Normally you cannot allocate memory in a signal ha
nilesh 2012/05/08 01:38:10 Done. Thanks for catching this.
+ old_sa[sig].sa_sigaction(sig, info, reserved);
+}
+
+void InstallHandlers() {
+ struct sigaction sa;
+ memset(&sa, 0, sizeof(sa));
+
+ sa.sa_sigaction = SignalHandler;
+ sa.sa_flags = SA_SIGINFO;
+
+ for (unsigned int i = 0; kExceptionSignals[i] != -1; ++i) {
+ sigaction(kExceptionSignals[i], &sa, &old_sa[kExceptionSignals[i]]);
+ }
+}
+
void ParseArgsFromString(const std::string& command_line,
std::vector<std::string>* args) {
StringTokenizer tokenizer(command_line, kWhitespaceASCII);
@@ -189,11 +217,16 @@ static void RunTests(JNIEnv* env,
// This is called by the VM when the shared library is first loaded.
JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
+
+ // Install signal handlers to detect crashes.
+ InstallHandlers();
+
base::android::InitVM(vm);
JNIEnv* env = base::android::AttachCurrentThread();
if (!RegisterNativesImpl(env)) {
return -1;
}
LibraryLoadedOnMainThread(env);
+
return JNI_VERSION_1_4;
}
« build/android/test_result.py ('K') | « build/android/test_result.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698