[PATCH RFC 3/7] selftests/nolibc: replace repetitive test structure with macro

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

 



A future patch will change these, so prepare for that.

Signed-off-by: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>
---
 tools/testing/selftests/nolibc/nolibc-test.c | 35 ++++++++++++----------------
 1 file changed, 15 insertions(+), 20 deletions(-)

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 1bd99e0fab4d..76bd6a0a8132 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -570,6 +570,13 @@ static int expect_strne(const char *expr, int llen, const char *cmp)
 #define CASE_TEST(name) \
 	case __LINE__: llen += printf("%d %s", test, #name);
 
+#define SWITCH_TEST \
+	switch (test + __LINE__ + 1) {
+
+#define SWITCH_TEST_END \
+	case __LINE__: return ret; }
+
+
 int run_startup(unsigned int min, unsigned int max)
 {
 	int test;
@@ -591,7 +598,7 @@ int run_startup(unsigned int min, unsigned int max)
 		/* avoid leaving empty lines below, this will insert holes into
 		 * test numbers.
 		 */
-		switch (test + __LINE__ + 1) {
+		SWITCH_TEST
 		CASE_TEST(argc);             EXPECT_GE(1, test_argc, 1); break;
 		CASE_TEST(argv_addr);        EXPECT_PTRGT(1, test_argv, brk); break;
 		CASE_TEST(argv_environ);     EXPECT_PTRLT(1, test_argv, environ); break;
@@ -607,10 +614,7 @@ int run_startup(unsigned int min, unsigned int max)
 		CASE_TEST(auxv_addr);        EXPECT_PTRGT(test_auxv != (void *)-1, test_auxv, brk); break;
 		CASE_TEST(auxv_AT_UID);      EXPECT_EQ(1, getauxval(AT_UID), getuid()); break;
 		CASE_TEST(auxv_AT_PAGESZ);   EXPECT_GE(1, getauxval(AT_PAGESZ), 4096); break;
-		case __LINE__:
-			return ret; /* must be last */
-		/* note: do not set any defaults so as to permit holes above */
-		}
+		SWITCH_TEST_END
 	}
 	return ret;
 }
@@ -803,7 +807,7 @@ int run_syscall(unsigned int min, unsigned int max)
 		/* avoid leaving empty lines below, this will insert holes into
 		 * test numbers.
 		 */
-		switch (test + __LINE__ + 1) {
+		SWITCH_TEST
 		CASE_TEST(getpid);            EXPECT_SYSNE(1, getpid(), -1); break;
 		CASE_TEST(getppid);           EXPECT_SYSNE(1, getppid(), -1); break;
 		CASE_TEST(gettid);            EXPECT_SYSNE(has_gettid, gettid(), -1); break;
@@ -876,10 +880,7 @@ int run_syscall(unsigned int min, unsigned int max)
 		CASE_TEST(write_zero);        EXPECT_SYSZR(1, write(1, &tmp, 0)); break;
 		CASE_TEST(syscall_noargs);    EXPECT_SYSEQ(1, syscall(__NR_getpid), getpid()); break;
 		CASE_TEST(syscall_args);      EXPECT_SYSER(1, syscall(__NR_statx, 0, NULL, 0, 0, NULL), -1, EFAULT); break;
-		case __LINE__:
-			return ret; /* must be last */
-		/* note: do not set any defaults so as to permit holes above */
-		}
+		SWITCH_TEST_END
 	}
 	return ret;
 }
@@ -897,7 +898,7 @@ int run_stdlib(unsigned int min, unsigned int max)
 		/* avoid leaving empty lines below, this will insert holes into
 		 * test numbers.
 		 */
-		switch (test + __LINE__ + 1) {
+		SWITCH_TEST
 		CASE_TEST(getenv_TERM);        EXPECT_STRNZ(1, getenv("TERM")); break;
 		CASE_TEST(getenv_blah);        EXPECT_STRZR(1, getenv("blah")); break;
 		CASE_TEST(setcmp_blah_blah);   EXPECT_EQ(1, strcmp("blah", "blah"), 0); break;
@@ -966,10 +967,7 @@ int run_stdlib(unsigned int min, unsigned int max)
 		CASE_TEST(limit_ptrdiff_min_32);    EXPECT_EQ(sizeof(long) == 4, PTRDIFF_MIN, (ptrdiff_t) 0x80000000); break;
 		CASE_TEST(limit_ptrdiff_max_32);    EXPECT_EQ(sizeof(long) == 4, PTRDIFF_MAX, (ptrdiff_t) 0x7fffffff); break;
 		CASE_TEST(limit_size_max_32);       EXPECT_EQ(sizeof(long) == 4, SIZE_MAX,    (size_t)    0xffffffffU); break;
-		case __LINE__:
-			return ret; /* must be last */
-		/* note: do not set any defaults so as to permit holes above */
-		}
+		SWITCH_TEST_END
 	}
 	return ret;
 }
@@ -1040,7 +1038,7 @@ static int run_vfprintf(unsigned int min, unsigned int max)
 		/* avoid leaving empty lines below, this will insert holes into
 		 * test numbers.
 		 */
-		switch (test + __LINE__ + 1) {
+		SWITCH_TEST
 		CASE_TEST(empty);        EXPECT_VFPRINTF(0, "", ""); break;
 		CASE_TEST(simple);       EXPECT_VFPRINTF(3, "foo", "foo"); break;
 		CASE_TEST(string);       EXPECT_VFPRINTF(3, "foo", "%s", "foo"); break;
@@ -1050,10 +1048,7 @@ static int run_vfprintf(unsigned int min, unsigned int max)
 		CASE_TEST(char);         EXPECT_VFPRINTF(1, "c", "%c", 'c'); break;
 		CASE_TEST(hex);          EXPECT_VFPRINTF(1, "f", "%x", 0xf); break;
 		CASE_TEST(pointer);      EXPECT_VFPRINTF(3, "0x1", "%p", (void *) 0x1); break;
-		case __LINE__:
-			return ret; /* must be last */
-		/* note: do not set any defaults so as to permit holes above */
-		}
+		SWITCH_TEST_END
 	}
 	return ret;
 }

-- 
2.41.0




[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