From patchwork Thu Dec 10 14:15:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1414234 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CsGCT32Dvz9sWy for ; Fri, 11 Dec 2020 01:15:16 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 4723F3C6228 for ; Thu, 10 Dec 2020 15:15:14 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) by picard.linux.it (Postfix) with ESMTP id 5A3FD3C6228 for ; Thu, 10 Dec 2020 15:14:54 +0100 (CET) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 810111A009B1 for ; Thu, 10 Dec 2020 15:14:53 +0100 (CET) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 09D0DAE87 for ; Thu, 10 Dec 2020 14:14:53 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 10 Dec 2020 15:15:39 +0100 Message-Id: <20201210141548.10982-2-chrubis@suse.cz> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201210141548.10982-1-chrubis@suse.cz> References: <20201210141548.10982-1-chrubis@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v2 01/10] lib: Introduce TST_EXP_* macros X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" In order to simplify common return value checks. Signed-off-by: Cyril Hrubis --- 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 + */ + +#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 + */ + +/* + * 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 + */ + +/* + * 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 + */ + +/* + * 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); From patchwork Thu Dec 10 14:15:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1414232 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CsGCP0PRkz9sWy for ; Fri, 11 Dec 2020 01:15:05 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id CAF983C7148 for ; Thu, 10 Dec 2020 15:14:55 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) by picard.linux.it (Postfix) with ESMTP id 1CB4D3C4B5F for ; Thu, 10 Dec 2020 15:14:54 +0100 (CET) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id D67341000C37 for ; Thu, 10 Dec 2020 15:14:53 +0100 (CET) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 77FC4AE95 for ; Thu, 10 Dec 2020 14:14:53 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 10 Dec 2020 15:15:40 +0100 Message-Id: <20201210141548.10982-3-chrubis@suse.cz> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201210141548.10982-1-chrubis@suse.cz> References: <20201210141548.10982-1-chrubis@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH v2 02/10] syscalls/uname: Make use of TST_EXP_MACROS X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Cyril Hrubis --- 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) From patchwork Thu Dec 10 14:15:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1414235 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CsGCd5Jhvz9sX4 for ; Fri, 11 Dec 2020 01:15:25 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id DE6243C788F for ; Thu, 10 Dec 2020 15:15:22 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) by picard.linux.it (Postfix) with ESMTP id 8D0453C4B5F for ; Thu, 10 Dec 2020 15:14:54 +0100 (CET) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 44EE5200C89 for ; Thu, 10 Dec 2020 15:14:54 +0100 (CET) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D96EEAE2E for ; Thu, 10 Dec 2020 14:14:53 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 10 Dec 2020 15:15:41 +0100 Message-Id: <20201210141548.10982-4-chrubis@suse.cz> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201210141548.10982-1-chrubis@suse.cz> References: <20201210141548.10982-1-chrubis@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v2 03/10] syscalls/accept: Make use of TST_EXP_MACROS X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Cyril Hrubis --- 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 = { From patchwork Thu Dec 10 14:15:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1414236 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CsGCq74Gcz9sWL for ; Fri, 11 Dec 2020 01:15:35 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 0AD3E3C75EB for ; Thu, 10 Dec 2020 15:15:33 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) by picard.linux.it (Postfix) with ESMTP id 1042B3C4B5F for ; Thu, 10 Dec 2020 15:14:55 +0100 (CET) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 9F1541A009A5 for ; Thu, 10 Dec 2020 15:14:54 +0100 (CET) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 48B19AE87 for ; Thu, 10 Dec 2020 14:14:54 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 10 Dec 2020 15:15:42 +0100 Message-Id: <20201210141548.10982-5-chrubis@suse.cz> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201210141548.10982-1-chrubis@suse.cz> References: <20201210141548.10982-1-chrubis@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v2 04/10] syscalls/access: Make use of TST_EXP_MACROS X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Cyril Hrubis --- 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) From patchwork Thu Dec 10 14:15:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1414237 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CsGD14ckVz9sWL for ; Fri, 11 Dec 2020 01:15:45 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B11823C7FCF for ; Thu, 10 Dec 2020 15:15:41 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) by picard.linux.it (Postfix) with ESMTP id 91E1D3C7141 for ; Thu, 10 Dec 2020 15:14:55 +0100 (CET) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 16626200C86 for ; Thu, 10 Dec 2020 15:14:55 +0100 (CET) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A83C7AE2E for ; Thu, 10 Dec 2020 14:14:54 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 10 Dec 2020 15:15:43 +0100 Message-Id: <20201210141548.10982-6-chrubis@suse.cz> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201210141548.10982-1-chrubis@suse.cz> References: <20201210141548.10982-1-chrubis@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v2 05/10] syscalls/bind: Make use of TST_EXP_MACROS X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Cyril Hrubis --- 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; } From patchwork Thu Dec 10 14:15:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1414238 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CsGD96Lzwz9sWf for ; Fri, 11 Dec 2020 01:15:53 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 2AEEF3C787C for ; Thu, 10 Dec 2020 15:15:51 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) by picard.linux.it (Postfix) with ESMTP id A4AF13C7146 for ; Thu, 10 Dec 2020 15:14:55 +0100 (CET) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 64A5160080B for ; Thu, 10 Dec 2020 15:14:55 +0100 (CET) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 0DEB0AE87 for ; Thu, 10 Dec 2020 14:14:55 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 10 Dec 2020 15:15:44 +0100 Message-Id: <20201210141548.10982-7-chrubis@suse.cz> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201210141548.10982-1-chrubis@suse.cz> References: <20201210141548.10982-1-chrubis@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v2 06/10] syscalls/brk01: Make use of TST_EXP_MACROS X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Cyril Hrubis --- 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 = { From patchwork Thu Dec 10 14:15:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1414239 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CsGDM6WP3z9sWj for ; Fri, 11 Dec 2020 01:16:03 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 24DC23C4B5F for ; Thu, 10 Dec 2020 15:16:01 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) by picard.linux.it (Postfix) with ESMTP id E87E23C7152 for ; Thu, 10 Dec 2020 15:14:55 +0100 (CET) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id B97CA1000C29 for ; Thu, 10 Dec 2020 15:14:55 +0100 (CET) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 65876AE95 for ; Thu, 10 Dec 2020 14:14:55 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 10 Dec 2020 15:15:45 +0100 Message-Id: <20201210141548.10982-8-chrubis@suse.cz> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201210141548.10982-1-chrubis@suse.cz> References: <20201210141548.10982-1-chrubis@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH v2 07/10] syscalls/cacheflush: Make use of TST_EXP_MACROS X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Cyril Hrubis --- 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 = { From patchwork Thu Dec 10 14:15:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1414240 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CsGDX3GTzz9sWk for ; Fri, 11 Dec 2020 01:16:12 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id A9C5C3C7FD0 for ; Thu, 10 Dec 2020 15:16:09 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) by picard.linux.it (Postfix) with ESMTP id 7CAE03C75D2 for ; Thu, 10 Dec 2020 15:14:56 +0100 (CET) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 34C831000ACB for ; Thu, 10 Dec 2020 15:14:56 +0100 (CET) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id CA6E9AE2E for ; Thu, 10 Dec 2020 14:14:55 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 10 Dec 2020 15:15:46 +0100 Message-Id: <20201210141548.10982-9-chrubis@suse.cz> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201210141548.10982-1-chrubis@suse.cz> References: <20201210141548.10982-1-chrubis@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH v2 08/10] syscalls/capget: Make use of TEST_MACROS X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Cyril Hrubis --- 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 From patchwork Thu Dec 10 14:15:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1414241 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CsGDk57nwz9sTg for ; Fri, 11 Dec 2020 01:16:22 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id DD4CB3C8098 for ; Thu, 10 Dec 2020 15:16:19 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) by picard.linux.it (Postfix) with ESMTP id 830F23C781E for ; Thu, 10 Dec 2020 15:14:57 +0100 (CET) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id C07851000ACB for ; Thu, 10 Dec 2020 15:14:56 +0100 (CET) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 6BB03AE87 for ; Thu, 10 Dec 2020 14:14:56 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 10 Dec 2020 15:15:47 +0100 Message-Id: <20201210141548.10982-10-chrubis@suse.cz> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201210141548.10982-1-chrubis@suse.cz> References: <20201210141548.10982-1-chrubis@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH v2 09/10] syscalls/capset: Make use of TST_EXP_MACROS X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Cyril Hrubis --- 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); From patchwork Thu Dec 10 14:15:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1414242 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CsGDv5Gx8z9s0b for ; Fri, 11 Dec 2020 01:16:30 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 558493C809F for ; Thu, 10 Dec 2020 15:16:28 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) by picard.linux.it (Postfix) with ESMTP id 93B133C75CB for ; Thu, 10 Dec 2020 15:14:57 +0100 (CET) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 406111A009B6 for ; Thu, 10 Dec 2020 15:14:57 +0100 (CET) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D663DAE2E for ; Thu, 10 Dec 2020 14:14:56 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 10 Dec 2020 15:15:48 +0100 Message-Id: <20201210141548.10982-11-chrubis@suse.cz> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201210141548.10982-1-chrubis@suse.cz> References: <20201210141548.10982-1-chrubis@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v2 10/10] syscalls/open: Make use of TST_EXP_MACROS X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" In the newlib testcases at least. Signed-off-by: Cyril Hrubis --- 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)