1/* 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. 3 * Use of this source code is governed by a BSD-style license that can be 4 * found in the LICENSE file. 5 */ 6 7#include <dlfcn.h> 8#include <stdio.h> 9#include <string.h> 10 11#include "ppapi/c/pp_errors.h" 12#include "ppapi/native_client/tests/ppapi_test_lib/get_browser_interface.h" 13#include "ppapi/native_client/tests/ppapi_test_lib/test_interface.h" 14#include "ppapi/native_client/tests/ppapi_test_lib/testable_callback.h" 15 16 17namespace { 18 19void TestDlopenMainThread() { 20 // This is a valid .so to load up, but dlopen doesn't work from the main 21 // PPAPI thread, so it should always fail. 22 void* lib_handle = dlopen("libmemusage.so", RTLD_LAZY); 23 EXPECT(lib_handle == NULL); 24 TEST_PASSED; 25} 26 27 28void CheckSecondaryThreadSuccess(void *lib_handle, int32_t unused_result) { 29 EXPECT(lib_handle != NULL); 30 PostTestMessage("TestDlopenSecondaryThread", "PASSED"); 31} 32 33void* SecondaryThreadFunc(void *unused_data) { 34 void* lib_handle = dlopen("libmemusage.so", RTLD_LAZY); 35 PP_CompletionCallback callback = PP_MakeCompletionCallback( 36 CheckSecondaryThreadSuccess, 37 lib_handle); 38 PPBCore()->CallOnMainThread(0, callback, PP_OK); 39 return NULL; 40} 41 42void TestDlopenSecondaryThread() { 43 pthread_t p; 44 pthread_create(&p, NULL, SecondaryThreadFunc, NULL); 45 // This function must return in order for the main message loop to 46 // service the requests issued from the dlopen call, we can't wait 47 // for the result of the thread here. The 'PASSED' message will 48 // be generated by the thread. 49} 50} 51 52void SetupTests() { 53 RegisterTest("TestDlopenMainThread", TestDlopenMainThread); 54 RegisterTest("TestDlopenSecondaryThread", TestDlopenSecondaryThread); 55} 56 57void SetupPluginInterfaces() { 58 // none 59} 60