Skip to contentSkip to conversation

Add TST_EXP_FAIL_ARR_SILENT() helper macros

PATCH In review Martin Doucha 4 participants 7 messages May 12

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Add TST_EXP_FAIL_ARR_SILENT() helper macros

Add silent version of TST_EXP_FAIL() macros with the possibility to check multiple expected errno values.

---
 include/tst_test_macros.h | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
include/tst_test_macros.h +30 -0
index 2cfbdb586..b1e74278d 100644
@@ -675,6 +675,36 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);
 			&tst_exp_err__, 1, ##__VA_ARGS__);                     \
 	} while (0)
 
+/**
+ * TST_EXP_FAIL_ARR_SILENT() - Test syscall to fail with expected errnos, silent variant.
+ *
+ * @SCALL: Tested syscall.
+ * @EXP_ERRS: Array of expected errnos.
+ * @EXP_ERRS_CNT: Lenght of EXP_ERRS.
+ * @...: A printf-like parameters.
+ *
+ * Unlike TST_EXP_FAIL_ARR() does not print :c:enum:`TPASS <tst_res_flags>` on
+ * success, only prints :c:enum:`TFAIL <tst_res_flags>` on failure.
+ */
+#define TST_EXP_FAIL_ARR_SILENT(SCALL, EXP_ERRS, EXP_ERRS_CNT, ...)            \
+	TST_EXP_FAIL_SILENT_(TST_RET == 0, SCALL, #SCALL,                      \
+		EXP_ERRS, EXP_ERRS_CNT, ##__VA_ARGS__)
+
+/**
+ * TST_EXP_FAIL2_ARR_SILENT() - Test syscall to fail with expected errnos, silent variant.
+ *
+ * @SCALL: Tested syscall.
+ * @EXP_ERRS: Array of expected errnos.
+ * @EXP_ERRS_CNT: Lenght of EXP_ERRS.
+ * @...: A printf-like parameters.
+ *
+ * Unlike TST_EXP_FAIL2_ARR() does not print :c:enum:`TPASS <tst_res_flags>` on
+ * success, only prints :c:enum:`TFAIL <tst_res_flags>` on failure.
+ */
+#define TST_EXP_FAIL2_ARR_SILENT(SCALL, EXP_ERRS, EXP_ERRS_CNT, ...)           \
+	TST_EXP_FAIL_SILENT_(TST_RET >= 0, SCALL, #SCALL,                     \
+		EXP_ERRS, EXP_ERRS_CNT, ##__VA_ARGS__)
+
 /**
  * TST_EXP_EXPR() - Check for expected expression.
  *
Signature · 5 lines
2.53.0


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

PATCH 2/2 af_alg08: Allow recv() to return EINVAL

Recent kernels return EBADMSG from recv() when the crypto operation fails. However, older kernels return EINVAL instead. Accept both errno values.

---
 testcases/kernel/crypto/af_alg08.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
testcases/kernel/crypto/af_alg08.c +6 -1
index 5e04b579c..937ab1758 100644
@@ -60,6 +60,10 @@ static int algfd = -1;
 static int reqfd = -1;
 static int pipefd[2] = { -1, -1 };
 static int file_fd = -1;
+static const int exp_errnos[] = {
+	EBADMSG,
+	EINVAL
+};
 
 static void try_corrupt(void)
 {
@@ -100,7 +104,8 @@ static void try_corrupt(void)
 	SAFE_SPLICE(pipefd[0], NULL, reqfd, NULL, OVERWRITE_SIZE, 0);
 
 	/* Expected to fail (invalid ciphertext); triggers the scratch write */
-	TST_EXP_FAIL_SILENT(recv(reqfd, recvbuf, sizeof(recvbuf), 0), EBADMSG);
+	TST_EXP_FAIL_ARR_SILENT(recv(reqfd, recvbuf, sizeof(recvbuf), 0),
+		exp_errnos, ARRAY_SIZE(exp_errnos));
 
 	SAFE_CLOSE(pipefd[0]);
 	SAFE_CLOSE(pipefd[1]);
Signature · 5 lines
2.53.0


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

Re: [LTP] [PATCH 2/2] af_alg08: Allow recv() to return EINVAL

In reply to Martin Doucha
Quoted 3 lines

Recent kernels return EBADMSG from recv() when the crypto operation fails. However, older kernels return EINVAL instead. Accept both errno values.

...

testcases/kernel/crypto/af_alg08.c static int algfd = -1; · line 65

Quoted 8 lines

+++ b/testcases/kernel/crypto/af_alg08.c

testcases/kernel/crypto/af_alg08.c +3 -0
@@ -60,6 +60,10 @@ static int algfd = -1;
 static int reqfd = -1;
 static int pipefd[2] = { -1, -1 };
 static int file_fd = -1;
+static const int exp_errnos[] = {
+	EBADMSG,
+	EINVAL

I'm also ok with not detecting kernel version because this is not a subject of testing. I guess that's the rule for question "when to bother with kernel version check for specific errno". Maybe we should mention it in the test macro doc.

Anyway, merged.

Kind regards,
Petr

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

Hi all,

Quoted 2 lines

Hi!

I dared to mention 2 variant in the commit message and merge whole patchset. Thanks!

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw
In reply to Martin Doucha

Hi Martin,

--- [PATCH 1/2] ---

Quoted 3 lines · Martin Doucha

[PATCH 1/2] Add TST_EXP_FAIL_ARR_SILENT() helper macros

+ * @EXP_ERRS_CNT: Lenght of EXP_ERRS.

Typo: s/Lenght/Length/. Appears twice, in both new macro doc blocks.

---
Note:

Our agent completed the review of the patch. The full review can be found at: https://patchwork.ozlabs.org/project/ltp/list/?series=503985

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