Skip to content

Commit d6283d0

Browse files
broonieshuahkh
authored andcommitted
kselftest/tty: Report a consistent test name for the one test we run
Currently the tty_tstamp_update test reports a different exit message for every path it can exit via. This can be confusing for automated systems as the string that gets logged is interpreted as a test name so if the test status changes they can't tell that it's the same test case that was run, they can see that the overall status of the test program is a failure but it's not clear that it was running the same test. Change all the messages that are logged to be diagnostic prints and log the name of the program as the test name. Signed-off-by: Mark Brown <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 6d75d75 commit d6283d0

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

tools/testing/selftests/tty/tty_tstamp_update.c

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,42 +47,60 @@ int main(int argc, char **argv)
4747
int r;
4848
char tty[PATH_MAX] = {};
4949
struct stat st1, st2;
50+
int result = KSFT_FAIL;
5051

5152
ksft_print_header();
5253
ksft_set_plan(1);
5354

5455
r = readlink("/proc/self/fd/0", tty, PATH_MAX);
55-
if (r < 0)
56-
ksft_exit_fail_msg("readlink on /proc/self/fd/0 failed: %m\n");
56+
if (r < 0) {
57+
ksft_print_msg("readlink on /proc/self/fd/0 failed: %m\n");
58+
goto out;
59+
}
60+
61+
if (!tty_valid(tty)) {
62+
ksft_print_msg("invalid tty path '%s'\n", tty);
63+
result = KSFT_SKIP;
64+
goto out;
5765

58-
if (!tty_valid(tty))
59-
ksft_exit_skip("invalid tty path '%s'\n", tty);
66+
}
6067

6168
r = stat(tty, &st1);
62-
if (r < 0)
63-
ksft_exit_fail_msg("stat failed on tty path '%s': %m\n", tty);
69+
if (r < 0) {
70+
ksft_print_msg("stat failed on tty path '%s': %m\n", tty);
71+
goto out;
72+
}
6473

6574
/* We need to wait at least 8 seconds in order to observe timestamp change */
6675
/* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fbf47635315ab308c9b58a1ea0906e711a9228de */
6776
sleep(10);
6877

6978
r = write_dev_tty();
70-
if (r < 0)
71-
ksft_exit_fail_msg("failed to write to /dev/tty: %s\n",
72-
strerror(-r));
79+
if (r < 0) {
80+
ksft_print_msg("failed to write to /dev/tty: %s\n",
81+
strerror(-r));
82+
goto out;
83+
}
7384

7485
r = stat(tty, &st2);
75-
if (r < 0)
76-
ksft_exit_fail_msg("stat failed on tty path '%s': %m\n", tty);
86+
if (r < 0) {
87+
ksft_print_msg("stat failed on tty path '%s': %m\n", tty);
88+
goto out;
89+
}
7790

7891
/* We wrote to the terminal so timestamps should have been updated */
7992
if (st1.st_atim.tv_sec == st2.st_atim.tv_sec &&
8093
st1.st_mtim.tv_sec == st2.st_mtim.tv_sec) {
81-
ksft_test_result_fail("tty timestamps not updated\n");
82-
ksft_exit_fail();
94+
ksft_print_msg("tty timestamps not updated\n");
95+
goto out;
8396
}
8497

85-
ksft_test_result_pass(
98+
ksft_print_msg(
8699
"timestamps of terminal '%s' updated after write to /dev/tty\n", tty);
87-
return EXIT_SUCCESS;
100+
result = KSFT_PASS;
101+
102+
out:
103+
ksft_test_result_report(result, "tty_tstamp_update\n");
104+
105+
ksft_finished();
88106
}

0 commit comments

Comments
 (0)