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