]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
sg: add regression test for patch scsi: sg: fix SG_DXFER_FROM_DEV transfers
authorJohannes Thumshirn <jthumshirn@suse.de>
Thu, 6 Jul 2017 12:09:21 +0000 (14:09 +0200)
committerOmar Sandoval <osandov@fb.com>
Fri, 14 Jul 2017 17:33:19 +0000 (10:33 -0700)
Add a regression test for the patch titled "scsi: sg: fix
SG_DXFER_FROM_DEV transfers" which reassembles the syscalls done by Nero
Burning ROM to discover CD and DVD burners.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
[Omar: rename _get_sg_from_blockdev to _get_test_dev_sg and fix sg/001]
Signed-off-by: Omar Sandoval <osandov@fb.com>
common/sg
src/.gitignore
src/Makefile
src/sg/dxfer-from-dev.c [new file with mode: 0644]
tests/sg/001
tests/sg/002 [new file with mode: 0755]
tests/sg/002.out [new file with mode: 0644]

index c306af5003507cbc7789be6a5af5312322ed0a2e..d9fcc0e15909fad2dec51dd1ef2dc1cc7c5c4367 100644 (file)
--- a/common/sg
+++ b/common/sg
@@ -29,6 +29,6 @@ _test_dev_is_scsi() {
        return 0
 }
 
-_get_sg_from_blockdev() {
-       echo /sys/block/"$1"/device/scsi_generic/sg+([0-9])
+_get_test_dev_sg() {
+       echo "${TEST_DEV_SYSFS}"/device/scsi_generic/sg* | grep -Eo "sg[0-9]+"
 }
index 722c137c7fca866f2bce13470d18b52cb2206cec..0fca08a74fb1f4e7c94a6893be94f7be4c106e19 100644 (file)
@@ -1 +1,2 @@
 /sg/syzkaller1
+/sg/dxfer-from-dev
index 0e8d74688db4d0644ab08fc707c6603d8e053257..e6dc0a1ca6926619807b05c3f712dbccb3d64a73 100644 (file)
@@ -1,4 +1,4 @@
-TARGETS := sg/syzkaller1
+TARGETS := sg/dxfer-from-dev sg/syzkaller1
 
 CFLAGS := -O2
 
diff --git a/src/sg/dxfer-from-dev.c b/src/sg/dxfer-from-dev.c
new file mode 100644 (file)
index 0000000..ca52f30
--- /dev/null
@@ -0,0 +1,57 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <scsi/sg.h>
+
+int main(int argc, char **argv)
+{
+       int fd;
+       int rc;
+       int rsz = 131072;
+       int tout = 10800000;
+       char buf[42] = { 0 };
+
+       if (argc != 2) {
+               printf("usage: %s /dev/sgX\n", argv[0]);
+               return 1;
+       }
+
+       fd = open(argv[1], O_RDWR);
+       if (fd < 0) {
+               perror("open");
+               return 1;
+       }
+
+       rc = ioctl(fd, SG_SET_RESERVED_SIZE, &rsz);
+       if (rc < 0) {
+               perror("ioctl SG_SET_RESERVED_SIZE");
+               goto out_close;
+       }
+
+       rc = ioctl(fd, SG_SET_TIMEOUT, &tout);
+       if (rc < 0) {
+               perror("ioctl SG_SET_TIMEOUT");
+               goto out_close;
+       }
+
+       buf[4] = 'H';
+       rc = write(fd, &buf, sizeof(buf));
+       if (rc < 0) {
+               perror("write");
+               if (errno == EINVAL)
+                       printf("FAIL\n");
+               goto out_close;
+       }
+
+       printf("PASS\n");
+
+out_close:
+       close(fd);
+}
index b5a14acc821e62cdbca061c90eac5c2a8d110fc7..a1dbd0cd778dd453c0405e5b351c867ef42cbdc2 100755 (executable)
@@ -30,7 +30,7 @@ requires() {
 test_device() {
        echo "Running ${TEST_NAME}"
 
-       SG_DEV="/dev/$(_get_sg_from_blockdev "$SCSI_DEBUG_NAME")"
+       SG_DEV="/dev/$(_get_test_dev_sg)"
        cd "$TMPDIR" || return 1
        timeout -s INT 10s "$SRCDIR/sg/syzkaller1" "$SG_DEV"
 
diff --git a/tests/sg/002 b/tests/sg/002
new file mode 100755 (executable)
index 0000000..42470a6
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/bash
+#
+# Regression test for patch "scsi: sg: fix SG_DXFER_FROM_DEV transfers"
+#
+# 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/>.
+
+DESCRIPTION="perfom a SG_DXFER_FROM_DEV from the /dev/sg read-write interface"
+QUICK=1
+
+requires() {
+       _have_src_program sg/dxfer-from-dev
+}
+
+test_device() {
+       echo "Running ${TEST_NAME}"
+
+       SG_DEV="/dev/$(_get_test_dev_sg)"
+       "$SRCDIR"/sg/dxfer-from-dev "$SG_DEV"
+
+       echo "Test complete"
+}
diff --git a/tests/sg/002.out b/tests/sg/002.out
new file mode 100644 (file)
index 0000000..77b4bc1
--- /dev/null
@@ -0,0 +1,3 @@
+Running sg/002
+PASS
+Test complete