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 | |
Mark Seaborn
2015/07/30 15:20:14
Nit: be consistent about whether there's 1 or 2 em
Sean Klein
2015/07/30 16:04:29
Done.
| |
74 | |
57 // Test mmap() and munmap(), since these often to go together. Tries to mmap | 75 // 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 | 76 // a 64 Kb region of memory and then tests to make sure that the pages have all |
59 // been 0-filled. | 77 // been 0-filled. |
60 int TestMmapMunmap() { | 78 int TestMmapMunmap() { |
61 START_TEST("TestMmapMunmap"); | 79 START_TEST("TestMmapMunmap"); |
62 void* mmap_ptr = mmap(NULL, | 80 void* mmap_ptr = mmap(NULL, |
63 k64Kbytes, | 81 k64Kbytes, |
64 PROT_READ, | 82 PROT_READ, |
65 MAP_PRIVATE | MAP_ANONYMOUS, | 83 MAP_PRIVATE | MAP_ANONYMOUS, |
66 kAnonymousFiledesc, | 84 kAnonymousFiledesc, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 END_TEST(); | 169 END_TEST(); |
152 } | 170 } |
153 } // namespace | 171 } // namespace |
154 | 172 |
155 // Run through the complete sequence of memory tests. Sets the exit code to | 173 // 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. | 174 // the number of failed tests. Exit code 0 means all passed. |
157 int main() { | 175 int main() { |
158 int fail_count = 0; | 176 int fail_count = 0; |
159 fail_count += TestZeroLengthRegion(); | 177 fail_count += TestZeroLengthRegion(); |
160 fail_count += TestBadFiledesc(); | 178 fail_count += TestBadFiledesc(); |
179 fail_count += TestMmapBadHint(); | |
161 fail_count += TestMmapMunmap(); | 180 fail_count += TestMmapMunmap(); |
162 fail_count += TestMunmapText(); | 181 fail_count += TestMunmapText(); |
163 fail_count += TestMmapNULL(); | 182 fail_count += TestMmapNULL(); |
164 fail_count += TestMmap32k(); | 183 fail_count += TestMmap32k(); |
165 fail_count += TestMmapNonPageAligned(); | 184 fail_count += TestMmapNonPageAligned(); |
166 return fail_count; | 185 return fail_count; |
167 } | 186 } |
OLD | NEW |