Skip to content

Commit 84ba3f2

Browse files
Muhammad Usama Anjumakpm00
authored andcommitted
selftests: mm: hugepage-mmap: conform to TAP format output
Conform the layout, informational and status messages to TAP. No functional change is intended other than the layout of output messages. Link: https://lkml.kernel.org/r/20240102053223.2099572-1-usama.anjum@collabora.com Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com> Cc: Shuah Khan <shuah@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent cb6e7ca commit 84ba3f2

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

tools/testing/selftests/mm/hugepage-mmap.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <unistd.h>
2323
#include <sys/mman.h>
2424
#include <fcntl.h>
25+
#include "../kselftest.h"
2526

2627
#define LENGTH (256UL*1024*1024)
2728
#define PROTECTION (PROT_READ | PROT_WRITE)
@@ -37,7 +38,7 @@
3738

3839
static void check_bytes(char *addr)
3940
{
40-
printf("First hex is %x\n", *((unsigned int *)addr));
41+
ksft_print_msg("First hex is %x\n", *((unsigned int *)addr));
4142
}
4243

4344
static void write_bytes(char *addr)
@@ -55,7 +56,7 @@ static int read_bytes(char *addr)
5556
check_bytes(addr);
5657
for (i = 0; i < LENGTH; i++)
5758
if (*(addr + i) != (char)i) {
58-
printf("Mismatch at %lu\n", i);
59+
ksft_print_msg("Error: Mismatch at %lu\n", i);
5960
return 1;
6061
}
6162
return 0;
@@ -66,26 +67,28 @@ int main(void)
6667
void *addr;
6768
int fd, ret;
6869

70+
ksft_print_header();
71+
ksft_set_plan(1);
72+
6973
fd = memfd_create("hugepage-mmap", MFD_HUGETLB);
70-
if (fd < 0) {
71-
perror("memfd_create() failed");
72-
exit(1);
73-
}
74+
if (fd < 0)
75+
ksft_exit_fail_msg("memfd_create() failed: %s\n", strerror(errno));
7476

7577
addr = mmap(ADDR, LENGTH, PROTECTION, FLAGS, fd, 0);
7678
if (addr == MAP_FAILED) {
77-
perror("mmap");
7879
close(fd);
79-
exit(1);
80+
ksft_exit_fail_msg("mmap(): %s\n", strerror(errno));
8081
}
8182

82-
printf("Returned address is %p\n", addr);
83+
ksft_print_msg("Returned address is %p\n", addr);
8384
check_bytes(addr);
8485
write_bytes(addr);
8586
ret = read_bytes(addr);
8687

8788
munmap(addr, LENGTH);
8889
close(fd);
8990

90-
return ret;
91+
ksft_test_result(!ret, "Read same data\n");
92+
93+
ksft_exit(!ret);
9194
}

0 commit comments

Comments
 (0)