selftests/mm: map_hugetlb: conform test 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/20240202113119.2047740-3-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>
This commit is contained in:
Muhammad Usama Anjum 2024-02-02 16:31:09 +05:00 committed by Andrew Morton
parent 4838cf70e5
commit d1e7bf2c70

View File

@ -16,6 +16,7 @@
#include <sys/mman.h>
#include <fcntl.h>
#include "vm_util.h"
#include "../kselftest.h"
#define LENGTH (256UL*1024*1024)
#define PROTECTION (PROT_READ | PROT_WRITE)
@ -31,7 +32,7 @@
static void check_bytes(char *addr)
{
printf("First hex is %x\n", *((unsigned int *)addr));
ksft_print_msg("First hex is %x\n", *((unsigned int *)addr));
}
static void write_bytes(char *addr, size_t length)
@ -42,23 +43,21 @@ static void write_bytes(char *addr, size_t length)
*(addr + i) = (char)i;
}
static int read_bytes(char *addr, size_t length)
static void read_bytes(char *addr, size_t length)
{
unsigned long i;
check_bytes(addr);
for (i = 0; i < length; i++)
if (*(addr + i) != (char)i) {
printf("Mismatch at %lu\n", i);
return 1;
}
return 0;
if (*(addr + i) != (char)i)
ksft_exit_fail_msg("Mismatch at %lu\n", i);
ksft_test_result_pass("Read correct data\n");
}
int main(int argc, char **argv)
{
void *addr;
int ret;
size_t hugepage_size;
size_t length = LENGTH;
int flags = FLAGS;
@ -69,6 +68,9 @@ int main(int argc, char **argv)
if (hugepage_size > length)
length = hugepage_size;
ksft_print_header();
ksft_set_plan(1);
if (argc > 1)
length = atol(argv[1]) << 20;
if (argc > 2) {
@ -78,27 +80,23 @@ int main(int argc, char **argv)
}
if (shift)
printf("%u kB hugepages\n", 1 << (shift - 10));
ksft_print_msg("%u kB hugepages\n", 1 << (shift - 10));
else
printf("Default size hugepages\n");
printf("Mapping %lu Mbytes\n", (unsigned long)length >> 20);
ksft_print_msg("Default size hugepages\n");
ksft_print_msg("Mapping %lu Mbytes\n", (unsigned long)length >> 20);
addr = mmap(ADDR, length, PROTECTION, flags, -1, 0);
if (addr == MAP_FAILED) {
perror("mmap");
exit(1);
}
if (addr == MAP_FAILED)
ksft_exit_fail_msg("mmap: %s\n", strerror(errno));
printf("Returned address is %p\n", addr);
ksft_print_msg("Returned address is %p\n", addr);
check_bytes(addr);
write_bytes(addr, length);
ret = read_bytes(addr, length);
read_bytes(addr, length);
/* munmap() length of MAP_HUGETLB memory must be hugepage aligned */
if (munmap(addr, length)) {
perror("munmap");
exit(1);
}
if (munmap(addr, length))
ksft_exit_fail_msg("munmap: %s\n", strerror(errno));
return ret;
ksft_finished();
}