Commit dc023873 authored by sbc's avatar sbc Committed by Commit bot

[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}
parent 37accc2c
......@@ -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):
......
......@@ -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
......@@ -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
// 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_ */
......@@ -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_
......@@ -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);
}
......@@ -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
......
......@@ -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'))]]
......
......@@ -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
......@@ -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) {
......
......@@ -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
......@@ -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
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment