1 2mkimg_blksz_list="512 4096" 3mkimg_format_list="qcow qcow2 raw vhd vhdf vhdx vmdk" 4mkimg_geom_list="1x1 63x255" 5mkimg_scheme_list="apm bsd ebr gpt mbr" 6 7bootcode() 8{ 9 case $1 in 10 bsd) echo 8192 ;; 11 gpt|mbr) echo 512 ;; 12 *) echo 0 ;; 13 esac 14 return 0 15} 16 17mkcontents() 18{ 19 local byte count name 20 21 byte=$1 22 count=$2 23 24 name=_tmp-$byte-$count.bin 25 jot -b $byte $(($count/2)) > $name 26 echo $name 27 return 0 28} 29 30makeimage() 31{ 32 local blksz bootarg bootsz format geom nhds nsecs partarg pfx scheme 33 34 format=$1 35 scheme=$2 36 blksz=$3 37 geom=$4 38 pfx=$5 39 shift 5 40 41 nsecs=${geom%x*} 42 nhds=${geom#*x} 43 44 bootsz=`bootcode $scheme` 45 if test $bootsz -gt 0; then 46 bootarg="-b `mkcontents B $bootsz`" 47 else 48 bootarg="" 49 fi 50 51 partarg="" 52 for P in $*; do 53 partarg="$partarg -p $P" 54 done 55 if test -z "$partarg"; then 56 local swap ufs 57 swap="-p freebsd-swap::128K" 58 ufs="-p freebsd-ufs:=$(atf_get_srcdir)/partition_data_4M.bin" 59 partarg="$ufs $swap" 60 fi 61 62 imagename=$pfx-$geom-$blksz-$scheme.$format 63 64 mkimg -y -f $format -o $imagename -s $scheme -P $blksz -H $nhds -T $nsecs \ 65 $bootarg $partarg 66 echo $imagename 67 return 0 68} 69 70mkimg_rebase() 71{ 72 local baseline image result tmpfile update 73 74 image=$1 75 result=$2 76 77 baseline=$image.hex 78 update=yes 79 80 if test -f $baseline; then 81 tmpfile=_tmp-baseline 82 sed -e '/^#.*/D' < $baseline > $tmpfile 83 if diff -u $tmpfile $result; then 84 update=no 85 fi 86 fi 87 88 if test $update = yes; then 89 cat $result > $baseline 90 fi 91 92 rm $image $result _tmp-* 93 return 0 94} 95 96mkimg_test() 97{ 98 local blksz format geom scheme 99 100 geom=$1 101 blksz=$2 102 scheme=$3 103 format=$4 104 105 case $scheme in 106 ebr|mbr) 107 bsd=`makeimage raw bsd $blksz $geom _tmp` 108 partinfo="freebsd:=$bsd" 109 ;; 110 *) 111 partinfo="" 112 ;; 113 esac 114 image=`makeimage $format $scheme $blksz $geom img $partinfo` 115 result=$image.out 116 hexdump -C $image > $result 117 if test "x$mkimg_update_baseline" = "xyes"; then 118 mkimg_rebase $image $result 119 else 120 baseline=`atf_get_srcdir`/$image 121 atf_check -s exit:0 diff -u $baseline $result 122 fi 123 return 0 124} 125 126atf_test_case rebase 127rebase_body() 128{ 129 local nm 130 131 mkimg_update_baseline=yes 132 for nm in $mkimg_tests; do 133 ${nm}_body 134 done 135 return 0 136} 137 138atf_init_test_cases() 139{ 140 local B F G S nm 141 142 for G in $mkimg_geom_list; do 143 for B in $mkimg_blksz_list; do 144 for S in $mkimg_scheme_list; do 145 for F in $mkimg_format_list; do 146 nm="${S}_${G}_${B}_${F}" 147 atf_test_case $nm 148 eval "${nm}_body() { mkimg_test $G $B $S $F; }" 149 mkimg_tests="${mkimg_tests} ${nm}" 150 atf_add_test_case $nm 151 done 152 done 153 done 154 done 155 156 # XXX hack to make updating the baseline easier 157 if test "${__RUNNING_INSIDE_ATF_RUN}" != "internal-yes-value"; then 158 atf_add_test_case rebase 159 fi 160} 161 162