From patchwork Fri Jan 24 09:48:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jorik Cronenberg X-Patchwork-Id: 1228722 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.de 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 483vVl3DFTz9sT2 for ; Fri, 24 Jan 2020 20:49:19 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id AD64A3C23A8 for ; Fri, 24 Jan 2020 10:49:16 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) by picard.linux.it (Postfix) with ESMTP id 9B9A13C2379 for ; Fri, 24 Jan 2020 10:49:14 +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-5.smtp.seeweb.it (Postfix) with ESMTPS id C34A9600672 for ; Fri, 24 Jan 2020 10:49:12 +0100 (CET) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 6CB92AAC2 for ; Fri, 24 Jan 2020 09:49:13 +0000 (UTC) From: Jorik Cronenberg To: ltp@lists.linux.it Date: Fri, 24 Jan 2020 10:48:18 +0100 Message-Id: <20200124094819.11710-1-jcronenberg@suse.de> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH v2 1/2] lib: Add timeout to TST_PROCESS_STATE_WAIT 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" Add a timeout to TST_PROCESS_STATE_WAIT. Timeout can be specified in milliseconds. After timeout it returns -1 and sets errno to ETIMEDOUT. Specifying a timeout of 0 makes it for the most part function like the old TST_PROCESS_STATE_WAIT. Update all existing testcases that used TST_PROCESS_STATE_WAIT and the new test library. Signed-off-by: Jorik Cronenberg --- v2: removed TST_PROCESS_STATE_WAIT2 change all existing testcases that use TST_PROCESS_STATE_WAIT and new testlib change doc to reflect changes also while going through tests I noticed that my previous implementation was broken and did timeout even with timeout set to 0, that should now also be fixed. doc/test-writing-guidelines.txt | 7 +++++-- include/tst_process_state.h | 12 ++++++------ lib/tst_process_state.c | 19 ++++++++++++++----- testcases/kernel/mem/mtest01/mtest01.c | 2 +- testcases/kernel/syscalls/clone/clone08.c | 2 +- .../syscalls/futex/futex_cmp_requeue01.c | 2 +- .../kernel/syscalls/ipc/msgsnd/msgsnd05.c | 2 +- .../kernel/syscalls/ipc/msgsnd/msgsnd06.c | 2 +- testcases/kernel/syscalls/pause/pause01.c | 2 +- testcases/kernel/syscalls/wait4/wait401.c | 2 +- 10 files changed, 32 insertions(+), 20 deletions(-) diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt index f0aa69ad4..bfc3b5554 100644 --- a/doc/test-writing-guidelines.txt +++ b/doc/test-writing-guidelines.txt @@ -820,11 +820,14 @@ For the details of the interface, look into the 'include/tst_checkpoint.h'. * Z - zombie process * T - process is traced */ -TST_PROCESS_STATE_WAIT(pid, state) +TST_PROCESS_STATE_WAIT(pid, state, msec_timeout) ------------------------------------------------------------------------------- The 'TST_PROCESS_STATE_WAIT()' waits until process 'pid' is in requested -'state'. The call polls +/proc/pid/stat+ to get this information. +'state' or timeout is reached. The call polls +/proc/pid/stat+ to get this +information. A timeout of 0 will wait infinitely. + +On timeout -1 is returned and errno set to ETIMEDOUT. It's mostly used with state 'S' which means that process is sleeping in kernel for example in 'pause()' or any other blocking syscall. diff --git a/include/tst_process_state.h b/include/tst_process_state.h index fab0491d9..a070e0921 100644 --- a/include/tst_process_state.h +++ b/include/tst_process_state.h @@ -47,9 +47,9 @@ */ #ifdef TST_TEST_H__ -#define TST_PROCESS_STATE_WAIT(pid, state) \ +#define TST_PROCESS_STATE_WAIT(pid, state, msec_timeout) \ tst_process_state_wait(__FILE__, __LINE__, NULL, \ - (pid), (state)) + (pid), (state), (msec_timeout)) #else /* * The same as above but does not use tst_brkm() interface. @@ -62,11 +62,11 @@ int tst_process_state_wait2(pid_t pid, const char state); # define TST_PROCESS_STATE_WAIT(cleanup_fn, pid, state) \ tst_process_state_wait(__FILE__, __LINE__, (cleanup_fn), \ - (pid), (state)) + (pid), (state), 0) #endif -void tst_process_state_wait(const char *file, const int lineno, - void (*cleanup_fn)(void), - pid_t pid, const char state); +int tst_process_state_wait(const char *file, const int lineno, + void (*cleanup_fn)(void), pid_t pid, + const char state, unsigned int msec_timeout); #endif /* TST_PROCESS_STATE__ */ diff --git a/lib/tst_process_state.c b/lib/tst_process_state.c index 7a7824959..323684b55 100644 --- a/lib/tst_process_state.c +++ b/lib/tst_process_state.c @@ -28,11 +28,12 @@ #include "test.h" #include "tst_process_state.h" -void tst_process_state_wait(const char *file, const int lineno, - void (*cleanup_fn)(void), - pid_t pid, const char state) +int tst_process_state_wait(const char *file, const int lineno, + void (*cleanup_fn)(void), pid_t pid, + const char state, unsigned int msec_timeout) { char proc_path[128], cur_state; + unsigned int msecs = 0; snprintf(proc_path, sizeof(proc_path), "/proc/%i/stat", pid); @@ -41,10 +42,18 @@ void tst_process_state_wait(const char *file, const int lineno, "%*i %*s %c", &cur_state); if (state == cur_state) - return; + break; - usleep(10000); + usleep(1000); + msecs += 1; + + if (msecs >= msec_timeout && msec_timeout) { + errno = ETIMEDOUT; + return -1; + } } + + return 0; } int tst_process_state_wait2(pid_t pid, const char state) diff --git a/testcases/kernel/mem/mtest01/mtest01.c b/testcases/kernel/mem/mtest01/mtest01.c index 446d26897..f08d3943f 100644 --- a/testcases/kernel/mem/mtest01/mtest01.c +++ b/testcases/kernel/mem/mtest01/mtest01.c @@ -227,7 +227,7 @@ static void mem_test(void) alloc_maxbytes / 1024, write_msg); for (i = 0; i < pid_cntr; i++) { - TST_PROCESS_STATE_WAIT(pid_list[i], 'T'); + TST_PROCESS_STATE_WAIT(pid_list[i], 'T', 0); kill(pid_list[i], SIGCONT); } } diff --git a/testcases/kernel/syscalls/clone/clone08.c b/testcases/kernel/syscalls/clone/clone08.c index aace30806..8e115b042 100644 --- a/testcases/kernel/syscalls/clone/clone08.c +++ b/testcases/kernel/syscalls/clone/clone08.c @@ -159,7 +159,7 @@ static void test_clone_stopped(int t) child = clone_child(&test_cases[t]); - TST_PROCESS_STATE_WAIT(child, 'T'); + TST_PROCESS_STATE_WAIT(child, 'T', 0); stopped_flag = 0; diff --git a/testcases/kernel/syscalls/futex/futex_cmp_requeue01.c b/testcases/kernel/syscalls/futex/futex_cmp_requeue01.c index a2e899b8d..f5e88a0d5 100644 --- a/testcases/kernel/syscalls/futex/futex_cmp_requeue01.c +++ b/testcases/kernel/syscalls/futex/futex_cmp_requeue01.c @@ -87,7 +87,7 @@ static void verify_futex_cmp_requeue(unsigned int n) } for (i = 0; i < tc->num_waiters; i++) - TST_PROCESS_STATE_WAIT(pid[i], 'S'); + TST_PROCESS_STATE_WAIT(pid[i], 'S', 0); tst_res(TINFO, "Test %d: waiters: %d, wakes: %d, requeues: %d", n, tc->num_waiters, tc->set_wakes, tc->set_requeues); diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c index e169831e0..ace32cdaa 100644 --- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c +++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c @@ -80,7 +80,7 @@ static void do_test(unsigned int n) _exit(0); } - TST_PROCESS_STATE_WAIT(pid, 'S'); + TST_PROCESS_STATE_WAIT(pid, 'S', 0); SAFE_KILL(pid, SIGHUP); tst_reap_children(); } diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c index e7855e844..9f462b672 100644 --- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c +++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c @@ -57,7 +57,7 @@ static void do_test(void) _exit(0); } - TST_PROCESS_STATE_WAIT(pid, 'S'); + TST_PROCESS_STATE_WAIT(pid, 'S', 0); SAFE_MSGCTL(queue_id, IPC_RMID, NULL); diff --git a/testcases/kernel/syscalls/pause/pause01.c b/testcases/kernel/syscalls/pause/pause01.c index d44e7972a..c88248da0 100644 --- a/testcases/kernel/syscalls/pause/pause01.c +++ b/testcases/kernel/syscalls/pause/pause01.c @@ -38,7 +38,7 @@ static void do_test(void) do_child(); TST_CHECKPOINT_WAIT(0); - TST_PROCESS_STATE_WAIT(pid, 'S'); + TST_PROCESS_STATE_WAIT(pid, 'S', 0); kill(pid, SIGINT); /* diff --git a/testcases/kernel/syscalls/wait4/wait401.c b/testcases/kernel/syscalls/wait4/wait401.c index fa0de693a..ed42d8659 100644 --- a/testcases/kernel/syscalls/wait4/wait401.c +++ b/testcases/kernel/syscalls/wait4/wait401.c @@ -25,7 +25,7 @@ static void run(void) pid = SAFE_FORK(); if (!pid) { - TST_PROCESS_STATE_WAIT(getppid(), 'S'); + TST_PROCESS_STATE_WAIT(getppid(), 'S', 0); exit(0); } From patchwork Fri Jan 24 09:48:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jorik Cronenberg X-Patchwork-Id: 1228723 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.de 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 483vVx2H7Kz9sT1 for ; Fri, 24 Jan 2020 20:49:29 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B2F213C2387 for ; Fri, 24 Jan 2020 10:49:26 +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 [217.194.8.3]) by picard.linux.it (Postfix) with ESMTP id 685663C23B0 for ; Fri, 24 Jan 2020 10:49:18 +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 ED9A51A01A0E for ; Fri, 24 Jan 2020 10:49:17 +0100 (CET) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id B2FE9ACA5 for ; Fri, 24 Jan 2020 09:49:16 +0000 (UTC) From: Jorik Cronenberg To: ltp@lists.linux.it Date: Fri, 24 Jan 2020 10:48:19 +0100 Message-Id: <20200124094819.11710-2-jcronenberg@suse.de> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124094819.11710-1-jcronenberg@suse.de> References: <20200124094819.11710-1-jcronenberg@suse.de> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH 2/2] syscalls/vmsplice: Add NONBLOCK testcase 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" Add a testcase for vmsplice() with the flag SPLICE_F_NONBLOCK. And also test that vmsplice() blocks when writing to a full pipe without the flag specified. --- v2: Made changes pointed out by Yang Xu: Add the test to runtest/syscalls Add "lapi/fcntl.h" Add additional info to the test's output messages Use guarded buffer for write_buffer --- Signed-off-by: Jorik Cronenberg --- runtest/syscalls | 1 + testcases/kernel/syscalls/vmsplice/.gitignore | 1 + .../kernel/syscalls/vmsplice/vmsplice04.c | 89 +++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 testcases/kernel/syscalls/vmsplice/vmsplice04.c diff --git a/runtest/syscalls b/runtest/syscalls index f58fefe17..ec94c554d 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1550,6 +1550,7 @@ vhangup02 vhangup02 vmsplice01 vmsplice01 vmsplice02 vmsplice02 vmsplice03 vmsplice03 +vmsplice04 vmsplice04 wait01 wait01 wait02 wait02 diff --git a/testcases/kernel/syscalls/vmsplice/.gitignore b/testcases/kernel/syscalls/vmsplice/.gitignore index 03922073c..042c32585 100644 --- a/testcases/kernel/syscalls/vmsplice/.gitignore +++ b/testcases/kernel/syscalls/vmsplice/.gitignore @@ -1,3 +1,4 @@ /vmsplice01 /vmsplice02 /vmsplice03 +/vmsplice04 diff --git a/testcases/kernel/syscalls/vmsplice/vmsplice04.c b/testcases/kernel/syscalls/vmsplice/vmsplice04.c new file mode 100644 index 000000000..0952d7caf --- /dev/null +++ b/testcases/kernel/syscalls/vmsplice/vmsplice04.c @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 SUSE LLC + * Author: Jorik Cronenberg + * + * Test vmsplice() to a full pipe with SPLICE_F_NONBLOCK and without + * With SPLICE_F_NONBLOCK vmsplice() should return with errno EAGAIN + * Without SPLICE_F_NONBLOCK it should block + */ + +#define _GNU_SOURCE + +#include "tst_test.h" +#include "lapi/vmsplice.h" +#include "lapi/fcntl.h" +#include + + +static int pipes[2]; +static ssize_t pipe_max_size; +static char *write_buffer; +static struct iovec iov; + +static void vmsplice_test(void) +{ + int status; + int pid; + + TEST(vmsplice(pipes[1], &iov, 1, 0)); + if (TST_RET < 0) + tst_brk(TBROK | TTERRNO, + "Initial vmsplice() to fill pipe failed"); + + TEST(vmsplice(pipes[1], &iov, 1, SPLICE_F_NONBLOCK)); + if (TST_RET < 0 && TST_ERR == EAGAIN) + tst_res(TPASS | TTERRNO, + "vmsplice(... , SPLICE_F_NONBLOCK) failed as expected"); + else if (TST_RET < 0) + tst_res(TFAIL | TTERRNO, + "vmsplice(... , SPLICE_F_NONBLOCK) " + "failed with unexpected errno"); + else + tst_res(TFAIL, + "vmsplice(... , SPLICE_F_NONBLOCK) wrote to a full pipe"); + + pid = SAFE_FORK(); + if (!pid) { + TEST(vmsplice(pipes[1], &iov, 1, 0)); + if (TST_RET < 0) + tst_res(TFAIL | TTERRNO, "vmsplice(... , 0) failed"); + else + tst_res(TFAIL, + "vmsplice(... , 0) wrote to a full pipe"); + exit(0); + } else { + if (TST_PROCESS_STATE_WAIT(pid, 'S', 1000) < 0) + return; + else + tst_res(TPASS, "vmsplice(... , 0) blocked"); + SAFE_KILL(pid, SIGKILL); + SAFE_WAIT(&status); + } + +} +static void cleanup(void) +{ + if (pipes[1] > 0) + SAFE_CLOSE(pipes[1]); + if (pipes[0] > 0) + SAFE_CLOSE(pipes[0]); +} +static void setup(void) +{ + SAFE_PIPE(pipes); + + pipe_max_size = SAFE_FCNTL(pipes[1], F_GETPIPE_SZ); + write_buffer = tst_alloc(pipe_max_size); + + iov.iov_base = write_buffer; + iov.iov_len = pipe_max_size; +} + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = vmsplice_test, + .min_kver = "2.6.17", + .forks_child = 1, +};