1#!/usr/bin/env bash 2testdir=$(readlink -f "$(dirname "$0")") 3rootdir=$(readlink -f "$testdir/../../") 4source "$testdir/common.sh" 5 6nvmes=("$@") 7 8offset_magic() { 9 local magic_check 10 local offsets offset 11 12 offsets=(16 256 1024) # * bs 13 14 for offset in "${offsets[@]}"; do 15 "${DD_APP[@]}" \ 16 --ib="$bdev0" \ 17 --ob="$bdev1" \ 18 --count="$count" \ 19 --seek="$offset" \ 20 --bs="$bs" \ 21 --json <(gen_conf) 22 23 "${DD_APP[@]}" \ 24 --ib="$bdev1" \ 25 --of="$test_file1" \ 26 --count=1 \ 27 --skip="$offset" \ 28 --bs="$bs" \ 29 --json <(gen_conf) 30 31 read -rn${#magic} magic_check < "$test_file1" 32 [[ $magic_check == "$magic" ]] 33 done 34} 35 36cleanup() { 37 # Zero up to 1G on input|output bdev 38 clear_nvme "$bdev0" "" $((0x40000000 + ${#magic})) 39 clear_nvme "$bdev1" "" $((0x40000000 + ${#magic})) 40 rm -f "$test_file0" "$test_file1" "$aio1" 41} 42 43trap "cleanup" EXIT 44 45bs=$((1024 << 10)) 46 47if ((${#nvmes[@]} > 1)); then 48 nvme0=Nvme0 bdev0=Nvme0n1 nvme0_pci=${nvmes[0]} # input bdev 49 nvme1=Nvme1 bdev1=Nvme1n1 nvme1_pci=${nvmes[1]} # output bdev 50 51 declare -A method_bdev_nvme_attach_controller_0=( 52 ["name"]=$nvme0 53 ["traddr"]=$nvme0_pci 54 ["trtype"]=pcie 55 ) 56 declare -A method_bdev_nvme_attach_controller_1=( 57 ["name"]=$nvme1 58 ["traddr"]=$nvme1_pci 59 ["trtype"]=pcie 60 ) 61else 62 # Use AIO to compensate lack of actual hardware 63 nvme0=Nvme0 bdev0=Nvme0n1 nvme0_pci=${nvmes[0]} # input bdev 64 aio1=$SPDK_TEST_STORAGE/aio1 bdev1=aio1 # output bdev 65 66 declare -A method_bdev_nvme_attach_controller_1=( 67 ["name"]=$nvme0 68 ["traddr"]=$nvme0_pci 69 ["trtype"]=pcie 70 ) 71 declare -A method_bdev_aio_create_0=( 72 ["name"]=$bdev1 73 ["filename"]=$aio1 74 ["block_size"]=4096 75 ) 76 77 # 2G AIO file 78 "${DD_APP[@]}" \ 79 --if=/dev/zero \ 80 --of="$aio1" \ 81 --bs="$bs" \ 82 --count=2048 83fi 84 85test_file0=$SPDK_TEST_STORAGE/dd.dump0 86test_file1=$SPDK_TEST_STORAGE/dd.dump1 87 88magic="This Is Our Magic, find it" 89echo "$magic" > "$test_file0" 90 91# Make the file a bit bigger (~512MB) 92run_test "dd_inflate_file" \ 93 "${DD_APP[@]}" \ 94 --if=/dev/zero \ 95 --of="$test_file0" \ 96 --oflag=append \ 97 --bs="$bs" \ 98 --count=512 99 100test_file0_size=$(wc -c < "$test_file0") 101 102# Now, copy it over to first nvme with default bs (4k) 103run_test "dd_copy_to_out_bdev" \ 104 "${DD_APP[@]}" \ 105 --if="$test_file0" \ 106 --ob="$bdev0" \ 107 --json <(gen_conf) 108 109count=$(((test_file0_size / bs) + 1)) 110 111run_test "dd_offset_magic" offset_magic 112