selftests/mm: conform test to TAP format output
[ Upstream commit 9a21701edc41465de56f97914741bfb7bfc2517d ] 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/20240101083614.1076768-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> Stable-dep-of: d4202e66a4b1 ("selftests/mm: compaction_test: fix bogus test success on Aarch64") Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
9d3886a160
commit
7c1cc0a5d4
@@ -33,7 +33,7 @@ int read_memory_info(unsigned long *memfree, unsigned long *hugepagesize)
|
|||||||
FILE *cmdfile = popen(cmd, "r");
|
FILE *cmdfile = popen(cmd, "r");
|
||||||
|
|
||||||
if (!(fgets(buffer, sizeof(buffer), cmdfile))) {
|
if (!(fgets(buffer, sizeof(buffer), cmdfile))) {
|
||||||
perror("Failed to read meminfo\n");
|
ksft_print_msg("Failed to read meminfo: %s\n", strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ int read_memory_info(unsigned long *memfree, unsigned long *hugepagesize)
|
|||||||
cmdfile = popen(cmd, "r");
|
cmdfile = popen(cmd, "r");
|
||||||
|
|
||||||
if (!(fgets(buffer, sizeof(buffer), cmdfile))) {
|
if (!(fgets(buffer, sizeof(buffer), cmdfile))) {
|
||||||
perror("Failed to read meminfo\n");
|
ksft_print_msg("Failed to read meminfo: %s\n", strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,14 +62,14 @@ int prereq(void)
|
|||||||
fd = open("/proc/sys/vm/compact_unevictable_allowed",
|
fd = open("/proc/sys/vm/compact_unevictable_allowed",
|
||||||
O_RDONLY | O_NONBLOCK);
|
O_RDONLY | O_NONBLOCK);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
perror("Failed to open\n"
|
ksft_print_msg("Failed to open /proc/sys/vm/compact_unevictable_allowed: %s\n",
|
||||||
"/proc/sys/vm/compact_unevictable_allowed\n");
|
strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read(fd, &allowed, sizeof(char)) != sizeof(char)) {
|
if (read(fd, &allowed, sizeof(char)) != sizeof(char)) {
|
||||||
perror("Failed to read from\n"
|
ksft_print_msg("Failed to read from /proc/sys/vm/compact_unevictable_allowed: %s\n",
|
||||||
"/proc/sys/vm/compact_unevictable_allowed\n");
|
strerror(errno));
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -78,12 +78,13 @@ int prereq(void)
|
|||||||
if (allowed == '1')
|
if (allowed == '1')
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
ksft_print_msg("Compaction isn't allowed\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int check_compaction(unsigned long mem_free, unsigned int hugepage_size)
|
int check_compaction(unsigned long mem_free, unsigned int hugepage_size)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd, ret = -1;
|
||||||
int compaction_index = 0;
|
int compaction_index = 0;
|
||||||
char initial_nr_hugepages[10] = {0};
|
char initial_nr_hugepages[10] = {0};
|
||||||
char nr_hugepages[10] = {0};
|
char nr_hugepages[10] = {0};
|
||||||
@@ -94,12 +95,14 @@ int check_compaction(unsigned long mem_free, unsigned int hugepage_size)
|
|||||||
|
|
||||||
fd = open("/proc/sys/vm/nr_hugepages", O_RDWR | O_NONBLOCK);
|
fd = open("/proc/sys/vm/nr_hugepages", O_RDWR | O_NONBLOCK);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
perror("Failed to open /proc/sys/vm/nr_hugepages");
|
ksft_test_result_fail("Failed to open /proc/sys/vm/nr_hugepages: %s\n",
|
||||||
|
strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read(fd, initial_nr_hugepages, sizeof(initial_nr_hugepages)) <= 0) {
|
if (read(fd, initial_nr_hugepages, sizeof(initial_nr_hugepages)) <= 0) {
|
||||||
perror("Failed to read from /proc/sys/vm/nr_hugepages");
|
ksft_test_result_fail("Failed to read from /proc/sys/vm/nr_hugepages: %s\n",
|
||||||
|
strerror(errno));
|
||||||
goto close_fd;
|
goto close_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +110,8 @@ int check_compaction(unsigned long mem_free, unsigned int hugepage_size)
|
|||||||
|
|
||||||
/* Start with the initial condition of 0 huge pages*/
|
/* Start with the initial condition of 0 huge pages*/
|
||||||
if (write(fd, "0", sizeof(char)) != sizeof(char)) {
|
if (write(fd, "0", sizeof(char)) != sizeof(char)) {
|
||||||
perror("Failed to write 0 to /proc/sys/vm/nr_hugepages\n");
|
ksft_test_result_fail("Failed to write 0 to /proc/sys/vm/nr_hugepages: %s\n",
|
||||||
|
strerror(errno));
|
||||||
goto close_fd;
|
goto close_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,14 +120,16 @@ int check_compaction(unsigned long mem_free, unsigned int hugepage_size)
|
|||||||
/* Request a large number of huge pages. The Kernel will allocate
|
/* Request a large number of huge pages. The Kernel will allocate
|
||||||
as much as it can */
|
as much as it can */
|
||||||
if (write(fd, "100000", (6*sizeof(char))) != (6*sizeof(char))) {
|
if (write(fd, "100000", (6*sizeof(char))) != (6*sizeof(char))) {
|
||||||
perror("Failed to write 100000 to /proc/sys/vm/nr_hugepages\n");
|
ksft_test_result_fail("Failed to write 100000 to /proc/sys/vm/nr_hugepages: %s\n",
|
||||||
|
strerror(errno));
|
||||||
goto close_fd;
|
goto close_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
lseek(fd, 0, SEEK_SET);
|
lseek(fd, 0, SEEK_SET);
|
||||||
|
|
||||||
if (read(fd, nr_hugepages, sizeof(nr_hugepages)) <= 0) {
|
if (read(fd, nr_hugepages, sizeof(nr_hugepages)) <= 0) {
|
||||||
perror("Failed to re-read from /proc/sys/vm/nr_hugepages\n");
|
ksft_test_result_fail("Failed to re-read from /proc/sys/vm/nr_hugepages: %s\n",
|
||||||
|
strerror(errno));
|
||||||
goto close_fd;
|
goto close_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,67 +137,58 @@ int check_compaction(unsigned long mem_free, unsigned int hugepage_size)
|
|||||||
huge pages */
|
huge pages */
|
||||||
compaction_index = mem_free/(atoi(nr_hugepages) * hugepage_size);
|
compaction_index = mem_free/(atoi(nr_hugepages) * hugepage_size);
|
||||||
|
|
||||||
if (compaction_index > 3) {
|
|
||||||
printf("No of huge pages allocated = %d\n",
|
|
||||||
(atoi(nr_hugepages)));
|
|
||||||
fprintf(stderr, "ERROR: Less that 1/%d of memory is available\n"
|
|
||||||
"as huge pages\n", compaction_index);
|
|
||||||
goto close_fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("No of huge pages allocated = %d\n",
|
|
||||||
(atoi(nr_hugepages)));
|
|
||||||
|
|
||||||
lseek(fd, 0, SEEK_SET);
|
lseek(fd, 0, SEEK_SET);
|
||||||
|
|
||||||
if (write(fd, initial_nr_hugepages, strlen(initial_nr_hugepages))
|
if (write(fd, initial_nr_hugepages, strlen(initial_nr_hugepages))
|
||||||
!= strlen(initial_nr_hugepages)) {
|
!= strlen(initial_nr_hugepages)) {
|
||||||
perror("Failed to write value to /proc/sys/vm/nr_hugepages\n");
|
ksft_test_result_fail("Failed to write value to /proc/sys/vm/nr_hugepages: %s\n",
|
||||||
|
strerror(errno));
|
||||||
goto close_fd;
|
goto close_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
if (compaction_index > 3) {
|
||||||
return 0;
|
ksft_print_msg("ERROR: Less that 1/%d of memory is available\n"
|
||||||
|
"as huge pages\n", compaction_index);
|
||||||
|
ksft_test_result_fail("No of huge pages allocated = %d\n", (atoi(nr_hugepages)));
|
||||||
|
goto close_fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
ksft_test_result_pass("Memory compaction succeeded. No of huge pages allocated = %d\n",
|
||||||
|
(atoi(nr_hugepages)));
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
close_fd:
|
close_fd:
|
||||||
close(fd);
|
close(fd);
|
||||||
printf("Not OK. Compaction test failed.");
|
return ret;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct rlimit lim;
|
struct rlimit lim;
|
||||||
struct map_list *list, *entry;
|
struct map_list *list = NULL, *entry;
|
||||||
size_t page_size, i;
|
size_t page_size, i;
|
||||||
void *map = NULL;
|
void *map = NULL;
|
||||||
unsigned long mem_free = 0;
|
unsigned long mem_free = 0;
|
||||||
unsigned long hugepage_size = 0;
|
unsigned long hugepage_size = 0;
|
||||||
long mem_fragmentable_MB = 0;
|
long mem_fragmentable_MB = 0;
|
||||||
|
|
||||||
if (prereq() != 0) {
|
ksft_print_header();
|
||||||
printf("Either the sysctl compact_unevictable_allowed is not\n"
|
|
||||||
"set to 1 or couldn't read the proc file.\n"
|
if (prereq() != 0)
|
||||||
"Skipping the test\n");
|
return ksft_exit_pass();
|
||||||
return KSFT_SKIP;
|
|
||||||
}
|
ksft_set_plan(1);
|
||||||
|
|
||||||
lim.rlim_cur = RLIM_INFINITY;
|
lim.rlim_cur = RLIM_INFINITY;
|
||||||
lim.rlim_max = RLIM_INFINITY;
|
lim.rlim_max = RLIM_INFINITY;
|
||||||
if (setrlimit(RLIMIT_MEMLOCK, &lim)) {
|
if (setrlimit(RLIMIT_MEMLOCK, &lim))
|
||||||
perror("Failed to set rlimit:\n");
|
ksft_exit_fail_msg("Failed to set rlimit: %s\n", strerror(errno));
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
page_size = getpagesize();
|
page_size = getpagesize();
|
||||||
|
|
||||||
list = NULL;
|
if (read_memory_info(&mem_free, &hugepage_size) != 0)
|
||||||
|
ksft_exit_fail_msg("Failed to get meminfo\n");
|
||||||
if (read_memory_info(&mem_free, &hugepage_size) != 0) {
|
|
||||||
printf("ERROR: Cannot read meminfo\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
mem_fragmentable_MB = mem_free * 0.8 / 1024;
|
mem_fragmentable_MB = mem_free * 0.8 / 1024;
|
||||||
|
|
||||||
@@ -227,7 +224,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (check_compaction(mem_free, hugepage_size) == 0)
|
if (check_compaction(mem_free, hugepage_size) == 0)
|
||||||
return 0;
|
return ksft_exit_pass();
|
||||||
|
|
||||||
return -1;
|
return ksft_exit_fail();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user