Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / test / data / nacl / crash / ppapi_crash_off_main_thread.cc
blobc87fcdb1a3d5f48437392756836e0b547634c2c3
1 // Copyright 2013 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.
7 #include <pthread.h>
8 #include <stdio.h>
9 #include <unistd.h>
11 #include "native_client/src/shared/platform/nacl_check.h"
12 #include "ppapi/native_client/tests/ppapi_test_lib/test_interface.h"
14 namespace {
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;
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);
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");
40 } // namespace
42 void SetupTests() {
43 RegisterTest("CrashOffMainThread", CrashOffMainThread);
44 RegisterTest("Ping", Ping);
47 void SetupPluginInterfaces() {
48 // none