Commit cb6e7cae authored by Muhammad Usama Anjum's avatar Muhammad Usama Anjum Committed by Andrew Morton

selftests/mm: gup_test: 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/20240102053807.2114200-1-usama.anjum@collabora.comSigned-off-by: default avatarMuhammad Usama Anjum <usama.anjum@collabora.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent e2cfedf4
...@@ -50,39 +50,41 @@ static char *cmd_to_str(unsigned long cmd) ...@@ -50,39 +50,41 @@ static char *cmd_to_str(unsigned long cmd)
void *gup_thread(void *data) void *gup_thread(void *data)
{ {
struct gup_test gup = *(struct gup_test *)data; struct gup_test gup = *(struct gup_test *)data;
int i; int i, status;
/* Only report timing information on the *_BENCHMARK commands: */ /* Only report timing information on the *_BENCHMARK commands: */
if ((cmd == PIN_FAST_BENCHMARK) || (cmd == GUP_FAST_BENCHMARK) || if ((cmd == PIN_FAST_BENCHMARK) || (cmd == GUP_FAST_BENCHMARK) ||
(cmd == PIN_LONGTERM_BENCHMARK)) { (cmd == PIN_LONGTERM_BENCHMARK)) {
for (i = 0; i < repeats; i++) { for (i = 0; i < repeats; i++) {
gup.size = size; gup.size = size;
if (ioctl(gup_fd, cmd, &gup)) status = ioctl(gup_fd, cmd, &gup);
perror("ioctl"), exit(1); if (status)
break;
pthread_mutex_lock(&print_mutex); pthread_mutex_lock(&print_mutex);
printf("%s: Time: get:%lld put:%lld us", ksft_print_msg("%s: Time: get:%lld put:%lld us",
cmd_to_str(cmd), gup.get_delta_usec, cmd_to_str(cmd), gup.get_delta_usec,
gup.put_delta_usec); gup.put_delta_usec);
if (gup.size != size) if (gup.size != size)
printf(", truncated (size: %lld)", gup.size); ksft_print_msg(", truncated (size: %lld)", gup.size);
printf("\n"); ksft_print_msg("\n");
pthread_mutex_unlock(&print_mutex); pthread_mutex_unlock(&print_mutex);
} }
} else { } else {
gup.size = size; gup.size = size;
if (ioctl(gup_fd, cmd, &gup)) { status = ioctl(gup_fd, cmd, &gup);
perror("ioctl"); if (status)
exit(1); goto return_;
}
pthread_mutex_lock(&print_mutex); pthread_mutex_lock(&print_mutex);
printf("%s: done\n", cmd_to_str(cmd)); ksft_print_msg("%s: done\n", cmd_to_str(cmd));
if (gup.size != size) if (gup.size != size)
printf("Truncated (size: %lld)\n", gup.size); ksft_print_msg("Truncated (size: %lld)\n", gup.size);
pthread_mutex_unlock(&print_mutex); pthread_mutex_unlock(&print_mutex);
} }
return_:
ksft_test_result(!status, "ioctl status %d\n", status);
return NULL; return NULL;
} }
...@@ -170,7 +172,7 @@ int main(int argc, char **argv) ...@@ -170,7 +172,7 @@ int main(int argc, char **argv)
touch = 1; touch = 1;
break; break;
default: default:
return -1; ksft_exit_fail_msg("Wrong argument\n");
} }
} }
...@@ -198,11 +200,12 @@ int main(int argc, char **argv) ...@@ -198,11 +200,12 @@ int main(int argc, char **argv)
} }
} }
ksft_print_header();
ksft_set_plan(nthreads);
filed = open(file, O_RDWR|O_CREAT); filed = open(file, O_RDWR|O_CREAT);
if (filed < 0) { if (filed < 0)
perror("open"); ksft_exit_fail_msg("Unable to open %s: %s\n", file, strerror(errno));
exit(filed);
}
gup.nr_pages_per_call = nr_pages; gup.nr_pages_per_call = nr_pages;
if (write) if (write)
...@@ -213,27 +216,24 @@ int main(int argc, char **argv) ...@@ -213,27 +216,24 @@ int main(int argc, char **argv)
switch (errno) { switch (errno) {
case EACCES: case EACCES:
if (getuid()) if (getuid())
printf("Please run this test as root\n"); ksft_print_msg("Please run this test as root\n");
break; break;
case ENOENT: case ENOENT:
if (opendir("/sys/kernel/debug") == NULL) { if (opendir("/sys/kernel/debug") == NULL)
printf("mount debugfs at /sys/kernel/debug\n"); ksft_print_msg("mount debugfs at /sys/kernel/debug\n");
break; ksft_print_msg("check if CONFIG_GUP_TEST is enabled in kernel config\n");
}
printf("check if CONFIG_GUP_TEST is enabled in kernel config\n");
break; break;
default: default:
perror("failed to open " GUP_TEST_FILE); ksft_print_msg("failed to open %s: %s\n", GUP_TEST_FILE, strerror(errno));
break; break;
} }
exit(KSFT_SKIP); ksft_test_result_skip("Please run this test as root\n");
return ksft_exit_pass();
} }
p = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, filed, 0); p = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, filed, 0);
if (p == MAP_FAILED) { if (p == MAP_FAILED)
perror("mmap"); ksft_exit_fail_msg("mmap: %s\n", strerror(errno));
exit(1);
}
gup.addr = (unsigned long)p; gup.addr = (unsigned long)p;
if (thp == 1) if (thp == 1)
...@@ -264,7 +264,8 @@ int main(int argc, char **argv) ...@@ -264,7 +264,8 @@ int main(int argc, char **argv)
ret = pthread_join(tid[i], NULL); ret = pthread_join(tid[i], NULL);
assert(ret == 0); assert(ret == 0);
} }
free(tid); free(tid);
return 0; return ksft_exit_pass();
} }
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