diff options
author | sbc <sbc@chromium.org> | 2014-08-29 16:12:37 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-08-29 23:17:57 +0000 |
commit | dc0238737d54d1c925cc4f012c0835bafd04ef2a (patch) | |
tree | b2067427682cbe34aadfc1b6ddd62ab46056147d /native_client_sdk | |
parent | 37accc2cd58a4f27f7cdd33907eae36f224bbb2e (diff) | |
download | chromium_src-dc0238737d54d1c925cc4f012c0835bafd04ef2a.zip chromium_src-dc0238737d54d1c925cc4f012c0835bafd04ef2a.tar.gz chromium_src-dc0238737d54d1c925cc4f012c0835bafd04ef2a.tar.bz2 |
[NaCl SDK] Allow ppapi_simple executables to run in both sel_ldr and in chrome.
Override the main() function from libppapi_stub, and rather than
simply failing when PPAPI is missing, assume that we are running
in sel_ldr and jump directly to the user's main function.
As a nice side effect this removes the needs to SEL_LDR=1 builds.
Review URL: https://codereview.chromium.org/412083002
Cr-Commit-Position: refs/heads/master@{#292710}
Diffstat (limited to 'native_client_sdk')
13 files changed, 90 insertions, 133 deletions
diff --git a/native_client_sdk/src/build_tools/generate_make.py b/native_client_sdk/src/build_tools/generate_make.py index febbd51..38d1ae3 100644 --- a/native_client_sdk/src/build_tools/generate_make.py +++ b/native_client_sdk/src/build_tools/generate_make.py @@ -189,29 +189,12 @@ def ModifyDescInPlace(desc): Currently this consists of: - Add -Wall to CXXFLAGS - - Synthesize SEL_LDR_LIBS and SEL_LDR_DEPS by stripping - down LIBS and DEPS (removing certain ppapi-only libs). """ - ppapi_only_libs = ['ppapi_simple'] - for target in desc['TARGETS']: target.setdefault('CXXFLAGS', []) target['CXXFLAGS'].insert(0, '-Wall') - def filter_out(key): - value = target.get(key, []) - if type(value) == dict: - value = dict(value) - for key in value.keys(): - value[key] = [v for v in value[key] if v not in ppapi_only_libs] - else: - value = [v for v in value if v not in ppapi_only_libs] - return value - - target['SEL_LDR_LIBS'] = filter_out('LIBS') - target['SEL_LDR_DEPS'] = filter_out('DEPS') - def ProcessProject(pepperdir, srcroot, dstroot, desc, toolchains, configs=None, first_toolchain=False): diff --git a/native_client_sdk/src/examples/tutorial/testing/testing.cc b/native_client_sdk/src/examples/tutorial/testing/testing.cc index 57ae127..b44b5a1 100644 --- a/native_client_sdk/src/examples/tutorial/testing/testing.cc +++ b/native_client_sdk/src/examples/tutorial/testing/testing.cc @@ -3,24 +3,6 @@ // found in the LICENSE file. #include "gtest/gtest.h" - -TEST(TestCase, SimpleTest) { - EXPECT_EQ(4, 2*2); -} - -TEST(TestCase, AnotherTest) { - EXPECT_EQ(1, sizeof(char)); -} - -#if defined(SEL_LDR) - -int main(int argc, char* argv[]) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - -#else - #include "ppapi/cpp/instance.h" #include "ppapi/cpp/var.h" #include "ppapi_simple/ps_main.h" @@ -30,6 +12,14 @@ int main(int argc, char* argv[]) { #undef PostMessage #endif +TEST(TestCase, SimpleTest) { + EXPECT_EQ(4, 2*2); +} + +TEST(TestCase, AnotherTest) { + EXPECT_EQ(1, sizeof(char)); +} + class GTestEventListener : public ::testing::EmptyTestEventListener { public: // TestEventListener overrides. @@ -59,14 +49,15 @@ class GTestEventListener : public ::testing::EmptyTestEventListener { }; int example_main(int argc, char* argv[]) { + setenv("TERM", "xterm-256color", 0); ::testing::InitGoogleTest(&argc, argv); - ::testing::UnitTest::GetInstance()->listeners() - .Append(new GTestEventListener()); + if (PSGetInstanceId() != 0) { + ::testing::UnitTest::GetInstance()->listeners() + .Append(new GTestEventListener()); + } return RUN_ALL_TESTS(); } // Register the function to call once the Instance Object is initialized. // see: pappi_simple/ps_main.h PPAPI_SIMPLE_REGISTER_MAIN(example_main); - -#endif diff --git a/native_client_sdk/src/examples/tutorial/using_ppapi_simple/hello_world.c b/native_client_sdk/src/examples/tutorial/using_ppapi_simple/hello_world.c index 10322d0..31e88fa5 100644 --- a/native_client_sdk/src/examples/tutorial/using_ppapi_simple/hello_world.c +++ b/native_client_sdk/src/examples/tutorial/using_ppapi_simple/hello_world.c @@ -8,10 +8,6 @@ #include "ppapi_simple/ps_main.h" -#ifdef SEL_LDR -#define example_main main -#endif - int example_main(int argc, char* argv[]) { /* Use ppb_messaging to send "Hello World" to JavaScript. */ printf("Hello World STDOUT.\n"); @@ -28,6 +24,4 @@ int example_main(int argc, char* argv[]) { * This is not needed when building the sel_ldr version of this example * which does not link against ppapi_simple. */ -#ifndef SEL_LDR PPAPI_SIMPLE_REGISTER_MAIN(example_main) -#endif diff --git a/native_client_sdk/src/libraries/ppapi_simple/ps.h b/native_client_sdk/src/libraries/ppapi_simple/ps.h index fdc1c10..1e345af 100644 --- a/native_client_sdk/src/libraries/ppapi_simple/ps.h +++ b/native_client_sdk/src/libraries/ppapi_simple/ps.h @@ -1,6 +1,6 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. +/* Copyright (c) 2012 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. */ #ifndef PPAPI_SIMPLE_PS_H_ #define PPAPI_SIMPLE_PS_H_ @@ -45,7 +45,6 @@ EXTERN_C_BEGIN */ PP_Instance PSGetInstanceId(void); - /** * PSGetInterface * @@ -54,7 +53,6 @@ PP_Instance PSGetInstanceId(void); */ const void* PSGetInterface(const char *name); - /** * PSUserCreateInstance * @@ -67,20 +65,6 @@ const void* PSGetInterface(const char *name); */ extern void* PSUserCreateInstance(PP_Instance inst); - -/** - * PPAPI_SIMPLE_USE_MAIN - * - * For use with C projects, this macro calls the provided factory with - * configuration information. - */ -#define PPAPI_SIMPLE_USE_MAIN(factory, func) \ -void* PSUserCreateInstance(PP_Instance inst) { \ - return factory(inst, func); \ -} - - EXTERN_C_END - -#endif // PPAPI_SIMPLE_PS_H_ +#endif /* PPAPI_SIMPLE_PS_H_ */ diff --git a/native_client_sdk/src/libraries/ppapi_simple/ps_instance.h b/native_client_sdk/src/libraries/ppapi_simple/ps_instance.h index c2a3304..21209d1 100644 --- a/native_client_sdk/src/libraries/ppapi_simple/ps_instance.h +++ b/native_client_sdk/src/libraries/ppapi_simple/ps_instance.h @@ -214,4 +214,4 @@ class PSInstance : public pp::Instance, pp::MouseLock, pp::Graphics3DClient { char* exit_message_; }; -#endif // PPAPI_MAIN_PS_INSTANCE_H_ +#endif // PPAPI_SIMPLE_PS_INSTANCE_H_ diff --git a/native_client_sdk/src/libraries/ppapi_simple/ps_main.cc b/native_client_sdk/src/libraries/ppapi_simple/ps_main.cc index eabbeaa..3b634f9 100644 --- a/native_client_sdk/src/libraries/ppapi_simple/ps_main.cc +++ b/native_client_sdk/src/libraries/ppapi_simple/ps_main.cc @@ -2,15 +2,46 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#ifdef __native_client__ +#include <irt.h> +#include <irt_ppapi.h> +#endif + +#include <stdio.h> + +#include "nacl_io/nacl_io.h" #include "ppapi/c/pp_instance.h" #include "ppapi/c/pp_module.h" - #include "ppapi_simple/ps_instance.h" #include "ppapi_simple/ps_main.h" +extern "C" int PpapiPluginMain(); -void* PSMainCreate(PP_Instance inst, PSMainFunc_t func) { +void* PSMainCreate(PP_Instance inst, PSMainFunc_t entry_point) { PSInstance* pInst = new PSInstance(inst); - pInst->SetMain(func); + pInst->SetMain(entry_point); return pInst; } + +/** + * main entry point for ppapi_simple applications. This differs from the + * regular ppapi main entry point in that it will fall back to running + * the user's main code in the case that the PPAPI hooks are not found. + * This allows ppapi_simple binary to run within chrome (with PPAPI present) + * and also under sel_ldr (no PPAPI). + */ +#ifdef __native_client__ +extern "C" int __nacl_main(int argc, char* argv[]) { + struct nacl_irt_ppapihook hooks; + if (nacl_interface_query(NACL_IRT_PPAPIHOOK_v0_1, &hooks, sizeof(hooks)) == + sizeof(hooks)) { + return PpapiPluginMain(); + } +#else +int main(int argc, char* argv[]) { +#endif + // By default, or if not running in the browser we simply run the main + // entry point directly, on the main thread. + nacl_io_init(); + return PSUserMainGet()(argc, argv); +} diff --git a/native_client_sdk/src/libraries/ppapi_simple/ps_main.h b/native_client_sdk/src/libraries/ppapi_simple/ps_main.h index c269d3a..2b42ac4 100644 --- a/native_client_sdk/src/libraries/ppapi_simple/ps_main.h +++ b/native_client_sdk/src/libraries/ppapi_simple/ps_main.h @@ -18,8 +18,16 @@ typedef int (*PSMainFunc_t)(int argc, char *argv[]); * Constructs an instance SimpleInstance and configures it to call into * the provided "main" function. */ -void* PSMainCreate(PP_Instance inst, PSMainFunc_t func); +void* PSMainCreate(PP_Instance inst, PSMainFunc_t entry_point); +/** + * PSUserMainGet + * + * Prototype for the user provided function which retrieves the user's main + * function. + * This is normally defined using the PPAPI_SIMPLE_REGISTER_MAIN macro. + */ +PSMainFunc_t PSUserMainGet(); /** * PPAPI_SIMPLE_REGISTER_MAIN @@ -27,8 +35,13 @@ void* PSMainCreate(PP_Instance inst, PSMainFunc_t func); * Constructs a PSInstance object and configures it to use call the provided * 'main' function on its own thread once initialization is complete. */ -#define PPAPI_SIMPLE_REGISTER_MAIN(main) \ - PPAPI_SIMPLE_USE_MAIN(PSMainCreate, main) +#define PPAPI_SIMPLE_REGISTER_MAIN(main_func) \ + PSMainFunc_t PSUserMainGet() { \ + return main_func; \ + } \ + void* PSUserCreateInstance(PP_Instance inst) { \ + return PSMainCreate(inst, main_func); \ + } EXTERN_C_END diff --git a/native_client_sdk/src/resources/Makefile.example.template b/native_client_sdk/src/resources/Makefile.example.template index ca1605f..3d6ceb0 100644 --- a/native_client_sdk/src/resources/Makefile.example.template +++ b/native_client_sdk/src/resources/Makefile.example.template @@ -47,18 +47,8 @@ CHROME_ARGS += --allow-nacl-socket-api=localhost [[]] TARGET = {{targets[0]['NAME']}} -[[if sel_ldr and targets[0].get('SEL_LDR_LIBS'):]] -ifdef SEL_LDR -[[ ExpandDict('DEPS', targets[0].get('SEL_LDR_DEPS', []))]] -[[ ExpandDict('LIBS', targets[0].get('SEL_LDR_LIBS', []))]] -else -[[ ExpandDict('DEPS', targets[0].get('DEPS', []))]] -[[ ExpandDict('LIBS', targets[0].get('LIBS', []))]] -endif -[[else:]] -[[ ExpandDict('DEPS', targets[0].get('DEPS', []))]] -[[ ExpandDict('LIBS', targets[0].get('LIBS', []))]] -[[]] +[[ExpandDict('DEPS', targets[0].get('DEPS', []))]] +[[ExpandDict('LIBS', targets[0].get('LIBS', []))]] [[for target in targets:]] [[ source_list = (s for s in sorted(target['SOURCES']) if not s.endswith('.h'))]] diff --git a/native_client_sdk/src/tests/nacl_io_socket_test/main.cc b/native_client_sdk/src/tests/nacl_io_socket_test/main.cc index ef7b094..61066a2 100644 --- a/native_client_sdk/src/tests/nacl_io_socket_test/main.cc +++ b/native_client_sdk/src/tests/nacl_io_socket_test/main.cc @@ -5,16 +5,6 @@ #include <string> #include "gtest/gtest.h" - -#if defined(SEL_LDR) - -int main(int argc, char* argv[]) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - -#else - #include "ppapi/cpp/instance.h" #include "ppapi/cpp/var.h" #include "ppapi_simple/ps_main.h" @@ -54,13 +44,13 @@ class GTestEventListener : public ::testing::EmptyTestEventListener { int example_main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); - ::testing::UnitTest::GetInstance()->listeners() - .Append(new GTestEventListener()); + if (PSGetInstanceId() != 0) { + ::testing::UnitTest::GetInstance()->listeners() + .Append(new GTestEventListener()); + } return RUN_ALL_TESTS(); } // Register the function to call once the Instance Object is initialized. // see: pappi_simple/ps_main.h PPAPI_SIMPLE_REGISTER_MAIN(example_main); - -#endif diff --git a/native_client_sdk/src/tests/nacl_io_test/kernel_wrap_test.cc b/native_client_sdk/src/tests/nacl_io_test/kernel_wrap_test.cc index 2bb6198..df2d994 100644 --- a/native_client_sdk/src/tests/nacl_io_test/kernel_wrap_test.cc +++ b/native_client_sdk/src/tests/nacl_io_test/kernel_wrap_test.cc @@ -19,6 +19,7 @@ #include "nacl_io/osmman.h" #include "nacl_io/ossocket.h" #include "nacl_io/ostermios.h" +#include "ppapi_simple/ps.h" #if defined(__native_client__) && !defined(__GLIBC__) extern "C" { @@ -633,13 +634,14 @@ TEST_F(KernelWrapTest, write) { EXPECT_EQ(kDummyInt3, write(kDummyInt, kDummyVoidPtr, kDummyInt2)); } -#if defined SEL_LDR class KernelWrapTestUninit : public ::testing::Test { void SetUp() { ASSERT_EQ(0, ki_push_state_for_testing()); + kernel_wrap_uninit(); } void TearDown() { + kernel_wrap_init(); ki_pop_state_for_testing(); } }; @@ -647,6 +649,8 @@ class KernelWrapTestUninit : public ::testing::Test { TEST_F(KernelWrapTestUninit, Mkdir_Uninitialised) { // If we are running within chrome we can't use these calls without // nacl_io initialized. + if (PSGetInstanceId() != 0) + return; EXPECT_EQ(0, mkdir("./foo", S_IREAD | S_IWRITE)); EXPECT_EQ(0, rmdir("./foo")); } @@ -654,6 +658,8 @@ TEST_F(KernelWrapTestUninit, Mkdir_Uninitialised) { TEST_F(KernelWrapTestUninit, Getcwd_Uninitialised) { // If we are running within chrome we can't use these calls without // nacl_io initialized. + if (PSGetInstanceId() != 0) + return; char dir[PATH_MAX]; ASSERT_NE((char*)NULL, getcwd(dir, PATH_MAX)); // Verify that the CWD ends with 'nacl_io_test' @@ -661,7 +667,6 @@ TEST_F(KernelWrapTestUninit, Getcwd_Uninitialised) { ASSERT_GT(strlen(dir), strlen(suffix)); ASSERT_EQ(0, strcmp(dir+strlen(dir)-strlen(suffix), suffix)); } -#endif #if defined(PROVIDES_SOCKET_API) and !defined(__BIONIC__) TEST_F(KernelWrapTest, poll) { diff --git a/native_client_sdk/src/tests/nacl_io_test/main.cc b/native_client_sdk/src/tests/nacl_io_test/main.cc index 326c18f..31414e6 100644 --- a/native_client_sdk/src/tests/nacl_io_test/main.cc +++ b/native_client_sdk/src/tests/nacl_io_test/main.cc @@ -5,17 +5,6 @@ #include <string> #include "gtest/gtest.h" - -#if defined(SEL_LDR) - -int main(int argc, char* argv[]) { - setenv("TERM", "xterm-256color", 0); - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - -#else - #include "ppapi/cpp/instance.h" #include "ppapi/cpp/var.h" #include "ppapi_simple/ps_main.h" @@ -54,14 +43,15 @@ class GTestEventListener : public ::testing::EmptyTestEventListener { }; int example_main(int argc, char* argv[]) { + setenv("TERM", "xterm-256color", 0); ::testing::InitGoogleTest(&argc, argv); - ::testing::UnitTest::GetInstance()->listeners() - .Append(new GTestEventListener()); + if (PSGetInstanceId() != 0) { + ::testing::UnitTest::GetInstance()->listeners() + .Append(new GTestEventListener()); + } return RUN_ALL_TESTS(); } // Register the function to call once the Instance Object is initialized. // see: pappi_simple/ps_main.h PPAPI_SIMPLE_REGISTER_MAIN(example_main); - -#endif diff --git a/native_client_sdk/src/tests/sdk_util_test/main.cc b/native_client_sdk/src/tests/sdk_util_test/main.cc index 7dedcc6..a715b1b 100644 --- a/native_client_sdk/src/tests/sdk_util_test/main.cc +++ b/native_client_sdk/src/tests/sdk_util_test/main.cc @@ -5,16 +5,6 @@ #include <string> #include "gtest/gtest.h" - -#if defined(SEL_LDR) - -int main(int argc, char* argv[]) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - -#else - #include "ppapi/cpp/instance.h" #include "ppapi/cpp/var.h" #include "ppapi_simple/ps_main.h" @@ -54,13 +44,13 @@ class GTestEventListener : public ::testing::EmptyTestEventListener { int example_main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); - ::testing::UnitTest::GetInstance()->listeners() - .Append(new GTestEventListener()); + if (PSGetInstanceId() != 0) { + ::testing::UnitTest::GetInstance()->listeners() + .Append(new GTestEventListener()); + } return RUN_ALL_TESTS(); } // Register the function to call once the Instance Object is initialized. // see: pappi_simple/ps_main.h PPAPI_SIMPLE_REGISTER_MAIN(example_main); - -#endif diff --git a/native_client_sdk/src/tools/common.mk b/native_client_sdk/src/tools/common.mk index 15cf783..b50195e 100644 --- a/native_client_sdk/src/tools/common.mk +++ b/native_client_sdk/src/tools/common.mk @@ -326,10 +326,6 @@ else POSIX_FLAGS ?= -g -O0 -pthread -MMD -DNACL_SDK_DEBUG endif -ifdef STANDALONE -POSIX_FLAGS += -DSEL_LDR=1 -endif - NACL_CFLAGS ?= -Wno-long-long -Werror NACL_CXXFLAGS ?= -Wno-long-long -Werror NACL_LDFLAGS += -Wl,-as-needed -pthread |