1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4 <!-- Copyright 2008 Google Inc. All rights reserved. -->
6 <title> SRPC Descriptor Passing Test
</title>
7 <style type=
"text/css">
8 td
.notrun
{ background-color: skyblue
}
9 td
.pass
{ background-color: lime
}
10 td
.fail
{ background-color: red
}
12 <script type=
"application/x-javascript">
17 var GeneralLog = function(str) {
18 var output = document.getElementById('GeneralOutput');
19 output.innerHTML += str + '<br>';
22 var SocketAddressLog = function(str) {
23 var output = document.getElementById('SocketAddressOutput');
24 output.innerHTML += str + '<br>';
27 var SetTestResult = function(element_id, result) {
28 var element = document.getElementById(element_id);
29 if ('pass' == result) {
30 element.className = 'pass';
32 element.className = 'fail';
35 var SocketAddressNaClToNacl = function() {
36 SocketAddressLog('<b> NaCl to NaCl Test');
37 SocketAddressLog('Invoking server.start_server');
38 var socket_address = server.start_server();
39 SocketAddressLog('Invoking NaCl client.sock_addr_client');
40 client_errors = client.sock_addr_client(socket_address);
41 var server_errors = server.report();
42 if (client_errors == 0 && server_errors == 0) {
43 SocketAddressLog('TEST PASSED');
44 SetTestResult('addr_nacl_nacl', 'pass');
45 } else if (client_errors == 0) {
46 SocketAddressLog('Server errors -- NaClToNaCl TEST FAILED');
47 SetTestResult('addr_nacl_nacl', 'fail');
49 SocketAddressLog('Client errors -- NaClToNaCl TEST FAILED');
50 SetTestResult('addr_nacl_nacl', 'fail');
54 var SocketAddressNaClToBrowser = function() {
55 SocketAddressLog('<b> NaCl to Browser Test');
56 SocketAddressLog('Invoking server.start_server');
57 var socket_address2 = server.start_server();
58 SocketAddressLog('Invoking connect');
59 var con_sock = socket_address2.connect();
60 SocketAddressLog('Invoking getmsg');
61 var retval = con_sock.getmsg(100);
63 for (var i = 0; i < retval.length && retval[i] != 0; i++) {
64 str += String.fromCharCode(retval[i]);
66 SocketAddressLog(str);
67 var server_errors = server.report();
68 if (server_errors == 0) {
69 SocketAddressLog('TEST PASSED');
70 SetTestResult('addr_nacl_browser', 'pass');
72 SocketAddressLog('Server errors -- NaClToBrowser TEST FAILED');
73 SetTestResult('addr_nacl_browser', 'fail');
77 var SharedMemoryLog = function(str) {
78 var output = document.getElementById('SharedMemoryOutput');
79 output.innerHTML += str + '<br>';
82 var SharedMemoryBrowserToBrowser = function() {
83 // This tests the basic creation of shared memory objects and manipulation
84 // within the JavaScript bridge. It creates a shared memory region, writes a
85 // string into it, and tests that reading a substring suffix is correct.
86 var in_str = 'hello, world';
88 SharedMemoryLog('<b> Browser to Browser Test');
89 var shared_memory = server.__shmFactory(65536);
90 SharedMemoryLog('created shared memory region');
91 shared_memory.write(0, in_str.length, in_str);
92 SharedMemoryLog('wrote to shared memory region');
93 var rval = shared_memory.read(0xFFFF - 0x80000000 - 10, 0x80000000);
94 if (rval == in_str.substring(test_offset)) {
95 SharedMemoryLog('TEST PASSED');
96 SetTestResult('mem_browser_browser', 'pass');
98 SharedMemoryLog('Strings miscompare: BrowserToBrowser TEST FAILED');
99 SetTestResult('mem_browser_browser', 'fail');
103 var SharedMemoryBrowserToNaCl = function() {
104 // This tests passing of shared memory objects from the browser to NaCl
105 // modules. It creates a shared memory region, writes a string to the region,
106 // invokes a method in the server that checks for the expected string and
107 // writes another string immediately after. It then checks the written
108 // return string and error count.
109 var in_str = 'hello, world';
110 var compare_string = 'Quod erat demonstrandum';
111 var region_size = 65536;
112 SharedMemoryLog('<b> Browser to NaCl Test');
113 // var shared_memory = server.__shmFactory(region_size);
114 SharedMemoryLog('created shared memory region');
115 shared_memory.write(0, in_str.length, in_str);
116 SharedMemoryLog('wrote to shared memory region');
117 var server_errors = server.test_shared_memory(shared_memory, in_str);
118 var rval = shared_memory.read(in_str.length, compare_string.length);
119 if (server_errors == 0 && rval == compare_string) {
120 SharedMemoryLog('TEST PASSED');
121 SetTestResult('mem_browser_nacl', 'pass');
123 SharedMemoryLog('Strings miscompare: BrowserToNaCl TEST FAILED');
124 SetTestResult('mem_browser_nacl', 'fail');
128 var SharedMemoryNaClToBrowser = function() {
129 // This tests passing of shared memory objects from NaCl to the browser.
130 // It invokes a method in client to create a shared memory region and write a
131 // string to the region.
132 var region_size = 65536;
133 SharedMemoryLog('<b> NaCl to Browser Test');
134 var retval = client.shared_memory_client(region_size);
135 var handle = retval[0];
136 var in_str = retval[1];
137 var client_errors = retval[2];
138 SharedMemoryLog('Compare to: ' + in_str);
139 var shared_memory = handle.map();
140 var read_string = shared_memory.read(0, in_str.length);
141 if (client_errors == 0 && in_str == read_string) {
142 SharedMemoryLog('TEST PASSED');
143 SetTestResult('mem_nacl_browser', 'pass');
145 SharedMemoryLog('Strings miscompare: NaClToBrowser TEST FAILED');
146 SetTestResult('mem_nacl_browser', 'fail');
150 var SharedMemoryNaClToNaCl = function() {
151 // This tests passing of shared memory objects from NaCl to NaCl.
152 // It invokes a method in client to create a shared memory region and write a
153 // string to the region. This region is then passed to the server, which
154 // checks the region and writes its own string and an error count.
155 var compare_string = 'Quod erat demonstrandum';
156 var region_size = 65536;
157 SharedMemoryLog('<b> NaCl to NaCl Test');
158 var retval = client.shared_memory_client(region_size);
159 var handle = retval[0];
160 var in_str = retval[1];
161 var client_errors = retval[2];
162 SharedMemoryLog('Compare to: ' + in_str);
163 var shared_memory = handle.map();
164 var server_errors = server.test_shared_memory(shared_memory, in_str);
165 var rval = shared_memory.read(in_str.length, compare_string.length);
166 if (client_errors == 0 && server_errors == 0 && rval == compare_string) {
167 SharedMemoryLog('TEST PASSED');
168 SetTestResult('mem_nacl_nacl', 'pass');
170 SharedMemoryLog('Strings miscompare: NaClToNaCl TEST FAILED');
171 SetTestResult('mem_nacl_nacl', 'fail');
175 var RunAllTests = function() {
176 // socket address passing tests.
177 SocketAddressNaClToBrowser();
178 SocketAddressNaClToNacl();
179 // shared memory passing tests.
180 SharedMemoryBrowserToBrowser();
181 SharedMemoryBrowserToNaCl();
182 SharedMemoryNaClToBrowser();
183 SharedMemoryNaClToNaCl();
186 // Before running tests we need to ensure the Native Client modules are loaded.
189 var RunTestsAfterLoad = function() {
190 if (client.__moduleReady && server.__moduleReady) {
191 clearTimeout(startupTimeout);
194 if (client.__moduleReady == undefined ||
195 server.__moduleReady == undefined) {
196 alert('The Native Client plugin was unable to load');
199 GeneralLog('waiting for loads...');
200 startupTimeout = setTimeout(RunTestsAfterLoad, 100);
204 // Init is called when the document has completed loading.
205 var Init = function(boxsize) {
206 // Remember objects to make access to the elements easier.
207 client = document.getElementById('nacl_client');
208 server = document.getElementById('nacl_server');
209 // Run the tests after ensuring loads have completed.
215 <body onload=
"Init();">
216 <h1> SRPC Descriptor Passing Test
</h1>
217 <table border=
5 cellpadding=
5%
218 summary=
"A three-column table of test results">
221 <button type=
"button" onclick=
"RunAllTests()"> Run All Tests
</button>
223 <td align=center
> <b> Socket Address Passing
</b> </td>
224 <td align=center
> <b> Shared Memory Passing
</b> </td>
227 <td align=center
> <b> Browser to Browser
</b> </td>
228 <td align=center
> <em> Not applicable
</em> </td>
229 <td align=center
id=
"mem_browser_browser" class=
"notrun">
230 <button type=
"button" onclick=
"SharedMemoryBrowserToBrowser()">
236 <td> <b> Browser to NaCl
</b> </td>
237 <td align=center
> <em> Not applicable
</em> </td>
238 <td align=center
id=
"mem_browser_nacl" class=
"notrun">
239 <button type=
"button" onclick=
"SharedMemoryBrowserToNaCl()">
245 <td> <b> NaCl to Browser
</b> </td>
246 <td align=center
id=
"addr_nacl_browser" class=
"notrun">
247 <button type=
"button" onclick=
"SocketAddressNaClToBrowser()">
251 <td align=center
id=
"mem_nacl_browser" class=
"notrun">
252 <button type=
"button" onclick=
"SharedMemoryNaClToBrowser()">
258 <td> <b> NaCl to NaCl
</b> </td>
259 <td align=center
id=
"addr_nacl_nacl" class=
"notrun">
260 <button type=
"button" onclick=
"SocketAddressNaClToNacl()">
264 <td align=center
id=
"mem_nacl_nacl" class=
"notrun">
265 <button type=
"button" onclick=
"SharedMemoryNaClToNaCl()">
271 <table summary=
"The color codes used for identifying test outcomes">
272 <tr> <td align=
"center"> <em> Legend
</em> </td> </tr>
273 <tr> <td align=
"center" class=
"notrun"> Test not run
</td> </tr>
274 <tr> <td align=
"center" class=
"pass"> Test passed
</td> </tr>
275 <tr> <td align=
"center" class=
"fail"> Test failed
</td> </tr>
278 <h2> Output logs
</h2>
280 <table border=
5 cellpadding=
5%
summary=
"A three-column test output log">
282 <td> <b> General test output
</b> </td>
283 <td> <b> Socket address test output
</b> </td>
284 <td> <b> Shared memory test output
</b> </td>
287 <td valign=top
id=
"GeneralOutput"> </td>
288 <td valign=top
id=
"SocketAddressOutput"> </td>
289 <td valign=top
id=
"SharedMemoryOutput"> </td>
292 <embed type=
"application/x-nacl-srpc" id=
"nacl_client"
293 width=
"0" height=
"0" src=
"srpc_nrd_client.nexe" />
294 <embed type=
"application/x-nacl-srpc" id=
"nacl_server"
295 width=
"0" height=
"0" src=
"srpc_nrd_server.nexe" />