Skip to contentSkip to conversation

test_macros: Add TST_EXP_PASS_OR_FAIL()

PATCH In review Petr Vorel 3 participants 3 messages Jul 10

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/1 test_macros: Add TST_EXP_PASS_OR_FAIL()

This allows instead of:

	if (err) {
		TST_EXP_FAIL(epoll_ctl(efd, EPOLL_CTL_ADD,
				 fd.fd, &ev), err,
				 "epoll_ctl() on %s", tst_fd_desc(&fd));
	} else {
		TST_EXP_PASS(epoll_ctl(efd, EPOLL_CTL_ADD,
				 fd.fd, &ev),
				 "epoll_ctl() on %s", tst_fd_desc(&fd));
	}

to simplify to just:

	TST_EXP_PASS_OR_FAIL(epoll_ctl(efd, EPOLL_CTL_ADD,
			 fd.fd, &ev), err,
			 "epoll_ctl() on %s", tst_fd_desc(&fd));

+ Fix macro parameter name in TST_EXP_FD_OR_FAIL() (upper case).

---
 include/tst_test_macros.h | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
include/tst_test_macros.h +24 -1
index f06c8aeb77..e980cc6022 100644
@@ -168,7 +168,7 @@ extern int TST_PASS;
  * @ERRNO: Expected errno or 0.
  * @...: A printf-like parameters.
  *
- * Expect a file descriptor if errno is 0 otherwise expect a failure with
+ * Expect a file descriptor if ERRNO is 0 otherwise expect a failure with
  * expected errno.
  *
  * Internally it uses TST_EXP_FAIL() and TST_EXP_FD().
@@ -354,6 +354,29 @@ extern int TST_PASS;
 			TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);     \
 	} while (0)
 
+/**
+ * TST_EXP_PASS_OR_FAIL() - Test syscall to and expect to pass or fail with
+ * expected errno.
+ *
+ * @SCALL: Tested syscall.
+ * @ERRNO: Expected errno or 0.
+ * @...: A printf-like parameters.
+ *
+ * Expect to pass if ERRNO is 0 otherwise expect a failure with
+ * expected errno.
+ *
+ * Internally it uses TST_EXP_FAIL() and TST_EXP_PASS().
+ */
+#define TST_EXP_PASS_OR_FAIL(SCALL, ERRNO, ...)                                \
+	({                                                                     \
+		if (ERRNO)                                                     \
+			TST_EXP_FAIL(SCALL, ERRNO, ##__VA_ARGS__);             \
+		else                                                           \
+			TST_EXP_PASS(SCALL, ##__VA_ARGS__);                      \
+		                                                               \
+		TST_RET;                                                       \
+	})
+
 /**
  * TST_EXP_PASS_PTR_VOID() - Test syscall to return a valid pointer.
  *
Signature · 5 lines
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi!

Quoted 32 lines
 include/tst_test_macros.h | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
include/tst_test_macros.h +13 -1
index f06c8aeb77..e980cc6022 100644
@@ -168,7 +168,7 @@ extern int TST_PASS;
  * @ERRNO: Expected errno or 0.
  * @...: A printf-like parameters.
  *
- * Expect a file descriptor if errno is 0 otherwise expect a failure with
+ * Expect a file descriptor if ERRNO is 0 otherwise expect a failure with
  * expected errno.
  *
  * Internally it uses TST_EXP_FAIL() and TST_EXP_FD().
@@ -354,6 +354,29 @@ extern int TST_PASS;
 			TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);     \
 	} while (0)
 
+/**
+ * TST_EXP_PASS_OR_FAIL() - Test syscall to and expect to pass or fail with
+ * expected errno.
+ *
+ * @SCALL: Tested syscall.
+ * @ERRNO: Expected errno or 0.
+ * @...: A printf-like parameters.
+ *
+ * Expect to pass if ERRNO is 0 otherwise expect a failure with
+ * expected errno.
+ *
+ * Internally it uses TST_EXP_FAIL() and TST_EXP_PASS().

include/tst_test_macros.h extern int TST_PASS; · line 378

Quoted 10 lines
include/tst_test_macros.h +10 -0
+ */
+#define TST_EXP_PASS_OR_FAIL(SCALL, ERRNO, ...)                                \
+	({                                                                     \
+		if (ERRNO)                                                     \
+			TST_EXP_FAIL(SCALL, ERRNO, ##__VA_ARGS__);             \
+		else                                                           \
+			TST_EXP_PASS(SCALL, ##__VA_ARGS__);                      \
+		                                                               \
+		TST_RET;                                                       \
+	})

I do not think that this is working as expected. If I remmeber correctly we have to stringify the SCALL in the first macro is passed into otherwise it may get expanded and produce unexpected results.

E.g. if we pass something with macro constants such as open() with O_RDONLY the O_RDONLY will be replaced with 0. This is the reason why the rest of the macros pass #SCALL to any macros it uses.

We need to change the TST_EXP_FAIL() and TST_EXP_PASS() so that they have underscore variant first, e.g.:

include/tst_test_macros.h +5 -2
index f06c8aeb7..d391bdb9e 100644
@@ -488,10 +488,13 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
  * printed by the pass or fail tst_res() calls. If omitted the first parameter
  * is converted to a string and used instead.
  */
-#define TST_EXP_FAIL(SCALL, EXP_ERR, ...)                                      \
+#define TST_EXP_FAIL(SCAL, EXP_ERR, ...) \
+       TST_EXP_FAIL_(SCAL, #SCAL, ##__VA_ARGS__)
+
+#define TST_EXP_FAIL_(SCALL, SSCAL, EXP_ERR, ...)                                      \
        do {                                                                   \
                int tst_exp_err__ = EXP_ERR;                                   \
-               TST_EXP_FAIL_ARR_(SCALL, #SCALL, &tst_exp_err__, 1,            \
+               TST_EXP_FAIL_ARR_(SCALL, SSCALL, &tst_exp_err__, 1,            \
                                   ##__VA_ARGS__);                              \
        } while (0)
 

Then we can build the _OR_FAIL() macros on the top of that. And the TST_EXP_FD_OR_FAIL() should be fixed too.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
In reply to Petr Vorel

Hi Petr,

Quoted 3 lines · Petr Vorel

test_macros: Add TST_EXP_PASS_OR_FAIL()

+ Fix macro parameter name in TST_EXP_FD_OR_FAIL() (upper case).

This is a second, independent logical change bundled into the same patch. Ground Rule 7 requires exactly one logical change per patch. The doc-comment fix in TST_EXP_FD_OR_FAIL() should go in a separate preparatory patch.

Quoted 2 lines

+ * TST_EXP_PASS_OR_FAIL() - Test syscall to and expect to pass or fail with
+ * expected errno.

"to and expect" reads as ungrammatical here. Something like:

TST_EXP_PASS_OR_FAIL() - Test syscall to pass or fail with expected errno.

Verdict - Needs revision

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp