Add SCSI generic test group
Subsystems (3)
cover Add SCSI generic test group
Add a test group for the SCSI generic driver and one syzcaller reproducer for this group.
The reprodcuer is distributed as a C program, so the makefile is amended to build C files to be used in the test.
I didn't get the TIMEOUT to work (not even with block/001) so I decided to just require the 'timeout' program in my testcase.
Johannes Thumshirn (3):
Add ability to build test-cases
tests/sg: add SCSI generic test grouop
sg/001: add regression test for syzcaller generated GPF
Makefile | 26 +++- common/sg | 22 +++ src/.gitignore | 1 + src/Makefile | 14 ++ src/sg-001.c | 430 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/sg/001 | 48 +++++++ tests/sg/001.out | 2 + tests/sg/group | 40 ++++++ 8 files changed, 582 insertions(+), 1 deletion(-) create mode 100644 common/sg create mode 100644 src/.gitignore create mode 100644 src/Makefile create mode 100644 src/sg-001.c create mode 100755 tests/sg/001 create mode 100644 tests/sg/001.out create mode 100644 tests/sg/group
Signature · 1 line
2.12.0
PATCH 1/3 Add ability to build test-cases
Add the ability to build test cases from C files. This is handy for things like syzcaller reproducers and all other kinds of test binaries.
--- Makefile | 26 +++- src/.gitignore | 1 + src/Makefile | 14 ++ src/sg-001.c | 430 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 470 insertions(+), 1 deletion(-) create mode 100644 src/.gitignore create mode 100644 src/Makefile create mode 100644 src/sg-001.c
Makefile +25 -1
@@ -1,7 +1,31 @@ +ifeq ("$(origin V)", "command line") + BUILD_VERBOSE = $(V) +else + BUILD_VERBOSE = 0 +endif +ifndef BUILD_VERBOSE + BUILD_VERBOSE = 0 +endif + +ifeq ($(BUILD_VERBOSE),1) + Q = +else + Q = @ +endif + +MAKEOPTS = --no-print-directory Q=$(Q) + +SUBDIRS = src +default: + $(Q)$(MAKE) $(MAKEOPTS) -C $(SUBDIRS) + +clean: + $(Q)$(MAKE) $(MAKEOPTS) -C $(SUBDIRS) clean + all: @echo "Please read README.md" shellcheck: shellcheck -x -f gcc check new common/* tests/*/[0-9]*[0-9] -.PHONY: all shellcheck +.PHONY: all shellcheck clean
src/.gitignore new file +1 -0
@@ -0,0 +1 @@ +sg-001
src/Makefile new file +14 -0
@@ -0,0 +1,14 @@ +CC = gcc +CFLAGS = -O2 + +TARGETS = sg-001 + +FILES = $(TARGETS:=.c) + +$(TARGETS): + @echo " [CC] $@" + $(Q)$(CC) [email protected] -o $@ $(CFLAGS) + +clean: + @echo " [CLEAN] $(notdir $(CURDIR))" + $(Q)rm -f $(TARGETS) *.o
src/sg-001.c new file +430 -0
430 lines not on this page · raw message
Signature · 1 line
2.12.0
PATCH 2/3 tests/sg: add SCSI generic test grouop
In reply to Johannes ThumshirnAdd a test group for tests of the SCSI generic driver and and functions common to the SCSI generic driver and it's test cases.
--- common/sg | 22 ++++++++++++++++++++++ tests/sg/group | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 common/sg create mode 100644 tests/sg/group
common/sg new file +22 -0
@@ -0,0 +1,22 @@ +#!/bin/bash +# +# SCSI generic helper functions. +# +# Copyright (C) 2017 Johannes Thumshirn +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +_have_scsi_generic() { + _have_module sg +}
tests/sg/group new file +40 -0
@@ -0,0 +1,40 @@ +#!/bin/bash +# +# Regression tests for SCSI generic device +# +# Copyright (C) 2017 Johannes Thumshirn <[email protected]> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. common/sg + +group_requires() { + _have_scsi_generic +} + +# TODO: if this test group has extra requirements for what devices it can be +# run on, it should define a group_device_requires() function. If tests in this +# group can be run on the test device, it should return zero. Otherwise, it +# should return non-zero and set the $SKIP_REASON variable. $TEST_DEV is the +# full path of the block device (e.g., /dev/nvme0n1 or /dev/sda1), and +# $TEST_DEV_SYSFS is the sysfs path of the disk (not the partition, e.g., +# /sys/block/nvme0n1 or /sys/block/sda). +# +# Usually, group_device_requires() just needs to check that the test device is +# the right type of hardware or supports any necessary features using the +# _test_dev_foo helpers. If group_device_requires() returns non-zero, all tests +# in this group will be skipped on that device. +# group_device_requires() { +# _test_dev_is_foo && _test_dev_supports_bar +# }
Signature · 1 line
2.12.0
PATCH 3/3 sg/001: add regression test for syzcaller generated GPF
In reply to Johannes ThumshirnAdd a regression test for commit 48ae8484e9fc ("scsi: sg: don't return bogus Sg_requests"). This is a general protection fault triggered by syzcaller.
--- tests/sg/001 | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/sg/001.out | 2 ++ 2 files changed, 50 insertions(+) create mode 100755 tests/sg/001 create mode 100644 tests/sg/001.out
tests/sg/001 new file +48 -0
@@ -0,0 +1,48 @@ +#!/bin/bash +# +# Regression test for commit 48ae8484e9fc ("scsi: sg: don't return bogus Sg_requests") +# +# Copyright (C) 2017 Johannes Thumshirn <[email protected]> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. common/sg +. common/scsi_debug + +DESCRIPTION="Regression test for commit 48ae8484e9fc (\"scsi: sg: don't return bogus Sg_requests\")" +TIMED=1 +QUICK=1 + +requires() { + _have_program src/sg-001 \ + _have_program timeout \ + && _have_scsi_debug \ + && _have_scsi_generic +} + + +test() { + echo "Running ${TEST_NAME}" + + if ! _get_scsi_debug_dev; then + return 1 + fi + + _divide_timeout 2 + timeout -s INT 10s ./src/sg-001 + + _put_scsi_debug_dev + + echo "Test complete" +}
tests/sg/001.out new file +2 -0
@@ -0,0 +1,2 @@ +Running sg/001 +Test complete
Signature · 1 line
2.12.0
All SG_IO test should also apply to block device nodes that support the ioctl..
Quoted 3 lines · Christoph Hellwig
All
SG_IOtest should also apply to block device nodes that support the ioctl..
But these are not necessarily SG_IO tests, are they?
The test included is doesn't hit the SG_IO path in the sg driver, but the sg_read path.
Of cause we can make a generic sg_io tool but IMHO it's quite convenient to just throw in the reproducers we get.
And as it exercises the /dev/sg character device I decided to make a new group.
Johannes
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH blktests 2/3] tests/sg: add SCSI generic test grouop
In reply to Johannes ThumshirnQuoted 21 lines · Johannes Thumshirn
Add a test group for tests of the SCSI generic driver and and functions common to the SCSI generic driver and it's test cases.
Signed-off-by Johannes Thumshirn <[email protected]>--- common/sg | 22 ++++++++++++++++++++++ tests/sg/group | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 common/sg create mode 100644 tests/sg/groupcommon/sg new file +5
-0+# TODO: if this test group has extra requirements for what devices it can be +# run on, it should define a group_device_requires() function. If tests in this +# group can be run on the test device, it should return zero. Otherwise, it +# should return non-zero and set the $SKIP_REASON variable. $TEST_DEV is the +# full path of the block device (e.g., /dev/nvme0n1 or /dev/sda1), and
common/sg
Quoted 10 lines
common/sg new file +10
-0+# $TEST_DEV_SYSFS is the sysfs path of the disk (not the partition, e.g., +# /sys/block/nvme0n1 or /sys/block/sda). +# +# Usually, group_device_requires() just needs to check that the test device is +# the right type of hardware or supports any necessary features using the +# _test_dev_foo helpers. If group_device_requires() returns non-zero, all tests +# in this group will be skipped on that device. +# group_device_requires() { +# _test_dev_is_foo && _test_dev_supports_bar +# }
Leftover TODO, I'll remove it when applying. If we add an sg test that runs on an actual device, we can define group_device_requires().
Re: [PATCH blktests 3/3] sg/001: add regression test for syzcaller generated GPF
In reply to Johannes ThumshirnQuoted 31 lines · Johannes Thumshirn
Add a regression test for commit
48ae8484e9fc("scsi: sg: don't return bogusSg_requests"). This is a general protection fault triggered by syzcaller.Signed-off-by Johannes Thumshirn <[email protected]>--- tests/sg/001 | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/sg/001.out | 2 ++ 2 files changed, 50 insertions(+) create mode 100755 tests/sg/001 create mode 100644 tests/sg/001.outtests/sg/001 new file +13
-0@@ -0,0 +1,48 @@ +#!/bin/bash +# +# Regression test for commit 48ae8484e9fc ("scsi: sg: don't return bogus Sg_requests") +# +# Copyright (C) 2017 Johannes Thumshirn <[email protected]> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of
tests/sg/001 line 23
Quoted 10 lines
tests/sg/001 new file +10
-0+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. common/sg +. common/scsi_debug + +DESCRIPTION="Regression test for commit 48ae8484e9fc (\"scsi: sg: don't return bogus Sg_requests\")"
This description doesn't really say what the test does. If this test fails, the person running it should be able to know what the test is doing without having to decode the syzkaller reproducer. I'd prefer something like:
DESCRIPTION="do bogus sg reads and writes"
Or something like that, that's my best attempt at understanding the reproducer :)
tests/sg/001 line 29
Quoted 6 lines
tests/sg/001 new file +6
-0+TIMED=1 +QUICK=1 + +requires() { + _have_program src/sg-001 \ + _have_program timeout \
timeout is part of coreutils so this isn't necessary.
tests/sg/001 line 42
Quoted 13 lines
tests/sg/001 new file +13
-0+ && _have_scsi_debug \ + && _have_scsi_generic +} + + +test() { + echo "Running ${TEST_NAME}" + + if ! _get_scsi_debug_dev; then + return 1 + fi + + _divide_timeout 2
You don't use $TIMEOUT in this test, so remove this and the TIMED=1. The arbitrary timeout is fine for this kind of test, I think.
Quoted 17 lines
tests/sg/001 new file +6
-0+ timeout -s INT 10s ./src/sg-001 + + _put_scsi_debug_dev + + echo "Test complete" +}tests/sg/001.out new file +2
-0@@ -0,0 +1,2 @@ +Running sg/001 +Test completeSignature · 1 line
2.12.0
Re: [PATCH blktests 2/3] tests/sg: add SCSI generic test grouop
In reply to Omar SandovalQuoted 27 lines · Omar Sandoval
Quoted 26 lines · Johannes Thumshirn
Add a test group for tests of the SCSI generic driver and and functions common to the SCSI generic driver and it's test cases.
Signed-off-by Johannes Thumshirn <[email protected]>--- common/sg | 22 ++++++++++++++++++++++ tests/sg/group | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 common/sg create mode 100644 tests/sg/groupcommon/sg new file +10
-0+# TODO: if this test group has extra requirements for what devices it can be +# run on, it should define a group_device_requires() function. If tests in this +# group can be run on the test device, it should return zero. Otherwise, it +# should return non-zero and set the $SKIP_REASON variable. $TEST_DEV is the +# full path of the block device (e.g., /dev/nvme0n1 or /dev/sda1), and +# $TEST_DEV_SYSFS is the sysfs path of the disk (not the partition, e.g., +# /sys/block/nvme0n1 or /sys/block/sda). +# +# Usually, group_device_requires() just needs to check that the test device is +# the right type of hardware or supports any necessary features using the
Quoted 8 lines
common/sg
Quoted 5 lines
common/sg new file +5
-0+# _test_dev_foo helpers. If group_device_requires() returns non-zero, all tests +# in this group will be skipped on that device. +# group_device_requires() { +# _test_dev_is_foo && _test_dev_supports_bar +# }Leftover TODO, I'll remove it when applying. If we add an sg test that runs on an actual device, we can define
group_device_requires().
On second though, since I had some comments for patch 3, just fix this up when you resend.
Quoted 10 lines · Johannes Thumshirn
Quoted 3 lines · Christoph Hellwig
All
SG_IOtest should also apply to block device nodes that support the ioctl..But these are not necessarily
SG_IOtests, are they?The test included is doesn't hit the
SG_IOpath in the sg driver, but thesg_readpath.
Quoted 7 lines
Of cause we can make a generic
sg_iotool but IMHO it's quite convenient to just throw in the reproducers we get.And as it exercises the
/dev/sgcharacter device I decided to make a new group.Johannes
Looking at this some more, it seems like the syzkaller reproducer always bangs on /dev/sg0. How hard would it be to adapt it to run on the sg device for every test device instead?
Quoted 3 lines · Omar Sandoval
Looking at this some more, it seems like the syzkaller reproducer always bangs on
/dev/sg0. How hard would it be to adapt it to run on the sg device for every test device instead?
Can't be too hard I guess ;-).
Maybe I can even clean it up a bit so it compiles with the "-Wall -Wextra -Werror" trinity.
I'll send you a v2 once I'm done with it (and all other comments).
Byte,
Johannes
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Quoted 9 lines · Johannes Thumshirn
Quoted 3 lines · Christoph Hellwig
All
SG_IOtest should also apply to block device nodes that support the ioctl..But these are not necessarily
SG_IOtests, are they?The test included is doesn't hit the
SG_IOpath in the sg driver, but thesg_readpath.
Oh, you're right.
Quoted 6 lines
Of cause we can make a generic
sg_iotool but IMHO it's quite convenient to just throw in the reproducers we get.And as it exercises the
/dev/sgcharacter device I decided to make a new group.
Yeah, makes sense. And any SG_IO test should be able to run on both block device nodes and sg nodes.