Some of the test cases in nvme test group do the exact same test for two blkdev types: device type and file type. Except for this difference, the test cases are pure duplication. It is desired to avoid the duplication. When the duplication is avoided, it is required to control which condition to run the test. To avoid the duplication and also to allow the blkdev type control, introduce a new configuration parameter NVMET_BLKDEV_TYPES. This parameter specifies which blkdev type to setup for the tests. It can take one of the blkdev types. Or it can take both types, which is the default. When both types are specified, the test cases are repeated twice to cover the types. Also add the helper function _set_nvme_trtype_and_nvmet_blkdev_type(). It sets up nvmet_blkdev_type variable for each test case run from NVMET_BLKDEV_TYPES. It also sets nvme_trtype from NVMET_TRTYPES. When NVMET_BLKDEV_TYPES and NVMET_TRTYPES are set as follows, the test case with _set_nvme_trtype_and_nvmet_blkdev_type in set_condition() hook is called 2 x 3 = 6 times. NVMET_BLKDEV_TYPES="device file" NVMET_TRTYPES="loop rdma tcp" Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@xxxxxxx> --- Documentation/running-tests.md | 5 +++++ tests/nvme/rc | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/Documentation/running-tests.md b/Documentation/running-tests.md index 144acd1..6d2f8ae 100644 --- a/Documentation/running-tests.md +++ b/Documentation/running-tests.md @@ -109,6 +109,11 @@ The NVMe tests can be additionally parameterized via environment variables. - nvme_trtype: 'loop' (default), 'tcp', 'rdma' and 'fc' Run the tests with the given transport. This parameter is still usable but replaced with NVMET_TRTYPES. Use NVMET_TRTYPES instead. +- NVMET_BLKDEV_TYPES: 'device', 'file' + Set up NVME target backends with the specified block device type. Multiple + block device types can be listed with separating spaces. In this case, the + tests are repeated to cover all of the block device types specified. Default + value is "device file". - nvme_img_size: '1G' (default) Run the tests with given image size in bytes. 'm', 'M', 'g' and 'G' postfix are supported. diff --git a/tests/nvme/rc b/tests/nvme/rc index d44a1c1..f678128 100644 --- a/tests/nvme/rc +++ b/tests/nvme/rc @@ -21,6 +21,7 @@ export def_subsys_uuid="91fdba0d-f87b-4c25-b80f-db7be1418b9e" nvme_img_size=${nvme_img_size:-"1G"} nvme_num_iter=${nvme_num_iter:-"1000"} nvmet_blkdev_type=${nvmet_blkdev_type:-"device"} +NVMET_BLKDEV_TYPES=${NVMET_BLKDEV_TYPES:-"device file"} # Check consistency of NVMET_TRTYPES and nvme_trtype configurations. # If neither is configured, set the default value. @@ -54,6 +55,27 @@ _set_nvme_trtype() { COND_DESC="nvmet tr=${nvme_trtype}" } +_set_nvme_trtype_and_nvmet_blkdev_type() { + local index=$1 + local bd_index tr_index + local -a blkdev_types + local -a trtypes + + read -r -a blkdev_types <<< "$NVMET_BLKDEV_TYPES" + read -r -a trtypes <<< "$NVMET_TRTYPES" + + if [[ -z $index ]]; then + echo $(( ${#trtypes[@]} * ${#blkdev_types[@]} )) + return + fi + + bd_index=$((index / ${#trtypes[@]})) + tr_index=$((index % ${#trtypes[@]})) + nvmet_blkdev_type=${blkdev_types[bd_index]} + nvme_trtype=${trtypes[tr_index]} + COND_DESC="nvmet bd=${nvmet_blkdev_type} tr=${nvme_trtype}" +} + # TMPDIR can not be referred out of test() or test_device() context. Instead of # global variable def_flie_path, use this getter function. _nvme_def_file_path() { -- 2.44.0