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

Side by Side Diff: tests/irt_ext/libc/mem_tests.c

Issue 511253005: Added irt extension support for supplying the nacl_irt_memory interface. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Moved size declaration down 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 | « tests/irt_ext/libc/libc_test.c ('k') | tests/irt_ext/mem_calls.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 int run_mem_tests(void) {
54 struct mem_calls_environment mem_call_env;
55 int num_failures = 0;
56 irt_ext_test_print("Running %d mem tests...\n",
57 NACL_ARRAY_SIZE(g_mem_tests));
58
59 for (int i = 0; i < NACL_ARRAY_SIZE(g_mem_tests); i++) {
60 init_mem_calls_environment(&mem_call_env);
61 activate_mem_calls_env(&mem_call_env);
62
63 if (0 != g_mem_tests[i](&mem_call_env)) {
64 num_failures++;
65 }
66
67 deactivate_mem_calls_env();
68 }
69
70 if (num_failures > 0) {
71 irt_ext_test_print("Mem Tests Failed [%d/%d]\n", num_failures,
72 NACL_ARRAY_SIZE(g_mem_tests));
73 } else {
74 irt_ext_test_print("Mem Tests Passed [%d/%d]\n",
75 NACL_ARRAY_SIZE(g_mem_tests),
76 NACL_ARRAY_SIZE(g_mem_tests));
77 }
78
79 return num_failures;
80 }
OLDNEW
« no previous file with comments | « tests/irt_ext/libc/libc_test.c ('k') | tests/irt_ext/mem_calls.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698