- add third_party src.
[platform/framework/web/crosswalk.git] / src / native_client / tests / unittests / shared / imc / nacl_create_memory_object_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 <stdio.h>
8
9 #include "native_client/src/shared/imc/nacl_imc_c.h"
10
11 #define MEMORY_SIZE (1 << 20)
12
13 /* Writes the last error message to the standard error. */
14 static void failWithErrno(const char* message) {
15   char buffer[256];
16
17   if (0 == NaClGetLastErrorString(buffer, sizeof(buffer))) {
18     fprintf(stderr, "%s: %s\n", message, buffer);
19   }
20   exit(EXIT_FAILURE);
21 }
22
23 int main(int argc, char* argv[]) {
24   NaClHandle handle;
25
26   UNREFERENCED_PARAMETER(argc);
27   UNREFERENCED_PARAMETER(argv);
28
29   /* Check not executable shared memory. */
30   handle = NaClCreateMemoryObject(MEMORY_SIZE, 0);
31   if (NACL_INVALID_HANDLE == handle) {
32     failWithErrno("NaClCreateMemoryObject(size, 0)");
33   }
34   if (0 != NaClClose(handle)) {
35     failWithErrno("NaClClose(0)");
36   }
37
38   /* Check executable shared memory. */
39   handle = NaClCreateMemoryObject(MEMORY_SIZE, 1);
40 #ifdef __native_client__
41   if (NACL_INVALID_HANDLE != handle) {
42     fprintf(stderr, "NaClCreateMemoryObject(size, 1) returned a valid shm. "
43             "It must return -1\n");
44     exit(EXIT_FAILURE);
45   }
46 #else
47   if (NACL_INVALID_HANDLE == handle) {
48     failWithErrno("NaClCreateMemoryObject(size, 1)");
49   }
50   if (0 != NaClClose(handle)) {
51     failWithErrno("NaClClose(1)");
52   }
53 #endif
54
55   return 0;
56 }