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

Side by Side Diff: tests/manifest_file/irt_manifest_file_test.cc

Issue 7605029: Extend IRT with nacl_irt_resource_open interface (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: more lint warnings Created 9 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7 //
8 // Post-message based test for manifest file open.
9 //
10
11 #include <stdio.h>
12 #include <string.h>
13
14 #include <string>
15
16 #include "native_client/src/include/elf32.h"
17 #include "native_client/src/include/elf_auxv.h"
18
19 #include "native_client/src/shared/ppapi_proxy/ppruntime.h"
20 #include "native_client/src/untrusted/irt/irt.h"
21
22 #include "ppapi/cpp/instance.h"
23 #include "ppapi/cpp/module.h"
24 #include "ppapi/cpp/var.h"
25
26 /*
27 * TODO(mcgrathr): This extremely stupid function should not exist.
28 * If the startup calling sequence were sane, this would be done
29 * someplace that has the initial pointer locally rather than stealing
30 * it from environ.
31 * See http://code.google.com/p/nativeclient/issues/detail?id=651
32 */
33 static Elf32_auxv_t *find_auxv(void) {
34 /*
35 * This presumes environ has its startup-time value on the stack.
36 */
37 char **ep = environ;
38 while (*ep != NULL)
39 ++ep;
40 return (Elf32_auxv_t *) (ep + 1);
41 }
42
43 /*
44 * Scan the auxv for AT_SYSINFO, which is the pointer to the IRT query function.
45 * TODO(mcgrathr): Could get this from __nacl_irt_query, where the libnacl
46 * startup code stored it, but that would have to be also added as part of
47 * the glibc ABI.
48 */
49 static TYPE_nacl_irt_query grok_auxv(const Elf32_auxv_t *auxv) {
50 const Elf32_auxv_t *av;
51 for (av = auxv; av->a_type != AT_NULL; ++av) {
52 if (av->a_type == AT_SYSINFO)
53 return (TYPE_nacl_irt_query) av->a_un.a_val;
54 }
55 return NULL;
56 }
57
58 std::string str;
59
60 void load_manifest(TYPE_nacl_irt_query *query_func) {
61 struct nacl_irt_manifest_open nacl_irt_manifest_open;
62 printf("load_manifest\n");
63 if (sizeof(nacl_irt_manifest_open) !=
64 (*query_func)(
65 NACL_IRT_MANIFEST_OPEN_v0_0,
66 &nacl_irt_manifest_open,
67 sizeof(nacl_irt_manifest_open))) {
68 printf("irt manifest api not found\n");
69 return;
70 }
71 int desc;
72 desc = nacl_irt_manifest_open.open_file_in_manifest("files/test_file");
73 if (-1 == desc) {
74 str = "Invalid file descriptor\n";
75 printf("%s", str.c_str());
76 return;
77 }
78
79 str = "File Contents:\n";
80
81 FILE *iob = fdopen(desc, "r");
82 char buffer[4096];
83 while (fgets(buffer, sizeof buffer, iob) != NULL) {
84 // NB: fgets does not discard the newline nor any carriage return
85 // character before that.
86 //
87 // Note that CR LF is the default end-of-line style for Windows.
pasko-google - do not use 2011/08/15 10:35:09 This is too complex and tied to our build-try-comm
88 // Furthermore, when the test_file (input data, which happens to
89 // be the nmf file) is initially created in a change list, the
90 // patch is sent to our try bots as text. This means that when
91 // the file arrives, it has CR LF endings instead of the original
92 // LF line endings. Since the expected or golden data is
93 // (manually) encoded in the HTML file's JavaScript, there will be
94 // a mismatch. After submission, the svn property svn:eol-style
95 // will be set to LF, so a clean check out should have LF and not
96 // CR LF endings, and the tests will pass without CR removal.
97 // However -- and there's always a however in long discourses --
98 // if the nmf file is edited, say, because the test is being
99 // modified, and the modification is being done on a Windows
100 // machine, then it is likely that the editor used by the
101 // programmer will convert the file to CR LF endings. Which,
102 // unfortunatly, implies that the test will mysteriously fail
103 // again.
104 //
105 // To defend against such nonsense, we weaken the test slighty,
106 // and just strip the CR if it is present.
107 int len = strlen(buffer);
108 if (len >= 2 && buffer[len-1] == '\n' && buffer[len-2] == '\r') {
109 buffer[len-2] = '\n';
110 buffer[len-1] = '\0';
111 }
112 str += buffer;
113 }
114 printf("file loaded: %s\n", str.c_str());
115 fclose(iob); // closed desc
116 return;
117 }
118
119 class TestInstance : public pp::Instance {
120 public:
121 explicit TestInstance(PP_Instance instance) : pp::Instance(instance) {}
122 virtual ~TestInstance() {}
123 virtual void HandleMessage(const pp::Var& var_message) {
124 if (!var_message.is_string()) {
125 return;
126 }
127 if (var_message.AsString() != "hello") {
128 return;
129 }
130 pp::Var reply = pp::Var(str);
131 PostMessage(reply);
132 }
133 };
134
135 class TestModule : public pp::Module {
136 public:
137 TestModule() : pp::Module() {}
138 virtual ~TestModule() {}
139
140 virtual pp::Instance* CreateInstance(PP_Instance instance) {
141 return new TestInstance(instance);
142 }
143 };
144
145 namespace pp {
146 Module* CreateModule() {
147 return new TestModule();
148 }
149 }
150
151 int main() {
152 TYPE_nacl_irt_query query_func = grok_auxv(find_auxv());
Roland McGrath 2011/08/12 16:44:56 Don't do all the auxv grovelling here. You can ju
halyavin 2011/08/15 10:35:52 Done.
153 printf("main\n");
154 if (NULL == query_func)
155 printf("PpapiPluginStart: No AT_SYSINFO item found in auxv, "
156 "so cannot start PPAPI. Is the IRT library not present?\n");
157 load_manifest(&query_func);
158 return PpapiPluginMain();
159 }
160
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698