Skip to content

Commit 4838cf7

Browse files
musamaanjumakpm00
authored andcommitted
selftests/mm: map_fixed_noreplace: conform test to TAP format output
Patch series "conform tests to TAP format output", v2. This patch (of 12): Conform the layout, informational and status messages to TAP. No functional change is intended other than the layout of output messages. While at it, convert commenting style from // to /**/. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Muhammad Usama Anjum <[email protected]> Cc: Shuah Khan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent eb1521d commit 4838cf7

File tree

1 file changed

+31
-65
lines changed

1 file changed

+31
-65
lines changed

tools/testing/selftests/mm/map_fixed_noreplace.c

Lines changed: 31 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <stdio.h>
1313
#include <stdlib.h>
1414
#include <unistd.h>
15+
#include "../kselftest.h"
1516

1617
static void dump_maps(void)
1718
{
@@ -28,15 +29,12 @@ static unsigned long find_base_addr(unsigned long size)
2829

2930
flags = MAP_PRIVATE | MAP_ANONYMOUS;
3031
addr = mmap(NULL, size, PROT_NONE, flags, -1, 0);
31-
if (addr == MAP_FAILED) {
32-
printf("Error: couldn't map the space we need for the test\n");
33-
return 0;
34-
}
32+
if (addr == MAP_FAILED)
33+
ksft_exit_fail_msg("Error: couldn't map the space we need for the test\n");
34+
35+
if (munmap(addr, size) != 0)
36+
ksft_exit_fail_msg("Error: munmap failed\n");
3537

36-
if (munmap(addr, size) != 0) {
37-
printf("Error: couldn't map the space we need for the test\n");
38-
return 0;
39-
}
4038
return (unsigned long)addr;
4139
}
4240

@@ -46,51 +44,39 @@ int main(void)
4644
unsigned long flags, addr, size, page_size;
4745
char *p;
4846

47+
ksft_print_header();
48+
ksft_set_plan(9);
49+
4950
page_size = sysconf(_SC_PAGE_SIZE);
5051

51-
//let's find a base addr that is free before we start the tests
52+
/* let's find a base addr that is free before we start the tests */
5253
size = 5 * page_size;
5354
base_addr = find_base_addr(size);
54-
if (!base_addr) {
55-
printf("Error: couldn't map the space we need for the test\n");
56-
return 1;
57-
}
5855

5956
flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE;
6057

61-
// Check we can map all the areas we need below
62-
errno = 0;
58+
/* Check we can map all the areas we need below */
6359
addr = base_addr;
6460
size = 5 * page_size;
6561
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
66-
67-
printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
68-
6962
if (p == MAP_FAILED) {
7063
dump_maps();
71-
printf("Error: couldn't map the space we need for the test\n");
72-
return 1;
64+
ksft_exit_fail_msg("Error: couldn't map the space we need for the test\n");
7365
}
74-
75-
errno = 0;
7666
if (munmap((void *)addr, 5 * page_size) != 0) {
7767
dump_maps();
78-
printf("Error: munmap failed!?\n");
79-
return 1;
68+
ksft_exit_fail_msg("Error: munmap failed!?\n");
8069
}
81-
printf("unmap() successful\n");
70+
ksft_test_result_pass("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
8271

83-
errno = 0;
8472
addr = base_addr + page_size;
8573
size = 3 * page_size;
8674
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
87-
printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
88-
8975
if (p == MAP_FAILED) {
9076
dump_maps();
91-
printf("Error: first mmap() failed unexpectedly\n");
92-
return 1;
77+
ksft_exit_fail_msg("Error: first mmap() failed unexpectedly\n");
9378
}
79+
ksft_test_result_pass("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
9480

9581
/*
9682
* Exact same mapping again:
@@ -100,17 +86,14 @@ int main(void)
10086
* +3 | mapped | new
10187
* +4 | free | new
10288
*/
103-
errno = 0;
10489
addr = base_addr;
10590
size = 5 * page_size;
10691
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
107-
printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
108-
10992
if (p != MAP_FAILED) {
11093
dump_maps();
111-
printf("Error:1: mmap() succeeded when it shouldn't have\n");
112-
return 1;
94+
ksft_exit_fail_msg("Error:1: mmap() succeeded when it shouldn't have\n");
11395
}
96+
ksft_test_result_pass("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
11497

11598
/*
11699
* Second mapping contained within first:
@@ -121,17 +104,14 @@ int main(void)
121104
* +3 | mapped |
122105
* +4 | free |
123106
*/
124-
errno = 0;
125107
addr = base_addr + (2 * page_size);
126108
size = page_size;
127109
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
128-
printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
129-
130110
if (p != MAP_FAILED) {
131111
dump_maps();
132-
printf("Error:2: mmap() succeeded when it shouldn't have\n");
133-
return 1;
112+
ksft_exit_fail_msg("Error:2: mmap() succeeded when it shouldn't have\n");
134113
}
114+
ksft_test_result_pass("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
135115

136116
/*
137117
* Overlap end of existing mapping:
@@ -141,17 +121,14 @@ int main(void)
141121
* +3 | mapped | new
142122
* +4 | free | new
143123
*/
144-
errno = 0;
145124
addr = base_addr + (3 * page_size);
146125
size = 2 * page_size;
147126
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
148-
printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
149-
150127
if (p != MAP_FAILED) {
151128
dump_maps();
152-
printf("Error:3: mmap() succeeded when it shouldn't have\n");
153-
return 1;
129+
ksft_exit_fail_msg("Error:3: mmap() succeeded when it shouldn't have\n");
154130
}
131+
ksft_test_result_pass("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
155132

156133
/*
157134
* Overlap start of existing mapping:
@@ -161,17 +138,14 @@ int main(void)
161138
* +3 | mapped |
162139
* +4 | free |
163140
*/
164-
errno = 0;
165141
addr = base_addr;
166142
size = 2 * page_size;
167143
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
168-
printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
169-
170144
if (p != MAP_FAILED) {
171145
dump_maps();
172-
printf("Error:4: mmap() succeeded when it shouldn't have\n");
173-
return 1;
146+
ksft_exit_fail_msg("Error:4: mmap() succeeded when it shouldn't have\n");
174147
}
148+
ksft_test_result_pass("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
175149

176150
/*
177151
* Adjacent to start of existing mapping:
@@ -181,17 +155,14 @@ int main(void)
181155
* +3 | mapped |
182156
* +4 | free |
183157
*/
184-
errno = 0;
185158
addr = base_addr;
186159
size = page_size;
187160
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
188-
printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
189-
190161
if (p == MAP_FAILED) {
191162
dump_maps();
192-
printf("Error:5: mmap() failed when it shouldn't have\n");
193-
return 1;
163+
ksft_exit_fail_msg("Error:5: mmap() failed when it shouldn't have\n");
194164
}
165+
ksft_test_result_pass("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
195166

196167
/*
197168
* Adjacent to end of existing mapping:
@@ -201,27 +172,22 @@ int main(void)
201172
* +3 | mapped |
202173
* +4 | free | new
203174
*/
204-
errno = 0;
205175
addr = base_addr + (4 * page_size);
206176
size = page_size;
207177
p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0);
208-
printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
209-
210178
if (p == MAP_FAILED) {
211179
dump_maps();
212-
printf("Error:6: mmap() failed when it shouldn't have\n");
213-
return 1;
180+
ksft_exit_fail_msg("Error:6: mmap() failed when it shouldn't have\n");
214181
}
182+
ksft_test_result_pass("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p);
215183

216184
addr = base_addr;
217185
size = 5 * page_size;
218186
if (munmap((void *)addr, size) != 0) {
219187
dump_maps();
220-
printf("Error: munmap failed!?\n");
221-
return 1;
188+
ksft_exit_fail_msg("Error: munmap failed!?\n");
222189
}
223-
printf("unmap() successful\n");
190+
ksft_test_result_pass("Base Address unmap() successful\n");
224191

225-
printf("OK\n");
226-
return 0;
192+
ksft_finished();
227193
}

0 commit comments

Comments
 (0)