Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / native_client / tests / nameservice / nameservice_test.c
1 /*
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
4  * found in the LICENSE file.
5  */
6
7 #include <assert.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <inttypes.h>
11 #include <sys/fcntl.h>
12 #include <string.h>
13 #include <unistd.h>
14
15 #include "native_client/src/include/nacl_assert.h"
16 #include "native_client/src/public/imc_syscalls.h"
17 #include "native_client/src/public/name_service.h"
18 #include "native_client/src/shared/srpc/nacl_srpc.h"
19
20 int main(void) {
21   int ns;
22   NaClSrpcChannel channel;
23   int connected_socket;
24   int status;
25   int rng;
26
27   if (!NaClSrpcModuleInit()) {
28     fprintf(stderr, "srpc module init failed\n");
29     return 1;
30   }
31   printf("Hello world\n");
32   ns = -1;
33   nacl_nameservice(&ns);
34   printf("ns = %d\n", ns);
35   assert(-1 != ns);
36
37   connected_socket = imc_connect(ns);
38   assert(-1 != connected_socket);
39   if (!NaClSrpcClientCtor(&channel, connected_socket)) {
40     fprintf(stderr, "Srpc client channel ctor failed\n");
41     return 1;
42   }
43   printf("NaClSrpcClientCtor succeeded\n");
44   if (NACL_SRPC_RESULT_OK !=
45       NaClSrpcInvokeBySignature(&channel, NACL_NAME_SERVICE_LOOKUP,
46                                 "SecureRandom", O_RDONLY, &status, &rng)) {
47     fprintf(stderr, "nameservice lookup failed, status %d\n", status);
48     return 1;
49   }
50   printf("rpc status %d\n", status);
51   /*
52    * Now that the "SecureRandom" service has been removed, there is no
53    * service that is registered with the name service by default that we
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);
60
61   return 0;
62 }