All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yang Xu <xuyang2018.jy@fujitsu.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3 2/3] include/tst_test_macro.h: Add TST_EXP_FAIL2 macros
Date: Thu, 24 Jun 2021 13:33:46 +0800	[thread overview]
Message-ID: <1624512827-3256-2-git-send-email-xuyang2018.jy@fujitsu.com> (raw)
In-Reply-To: <1624512827-3256-1-git-send-email-xuyang2018.jy@fujitsu.com>

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 doc/c-test-api.txt        | 11 +++++++++++
 include/tst_test_macros.h |  8 ++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/doc/c-test-api.txt b/doc/c-test-api.txt
index 4cccbdc10..e3ca27696 100644
--- a/doc/c-test-api.txt
+++ b/doc/c-test-api.txt
@@ -281,6 +281,17 @@ The 'TST_EXP_FAIL()' is similar to 'TST_EXP_PASS()' but it fails the test if
 the call haven't failed with -1 and 'errno' wasn't set to the expected one
 passed as the second argument.
 
+[source,c]
+-------------------------------------------------------------------------------
+static void test(void)
+{
+	...
+	TST_EXP_FAIL2(msgget(key, flags), EINVAL, "msgget(%i, %i)", key, flags);
+	...
+}
+The 'TST_EXP_FAIL2()' is the same as 'TST_EXP_FAIL' the only difference is that
+the return value is a non-negative integer if call passes.
+
 [source,c]
 -------------------------------------------------------------------------------
 const char *tst_strsig(int sig);
diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index 89dfe5a31..78cee47de 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -120,13 +120,13 @@ extern void *TST_RET_PTR;
 			TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);     \
 	} while (0)                                                            \
 
-#define TST_EXP_FAIL(SCALL, ERRNO, ...)                                        \
+#define TST_EXP_FAIL_(PASS_COND, SCALL, ERRNO, ...)                            \
 	do {                                                                   \
 		TEST(SCALL);                                                   \
 		                                                               \
 		TST_PASS = 0;                                                  \
 		                                                               \
-		if (TST_RET == 0) {                                            \
+		if (PASS_COND) {                                               \
 			TST_MSG_(TFAIL, " succeeded", #SCALL, ##__VA_ARGS__);  \
 		        break;                                                 \
 		}                                                              \
@@ -150,4 +150,8 @@ extern void *TST_RET_PTR;
 		}                                                              \
 	} while (0)
 
+#define TST_EXP_FAIL(SCALL, ERRNO, ...) TST_EXP_FAIL_(TST_RET == 0, SCALL, ERRNO, __VA_ARGS__)
+
+#define TST_EXP_FAIL2(SCALL, ERRNO, ...) TST_EXP_FAIL_(TST_RET >= 0, SCALL, ERRNO, __VA_ARGS__)
+
 #endif	/* TST_TEST_MACROS_H__ */
-- 
2.23.0


  reply	other threads:[~2021-06-24  5:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <YNM4rlDJLzb4xk6v@yuki>
2021-06-24  5:33 ` [LTP] [PATCH v3 1/3] lib: Add SAFE_SETGROUPS() and SAFE_GETGROUPS() function to LTP library Yang Xu
2021-06-24  5:33   ` Yang Xu [this message]
2021-06-28 15:02     ` [LTP] [PATCH v3 2/3] include/tst_test_macro.h: Add TST_EXP_FAIL2 macros Cyril Hrubis
2021-06-24  5:33   ` [LTP] [PATCH v3 3/3] syscalls/shmget*: Convert into new api Yang Xu
2021-06-28 15:05     ` Cyril Hrubis
2021-07-05 10:03       ` Krzysztof Kozlowski
2021-07-06 13:22         ` Thadeu Lima de Souza Cascardo
2021-07-22 10:51     ` Cyril Hrubis
2021-07-23  4:36       ` xuyang2018.jy
2021-06-28 15:01   ` [LTP] [PATCH v3 1/3] lib: Add SAFE_SETGROUPS() and SAFE_GETGROUPS() function to LTP library Cyril Hrubis

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=1624512827-3256-2-git-send-email-xuyang2018.jy@fujitsu.com \
    --to=xuyang2018.jy@fujitsu.com \
    --cc=ltp@lists.linux.it \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.