Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests: ublk: add ublk auto integrity test

The end-to-end integrity ublk selftest test_integrity_02 requires a
relatively recent fio version to support I/O with integrity buffers. Add
a version test_integrity_03 that uses the block layer's auto integrity
path instead. The auto integrity code doesn't check the application tag,
and doesn't indicate the bad guard/ref tag (just returns EILSEQ). But
it's a good smoke-test of the ublk integrity code and provides coverage
of the auto integrity path as well.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
Reviewed-by: Ming Lei <tom.leiming@gmail.com>
Link: https://patch.msgid.link/20260421200901.1528842-4-csander@purestorage.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Caleb Sander Mateos and committed by
Jens Axboe
1cdf3b28 eb3d1922

+104
+1
tools/testing/selftests/ublk/Makefile
··· 37 37 38 38 TEST_PROGS += test_integrity_01.sh 39 39 TEST_PROGS += test_integrity_02.sh 40 + TEST_PROGS += test_integrity_03.sh 40 41 41 42 TEST_PROGS += test_recover_01.sh 42 43 TEST_PROGS += test_recover_02.sh
+103
tools/testing/selftests/ublk/test_integrity_03.sh
··· 1 + #!/bin/bash 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + . "$(cd "$(dirname "$0")" && pwd)"/test_common.sh 5 + 6 + if ! _have_program fio; then 7 + exit $UBLK_SKIP_CODE 8 + fi 9 + 10 + _test_fill_and_verify() { 11 + fio --name fill --rw randwrite $fio_args > /dev/null 12 + if [ $? != 0 ]; then 13 + echo "fio fill failed" 14 + ERR_CODE=255 15 + return 1 16 + fi 17 + 18 + fio --name verify --rw randread $fio_args > /dev/null 19 + if [ $? != 0 ]; then 20 + echo "fio verify failed" 21 + ERR_CODE=255 22 + return 1 23 + fi 24 + } 25 + 26 + _test_corrupted_reftag() { 27 + local dd_reftag_args="bs=1 seek=58 count=6 oflag=dsync conv=notrunc status=none" 28 + 29 + # Overwrite 6-byte reftag at offset 48 + 10 = 58 30 + dd if=/dev/urandom "of=${UBLK_BACKFILES[1]}" $dd_reftag_args 31 + if [ $? != 0 ]; then 32 + echo "dd corrupted_reftag failed" 33 + ERR_CODE=255 34 + return 1 35 + fi 36 + 37 + if fio --name corrupted_reftag --rw randread $fio_args > /dev/null 2> "$fio_err"; then 38 + echo "fio corrupted_reftag unexpectedly succeeded" 39 + ERR_CODE=255 40 + return 1 41 + fi 42 + 43 + if ! grep -q "$expected_err" "$fio_err"; then 44 + echo "fio corrupted_reftag message not found: $expected_err" 45 + ERR_CODE=255 46 + return 1 47 + fi 48 + 49 + # Reset to 0 50 + dd if=/dev/zero "of=${UBLK_BACKFILES[1]}" $dd_reftag_args 51 + if [ $? != 0 ]; then 52 + echo "dd restore corrupted_reftag failed" 53 + ERR_CODE=255 54 + return 1 55 + fi 56 + } 57 + 58 + _test_corrupted_data() { 59 + local dd_data_args="bs=512 count=1 oflag=direct,dsync conv=notrunc status=none" 60 + 61 + dd if=/dev/zero "of=${UBLK_BACKFILES[0]}" $dd_data_args 62 + if [ $? != 0 ]; then 63 + echo "dd corrupted_data failed" 64 + ERR_CODE=255 65 + return 1 66 + fi 67 + 68 + if fio --name corrupted_data --rw randread $fio_args > /dev/null 2> "$fio_err"; then 69 + echo "fio corrupted_data unexpectedly succeeded" 70 + ERR_CODE=255 71 + return 1 72 + fi 73 + 74 + if ! grep -q "$expected_err" "$fio_err"; then 75 + echo "fio corrupted_data message not found: $expected_err" 76 + ERR_CODE=255 77 + return 1 78 + fi 79 + } 80 + 81 + _prep_test "loop" "end-to-end auto integrity" 82 + 83 + _create_backfile 0 256M 84 + _create_backfile 1 32M # 256M * (64 integrity bytes / 512 data bytes) 85 + integrity_params="--integrity_capable --integrity_reftag 86 + --metadata_size 64 --pi_offset 48 --csum_type nvme" 87 + dev_id=$(_add_ublk_dev -t loop -u $integrity_params "${UBLK_BACKFILES[@]}") 88 + _check_add_dev "$TID" $? 89 + 90 + fio_args="--ioengine libaio --direct 1 --bsrange 512-1M --iodepth 32 91 + --filename /dev/ublkb$dev_id" 92 + fio_err=$(mktemp "${UBLK_TEST_DIR}"/fio_err_XXXXX) 93 + ERR_CODE=0 94 + 95 + expected_err="Invalid or incomplete multibyte or wide character: read offset=0" 96 + _test_fill_and_verify && \ 97 + _test_corrupted_reftag && \ 98 + _test_corrupted_data 99 + 100 + rm -f "$fio_err" 101 + 102 + _cleanup_test 103 + _show_result "$TID" $ERR_CODE