tools/testing/selftests/ublk/test_integrity_02.sh

Source file repositories/reference/linux-study-clean/tools/testing/selftests/ublk/test_integrity_02.sh

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/ublk/test_integrity_02.sh
Extension
.sh
Size
3539 bytes
Lines
143
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: tools
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#!/bin/bash
# SPDX-License-Identifier: GPL-2.0

. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh

if ! _have_program fio; then
	exit $UBLK_SKIP_CODE
fi

min_fio_version=fio-3.42
fio_version=$(fio --version)
if ! sort --version-sort --check=quiet <(printf "%s\n%s\n" "$min_fio_version" "$fio_version"); then
	echo "Requires fio version with https://github.com/axboe/fio/pull/1992"
	exit $UBLK_SKIP_CODE
fi

ERR_CODE=0

# Global variables set during device setup
dev_id=""
fio_args=""
fio_err=""

_setup_device() {
	_create_backfile 0 256M
	_create_backfile 1 32M # 256M * (64 integrity bytes / 512 data bytes)

	local integrity_params="--integrity_capable --integrity_reftag
		--metadata_size 64 --pi_offset 56 --csum_type t10dif"
	dev_id=$(_add_ublk_dev -t loop -u $integrity_params "${UBLK_BACKFILES[@]}")
	_check_add_dev "$TID" $?

	# 1M * (64 integrity bytes / 512 data bytes) = 128K
	fio_args="--ioengine io_uring --direct 1 --bsrange 512-1M --iodepth 32
		--md_per_io_size 128K --pi_act 0 --pi_chk GUARD,REFTAG,APPTAG
		--filename /dev/ublkb$dev_id"

	fio_err=$(mktemp "${UBLK_TEST_DIR}"/fio_err_XXXXX)
}

_test_fill_and_verify() {
	fio --name fill --rw randwrite $fio_args > /dev/null
	if [ $? != 0 ]; then
		echo "fio fill failed"
		ERR_CODE=255
		return 1
	fi

	fio --name verify --rw randread $fio_args > /dev/null
	if [ $? != 0 ]; then
		echo "fio verify failed"
		ERR_CODE=255
		return 1
	fi
}

_test_corrupted_reftag() {
	local dd_reftag_args="bs=1 seek=60 count=4 oflag=dsync conv=notrunc status=none"
	local expected_err="REFTAG compare error: LBA: 0 Expected=0, Actual="

	# Overwrite 4-byte reftag at offset 56 + 4 = 60
	dd if=/dev/urandom "of=${UBLK_BACKFILES[1]}" $dd_reftag_args
	if [ $? != 0 ]; then
		echo "dd corrupted_reftag failed"
		ERR_CODE=255
		return 1
	fi

	if fio --name corrupted_reftag --rw randread $fio_args > /dev/null 2> "$fio_err"; then
		echo "fio corrupted_reftag unexpectedly succeeded"

Annotation

Implementation Notes