firmware: selftest for request_firmware_into_buf
Subsystems (4)
v2 cover firmware: selftest for request_firmware_into_buf
This patch series adds kernel selftest of request_firmware_into_buf. The API was added to the kernel previously untested.
Changes from v1:
- Dropped demonstration patch for a race condition discovered
while testing request_firmare_into_buf.
The new test exposes a kernel opps with the firmware fallback mechanism that may be fixed separate from these tests.
- minor whitespace formatting in patch
- added Ack's
- added "s" in commit message (changed selftest: to selftests:)
Scott Branden (2):
test_firmware: add support for request_firmware_into_buf
selftests: firmware: Add request_firmware_into_buf tests
lib/test_firmware.c | 50 +++++++++++++++- .../selftests/firmware/fw_filesystem.sh | 57 ++++++++++++++++++- tools/testing/selftests/firmware/fw_lib.sh | 11 ++++ 3 files changed, 114 insertions(+), 4 deletions(-)
Signature · 1 line
2.17.1
PATCH v2 1/2 test_firmware: add support for request_firmware_into_buf
Add test config into_buf to allow request_firmware_into_buf to be called instead of request_firmware/request_firmware_direct. The number of parameters differ calling request_firmware_into_buf and support has not been added to test such api in test_firmware until now.
--- lib/test_firmware.c | 50 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-)
lib/test_firmware.c +48 -2
@@ -18,6 +18,7 @@#include <linux/device.h> #include <linux/fs.h> #include <linux/miscdevice.h> +#include <linux/sizes.h> #include <linux/slab.h> #include <linux/uaccess.h> #include <linux/delay.h>
@@ -26,6 +27,7 @@#define TEST_FIRMWARE_NAME "test-firmware.bin"#define TEST_FIRMWARE_NUM_REQS 4 +#define TEST_FIRMWARE_BUF_SIZE SZ_1Kstatic DEFINE_MUTEX (test_fw_mutex);static const struct firmware *test_firmware;
@@ -45,6 +47,8 @@ struct test_batched_req {* test_config - represents configuration for the test for different triggers * * @name: the name of the firmware file to look for +* @into_buf: when the into_buf is used if this is true +* request_firmware_into_buf() will be used instead. * @sync_direct: when the sync trigger is used if this is true * request_firmware_direct() will be used instead. * @send_uevent: whether or not to send a uevent for async requests
@@ -83,6 +87,7 @@ struct test_batched_req {*/ struct test_config {char *name; +bool into_buf;bool sync_direct;bool send_uevent;u8 num_requests;
@@ -176,6 +181,7 @@ static int __test_firmware_config_init(void) test_fw_config->num_requests =TEST_FIRMWARE_NUM_REQS ; test_fw_config->send_uevent = true; + test_fw_config->into_buf = false; test_fw_config->sync_direct = false; test_fw_config->req_firmware = request_firmware; test_fw_config->test_result =0 ;
@@ -244,6 +250,9 @@ static ssize_t config_show(struct device *dev, test_fw_config->send_uevent ?"FW_ACTION_HOTPLUG" : "FW_ACTION_NOHOTPLUG"); + len +=scnprintf (buf+len,PAGE_SIZE - len, +"into_buf:\t\t%s\n" , + test_fw_config->into_buf ?"true" :"false" ); len +=scnprintf (buf+len,PAGE_SIZE - len,"sync_direct:\t\t%s\n" , test_fw_config->sync_direct ?"true" :"false" );
@@ -393,6 +402,23 @@ static ssize_t config_num_requests_show(struct device *dev, }static DEVICE_ATTR_RW (config_num_requests); +static ssize_t config_into_buf_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +return test_dev_config_update_bool (buf, + count, + &test_fw_config->into_buf); +} + +static ssize_t config_into_buf_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return test_dev_config_show_bool (buf, test_fw_config->into_buf); +} +static DEVICE_ATTR_RW (config_into_buf); +static ssize_t config_sync_direct_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t count)
@@ -522,7 +548,7 @@ static ssize_t trigger_async_request_store(struct device *dev, rc = count; }else {pr_err ("failed to async load firmware\n" ); - rc = -ENODEV ; + rc = -ENOMEM ; } out:
@@ -585,7 +611,26 @@ static int test_fw_run_batch_request(void *data)return -EINVAL ; } - req->rc = test_fw_config->req_firmware (&req->fw, req->name, req->dev); +if (test_fw_config->into_buf) { +void *test_buf; + + test_buf =kzalloc (TEST_FIRMWARE_BUF_SIZE ,GFP_KERNEL ); +if (!test_buf) +return -ENOSPC ; + + req->rc =request_firmware_into_buf (&req->fw, + req->name, + req->dev, + test_buf, +TEST_FIRMWARE_BUF_SIZE ); +if (!req->fw) +kfree (test_buf); + }else { + req->rc = test_fw_config->req_firmware (&req->fw, + req->name, + req->dev); + } +if (req->rc) {pr_info ("#%u: batched sync load failed: %d\n" , req->idx, req->rc);
@@ -849,6 +894,7 @@ static struct attribute *test_dev_attrs[] = {TEST_FW_DEV_ATTR (config),TEST_FW_DEV_ATTR (config_name),TEST_FW_DEV_ATTR (config_num_requests), +TEST_FW_DEV_ATTR (config_into_buf),TEST_FW_DEV_ATTR (config_sync_direct),TEST_FW_DEV_ATTR (config_send_uevent), TEST_FW_DEV_ATTR(config_read_fw_idx),
Signature · 1 line
2.17.1
PATCH v2 2/2 selftests: firmware: Add request_firmware_into_buf tests
In reply to Scott BrandenAdd tests cases for checking request_firmware_into_buf api. API was introduced into kernel with no testing present previously.
--- .../selftests/firmware/fw_filesystem.sh | 57 ++++++++++++++++++- tools/testing/selftests/firmware/fw_lib.sh | 11 ++++ 2 files changed, 66 insertions(+), 2 deletions(-)
tools/testing/selftests/firmware/fw_filesystem.sh +55 -2
@@ -116,6 +116,16 @@ config_set_name() echo -n $1 > $DIR/config_name } +config_set_into_buf() +{ + echo 1 > $DIR/config_into_buf +} + +config_unset_into_buf() +{ + echo 0 > $DIR/config_into_buf +} + config_set_sync_direct() { echo 1 > $DIR/config_sync_direct
@@ -153,11 +163,14 @@ config_set_read_fw_idx() read_firmwares() { - if [ "$1" = "xzonly" ]; then - fwfile="${FW}-orig" + if [ "$(cat $DIR/config_into_buf)" == "1" ]; then + fwfile="$FW_INTO_BUF" else fwfile="$FW" fi + if [ "$1" = "xzonly" ]; then + fwfile="${fwfile}-orig" + fi for i in $(seq 0 3); do config_set_read_fw_idx $i # Verify the contents are what we expect.
@@ -194,6 +207,18 @@ test_batched_request_firmware_nofile() echo "OK" } +test_batched_request_firmware_into_buf_nofile() +{ + echo -n "Batched request_firmware_into_buf() nofile try #$1: " + config_reset + config_set_name nope-test-firmware.bin + config_set_into_buf + config_trigger_sync + read_firmwares_expect_nofile + release_all_firmware + echo "OK" +} + test_batched_request_firmware_direct_nofile() { echo -n "Batched request_firmware_direct() nofile try #$1: "
@@ -259,6 +284,18 @@ test_batched_request_firmware() echo "OK" } +test_batched_request_firmware_into_buf() +{ + echo -n "Batched request_firmware_into_buf() $2 try #$1: " + config_reset + config_set_name $TEST_FIRMWARE_INTO_BUF_FILENAME + config_set_into_buf + config_trigger_sync + read_firmwares $2 + release_all_firmware + echo "OK" +} + test_batched_request_firmware_direct() { echo -n "Batched request_firmware_direct() $2 try #$1: "
@@ -307,6 +344,10 @@ for i in $(seq 1 5); do test_batched_request_firmware $i normal done +for i in $(seq 1 5); do + test_batched_request_firmware_into_buf $i normal +done + for i in $(seq 1 5); do test_batched_request_firmware_direct $i normal done
@@ -327,6 +368,10 @@ for i in $(seq 1 5); do test_batched_request_firmware_nofile $i done +for i in $(seq 1 5); do + test_batched_request_firmware_into_buf_nofile $i +done + for i in $(seq 1 5); do test_batched_request_firmware_direct_nofile $i done
@@ -350,6 +395,10 @@ for i in $(seq 1 5); do test_batched_request_firmware $i both done +for i in $(seq 1 5); do + test_batched_request_firmware_into_buf $i both +done + for i in $(seq 1 5); do test_batched_request_firmware_direct $i both done
@@ -370,6 +419,10 @@ for i in $(seq 1 5); do test_batched_request_firmware $i xzonly done +for i in $(seq 1 5); do + test_batched_request_firmware_into_buf $i xzonly +done + for i in $(seq 1 5); do test_batched_request_firmware_direct $i xzonly done
tools/testing/selftests/firmware/fw_lib.sh +11 -0
@@ -9,6 +9,12 @@ DIR=/sys/devices/virtual/misc/test_firmware PROC_CONFIG="/proc/config.gz" TEST_DIR=$(dirname $0) +# We need to load a different file to test request_firmware_into_buf +# I believe the issue is firmware loaded cached vs. non-cached +# with same filename is bungled. +# To reproduce rename this to test-firmware.bin +TEST_FIRMWARE_INTO_BUF_FILENAME=test-firmware-into-buf.bin + # Kselftest framework requirement - SKIP code is 4. ksft_skip=4
@@ -108,6 +114,8 @@ setup_tmp_file() FWPATH=$(mktemp -d) FW="$FWPATH/test-firmware.bin" echo "ABCD0123" >"$FW" + FW_INTO_BUF="$FWPATH/$TEST_FIRMWARE_INTO_BUF_FILENAME" + echo "EFGH4567" >"$FW_INTO_BUF" NAME=$(basename "$FW") if [ "$TEST_REQS_FW_SET_CUSTOM_PATH" = "yes" ]; then echo -n "$FWPATH" >/sys/module/firmware_class/parameters/path
@@ -175,6 +183,9 @@ test_finish() if [ -f $FW ]; then rm -f "$FW" fi + if [ -f $FW_INTO_BUF ]; then + rm -f "$FW_INTO_BUF" + fi if [ -d $FWPATH ]; then rm -rf "$FWPATH" fi
Signature · 1 line
2.17.1