Linux-kselftest Archive mirror
 help / color / mirror / Atom feed
From: Shengyu Li <shengyu.li.evgeny@gmail.com>
To: shuah@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	Shengyu Li <shengyu.li.evgeny@gmail.com>
Subject: [PATCH] selftest/tty: Use harness framework in tty
Date: Tue, 30 Apr 2024 23:05:08 +0800	[thread overview]
Message-ID: <20240430150508.82467-1-shengyu.li.evgeny@gmail.com> (raw)

Similarly, this one is based on automated tools and a very 
small percentage of manual modifications to automatically refactor 
the version that uses kselftest_harness.h, which is logically clearer.

Signed-off-by: Shengyu Li <shengyu.li.evgeny@gmail.com>
---
 .../testing/selftests/tty/tty_tstamp_update.c | 48 ++++++-------------
 1 file changed, 14 insertions(+), 34 deletions(-)

diff --git a/tools/testing/selftests/tty/tty_tstamp_update.c b/tools/testing/selftests/tty/tty_tstamp_update.c
index 9e1a40f5db17..cdaa6a15ee65 100644
--- a/tools/testing/selftests/tty/tty_tstamp_update.c
+++ b/tools/testing/selftests/tty/tty_tstamp_update.c
@@ -9,7 +9,7 @@
 #include <unistd.h>
 #include <linux/limits.h>
 
-#include "../kselftest.h"
+#include "../kselftest_harness.h"
 
 #define MIN_TTY_PATH_LEN 8
 
@@ -42,65 +42,45 @@ static int write_dev_tty(void)
 	return r;
 }
 
-int main(int argc, char **argv)
+TEST(tty_tstamp_update)
 {
-	int r;
 	char tty[PATH_MAX] = {};
 	struct stat st1, st2;
-	int result = KSFT_FAIL;
 
-	ksft_print_header();
-	ksft_set_plan(1);
-
-	r = readlink("/proc/self/fd/0", tty, PATH_MAX);
-	if (r < 0) {
+	ASSERT_GE(readlink("/proc/self/fd/0", tty, PATH_MAX), 0) {
 		ksft_print_msg("readlink on /proc/self/fd/0 failed: %m\n");
-		goto out;
 	}
 
 	if (!tty_valid(tty)) {
-		ksft_print_msg("invalid tty path '%s'\n", tty);
-		result = KSFT_SKIP;
-		goto out;
-
+		ksft_print_msg("SKIP: invalid tty path '%s'\n", tty);
+		exit(KSFT_SKIP);
 	}
 
-	r = stat(tty, &st1);
-	if (r < 0) {
+	ASSERT_GE(stat(tty, &st1), 0) {
 		ksft_print_msg("stat failed on tty path '%s': %m\n", tty);
-		goto out;
 	}
 
 	/* We need to wait at least 8 seconds in order to observe timestamp change */
 	/* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fbf47635315ab308c9b58a1ea0906e711a9228de */
 	sleep(10);
 
-	r = write_dev_tty();
-	if (r < 0) {
-		ksft_print_msg("failed to write to /dev/tty: %s\n",
-			       strerror(-r));
-		goto out;
+	ASSERT_GE(write_dev_tty(), 0) {
+		ksft_perror("failed to write to /dev/tty");
 	}
 
-	r = stat(tty, &st2);
-	if (r < 0) {
+	ASSERT_GE(stat(tty, &st2), 0) {
 		ksft_print_msg("stat failed on tty path '%s': %m\n", tty);
-		goto out;
 	}
 
 	/* We wrote to the terminal so timestamps should have been updated */
-	if (st1.st_atim.tv_sec == st2.st_atim.tv_sec &&
-	    st1.st_mtim.tv_sec == st2.st_mtim.tv_sec) {
+	ASSERT_NE(st1.st_atim.tv_sec, st2.st_atim.tv_sec) {
+		ksft_print_msg("tty timestamps not updated\n");
+	}
+	ASSERT_NE(st1.st_mtim.tv_sec, st2.st_mtim.tv_sec) {
 		ksft_print_msg("tty timestamps not updated\n");
-		goto out;
 	}
 
 	ksft_print_msg(
 		"timestamps of terminal '%s' updated after write to /dev/tty\n", tty);
-	result = KSFT_PASS;
-
-out:
-	ksft_test_result_report(result, "tty_tstamp_update\n");
-
-	ksft_finished();
 }
+TEST_HARNESS_MAIN
-- 
2.25.1


             reply	other threads:[~2024-04-30 15:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-30 15:05 Shengyu Li [this message]
2024-05-03 19:42 ` [PATCH] selftest/tty: Use harness framework in tty Shuah Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240430150508.82467-1-shengyu.li.evgeny@gmail.com \
    --to=shengyu.li.evgeny@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).