[PATCHv2,3/3] test: add no_cache to driver_data load tester
diff mbox

Message ID 1495262819-981-4-git-send-email-yi1.li@linux.intel.com
State New
Headers show

Commit Message

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

This adds a no_cache flag to simple sync and async test.

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

Patch
diff mbox

diff --git a/lib/test_driver_data.c b/lib/test_driver_data.c
index 488cc6e..fa7f52b 100644
--- a/lib/test_driver_data.c
+++ b/lib/test_driver_data.c
@@ -64,6 +64,10 @@  int num_test_devs;
  *	struct driver_data_reg_params @optional field for more information.
  * @keep: whether or not we wish to free the driver_data on our own, refer to
  *	the struct driver_data_req_params @keep field for more information.
+ * @no_cache: whether or not we wish to use the internal caching mechanism
+ *      to assist drivers from fetching driver data at resume time after
+ *      suspend, refer to the struct driver_data_req_params .req
+ *      DRIVER_DATA_REQ_NO_CACHE for more information.
  * @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
@@ -112,6 +116,7 @@  struct test_config {
 	bool async;
 	bool optional;
 	bool keep;
+	bool no_cache;
 	bool enable_opt_cb;
 	bool use_api_versioning;
 	u8 api_min;
@@ -337,6 +342,9 @@  static ssize_t config_show(struct device *dev,
 	len += snprintf(buf+len, PAGE_SIZE,
 			"keep:\t\t%s\n",
 			config->keep ? "true" : "false");
+	len += snprintf(buf+len, PAGE_SIZE,
+			"no_cache:\t\t%s\n",
+			config->no_cache ? "true" : "false");
 
 	mutex_unlock(&test_dev->config_mutex);
 
@@ -452,7 +460,8 @@  static int trigger_config_sync(struct driver_data_test_device *test_dev)
 		DRIVER_DATA_SYNC_OPT_CB(config_sync_req_default_cb,
 					     test_dev),
 		.reqs = (config->optional ? DRIVER_DATA_REQ_OPTIONAL : 0) |
-			(config->keep ? DRIVER_DATA_REQ_KEEP : 0),
+			(config->keep ? DRIVER_DATA_REQ_KEEP : 0) |
+			(config->no_cache ? DRIVER_DATA_REQ_NO_CACHE : 0),
 	};
 	const struct driver_data_req_params *req_params;
 
@@ -518,19 +527,22 @@  static int trigger_config_async(struct driver_data_test_device *test_dev)
 	const struct driver_data_req_params req_params_default = {
 		DRIVER_DATA_DEFAULT_ASYNC(config_async_req_cb, test_dev),
 		.reqs = (config->optional ? DRIVER_DATA_REQ_OPTIONAL : 0) |
-			(config->keep ? DRIVER_DATA_REQ_KEEP : 0),
+			(config->keep ? DRIVER_DATA_REQ_KEEP : 0) |
+			(config->no_cache ? DRIVER_DATA_REQ_NO_CACHE : 0),
 	};
 	const struct driver_data_req_params req_params_opt_cb = {
 		DRIVER_DATA_DEFAULT_ASYNC(config_async_req_cb, test_dev),
 		DRIVER_DATA_ASYNC_OPT_CB(config_async_req_default_cb, test_dev),
 		.reqs = (config->optional ? DRIVER_DATA_REQ_OPTIONAL : 0) |
-			(config->keep ? DRIVER_DATA_REQ_KEEP : 0),
+			(config->keep ? DRIVER_DATA_REQ_KEEP : 0) |
+			(config->no_cache ? DRIVER_DATA_REQ_NO_CACHE : 0),
 	};
 	const struct driver_data_req_params req_params_api = {
 		DRIVER_DATA_API_CB(config_async_req_api_cb, test_dev),
 		DRIVER_DATA_API(config->api_min, config->api_max, config->api_name_postfix),
 		.reqs = (config->optional ? DRIVER_DATA_REQ_OPTIONAL : 0) |
 			(config->keep ? DRIVER_DATA_REQ_KEEP : 0) |
+			(config->no_cache ? DRIVER_DATA_REQ_NO_CACHE : 0) |
 			(config->use_api_versioning ? DRIVER_DATA_REQ_USE_API_VERSIONING : 0),
 	};
 	const struct driver_data_req_params *req_params;
@@ -656,6 +668,7 @@  static int __driver_data_config_init(struct test_config *config)
 	config->async = false;
 	config->optional = false;
 	config->keep = false;
+	config->no_cache = false;
 	config->enable_opt_cb = false;
 	config->use_api_versioning = false;
 	config->api_min = 0;
@@ -975,6 +988,29 @@  static ssize_t config_keep_show(struct device *dev,
 }
 static DEVICE_ATTR(config_keep, 0644, config_keep_show, config_keep_store);
 
+static ssize_t config_no_cache_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->no_cache);
+}
+
+static ssize_t config_no_cache_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->no_cache);
+}
+static DEVICE_ATTR(config_no_cache, 0644, config_no_cache_show,
+		   config_no_cache_store);
+
 static ssize_t config_enable_opt_cb_store(struct device *dev,
 					  struct device_attribute *attr,
 					  const char *buf, size_t count)
@@ -1132,6 +1168,7 @@  static struct attribute *test_dev_attrs[] = {
 	TEST_DRIVER_DATA_DEV_ATTR(config_async),
 	TEST_DRIVER_DATA_DEV_ATTR(config_optional),
 	TEST_DRIVER_DATA_DEV_ATTR(config_keep),
+	TEST_DRIVER_DATA_DEV_ATTR(config_no_cache),
 	TEST_DRIVER_DATA_DEV_ATTR(config_use_api_versioning),
 	TEST_DRIVER_DATA_DEV_ATTR(config_enable_opt_cb),
 	TEST_DRIVER_DATA_DEV_ATTR(config_api_min),
diff --git a/tools/testing/selftests/firmware/driver_data.sh b/tools/testing/selftests/firmware/driver_data.sh
index c830d04..82fae0a 100755
--- a/tools/testing/selftests/firmware/driver_data.sh
+++ b/tools/testing/selftests/firmware/driver_data.sh
@@ -212,6 +212,22 @@  config_disable_keep()
 	fi
 }
 
+config_set_no_cache()
+{
+	if ! echo -n 1 >$DIR/config_no_cache; then
+		echo "$0: Unable to set to no_cache" >&2
+		exit 1
+	fi
+}
+
+config_disable_no_cache()
+{
+	if ! echo -n 0 >$DIR/config_no_cache; then
+		echo "$0: Unable to disable no_cache option" >&2
+		exit 1
+	fi
+}
+
 config_enable_opt_cb()
 {
 	if ! echo -n 1 >$DIR/config_enable_opt_cb; then
@@ -525,10 +541,30 @@  driver_data_test_0004a()
 	config_expect_result ${FUNCNAME[0]} SUCCESS
 }
 
+driver_data_test_0004s_no_cache()
+{
+	driver_data_set_sync_defaults
+	config_set_no_cache
+	config_trigger ${FUNCNAME[0]}
+	config_file_should_match ${FUNCNAME[0]}
+	config_expect_result ${FUNCNAME[0]} SUCCESS
+}
+
+driver_data_test_0004a_no_cache()
+{
+	driver_data_set_async_defaults
+	config_set_no_cache
+	config_trigger ${FUNCNAME[0]}
+	config_file_should_match ${FUNCNAME[0]}
+	config_expect_result ${FUNCNAME[0]} SUCCESS
+}
+
 driver_data_test_0004()
 {
 	driver_data_test_0004s
 	driver_data_test_0004a
+	driver_data_test_0004s_no_cache
+	driver_data_test_0004a_no_cache
 }
 
 driver_data_test_0005s()