Commit f3b7568c authored by Mark Brown's avatar Mark Brown Committed by Andrew Morton

selftests/mm: log a consistent test name for check_compaction

Every test result report in the compaction test prints a distinct log
messae, and some of the reports print a name that varies at runtime.  This
causes problems for automation since a lot of automation software uses the
printed string as the name of the test, if the name varies from run to run
and from pass to fail then the automation software can't identify that a
test changed result or that the same tests are being run.

Refactor the logging to use a consistent name when printing the result of
the test, printing the existing messages as diagnostic information instead
so they are still available for people trying to interpret the results.

Link: https://lkml.kernel.org/r/20240209-kselftest-mm-cleanup-v1-2-a3c0386496b5@kernel.orgSigned-off-by: default avatarMark Brown <broonie@kernel.org>
Cc: Muhammad Usama Anjum <usama.anjum@collabora.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 9c1490d9
...@@ -95,21 +95,22 @@ int check_compaction(unsigned long mem_free, unsigned int hugepage_size) ...@@ -95,21 +95,22 @@ 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) {
ksft_test_result_fail("Failed to open /proc/sys/vm/nr_hugepages: %s\n", ksft_print_msg("Failed to open /proc/sys/vm/nr_hugepages: %s\n",
strerror(errno)); strerror(errno));
return -1; ret = -1;
goto out;
} }
if (read(fd, initial_nr_hugepages, sizeof(initial_nr_hugepages)) <= 0) { if (read(fd, initial_nr_hugepages, sizeof(initial_nr_hugepages)) <= 0) {
ksft_test_result_fail("Failed to read from /proc/sys/vm/nr_hugepages: %s\n", ksft_print_msg("Failed to read from /proc/sys/vm/nr_hugepages: %s\n",
strerror(errno)); strerror(errno));
goto close_fd; goto close_fd;
} }
/* 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)) {
ksft_test_result_fail("Failed to write 0 to /proc/sys/vm/nr_hugepages: %s\n", ksft_print_msg("Failed to write 0 to /proc/sys/vm/nr_hugepages: %s\n",
strerror(errno)); strerror(errno));
goto close_fd; goto close_fd;
} }
...@@ -118,16 +119,16 @@ int check_compaction(unsigned long mem_free, unsigned int hugepage_size) ...@@ -118,16 +119,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))) {
ksft_test_result_fail("Failed to write 100000 to /proc/sys/vm/nr_hugepages: %s\n", ksft_print_msg("Failed to write 100000 to /proc/sys/vm/nr_hugepages: %s\n",
strerror(errno)); 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) {
ksft_test_result_fail("Failed to re-read from /proc/sys/vm/nr_hugepages: %s\n", ksft_print_msg("Failed to re-read from /proc/sys/vm/nr_hugepages: %s\n",
strerror(errno)); strerror(errno));
goto close_fd; goto close_fd;
} }
...@@ -139,24 +140,26 @@ int check_compaction(unsigned long mem_free, unsigned int hugepage_size) ...@@ -139,24 +140,26 @@ int check_compaction(unsigned long mem_free, unsigned int hugepage_size)
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)) {
ksft_test_result_fail("Failed to write value to /proc/sys/vm/nr_hugepages: %s\n", ksft_print_msg("Failed to write value to /proc/sys/vm/nr_hugepages: %s\n",
strerror(errno)); strerror(errno));
goto close_fd; goto close_fd;
} }
ksft_print_msg("Number of huge pages allocated = %d\n",
atoi(nr_hugepages));
if (compaction_index > 3) { if (compaction_index > 3) {
ksft_print_msg("ERROR: Less that 1/%d of memory is available\n" ksft_print_msg("ERROR: Less that 1/%d of memory is available\n"
"as huge pages\n", compaction_index); "as huge pages\n", compaction_index);
ksft_test_result_fail("No of huge pages allocated = %d\n", (atoi(nr_hugepages)));
goto close_fd; goto close_fd;
} }
ksft_test_result_pass("Memory compaction succeeded. No of huge pages allocated = %d\n",
(atoi(nr_hugepages)));
ret = 0; ret = 0;
close_fd: close_fd:
close(fd); close(fd);
out:
ksft_test_result(ret == 0, "check_compaction\n");
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment