Home | History | Annotate | Download | only in crash
      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
      3 // found in the LICENSE file.
      4 //
      5 // Test that we handle crashes on threads other than main.
      6 
      7 #include <pthread.h>
      8 #include <stdio.h>
      9 #include <unistd.h>
     10 
     11 #include "native_client/src/shared/platform/nacl_check.h"
     12 #include "ppapi/native_client/tests/ppapi_test_lib/test_interface.h"
     13 
     14 namespace {
     15 
     16 void* CrashOffMainThreadFunction(void* thread_arg) {
     17   printf("--- CrashOffMainThreadFunction\n");
     18   usleep(1000);  // Try to wait until PPP_Messaging::HandleMessage returns.
     19   CRASH;
     20   return NULL;
     21 }
     22 
     23 // Depending on how the detached thread is scheduled, this will either crash
     24 // during PPP_Messaging::HandleMessage or after it and before the next PPP call.
     25 // If a crash occurs within a PPP call, it returns an RPC error.
     26 // If a crash occurs between PPP calls, the next call will return an RPC error.
     27 void CrashOffMainThread() {
     28   printf("--- CrashOffMainThread\n");
     29   pthread_t tid;
     30   pthread_create(&tid, NULL /*attr*/, CrashOffMainThreadFunction, NULL);
     31   pthread_detach(tid);
     32 }
     33 
     34 // This will allow us to ping the nexe to detect a crash that occured
     35 // while the main thread was waiting for the next PPP call.
     36 void Ping() {
     37   LOG_TO_BROWSER("ping received");
     38 }
     39 
     40 }  // namespace
     41 
     42 void SetupTests() {
     43   RegisterTest("CrashOffMainThread", CrashOffMainThread);
     44   RegisterTest("Ping", Ping);
     45 }
     46 
     47 void SetupPluginInterfaces() {
     48   // none
     49 }
     50