Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Unified Diff: ppapi/native_client/tests/nacl_browser/sysconf_nprocessors/sysconf_nprocessors_onln_test.cc

Issue 14238013: Set up NaClChromeMainArgs number_of_cores member so apps can size threadpools appropriately (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ppapi/native_client/tests/nacl_browser/sysconf_nprocessors/sysconf_nprocessors_onln_test.cc
diff --git a/chrome/test/data/nacl/exit_status/pm_exit_status_test.cc b/ppapi/native_client/tests/nacl_browser/sysconf_nprocessors/sysconf_nprocessors_onln_test.cc
similarity index 61%
copy from chrome/test/data/nacl/exit_status/pm_exit_status_test.cc
copy to ppapi/native_client/tests/nacl_browser/sysconf_nprocessors/sysconf_nprocessors_onln_test.cc
index d1289cf060f55021a9d4af5f4c064f8697cd4594..9c801f39d6e9b7d679fcecca80d1528d79a4fbca 100644
--- a/chrome/test/data/nacl/exit_status/pm_exit_status_test.cc
+++ b/ppapi/native_client/tests/nacl_browser/sysconf_nprocessors/sysconf_nprocessors_onln_test.cc
@@ -5,59 +5,38 @@
*/
/*
- * Post-message based test for testing crash detection.
+ * Post-message based test for simple rpc based access to sysconf result.
*/
-#include <string>
#include <assert.h>
+#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
-#include <inttypes.h>
-#include <sys/fcntl.h>
#include <string.h>
+#include <sys/fcntl.h>
#include <unistd.h>
+#include "native_client/src/include/nacl_scoped_ptr.h"
+#include "native_client/src/shared/srpc/nacl_srpc.h"
+#include "native_client/src/untrusted/nacl_ppapi_util/nacl_ppapi_util.h"
+#include "native_client/src/untrusted/nacl_ppapi_util/string_buffer.h"
+
#include <sys/nacl_syscalls.h>
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/var.h"
-void Initialize(const pp::Var& message_data, std::string* out) {
- *out = "hello world";
-}
-
-void RunExit0(const pp::Var& message_data, std::string* out) {
- *out = "good bye cruel world";
- // the out string should not actually get sent back in reply, since
- // we exit immediately.
- exit(0);
-}
-
-void RunExit7(const pp::Var& message_data, std::string* out) {
- *out = "good bye cruel world";
- // the out string should not actually get sent back in reply, since
- // we exit immediately.
- exit(7);
-}
+void NumProcessors(const pp::Var& message_data, nacl::StringBuffer* sb) {
+ int num_cores;
-void RunExit254(const pp::Var& message_data, std::string* out) {
- *out = "good bye cruel world";
- // the out string should not actually get sent back in reply, since
- // we exit immediately.
- exit(254);
-}
-
-void RunExitNeg2(const pp::Var& message_data, std::string* out) {
- *out = "good bye cruel world";
- // the out string should not actually get sent back in reply, since
- // we exit immediately.
- exit(-2);
+ num_cores = sysconf(_SC_NPROCESSORS_ONLN);
+ sb->Printf("%d", num_cores);
}
struct PostMessageHandlerDesc {
char const *request;
- void (*handler)(const pp::Var& message_data, std::string* out);
+ void (*handler)(const pp::Var& message_data, nacl::StringBuffer* out);
};
// This object represents one time the page says <embed>.
@@ -74,24 +53,20 @@ class MyInstance : public pp::Instance {
// reply string -- essentially treating this as a string-based RPC.
void MyInstance::HandleMessage(const pp::Var& message_data) {
static struct PostMessageHandlerDesc kMsgHandlers[] = {
- { "init", Initialize },
- { "exit0", RunExit0 },
- { "exit7", RunExit7 },
- { "exit254", RunExit254 },
- { "exitneg2", RunExitNeg2 },
+ { "nprocessors", NumProcessors },
{ reinterpret_cast<char const *>(NULL),
- reinterpret_cast<void (*)(const pp::Var&, std::string*)>(NULL) }
+ reinterpret_cast<void (*)(const pp::Var&, nacl::StringBuffer*)>(NULL) }
};
+ nacl::StringBuffer sb;
if (message_data.is_string()) {
std::string op_name(message_data.AsString());
+ std::string reply;
size_t len;
fprintf(stderr, "Searching for handler for request \"%s\".\n",
op_name.c_str());
- std::string sb;
-
for (size_t ix = 0; kMsgHandlers[ix].request != NULL; ++ix) {
if (op_name == kMsgHandlers[ix].request) {
fprintf(stderr, "found at index %u\n", ix);
@@ -100,12 +75,17 @@ void MyInstance::HandleMessage(const pp::Var& message_data) {
}
}
- len = strlen(sb.c_str());
+ reply = sb.ToString();
+ len = strlen(reply.c_str());
fprintf(stderr, "posting reply len %d\n", len);
- fprintf(stderr, "posting reply \"%s\".\n", sb.c_str());
+ // fprintf(stderr, "posting reply \"%s\".\n", sb.ToString().c_str());
+ fprintf(stderr, "posting reply \"");
+ fflush(stderr);
+ write(2, reply.c_str(), len);
+ fprintf(stderr, "\".\n");
fflush(stderr);
- PostMessage(pp::Var(sb));
+ PostMessage(pp::Var(sb.ToString()));
fprintf(stderr, "returning\n");
fflush(stderr);
}
@@ -128,7 +108,6 @@ namespace pp {
// Factory function for your specialization of the Module object.
Module* CreateModule() {
- printf("hello world from CreateModule\n"); fflush(NULL);
return new MyModule();
}

Powered by Google App Engine
This is Rietveld 408576698