OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2014 The Chromium Authors. All rights reserved. | 2 * Copyright 2014 The Chromium Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 // | 7 // |
8 // Test for resource open before PPAPI initialization. | 8 // Test for resource open before PPAPI initialization. |
9 // | 9 // |
10 | 10 |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 #include <string.h> | 12 #include <string.h> |
13 | 13 |
14 #include <sstream> | 14 #include <sstream> |
15 #include <string> | 15 #include <string> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "native_client/src/untrusted/irt/irt.h" | 18 #include "native_client/src/untrusted/irt/irt.h" |
19 #include "native_client/src/untrusted/nacl/nacl_irt.h" | 19 #include "native_client/src/untrusted/nacl/nacl_irt.h" |
20 | 20 |
21 #include "ppapi/cpp/completion_callback.h" | |
21 #include "ppapi/cpp/instance.h" | 22 #include "ppapi/cpp/instance.h" |
22 #include "ppapi/cpp/module.h" | 23 #include "ppapi/cpp/module.h" |
23 #include "ppapi/cpp/var.h" | 24 #include "ppapi/cpp/var.h" |
24 #include "ppapi/cpp/var_array.h" | 25 #include "ppapi/cpp/var_array.h" |
25 #include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h" | 26 #include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h" |
26 | 27 |
27 | 28 |
28 std::vector<std::string> result; | 29 std::vector<std::string> result; |
29 | 30 |
31 pp::Instance* g_instance = NULL; | |
32 | |
30 std::string LoadManifestSuccess(TYPE_nacl_irt_query *query_func) { | 33 std::string LoadManifestSuccess(TYPE_nacl_irt_query *query_func) { |
31 struct nacl_irt_resource_open nacl_irt_resource_open; | 34 struct nacl_irt_resource_open nacl_irt_resource_open; |
32 if (sizeof(nacl_irt_resource_open) != | 35 if (sizeof(nacl_irt_resource_open) != |
33 (*query_func)( | 36 (*query_func)( |
34 NACL_IRT_RESOURCE_OPEN_v0_1, | 37 NACL_IRT_RESOURCE_OPEN_v0_1, |
35 &nacl_irt_resource_open, | 38 &nacl_irt_resource_open, |
36 sizeof(nacl_irt_resource_open))) { | 39 sizeof(nacl_irt_resource_open))) { |
37 return "irt manifest api not found"; | 40 return "irt manifest api not found"; |
38 } | 41 } |
39 int desc; | 42 int desc; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 if (error != ENOENT) { | 108 if (error != ENOENT) { |
106 printf("Unexpected error code: %d\n", error); | 109 printf("Unexpected error code: %d\n", error); |
107 char buf[80]; | 110 char buf[80]; |
108 snprintf(buf, sizeof(buf), "open_resource() result: %d", error); | 111 snprintf(buf, sizeof(buf), "open_resource() result: %d", error); |
109 return std::string(buf); | 112 return std::string(buf); |
110 } | 113 } |
111 | 114 |
112 return "Pass"; | 115 return "Pass"; |
113 } | 116 } |
114 | 117 |
118 void RunTests() { | |
119 result.push_back(LoadManifestSuccess(&__nacl_irt_query)); | |
120 result.push_back(LoadManifestNonExistentEntry(&__nacl_irt_query)); | |
121 result.push_back(LoadManifestNonExistentFile(&__nacl_irt_query)); | |
122 } | |
123 | |
124 void PostReply(void* user_data, int32_t status) { | |
125 pp::VarArray reply = pp::VarArray(); | |
126 for (size_t i = 0; i < result.size(); ++i) | |
127 reply.Set(i, pp::Var(result[i])); | |
128 g_instance->PostMessage(reply); | |
129 } | |
130 | |
131 void* RunTestsOnBackgroundThread(void *thread_id) { | |
132 RunTests(); | |
133 pp::Module::Get()->core()->CallOnMainThread( | |
Mark Seaborn
2014/09/04 17:41:36
BTW, why does this require a CallOnMainThread()?
teravest
2014/09/04 20:21:28
pp::Instance::PostMessage() has to be called from
Mark Seaborn
2014/09/04 22:00:41
Hmm, you mean the C++ wrappers for PPAPI add a thr
teravest
2014/09/04 22:12:39
I believe that only happens for pp::Instance.
Ther
dmichael (off chromium)
2014/09/05 19:44:08
In theory it doesn't matter for NaCl, since we jus
| |
134 0, pp::CompletionCallback(&PostReply, NULL)); | |
135 return NULL; | |
136 } | |
137 | |
115 class TestInstance : public pp::Instance { | 138 class TestInstance : public pp::Instance { |
116 public: | 139 public: |
117 explicit TestInstance(PP_Instance instance) : pp::Instance(instance) {} | 140 explicit TestInstance(PP_Instance instance) : pp::Instance(instance) { |
141 g_instance = this; | |
142 } | |
143 | |
118 virtual ~TestInstance() {} | 144 virtual ~TestInstance() {} |
119 virtual void HandleMessage(const pp::Var& var_message) { | 145 virtual void HandleMessage(const pp::Var& var_message) { |
120 if (!var_message.is_string()) { | 146 if (!var_message.is_string()) { |
121 return; | 147 return; |
122 } | 148 } |
123 if (var_message.AsString() != "hello") { | 149 if (var_message.AsString() != "hello") { |
124 return; | 150 return; |
125 } | 151 } |
126 pp::VarArray reply = pp::VarArray(); | 152 |
127 for (size_t i = 0; i < result.size(); ++i) { | 153 // We test the manifest routines again after PPAPI has initialized to |
128 reply.Set(i, pp::Var(result[i])); | 154 // ensure that they still work. |
129 } | 155 // |
130 PostMessage(reply); | 156 // irt_open_resource() isn't allowed to be called on the main thread once |
157 // pepper starts, so these tests must happen on a background thread. | |
158 pthread_create(&thread_, NULL, &RunTestsOnBackgroundThread, NULL); | |
Mark Seaborn
2014/09/04 17:41:36
Nit: can you check the return value?
Nit: thread_
teravest
2014/09/04 20:21:28
Sure, do you want me to write a change to fix up t
Mark Seaborn
2014/09/04 22:00:41
It's your call -- I'll leave it up to you.
| |
131 } | 159 } |
160 private: | |
161 pthread_t thread_; | |
132 }; | 162 }; |
133 | 163 |
134 class TestModule : public pp::Module { | 164 class TestModule : public pp::Module { |
135 public: | 165 public: |
136 TestModule() : pp::Module() {} | 166 TestModule() : pp::Module() {} |
137 virtual ~TestModule() {} | 167 virtual ~TestModule() {} |
138 | 168 |
139 virtual pp::Instance* CreateInstance(PP_Instance instance) { | 169 virtual pp::Instance* CreateInstance(PP_Instance instance) { |
140 return new TestInstance(instance); | 170 return new TestInstance(instance); |
141 } | 171 } |
142 }; | 172 }; |
143 | 173 |
144 namespace pp { | 174 namespace pp { |
145 Module* CreateModule() { | 175 Module* CreateModule() { |
146 return new TestModule(); | 176 return new TestModule(); |
147 } | 177 } |
148 } | 178 } |
149 | 179 |
150 int main() { | 180 int main() { |
151 result.push_back(LoadManifestSuccess(&__nacl_irt_query)); | 181 RunTests(); |
152 result.push_back(LoadManifestNonExistentEntry(&__nacl_irt_query)); | |
153 result.push_back(LoadManifestNonExistentFile(&__nacl_irt_query)); | |
154 return PpapiPluginMain(); | 182 return PpapiPluginMain(); |
155 } | 183 } |
OLD | NEW |