2 * Copyright 2008, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #define PRINT_HEADER 0
41 #define TEXT_LINE_SIZE 1024
45 * function failed(testname, msg)
46 * print failure message and exit with a return code of -1
49 bool failed(const char *testname
, const char *msg
) {
50 printf("TEST FAILED: %s: %s\n", testname
, msg
);
56 * function passed(testname, msg)
57 * print success message
60 bool passed(const char *testname
, const char *msg
) {
61 printf("TEST PASSED: %s: %s\n", testname
, msg
);
70 * Simple tests follow below. Each test may call one or more
71 * of the functions above. They all have a boolean return value
72 * to indicate success (all tests passed) or failure (one or more
73 * tests failed) Order matters - the parent should call
74 * test1() before test2(), and so on.
79 int size
= 64 * 1024; /* we need 64K */
87 res
= mmap(res
, size
, PROT_READ
, MAP_PRIVATE
| MAP_ANONYMOUS
, 0, 0);
88 if (0 >= res
) /* define MAP_FAILED */
90 printf("mmap done\n");
91 zeroes
= malloc(size
);
92 memset(zeroes
, 0, size
);
93 if (memcmp(res
, zeroes
, size
)) {
94 printf("memcmp failed\n");
98 rv
= munmap(res
, 1024);
100 printf("munmap failed\n");
103 printf("munmap good\n");
110 * Verify that munmap of executable text pages will fail.
119 rv
= munmap((void *) (1<<16), (size_t) (1<<16)); /* text starts at 64K */
122 * if the munmap succeeds, we probably won't be able to continue to
125 printf("munmap returned %d\n", rv
);
128 printf("munmap good (failed as expected)\n");
137 * Verify that mmap into the NULL pointer guard page will fail.
145 res
= mmap((void *) 0, (size_t) (1 << 16),
146 PROT_READ
, MAP_PRIVATE
| MAP_ANONYMOUS
| MAP_FIXED
, 0, 0);
147 printf("res = %p\n", res
);
148 if (MAP_FAILED
== res
) {
149 printf("mmap okay\n");
152 printf("mmap should not have succeeded\n");
159 * function testSuite()
161 * Run through a complete sequence of file tests.
163 * returns true if all tests succeed. false if one or more fail.
169 // The order of executing these tests matters!
180 * run all tests and call system exit with appropriate value
181 * 0 - success, all tests passed.
182 * -1 - one or more tests failed.
185 int main(const int argc
, const char *argv
[])
189 // run the full test suite
190 passed
= testSuite();
193 printf("All tests PASSED\n");
196 printf("One or more tests FAILED\n");