diff mbox

[PATCHv2,2/3] test: add streaming test to driver_data tester

Message ID 1495262948-1106-3-git-send-email-yi1.li@linux.intel.com (mailing list archive)
State New
Headers show

Commit Message

Li, Yi May 20, 2017, 6:49 a.m. UTC
From: Yi Li <yi1.li@linux.intel.com>

This adds streaming test case, which pre-allocate the buffer and ask
driver_data_request_sync API to read 4KB each. Since the dummy firmware
image is very small, the test only stream couple bytes.
A manual test method:
echo -n 'bigfile' > /sys/devices/virtual/misc/test_driver_data0/config_name
echo -n 0 > /sys/devices/virtual/misc/test_driver_data0/config_async
echo -n 1 > /sys/devices/virtual/misc/test_driver_data0/config_stream
echo -n 1 > /sys/devices/virtual/misc/test_driver_data0/config_no_cache
echo -n 1 > /sys/devices/virtual/misc/test_driver_data0/trigger_config

Signed-off-by: Yi Li <yi1.li@linux.intel.com>
---
 lib/test_driver_data.c                          | 80 ++++++++++++++++++++++++-
 tools/testing/selftests/firmware/driver_data.sh | 32 ++++++++++
 2 files changed, 110 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/lib/test_driver_data.c b/lib/test_driver_data.c
index 13fb091..9cca0b7 100644
--- a/lib/test_driver_data.c
+++ b/lib/test_driver_data.c
@@ -72,6 +72,8 @@  int num_test_devs;
  * @prealloc: if set, driver_data will use preallocated buffer for
  *      firmware_buf->data. The caller need to setup alloc_buf_size and
  *      alloc_buf in the driver_data_req_params structure.
+ * @stream: true if you want to trigger an streaming request. This will use
+ *	driver_data_request_sync() with streaming flag.
  * @enable_opt_cb: whether or not the optional callback should be set
  *	on a trigger. There is no equivalent setting on the struct
  *	driver_data_req_params as this is implementation specific, and in
@@ -118,6 +120,7 @@  struct test_config {
 	char *name;
 	char *default_name;
 	bool async;
+	bool stream;
 	bool optional;
 	bool keep;
 	bool no_cache;
@@ -353,6 +356,9 @@  static ssize_t config_show(struct device *dev,
 	len += snprintf(buf+len, PAGE_SIZE,
 			"prealloc:\t\t%s\n",
 			config->prealloc ? "true" : "false");
+	len += snprintf(buf+len, PAGE_SIZE,
+			"stream:\t\t%s\n",
+			config->stream ? "true" : "false");
 
 	mutex_unlock(&test_dev->config_mutex);
 
@@ -502,6 +508,47 @@  static int trigger_config_sync(struct driver_data_test_device *test_dev)
 	return ret;
 }
 
+static int trigger_config_stream(struct driver_data_test_device *test_dev)
+{
+	struct test_config *config = &test_dev->config;
+	int ret;
+	char *path = NULL;
+	void *buf;
+	loff_t offset = 0;
+	size_t length = INT_MAX;
+	const struct driver_data_req_params req_params_default = {
+		DRIVER_DATA_DEFAULT_SYNC_REQS(config_sync_req_cb, test_dev,
+					      DRIVER_DATA_REQ_NO_CACHE |
+					      DRIVER_DATA_REQ_STREAMING),
+		.alloc_buf_size = SZ_4K,
+		.alloc_buf = &buf,
+		.img_offset = &offset,
+		.path = &path,
+	};
+	const struct driver_data_req_params *req_params = &req_params_default;
+
+	buf = kmalloc(SZ_4K, GFP_KERNEL);
+	if (!buf) {
+		dev_err(test_dev->dev, "%s: kmalloc buf failed\n", __func__);
+		return -ENOMEM;
+	}
+
+	while (length > 0) {
+		ret = driver_data_request_sync(config->name, req_params,
+					       test_dev->dev);
+		if (ret)
+			dev_err(test_dev->dev, "sync load of '%s' failed: %d\n",
+				config->name, ret);
+		length -= test_dev->test_driver_data.size;
+		offset += test_dev->test_driver_data.size;
+		if (test_dev->test_driver_data.size < SZ_4K)
+			break;
+	}
+
+	kfree(buf);
+	return ret;
+}
+
 static void config_async_req_cb(const struct firmware *driver_data,
 				void *context, int unused_error)
 {
@@ -636,8 +683,12 @@  trigger_config_store(struct device *dev,
 
 	if (config->async)
 		ret = trigger_config_async(test_dev);
-	else
-		ret = trigger_config_sync(test_dev);
+	else {
+		if (config->stream)
+			ret = trigger_config_stream(test_dev);
+		else
+			ret = trigger_config_sync(test_dev);
+	}
 
 	config->test_result = ret;
 
@@ -707,6 +758,7 @@  static int __driver_data_config_init(struct test_config *config)
 		goto out;
 
 	config->async = false;
+	config->stream = false;
 	config->optional = false;
 	config->keep = false;
 	config->no_cache = false;
@@ -985,6 +1037,29 @@  static ssize_t config_async_show(struct device *dev,
 }
 static DEVICE_ATTR(config_async, 0644, config_async_show, config_async_store);
 
+static ssize_t config_stream_store(struct device *dev,
+				   struct device_attribute *attr,
+				   const char *buf, size_t count)
+{
+	struct driver_data_test_device *test_dev = dev_to_test_dev(dev);
+	struct test_config *config = &test_dev->config;
+
+	return test_dev_config_update_bool(test_dev, buf, count,
+					   &config->stream);
+}
+
+static ssize_t config_stream_show(struct device *dev,
+				  struct device_attribute *attr,
+				  char *buf)
+{
+	struct driver_data_test_device *test_dev = dev_to_test_dev(dev);
+	struct test_config *config = &test_dev->config;
+
+	return test_dev_config_show_bool(test_dev, buf, config->stream);
+}
+static DEVICE_ATTR(config_stream, 0644, config_stream_show,
+		   config_stream_store);
+
 static ssize_t config_optional_store(struct device *dev,
 				     struct device_attribute *attr,
 				     const char *buf, size_t count)
@@ -1231,6 +1306,7 @@  static struct attribute *test_dev_attrs[] = {
 	TEST_DRIVER_DATA_DEV_ATTR(config_name),
 	TEST_DRIVER_DATA_DEV_ATTR(config_default_name),
 	TEST_DRIVER_DATA_DEV_ATTR(config_async),
+	TEST_DRIVER_DATA_DEV_ATTR(config_stream),
 	TEST_DRIVER_DATA_DEV_ATTR(config_optional),
 	TEST_DRIVER_DATA_DEV_ATTR(config_keep),
 	TEST_DRIVER_DATA_DEV_ATTR(config_no_cache),
diff --git a/tools/testing/selftests/firmware/driver_data.sh b/tools/testing/selftests/firmware/driver_data.sh
index dcbbc78..f63a703 100755
--- a/tools/testing/selftests/firmware/driver_data.sh
+++ b/tools/testing/selftests/firmware/driver_data.sh
@@ -41,6 +41,7 @@  ALL_TESTS="$ALL_TESTS 0010:10:1"
 ALL_TESTS="$ALL_TESTS 0011:10:1"
 ALL_TESTS="$ALL_TESTS 0012:1:1"
 ALL_TESTS="$ALL_TESTS 0013:1:1"
+ALL_TESTS="$ALL_TESTS 0015:1:1"
 
 # Not yet sure how to automate suspend test well yet.  For now we expect a
 # manual run. If using qemu you can resume a guest using something like the
@@ -244,6 +245,22 @@  config_disable_prealloc()
 	fi
 }
 
+config_set_stream()
+{
+	if ! echo -n 1 >$DIR/config_stream ; then
+		echo "$0: Unable to unset to stream" >&2
+		exit 1
+	fi
+}
+
+config_disable_stream()
+{
+	if ! echo -n 0 >$DIR/config_stream ; then
+		echo "$0: Unable to set to stream" >&2
+		exit 1
+	fi
+}
+
 config_enable_opt_cb()
 {
 	if ! echo -n 1 >$DIR/config_enable_opt_cb; then
@@ -470,6 +487,12 @@  driver_data_set_async_defaults()
 	config_set_async
 }
 
+driver_data_set_stream_defaults()
+{
+	config_reset
+	config_set_stream
+}
+
 set_system_state()
 {
 	STATE="mem"
@@ -886,6 +909,14 @@  driver_data_test_0014()
 	driver_data_test_0014a
 }
 
+driver_data_test_0015()
+{
+	driver_data_set_stream_defaults
+	config_trigger ${FUNCNAME[0]}
+	config_file_should_match ${FUNCNAME[0]}
+	config_expect_result ${FUNCNAME[0]} SUCCESS
+}
+
 list_tests()
 {
 	echo "Test ID list:"
@@ -908,6 +939,7 @@  list_tests()
 	echo "0012 x $(get_test_count 0012) - Verify api call wills will hunt for files, ignore file"
 	echo "0013 x $(get_test_count 0013) - Verify api call works"
 	echo "0014 x $(get_test_count 0013) - Verify api call works with suspend + resume"
+	echo "0015 x $(get_test_count 0015) - Simple streaming loader"
 }
 
 test_reqs