[PATCH] selftest/tmpfs: Use harness framework in tmpfs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Notice that there are a lot of Patch commits to enhance 
the consistency of output from our legacy tests, 
we plan to refactor them using kselftest_harness.h automatically by tools. 
This will help standardize the TAP output format, 
ensuring clarity and traceability of test results.
This is the version of tmpfs after auto-refactoring.

Signed-off-by: Shengyu Li <shengyu.li.evgeny@xxxxxxxxx>
---
 .../selftests/tmpfs/bug-link-o-tmpfile.c      | 54 +++++++++----------
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c b/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c
index b5c3ddb90942..8a9a29bff287 100644
--- a/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c
+++ b/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c
@@ -23,45 +23,45 @@
 #include <sys/mount.h>
 #include <unistd.h>
 
-int main(void)
-{
-	int fd;
+#include "../kselftest_harness.h"
 
-	if (unshare(CLONE_NEWNS) == -1) {
+TEST(tmpfs_inodes_and_linking)
+{
+	ASSERT_NE(unshare(CLONE_NEWNS), -1)
+	{
 		if (errno == ENOSYS || errno == EPERM) {
-			fprintf(stderr, "error: unshare, errno %d\n", errno);
-			return 4;
+			SKIP(return, "error: unshare, errno %d\n", errno);
 		}
-		fprintf(stderr, "error: unshare, errno %d\n", errno);
-		return 1;
+		TH_LOG("error: unshare, errno %d\n", errno);
 	}
-	if (mount(NULL, "/", NULL, MS_PRIVATE|MS_REC, NULL) == -1) {
-		fprintf(stderr, "error: mount '/', errno %d\n", errno);
-		return 1;
+
+	ASSERT_NE(mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL), -1)
+	{
+		TH_LOG("error: mount '/', errno %d\n", errno);
 	}
 
 	/* Our heroes: 1 root inode, 1 O_TMPFILE inode, 1 permanent inode. */
-	if (mount(NULL, "/tmp", "tmpfs", 0, "nr_inodes=3") == -1) {
-		fprintf(stderr, "error: mount tmpfs, errno %d\n", errno);
-		return 1;
+	ASSERT_NE(mount(NULL, "/tmp", "tmpfs", 0, "nr_inodes=3"), -1)
+	{
+		TH_LOG("error: mount tmpfs, errno %d\n", errno);
 	}
 
-	fd = openat(AT_FDCWD, "/tmp", O_WRONLY|O_TMPFILE, 0600);
-	if (fd == -1) {
-		fprintf(stderr, "error: open 1, errno %d\n", errno);
-		return 1;
+	int fd = openat(AT_FDCWD, "/tmp", O_WRONLY | O_TMPFILE, 0600);
+
+	ASSERT_NE(fd, -1)
+	{
+		TH_LOG("error: open 1, errno %d\n", errno);
 	}
-	if (linkat(fd, "", AT_FDCWD, "/tmp/1", AT_EMPTY_PATH) == -1) {
-		fprintf(stderr, "error: linkat, errno %d\n", errno);
-		return 1;
+
+	ASSERT_NE(linkat(fd, "", AT_FDCWD, "/tmp/1", AT_EMPTY_PATH), -1)
+	{
+		TH_LOG("error: linkat, errno %d\n", errno);
 	}
 	close(fd);
 
-	fd = openat(AT_FDCWD, "/tmp", O_WRONLY|O_TMPFILE, 0600);
-	if (fd == -1) {
-		fprintf(stderr, "error: open 2, errno %d\n", errno);
-		return 1;
+	ASSERT_NE(openat(AT_FDCWD, "/tmp", O_WRONLY | O_TMPFILE, 0600), -1)
+	{
+		TH_LOG("error: open 2, errno %d\n", errno);
 	}
-
-	return 0;
 }
+TEST_HARNESS_MAIN
-- 
2.25.1





[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux