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

Side by Side Diff: tests/syscalls/mem_test.cc

Issue 1264783002: Remove failure for bad mmap address hints. (Closed) Base URL: https://chromium.googlesource.com/native_client/src/native_client.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « src/trusted/service_runtime/sys_memory.c ('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 // Copyright 2010 The Native Client Authors. All rights reserved. 1 /*
2 // Use of this source code is governed by a BSD-style license that can 2 * Copyright (c) 2010 The Native Client Authors. All rights reserved.
3 // be found in the LICENSE file. 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
4 6
5 #include <errno.h> 7 #include <errno.h>
6 #include <sys/mman.h> 8 #include <sys/mman.h>
7 9
8 #include <cstdlib> 10 #include <cstdlib>
9 #include <cstring> 11 #include <cstring>
10 12
11 #include "native_client/tests/syscalls/test.h" 13 #include "native_client/tests/syscalls/test.h"
12 14
13 namespace { 15 namespace {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 k64Kbytes, 49 k64Kbytes,
48 PROT_READ, 50 PROT_READ,
49 MAP_PRIVATE, 51 MAP_PRIVATE,
50 kBadFiledesc, 52 kBadFiledesc,
51 0); 53 0);
52 EXPECT(MAP_FAILED == mmap_ptr); 54 EXPECT(MAP_FAILED == mmap_ptr);
53 EXPECT(EBADF == errno); 55 EXPECT(EBADF == errno);
54 END_TEST(); 56 END_TEST();
55 } 57 }
56 58
59 // Verify that mmap does not fail if a bad hint address is passed, but
60 // |MMAP_FIXED| is not specified.
61 int TestMmapBadHint() {
62 START_TEST("TestMmapBadHint");
63 void* bad_hint = (void *) 0x123;
64 void* mmap_ptr = mmap(bad_hint,
65 k64Kbytes,
66 PROT_READ,
67 MAP_PRIVATE | MAP_ANONYMOUS,
68 kAnonymousFiledesc,
69 0);
70 EXPECT(MAP_FAILED != mmap_ptr);
71 EXPECT(mmap_ptr != bad_hint);
72 EXPECT(munmap(mmap_ptr, k64Kbytes) == 0);
73 END_TEST();
74 }
75
76 // Verify that mmap does fail if a bad hint address is passed and
77 // |MMAP_FIXED| is specified.
78 int TestMmapBadHintFixed() {
79 START_TEST("TestMmapBadHintFixed");
80 void* bad_hint = (void *) 0x123;
81 void* mmap_ptr = mmap(bad_hint,
82 k64Kbytes,
83 PROT_READ,
84 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
85 kAnonymousFiledesc,
86 0);
87 EXPECT(MAP_FAILED == mmap_ptr);
88 END_TEST();
89 }
90
57 // Test mmap() and munmap(), since these often to go together. Tries to mmap 91 // Test mmap() and munmap(), since these often to go together. Tries to mmap
58 // a 64 Kb region of memory and then tests to make sure that the pages have all 92 // a 64 Kb region of memory and then tests to make sure that the pages have all
59 // been 0-filled. 93 // been 0-filled.
60 int TestMmapMunmap() { 94 int TestMmapMunmap() {
61 START_TEST("TestMmapMunmap"); 95 START_TEST("TestMmapMunmap");
62 void* mmap_ptr = mmap(NULL, 96 void* mmap_ptr = mmap(NULL,
63 k64Kbytes, 97 k64Kbytes,
64 PROT_READ, 98 PROT_READ,
65 MAP_PRIVATE | MAP_ANONYMOUS, 99 MAP_PRIVATE | MAP_ANONYMOUS,
66 kAnonymousFiledesc, 100 kAnonymousFiledesc,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 END_TEST(); 185 END_TEST();
152 } 186 }
153 } // namespace 187 } // namespace
154 188
155 // Run through the complete sequence of memory tests. Sets the exit code to 189 // Run through the complete sequence of memory tests. Sets the exit code to
156 // the number of failed tests. Exit code 0 means all passed. 190 // the number of failed tests. Exit code 0 means all passed.
157 int main() { 191 int main() {
158 int fail_count = 0; 192 int fail_count = 0;
159 fail_count += TestZeroLengthRegion(); 193 fail_count += TestZeroLengthRegion();
160 fail_count += TestBadFiledesc(); 194 fail_count += TestBadFiledesc();
195 fail_count += TestMmapBadHint();
196 fail_count += TestMmapBadHintFixed();
161 fail_count += TestMmapMunmap(); 197 fail_count += TestMmapMunmap();
162 fail_count += TestMunmapText(); 198 fail_count += TestMunmapText();
163 fail_count += TestMmapNULL(); 199 fail_count += TestMmapNULL();
164 fail_count += TestMmap32k(); 200 fail_count += TestMmap32k();
165 fail_count += TestMmapNonPageAligned(); 201 fail_count += TestMmapNonPageAligned();
166 return fail_count; 202 return fail_count;
167 } 203 }
OLDNEW
« no previous file with comments | « src/trusted/service_runtime/sys_memory.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698