From patchwork Mon Aug 27 09:30:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Palethorpe X-Patchwork-Id: 962403 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41zRTl0nFrz9s2P for ; Mon, 27 Aug 2018 19:31:20 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id D26EB3E78D1 for ; Mon, 27 Aug 2018 11:31:17 +0200 (CEST) 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 6B8F93E7254 for ; Mon, 27 Aug 2018 11:31:10 +0200 (CEST) Received: from mx1.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 E10DC1000BE2 for ; Mon, 27 Aug 2018 11:31:09 +0200 (CEST) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id C7E9FAEB0 for ; Mon, 27 Aug 2018 09:31:08 +0000 (UTC) From: Richard Palethorpe To: ltp@lists.linux.it Date: Mon, 27 Aug 2018 11:30:50 +0200 Message-Id: <20180827093053.24658-1-rpalethorpe@suse.com> X-Mailer: git-send-email 2.18.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Cc: pvorel@suse.com, Richard Palethorpe Subject: [LTP] [PATCH v2 1/4] Convert nanosleep02 to newlib X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Also add extra check that nanosleep exited with the expected return value and errno for the user's information. Signed-off-by: Richard Palethorpe Reviewed-by: Petr Vorel --- V2: Removed the falls through attribute for case statements and replace it with a comment .../kernel/syscalls/nanosleep/nanosleep02.c | 123 ++++++------------ 1 file changed, 40 insertions(+), 83 deletions(-) diff --git a/testcases/kernel/syscalls/nanosleep/nanosleep02.c b/testcases/kernel/syscalls/nanosleep/nanosleep02.c index 42c825190..2abe38a95 100644 --- a/testcases/kernel/syscalls/nanosleep/nanosleep02.c +++ b/testcases/kernel/syscalls/nanosleep/nanosleep02.c @@ -26,24 +26,10 @@ */ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include "test.h" -#include "safe_macros.h" - -char *TCID = "nanosleep02"; -int TST_TOTAL = 1; - -static void do_child(void); -static void setup(void); -static void sig_handler(); +#include "tst_test.h" +#include "tst_timer.h" +#include "tst_safe_macros.h" /* * Define here the "rem" precision in microseconds, @@ -57,50 +43,6 @@ static void sig_handler(); */ #define USEC_PRECISION 250000 /* Error margin allowed in usec */ -int main(int ac, char **av) -{ - int lc; - pid_t cpid; - - tst_parse_opts(ac, av, NULL, NULL); - -#ifdef UCLINUX - maybe_run_child(&do_child, ""); -#endif - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - if ((cpid = FORK_OR_VFORK()) == -1) { - tst_brkm(TBROK, NULL, - "fork() failed to create child process"); - } - - if (cpid == 0) { -#ifdef UCLINUX - if (self_exec(av[0], "")) { - tst_brkm(TBROK, NULL, "self_exec failed"); - } -#else - do_child(); -#endif - } - - /* wait for child to time slot for execution */ - sleep(1); - - /* Now send signal to child */ - SAFE_KILL(NULL, cpid, SIGINT); - - tst_record_childstatus(NULL, cpid); - } - - tst_exit(); -} - static void do_child(void) { struct timespec timereq = {.tv_sec = 5, .tv_nsec = 9999}; @@ -110,42 +52,57 @@ static void do_child(void) TEST(nanosleep(&timereq, &timerem)); tst_timer_stop(); - if (tst_timespec_lt(timereq, tst_timer_elapsed())) { - tst_resm(TFAIL, "nanosleep() slept more than timereq"); - return; - } + if (!TST_RET) + tst_brk(TBROK, "nanosleep was not interrupted"); + if (TST_ERR != EINTR) + tst_brk(TBROK | TTERRNO, "nanosleep() failed"); + + if (tst_timespec_lt(timereq, tst_timer_elapsed())) + tst_brk(TFAIL, "nanosleep() slept more than timereq"); exp_rem = tst_timespec_diff(timereq, tst_timer_elapsed()); if (tst_timespec_abs_diff_us(timerem, exp_rem) > USEC_PRECISION) { - tst_resm(TFAIL, - "nanosleep() remaining time %llius, expected %llius, diff %llius", - tst_timespec_to_us(timerem), tst_timespec_to_us(exp_rem), - tst_timespec_abs_diff_us(timerem, exp_rem)); + tst_res(TFAIL, + "nanosleep() remaining time %llius, expected %llius, diff %llius", + tst_timespec_to_us(timerem), tst_timespec_to_us(exp_rem), + tst_timespec_abs_diff_us(timerem, exp_rem)); } else { - tst_resm(TPASS, - "nanosleep() slept for %llius, remaining time difference %llius", - tst_timer_elapsed_us(), - tst_timespec_abs_diff_us(timerem, exp_rem)); + tst_res(TPASS, + "nanosleep() slept for %llius, remaining time difference %llius", + tst_timer_elapsed_us(), + tst_timespec_abs_diff_us(timerem, exp_rem)); } - - tst_exit(); } -static void setup(void) +void run(void) { - tst_sig(FORK, DEF_HANDLER, NULL); + pid_t cpid; - tst_timer_check(CLOCK_MONOTONIC); + cpid = SAFE_FORK(); + if (cpid == 0) { + do_child(); + } else { + sleep(1); - TEST_PAUSE; + SAFE_KILL(cpid, SIGINT); - if (signal(SIGINT, sig_handler) == SIG_ERR) { - tst_brkm(TBROK, NULL, - "signal() fails to setup signal handler"); + tst_reap_children(); } } -static void sig_handler(void) +static void sig_handler(int si LTP_ATTRIBUTE_UNUSED) +{ +} + +static void setup(void) { + tst_timer_check(CLOCK_MONOTONIC); + SAFE_SIGNAL(SIGINT, sig_handler); } + +static struct tst_test test = { + .forks_child = 1, + .setup = setup, + .test_all = run, +}; From patchwork Mon Aug 27 09:30:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Palethorpe X-Patchwork-Id: 962405 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41zRTt50ZKz9ryt for ; Mon, 27 Aug 2018 19:31:30 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 2DF883E7909 for ; Mon, 27 Aug 2018 11:31:24 +0200 (CEST) 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 [217.194.8.4]) by picard.linux.it (Postfix) with ESMTP id 6F5E83E7256 for ; Mon, 27 Aug 2018 11:31:11 +0200 (CEST) Received: from mx1.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 E0E201000BDF for ; Mon, 27 Aug 2018 11:31:09 +0200 (CEST) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D07A6AEF8 for ; Mon, 27 Aug 2018 09:31:08 +0000 (UTC) From: Richard Palethorpe To: ltp@lists.linux.it Date: Mon, 27 Aug 2018 11:30:51 +0200 Message-Id: <20180827093053.24658-2-rpalethorpe@suse.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180827093053.24658-1-rpalethorpe@suse.com> References: <20180827093053.24658-1-rpalethorpe@suse.com> X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Cc: pvorel@suse.com, Richard Palethorpe Subject: [LTP] [PATCH v2 2/4] Convert fcntl33 to newlib X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Also add extra checks that fcntl does not return success after trying to downgrade a lease on a file where it can only be removed and that it can downgrade a lease on a file opened as read only. Signed-off-by: Richard Palethorpe Reviewed-by: Petr Vorel --- testcases/kernel/syscalls/fcntl/fcntl33.c | 168 +++++++++------------- 1 file changed, 71 insertions(+), 97 deletions(-) diff --git a/testcases/kernel/syscalls/fcntl/fcntl33.c b/testcases/kernel/syscalls/fcntl/fcntl33.c index 13616c65f..b45cd90b5 100644 --- a/testcases/kernel/syscalls/fcntl/fcntl33.c +++ b/testcases/kernel/syscalls/fcntl/fcntl33.c @@ -28,8 +28,9 @@ #include -#include "test.h" -#include "safe_macros.h" +#include "tst_test.h" +#include "tst_timer.h" +#include "tst_safe_macros.h" /* * MIN_TIME_LIMIT is defined to 5 senconds as a minimal acceptable @@ -50,10 +51,8 @@ #define FILE_MODE (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID) #define PATH_LS_BRK_T "/proc/sys/fs/lease-break-time" -static void setup(void); -static void do_test(int); -static int do_child(int); -static void cleanup(void); +static void do_test(unsigned int); +static void do_child(unsigned int); static int fd; static int ls_brk_t; @@ -84,113 +83,86 @@ static struct test_case_t { "truncate() conflicts with fcntl(F_SETLEASE, F_RDLCK)"}, }; -char *TCID = "fcntl33"; -int TST_TOTAL = ARRAY_SIZE(test_cases); - -int main(int ac, char **av) -{ - int lc; - int tc; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - - for (tc = 0; tc < TST_TOTAL; tc++) - do_test(tc); - } - - cleanup(); - tst_exit(); -} - static void setup(void) { - tst_sig(FORK, DEF_HANDLER, cleanup); - - tst_require_root(); - tst_timer_check(CLOCK_MONOTONIC); /* Backup and set the lease-break-time. */ - SAFE_FILE_SCANF(NULL, PATH_LS_BRK_T, "%d", &ls_brk_t); - SAFE_FILE_PRINTF(NULL, PATH_LS_BRK_T, "%d", 45); + SAFE_FILE_SCANF(PATH_LS_BRK_T, "%d", &ls_brk_t); + SAFE_FILE_PRINTF(PATH_LS_BRK_T, "%d", 45); - tst_tmpdir(); - - switch ((type = tst_fs_type(cleanup, "."))) { + switch ((type = tst_fs_type("."))) { case TST_NFS_MAGIC: case TST_RAMFS_MAGIC: case TST_TMPFS_MAGIC: - tst_brkm(TCONF, cleanup, - "Cannot do fcntl(F_SETLEASE, F_WRLCK) " - "on %s filesystem", - tst_fs_type_name(type)); + tst_brk(TCONF, + "Cannot do fcntl(F_SETLEASE, F_WRLCK) on %s filesystem", + tst_fs_type_name(type)); default: break; } - SAFE_TOUCH(cleanup, "file", FILE_MODE, NULL); + SAFE_TOUCH("file", FILE_MODE, NULL); sigemptyset(&newset); sigaddset(&newset, SIGIO); if (sigprocmask(SIG_SETMASK, &newset, &oldset) < 0) - tst_brkm(TBROK | TERRNO, cleanup, "sigprocmask() failed"); - - TEST_PAUSE; + tst_brk(TBROK | TERRNO, "sigprocmask() failed"); } -static void do_test(int i) +static void do_test(unsigned int i) { - fd = SAFE_OPEN(cleanup, "file", O_RDONLY); - - pid_t cpid = tst_fork(); - - if (cpid < 0) - tst_brkm(TBROK | TERRNO, cleanup, "fork() failed"); + pid_t cpid; + cpid = SAFE_FORK(); if (cpid == 0) { - SAFE_CLOSE(NULL, fd); do_child(i); + return; } + fd = SAFE_OPEN("file", O_RDONLY); + TEST(fcntl(fd, F_SETLEASE, test_cases[i].lease_type)); - if (TEST_RETURN == -1) { - tst_resm(TFAIL | TTERRNO, "fcntl() failed to set lease"); - SAFE_WAITPID(cleanup, cpid, NULL, 0); - SAFE_CLOSE(cleanup, fd); - fd = 0; - return; + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, "fcntl() failed to set lease"); + goto exit; } /* Wait for SIGIO caused by lease breaker. */ TEST(sigtimedwait(&newset, NULL, &timeout)); - if (TEST_RETURN == -1) { - if (TEST_ERRNO == EAGAIN) { - tst_resm(TFAIL | TTERRNO, "failed to receive SIGIO " - "within %lis", timeout.tv_sec); - SAFE_WAITPID(cleanup, cpid, NULL, 0); - SAFE_CLOSE(cleanup, fd); - fd = 0; - return; + if (TST_RET == -1) { + if (TST_ERR == EAGAIN) { + tst_res(TFAIL | TTERRNO, + "failed to receive SIGIO within %lis", + timeout.tv_sec); + goto exit; } - tst_brkm(TBROK | TTERRNO, cleanup, "sigtimedwait() failed"); + tst_brk(TBROK | TTERRNO, "sigtimedwait() failed"); } /* Try to downgrade or remove the lease. */ switch (test_cases[i].lease_type) { case F_WRLCK: TEST(fcntl(fd, F_SETLEASE, F_RDLCK)); - if (TEST_RETURN == 0) - break; + if (TST_RET == 0) { + if (test_cases[i].op_type == OP_OPEN_RDONLY) + break; + + tst_res(TFAIL, + "fcntl() downgraded lease when not read-only"); + } + + if (test_cases[i].op_type == OP_OPEN_RDONLY) { + tst_res(TFAIL | TTERRNO, + "fcntl() failed to downgrade lease"); + } + + /* Falls through */ case F_RDLCK: TEST(fcntl(fd, F_SETLEASE, F_UNLCK)); - if (TEST_RETURN == -1) { - tst_resm(TFAIL | TTERRNO, + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, "fcntl() failed to remove the lease"); } break; @@ -198,35 +170,31 @@ static void do_test(int i) break; } - tst_record_childstatus(cleanup, cpid); - - SAFE_CLOSE(cleanup, fd); - fd = 0; +exit: + tst_reap_children(); + SAFE_CLOSE(fd); } -static int do_child(int i) +static void do_child(unsigned int i) { long long elapsed_ms; - if (tst_process_state_wait2(getppid(), 'S') != 0) { - tst_brkm(TBROK | TERRNO, NULL, - "failed to wait for parent process's state"); - } + TST_PROCESS_STATE_WAIT(getppid(), 'S'); tst_timer_start(CLOCK_MONOTONIC); switch (test_cases[i].op_type) { case OP_OPEN_RDONLY: - SAFE_OPEN(NULL, "file", O_RDONLY); + SAFE_OPEN("file", O_RDONLY); break; case OP_OPEN_WRONLY: - SAFE_OPEN(NULL, "file", O_WRONLY); + SAFE_OPEN("file", O_WRONLY); break; case OP_OPEN_RDWR: - SAFE_OPEN(NULL, "file", O_RDWR); + SAFE_OPEN("file", O_RDWR); break; case OP_TRUNCATE: - SAFE_TRUNCATE(NULL, "file", 0); + SAFE_TRUNCATE("file", 0); break; default: break; @@ -237,27 +205,33 @@ static int do_child(int i) elapsed_ms = tst_timer_elapsed_ms(); if (elapsed_ms < MIN_TIME_LIMIT * 1000) { - tst_resm(TPASS, "%s, unblocked within %ds", + tst_res(TPASS, "%s, unblocked within %ds", test_cases[i].desc, MIN_TIME_LIMIT); } else { - tst_resm(TFAIL, "%s, blocked too long %llims, " - "expected within %ds", - test_cases[i].desc, elapsed_ms, MIN_TIME_LIMIT); + tst_res(TFAIL, + "%s, blocked too long %llims, expected within %ds", + test_cases[i].desc, elapsed_ms, MIN_TIME_LIMIT); } - - tst_exit(); } static void cleanup(void) { if (sigprocmask(SIG_SETMASK, &oldset, NULL) < 0) - tst_resm(TWARN | TERRNO, "sigprocmask restore oldset failed"); + tst_res(TWARN | TERRNO, "sigprocmask restore oldset failed"); - if (fd > 0 && close(fd)) - tst_resm(TWARN | TERRNO, "failed to close file"); - - tst_rmdir(); + if (fd > 0) + SAFE_CLOSE(fd); /* Restore the lease-break-time. */ FILE_PRINTF(PATH_LS_BRK_T, "%d", ls_brk_t); } + +static struct tst_test test = { + .forks_child = 1, + .needs_root = 1, + .needs_tmpdir = 1, + .tcnt = ARRAY_SIZE(test_cases), + .setup = setup, + .test = do_test, + .cleanup = cleanup +}; From patchwork Mon Aug 27 09:30:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Palethorpe X-Patchwork-Id: 962404 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41zRTl6jQhz9s3x for ; Mon, 27 Aug 2018 19:31:23 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 0A3B73E7811 for ; Mon, 27 Aug 2018 11:31:21 +0200 (CEST) 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 [217.194.8.4]) by picard.linux.it (Postfix) with ESMTP id 6DABE3E7255 for ; Mon, 27 Aug 2018 11:31:11 +0200 (CEST) Received: from mx1.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 E0DA31000BDE for ; Mon, 27 Aug 2018 11:31:09 +0200 (CEST) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id DF114AF3B for ; Mon, 27 Aug 2018 09:31:08 +0000 (UTC) From: Richard Palethorpe To: ltp@lists.linux.it Date: Mon, 27 Aug 2018 11:30:52 +0200 Message-Id: <20180827093053.24658-3-rpalethorpe@suse.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180827093053.24658-1-rpalethorpe@suse.com> References: <20180827093053.24658-1-rpalethorpe@suse.com> X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Cc: pvorel@suse.com, Richard Palethorpe Subject: [LTP] [PATCH v2 3/4] Convert futex_wait_bitset tests to newlib X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Richard Palethorpe Reviewed-by: Petr Vorel --- .../kernel/syscalls/futex/futex_wait_bitset.h | 54 ++++++++++++------- .../syscalls/futex/futex_wait_bitset01.c | 22 ++------ .../syscalls/futex/futex_wait_bitset02.c | 23 ++------ 3 files changed, 43 insertions(+), 56 deletions(-) diff --git a/testcases/kernel/syscalls/futex/futex_wait_bitset.h b/testcases/kernel/syscalls/futex/futex_wait_bitset.h index 81a5d93ab..090dc51d2 100644 --- a/testcases/kernel/syscalls/futex/futex_wait_bitset.h +++ b/testcases/kernel/syscalls/futex/futex_wait_bitset.h @@ -18,6 +18,7 @@ */ #define TRESHOLD_US 100000 +#define DEFAULT_TIMEOUT_US 100010 static void verify_futex_wait_bitset(long long wait_us, clock_t clk_id) { @@ -26,8 +27,8 @@ static void verify_futex_wait_bitset(long long wait_us, clock_t clk_id) u_int32_t bitset = 0xffffffff; int flags = clk_id == CLOCK_REALTIME ? FUTEX_CLOCK_REALTIME : 0; - tst_resm(TINFO, "testing futex_wait_bitset() timeout with %s", - clk_id == CLOCK_REALTIME ? "CLOCK_REALTIME" : "CLOCK_MONOTONIC"); + tst_res(TINFO, "testing futex_wait_bitset() timeout with %s", + clk_id == CLOCK_REALTIME ? "CLOCK_REALTIME" : "CLOCK_MONOTONIC"); clock_gettime(clk_id, &start); to = tst_timespec_add_us(start, wait_us); @@ -36,38 +37,53 @@ static void verify_futex_wait_bitset(long long wait_us, clock_t clk_id) clock_gettime(clk_id, &end); - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "futex_wait_bitset() returned %li, expected -1", - TEST_RETURN); + if (TST_RET != -1) { + tst_res(TFAIL, "futex_wait_bitset() returned %li, expected -1", + TST_RET); return; } - if (TEST_ERRNO == ENOSYS) { - tst_resm(TCONF, "In this kernel, futex() does not support " - "FUTEX_WAIT_BITSET operation"); + if (TST_ERR == ENOSYS) { + tst_res(TCONF, + "In this kernel, futex() does not support FUTEX_WAIT_BITSET operation"); return; } - if (TEST_ERRNO != ETIMEDOUT) { - tst_resm(TFAIL | TTERRNO, "expected %s", - tst_strerrno(ETIMEDOUT)); + if (TST_ERR != ETIMEDOUT) { + tst_res(TFAIL | TTERRNO, "expected %s", + tst_strerrno(ETIMEDOUT)); return; } if (tst_timespec_lt(end, to)) { - tst_resm(TFAIL, - "futex_wait_bitset() woken up prematurely %llius, expected %llius", - tst_timespec_diff_us(end, start), wait_us); + tst_res(TFAIL, + "futex_wait_bitset() woken up prematurely %llius, expected %llius", + tst_timespec_diff_us(end, start), wait_us); return; } if (tst_timespec_diff_us(end, to) > TRESHOLD_US) { - tst_resm(TFAIL, - "futex_wait_bitset() waited too long %llius, expected %llius", - tst_timespec_diff_us(end, start), wait_us); + tst_res(TFAIL, + "futex_wait_bitset() waited too long %llius, expected %llius", + tst_timespec_diff_us(end, start), wait_us); return; } - tst_resm(TPASS, "futex_wait_bitset() waited %llius, expected %llius", - tst_timespec_diff_us(end, start), wait_us); + tst_res(TPASS, "futex_wait_bitset() waited %llius, expected %llius", + tst_timespec_diff_us(end, start), wait_us); } + +static void setup(void) +{ + tst_timer_check(USE_CLOCK); +} + +static void run(void) +{ + verify_futex_wait_bitset(DEFAULT_TIMEOUT_US, USE_CLOCK); +} + +static struct tst_test test = { + .setup = setup, + .test_all = run, +}; diff --git a/testcases/kernel/syscalls/futex/futex_wait_bitset01.c b/testcases/kernel/syscalls/futex/futex_wait_bitset01.c index e5fd621e5..371febb3b 100644 --- a/testcases/kernel/syscalls/futex/futex_wait_bitset01.c +++ b/testcases/kernel/syscalls/futex/futex_wait_bitset01.c @@ -24,25 +24,11 @@ #include -#include "test.h" +#include "tst_test.h" +#include "tst_timer.h" #include "futextest.h" -#include "futex_wait_bitset.h" - -const char *TCID="futex_wait_bitset01"; -const int TST_TOTAL=1; - -#define DEFAULT_TIMEOUT_US 100010 -int main(int argc, char *argv[]) -{ - int lc; +#define USE_CLOCK CLOCK_MONOTONIC - tst_timer_check(CLOCK_MONOTONIC); - - tst_parse_opts(argc, argv, NULL, NULL); - - for (lc = 0; TEST_LOOPING(lc); lc++) - verify_futex_wait_bitset(DEFAULT_TIMEOUT_US, CLOCK_MONOTONIC); +#include "futex_wait_bitset.h" - tst_exit(); -} diff --git a/testcases/kernel/syscalls/futex/futex_wait_bitset02.c b/testcases/kernel/syscalls/futex/futex_wait_bitset02.c index 820c65c26..e727a1b38 100644 --- a/testcases/kernel/syscalls/futex/futex_wait_bitset02.c +++ b/testcases/kernel/syscalls/futex/futex_wait_bitset02.c @@ -24,25 +24,10 @@ #include -#include "test.h" +#include "tst_test.h" +#include "tst_timer.h" #include "futextest.h" -#include "futex_wait_bitset.h" - -const char *TCID="futex_wait_bitset02"; -const int TST_TOTAL=1; - -#define DEFAULT_TIMEOUT_US 100010 - -int main(int argc, char *argv[]) -{ - int lc; - tst_timer_check(CLOCK_REALTIME); +#define USE_CLOCK CLOCK_REALTIME - tst_parse_opts(argc, argv, NULL, NULL); - - for (lc = 0; TEST_LOOPING(lc); lc++) - verify_futex_wait_bitset(DEFAULT_TIMEOUT_US, CLOCK_REALTIME); - - tst_exit(); -} +#include "futex_wait_bitset.h"