[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <1495262886-1045-3-git-send-email-yi1.li@linux.intel.com>
Date: Sat, 20 May 2017 01:48:06 -0500
From: yi1.li@...ux.intel.com
To: mcgrof@...nel.org, atull@...nel.org, gregkh@...uxfoundation.org,
wagi@...om.org, dwmw2@...radead.org, rafal@...ecki.pl,
arend.vanspriel@...adcom.com, rjw@...ysocki.net,
moritz.fischer@...us.com, pmladek@...e.com,
johannes.berg@...el.com, emmanuel.grumbach@...el.com,
luciano.coelho@...el.com, kvalo@...eaurora.org, luto@...nel.org,
takahiro.akashi@...aro.org, dhowells@...hat.com, pjones@...hat.com
Cc: linux-kernel@...r.kernel.org, linux-fpga@...r.kernel.org,
Yi Li <yi1.li@...ux.intel.com>
Subject: [PATCHv2 2/2] test: add pre-allocated buffer to driver_data tester
From: Yi Li <yi1.li@...ux.intel.com>
This adds pre-allocated buffer test cases to the simple sync and
async test.
Signed-off-by: Yi Li <yi1.li@...ux.intel.com>
---
lib/test_driver_data.c | 68 ++++++++++++++++++++++++-
tools/testing/selftests/firmware/driver_data.sh | 36 +++++++++++++
2 files changed, 103 insertions(+), 1 deletion(-)
diff --git a/lib/test_driver_data.c b/lib/test_driver_data.c
index fa7f52b..13fb091 100644
--- a/lib/test_driver_data.c
+++ b/lib/test_driver_data.c
@@ -35,6 +35,7 @@
#include <linux/async.h>
#include <linux/delay.h>
#include <linux/vmalloc.h>
+#include <linux/sizes.h>
/* Used for the fallback default to test against */
#define TEST_DRIVER_DATA "test-driver_data.bin"
@@ -68,6 +69,9 @@ int num_test_devs;
* 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.
+ * @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.
* @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
@@ -117,6 +121,7 @@ struct test_config {
bool optional;
bool keep;
bool no_cache;
+ bool prealloc;
bool enable_opt_cb;
bool use_api_versioning;
u8 api_min;
@@ -345,6 +350,9 @@ static ssize_t config_show(struct device *dev,
len += snprintf(buf+len, PAGE_SIZE,
"no_cache:\t\t%s\n",
config->no_cache ? "true" : "false");
+ len += snprintf(buf+len, PAGE_SIZE,
+ "prealloc:\t\t%s\n",
+ config->prealloc ? "true" : "false");
mutex_unlock(&test_dev->config_mutex);
@@ -450,10 +458,13 @@ static int trigger_config_sync(struct driver_data_test_device *test_dev)
{
struct test_config *config = &test_dev->config;
int ret;
+ void *buf;
const struct driver_data_req_params req_params_default = {
DRIVER_DATA_DEFAULT_SYNC_REQS(config_sync_req_cb, test_dev,
DRIVER_DATA_REQ_OPTIONAL |
- DRIVER_DATA_REQ_KEEP)
+ DRIVER_DATA_REQ_KEEP),
+ .alloc_buf_size = (config->prealloc ? SZ_4K : 0),
+ .alloc_buf = (config->prealloc ? &buf : NULL),
};
const struct driver_data_req_params req_params_opt_cb = {
DRIVER_DATA_DEFAULT_SYNC(config_sync_req_cb, test_dev),
@@ -462,6 +473,8 @@ static int trigger_config_sync(struct driver_data_test_device *test_dev)
.reqs = (config->optional ? DRIVER_DATA_REQ_OPTIONAL : 0) |
(config->keep ? DRIVER_DATA_REQ_KEEP : 0) |
(config->no_cache ? DRIVER_DATA_REQ_NO_CACHE : 0),
+ .alloc_buf_size = (config->prealloc ? SZ_4K : 0),
+ .alloc_buf = (config->prealloc ? &buf : NULL),
};
const struct driver_data_req_params *req_params;
@@ -470,11 +483,22 @@ static int trigger_config_sync(struct driver_data_test_device *test_dev)
else
req_params = &req_params_default;
+ if (config->prealloc) {
+ buf = kmalloc(SZ_4K, GFP_KERNEL);
+ if (!buf) {
+ dev_err(test_dev->dev, "%s: kmalloc buf failed\n",
+ __func__);
+ return -ENOMEM;
+ }
+ }
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);
+ if (config->prealloc)
+ kfree(buf);
+
return ret;
}
@@ -524,11 +548,14 @@ static int trigger_config_async(struct driver_data_test_device *test_dev)
{
struct test_config *config = &test_dev->config;
int ret;
+ void *buf;
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->no_cache ? DRIVER_DATA_REQ_NO_CACHE : 0),
+ .alloc_buf_size = (config->prealloc ? SZ_4K : 0),
+ .alloc_buf = (config->prealloc ? &buf : NULL),
};
const struct driver_data_req_params req_params_opt_cb = {
DRIVER_DATA_DEFAULT_ASYNC(config_async_req_cb, test_dev),
@@ -536,6 +563,8 @@ static int trigger_config_async(struct driver_data_test_device *test_dev)
.reqs = (config->optional ? DRIVER_DATA_REQ_OPTIONAL : 0) |
(config->keep ? DRIVER_DATA_REQ_KEEP : 0) |
(config->no_cache ? DRIVER_DATA_REQ_NO_CACHE : 0),
+ .alloc_buf_size = (config->prealloc ? SZ_4K : 0),
+ .alloc_buf = (config->prealloc ? &buf : NULL),
};
const struct driver_data_req_params req_params_api = {
DRIVER_DATA_API_CB(config_async_req_api_cb, test_dev),
@@ -544,6 +573,8 @@ static int trigger_config_async(struct driver_data_test_device *test_dev)
(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),
+ .alloc_buf_size = (config->prealloc ? SZ_4K : 0),
+ .alloc_buf = (config->prealloc ? &buf : NULL),
};
const struct driver_data_req_params *req_params;
@@ -554,6 +585,14 @@ static int trigger_config_async(struct driver_data_test_device *test_dev)
else
req_params = &req_params_default;
+ if (config->prealloc) {
+ buf = kmalloc(SZ_4K, GFP_KERNEL);
+ if (!buf) {
+ dev_err(test_dev->dev, "%s: kmalloc buf failed\n",
+ __func__);
+ return -ENOMEM;
+ }
+ }
test_dev->api_found_calls = 0;
ret = driver_data_request_async(config->name, req_params,
test_dev->dev);
@@ -574,6 +613,8 @@ static int trigger_config_async(struct driver_data_test_device *test_dev)
wait_for_completion_timeout(&test_dev->request_complete, 5 * HZ);
out:
+ if (config->prealloc)
+ kfree(buf);
return ret;
}
@@ -669,6 +710,7 @@ static int __driver_data_config_init(struct test_config *config)
config->optional = false;
config->keep = false;
config->no_cache = false;
+ config->prealloc = false;
config->enable_opt_cb = false;
config->use_api_versioning = false;
config->api_min = 0;
@@ -1011,6 +1053,29 @@ static ssize_t config_no_cache_show(struct device *dev,
static DEVICE_ATTR(config_no_cache, 0644, config_no_cache_show,
config_no_cache_store);
+static ssize_t config_prealloc_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->prealloc);
+}
+
+static ssize_t config_prealloc_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->prealloc);
+}
+static DEVICE_ATTR(config_prealloc, 0644, config_prealloc_show,
+ config_prealloc_store);
+
static ssize_t config_enable_opt_cb_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
@@ -1169,6 +1234,7 @@ static struct attribute *test_dev_attrs[] = {
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_prealloc),
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 82fae0a..dcbbc78 100755
--- a/tools/testing/selftests/firmware/driver_data.sh
+++ b/tools/testing/selftests/firmware/driver_data.sh
@@ -228,6 +228,22 @@ config_disable_no_cache()
fi
}
+config_set_prealloc()
+{
+ if ! echo -n 1 >$DIR/config_prealloc; then
+ echo "$0: Unable to set to prealloc" >&2
+ exit 1
+ fi
+}
+
+config_disable_prealloc()
+{
+ if ! echo -n 0 >$DIR/config_prealloc; then
+ echo "$0: Unable to disable prealloc option" >&2
+ exit 1
+ fi
+}
+
config_enable_opt_cb()
{
if ! echo -n 1 >$DIR/config_enable_opt_cb; then
@@ -559,12 +575,32 @@ driver_data_test_0004a_no_cache()
config_expect_result ${FUNCNAME[0]} SUCCESS
}
+driver_data_test_0004s_prealloc()
+{
+ driver_data_set_sync_defaults
+ config_set_prealloc
+ config_trigger ${FUNCNAME[0]}
+ config_file_should_match ${FUNCNAME[0]}
+ config_expect_result ${FUNCNAME[0]} SUCCESS
+}
+
+driver_data_test_0004a_prealloc()
+{
+ driver_data_set_async_defaults
+ config_set_prealloc
+ 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_0004s_prealloc
+ driver_data_test_0004a_prealloc
}
driver_data_test_0005s()
--
2.7.4
Powered by blists - more mailing lists