mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/4] Add new media test and regression test scripts
@ 2016-06-18  0:24 Shuah Khan
  2016-06-18  0:24 ` [PATCH 1/4] selftests: media_device_test change it to randomize loop count Shuah Khan
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Shuah Khan @ 2016-06-18  0:24 UTC (permalink / raw)
  To: shuah; +Cc: Shuah Khan, linux-kselftest, linux-kernel

This patch series changes an exixtsing test to randomize the loop count,
adds a new test, and regression test scripts, and regression test how to.

Shuah Khan (4):
  selftests: media_device_test change it to randomize loop count
  selftests: add media_device_open test
  selftests: add media controller regression test scripts and document
  selftests: media_tests - Add media_device_open to .gitignore

 tools/testing/selftests/media_tests/.gitignore     |  1 +
 tools/testing/selftests/media_tests/Makefile       |  4 +-
 .../selftests/media_tests/bind_unbind_sample.sh    | 13 ++++
 .../selftests/media_tests/media_device_open.c      | 81 ++++++++++++++++++++++
 .../selftests/media_tests/media_device_test.c      | 19 +++--
 .../selftests/media_tests/open_loop_test.sh        | 10 +++
 .../selftests/media_tests/regression_test.txt      | 43 ++++++++++++
 7 files changed, 163 insertions(+), 8 deletions(-)
 create mode 100755 tools/testing/selftests/media_tests/bind_unbind_sample.sh
 create mode 100644 tools/testing/selftests/media_tests/media_device_open.c
 create mode 100755 tools/testing/selftests/media_tests/open_loop_test.sh
 create mode 100644 tools/testing/selftests/media_tests/regression_test.txt

-- 
2.7.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] selftests: media_device_test change it to randomize loop count
  2016-06-18  0:24 [PATCH 0/4] Add new media test and regression test scripts Shuah Khan
@ 2016-06-18  0:24 ` Shuah Khan
  2016-06-18  0:24 ` [PATCH 2/4] selftests: add media_device_open test Shuah Khan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Shuah Khan @ 2016-06-18  0:24 UTC (permalink / raw)
  To: shuah; +Cc: Shuah Khan, linux-kselftest, linux-kernel

Change it to randomize the loop count instead of hardcoded number of times
ioctl is called.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 .../testing/selftests/media_tests/media_device_test.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/media_tests/media_device_test.c b/tools/testing/selftests/media_tests/media_device_test.c
index cbf53a0..5d49943 100644
--- a/tools/testing/selftests/media_tests/media_device_test.c
+++ b/tools/testing/selftests/media_tests/media_device_test.c
@@ -1,5 +1,5 @@
 /*
- * media_devkref_test.c - Media Controller Device Kref API Test
+ * media_device_test.c - Media Controller Device ioctl loop Test
  *
  * Copyright (c) 2016 Shuah Khan <shuahkh@osg.samsung.com>
  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
@@ -35,13 +35,14 @@
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
+#include <time.h>
 #include <linux/media.h>
 
 int main(int argc, char **argv)
 {
 	int opt;
 	char media_device[256];
-	int count = 0;
+	int count;
 	struct media_device_info mdi;
 	int ret;
 	int fd;
@@ -69,6 +70,10 @@ int main(int argc, char **argv)
 		exit(-1);
 	}
 
+	/* Generate random number of interations */
+	srand((unsigned int) time(NULL));
+	count = rand();
+
 	/* Open Media device and keep it open */
 	fd = open(media_device, O_RDWR);
 	if (fd == -1) {
@@ -82,14 +87,16 @@ int main(int argc, char **argv)
 	       "other Oops in the dmesg. Enable KaSan kernel\n"
 	       "config option for use-after-free error detection.\n\n");
 
-	while (count < 100) {
+	printf("Running test for %d iternations\n", count);
+
+	while (count > 0) {
 		ret = ioctl(fd, MEDIA_IOC_DEVICE_INFO, &mdi);
 		if (ret < 0)
 			printf("Media Device Info errno %s\n", strerror(errno));
 		else
-			printf("Media device model %s driver %s\n",
-				mdi.model, mdi.driver);
+			printf("Media device model %s driver %s - count %d\n",
+				mdi.model, mdi.driver, count);
 		sleep(10);
-		count++;
+		count--;
 	}
 }
-- 
2.7.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/4] selftests: add media_device_open test
  2016-06-18  0:24 [PATCH 0/4] Add new media test and regression test scripts Shuah Khan
  2016-06-18  0:24 ` [PATCH 1/4] selftests: media_device_test change it to randomize loop count Shuah Khan
@ 2016-06-18  0:24 ` Shuah Khan
  2016-06-18  0:24 ` [PATCH 3/4] selftests: add media controller regression test scripts and document Shuah Khan
  2016-06-18  0:24 ` [PATCH 4/4] selftests: media_tests - Add media_device_open to .gitignore Shuah Khan
  3 siblings, 0 replies; 5+ messages in thread
From: Shuah Khan @ 2016-06-18  0:24 UTC (permalink / raw)
  To: shuah; +Cc: Shuah Khan, linux-kselftest, linux-kernel

Add a new media test to open, run ioctl, and close the media device file.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 tools/testing/selftests/media_tests/Makefile       |  4 +-
 .../selftests/media_tests/media_device_open.c      | 81 ++++++++++++++++++++++
 2 files changed, 83 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/selftests/media_tests/media_device_open.c

diff --git a/tools/testing/selftests/media_tests/Makefile b/tools/testing/selftests/media_tests/Makefile
index 7071bcc..177256a 100644
--- a/tools/testing/selftests/media_tests/Makefile
+++ b/tools/testing/selftests/media_tests/Makefile
@@ -1,7 +1,7 @@
-TEST_PROGS := media_device_test
+TEST_PROGS := media_device_test media_device_open
 all: $(TEST_PROGS)
 
 include ../lib.mk
 
 clean:
-	rm -fr media_device_test
+	rm -fr media_device_test media_device_open
diff --git a/tools/testing/selftests/media_tests/media_device_open.c b/tools/testing/selftests/media_tests/media_device_open.c
new file mode 100644
index 0000000..44343c0
--- /dev/null
+++ b/tools/testing/selftests/media_tests/media_device_open.c
@@ -0,0 +1,81 @@
+/*
+ * media_device_open.c - Media Controller Device Open Test
+ *
+ * Copyright (c) 2016 Shuah Khan <shuahkh@osg.samsung.com>
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * This file is released under the GPLv2.
+ */
+
+/*
+ * This file adds a test for Media Controller API.
+ * This test should be run as root and should not be
+ * included in the Kselftest run. This test should be
+ * run when hardware and driver that makes use Media
+ * Controller API are present in the system.
+ *
+ * This test opens user specified Media Device and calls
+ * MEDIA_IOC_DEVICE_INFO ioctl, closes the file, and exits.
+ *
+ * Usage:
+ *	sudo ./media_device_open -d /dev/mediaX
+ *
+ *	Run this test is a loop and run bind/unbind on the driver.
+*/
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <linux/media.h>
+
+int main(int argc, char **argv)
+{
+	int opt;
+	char media_device[256];
+	int count = 0;
+	struct media_device_info mdi;
+	int ret;
+	int fd;
+
+	if (argc < 2) {
+		printf("Usage: %s [-d </dev/mediaX>]\n", argv[0]);
+		exit(-1);
+	}
+
+	/* Process arguments */
+	while ((opt = getopt(argc, argv, "d:")) != -1) {
+		switch (opt) {
+		case 'd':
+			strncpy(media_device, optarg, sizeof(media_device) - 1);
+			media_device[sizeof(media_device)-1] = '\0';
+			break;
+		default:
+			printf("Usage: %s [-d </dev/mediaX>]\n", argv[0]);
+			exit(-1);
+		}
+	}
+
+	if (getuid() != 0) {
+		printf("Please run the test as root - Exiting.\n");
+		exit(-1);
+	}
+
+	/* Open Media device and keep it open */
+	fd = open(media_device, O_RDWR);
+	if (fd == -1) {
+		printf("Media Device open errno %s\n", strerror(errno));
+		exit(-1);
+	}
+
+	ret = ioctl(fd, MEDIA_IOC_DEVICE_INFO, &mdi);
+	if (ret < 0)
+		printf("Media Device Info errno %s\n", strerror(errno));
+	else
+		printf("Media device model %s driver %s\n",
+			mdi.model, mdi.driver);
+}
-- 
2.7.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/4] selftests: add media controller regression test scripts and document
  2016-06-18  0:24 [PATCH 0/4] Add new media test and regression test scripts Shuah Khan
  2016-06-18  0:24 ` [PATCH 1/4] selftests: media_device_test change it to randomize loop count Shuah Khan
  2016-06-18  0:24 ` [PATCH 2/4] selftests: add media_device_open test Shuah Khan
@ 2016-06-18  0:24 ` Shuah Khan
  2016-06-18  0:24 ` [PATCH 4/4] selftests: media_tests - Add media_device_open to .gitignore Shuah Khan
  3 siblings, 0 replies; 5+ messages in thread
From: Shuah Khan @ 2016-06-18  0:24 UTC (permalink / raw)
  To: shuah; +Cc: Shuah Khan, linux-kselftest, linux-kernel

Add regression test scripts open_loop_test.sh, and bind_unbind_sample.sh.
Also add regression_test.txt that describes the regression test procedure.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 .../selftests/media_tests/bind_unbind_sample.sh    | 13 +++++++
 .../selftests/media_tests/open_loop_test.sh        | 10 +++++
 .../selftests/media_tests/regression_test.txt      | 43 ++++++++++++++++++++++
 3 files changed, 66 insertions(+)
 create mode 100755 tools/testing/selftests/media_tests/bind_unbind_sample.sh
 create mode 100755 tools/testing/selftests/media_tests/open_loop_test.sh
 create mode 100644 tools/testing/selftests/media_tests/regression_test.txt

diff --git a/tools/testing/selftests/media_tests/bind_unbind_sample.sh b/tools/testing/selftests/media_tests/bind_unbind_sample.sh
new file mode 100755
index 0000000..2b24743
--- /dev/null
+++ b/tools/testing/selftests/media_tests/bind_unbind_sample.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+# Find device number in /sys/bus/usb/drivers/drivername
+# Edit this file to update the driver numer and name
+# Example test for uvcvideo driver
+#i=0
+# while :; do
+#  i=$((i+1))
+#  echo 1-5:1.0 > /sys/bus/usb/drivers/uvcvideo/unbind;
+#  echo 1-5:1.0 > /sys/bus/usb/drivers/uvcvideo/bind;
+#  clear
+#	echo $i
+#done
+
diff --git a/tools/testing/selftests/media_tests/open_loop_test.sh b/tools/testing/selftests/media_tests/open_loop_test.sh
new file mode 100755
index 0000000..dcd3c17
--- /dev/null
+++ b/tools/testing/selftests/media_tests/open_loop_test.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+ i=0
+file=/dev/media$1
+ while :; do
+  echo $file
+  i=$((i+1))
+  R=$(./media_device_open -d $file);
+ # clear
+  echo -e "Loop $i\n$R"
+ done
diff --git a/tools/testing/selftests/media_tests/regression_test.txt b/tools/testing/selftests/media_tests/regression_test.txt
new file mode 100644
index 0000000..2627367
--- /dev/null
+++ b/tools/testing/selftests/media_tests/regression_test.txt
@@ -0,0 +1,43 @@
+Testing for regressions in Media Controller API register, ioctl, syscall,
+and unregister paths. There have a few problems that result in user-after
+free on media_device, media_devnode, and cdev pointers when the driver is
+unbound while ioctl is in progress.
+
+Test Procedure:
+
+Run bin/unbind loop while ioctls are in progress.
+Run rmmod and modprobe.
+Disconnect the device.
+
+Setup:
+
+Build media_device_test
+cd tools/testing/selftests/media_tests
+make
+
+Regressions test for cdev user-after free error on /dev/mediaX when driver
+is unbound:
+
+Start media_device_test to regression test media devnode dynamic alloc
+and cdev user-after-free fixes. This opens media dev files and sits in
+a loop running media ioctl MEDIA_IOC_DEVICE_INFO command once every 10
+seconds. The idea is when device file goes away, media devnode and cdev
+should stick around until this test exits.
+
+The test for a random number of iterations or until user kills it with a
+sleep 10 in between the ioctl calls.
+
+sudo ./media_device_test -d /dev/mediaX
+
+Regression test for media_devnode unregister race with ioctl_syscall:
+
+Start 6 open_loop_test.sh tests with different /dev/mediaX files. When
+device file goes away after unbind, device file name changes. Start the
+test with possible device names. If we start with /dev/media0 for example,
+after unbind, /dev/media1 or /dev/media2 could get created. The idea is
+keep ioctls going while bind/unbind runs.
+
+Copy bind_unbind_sample.txt and make changes to specify the driver name
+and number to run bind and unbind. Start the bind_unbind.sh
+
+Run dmesg looking for any user-after free errors or mutex lock errors.
-- 
2.7.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 4/4] selftests: media_tests - Add media_device_open to .gitignore
  2016-06-18  0:24 [PATCH 0/4] Add new media test and regression test scripts Shuah Khan
                   ` (2 preceding siblings ...)
  2016-06-18  0:24 ` [PATCH 3/4] selftests: add media controller regression test scripts and document Shuah Khan
@ 2016-06-18  0:24 ` Shuah Khan
  3 siblings, 0 replies; 5+ messages in thread
From: Shuah Khan @ 2016-06-18  0:24 UTC (permalink / raw)
  To: shuah; +Cc: Shuah Khan, linux-kselftest, linux-kernel

Add media_device_open to .gitignore

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 tools/testing/selftests/media_tests/.gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/media_tests/.gitignore b/tools/testing/selftests/media_tests/.gitignore
index 1c07117..faf5891 100644
--- a/tools/testing/selftests/media_tests/.gitignore
+++ b/tools/testing/selftests/media_tests/.gitignore
@@ -1 +1,2 @@
 media_device_test
+media_device_open
-- 
2.7.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-06-18  0:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-18  0:24 [PATCH 0/4] Add new media test and regression test scripts Shuah Khan
2016-06-18  0:24 ` [PATCH 1/4] selftests: media_device_test change it to randomize loop count Shuah Khan
2016-06-18  0:24 ` [PATCH 2/4] selftests: add media_device_open test Shuah Khan
2016-06-18  0:24 ` [PATCH 3/4] selftests: add media controller regression test scripts and document Shuah Khan
2016-06-18  0:24 ` [PATCH 4/4] selftests: media_tests - Add media_device_open to .gitignore Shuah Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®