summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbinji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-06 22:22:01 +0000
committerbinji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-06 22:22:01 +0000
commit3cfdab14e64202bfbe2b31a609ef3a8aeddef4ae (patch)
treeb14da41c545743b602a1f2f931f2e01ac0c2428b
parent81bf18bf1f2a7e068a631ca5a2de259278885867 (diff)
downloadchromium_src-3cfdab14e64202bfbe2b31a609ef3a8aeddef4ae.zip
chromium_src-3cfdab14e64202bfbe2b31a609ef3a8aeddef4ae.tar.gz
chromium_src-3cfdab14e64202bfbe2b31a609ef3a8aeddef4ae.tar.bz2
[NaCl SDK] Run nacl_io_socket_test on the bots.
Also added PS_EXIT_MESSAGE to ppapi_simple; this will prevent exit() from being called when the main() function returns. Instead, it will PostMessage to JavaScript. BUG=none R=sbc@chromium.org Review URL: https://codereview.chromium.org/61213002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233397 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--native_client_sdk/src/libraries/ppapi_simple/ps_instance.cc37
-rw-r--r--native_client_sdk/src/libraries/ppapi_simple/ps_instance.h4
-rw-r--r--native_client_sdk/src/tests/nacl_io_socket_test/example.js18
-rw-r--r--native_client_sdk/src/tests/nacl_io_socket_test/index.html2
-rw-r--r--native_client_sdk/src/tests/nacl_io_socket_test/test.js18
-rw-r--r--native_client_sdk/src/tests/nacl_io_test/example.js1
-rw-r--r--native_client_sdk/src/tests/nacl_io_test/index.html2
-rw-r--r--native_client_sdk/src/tests/nacl_io_test/main.cc14
-rw-r--r--native_client_sdk/src/tests/sdk_util_test/example.js19
-rw-r--r--native_client_sdk/src/tests/sdk_util_test/index.html2
-rw-r--r--native_client_sdk/src/tests/sdk_util_test/test.js18
11 files changed, 108 insertions, 27 deletions
diff --git a/native_client_sdk/src/libraries/ppapi_simple/ps_instance.cc b/native_client_sdk/src/libraries/ppapi_simple/ps_instance.cc
index 8aa50b9..3f59e08 100644
--- a/native_client_sdk/src/libraries/ppapi_simple/ps_instance.cc
+++ b/native_client_sdk/src/libraries/ppapi_simple/ps_instance.cc
@@ -64,21 +64,39 @@ void* PSInstance::MainThreadThunk(void *info) {
si->inst_->main_loop_->AttachToCurrentThread();
int ret = si->inst_->MainThread(si->argc_, si->argv_);
+
+ char* exit_message = si->inst_->exit_message_;
+ bool should_exit = exit_message == NULL;
+
+ if (exit_message) {
+ // Send the exit message to JavaScript. Don't call exit(), so the message
+ // doesn't get dropped.
+ si->inst_->Log("Posting exit message to JavaScript.\n");
+ si->inst_->PostMessage(exit_message);
+ free(exit_message);
+ exit_message = si->inst_->exit_message_ = NULL;
+ }
+
+ // Clean up StartInfo.
for (uint32_t i = 0; i < si->argc_; i++) {
delete[] si->argv_[i];
}
delete[] si->argv_;
delete si;
- // Exit the entire process once the 'main' thread returns.
- // The error code will be available to javascript via
- // the exitcode paramater of the crash event.
- exit(ret);
+
+ if (should_exit) {
+ // Exit the entire process once the 'main' thread returns.
+ // The error code will be available to javascript via
+ // the exitcode parameter of the crash event.
+ exit(ret);
+ }
+
return NULL;
}
// The default implementation supports running a 'C' main.
-int PSInstance::MainThread(int argc, char *argv[]) {
+int PSInstance::MainThread(int argc, char* argv[]) {
if (!main_cb_) {
Error("No main defined.\n");
return 0;
@@ -87,6 +105,7 @@ int PSInstance::MainThread(int argc, char *argv[]) {
Trace("Starting MAIN.\n");
int ret = main_cb_(argc, argv);
Log("Main thread returned with %d.\n", ret);
+
return ret;
}
@@ -98,7 +117,8 @@ PSInstance::PSInstance(PP_Instance instance)
events_enabled_(PSE_NONE),
verbosity_(PSV_WARN),
tty_fd_(-1),
- tty_prefix_(NULL) {
+ tty_prefix_(NULL),
+ exit_message_(NULL) {
// Set the single Instance object
s_InstanceObject = this;
@@ -227,6 +247,11 @@ bool PSInstance::ProcessProperties() {
}
}
+ const char* exit_message = getenv("PS_EXIT_MESSAGE");
+ if (exit_message) {
+ exit_message_ = strdup(exit_message);
+ }
+
// Set line buffering on stdout and stderr
#if !defined(WIN32)
setvbuf(stderr, NULL, _IOLBF, 0);
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 1829bee..ce96aae 100644
--- a/native_client_sdk/src/libraries/ppapi_simple/ps_instance.h
+++ b/native_client_sdk/src/libraries/ppapi_simple/ps_instance.h
@@ -184,6 +184,10 @@ class PSInstance : public pp::Instance, pp::MouseLock, pp::Graphics3DClient {
const char* tty_prefix_;
MessageHandlerMap message_handlers_;
+ // A message to Post to JavaScript instead of exiting, or NULL if exit()
+ // should be called instead.
+ char* exit_message_;
+
PSMainFunc_t main_cb_;
const PPB_Core* ppb_core_;
diff --git a/native_client_sdk/src/tests/nacl_io_socket_test/example.js b/native_client_sdk/src/tests/nacl_io_socket_test/example.js
index 72b21ce..8b95dbf 100644
--- a/native_client_sdk/src/tests/nacl_io_socket_test/example.js
+++ b/native_client_sdk/src/tests/nacl_io_socket_test/example.js
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Called by the common.js module.
-
function moduleDidLoad() {
// The module is not hidden by default so we can easily see if the plugin
// failed to load.
@@ -10,6 +9,8 @@ function moduleDidLoad() {
}
var currentTestEl = null;
+var failedTests = 0;
+var testsFinished = false;
function startCommand(testName) {
var testListEl = document.getElementById('tests');
@@ -33,6 +34,7 @@ function failCommand(fileName, lineNumber, summary) {
var testMessageEl = document.createElement('pre');
testMessageEl.textContent += fileName + ':' + lineNumber + ': ' + summary;
currentTestEl.appendChild(testMessageEl);
+ failedTests++;
}
function endCommand(testName, testResult) {
@@ -42,10 +44,22 @@ function endCommand(testName, testResult) {
testResultEl.textContent = testResult;
}
+function testendCommand() {
+ testsFinished = true;
+
+ if (failedTests) {
+ common.updateStatus('FAILED');
+ document.getElementById('statusField').classList.add('failed');
+ } else {
+ common.updateStatus('OK');
+ document.getElementById('statusField').classList.add('ok');
+ }
+}
+
function handleMessage(event) {
var msg = event.data;
var firstColon = msg.indexOf(':');
- var cmd = msg.substr(0, firstColon);
+ var cmd = firstColon !== -1 ? msg.substr(0, firstColon) : msg;
var cmdFunctionName = cmd + 'Command';
var cmdFunction = window[cmdFunctionName];
diff --git a/native_client_sdk/src/tests/nacl_io_socket_test/index.html b/native_client_sdk/src/tests/nacl_io_socket_test/index.html
index ba54317..2a037b8 100644
--- a/native_client_sdk/src/tests/nacl_io_socket_test/index.html
+++ b/native_client_sdk/src/tests/nacl_io_socket_test/index.html
@@ -17,7 +17,7 @@ found in the LICENSE file.
.failed { background-color: #f00; }
</style>
</head>
-<body {{attrs}}>
+<body data-attrs="PS_EXIT_MESSAGE=testend" {{attrs}}>
<h1>{{title}}</h1>
<h2>Status: <code id="statusField">NO-STATUS</code></h2>
<!-- The NaCl plugin will be embedded inside the element with id "listener".
diff --git a/native_client_sdk/src/tests/nacl_io_socket_test/test.js b/native_client_sdk/src/tests/nacl_io_socket_test/test.js
new file mode 100644
index 0000000..88648ba
--- /dev/null
+++ b/native_client_sdk/src/tests/nacl_io_socket_test/test.js
@@ -0,0 +1,18 @@
+// Copyright (c) 2013 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.
+
+function addTests() {
+ common.tester.addAsyncTest('nacl_io_socket_test', function (test) {
+ var intervalId = window.setInterval(function () {
+ if (!testsFinished)
+ return;
+
+ window.clearInterval(intervalId);
+ if (failedTests > 0)
+ test.fail('tests failed');
+ else
+ test.pass();
+ }, 100);
+ });
+}
diff --git a/native_client_sdk/src/tests/nacl_io_test/example.js b/native_client_sdk/src/tests/nacl_io_test/example.js
index 829a490..8b95dbf 100644
--- a/native_client_sdk/src/tests/nacl_io_test/example.js
+++ b/native_client_sdk/src/tests/nacl_io_test/example.js
@@ -46,7 +46,6 @@ function endCommand(testName, testResult) {
function testendCommand() {
testsFinished = true;
- common.removeModule();
if (failedTests) {
common.updateStatus('FAILED');
diff --git a/native_client_sdk/src/tests/nacl_io_test/index.html b/native_client_sdk/src/tests/nacl_io_test/index.html
index ba54317..2a037b8 100644
--- a/native_client_sdk/src/tests/nacl_io_test/index.html
+++ b/native_client_sdk/src/tests/nacl_io_test/index.html
@@ -17,7 +17,7 @@ found in the LICENSE file.
.failed { background-color: #f00; }
</style>
</head>
-<body {{attrs}}>
+<body data-attrs="PS_EXIT_MESSAGE=testend" {{attrs}}>
<h1>{{title}}</h1>
<h2>Status: <code id="statusField">NO-STATUS</code></h2>
<!-- The NaCl plugin will be embedded inside the element with id "listener".
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 7722670..ef7b094 100644
--- a/native_client_sdk/src/tests/nacl_io_test/main.cc
+++ b/native_client_sdk/src/tests/nacl_io_test/main.cc
@@ -50,25 +50,13 @@ class GTestEventListener : public ::testing::EmptyTestEventListener {
<< "," << (test_info.result()->Failed() ? "failed" : "ok");
pp::Instance(PSGetInstanceId()).PostMessage(msg.str());
}
-
- virtual void OnTestProgramEnd(const ::testing::UnitTest&) {
- pp::Instance(PSGetInstanceId()).PostMessage("testend");
- }
};
int example_main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
::testing::UnitTest::GetInstance()->listeners()
.Append(new GTestEventListener());
- int result = RUN_ALL_TESTS();
-
- // When running as an automated test, we don't want the final message
- // ("testend") to be dropped, so don't exit. The web page will kill the
- // plugin if it needs to.
- while(1);
-
- // Silence the warning.
- return result;
+ return RUN_ALL_TESTS();
}
// Register the function to call once the Instance Object is initialized.
diff --git a/native_client_sdk/src/tests/sdk_util_test/example.js b/native_client_sdk/src/tests/sdk_util_test/example.js
index d004ac4..8b95dbf 100644
--- a/native_client_sdk/src/tests/sdk_util_test/example.js
+++ b/native_client_sdk/src/tests/sdk_util_test/example.js
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// 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.
// Called by the common.js module.
@@ -9,6 +9,8 @@ function moduleDidLoad() {
}
var currentTestEl = null;
+var failedTests = 0;
+var testsFinished = false;
function startCommand(testName) {
var testListEl = document.getElementById('tests');
@@ -32,6 +34,7 @@ function failCommand(fileName, lineNumber, summary) {
var testMessageEl = document.createElement('pre');
testMessageEl.textContent += fileName + ':' + lineNumber + ': ' + summary;
currentTestEl.appendChild(testMessageEl);
+ failedTests++;
}
function endCommand(testName, testResult) {
@@ -41,10 +44,22 @@ function endCommand(testName, testResult) {
testResultEl.textContent = testResult;
}
+function testendCommand() {
+ testsFinished = true;
+
+ if (failedTests) {
+ common.updateStatus('FAILED');
+ document.getElementById('statusField').classList.add('failed');
+ } else {
+ common.updateStatus('OK');
+ document.getElementById('statusField').classList.add('ok');
+ }
+}
+
function handleMessage(event) {
var msg = event.data;
var firstColon = msg.indexOf(':');
- var cmd = msg.substr(0, firstColon);
+ var cmd = firstColon !== -1 ? msg.substr(0, firstColon) : msg;
var cmdFunctionName = cmd + 'Command';
var cmdFunction = window[cmdFunctionName];
diff --git a/native_client_sdk/src/tests/sdk_util_test/index.html b/native_client_sdk/src/tests/sdk_util_test/index.html
index 20b24b5..cb85af1 100644
--- a/native_client_sdk/src/tests/sdk_util_test/index.html
+++ b/native_client_sdk/src/tests/sdk_util_test/index.html
@@ -17,7 +17,7 @@ found in the LICENSE file.
.failed { background-color: #f00; }
</style>
</head>
-<body {{attrs}}>
+<body data-attrs="PS_EXIT_MESSAGE=testend" {{attrs}}>
<h1>{{title}}</h1>
<h2>Status: <code id="statusField">NO-STATUS</code></h2>
<!-- The NaCl plugin will be embedded inside the element with id "listener".
diff --git a/native_client_sdk/src/tests/sdk_util_test/test.js b/native_client_sdk/src/tests/sdk_util_test/test.js
new file mode 100644
index 0000000..f207f00
--- /dev/null
+++ b/native_client_sdk/src/tests/sdk_util_test/test.js
@@ -0,0 +1,18 @@
+// Copyright (c) 2013 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.
+
+function addTests() {
+ common.tester.addAsyncTest('sdk_util_test', function (test) {
+ var intervalId = window.setInterval(function () {
+ if (!testsFinished)
+ return;
+
+ window.clearInterval(intervalId);
+ if (failedTests > 0)
+ test.fail('tests failed');
+ else
+ test.pass();
+ }, 100);
+ });
+}