]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
scsi/006: allow changing cache_type to fail
authorOmar Sandoval <osandov@fb.com>
Tue, 18 Dec 2018 20:15:56 +0000 (12:15 -0800)
committerOmar Sandoval <osandov@fb.com>
Tue, 18 Dec 2018 20:18:47 +0000 (12:18 -0800)
Some devices don't support all cache types. Allow setting the cache type
to fail with EINVAL. On success, make sure it was changed to the desired
value.

Signed-off-by: Omar Sandoval <osandov@fb.com>
tests/scsi/006

index bccb6d69d46003338576c89af4e63467a1a1b019..f220f61e3c1e0be309dadead612c62879922498a 100755 (executable)
@@ -9,7 +9,6 @@
 . tests/scsi/rc
 
 DESCRIPTION="toggle SCSI cache type"
-
 QUICK=1
 
 device_requires() {
@@ -25,15 +24,24 @@ test_device() {
                "write back"
                "write back, no read (daft)"
        )
-       local cache_type
+       local cache_type_paths
+       local cache_type_path
        local original_cache_type
+       local cache_type
 
-       original_cache_type="$(cat "${TEST_DEV_SYSFS}"/device/scsi_disk/*/cache_type)"
+       cache_type_paths=("${TEST_DEV_SYSFS}"/device/scsi_disk/*/cache_type)
+       cache_type_path="${cache_type_paths[0]}"
+       original_cache_type="$(cat "$cache_type_path")"
        for cache_type in "${cache_types[@]}"; do
-               echo "$cache_type" > "${TEST_DEV_SYSFS}"/device/scsi_disk/*/cache_type
-               cat "${TEST_DEV_SYSFS}"/device/scsi_disk/*/cache_type
+               echo "$cache_type"
+               ( echo "$cache_type" > "$cache_type_path" ) |& grep -v "Invalid argument"
+               if [[ ${PIPESTATUS[0]} -eq 0 ]]; then
+                       # If setting the cache type succeeded, it should now
+                       # contain the new cache type.
+                       grep -Fxv "$cache_type" "$cache_type_path"
+               fi
        done
-       echo "$original_cache_type" > "${TEST_DEV_SYSFS}"/device/scsi_disk/*/cache_type
+       ( echo "$original_cache_type" > "$cache_type_path" ) |& grep -v "Invalid argument"
 
        echo "Test complete"
 }