* [LTP] [PATCH v2 00/10] Introduce TST_EXP_MACROS
@ 2020-12-10 14:15 Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 01/10] lib: Introduce TST_EXP_* macros Cyril Hrubis
` (11 more replies)
0 siblings, 12 replies; 15+ messages in thread
From: Cyril Hrubis @ 2020-12-10 14:15 UTC (permalink / raw)
To: ltp
This patchset adds TST_EXP_MACROS() implementation.
These macros are intended to simplify and unify syscall unit tests.
This patchset converts a few testcases to use TST_EXP_MACROS() it's
intenteded to serve as an example since there is a lot of testcases that
could use them as well.
Also the documentation for these macros is ommited at this point, I will
add it in a case that we agree to include them in the test library.
Changes in v2:
- renamed the macros so that it's more clear that they do
- added documentation to test-writing-guidelines
- minor fixed in the converted testcases
Cyril Hrubis (10):
lib: Introduce TST_EXP_* macros
syscalls/uname: Make use of TST_EXP_MACROS
syscalls/accept: Make use of TST_EXP_MACROS
syscalls/access: Make use of TST_EXP_MACROS
syscalls/bind: Make use of TST_EXP_MACROS
syscalls/brk01: Make use of TST_EXP_MACROS
syscalls/cacheflush: Make use of TST_EXP_MACROS
syscalls/capget: Make use of TEST_MACROS
syscalls/capset: Make use of TST_EXP_MACROS
syscalls/open: Make use of TST_EXP_MACROS
doc/test-writing-guidelines.txt | 54 ++++++++
include/tst_test.h | 28 +---
include/tst_test_macros.h | 130 ++++++++++++++++++
lib/newlib_tests/.gitignore | 3 +
lib/newlib_tests/test_macros01.c | 40 ++++++
lib/newlib_tests/test_macros02.c | 42 ++++++
lib/newlib_tests/test_macros03.c | 40 ++++++
lib/tst_test.c | 1 +
testcases/kernel/syscalls/accept/accept01.c | 17 +--
testcases/kernel/syscalls/access/access01.c | 45 +-----
testcases/kernel/syscalls/access/access02.c | 8 +-
testcases/kernel/syscalls/access/access03.c | 28 +---
testcases/kernel/syscalls/access/access04.c | 17 +--
testcases/kernel/syscalls/bind/bind01.c | 12 +-
testcases/kernel/syscalls/bind/bind02.c | 11 +-
testcases/kernel/syscalls/bind/bind03.c | 26 +---
testcases/kernel/syscalls/bind/bind04.c | 5 +-
testcases/kernel/syscalls/bind/bind05.c | 5 +-
testcases/kernel/syscalls/brk/brk01.c | 9 +-
.../kernel/syscalls/cacheflush/cacheflush01.c | 8 +-
testcases/kernel/syscalls/capget/capget01.c | 17 +--
testcases/kernel/syscalls/capget/capget02.c | 26 ++--
testcases/kernel/syscalls/capset/capset01.c | 14 +-
testcases/kernel/syscalls/capset/capset02.c | 28 ++--
testcases/kernel/syscalls/capset/capset03.c | 10 +-
testcases/kernel/syscalls/capset/capset04.c | 13 +-
testcases/kernel/syscalls/open/open01.c | 11 +-
testcases/kernel/syscalls/open/open02.c | 25 +---
testcases/kernel/syscalls/open/open11.c | 22 ++-
testcases/kernel/syscalls/uname/uname01.c | 13 +-
testcases/kernel/syscalls/uname/uname02.c | 17 +--
31 files changed, 403 insertions(+), 322 deletions(-)
create mode 100644 include/tst_test_macros.h
create mode 100644 lib/newlib_tests/test_macros01.c
create mode 100644 lib/newlib_tests/test_macros02.c
create mode 100644 lib/newlib_tests/test_macros03.c
--
2.26.2
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH v2 01/10] lib: Introduce TST_EXP_* macros
2020-12-10 14:15 [LTP] [PATCH v2 00/10] Introduce TST_EXP_MACROS Cyril Hrubis
@ 2020-12-10 14:15 ` Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 02/10] syscalls/uname: Make use of TST_EXP_MACROS Cyril Hrubis
` (10 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Cyril Hrubis @ 2020-12-10 14:15 UTC (permalink / raw)
To: ltp
In order to simplify common return value checks.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
doc/test-writing-guidelines.txt | 54 +++++++++++++
include/tst_test.h | 28 +------
include/tst_test_macros.h | 130 +++++++++++++++++++++++++++++++
lib/newlib_tests/.gitignore | 3 +
lib/newlib_tests/test_macros01.c | 40 ++++++++++
lib/newlib_tests/test_macros02.c | 42 ++++++++++
lib/newlib_tests/test_macros03.c | 40 ++++++++++
lib/tst_test.c | 1 +
8 files changed, 311 insertions(+), 27 deletions(-)
create mode 100644 include/tst_test_macros.h
create mode 100644 lib/newlib_tests/test_macros01.c
create mode 100644 lib/newlib_tests/test_macros02.c
create mode 100644 lib/newlib_tests/test_macros03.c
diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt
index 149c0854a..99fb34628 100644
--- a/doc/test-writing-guidelines.txt
+++ b/doc/test-writing-guidelines.txt
@@ -451,6 +451,60 @@ Printf-like function to report error and exit the test, it can be used with ttyp
The 'ttype' can be combined bitwise with 'TERRNO' or 'TTERRNO' to print
'errno', 'TST_ERR' respectively.
+There are also 'TST_EXP_*()' macros that can simplify syscall unit tests to a
+single line, use them whenever possible. These macros take a function call as
+the first parameter and a printf-like format string and parameters as well.
+These test macros then expand to a code that runs the call, checks the return
+value and errno and reports the test result.
+
+[source,c]
+-------------------------------------------------------------------------------
+static void test(void)
+{
+ ...
+ TST_EXP_PASS(stat(fname, &statbuf), "stat(%s, ...)", fname);
+
+ if (!TST_PASS)
+ return;
+ ...
+}
+-------------------------------------------------------------------------------
+
+The 'TST_EXP_PASS()' can be used for calls that return -1 on failure and 0 on
+success. It will check for the return value and reports failure if the return
+value is not equal to 0. The call also sets the 'TST_PASS' variable to 1 if
+the call succeeeded.
+
+[source,c]
+-------------------------------------------------------------------------------
+static void test(void)
+{
+ ...
+ TST_EXP_FD(open(fname, O_RDONLY), "open(%s, O_RDONLY)", fname);
+
+ SAFE_CLOSE(TST_RET);
+ ...
+}
+-------------------------------------------------------------------------------
+
+The 'TST_EXP_FD()' is the same as 'TST_EXP_PASS()' the only difference is that
+the return value is expected to be a file descriptor so the call passes if
+positive integer is returned.
+
+[source,c]
+-------------------------------------------------------------------------------
+static void test(void)
+{
+ ...
+ TST_EXP_FAIL(stat(fname, &statbuf), ENOENT, "stat(%s, ...)", fname);
+ ...
+}
+-------------------------------------------------------------------------------
+
+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]
-------------------------------------------------------------------------------
const char *tst_strsig(int sig);
diff --git a/include/tst_test.h b/include/tst_test.h
index cf08f3c78..c87251870 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -18,6 +18,7 @@
#include "tst_common.h"
#include "tst_res_flags.h"
+#include "tst_test_macros.h"
#include "tst_checkpoint.h"
#include "tst_device.h"
#include "tst_mkfs.h"
@@ -272,33 +273,6 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
*/
void tst_reinit(void);
-//TODO Clean?
-#define TEST(SCALL) \
- do { \
- errno = 0; \
- TST_RET = SCALL; \
- TST_ERR = errno; \
- } while (0)
-
-#define TEST_VOID(SCALL) \
- do { \
- errno = 0; \
- SCALL; \
- TST_ERR = errno; \
- } while (0)
-
-extern long TST_RET;
-extern int TST_ERR;
-
-extern void *TST_RET_PTR;
-
-#define TESTPTR(SCALL) \
- do { \
- errno = 0; \
- TST_RET_PTR = (void*)SCALL; \
- TST_ERR = errno; \
- } while (0)
-
/*
* Functions to convert ERRNO to its name and SIGNAL to its name.
*/
diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
new file mode 100644
index 000000000..3016d95c2
--- /dev/null
+++ b/include/tst_test_macros.h
@@ -0,0 +1,130 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015-2020 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef TST_TEST_MACROS_H__
+#define TST_TEST_MACROS_H__
+
+#define TEST(SCALL) \
+ do { \
+ errno = 0; \
+ TST_RET = SCALL; \
+ TST_ERR = errno; \
+ } while (0)
+
+#define TEST_VOID(SCALL) \
+ do { \
+ errno = 0; \
+ SCALL; \
+ TST_ERR = errno; \
+ } while (0)
+
+extern long TST_RET;
+extern int TST_ERR;
+extern int TST_PASS;
+
+extern void *TST_RET_PTR;
+
+#define TESTPTR(SCALL) \
+ do { \
+ errno = 0; \
+ TST_RET_PTR = (void*)SCALL; \
+ TST_ERR = errno; \
+ } while (0)
+
+
+#define TST_2_(_1, _2, ...) _2
+
+#define TST_FMT_(FMT, _1, ...) FMT, ##__VA_ARGS__
+
+#define TST_MSG_(RES, FMT, SCALL, ...) \
+ tst_res_(__FILE__, __LINE__, RES, \
+ TST_FMT_(TST_2_(dummy, ##__VA_ARGS__, SCALL) FMT, __VA_ARGS__))
+
+#define TST_MSGP_(RES, FMT, PAR, SCALL, ...) \
+ tst_res_(__FILE__, __LINE__, RES, \
+ TST_FMT_(TST_2_(dummy, ##__VA_ARGS__, SCALL) FMT, __VA_ARGS__), PAR)
+
+#define TST_EXP_FD(SCALL, ...) \
+ do { \
+ TEST(SCALL); \
+ \
+ TST_PASS = 0; \
+ \
+ if (TST_RET == -1) { \
+ TST_MSG_(TFAIL | TTERRNO, " failed", \
+ #SCALL, ##__VA_ARGS__); \
+ break; \
+ } \
+ \
+ if (TST_RET < 0) { \
+ TST_MSGP_(TFAIL | TTERRNO, " invalid retval %ld", \
+ TST_RET, #SCALL, ##__VA_ARGS__); \
+ break; \
+ } \
+ \
+ TST_MSGP_(TPASS, " returned fd %ld", TST_RET, \
+ #SCALL, ##__VA_ARGS__); \
+ \
+ TST_PASS = 1; \
+ \
+ } while (0)
+
+#define TST_EXP_PASS(SCALL, ...) \
+ do { \
+ TEST(SCALL); \
+ \
+ TST_PASS = 0; \
+ \
+ if (TST_RET == -1) { \
+ TST_MSG_(TFAIL | TTERRNO, " failed", \
+ #SCALL, ##__VA_ARGS__); \
+ break; \
+ } \
+ \
+ if (TST_RET != 0) { \
+ TST_MSGP_(TFAIL | TTERRNO, " invalid retval %ld", \
+ TST_RET, #SCALL, ##__VA_ARGS__); \
+ break; \
+ } \
+ \
+ TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__); \
+ \
+ TST_PASS = 1; \
+ \
+ } while (0)
+
+
+#define TST_EXP_FAIL(SCALL, ERRNO, ...) \
+ do { \
+ TEST(SCALL); \
+ \
+ TST_PASS = 0; \
+ \
+ if (TST_RET == 0) { \
+ TST_MSG_(TFAIL | TTERRNO, " succeeded", \
+ #SCALL, ##__VA_ARGS__); \
+ break; \
+ } \
+ \
+ if (TST_RET != -1) { \
+ TST_MSGP_(TFAIL | TTERRNO, " invalid retval %ld", \
+ TST_RET, #SCALL, ##__VA_ARGS__); \
+ break; \
+ } \
+ \
+ if (ERRNO) { \
+ if (TST_ERR == ERRNO) { \
+ TST_MSG_(TPASS | TERRNO, "", \
+ #SCALL, ##__VA_ARGS__); \
+ TST_PASS = 1; \
+ } else { \
+ TST_MSGP_(TFAIL | TERRNO, " expected %s", \
+ tst_strerrno(ERRNO), \
+ #SCALL, ##__VA_ARGS__); \
+ } \
+ } \
+ } while (0)
+
+#endif /* TST_TEST_MACROS_H__ */
diff --git a/lib/newlib_tests/.gitignore b/lib/newlib_tests/.gitignore
index 6fc549cf2..6c2612259 100644
--- a/lib/newlib_tests/.gitignore
+++ b/lib/newlib_tests/.gitignore
@@ -37,3 +37,6 @@ test_kconfig02
variant
test_guarded_buf
tst_bool_expr
+test_macros01
+test_macros02
+test_macros03
diff --git a/lib/newlib_tests/test_macros01.c b/lib/newlib_tests/test_macros01.c
new file mode 100644
index 000000000..9a920f8e4
--- /dev/null
+++ b/lib/newlib_tests/test_macros01.c
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+/*
+ * Test macros.
+ */
+
+#include "tst_test.h"
+
+static int fail_fd(void)
+{
+ errno = EINVAL;
+ return -1;
+}
+
+static int pass_fd(void)
+{
+ return 42;
+}
+
+static int inval_val(void)
+{
+ return -42;
+}
+
+static void do_test(void)
+{
+ TST_EXP_FD(fail_fd(), "TEST DESCRIPTION");
+ tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+ TST_EXP_FD(pass_fd(), "%s", "TEST DESCRIPTION PARAM");
+ tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+ TST_EXP_FD(inval_val());
+ tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+}
+
+static struct tst_test test = {
+ .test_all = do_test,
+};
diff --git a/lib/newlib_tests/test_macros02.c b/lib/newlib_tests/test_macros02.c
new file mode 100644
index 000000000..f0a692ab6
--- /dev/null
+++ b/lib/newlib_tests/test_macros02.c
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+/*
+ * Test macros.
+ */
+
+#include "tst_test.h"
+
+static int fail_fn(void)
+{
+ errno = EINVAL;
+ return -1;
+}
+
+static int pass_fn(void)
+{
+ return 0;
+}
+
+static int inval_ret_fn(void)
+{
+ return 42;
+}
+
+static void do_test(void)
+{
+ TST_EXP_FAIL(fail_fn(), EINVAL);
+ tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+ TST_EXP_FAIL(fail_fn(), ENOTTY);
+ tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+ TST_EXP_FAIL(pass_fn(), ENOTTY);
+ tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+ TST_EXP_FAIL(inval_ret_fn(), ENOTTY, "TEST DESCRIPTION");
+ tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+}
+
+static struct tst_test test = {
+ .test_all = do_test,
+};
diff --git a/lib/newlib_tests/test_macros03.c b/lib/newlib_tests/test_macros03.c
new file mode 100644
index 000000000..414370980
--- /dev/null
+++ b/lib/newlib_tests/test_macros03.c
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+/*
+ * Test macros.
+ */
+
+#include "tst_test.h"
+
+static int fail_fn(void)
+{
+ errno = EINVAL;
+ return -1;
+}
+
+static int pass_fn(void)
+{
+ return 0;
+}
+
+static int inval_ret_fn(void)
+{
+ return 42;
+}
+
+static void do_test(void)
+{
+ TST_EXP_PASS(fail_fn());
+ tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+ TST_EXP_PASS(pass_fn(), "TEST DESCRIPTION");
+ tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+ TST_EXP_PASS(inval_ret_fn());
+ tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+}
+
+static struct tst_test test = {
+ .test_all = do_test,
+};
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 9c0a95b95..0714f0a0e 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -75,6 +75,7 @@ const char *tst_ipc_path = ipc_path;
static char shm_path[1024];
int TST_ERR;
+int TST_PASS;
long TST_RET;
static void do_cleanup(void);
--
2.26.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH v2 02/10] syscalls/uname: Make use of TST_EXP_MACROS
2020-12-10 14:15 [LTP] [PATCH v2 00/10] Introduce TST_EXP_MACROS Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 01/10] lib: Introduce TST_EXP_* macros Cyril Hrubis
@ 2020-12-10 14:15 ` Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 03/10] syscalls/accept: " Cyril Hrubis
` (9 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Cyril Hrubis @ 2020-12-10 14:15 UTC (permalink / raw)
To: ltp
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
testcases/kernel/syscalls/uname/uname01.c | 13 +++----------
testcases/kernel/syscalls/uname/uname02.c | 17 +----------------
2 files changed, 4 insertions(+), 26 deletions(-)
diff --git a/testcases/kernel/syscalls/uname/uname01.c b/testcases/kernel/syscalls/uname/uname01.c
index bd3b05303..5e2f5ffac 100644
--- a/testcases/kernel/syscalls/uname/uname01.c
+++ b/testcases/kernel/syscalls/uname/uname01.c
@@ -18,24 +18,17 @@ static void verify_uname(void)
memset(&un, 0, sizeof(un));
- TEST(uname(&un));
- if (TST_RET == -1) {
- tst_res(TFAIL | TTERRNO, "uname() failed");
- return;
- }
+ TST_EXP_PASS(uname(&un));
- if (TST_RET != 0) {
- tst_res(TFAIL | TTERRNO,
- "uname() returned invalid value %ld", TST_RET);
+ if (!TST_PASS)
return;
- }
if (strcmp(un.sysname, "Linux")) {
tst_res(TFAIL, "sysname is not Linux");
return;
}
- tst_res(TPASS, "uname() succeeded");
+ tst_res(TPASS, "sysname set to Linux");
}
static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/uname/uname02.c b/testcases/kernel/syscalls/uname/uname02.c
index 1903dae24..cd4b15487 100644
--- a/testcases/kernel/syscalls/uname/uname02.c
+++ b/testcases/kernel/syscalls/uname/uname02.c
@@ -16,22 +16,7 @@ static void *bad_addr;
static void verify_uname(void)
{
- TEST(uname(bad_addr));
- if (TST_RET == 0) {
- tst_res(TFAIL, "uname() succeed when failure expected");
- return;
- }
-
- if (TST_RET != -1) {
- tst_res(TFAIL, "Invalid uname() return value %ld", TST_RET);
- return;
- }
-
- if (TST_ERR == EFAULT)
- tst_res(TPASS, "uname() got EFAULT as expected");
- else
- tst_res(TFAIL | TTERRNO, "uname() failed unexpectedly");
-
+ TST_EXP_FAIL(uname(bad_addr), EFAULT);
}
static void setup(void)
--
2.26.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH v2 03/10] syscalls/accept: Make use of TST_EXP_MACROS
2020-12-10 14:15 [LTP] [PATCH v2 00/10] Introduce TST_EXP_MACROS Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 01/10] lib: Introduce TST_EXP_* macros Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 02/10] syscalls/uname: Make use of TST_EXP_MACROS Cyril Hrubis
@ 2020-12-10 14:15 ` Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 04/10] syscalls/access: " Cyril Hrubis
` (8 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Cyril Hrubis @ 2020-12-10 14:15 UTC (permalink / raw)
To: ltp
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
testcases/kernel/syscalls/accept/accept01.c | 17 ++---------------
1 file changed, 2 insertions(+), 15 deletions(-)
diff --git a/testcases/kernel/syscalls/accept/accept01.c b/testcases/kernel/syscalls/accept/accept01.c
index 01d6db84c..8722f2c7f 100644
--- a/testcases/kernel/syscalls/accept/accept01.c
+++ b/testcases/kernel/syscalls/accept/accept01.c
@@ -97,21 +97,8 @@ void verify_accept(unsigned int nr)
{
struct test_case *tcase = &tcases[nr];
- TEST(accept(*tcase->fd, tcase->sockaddr, &tcase->salen));
-
- if (TST_RET != -1) {
- tst_res(TFAIL, "%s: returned %li, expected -1",
- tcase->desc, TST_RET);
- return;
- }
-
- if (TST_ERR != tcase->experrno) {
- tst_res(TFAIL | TTERRNO, "%s: expected errno %s, got ",
- tcase->desc, tst_strerrno(tcase->experrno));
- return;
- }
-
- tst_res(TPASS | TTERRNO, "%s successful", tcase->desc);
+ TST_EXP_FAIL(accept(*tcase->fd, tcase->sockaddr, &tcase->salen),
+ tcase->experrno, "%s", tcase->desc);
}
static struct tst_test test = {
--
2.26.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH v2 04/10] syscalls/access: Make use of TST_EXP_MACROS
2020-12-10 14:15 [LTP] [PATCH v2 00/10] Introduce TST_EXP_MACROS Cyril Hrubis
` (2 preceding siblings ...)
2020-12-10 14:15 ` [LTP] [PATCH v2 03/10] syscalls/accept: " Cyril Hrubis
@ 2020-12-10 14:15 ` Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 05/10] syscalls/bind: " Cyril Hrubis
` (7 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Cyril Hrubis @ 2020-12-10 14:15 UTC (permalink / raw)
To: ltp
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
testcases/kernel/syscalls/access/access01.c | 45 ++++-----------------
testcases/kernel/syscalls/access/access02.c | 8 ++--
testcases/kernel/syscalls/access/access03.c | 28 ++-----------
testcases/kernel/syscalls/access/access04.c | 17 +-------
4 files changed, 16 insertions(+), 82 deletions(-)
diff --git a/testcases/kernel/syscalls/access/access01.c b/testcases/kernel/syscalls/access/access01.c
index 1b73058d4..c9a076dfe 100644
--- a/testcases/kernel/syscalls/access/access01.c
+++ b/testcases/kernel/syscalls/access/access01.c
@@ -231,46 +231,15 @@ static struct tcase {
{DNAME_WX"/"FNAME_X, W_OK, "W_OK", EACCES, 1}
};
-static void verify_success(struct tcase *tc, const char *user)
-{
- if (TST_RET == -1) {
- tst_res(TFAIL | TTERRNO,
- "access(%s, %s) as %s failed unexpectedly",
- tc->fname, tc->name, user);
- return;
- }
-
- tst_res(TPASS, "access(%s, %s) as %s", tc->fname, tc->name, user);
-}
-
-static void verify_failure(struct tcase *tc, const char *user)
-{
- if (TST_RET != -1) {
- tst_res(TFAIL, "access(%s, %s) as %s succeded unexpectedly",
- tc->fname, tc->name, user);
- return;
- }
-
- if (TST_ERR != tc->exp_errno) {
- tst_res(TFAIL | TTERRNO,
- "access(%s, %s) as %s should fail with %s",
- tc->fname, tc->name, user,
- tst_strerrno(tc->exp_errno));
- return;
- }
-
- tst_res(TPASS | TTERRNO, "access(%s, %s) as %s",
- tc->fname, tc->name, user);
-}
-
static void access_test(struct tcase *tc, const char *user)
{
- TEST(access(tc->fname, tc->mode));
-
- if (tc->exp_errno)
- verify_failure(tc, user);
- else
- verify_success(tc, user);
+ if (tc->exp_errno) {
+ TST_EXP_FAIL(access(tc->fname, tc->mode), tc->exp_errno,
+ "access(%s, %s) as %s", tc->fname, tc->name, user);
+ } else {
+ TST_EXP_PASS(access(tc->fname, tc->mode),
+ "access(%s, %s) as %s", tc->fname, tc->name, user);
+ }
}
static void verify_access(unsigned int n)
diff --git a/testcases/kernel/syscalls/access/access02.c b/testcases/kernel/syscalls/access/access02.c
index db1d350bf..ff3e7b6f4 100644
--- a/testcases/kernel/syscalls/access/access02.c
+++ b/testcases/kernel/syscalls/access/access02.c
@@ -59,13 +59,11 @@ static void access_test(struct tcase *tc, const char *user)
struct stat stat_buf;
char command[64];
- TEST(access(tc->pathname, tc->mode));
+ TST_EXP_PASS(access(tc->pathname, tc->mode),
+ "access(%s, %s) as %s", tc->pathname, tc->name, user);
- if (TST_RET == -1) {
- tst_res(TFAIL | TTERRNO, "access(%s, %s) as %s failed",
- tc->pathname, tc->name, user);
+ if (!TST_PASS)
return;
- }
switch (tc->mode) {
case F_OK:
diff --git a/testcases/kernel/syscalls/access/access03.c b/testcases/kernel/syscalls/access/access03.c
index 612256c17..ae3f676b1 100644
--- a/testcases/kernel/syscalls/access/access03.c
+++ b/testcases/kernel/syscalls/access/access03.c
@@ -26,34 +26,13 @@ static struct tcase {
{(void *)-1, X_OK, "X_OK"},
};
-static void access_test(struct tcase *tc, const char *user)
-{
- TEST(access(tc->addr, tc->mode));
-
- if (TST_RET != -1) {
- tst_res(TFAIL, "access(%p, %s) as %s succeeded unexpectedly",
- tc->addr, tc->name, user);
- return;
- }
-
- if (TST_ERR != EFAULT) {
- tst_res(TFAIL | TTERRNO,
- "access(%p, %s) as %s should fail with EFAULT",
- tc->addr, tc->name, user);
- return;
- }
-
- tst_res(TPASS | TTERRNO, "access(%p, %s) as %s",
- tc->addr, tc->name, user);
-}
-
static void verify_access(unsigned int n)
{
struct tcase *tc = &tcases[n];
pid_t pid;
- /* test as root */
- access_test(tc, "root");
+ TST_EXP_FAIL(access(tc->addr, tc->mode), EFAULT,
+ "invalid address as root");
/* test as nobody */
pid = SAFE_FORK();
@@ -61,7 +40,8 @@ static void verify_access(unsigned int n)
SAFE_WAITPID(pid, NULL, 0);
} else {
SAFE_SETUID(uid);
- access_test(tc, "nobody");
+ TST_EXP_FAIL(access(tc->addr, tc->mode), EFAULT,
+ "invalid address as nobody");
}
}
diff --git a/testcases/kernel/syscalls/access/access04.c b/testcases/kernel/syscalls/access/access04.c
index 328be1b73..2d6dd70e8 100644
--- a/testcases/kernel/syscalls/access/access04.c
+++ b/testcases/kernel/syscalls/access/access04.c
@@ -58,21 +58,8 @@ static struct tcase {
static void access_test(struct tcase *tc, const char *user)
{
- TEST(access(tc->pathname, tc->mode));
-
- if (TST_RET != -1) {
- tst_res(TFAIL, "access as %s succeeded unexpectedly", user);
- return;
- }
-
- if (tc->exp_errno != TST_ERR) {
- tst_res(TFAIL | TTERRNO,
- "access as %s should fail with %s",
- user, tst_strerrno(tc->exp_errno));
- return;
- }
-
- tst_res(TPASS | TTERRNO, "access as %s failed expectedly", user);
+ TST_EXP_FAIL(access(tc->pathname, tc->mode), tc->exp_errno,
+ "access as %s", user);
}
static void verify_access(unsigned int n)
--
2.26.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH v2 05/10] syscalls/bind: Make use of TST_EXP_MACROS
2020-12-10 14:15 [LTP] [PATCH v2 00/10] Introduce TST_EXP_MACROS Cyril Hrubis
` (3 preceding siblings ...)
2020-12-10 14:15 ` [LTP] [PATCH v2 04/10] syscalls/access: " Cyril Hrubis
@ 2020-12-10 14:15 ` Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 06/10] syscalls/brk01: " Cyril Hrubis
` (6 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Cyril Hrubis @ 2020-12-10 14:15 UTC (permalink / raw)
To: ltp
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
testcases/kernel/syscalls/bind/bind01.c | 12 +++++-------
testcases/kernel/syscalls/bind/bind02.c | 11 ++---------
testcases/kernel/syscalls/bind/bind03.c | 26 ++++---------------------
testcases/kernel/syscalls/bind/bind04.c | 5 ++---
testcases/kernel/syscalls/bind/bind05.c | 5 ++---
5 files changed, 15 insertions(+), 44 deletions(-)
diff --git a/testcases/kernel/syscalls/bind/bind01.c b/testcases/kernel/syscalls/bind/bind01.c
index 2054996ac..758d12863 100644
--- a/testcases/kernel/syscalls/bind/bind01.c
+++ b/testcases/kernel/syscalls/bind/bind01.c
@@ -47,14 +47,12 @@ void verify_bind(unsigned int nr)
{
struct test_case *tcase = &tcases[nr];
- TEST(bind(*tcase->socket_fd, tcase->sockaddr, tcase->salen));
- if (TST_RET != tcase->retval && TST_ERR != tcase->experrno) {
- tst_res(TFAIL, "%s ; returned"
- " %ld (expected %d), errno %d (expected"
- " %d)", tcase->desc, TST_RET, tcase->retval,
- TST_ERR, tcase->experrno);
+ if (tcase->experrno) {
+ TST_EXP_FAIL(bind(*tcase->socket_fd, tcase->sockaddr, tcase->salen),
+ tcase->experrno, "%s", tcase->desc);
} else {
- tst_res(TPASS, "%s successful", tcase->desc);
+ TST_EXP_PASS(bind(*tcase->socket_fd, tcase->sockaddr, tcase->salen),
+ "%s", tcase->desc);
}
}
diff --git a/testcases/kernel/syscalls/bind/bind02.c b/testcases/kernel/syscalls/bind/bind02.c
index 65944cbe3..a997157d6 100644
--- a/testcases/kernel/syscalls/bind/bind02.c
+++ b/testcases/kernel/syscalls/bind/bind02.c
@@ -36,16 +36,9 @@ static void run(void)
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(TCP_PRIVILEGED_PORT);
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
- TEST(bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)));
+ TST_EXP_FAIL(bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)),
+ EACCES, "bind()");
SAFE_CLOSE(sockfd);
-
- if (TST_RET != -1) {
- tst_res(TFAIL, "bind() returned %li, expected -1", TST_RET);
- } else if (TST_ERR == EACCES) {
- tst_res(TPASS | TTERRNO, "bind() failed as expected");
- } else {
- tst_res(TFAIL | TTERRNO, "Unexpected error");
- }
}
static void setup(void)
diff --git a/testcases/kernel/syscalls/bind/bind03.c b/testcases/kernel/syscalls/bind/bind03.c
index dda5ca374..c39e8f197 100644
--- a/testcases/kernel/syscalls/bind/bind03.c
+++ b/testcases/kernel/syscalls/bind/bind03.c
@@ -51,17 +51,8 @@ void run(void)
* Once a STREAM UNIX domain socket has been bound, it can't be
* rebound.
*/
- if (bind(sock1, (struct sockaddr *)&sun2, sizeof(sun2)) == 0) {
- tst_res(TFAIL, "re-binding of socket succeeded");
- return;
- }
-
- if (errno != EINVAL) {
- tst_res(TFAIL | TERRNO, "expected EINVAL");
- return;
- }
-
- tst_res(TPASS, "bind() failed with EINVAL as expected");
+ TST_EXP_FAIL(bind(sock1, (struct sockaddr *)&sun2, sizeof(sun2)),
+ EINVAL, "re-bind() socket");
sock2 = SAFE_SOCKET(PF_UNIX, SOCK_STREAM, 0);
@@ -69,17 +60,8 @@ void run(void)
* Since a socket is already bound to the pathname, it can't be bound
* to a second socket. Expected error is EADDRINUSE.
*/
- if (bind(sock2, (struct sockaddr *)&sun1, sizeof(sun1)) == 0) {
- tst_res(TFAIL, "bind() succeeded with already bound pathname!");
- return;
- }
-
- if (errno != EADDRINUSE) {
- tst_res(TFAIL | TERRNO, "expected to fail with EADDRINUSE");
- return;
- }
-
- tst_res(TPASS, "bind() failed with EADDRINUSE as expected");
+ TST_EXP_FAIL(bind(sock2, (struct sockaddr *)&sun1, sizeof(sun1)),
+ EADDRINUSE, "bind() with bound pathname");
}
static void cleanup(void)
diff --git a/testcases/kernel/syscalls/bind/bind04.c b/testcases/kernel/syscalls/bind/bind04.c
index 51f19c6cd..49e784ccd 100644
--- a/testcases/kernel/syscalls/bind/bind04.c
+++ b/testcases/kernel/syscalls/bind/bind04.c
@@ -118,10 +118,9 @@ static void test_bind(unsigned int n)
listen_sock = SAFE_SOCKET(tc->address->sa_family, tc->type,
tc->protocol);
- TEST(bind(listen_sock, tc->address, tc->addrlen));
+ TST_EXP_PASS(bind(listen_sock, tc->address, tc->addrlen), "bind()");
- if (TST_RET) {
- tst_res(TFAIL | TERRNO, "bind() failed");
+ if (!TST_PASS) {
SAFE_CLOSE(listen_sock);
return;
}
diff --git a/testcases/kernel/syscalls/bind/bind05.c b/testcases/kernel/syscalls/bind/bind05.c
index 16c9c711d..3b384cf1b 100644
--- a/testcases/kernel/syscalls/bind/bind05.c
+++ b/testcases/kernel/syscalls/bind/bind05.c
@@ -131,10 +131,9 @@ static void test_bind(unsigned int n)
tst_res(TINFO, "Testing %s", tc->description);
sock = SAFE_SOCKET(tc->address->sa_family, tc->type, tc->protocol);
- TEST(bind(sock, tc->address, tc->addrlen));
+ TST_EXP_PASS(bind(sock, tc->address, tc->addrlen), "bind()");
- if (TST_RET) {
- tst_res(TFAIL | TERRNO, "bind() failed");
+ if (!TST_PASS) {
SAFE_CLOSE(sock);
return;
}
--
2.26.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH v2 06/10] syscalls/brk01: Make use of TST_EXP_MACROS
2020-12-10 14:15 [LTP] [PATCH v2 00/10] Introduce TST_EXP_MACROS Cyril Hrubis
` (4 preceding siblings ...)
2020-12-10 14:15 ` [LTP] [PATCH v2 05/10] syscalls/bind: " Cyril Hrubis
@ 2020-12-10 14:15 ` Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 07/10] syscalls/cacheflush: " Cyril Hrubis
` (5 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Cyril Hrubis @ 2020-12-10 14:15 UTC (permalink / raw)
To: ltp
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
testcases/kernel/syscalls/brk/brk01.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/testcases/kernel/syscalls/brk/brk01.c b/testcases/kernel/syscalls/brk/brk01.c
index c50791d40..3f8606375 100644
--- a/testcases/kernel/syscalls/brk/brk01.c
+++ b/testcases/kernel/syscalls/brk/brk01.c
@@ -31,12 +31,7 @@ void verify_brk(void)
break;
}
- TEST(brk((void *)new_brk));
-
- if (TST_RET == -1) {
- tst_res(TFAIL | TERRNO, "brk() failed");
- return;
- }
+ TST_EXP_PASS(brk((void *)new_brk), "brk()");
cur_brk = (uintptr_t)sbrk(0);
@@ -51,8 +46,6 @@ void verify_brk(void)
if (i % 3 == 0)
*((char *)cur_brk) = 0;
}
-
- tst_res(TPASS, "brk() works fine");
}
static struct tst_test test = {
--
2.26.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH v2 07/10] syscalls/cacheflush: Make use of TST_EXP_MACROS
2020-12-10 14:15 [LTP] [PATCH v2 00/10] Introduce TST_EXP_MACROS Cyril Hrubis
` (5 preceding siblings ...)
2020-12-10 14:15 ` [LTP] [PATCH v2 06/10] syscalls/brk01: " Cyril Hrubis
@ 2020-12-10 14:15 ` Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 08/10] syscalls/capget: Make use of TEST_MACROS Cyril Hrubis
` (4 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Cyril Hrubis @ 2020-12-10 14:15 UTC (permalink / raw)
To: ltp
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
testcases/kernel/syscalls/cacheflush/cacheflush01.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/testcases/kernel/syscalls/cacheflush/cacheflush01.c b/testcases/kernel/syscalls/cacheflush/cacheflush01.c
index 6ad8b953a..3daaff624 100644
--- a/testcases/kernel/syscalls/cacheflush/cacheflush01.c
+++ b/testcases/kernel/syscalls/cacheflush/cacheflush01.c
@@ -45,12 +45,8 @@ static void test_cacheflush(unsigned int i)
{
struct test_case_t *tc = &test_cases[i];
- TEST(tst_syscall(__NR_cacheflush, addr, getpagesize(), tc->cache));
- if (TST_RET == 0) {
- tst_res(TPASS, "%s passed", tc->desc);
- } else {
- tst_res(TFAIL | TTERRNO, "%s failed", tc->desc);
- }
+ TST_EXP_PASS(tst_syscall(__NR_cacheflush, addr, getpagesize(), tc->cache),
+ "%s", tc->desc);
}
static struct tst_test test = {
--
2.26.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH v2 08/10] syscalls/capget: Make use of TEST_MACROS
2020-12-10 14:15 [LTP] [PATCH v2 00/10] Introduce TST_EXP_MACROS Cyril Hrubis
` (6 preceding siblings ...)
2020-12-10 14:15 ` [LTP] [PATCH v2 07/10] syscalls/cacheflush: " Cyril Hrubis
@ 2020-12-10 14:15 ` Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 09/10] syscalls/capset: Make use of TST_EXP_MACROS Cyril Hrubis
` (3 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Cyril Hrubis @ 2020-12-10 14:15 UTC (permalink / raw)
To: ltp
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
testcases/kernel/syscalls/capget/capget01.c | 17 +++++---------
testcases/kernel/syscalls/capget/capget02.c | 26 +++++++--------------
2 files changed, 14 insertions(+), 29 deletions(-)
diff --git a/testcases/kernel/syscalls/capget/capget01.c b/testcases/kernel/syscalls/capget/capget01.c
index f3767594b..6c17a7c7c 100644
--- a/testcases/kernel/syscalls/capget/capget01.c
+++ b/testcases/kernel/syscalls/capget/capget01.c
@@ -20,25 +20,20 @@ static struct tcase {
int version;
char *message;
} tcases[] = {
- {0x19980330, "Test on LINUX_CAPABILITY_VERSION_1"},
- {0x20071026, "Test on LINUX_CAPABILITY_VERSION_2"},
- {0x20080522, "Test on LINUX_CAPABILITY_VERSION_3"},
+ {0x19980330, "LINUX_CAPABILITY_VERSION_1"},
+ {0x20071026, "LINUX_CAPABILITY_VERSION_2"},
+ {0x20080522, "LINUX_CAPABILITY_VERSION_3"},
};
static void verify_capget(unsigned int n)
{
struct tcase *tc = &tcases[n];
- tst_res(TINFO, "%s", tc->message);
-
hdr->version = tc->version;
hdr->pid = pid;
- TEST(tst_syscall(__NR_capget, hdr, data));
- if (TST_RET == 0)
- tst_res(TPASS, "capget() returned %ld", TST_RET);
- else
- tst_res(TFAIL | TTERRNO, "Test Failed, capget() returned %ld",
- TST_RET);
+
+ TST_EXP_PASS(tst_syscall(__NR_capget, hdr, data),
+ "capget() with %s", tc->message);
if (data[0].effective & 1 << CAP_NET_RAW)
tst_res(TFAIL, "capget() gets CAP_NET_RAW unexpectedly in pE");
diff --git a/testcases/kernel/syscalls/capget/capget02.c b/testcases/kernel/syscalls/capget/capget02.c
index e770ea0a9..f4a2b471c 100644
--- a/testcases/kernel/syscalls/capget/capget02.c
+++ b/testcases/kernel/syscalls/capget/capget02.c
@@ -31,11 +31,11 @@ static struct tcase {
int flag;
char *message;
} tcases[] = {
- {0x20080522, 0, EFAULT, 1, "Test bad address header"},
- {0x20080522, 0, EFAULT, 2, "Test bad address data"},
- {0, 0, EINVAL, 0, "Test bad version"},
- {0x20080522, -1, EINVAL, 0, "Test bad pid"},
- {0x20080522, 1, ESRCH, 0, "Test unused pid"},
+ {0x20080522, 0, EFAULT, 1, "bad address header"},
+ {0x20080522, 0, EFAULT, 2, "bad address data"},
+ {0, 0, EINVAL, 0, "bad version"},
+ {0x20080522, -1, EINVAL, 0, "bad pid"},
+ {0x20080522, 1, ESRCH, 0, "unused pid"},
};
static void verify_capget(unsigned int n)
@@ -48,25 +48,15 @@ static void verify_capget(unsigned int n)
else
header->pid = tc->pid;
- tst_res(TINFO, "%s", tc->message);
-
/*
* header must not be NULL. data may be NULL only when the user is
* trying to determine the preferred capability version format
* supported by the kernel. So use tst_get_bad_addr() to get
* this error.
*/
- TEST(tst_syscall(__NR_capget, tc->flag - 1 ? header : NULL,
- tc->flag - 2 ? data : bad_data));
- if (TST_RET == 0) {
- tst_res(TFAIL, "capget() succeed unexpectedly");
- return;
- }
- if (TST_ERR == tc->exp_err)
- tst_res(TPASS | TTERRNO, "capget() failed as expected");
- else
- tst_res(TFAIL | TTERRNO, "capget() expected %s got ",
- tst_strerrno(tc->exp_err));
+ TST_EXP_FAIL(tst_syscall(__NR_capget, tc->flag - 1 ? header : NULL,
+ tc->flag - 2 ? data : bad_data),
+ tc->exp_err, "capget() with %s", tc->message);
/*
* When an unsupported version value is specified, it will
--
2.26.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH v2 09/10] syscalls/capset: Make use of TST_EXP_MACROS
2020-12-10 14:15 [LTP] [PATCH v2 00/10] Introduce TST_EXP_MACROS Cyril Hrubis
` (7 preceding siblings ...)
2020-12-10 14:15 ` [LTP] [PATCH v2 08/10] syscalls/capget: Make use of TEST_MACROS Cyril Hrubis
@ 2020-12-10 14:15 ` Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 10/10] syscalls/open: " Cyril Hrubis
` (2 subsequent siblings)
11 siblings, 0 replies; 15+ messages in thread
From: Cyril Hrubis @ 2020-12-10 14:15 UTC (permalink / raw)
To: ltp
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
testcases/kernel/syscalls/capset/capset01.c | 14 ++++-------
testcases/kernel/syscalls/capset/capset02.c | 28 +++++++--------------
testcases/kernel/syscalls/capset/capset03.c | 10 +-------
testcases/kernel/syscalls/capset/capset04.c | 13 +++-------
4 files changed, 18 insertions(+), 47 deletions(-)
diff --git a/testcases/kernel/syscalls/capset/capset01.c b/testcases/kernel/syscalls/capset/capset01.c
index f8540539d..6b064517a 100644
--- a/testcases/kernel/syscalls/capset/capset01.c
+++ b/testcases/kernel/syscalls/capset/capset01.c
@@ -20,16 +20,15 @@ static struct tcase {
int version;
char *message;
} tcases[] = {
- {0x19980330, "Test on LINUX_CAPABILITY_VERSION_1"},
- {0x20071026, "Test on LINUX_CAPABILITY_VERSION_2"},
- {0x20080522, "Test on LINUX_CAPABILITY_VERSION_3"},
+ {0x19980330, "LINUX_CAPABILITY_VERSION_1"},
+ {0x20071026, "LINUX_CAPABILITY_VERSION_2"},
+ {0x20080522, "LINUX_CAPABILITY_VERSION_3"},
};
static void verify_capset(unsigned int n)
{
struct tcase *tc = &tcases[n];
- tst_res(TINFO, "%s", tc->message);
header->version = tc->version;
header->pid = pid;
@@ -38,11 +37,8 @@ static void verify_capset(unsigned int n)
return;
}
- TEST(tst_syscall(__NR_capset, header, data));
- if (TST_RET == 0)
- tst_res(TPASS, "capset() returned %ld", TST_RET);
- else
- tst_res(TFAIL | TTERRNO, "Test Failed, capset() returned %ld", TST_RET);
+ TST_EXP_PASS(tst_syscall(__NR_capset, header, data),
+ "capset() with %s", tc->message);
}
static void setup(void)
diff --git a/testcases/kernel/syscalls/capset/capset02.c b/testcases/kernel/syscalls/capset/capset02.c
index a6c4f29a0..5173be09b 100644
--- a/testcases/kernel/syscalls/capset/capset02.c
+++ b/testcases/kernel/syscalls/capset/capset02.c
@@ -43,12 +43,12 @@ static struct tcase {
int flag;
char *message;
} tcases[] = {
- {0x20080522, 0, CAP1, CAP1, CAP1, EFAULT, 1, "Test bad address header"},
- {0x20080522, 0, CAP1, CAP1, CAP1, EFAULT, 2, "Test bad address data"},
- {0, 0, CAP1, CAP1, CAP1, EINVAL, 0, "Test bad version"},
- {0x20080522, 0, CAP2, CAP1, CAP1, EPERM, 0, "Test bad value data(when pE is not in pP)"},
- {0x20080522, 0, CAP1, CAP2, CAP1, EPERM, 0, "Test bad value data(when pP is not in old pP)"},
- {0x20080522, 0, CAP1, CAP1, CAP2, EPERM, 0, "Test bad value data(when pI is not in bounding set or old pI)"},
+ {0x20080522, 0, CAP1, CAP1, CAP1, EFAULT, 1, "bad address header"},
+ {0x20080522, 0, CAP1, CAP1, CAP1, EFAULT, 2, "bad address data"},
+ {0, 0, CAP1, CAP1, CAP1, EINVAL, 0, "bad version"},
+ {0x20080522, 0, CAP2, CAP1, CAP1, EPERM, 0, "bad value data(when pE is not in pP)"},
+ {0x20080522, 0, CAP1, CAP2, CAP1, EPERM, 0, "bad value data(when pP is not in old pP)"},
+ {0x20080522, 0, CAP1, CAP1, CAP2, EPERM, 0, "bad value data(when pI is not in bounding set or old pI)"},
};
static void verify_capset(unsigned int n)
@@ -62,19 +62,9 @@ static void verify_capset(unsigned int n)
data->permitted = tc->permitted;
data->inheritable = tc->inheritable;
- tst_res(TINFO, "%s", tc->message);
-
- TEST(tst_syscall(__NR_capset, tc->flag - 1 ? header : bad_addr,
- tc->flag - 2 ? data : bad_addr));
- if (TST_RET == 0) {
- tst_res(TFAIL, "capset() succeed unexpectedly");
- return;
- }
- if (TST_ERR == tc->exp_err)
- tst_res(TPASS | TTERRNO, "capset() failed as expected");
- else
- tst_res(TFAIL | TTERRNO, "capset() expected %s got ",
- tst_strerrno(tc->exp_err));
+ TST_EXP_FAIL(tst_syscall(__NR_capset, tc->flag - 1 ? header : bad_addr,
+ tc->flag - 2 ? data : bad_addr),
+ tc->exp_err, "capset() with %s", tc->message);
/*
* When an unsupported version value is specified, it will
* return the kernel preferred value of _LINUX_CAPABILITY_VERSION_?.
diff --git a/testcases/kernel/syscalls/capset/capset03.c b/testcases/kernel/syscalls/capset/capset03.c
index d5754753d..074ab1f50 100644
--- a/testcases/kernel/syscalls/capset/capset03.c
+++ b/testcases/kernel/syscalls/capset/capset03.c
@@ -23,15 +23,7 @@ static void verify_capset(void)
{
tst_res(TINFO, "Test bad value data(when pI is not old pP or old pI without CAP_SETPCAP)");
data[0].inheritable = CAP2;
- TEST(tst_syscall(__NR_capset, header, data));
- if (TST_RET == 0) {
- tst_res(TFAIL, "capset succeed unexpectedly");
- return;
- }
- if (TST_ERR == EPERM)
- tst_res(TPASS | TTERRNO, "capset() failed as expected");
- else
- tst_res(TFAIL | TTERRNO, "capset expected EPERM, bug got");
+ TST_EXP_FAIL(tst_syscall(__NR_capset, header, data), EPERM, "capset()");
}
static void setup(void)
diff --git a/testcases/kernel/syscalls/capset/capset04.c b/testcases/kernel/syscalls/capset/capset04.c
index 81ad7a35f..f929be555 100644
--- a/testcases/kernel/syscalls/capset/capset04.c
+++ b/testcases/kernel/syscalls/capset/capset04.c
@@ -24,18 +24,11 @@ static void verify_capset(void)
if (!child_pid)
pause();
- header->pid = child_pid;
+ tst_res(TINFO, "Test capset() for a different process");
- TEST(tst_syscall(__NR_capset, header, data));
- if (TST_RET == 0) {
- tst_res(TFAIL, "capset succeed unexpectedly");
- return;
- }
+ header->pid = child_pid;
- if (TST_ERR == EPERM)
- tst_res(TPASS, "capset can't modify other process capabilities");
- else
- tst_res(TFAIL | TTERRNO, "capset expected EPERM, bug got");
+ TST_EXP_FAIL(tst_syscall(__NR_capset, header, data), EPERM, "capset()");
SAFE_KILL(child_pid, SIGTERM);
SAFE_WAIT(NULL);
--
2.26.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH v2 10/10] syscalls/open: Make use of TST_EXP_MACROS
2020-12-10 14:15 [LTP] [PATCH v2 00/10] Introduce TST_EXP_MACROS Cyril Hrubis
` (8 preceding siblings ...)
2020-12-10 14:15 ` [LTP] [PATCH v2 09/10] syscalls/capset: Make use of TST_EXP_MACROS Cyril Hrubis
@ 2020-12-10 14:15 ` Cyril Hrubis
2020-12-11 10:45 ` [LTP] [PATCH v2 00/10] Introduce TST_EXP_MACROS Li Wang
2020-12-11 12:45 ` Petr Vorel
11 siblings, 0 replies; 15+ messages in thread
From: Cyril Hrubis @ 2020-12-10 14:15 UTC (permalink / raw)
To: ltp
In the newlib testcases at least.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
testcases/kernel/syscalls/open/open01.c | 11 ++++-------
testcases/kernel/syscalls/open/open02.c | 25 ++++++-------------------
testcases/kernel/syscalls/open/open11.c | 22 ++++++++++------------
3 files changed, 20 insertions(+), 38 deletions(-)
diff --git a/testcases/kernel/syscalls/open/open01.c b/testcases/kernel/syscalls/open/open01.c
index c689a4b9b..1172f832b 100644
--- a/testcases/kernel/syscalls/open/open01.c
+++ b/testcases/kernel/syscalls/open/open01.c
@@ -36,8 +36,8 @@ static struct tcase {
unsigned short tst_bit;
char *desc;
} tcases[] = {
- {TEST_FILE, O_RDWR | O_CREAT, 01444, S_ISVTX, "Sticky bit"},
- {TEST_DIR, O_DIRECTORY, 0, S_IFDIR, "Directory bit"}
+ {TEST_FILE, O_RDWR | O_CREAT, 01444, S_ISVTX, "sticky bit"},
+ {TEST_DIR, O_DIRECTORY, 0, S_IFDIR, "sirectory bit"}
};
static void verify_open(unsigned int n)
@@ -45,12 +45,9 @@ static void verify_open(unsigned int n)
struct tcase *tc = &tcases[n];
struct stat buf;
- TEST(open(tc->filename, tc->flag, tc->mode));
+ TST_EXP_FD(open(tc->filename, tc->flag, tc->mode),
+ "open() with %s", tc->desc);
fd = TST_RET;
- if (fd == -1) {
- tst_res(TFAIL, "Cannot open a file");
- return;
- }
SAFE_FSTAT(fd, &buf);
if (!(buf.st_mode & tc->tst_bit))
diff --git a/testcases/kernel/syscalls/open/open02.c b/testcases/kernel/syscalls/open/open02.c
index 7195b1b6c..ca9839c2d 100644
--- a/testcases/kernel/syscalls/open/open02.c
+++ b/testcases/kernel/syscalls/open/open02.c
@@ -25,12 +25,13 @@
#define TEST_FILE2 "test_file2"
static struct tcase {
- char *filename;
+ const char *filename;
int flag;
int exp_errno;
+ const char *desc;
} tcases[] = {
- {TEST_FILE, O_RDWR, ENOENT},
- {TEST_FILE2, O_RDONLY | O_NOATIME, EPERM},
+ {TEST_FILE, O_RDWR, ENOENT, "new file without O_CREAT"},
+ {TEST_FILE2, O_RDONLY | O_NOATIME, EPERM, "unpriviledget O_RDONLY | O_NOATIME"},
};
void setup(void)
@@ -48,22 +49,8 @@ static void verify_open(unsigned int n)
{
struct tcase *tc = &tcases[n];
- TEST(open(tc->filename, tc->flag, 0444));
-
- if (TST_RET != -1) {
- tst_res(TFAIL, "open(%s) succeeded unexpectedly",
- tc->filename);
- return;
- }
-
- if (tc->exp_errno != TST_ERR) {
- tst_res(TFAIL | TTERRNO,
- "open() should fail with %s",
- tst_strerrno(tc->exp_errno));
- return;
- }
-
- tst_res(TPASS | TTERRNO, "open() failed as expected");
+ TST_EXP_FAIL(open(tc->filename, tc->flag, 0444),
+ tc->exp_errno, "open() %s", tc->desc);
}
void cleanup(void)
diff --git a/testcases/kernel/syscalls/open/open11.c b/testcases/kernel/syscalls/open/open11.c
index cfd04fdcd..ded384fa8 100644
--- a/testcases/kernel/syscalls/open/open11.c
+++ b/testcases/kernel/syscalls/open/open11.c
@@ -277,21 +277,19 @@ static struct test_case {
static void verify_open(unsigned int n)
{
- int fd;
-
- TEST(open(tc[n].path, tc[n].flags, tc[n].mode));
- fd = TST_RET;
-
- if (fd > 0)
- SAFE_CLOSE(fd);
-
- if (tc[n].err == -1 || TST_ERR == tc[n].err) {
+ if (tc[n].err > 0) {
+ TST_EXP_FAIL(open(tc[n].path, tc[n].flags, tc[n].mode),
+ tc[n].err, "%s", tc[n].desc);
+ } else if (tc[n].err == 0) {
+ TST_EXP_FD(open(tc[n].path, tc[n].flags, tc[n].mode),
+ "%s", tc[n].desc);
+ } else {
+ TEST(open(tc[n].path, tc[n].flags, tc[n].mode));
tst_res(TPASS, "%s", tc[n].desc);
- return;
}
- tst_res(TFAIL | TTERRNO, "%s - expected %s",
- tc[n].desc, tst_strerrno(tc[n].err));
+ if (TST_RET > 0)
+ SAFE_CLOSE(TST_RET);
}
static void setup(void)
--
2.26.2
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH v2 00/10] Introduce TST_EXP_MACROS
2020-12-10 14:15 [LTP] [PATCH v2 00/10] Introduce TST_EXP_MACROS Cyril Hrubis
` (9 preceding siblings ...)
2020-12-10 14:15 ` [LTP] [PATCH v2 10/10] syscalls/open: " Cyril Hrubis
@ 2020-12-11 10:45 ` Li Wang
2020-12-11 13:34 ` Cyril Hrubis
2020-12-11 12:45 ` Petr Vorel
11 siblings, 1 reply; 15+ messages in thread
From: Li Wang @ 2020-12-11 10:45 UTC (permalink / raw)
To: ltp
On Thu, Dec 10, 2020 at 10:15 PM Cyril Hrubis <chrubis@suse.cz> wrote:
> This patchset adds TST_EXP_MACROS() implementation.
>
> These macros are intended to simplify and unify syscall unit tests.
>
> This patchset converts a few testcases to use TST_EXP_MACROS() it's
> intenteded to serve as an example since there is a lot of testcases that
> could use them as well.
>
> Also the documentation for these macros is ommited at this point, I will
> add it in a case that we agree to include them in the test library.
>
>
> Changes in v2:
>
> - renamed the macros so that it's more clear that they do
> - added documentation to test-writing-guidelines
> - minor fixed in the converted testcases
>
One more point, we might have to handle the unsupported syscall
issue in TST_EXP_*. Otherwise, we can NOT make use of these
macros in tests like madvise01.c. But, I agree to merge patchset
as V2, and solve that in follow-up changes.
For the series:
Acked-by: Li Wang <liwang@redhat.com>
--
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20201211/2c269794/attachment-0001.htm>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH v2 00/10] Introduce TST_EXP_MACROS
2020-12-10 14:15 [LTP] [PATCH v2 00/10] Introduce TST_EXP_MACROS Cyril Hrubis
` (10 preceding siblings ...)
2020-12-11 10:45 ` [LTP] [PATCH v2 00/10] Introduce TST_EXP_MACROS Li Wang
@ 2020-12-11 12:45 ` Petr Vorel
2020-12-11 13:34 ` Cyril Hrubis
11 siblings, 1 reply; 15+ messages in thread
From: Petr Vorel @ 2020-12-11 12:45 UTC (permalink / raw)
To: ltp
Hi Cyril,
Very nice helpers!
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Another tip for future: many tests would benefit for handling some errno as
TCONF (e.g. TST_EXP_{FAIL,PASS}_TCONF(), but it's be nice if more than one could
be passed).
Kind regards,
Petr
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH v2 00/10] Introduce TST_EXP_MACROS
2020-12-11 10:45 ` [LTP] [PATCH v2 00/10] Introduce TST_EXP_MACROS Li Wang
@ 2020-12-11 13:34 ` Cyril Hrubis
0 siblings, 0 replies; 15+ messages in thread
From: Cyril Hrubis @ 2020-12-11 13:34 UTC (permalink / raw)
To: ltp
Hi!
> One more point, we might have to handle the unsupported syscall
> issue in TST_EXP_*. Otherwise, we can NOT make use of these
> macros in tests like madvise01.c. But, I agree to merge patchset
> as V2, and solve that in follow-up changes.
We should add versions that will take zero terminated array of errnos
that should end up in TCONF later on, but as said I want to convert the
easy cases for now.
> For the series:
> Acked-by: Li Wang <liwang@redhat.com>
Pushed, thanks.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH v2 00/10] Introduce TST_EXP_MACROS
2020-12-11 12:45 ` Petr Vorel
@ 2020-12-11 13:34 ` Cyril Hrubis
0 siblings, 0 replies; 15+ messages in thread
From: Cyril Hrubis @ 2020-12-11 13:34 UTC (permalink / raw)
To: ltp
Hi!
> Another tip for future: many tests would benefit for handling some errno as
> TCONF (e.g. TST_EXP_{FAIL,PASS}_TCONF(), but it's be nice if more than one could
> be passed).
See the answer to Li.
Also thanks for the review.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2020-12-11 13:34 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-10 14:15 [LTP] [PATCH v2 00/10] Introduce TST_EXP_MACROS Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 01/10] lib: Introduce TST_EXP_* macros Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 02/10] syscalls/uname: Make use of TST_EXP_MACROS Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 03/10] syscalls/accept: " Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 04/10] syscalls/access: " Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 05/10] syscalls/bind: " Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 06/10] syscalls/brk01: " Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 07/10] syscalls/cacheflush: " Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 08/10] syscalls/capget: Make use of TEST_MACROS Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 09/10] syscalls/capset: Make use of TST_EXP_MACROS Cyril Hrubis
2020-12-10 14:15 ` [LTP] [PATCH v2 10/10] syscalls/open: " Cyril Hrubis
2020-12-11 10:45 ` [LTP] [PATCH v2 00/10] Introduce TST_EXP_MACROS Li Wang
2020-12-11 13:34 ` Cyril Hrubis
2020-12-11 12:45 ` Petr Vorel
2020-12-11 13:34 ` Cyril Hrubis
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.