From patchwork Thu Apr 8 18:45:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 1463995 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=) 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 4FGVZH2Hqrz9sSC for ; Fri, 9 Apr 2021 04:45:25 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id CF1623C738C for ; Thu, 8 Apr 2021 20:45:11 +0200 (CEST) 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 [217.194.8.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id BEAE73C19E4 for ; Thu, 8 Apr 2021 20:45:09 +0200 (CEST) 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 192796012DA for ; Thu, 8 Apr 2021 20:45:08 +0200 (CEST) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 55488B1AE; Thu, 8 Apr 2021 18:45:08 +0000 (UTC) From: Petr Vorel To: ltp@lists.linux.it Date: Thu, 8 Apr 2021 20:45:02 +0200 Message-Id: <20210408184503.28414-1-pvorel@suse.cz> X-Mailer: git-send-email 2.30.2 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.0 required=7.0 tests=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 1/2] splice02: Generate input in C 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: , Cc: Martin Loviska Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" instead relying on shell piping data into it. Found on SLES JeOS (https://progress.opensuse.org/issues/77260). Also add metadata docs. Reported-by: Martin Loviska Suggested-by: Cyril Hrubis Signed-off-by: Petr Vorel --- changes v1->v2: * writing in loop (Cyril), that allowed to drop TST_CHECKPOINT_*() * default number of writes is 2x max pipe size * fixed problems reported by Cyril (drop redundant close(STDIN_FILENO), better phrase error message). NOTE: I kept verbose output to make behavior easier for reviewers. Mainly to see if write size and whole behavior is ok (please do run the test). But before merge I guess I should then delete: tst_res(TINFO, "splice() wrote %ld, remaining %d", TST_RET, to_write); I haven't compared file content (Cyril), only checked size. Kind regards, Petr runtest/smoketest | 2 +- runtest/syscalls | 2 +- testcases/kernel/syscalls/splice/splice02.c | 102 +++++++++++++++++--- 3 files changed, 92 insertions(+), 14 deletions(-) diff --git a/runtest/smoketest b/runtest/smoketest index 0c24fc1fa..ec0c088cb 100644 --- a/runtest/smoketest +++ b/runtest/smoketest @@ -11,5 +11,5 @@ symlink01 symlink01 stat04 symlink01 -T stat04 utime01A symlink01 -T utime01 rename01A symlink01 -T rename01 -splice02 seq 1 20 | splice02 +splice02 splice02 -n 20 route4-change-dst route-change-dst.sh diff --git a/runtest/syscalls b/runtest/syscalls index 2d1e7b648..b89c545f0 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1451,7 +1451,7 @@ socketpair02 socketpair02 sockioctl01 sockioctl01 splice01 splice01 -splice02 seq 1 20000 | splice02 +splice02 splice02 splice03 splice03 splice04 splice04 splice05 splice05 diff --git a/testcases/kernel/syscalls/splice/splice02.c b/testcases/kernel/syscalls/splice/splice02.c index b579667b9..20bf91fb1 100644 --- a/testcases/kernel/syscalls/splice/splice02.c +++ b/testcases/kernel/syscalls/splice/splice02.c @@ -1,40 +1,118 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) Jens Axboe , 2009 + * Copyright (c) 2021 Petr Vorel + */ + +/*\ + * [DESCRIPTION] + * Original reproducer for kernel fix + * bf40d3435caf NFS: add support for splice writes + * from v2.6.31-rc1. + * * http://lkml.org/lkml/2009/4/2/55 + * + * [ALGORITHM] + * - create pipe + * - fork(), child replace stdin with pipe + * - parent write to pipe + * - child slice from pipe + * - check resulted file size */ #define _GNU_SOURCE +#include #include #include +#include #include -#include #include "tst_test.h" #include "lapi/splice.h" -#define SPLICE_SIZE (64*1024) +#define WRITE_SIZE 1024 +#define TEST_FILENAME "splice02-temp" + +static char *narg; +static int num_writes = -1; +static int pipe_fd[2]; + +static void setup(void) +{ + if (tst_parse_int(narg, &num_writes, 1, INT_MAX)) + tst_brk(TBROK, "invalid number of writes '%s'", narg); +} -static void splice_test(void) +static void do_child(void) { - int fd; + int fd, to_write = num_writes; + struct stat st; + + SAFE_CLOSE(pipe_fd[1]); + SAFE_DUP2(pipe_fd[0], STDIN_FILENO); - fd = SAFE_OPEN("splice02-temp", O_WRONLY | O_CREAT | O_TRUNC, 0644); + fd = SAFE_OPEN(TEST_FILENAME, O_WRONLY | O_CREAT | O_TRUNC, 0644); - TEST(splice(STDIN_FILENO, NULL, fd, NULL, SPLICE_SIZE, 0)); - if (TST_RET < 0) { - tst_res(TFAIL, "splice failed - errno = %d : %s", - TST_ERR, strerror(TST_ERR)); - } else { - tst_res(TPASS, "splice() system call Passed"); + while (to_write > 0) { + TEST(splice(STDIN_FILENO, NULL, fd, NULL, WRITE_SIZE, 0)); + tst_res(TINFO, "splice() wrote %ld, remaining %d", TST_RET, to_write); + if (TST_RET < 0) { + tst_res(TFAIL | TTERRNO, "splice failed"); + goto cleanup; + } else { + to_write -= TST_RET; + } } + stat(TEST_FILENAME, &st); + if (st.st_size != num_writes) { + tst_res(TFAIL, "file size is different from expected: %d (%d)", + st.st_size, num_writes); + return; + } + + tst_res(TPASS, "splice() system call passed"); + +cleanup: SAFE_CLOSE(fd); + exit(0); +} + +static void run(void) +{ + int i, max_pipe_size; + + SAFE_PIPE(pipe_fd); + + if (num_writes == -1) { + max_pipe_size = SAFE_FCNTL(pipe_fd[1], F_GETPIPE_SZ); + num_writes = max_pipe_size << 2; + } + + if (SAFE_FORK()) + do_child(); + + tst_res(TINFO, "writting %d times", num_writes); + + for (i = 0; i < num_writes; i++) + SAFE_WRITE(1, pipe_fd[1], "x", 1); + + tst_reap_children(); + + SAFE_CLOSE(pipe_fd[0]); + SAFE_CLOSE(pipe_fd[1]); } static struct tst_test test = { - .test_all = splice_test, + .test_all = run, + .setup = setup, + .needs_checkpoints = 1, .needs_tmpdir = 1, + .forks_child = 1, .min_kver = "2.6.17", + .options = (struct tst_option[]) { + {"n:", &narg, "-n x Number of writes (default 2x max pipe size)"}, + {} + }, }; From patchwork Thu Apr 8 18:45:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 1463996 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=) 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 4FGVZH39hBz9sW1 for ; Fri, 9 Apr 2021 04:45:25 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E55583C800E for ; Thu, 8 Apr 2021 20:45:21 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [IPv6:2001:4b78:1:20::6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 24E0E3C19E4 for ; Thu, 8 Apr 2021 20:45:09 +0200 (CEST) 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-6.smtp.seeweb.it (Postfix) with ESMTPS id 2F1861400B7B for ; Thu, 8 Apr 2021 20:45:08 +0200 (CEST) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 75D6EB1C5 for ; Thu, 8 Apr 2021 18:45:08 +0000 (UTC) From: Petr Vorel To: ltp@lists.linux.it Date: Thu, 8 Apr 2021 20:45:03 +0200 Message-Id: <20210408184503.28414-2-pvorel@suse.cz> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210408184503.28414-1-pvorel@suse.cz> References: <20210408184503.28414-1-pvorel@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-6.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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH 2/2] commands: Add shell pipe test 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" This adds basic shell pipe testing, which was removed from splice02 in 85cebe238 ("splice02: Generate input in C"). Suggested-by: Cyril Hrubis Signed-off-by: Petr Vorel Reviewed-by: Cyril Hrubis --- New in v2. Maybe there should be new runtest runtest/shell and test added into new directory testcases/shell/ or testcases/misc/shell/. But I didn't want to create new directory for single simple test and certainly not new runtest file for a single test. Kind regards, Petr runtest/commands | 1 + runtest/smoketest | 1 + testcases/commands/shell/shell_pipe01.sh | 17 +++++++++++++++++ 3 files changed, 19 insertions(+) create mode 100755 testcases/commands/shell/shell_pipe01.sh diff --git a/runtest/commands b/runtest/commands index 058266b54..8cfad0449 100644 --- a/runtest/commands +++ b/runtest/commands @@ -41,3 +41,4 @@ gdb01_sh gdb01.sh unshare01_sh unshare01.sh sysctl01_sh sysctl01.sh sysctl02_sh sysctl02.sh +shell_test01 echo "SUCCESS" | shell_pipe01.sh diff --git a/runtest/smoketest b/runtest/smoketest index ec0c088cb..85f377192 100644 --- a/runtest/smoketest +++ b/runtest/smoketest @@ -13,3 +13,4 @@ utime01A symlink01 -T utime01 rename01A symlink01 -T rename01 splice02 splice02 -n 20 route4-change-dst route-change-dst.sh +shell_test01 echo "SUCCESS" | shell_pipe01.sh diff --git a/testcases/commands/shell/shell_pipe01.sh b/testcases/commands/shell/shell_pipe01.sh new file mode 100755 index 000000000..3c8ef49fb --- /dev/null +++ b/testcases/commands/shell/shell_pipe01.sh @@ -0,0 +1,17 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2021 Petr Vorel + +TST_TESTFUNC=do_test + +. tst_test.sh + +do_test() +{ + tst_res TINFO "expecting SUCCESS string passed from stdin" + + read line + EXPECT_PASS [ "$line" = "SUCCESS" ] +} + +tst_run