From patchwork Sat May 20 06:49:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Yi" X-Patchwork-Id: 9738495 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B6A2C600C8 for ; Sat, 20 May 2017 06:54:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A93B0285BD for ; Sat, 20 May 2017 06:54:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DD35285C5; Sat, 20 May 2017 06:54:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BFA71285BD for ; Sat, 20 May 2017 06:54:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751782AbdETGyZ (ORCPT ); Sat, 20 May 2017 02:54:25 -0400 Received: from mga09.intel.com ([134.134.136.24]:63622 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751034AbdETGyY (ORCPT ); Sat, 20 May 2017 02:54:24 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 May 2017 23:54:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,367,1491289200"; d="scan'208";a="1132798931" Received: from yi-patch.an.intel.com ([10.122.105.158]) by orsmga001.jf.intel.com with ESMTP; 19 May 2017 23:54:16 -0700 From: yi1.li@linux.intel.com To: mcgrof@kernel.org, atull@kernel.org, gregkh@linuxfoundation.org, wagi@monom.org, dwmw2@infradead.org, rafal@milecki.pl, arend.vanspriel@broadcom.com, rjw@rjwysocki.net, moritz.fischer@ettus.com, pmladek@suse.com, johannes.berg@intel.com, emmanuel.grumbach@intel.com, luciano.coelho@intel.com, kvalo@codeaurora.org, luto@kernel.org, takahiro.akashi@linaro.org, dhowells@redhat.com, pjones@redhat.com Cc: linux-kernel@vger.kernel.org, linux-fpga@vger.kernel.org, Yi Li Subject: [PATCHv2 2/3] test: add streaming test to driver_data tester Date: Sat, 20 May 2017 01:49:07 -0500 Message-Id: <1495262948-1106-3-git-send-email-yi1.li@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495262948-1106-1-git-send-email-yi1.li@linux.intel.com> References: <1495262948-1106-1-git-send-email-yi1.li@linux.intel.com> Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Yi Li 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 --- lib/test_driver_data.c | 80 ++++++++++++++++++++++++- tools/testing/selftests/firmware/driver_data.sh | 32 ++++++++++ 2 files changed, 110 insertions(+), 2 deletions(-) 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