Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / native_client / tests / irt_ext / libc / mem_tests.c
1 /*
2  * Copyright (c) 2014 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 <sys/mman.h>
8
9 #include "native_client/src/include/nacl_macros.h"
10 #include "native_client/tests/irt_ext/error_report.h"
11 #include "native_client/tests/irt_ext/libc/libc_test.h"
12 #include "native_client/tests/irt_ext/mem_calls.h"
13
14 typedef int (*TYPE_mem_test)(struct mem_calls_environment *env);
15
16 static int do_mmap_test(struct mem_calls_environment *env) {
17   mmap(NULL, 0, 0, 0, 0, 0);
18   if (env->num_mmap_calls != 1) {
19     irt_ext_test_print("do_mmap_test: mmap() call was not intercepted.\n");
20     return 1;
21   }
22
23   return 0;
24 }
25
26 static int do_munmap_test(struct mem_calls_environment *env) {
27   munmap(NULL, 0);
28   if (env->num_munmap_calls != 1) {
29     irt_ext_test_print("do_munmap_test: munmap() call was not intercepted.\n");
30     return 1;
31   }
32
33   return 0;
34 }
35
36 static int do_mprotect_test(struct mem_calls_environment *env) {
37   mprotect(NULL, 0, 0);
38   if (env->num_mprotect_calls != 1) {
39     irt_ext_test_print("do_mprotect_test: mprotect() call was not"
40                        " intercepted.\n");
41     return 1;
42   }
43
44   return 0;
45 }
46
47 static const TYPE_mem_test g_mem_tests[] = {
48   do_mmap_test,
49   do_munmap_test,
50   do_mprotect_test,
51 };
52
53 static void setup(struct mem_calls_environment *env) {
54   init_mem_calls_environment(env);
55   activate_mem_calls_env(env);
56 }
57
58 static void teardown(void) {
59   deactivate_mem_calls_env();
60 }
61
62 DEFINE_TEST(Mem, g_mem_tests, struct mem_calls_environment, setup, teardown)