tools/testing/selftests/ublk/test_integrity_03.sh

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

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/ublk/test_integrity_03.sh
Extension
.sh
Size
2545 bytes
Lines
104
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

_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=58 count=6 oflag=dsync conv=notrunc status=none"

	# Overwrite 6-byte reftag at offset 48 + 10 = 58
	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"
		ERR_CODE=255
		return 1
	fi

	if ! grep -q "$expected_err" "$fio_err"; then
		echo "fio corrupted_reftag message not found: $expected_err"
		ERR_CODE=255
		return 1
	fi

	# Reset to 0
	dd if=/dev/zero "of=${UBLK_BACKFILES[1]}" $dd_reftag_args
	if [ $? != 0 ]; then
		echo "dd restore corrupted_reftag failed"
		ERR_CODE=255
		return 1
	fi
}

_test_corrupted_data() {
	local dd_data_args="bs=512 count=1 oflag=direct,dsync conv=notrunc status=none"

	dd if=/dev/zero "of=${UBLK_BACKFILES[0]}" $dd_data_args
	if [ $? != 0 ]; then
		echo "dd corrupted_data failed"
		ERR_CODE=255
		return 1
	fi

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

Annotation

Implementation Notes