Skip to content

Commit

Permalink
tests: Remove unnecessary '&&' in requires() functions
Browse files Browse the repository at this point in the history
The '&&' operator should only be used when the second operand
is dependent on the first. In the context of requires() functions,
we prefer to evaluate all conditions independently to display
all SKIP_REASONS at once. This change separates the conditions
into individual lines to ensure each condition is evaluated
regardless of the others.

After this patch, there are a few '&&' remain
$ git grep -wl 'requires()' | xargs -I {} sed -n '/^requires() *{/,/}/p' {} | grep '&&'
        _have_null_blk && _have_module_param null_blk blocking
        _have_null_blk && _have_module_param null_blk shared_tags
        _have_null_blk && _have_module_param null_blk timeout
        _have_null_blk && _have_module_param null_blk requeue
        _have_null_blk && _have_module_param null_blk shared_tags
        _have_null_blk && _have_module_param null_blk init_hctx
        _have_module nvme_tcp && _have_module_param nvme_tcp ddp_offload
        _have_program mkfs.btrfs && have_good_mkfs_btrfs

Signed-off-by: Li Zhijian <[email protected]>
Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
  • Loading branch information
zhijianli88 authored and kawasaki committed Jan 17, 2025
1 parent 5e517ef commit 50af4ac
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 18 deletions.
3 changes: 2 additions & 1 deletion tests/block/006
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ TIMED=1
CAN_BE_ZONED=1

requires() {
_have_null_blk && _have_module_param null_blk blocking && _have_fio
_have_null_blk && _have_module_param null_blk blocking
_have_fio
}

test() {
Expand Down
3 changes: 2 additions & 1 deletion tests/block/008
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ TIMED=1
CAN_BE_ZONED=1

requires() {
_have_cpu_hotplug && _have_fio
_have_cpu_hotplug
_have_fio
}

test_device() {
Expand Down
3 changes: 2 additions & 1 deletion tests/block/010
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ TIMED=1
CAN_BE_ZONED=1

requires() {
_have_null_blk && _have_module_param null_blk shared_tags && _have_fio
_have_null_blk && _have_module_param null_blk shared_tags
_have_fio
}

run_fio_job() {
Expand Down
3 changes: 2 additions & 1 deletion tests/block/011
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ pci_dev_mounted() {
}

requires() {
_have_fio && _have_program setpci
_have_fio
_have_program setpci
}

device_requires() {
Expand Down
3 changes: 2 additions & 1 deletion tests/block/019
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ QUICK=1
CAN_BE_ZONED=1

requires() {
_have_fio && _have_program setpci
_have_fio
_have_program setpci
}

device_requires() {
Expand Down
3 changes: 2 additions & 1 deletion tests/block/020
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ QUICK=1
CAN_BE_ZONED=1

requires() {
_have_null_blk && _have_fio
_have_null_blk
_have_fio
}

test() {
Expand Down
3 changes: 2 additions & 1 deletion tests/block/029
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ DESCRIPTION="trigger blk_mq_update_nr_hw_queues()"
QUICK=1

requires() {
_have_fio && _have_null_blk
_have_fio
_have_null_blk
}

modify_nr_hw_queues() {
Expand Down
4 changes: 3 additions & 1 deletion tests/loop/002
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ DESCRIPTION="try various loop device block sizes"
QUICK=1

requires() {
_have_program xfs_io && _have_src_program loblksize && _have_loop_set_block_size
_have_program xfs_io
_have_src_program loblksize
_have_loop_set_block_size
}

test() {
Expand Down
4 changes: 3 additions & 1 deletion tests/nbd/001
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ DESCRIPTION="resize a connected nbd device"
QUICK=1

requires() {
_have_nbd && _have_program parted && _have_src_program nbdsetsize
_have_nbd
_have_program parted
_have_src_program nbdsetsize
}

test() {
Expand Down
3 changes: 2 additions & 1 deletion tests/nbd/002
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ DESCRIPTION="tests on partition handling for an nbd device"
QUICK=1

requires() {
_have_nbd_netlink && _have_program parted
_have_nbd_netlink
_have_program parted
}

test() {
Expand Down
3 changes: 2 additions & 1 deletion tests/nbd/003
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ DESCRIPTION="mount/unmount concurrently with NBD_CLEAR_SOCK"
QUICK=1

requires() {
_have_nbd && _have_src_program mount_clear_sock
_have_nbd
_have_src_program mount_clear_sock
}

test() {
Expand Down
3 changes: 2 additions & 1 deletion tests/nvme/005
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ QUICK=1

requires() {
_nvme_requires
_have_loop && _have_module_param_value nvme_core multipath Y
_have_loop
_have_module_param_value nvme_core multipath Y
_require_nvme_trtype_is_fabrics
}

Expand Down
3 changes: 2 additions & 1 deletion tests/nvme/010
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ TIMED=1

requires() {
_nvme_requires
_have_fio && _have_loop
_have_fio
_have_loop
_require_nvme_trtype_is_fabrics
}

Expand Down
4 changes: 2 additions & 2 deletions tests/nvme/039
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ QUICK=1

requires() {
_have_program nvme
_have_kernel_option FAULT_INJECTION && \
_have_kernel_option FAULT_INJECTION_DEBUG_FS
_have_kernel_option FAULT_INJECTION
_have_kernel_option FAULT_INJECTION_DEBUG_FS
}

device_requires() {
Expand Down
4 changes: 3 additions & 1 deletion tests/nvme/056
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ requires() {
_have_fio
_have_program ip
_have_program ethtool
_have_kernel_source && _have_program python3 && have_netlink_cli
_have_kernel_source
_have_program python3
have_netlink_cli
have_iface
}

Expand Down
3 changes: 2 additions & 1 deletion tests/scsi/001
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ DESCRIPTION="try triggering a kernel GPF with 0 byte SG reads"
QUICK=1

requires() {
_have_scsi_generic && _have_src_program sg/syzkaller1
_have_scsi_generic
_have_src_program sg/syzkaller1
}

test_device() {
Expand Down
3 changes: 2 additions & 1 deletion tests/scsi/002
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ DESCRIPTION="perform a SG_DXFER_FROM_DEV from the /dev/sg read-write interface"
QUICK=1

requires() {
_have_scsi_generic && _have_src_program sg/dxfer-from-dev
_have_scsi_generic
_have_src_program sg/dxfer-from-dev
}

test_device() {
Expand Down

0 comments on commit 50af4ac

Please sign in to comment.