From patchwork Wed Aug 18 15:46:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis Efremov (Oracle)" X-Patchwork-Id: 12444767 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95726C4320A for ; Wed, 18 Aug 2021 15:47:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 738AD60EFF for ; Wed, 18 Aug 2021 15:47:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240028AbhHRPsE (ORCPT ); Wed, 18 Aug 2021 11:48:04 -0400 Received: from mail-lf1-f46.google.com ([209.85.167.46]:46828 "EHLO mail-lf1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240052AbhHRPry (ORCPT ); Wed, 18 Aug 2021 11:47:54 -0400 Received: by mail-lf1-f46.google.com with SMTP id u22so5519459lfq.13; Wed, 18 Aug 2021 08:47:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ly8XYYipoD2ui1uOI6rBTuBqM3/79CjvaDtgsH2un6s=; b=XW3u26JgYxM1wF0meHea8JFbo6/nBp8Tbq8k/8JqspU60V3D0cWPitDsQNVpzGucGi e5idfJPecmpzQxuLu3YYTg+6/pIjMRj/wljhkLs3CiLRoc8tcGNsy3zx2fJPJu23vWFp qQ73j/UO8BhCvQfwblYcQExEZNk+nhshrwyq/U7N/m5uzkOuuG+/eC7WBHJ9Xmh+aR3k 8C1AO1GG/Lwy/w7LpcLdxkpg9mwpmH6WIYQG+OD+x5bfZjKVwp9bg1/eXzyKcKSWjdW6 ko0xT73YYqpjcY1GITCy5/ZMOhLqObx28zK+39Gd8uudmY+N/Q0e6QF4fW5XvmoBui+V hUaw== X-Gm-Message-State: AOAM532l9FtUfIYm3uu5EcrGsjaX0QqmPDP+NklBVgj8eD8RZTJvUYRb +8d3SiV4Fuam9jy+SAeLzc1rJUH25uTOUXt+ X-Google-Smtp-Source: ABdhPJxSW5NiBVI2AeSdHNUlHFh2wl5ZhVlKxtXub5Ms8sBmwEilPwk668+BiEqh3eJrzR2ehxSh9A== X-Received: by 2002:ac2:4185:: with SMTP id z5mr6821837lfh.391.1629301637805; Wed, 18 Aug 2021 08:47:17 -0700 (PDT) Received: from localhost.localdomain (broadband-188-32-236-56.ip.moscow.rt.ru. [188.32.236.56]) by smtp.googlemail.com with ESMTPSA id j4sm23808ljh.120.2021.08.18.08.47.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 08:47:17 -0700 (PDT) From: Denis Efremov To: linux-kselftest@vger.kernel.org Cc: Denis Efremov , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Jiri Kosina , Willy Tarreau , Joe Perches Subject: [RFC PATCH 1/5] checkpatch: improve handling of revert commits Date: Wed, 18 Aug 2021 18:46:42 +0300 Message-Id: <20210818154646.925351-2-efremov@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210818154646.925351-1-efremov@linux.com> References: <20210818154646.925351-1-efremov@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Properly handle commits like: commit f2791e7eadf4 ("Revert "floppy: refactor open() flags handling"") Cc: Joe Perches Signed-off-by: Denis Efremov --- scripts/checkpatch.pl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 461d4221e4a4..cf31e8c994d3 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3200,20 +3200,20 @@ sub process { $long = 1 if ($line =~ /\bcommit\s+[0-9a-f]{41,}/i); $space = 0 if ($line =~ /\bcommit [0-9a-f]/i); $case = 0 if ($line =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/); - if ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)"\)/i) { + if ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("(.+)"\)/i) { $orig_desc = $1; $hasparens = 1; } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s*$/i && defined $rawlines[$linenr] && - $rawlines[$linenr] =~ /^\s*\("([^"]+)"\)/) { + $rawlines[$linenr] =~ /^\s*\("(.+)"\)/) { $orig_desc = $1; $hasparens = 1; - } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i && + } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\(".+$/i && defined $rawlines[$linenr] && - $rawlines[$linenr] =~ /^\s*[^"]+"\)/) { - $line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)$/i; + $rawlines[$linenr] =~ /^\s*.+"\)/) { + $line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("(.+)$/i; $orig_desc = $1; - $rawlines[$linenr] =~ /^\s*([^"]+)"\)/; + $rawlines[$linenr] =~ /^\s*(.+)"\)/; $orig_desc .= " " . $1; $hasparens = 1; } From patchwork Wed Aug 18 15:46:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis Efremov (Oracle)" X-Patchwork-Id: 12444769 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DCF7C4320E for ; Wed, 18 Aug 2021 15:47:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 49615610D2 for ; Wed, 18 Aug 2021 15:47:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237755AbhHRPsP (ORCPT ); Wed, 18 Aug 2021 11:48:15 -0400 Received: from mail-lf1-f44.google.com ([209.85.167.44]:46887 "EHLO mail-lf1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240060AbhHRPsM (ORCPT ); Wed, 18 Aug 2021 11:48:12 -0400 Received: by mail-lf1-f44.google.com with SMTP id u22so5520954lfq.13; Wed, 18 Aug 2021 08:47:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dEDUliLc2qrFYYbpwGoL3AeOYmTJ041IXVBP+u79Zy0=; b=PuW+7NltJ0sMKCWza9vpojkwxQ7xAKZqOEMCq8/9MIfWL59rDm/9hZaiz3NG5awhXX wCK/AzD3J54KG3ReaufsfOoR82lyOKWllBNE4vH6j6ndYnv+lhFBePOu7+7cPE+O1rie 7e/nD5hgrxjZFO54Pi/ywAMflvXwPCTEO8g2XneABwm3+ETDI0z0HIJfr/ZNHz6sGXSS R08bS+lirhuQK1B+9jpSgjPuhpDffP42RwjY/47XPeNfSmE+PZGDv8QyRz/xbaGLmGk1 A065VXCji6SO7x2vBhraVJp5nYhGeBluT7DlUgaw8CrEezZOPUYRyuYl+kCJkWK9LLhC iwrw== X-Gm-Message-State: AOAM532Nut5CHNHFPgvMKTrBfRMogcCg3WFiYR2uADk2XLqb3tiFBIN6 PP4oQafZVy0qyj1dMxfKdH+9m7PhUeiMBaK4 X-Google-Smtp-Source: ABdhPJwtnKUf8dXunIBVcILoF/7iUwhJlN+CcBF7EUEtUNE8kE0EEYVLyZ36O8kFfcN2zSzuUFHoLQ== X-Received: by 2002:ac2:4856:: with SMTP id 22mr5918526lfy.638.1629301653187; Wed, 18 Aug 2021 08:47:33 -0700 (PDT) Received: from localhost.localdomain (broadband-188-32-236-56.ip.moscow.rt.ru. [188.32.236.56]) by smtp.googlemail.com with ESMTPSA id j4sm23808ljh.120.2021.08.18.08.47.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 08:47:32 -0700 (PDT) From: Denis Efremov To: linux-kselftest@vger.kernel.org Cc: Denis Efremov , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Jiri Kosina , Willy Tarreau , Masahiro Yamada Subject: [RFC PATCH 2/5] gen_initramfs.sh: use absolute path for gen_init_cpio Date: Wed, 18 Aug 2021 18:46:43 +0300 Message-Id: <20210818154646.925351-3-efremov@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210818154646.925351-1-efremov@linux.com> References: <20210818154646.925351-1-efremov@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Use absolute path to call gen_init_cpio. This allows one to use gen_initramfs.sh from any directory. Cc: Masahiro Yamada Signed-off-by: Denis Efremov Reviewed-by: Masahiro Yamada --- usr/gen_initramfs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/gen_initramfs.sh b/usr/gen_initramfs.sh index 63476bb70b41..2e4a86181c79 100755 --- a/usr/gen_initramfs.sh +++ b/usr/gen_initramfs.sh @@ -244,4 +244,4 @@ if test -n "$KBUILD_BUILD_TIMESTAMP"; then timestamp="-t $timestamp" fi fi -usr/gen_init_cpio $timestamp $cpio_list > $output +"$(dirname "$0")"/gen_init_cpio $timestamp $cpio_list > $output From patchwork Wed Aug 18 15:46:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis Efremov (Oracle)" X-Patchwork-Id: 12444771 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, LOTS_OF_MONEY,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF7AAC4338F for ; Wed, 18 Aug 2021 15:47:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B9C6260EFF for ; Wed, 18 Aug 2021 15:47:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240058AbhHRPsS (ORCPT ); Wed, 18 Aug 2021 11:48:18 -0400 Received: from mail-lj1-f172.google.com ([209.85.208.172]:43558 "EHLO mail-lj1-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240003AbhHRPsR (ORCPT ); Wed, 18 Aug 2021 11:48:17 -0400 Received: by mail-lj1-f172.google.com with SMTP id x7so5874447ljn.10; Wed, 18 Aug 2021 08:47:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QQ1pbYxxSXDHS5PZboZJzEI8JskJZI6zkGDFpVYhurc=; b=JSqHCq8AMLxOfxBHNLPeraQn1EjrXLNsDFYiCYOEC2KgstobLzZb1XeHLDRUc0sQOC gXxY3p72G7E5HmX0pkZYDwzAfyg6YKpP/H49gJxLQupwpCijzEyFfc8+kIcdWosxjr5Z Y6quXaw6wKfUx3PUHlBKmcRulR3DHl8ua9sYFzOryJm6zZsgH19vLTQJ0iX8yqk8GiRy mEuCCYrCaKzHXM7Az1d0b3naan2Zi5lKm38rmi98dVquYK+/DJl2SdmNA7Irbt5kasFf vYBashZzfvV+5sJ0B6voU2kLvLWNWWcRmDfQWEz3nCq8su87XN+yZ5esV1dRIJYqj+iM ie0g== X-Gm-Message-State: AOAM533XiBQZnDwobdCXMuwWOAUh34z9bJ06tiaNtthZ5gK1CUb0RRCq 2d/qqfWOvQzHwjjHAKLGIfWCvrmw6tTBQBPV X-Google-Smtp-Source: ABdhPJwO44fMOYzmnl7ziE9pnB6IujFYbe9/oC6OPwXYBSSAtLOzxlRdIt6yBOVs7vHOyIKhzQ3d/A== X-Received: by 2002:a2e:5307:: with SMTP id h7mr8788219ljb.154.1629301660712; Wed, 18 Aug 2021 08:47:40 -0700 (PDT) Received: from localhost.localdomain (broadband-188-32-236-56.ip.moscow.rt.ru. [188.32.236.56]) by smtp.googlemail.com with ESMTPSA id j4sm23808ljh.120.2021.08.18.08.47.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 08:47:40 -0700 (PDT) From: Denis Efremov To: linux-kselftest@vger.kernel.org Cc: Denis Efremov , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Jiri Kosina , Willy Tarreau Subject: [RFC PATCH 3/5] selftests: floppy: add basic tests for opening an empty device Date: Wed, 18 Aug 2021 18:46:44 +0300 Message-Id: <20210818154646.925351-4-efremov@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210818154646.925351-1-efremov@linux.com> References: <20210818154646.925351-1-efremov@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Add basic tests for O_NDELAY and O_ACCMODE open of an empty floppy device. "empty" test works under assumption that there is no disk in "/dev/fd0". It's possible to run it on a real hardware. "run_empty.sh" automates the testing process by creating a minimal initrd image with "init" and "test" binaries and running the kernel in QEMU. The tests cover these regressions: - commit f2791e7eadf4 ("Revert "floppy: refactor open() flags handling"") - commit ff06db1efb2a ("floppy: fix open(O_ACCMODE) for ioctl-only open") Signed-off-by: Denis Efremov --- MAINTAINERS | 1 + tools/testing/selftests/floppy/.gitignore | 5 ++ tools/testing/selftests/floppy/Makefile | 10 ++++ tools/testing/selftests/floppy/config | 1 + tools/testing/selftests/floppy/empty.c | 58 +++++++++++++++++++++ tools/testing/selftests/floppy/init.c | 43 +++++++++++++++ tools/testing/selftests/floppy/lib.sh | 57 ++++++++++++++++++++ tools/testing/selftests/floppy/run_empty.sh | 16 ++++++ 8 files changed, 191 insertions(+) create mode 100644 tools/testing/selftests/floppy/.gitignore create mode 100644 tools/testing/selftests/floppy/Makefile create mode 100644 tools/testing/selftests/floppy/config create mode 100644 tools/testing/selftests/floppy/empty.c create mode 100644 tools/testing/selftests/floppy/init.c create mode 100644 tools/testing/selftests/floppy/lib.sh create mode 100755 tools/testing/selftests/floppy/run_empty.sh diff --git a/MAINTAINERS b/MAINTAINERS index fd25e4ecf0b9..f2a08b793b54 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7227,6 +7227,7 @@ M: Denis Efremov L: linux-block@vger.kernel.org S: Odd Fixes F: drivers/block/floppy.c +F: tools/testing/selftests/floppy/ FLYSKY FSIA6B RC RECEIVER M: Markus Koch diff --git a/tools/testing/selftests/floppy/.gitignore b/tools/testing/selftests/floppy/.gitignore new file mode 100644 index 000000000000..a9fdf1dbaa97 --- /dev/null +++ b/tools/testing/selftests/floppy/.gitignore @@ -0,0 +1,5 @@ +init +cpio_list +initrd + +empty diff --git a/tools/testing/selftests/floppy/Makefile b/tools/testing/selftests/floppy/Makefile new file mode 100644 index 000000000000..83e18cd63210 --- /dev/null +++ b/tools/testing/selftests/floppy/Makefile @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 +CFLAGS := -static -I../../../../usr/include + +TEST_PROGS := run_empty.sh +TEST_GEN_FILES := init empty +TEST_FILES := lib.sh + +include ../lib.mk + +EXTRA_CLEAN := initrd cpio_list diff --git a/tools/testing/selftests/floppy/config b/tools/testing/selftests/floppy/config new file mode 100644 index 000000000000..d0c2cd8edfb2 --- /dev/null +++ b/tools/testing/selftests/floppy/config @@ -0,0 +1 @@ +CONFIG_BLK_DEV_FD=y diff --git a/tools/testing/selftests/floppy/empty.c b/tools/testing/selftests/floppy/empty.c new file mode 100644 index 000000000000..d7e2e6a74132 --- /dev/null +++ b/tools/testing/selftests/floppy/empty.c @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include "../kselftest_harness.h" + +FIXTURE(floppy) { + const char *dev; + int fd; +}; + +FIXTURE_VARIANT(floppy) { + int flags; +}; + +/* + * See ff06db1efb2a ("floppy: fix open(O_ACCMODE) for ioctl-only open") + * fdutils use O_ACCMODE for probing and ioctl-only open + */ +FIXTURE_VARIANT_ADD(floppy, ACCMODE) { + .flags = O_ACCMODE, +}; + +FIXTURE_VARIANT_ADD(floppy, NACCMODE) { + .flags = O_ACCMODE|O_NDELAY, +}; + +FIXTURE_VARIANT_ADD(floppy, NRD) { + .flags = O_RDONLY|O_NDELAY, +}; + +FIXTURE_VARIANT_ADD(floppy, NWR) { + .flags = O_WRONLY|O_NDELAY, +}; + +FIXTURE_VARIANT_ADD(floppy, NRDWR) { + .flags = O_RDWR|O_NDELAY, +}; + +FIXTURE_SETUP(floppy) +{ + self->dev = "/dev/fd0"; + if (access(self->dev, F_OK)) + ksft_exit_skip("No floppy device found\n"); +}; + +FIXTURE_TEARDOWN(floppy) +{ + ASSERT_EQ(close(self->fd), 0); +} + +TEST_F(floppy, open) +{ + self->fd = open(self->dev, variant->flags); + ASSERT_GT(self->fd, 0); +} + +TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/floppy/init.c b/tools/testing/selftests/floppy/init.c new file mode 100644 index 000000000000..d4df4fcfd21f --- /dev/null +++ b/tools/testing/selftests/floppy/init.c @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include +#include + +__attribute__((noreturn)) static void poweroff(void) +{ + fflush(stdout); + fflush(stderr); + reboot(RB_POWER_OFF); + sleep(10); + fprintf(stderr, "\nFailed to power off\n"); + exit(1); +} + +static void panic(const char *what) +{ + fprintf(stderr, "\nPANIC %s: %s\n", what, strerror(errno)); + poweroff(); +} + +int main(int argc, char *argv[]) +{ + pid_t pid; + + pid = fork(); + if (pid == -1) + panic("fork"); + else if (pid == 0) { + execl("/test", "test", NULL); + panic("exec"); + } + if (waitpid(pid, NULL, 0) < 0) + panic("waitpid"); + + poweroff(); + return 1; +} diff --git a/tools/testing/selftests/floppy/lib.sh b/tools/testing/selftests/floppy/lib.sh new file mode 100644 index 000000000000..22b711ec32ee --- /dev/null +++ b/tools/testing/selftests/floppy/lib.sh @@ -0,0 +1,57 @@ +# SPDX-License-Identifier: GPL-2.0 + +TOP_DIR="$(realpath "$(dirname "$0")"/../../../../)" + +QEMU=qemu-system-x86_64 +KERNEL="$TOP_DIR"/arch/x86/boot/bzImage +INITRD=initrd + +gen_cpio_list() { + echo "file /init init 755 0 0" > cpio_list + echo "file /test $1 755 0 0" >> cpio_list + echo "dir /dev 755 0 0" >> cpio_list + echo "nod /dev/console 644 0 0 c 5 1" >> cpio_list + echo "nod /dev/fd0 666 0 0 b 2 0" >> cpio_list + echo "dir /mnt 755 0 0" >> cpio_list +} + +gen_initrd() { + "$TOP_DIR"/usr/gen_initramfs.sh -o initrd ./cpio_list +} + +get_selftest_log() { + perl -ne '$begin = $_ =~ /^TAP version/ unless $begin; + if ($begin && !$end) { + $_ =~ s/^\s+|\s+$|\[.+//g; + print($_ . "\n") if $_; + } + $end = $_ =~ /^# Totals:/ unless $end;' +} + +run_qemu() { + $QEMU -enable-kvm -nodefaults -nographic \ + -kernel "$KERNEL" -initrd "$INITRD" \ + -append "console=ttyS0 earlyprintk=serial" \ + -serial stdio -monitor none -no-reboot "$@" +} + +run_qemu_debug() { + run_qemu "$@" +} + +run_qemu_nodebug() { + run_qemu "$@" | get_selftest_log +} + +detect_debug() { + if [ "x$1" = "x" ]; then + run=run_qemu_nodebug + else + run=run_qemu_debug + fi +} + +run_qemu_empty() { + detect_debug "$1" + $run -drive index=0,if=floppy +} diff --git a/tools/testing/selftests/floppy/run_empty.sh b/tools/testing/selftests/floppy/run_empty.sh new file mode 100755 index 000000000000..f018107dc6a5 --- /dev/null +++ b/tools/testing/selftests/floppy/run_empty.sh @@ -0,0 +1,16 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 + +set -e + +source "$(dirname $0)"/lib.sh + +while getopts d flag; do + case "${flag}" in + d) debug=1;; + esac +done + +gen_cpio_list empty +gen_initrd empty +run_qemu_empty $debug From patchwork Wed Aug 18 15:46:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis Efremov (Oracle)" X-Patchwork-Id: 12444773 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C437C4338F for ; Wed, 18 Aug 2021 15:47:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64A6660EFF for ; Wed, 18 Aug 2021 15:47:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239944AbhHRPs0 (ORCPT ); Wed, 18 Aug 2021 11:48:26 -0400 Received: from mail-lj1-f171.google.com ([209.85.208.171]:39730 "EHLO mail-lj1-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239971AbhHRPsV (ORCPT ); Wed, 18 Aug 2021 11:48:21 -0400 Received: by mail-lj1-f171.google.com with SMTP id q21so5921693ljj.6; Wed, 18 Aug 2021 08:47:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Xo/kWZ/Q6p5cSot9iJCnbo6zu7GIyqYV9mIUYePGUPs=; b=NOv0gGkjHoTNC0CQlIN69hx9RLXPmtmI4R83d3Gbb702SzPfsbKzHa+Expd4sqArXy MbrEXZm5qeZklckthQxxnJY8lnF4t37RCRbEFrjGMeLw/ycmpEgEsR3icb67lo/Q0Mpd 7T+CYKyYedqBw9RmoG298rnAHk0VE+2TUEs5g72lPinx81cVKvv4DxC2IlCVmTmwGlWv TTBO0eh0rkM5o+EMn09QdcY2qidQscEIdM4+t0tPtmuCt6yRzutECEQajRnZLZlMJuqc ce0vPSYbThSc7hNM3Z16fTFbJzgazPWziIQsSngkKU9vtawirelI7tId0q3Cia989AGn rcrA== X-Gm-Message-State: AOAM533e1nWfRyBBhdR87Y0dGy+uEps9sJUUiL4QAG5yNI/OdBTxLSLJ Ib5EFpNg9eXaMe3EWbe6XFjfnD5NAchUlOBd X-Google-Smtp-Source: ABdhPJxWF6fSa4HMmYCAKmmj7d8BhZWiADsgdS+XXkQEe9jmoJPWjoybpGBMZ/QnMyBgkUA5Q6Iz7g== X-Received: by 2002:a2e:509:: with SMTP id 9mr8362496ljf.453.1629301664689; Wed, 18 Aug 2021 08:47:44 -0700 (PDT) Received: from localhost.localdomain (broadband-188-32-236-56.ip.moscow.rt.ru. [188.32.236.56]) by smtp.googlemail.com with ESMTPSA id j4sm23808ljh.120.2021.08.18.08.47.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 08:47:44 -0700 (PDT) From: Denis Efremov To: linux-kselftest@vger.kernel.org Cc: Denis Efremov , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Jiri Kosina , Willy Tarreau Subject: [RFC PATCH 4/5] selftests: floppy: add basic tests for a readonly disk Date: Wed, 18 Aug 2021 18:46:45 +0300 Message-Id: <20210818154646.925351-5-efremov@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210818154646.925351-1-efremov@linux.com> References: <20210818154646.925351-1-efremov@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Add basic tests for a floppy with a readonly disk. "rdonly" test works under following assumptions: - there is a readonly disk in "/dev/fd0" - the disk is VFAT formatted - there is "test" file with "TEST" in it on the disk "run_rdonly.sh" script simulates the conditions and automates the testing process. The tests cover the regression: - commit f2791e7eadf4 ("Revert "floppy: refactor open() flags handling"") Signed-off-by: Denis Efremov --- tools/testing/selftests/floppy/.gitignore | 2 + tools/testing/selftests/floppy/Makefile | 6 +- tools/testing/selftests/floppy/lib.sh | 6 ++ tools/testing/selftests/floppy/rdonly.c | 99 ++++++++++++++++++++ tools/testing/selftests/floppy/run_rdonly.sh | 22 +++++ 5 files changed, 132 insertions(+), 3 deletions(-) create mode 100644 tools/testing/selftests/floppy/rdonly.c create mode 100755 tools/testing/selftests/floppy/run_rdonly.sh diff --git a/tools/testing/selftests/floppy/.gitignore b/tools/testing/selftests/floppy/.gitignore index a9fdf1dbaa97..7642dc0ef281 100644 --- a/tools/testing/selftests/floppy/.gitignore +++ b/tools/testing/selftests/floppy/.gitignore @@ -1,5 +1,7 @@ init cpio_list initrd +testdir/ empty +rdonly diff --git a/tools/testing/selftests/floppy/Makefile b/tools/testing/selftests/floppy/Makefile index 83e18cd63210..ed8fdeb79aea 100644 --- a/tools/testing/selftests/floppy/Makefile +++ b/tools/testing/selftests/floppy/Makefile @@ -1,10 +1,10 @@ # SPDX-License-Identifier: GPL-2.0 CFLAGS := -static -I../../../../usr/include -TEST_PROGS := run_empty.sh -TEST_GEN_FILES := init empty +TEST_PROGS := run_empty.sh run_rdonly.sh +TEST_GEN_FILES := init empty rdonly TEST_FILES := lib.sh include ../lib.mk -EXTRA_CLEAN := initrd cpio_list +EXTRA_CLEAN := initrd cpio_list testdir diff --git a/tools/testing/selftests/floppy/lib.sh b/tools/testing/selftests/floppy/lib.sh index 22b711ec32ee..9988be187bc9 100644 --- a/tools/testing/selftests/floppy/lib.sh +++ b/tools/testing/selftests/floppy/lib.sh @@ -55,3 +55,9 @@ run_qemu_empty() { detect_debug "$1" $run -drive index=0,if=floppy } + +run_qemu_rdonly_fat() { + detect_debug "$2" + $run -drive file=fat:floppy:"$1",index=0,if=floppy,readonly +} + diff --git a/tools/testing/selftests/floppy/rdonly.c b/tools/testing/selftests/floppy/rdonly.c new file mode 100644 index 000000000000..fa60d069540b --- /dev/null +++ b/tools/testing/selftests/floppy/rdonly.c @@ -0,0 +1,99 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include +#include "../kselftest_harness.h" + +FIXTURE(floppy) { + const char *dev; +}; + +FIXTURE_SETUP(floppy) +{ + int fd; + struct floppy_drive_params params; + + self->dev = "/dev/fd0"; + if (access(self->dev, F_OK)) + ksft_exit_skip("No floppy device found\n"); + if (access(self->dev, R_OK)) + ksft_exit_skip("Floppy is not read accessible\n"); + + fd = open(self->dev, O_ACCMODE|O_NDELAY); + EXPECT_EQ(0, ioctl(fd, FDGETDRVPRM, ¶ms)); + params.flags |= FTD_MSG|FD_DEBUG; + EXPECT_EQ(0, ioctl(fd, FDSETDRVPRM, ¶ms)); + close(fd); +} + +FIXTURE_TEARDOWN(floppy) +{ +} + +TEST_F(floppy, read) +{ + int fd, test; + + fd = open(self->dev, O_RDONLY); + ASSERT_GT(fd, 0); + ASSERT_EQ(read(fd, &test, sizeof(test)), sizeof(test)); + ASSERT_EQ(close(fd), 0); +} + +TEST_F(floppy, open_write_fail) +{ + ASSERT_LT(open(self->dev, O_WRONLY), 0); +} + +TEST_F(floppy, open_rdwr_fail) +{ + ASSERT_LT(open(self->dev, O_RDWR), 0); +} + +TEST_F(floppy, ioctl_disk_writable) +{ + int fd; + struct floppy_drive_struct drive; + + fd = open(self->dev, O_RDONLY|O_NDELAY); + ASSERT_GT(fd, 0); + ASSERT_EQ(0, ioctl(fd, FDGETDRVSTAT, &drive)); + ASSERT_FALSE(drive.flags & FD_DISK_WRITABLE); + ASSERT_EQ(close(fd), 0); +} + +TEST_F(floppy, mount) +{ + int fd; + char test[5] = {}; + + mount(self->dev, "/mnt", "vfat", MS_RDONLY, NULL); + ASSERT_EQ(0, errno); + + fd = open("/mnt/test", O_RDONLY); + read(fd, &test, sizeof(test)); + ASSERT_EQ(0, strncmp(test, "TEST", 4)); +} + +TEST_F(floppy, open_ndelay_write_fail) +{ +#define TEST_DATA "TEST_FAIL_WRITE" + int fd; + char test[] = TEST_DATA; + + fd = open(self->dev, O_RDWR|O_NDELAY); + ASSERT_GT(fd, 0); + + write(fd, test, sizeof(test)); + read(fd, test, sizeof(test)); + ASSERT_NE(0, strncmp(TEST_DATA, test, sizeof(TEST_DATA))); + + ASSERT_EQ(close(fd), 0); +#undef TEST_DATA +} + +TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/floppy/run_rdonly.sh b/tools/testing/selftests/floppy/run_rdonly.sh new file mode 100755 index 000000000000..a358a1b6e58d --- /dev/null +++ b/tools/testing/selftests/floppy/run_rdonly.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 + +set -e + +source "$(dirname $0)"/lib.sh + +while getopts d flag; do + case "${flag}" in + d) debug=1;; + esac +done + +if [ -z $debug ]; then + trap "rm -rf testdir" EXIT +fi +mkdir -p testdir +echo -n TEST > testdir/test + +gen_cpio_list rdonly +gen_initrd rdonly +run_qemu_rdonly_fat testdir $debug From patchwork Wed Aug 18 15:46:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis Efremov (Oracle)" X-Patchwork-Id: 12444775 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F83BC4320E for ; Wed, 18 Aug 2021 15:47:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 83A0D610CD for ; Wed, 18 Aug 2021 15:47:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240107AbhHRPs2 (ORCPT ); Wed, 18 Aug 2021 11:48:28 -0400 Received: from mail-lf1-f44.google.com ([209.85.167.44]:43712 "EHLO mail-lf1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240125AbhHRPs0 (ORCPT ); Wed, 18 Aug 2021 11:48:26 -0400 Received: by mail-lf1-f44.google.com with SMTP id i9so5535008lfg.10; Wed, 18 Aug 2021 08:47:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9bvaZZWUnooV8Jw75jd8qrJDvM8A6y9DHRPhc6M+/sI=; b=chnDyw5zPdhgShW1Q4A0tvohOju0LM8CNqRVMsT4x0h+OeeXph8jlNa+WcdcHzedst 7WDLIxf0bdE8vyV6e1wvuhNoOKyjv9y+rqZbcnPV96/3Jn1VL8RbnH0hUMj5ihychl5k F1w2wGwcuudm51JtjWcd6Lb8h8DNYe+XQsQwW0QdhKK3rVT+crWHKQ8GrMyrZGf6g+Zj J1HjL9eRU7GfN0gN0iVltRprU6zR3SVgCvkto5doyP45TcY3oN5u1KzSZbq7o91bh8HF OZnTBaClSIlphquOBSwhRr6GlZBhzb7tc5ZImGwAOU1/W/kdN8lOL7Z2RU9QoFwI60Py ovrg== X-Gm-Message-State: AOAM531YqiF0Yvj+krmrPtzz2Xn62hiTlTbR6AqWMNn4MlF1UYl7b04G AVQkXknJavb0gt1QG2xdXoXUeRF74WogIqXu X-Google-Smtp-Source: ABdhPJyr8G1yfTuq0VreQDkFsJJ0P7+twk1JxBRGT3Ai6uEwI88aRpUUOkMZx89CEUKflZadKZdEpQ== X-Received: by 2002:a05:6512:3091:: with SMTP id z17mr7043553lfd.207.1629301670115; Wed, 18 Aug 2021 08:47:50 -0700 (PDT) Received: from localhost.localdomain (broadband-188-32-236-56.ip.moscow.rt.ru. [188.32.236.56]) by smtp.googlemail.com with ESMTPSA id j4sm23808ljh.120.2021.08.18.08.47.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 08:47:49 -0700 (PDT) From: Denis Efremov To: linux-kselftest@vger.kernel.org Cc: Denis Efremov , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Jiri Kosina , Willy Tarreau Subject: [RFC PATCH 5/5] selftests: floppy: add basic rdwr tests Date: Wed, 18 Aug 2021 18:46:46 +0300 Message-Id: <20210818154646.925351-6-efremov@linux.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210818154646.925351-1-efremov@linux.com> References: <20210818154646.925351-1-efremov@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Add basic tests for a floppy with writable disk. "rdwr" test works under following assumptions: - writable disk in "/dev/fd0" To simulate the conditions and automate the testing process there is "run_rdwr.sh". Signed-off-by: Denis Efremov --- tools/testing/selftests/floppy/.gitignore | 1 + tools/testing/selftests/floppy/Makefile | 4 +- tools/testing/selftests/floppy/lib.sh | 4 ++ tools/testing/selftests/floppy/rdwr.c | 67 ++++++++++++++++++++++ tools/testing/selftests/floppy/run_rdwr.sh | 22 +++++++ 5 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/floppy/rdwr.c create mode 100755 tools/testing/selftests/floppy/run_rdwr.sh diff --git a/tools/testing/selftests/floppy/.gitignore b/tools/testing/selftests/floppy/.gitignore index 7642dc0ef281..f53e70197edd 100644 --- a/tools/testing/selftests/floppy/.gitignore +++ b/tools/testing/selftests/floppy/.gitignore @@ -5,3 +5,4 @@ testdir/ empty rdonly +rdwr diff --git a/tools/testing/selftests/floppy/Makefile b/tools/testing/selftests/floppy/Makefile index ed8fdeb79aea..c5d010dd4445 100644 --- a/tools/testing/selftests/floppy/Makefile +++ b/tools/testing/selftests/floppy/Makefile @@ -1,8 +1,8 @@ # SPDX-License-Identifier: GPL-2.0 CFLAGS := -static -I../../../../usr/include -TEST_PROGS := run_empty.sh run_rdonly.sh -TEST_GEN_FILES := init empty rdonly +TEST_PROGS := run_empty.sh run_rdonly.sh run_rdwr.sh +TEST_GEN_FILES := init empty rdonly rdwr TEST_FILES := lib.sh include ../lib.mk diff --git a/tools/testing/selftests/floppy/lib.sh b/tools/testing/selftests/floppy/lib.sh index 9988be187bc9..0eab702b355a 100644 --- a/tools/testing/selftests/floppy/lib.sh +++ b/tools/testing/selftests/floppy/lib.sh @@ -61,3 +61,7 @@ run_qemu_rdonly_fat() { $run -drive file=fat:floppy:"$1",index=0,if=floppy,readonly } +run_qemu_rdwr_img() { + detect_debug "$2" + $run -drive file="$1",index=0,if=floppy,format=raw +} diff --git a/tools/testing/selftests/floppy/rdwr.c b/tools/testing/selftests/floppy/rdwr.c new file mode 100644 index 000000000000..44ad18701530 --- /dev/null +++ b/tools/testing/selftests/floppy/rdwr.c @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include "../kselftest_harness.h" + +FIXTURE(floppy) { + const char *dev; +}; + +FIXTURE_SETUP(floppy) +{ + int fd; + struct floppy_drive_params params; + + self->dev = "/dev/fd0"; + if (access(self->dev, F_OK)) + ksft_exit_skip("No floppy device found\n"); + if (access(self->dev, R_OK)) + ksft_exit_skip("Floppy is not read accessible\n"); + if (access(self->dev, W_OK)) + ksft_exit_skip("Floppy is not write accessible\n"); + + fd = open("/dev/fd0", O_ACCMODE|O_NDELAY); + EXPECT_EQ(0, ioctl(fd, FDGETDRVPRM, ¶ms)); + params.flags |= FD_DEBUG; + EXPECT_EQ(0, ioctl(fd, FDSETDRVPRM, ¶ms)); + close(fd); +} + +FIXTURE_TEARDOWN(floppy) +{ +} + +TEST_F(floppy, write) +{ +#define TEST_DATA "TEST_WRITE" + int fd; + char test[] = TEST_DATA; + + fd = open(self->dev, O_RDWR); + ASSERT_GT(fd, 0); + + ASSERT_EQ(sizeof(test), write(fd, test, sizeof(test))); + ASSERT_EQ(sizeof(test), read(fd, test, sizeof(test))); + ASSERT_NE(0, strncmp(TEST_DATA, test, sizeof(TEST_DATA))); + + ASSERT_EQ(close(fd), 0); +#undef TEST_DATA +} + +TEST_F(floppy, ioctl_disk_writable) +{ + int fd; + struct floppy_drive_struct drive; + + fd = open(self->dev, O_RDONLY|O_NDELAY); + ASSERT_GT(fd, 0); + ASSERT_EQ(0, ioctl(fd, FDGETDRVSTAT, &drive)); + ASSERT_TRUE(drive.flags & FD_DISK_WRITABLE); + ASSERT_EQ(close(fd), 0); +} + +TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/floppy/run_rdwr.sh b/tools/testing/selftests/floppy/run_rdwr.sh new file mode 100755 index 000000000000..0ebe8bd6bc69 --- /dev/null +++ b/tools/testing/selftests/floppy/run_rdwr.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 + +set -e + +source "$(dirname $0)"/lib.sh + +while getopts d flag; do + case "${flag}" in + d) debug=1;; + esac +done + +if [ -z $debug ]; then + trap "rm -rf testdir" EXIT +fi +mkdir -p testdir +head -c 1474560 /dev/zero > testdir/floppy.raw + +gen_cpio_list rdwr +gen_initrd rdwr +run_qemu_rdwr_img testdir/floppy.raw $debug