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

Side by Side Diff: tests/nameservice/nameservice_test.c

Issue 550523002: Remove the old "SecureRandom" service, formerly used by get_random_bytes() (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Created 6 years, 3 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
« no previous file with comments | « src/trusted/service_runtime/service_runtime.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2012 The Native Client 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 #include <assert.h> 7 #include <assert.h>
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <inttypes.h> 10 #include <inttypes.h>
11 #include <sys/fcntl.h> 11 #include <sys/fcntl.h>
12 #include <string.h> 12 #include <string.h>
13 #include <unistd.h> 13 #include <unistd.h>
14 14
15 #include "native_client/src/include/nacl_assert.h"
15 #include "native_client/src/public/imc_syscalls.h" 16 #include "native_client/src/public/imc_syscalls.h"
16 #include "native_client/src/public/name_service.h" 17 #include "native_client/src/public/name_service.h"
17 #include "native_client/src/shared/srpc/nacl_srpc.h" 18 #include "native_client/src/shared/srpc/nacl_srpc.h"
18 19
19 #define RNG_OUTPUT_BYTES 1024
20
21 #define BYTES_PER_LINE 32
22 #define BYTE_SPACING 4
23
24 void dump_output(int d, size_t nbytes) {
25 uint8_t *bytes;
26 int got;
27 int copied;
28 int ix;
29
30 bytes = malloc(nbytes);
31 if (!bytes) {
32 perror("dump_output");
33 fprintf(stderr, "No memory\n");
34 return;
35 }
36 /* read output */
37 for (got = 0; got < nbytes; got += copied) {
38 copied = read(d, bytes + got, nbytes - got);
39 if (-1 == copied) {
40 perror("dump_output:read");
41 fprintf(stderr, "read failure\n");
42 break;
43 }
44 printf("read(%d, ..., %zd) -> %d\n", d, nbytes - got, copied);
45 }
46 /* hex dump it */
47 for (ix = 0; ix < got; ++ix) {
48 if (0 == (ix & (BYTES_PER_LINE-1))) {
49 printf("\n%04x:", ix);
50 } else if (0 == (ix & (BYTE_SPACING-1))) {
51 putchar(' ');
52 }
53 printf("%02x", bytes[ix]);
54 }
55 putchar('\n');
56
57 free(bytes);
58 }
59
60 int main(void) { 20 int main(void) {
61 int ns; 21 int ns;
62 NaClSrpcChannel channel; 22 NaClSrpcChannel channel;
63 int connected_socket; 23 int connected_socket;
64 int status; 24 int status;
65 int rng; 25 int rng;
66 26
67 if (!NaClSrpcModuleInit()) { 27 if (!NaClSrpcModuleInit()) {
68 fprintf(stderr, "srpc module init failed\n"); 28 fprintf(stderr, "srpc module init failed\n");
69 return 1; 29 return 1;
(...skipping 11 matching lines...) Expand all
81 return 1; 41 return 1;
82 } 42 }
83 printf("NaClSrpcClientCtor succeeded\n"); 43 printf("NaClSrpcClientCtor succeeded\n");
84 if (NACL_SRPC_RESULT_OK != 44 if (NACL_SRPC_RESULT_OK !=
85 NaClSrpcInvokeBySignature(&channel, NACL_NAME_SERVICE_LOOKUP, 45 NaClSrpcInvokeBySignature(&channel, NACL_NAME_SERVICE_LOOKUP,
86 "SecureRandom", O_RDONLY, &status, &rng)) { 46 "SecureRandom", O_RDONLY, &status, &rng)) {
87 fprintf(stderr, "nameservice lookup failed, status %d\n", status); 47 fprintf(stderr, "nameservice lookup failed, status %d\n", status);
88 return 1; 48 return 1;
89 } 49 }
90 printf("rpc status %d\n", status); 50 printf("rpc status %d\n", status);
91 assert(NACL_NAME_SERVICE_SUCCESS == status); 51 /*
92 printf("rng descriptor %d\n", rng); 52 * Now that the "SecureRandom" service has been removed, there is no
93 53 * service that is registered with the name service by default that we
94 dump_output(rng, RNG_OUTPUT_BYTES); 54 * can test here. "ManifestNameService" only gets registered after the
55 * "reverse service" is initialized, which doesn't normally happen in
56 * standalone sel_ldr. So we just check that querying returns a sensible
57 * error here.
58 */
59 ASSERT_EQ(NACL_NAME_SERVICE_NAME_NOT_FOUND, status);
95 60
96 return 0; 61 return 0;
97 } 62 }
OLDNEW
« no previous file with comments | « src/trusted/service_runtime/service_runtime.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698