OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 The Native Client Authors. All rights reserved. | 2 * Copyright 2010 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can | 3 * Use of this source code is governed by a BSD-style license that can |
4 * be found in the LICENSE file. | 4 * be found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <nacl/nacl_srpc.h> | 8 #include <nacl/nacl_srpc.h> |
9 | 9 |
10 #include "native_client/tests/inbrowser_test_runner/test_runner.h" | 10 #include "native_client/tests/inbrowser_test_runner/test_runner.h" |
11 | 11 |
12 | 12 |
13 /* We use SRPC to send the test results back to Javascript. This was | 13 /* We use SRPC to send the test results back to Javascript. This was |
14 quick to write, but it has the significant disadvantage that it | 14 quick to write, but it has the significant disadvantage that it |
15 blocks the browser/renderer while the test is running. This would | 15 blocks the browser/renderer while the test is running. This would |
16 not be good if we have tests that fail by hanging. | 16 not be good if we have tests that fail by hanging. |
17 TODO(mseaborn): We could switch to using async messaging instead. */ | 17 TODO(mseaborn): We could switch to using async messaging instead. */ |
18 | 18 |
19 /* Use of a global variable is just a short cut, since | 19 /* Use of a global variable is just a short cut, since |
20 NaClSrpcAcceptClientOnThread() does not take arguments besides | 20 NaClSrpcAcceptClientOnThread() does not take arguments besides |
21 function pointers. */ | 21 function pointers. */ |
22 static int (*g_test_func)(void); | 22 static int (*g_test_func)(void); |
23 | 23 |
24 void RunTestsWrapper(NaClSrpcRpc *rpc, | 24 void RunTestsWrapper(NaClSrpcRpc *rpc, |
25 NaClSrpcArg **in_args, | 25 NaClSrpcArg **in_args, |
26 NaClSrpcArg **out_args, | 26 NaClSrpcArg **out_args, |
27 NaClSrpcClosure *done) { | 27 NaClSrpcClosure *done) { |
28 int result = g_test_func(); | 28 int result = g_test_func(); |
29 out_args[0]->u.sval.str = strdup(result == 0 ? "passed" : "failed"); | 29 out_args[0]->arrays.str = strdup(result == 0 ? "passed" : "failed"); |
30 rpc->result = NACL_SRPC_RESULT_OK; | 30 rpc->result = NACL_SRPC_RESULT_OK; |
31 done->Run(done); | 31 done->Run(done); |
32 } | 32 } |
33 | 33 |
34 const struct NaClSrpcHandlerDesc srpc_methods[] = { | 34 const struct NaClSrpcHandlerDesc srpc_methods[] = { |
35 { "run_tests::s", RunTestsWrapper }, | 35 { "run_tests::s", RunTestsWrapper }, |
36 { NULL, NULL }, | 36 { NULL, NULL }, |
37 }; | 37 }; |
38 | 38 |
39 int RunTests(int (*test_func)(void)) { | 39 int RunTests(int (*test_func)(void)) { |
40 /* Turn off stdout buffering to aid debugging in case of a crash. */ | 40 /* Turn off stdout buffering to aid debugging in case of a crash. */ |
41 setvbuf(stdout, NULL, _IONBF, 0); | 41 setvbuf(stdout, NULL, _IONBF, 0); |
42 if (NaClSrpcIsStandalone()) { | 42 if (NaClSrpcIsStandalone()) { |
43 return test_func(); | 43 return test_func(); |
44 } else { | 44 } else { |
45 g_test_func = test_func; | 45 g_test_func = test_func; |
46 if (!NaClSrpcModuleInit()) { | 46 if (!NaClSrpcModuleInit()) { |
47 return 1; | 47 return 1; |
48 } | 48 } |
49 return !NaClSrpcAcceptClientOnThread(srpc_methods); | 49 return !NaClSrpcAcceptClientOnThread(srpc_methods); |
50 } | 50 } |
51 } | 51 } |
OLD | NEW |