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