xref: /spdk/test/dd/basic_rw.sh (revision 7192849ed24874f3e9cc31e8a33a9b32c49b9506)
1#!/usr/bin/env bash
2testdir=$(readlink -f "$(dirname "$0")")
3rootdir=$(readlink -f "$testdir/../../")
4source "$testdir/common.sh"
5
6basic_rw() {
7	local native_bs=$1
8	local count size
9	local qds bss
10
11	qds=(1 64)
12	# Generate some bs for tests based on the native_bs
13	for bs in {0..4}; do
14		bss+=($((native_bs << bs)))
15	done
16
17	for bs in "${bss[@]}"; do
18		for qd in "${qds[@]}"; do
19			count=$((0xffff / bs))
20			count=$((count == 0 ? 1 : count))
21			size=$((count * bs))
22
23			gen_bytes "$size" > "$test_file0"
24
25			"${DD_APP[@]}" \
26				--if="$test_file0" \
27				--ob="$bdev0" \
28				--bs="$bs" \
29				--qd="$qd" \
30				--json <(gen_conf)
31
32			"${DD_APP[@]}" \
33				--ib="$bdev0" \
34				--of="$test_file1" \
35				--bs="$bs" \
36				--qd="$qd" \
37				--count="$count" \
38				--json <(gen_conf)
39
40			diff -q "$test_file0" "$test_file1"
41			clear_nvme "$bdev0" "" "$size"
42		done
43	done
44}
45
46basic_offset() {
47	# Check if offseting works - using default io size of 4k
48	local count seek skip data data_check
49
50	gen_bytes 4096 > "$test_file0"
51	((count = seek = skip = 1))
52	data=$(< "$test_file0")
53
54	"${DD_APP[@]}" \
55		--if="$test_file0" \
56		--ob="$bdev0" \
57		--seek="$seek" \
58		--json <(gen_conf)
59
60	"${DD_APP[@]}" \
61		--ib="$bdev0" \
62		--of="$test_file1" \
63		--skip="$skip" \
64		--count="$count" \
65		--json <(gen_conf)
66
67	read -rn${#data} data_check < "$test_file1"
68	[[ $data == "$data_check" ]]
69}
70
71plain_copy() {
72	# Test if copy between plain files works as well
73	"${DD_APP[@]}" --if="$test_file0" --of="$test_file1"
74	diff -q "$test_file0" "$test_file1"
75}
76
77cleanup() {
78	clear_nvme "$bdev0"
79	rm -f "$test_file0" "$test_file1"
80}
81
82trap "cleanup" EXIT
83
84nvmes=("$@")
85nvme0=Nvme0 nvme0_pci=${nvmes[0]} bdev0=Nvme0n1
86
87declare -A method_bdev_nvme_attach_controller_0=(
88	["name"]=$nvme0
89	["traddr"]=$nvme0_pci
90	["trtype"]=pcie
91)
92
93test_file0=$SPDK_TEST_STORAGE/dd.dump0
94test_file1=$SPDK_TEST_STORAGE/dd.dump1
95native_bs=$(get_native_nvme_bs "$nvme0_pci")
96
97# Test if running with bs < native_bs successfully fails
98run_test "dd_bs_lt_native_bs" \
99	NOT "${DD_APP[@]}" \
100	--if=<(:) \
101	--ob="$bdev0" \
102	--bs=$((native_bs >> 1)) \
103	--json <(gen_conf)
104
105run_test "dd_rw" basic_rw "$native_bs"
106run_test "dd_rw_offset" basic_offset
107run_test "dd_rw_file_copy" plain_copy
108