1# 2# Copyright (c) 2024 Dell Inc. or its subsidiaries. All Rights Reserved. 3# 4# SPDX-License-Identifier: BSD-2-Clause 5# 6 7. $(atf_get_srcdir)/conf.sh 8 9atf_test_case basic cleanup 10basic_head() 11{ 12 atf_set "descr" "geom virstor basic functional test" 13 atf_set "require.user" "root" 14} 15basic_body() 16{ 17 geom_atf_test_setup 18 # Choose a virstor device name 19 gvirstor_dev_setup name 20 21 # Create an md backing device and initialize it with junk 22 psecsize=512 23 attach_md md -t swap -S $psecsize -s 5M || atf_fail "attach_md" 24 jot -b uninitialized 0 | dd status=none of=/dev/$md 2> /dev/null 25 26 # Create a virstor device 27 vsizemb=64 28 vsize=$((vsizemb * 1024 * 1024)) 29 atf_check -o ignore -e ignore \ 30 gvirstor label -v -s ${vsizemb}M -m 512 $name /dev/$md 31 devwait 32 vdev="/dev/$class/$name" 33 34 ssize=$(diskinfo $vdev | awk '{print $2}') 35 atf_check_equal $psecsize $ssize 36 37 size=$(diskinfo $vdev | awk '{print $3}') 38 atf_check_equal $vsize $size 39 40 # Write the first and last sectors of the virtual address space 41 hasha=$(jot -b a 0 | head -c $ssize | sha1) 42 hashz=$(jot -b z 0 | head -c $ssize | sha1) 43 zsector=$((vsize / ssize - 1)) 44 jot -b a 0 | dd status=none of=$vdev bs=$ssize count=1 conv=notrunc 45 jot -b z 0 | dd status=none of=$vdev bs=$ssize count=1 conv=notrunc \ 46 seek=$zsector 47 48 # Read back and compare 49 hashx=$(dd status=none if=$vdev bs=$ssize count=1 | sha1) 50 atf_check_equal $hasha $hashx 51 hashx=$(dd status=none if=$vdev bs=$ssize count=1 skip=$zsector | sha1) 52 atf_check_equal $hashz $hashx 53 54 # Destroy, then retaste and reload 55 atf_check -o ignore gvirstor destroy $name 56 true > /dev/$md 57 devwait 58 59 # Read back and compare 60 hashx=$(dd status=none if=$vdev bs=$ssize count=1 | sha1) 61 atf_check_equal $hasha $hashx 62 hashx=$(dd status=none if=$vdev bs=$ssize count=1 skip=$zsector | sha1) 63 atf_check_equal $hashz $hashx 64} 65basic_cleanup() 66{ 67 gvirstor_test_cleanup 68} 69 70atf_init_test_cases() 71{ 72 atf_add_test_case basic 73} 74