1 #!/bin/sh 1 #!/bin/sh 2 # SPDX-License-Identifier: GPL-2.0-only 2 # SPDX-License-Identifier: GPL-2.0-only 3 3 4 echo "Boot config test script" 4 echo "Boot config test script" 5 5 6 if [ -d "$1" ]; then 6 if [ -d "$1" ]; then 7 TESTDIR=$1 7 TESTDIR=$1 8 else 8 else 9 TESTDIR=. 9 TESTDIR=. 10 fi 10 fi 11 BOOTCONF=${TESTDIR}/bootconfig 11 BOOTCONF=${TESTDIR}/bootconfig 12 ALIGN=4 << 13 12 14 INITRD=`mktemp ${TESTDIR}/initrd-XXXX` 13 INITRD=`mktemp ${TESTDIR}/initrd-XXXX` 15 TEMPCONF=`mktemp ${TESTDIR}/temp-XXXX.bconf` 14 TEMPCONF=`mktemp ${TESTDIR}/temp-XXXX.bconf` 16 OUTFILE=`mktemp ${TESTDIR}/tempout-XXXX` 15 OUTFILE=`mktemp ${TESTDIR}/tempout-XXXX` 17 NG=0 16 NG=0 18 17 19 cleanup() { 18 cleanup() { 20 rm -f $INITRD $TEMPCONF $OUTFILE 19 rm -f $INITRD $TEMPCONF $OUTFILE 21 exit $NG 20 exit $NG 22 } 21 } 23 22 24 trap cleanup EXIT TERM 23 trap cleanup EXIT TERM 25 24 26 NO=1 25 NO=1 27 26 28 xpass() { # pass test command 27 xpass() { # pass test command 29 echo "test case $NO ($*)... " !! 28 echo "test case $NO ($3)... " 30 if ! ($@ && echo "\t\t[OK]"); then 29 if ! ($@ && echo "\t\t[OK]"); then 31 echo "\t\t[NG]"; NG=$((NG + 1)) 30 echo "\t\t[NG]"; NG=$((NG + 1)) 32 fi 31 fi 33 NO=$((NO + 1)) 32 NO=$((NO + 1)) 34 } 33 } 35 34 36 xfail() { # fail test command 35 xfail() { # fail test command 37 echo "test case $NO ($*)... " !! 36 echo "test case $NO ($3)... " 38 if ! (! $@ && echo "\t\t[OK]"); then 37 if ! (! $@ && echo "\t\t[OK]"); then 39 echo "\t\t[NG]"; NG=$((NG + 1)) 38 echo "\t\t[NG]"; NG=$((NG + 1)) 40 fi 39 fi 41 NO=$((NO + 1)) 40 NO=$((NO + 1)) 42 } 41 } 43 42 44 echo "Basic command test" 43 echo "Basic command test" 45 xpass $BOOTCONF $INITRD 44 xpass $BOOTCONF $INITRD 46 45 47 echo "Delete command should success without bo 46 echo "Delete command should success without bootconfig" 48 xpass $BOOTCONF -d $INITRD 47 xpass $BOOTCONF -d $INITRD 49 48 50 dd if=/dev/zero of=$INITRD bs=4096 count=1 49 dd if=/dev/zero of=$INITRD bs=4096 count=1 51 echo "key = value;" > $TEMPCONF 50 echo "key = value;" > $TEMPCONF 52 bconf_size=$(stat -c %s $TEMPCONF) 51 bconf_size=$(stat -c %s $TEMPCONF) 53 initrd_size=$(stat -c %s $INITRD) 52 initrd_size=$(stat -c %s $INITRD) 54 53 55 echo "Apply command test" 54 echo "Apply command test" 56 xpass $BOOTCONF -a $TEMPCONF $INITRD 55 xpass $BOOTCONF -a $TEMPCONF $INITRD 57 new_size=$(stat -c %s $INITRD) 56 new_size=$(stat -c %s $INITRD) 58 57 59 echo "Show command test" 58 echo "Show command test" 60 xpass $BOOTCONF $INITRD 59 xpass $BOOTCONF $INITRD 61 60 62 echo "File size check" 61 echo "File size check" 63 total_size=$(expr $bconf_size + $initrd_size + !! 62 xpass test $new_size -eq $(expr $bconf_size + $initrd_size + 9 + 12) 64 total_size=$(expr $total_size / $ALIGN) << 65 total_size=$(expr $total_size \* $ALIGN) << 66 xpass test $new_size -eq $total_size << 67 63 68 echo "Apply command repeat test" 64 echo "Apply command repeat test" 69 xpass $BOOTCONF -a $TEMPCONF $INITRD 65 xpass $BOOTCONF -a $TEMPCONF $INITRD 70 66 71 echo "File size check" 67 echo "File size check" 72 xpass test $new_size -eq $(stat -c %s $INITRD) 68 xpass test $new_size -eq $(stat -c %s $INITRD) 73 69 74 echo "Delete command check" 70 echo "Delete command check" 75 xpass $BOOTCONF -d $INITRD 71 xpass $BOOTCONF -d $INITRD 76 72 77 echo "File size check" 73 echo "File size check" 78 new_size=$(stat -c %s $INITRD) 74 new_size=$(stat -c %s $INITRD) 79 xpass test $new_size -eq $initrd_size 75 xpass test $new_size -eq $initrd_size 80 76 81 echo "No error messge while applying" 77 echo "No error messge while applying" 82 dd if=/dev/zero of=$INITRD bs=4096 count=1 78 dd if=/dev/zero of=$INITRD bs=4096 count=1 83 printf " \0\0\0 \0\0\0" >> $INITRD 79 printf " \0\0\0 \0\0\0" >> $INITRD 84 $BOOTCONF -a $TEMPCONF $INITRD > $OUTFILE 2>&1 80 $BOOTCONF -a $TEMPCONF $INITRD > $OUTFILE 2>&1 85 xfail grep -i "failed" $OUTFILE 81 xfail grep -i "failed" $OUTFILE 86 xfail grep -i "error" $OUTFILE 82 xfail grep -i "error" $OUTFILE 87 83 88 echo "Max node number check" 84 echo "Max node number check" 89 85 90 awk ' !! 86 echo -n > $TEMPCONF 91 BEGIN { !! 87 for i in `seq 1 1024` ; do 92 for (i = 0; i < 26; i += 1) !! 88 echo "node$i" >> $TEMPCONF 93 printf("%c\n", 65 + i % 26) !! 89 done 94 for (i = 26; i < 8192; i += 1) << 95 printf("%c%c%c\n", 65 + i % 26, 65 + (i << 96 } << 97 ' > $TEMPCONF << 98 xpass $BOOTCONF -a $TEMPCONF $INITRD 90 xpass $BOOTCONF -a $TEMPCONF $INITRD 99 91 100 echo "badnode" >> $TEMPCONF 92 echo "badnode" >> $TEMPCONF 101 xfail $BOOTCONF -a $TEMPCONF $INITRD 93 xfail $BOOTCONF -a $TEMPCONF $INITRD 102 94 103 echo "Max filesize check" 95 echo "Max filesize check" 104 96 105 # Max size is 32767 (including terminal byte) 97 # Max size is 32767 (including terminal byte) 106 echo -n "data = \"" > $TEMPCONF 98 echo -n "data = \"" > $TEMPCONF 107 dd if=/dev/urandom bs=768 count=32 | base64 -w 99 dd if=/dev/urandom bs=768 count=32 | base64 -w0 >> $TEMPCONF 108 echo "\"" >> $TEMPCONF 100 echo "\"" >> $TEMPCONF 109 xfail $BOOTCONF -a $TEMPCONF $INITRD 101 xfail $BOOTCONF -a $TEMPCONF $INITRD 110 102 111 truncate -s 32764 $TEMPCONF 103 truncate -s 32764 $TEMPCONF 112 echo "\"" >> $TEMPCONF # add 2 bytes + termin 104 echo "\"" >> $TEMPCONF # add 2 bytes + terminal ('\"\n\0') 113 xpass $BOOTCONF -a $TEMPCONF $INITRD 105 xpass $BOOTCONF -a $TEMPCONF $INITRD 114 106 115 echo "Adding same-key values" 107 echo "Adding same-key values" 116 cat > $TEMPCONF << EOF 108 cat > $TEMPCONF << EOF 117 key = bar, baz 109 key = bar, baz 118 key += qux 110 key += qux 119 EOF 111 EOF 120 echo > $INITRD 112 echo > $INITRD 121 113 122 xpass $BOOTCONF -a $TEMPCONF $INITRD 114 xpass $BOOTCONF -a $TEMPCONF $INITRD 123 $BOOTCONF $INITRD > $OUTFILE 115 $BOOTCONF $INITRD > $OUTFILE 124 xpass grep -q "bar" $OUTFILE 116 xpass grep -q "bar" $OUTFILE 125 xpass grep -q "baz" $OUTFILE 117 xpass grep -q "baz" $OUTFILE 126 xpass grep -q "qux" $OUTFILE 118 xpass grep -q "qux" $OUTFILE 127 119 128 echo "Override same-key values" << 129 cat > $TEMPCONF << EOF << 130 key = bar, baz << 131 key := qux << 132 EOF << 133 echo > $INITRD << 134 << 135 xpass $BOOTCONF -a $TEMPCONF $INITRD << 136 $BOOTCONF $INITRD > $OUTFILE << 137 xfail grep -q "bar" $OUTFILE << 138 xfail grep -q "baz" $OUTFILE << 139 xpass grep -q "qux" $OUTFILE << 140 << 141 echo "Double/single quotes test" 120 echo "Double/single quotes test" 142 echo "key = '\"string\"';" > $TEMPCONF 121 echo "key = '\"string\"';" > $TEMPCONF 143 $BOOTCONF -a $TEMPCONF $INITRD 122 $BOOTCONF -a $TEMPCONF $INITRD 144 $BOOTCONF $INITRD > $TEMPCONF 123 $BOOTCONF $INITRD > $TEMPCONF 145 cat $TEMPCONF 124 cat $TEMPCONF 146 xpass grep \'\"string\"\' $TEMPCONF 125 xpass grep \'\"string\"\' $TEMPCONF 147 << 148 echo "Repeat same-key tree" << 149 cat > $TEMPCONF << EOF << 150 foo << 151 bar << 152 foo { buz } << 153 EOF << 154 echo > $INITRD << 155 << 156 xpass $BOOTCONF -a $TEMPCONF $INITRD << 157 $BOOTCONF $INITRD > $OUTFILE << 158 xpass grep -q "bar" $OUTFILE << 159 << 160 << 161 echo "Remove/keep tailing spaces" << 162 cat > $TEMPCONF << EOF << 163 foo = val # comment << 164 bar = "val2 " # comment << 165 EOF << 166 echo > $INITRD << 167 << 168 xpass $BOOTCONF -a $TEMPCONF $INITRD << 169 $BOOTCONF $INITRD > $OUTFILE << 170 xfail grep -q val[[:space:]] $OUTFILE << 171 xpass grep -q val2[[:space:]] $OUTFILE << 172 126 173 echo "=== expected failure cases ===" 127 echo "=== expected failure cases ===" 174 for i in samples/bad-* ; do 128 for i in samples/bad-* ; do 175 xfail $BOOTCONF -a $i $INITRD 129 xfail $BOOTCONF -a $i $INITRD 176 done 130 done 177 131 178 echo "=== expected success cases ===" 132 echo "=== expected success cases ===" 179 for i in samples/good-* ; do 133 for i in samples/good-* ; do 180 xpass $BOOTCONF -a $i $INITRD 134 xpass $BOOTCONF -a $i $INITRD 181 done 135 done 182 136 183 137 184 echo 138 echo 185 echo "=== Summary ===" 139 echo "=== Summary ===" 186 echo "# of Passed: $(expr $NO - $NG - 1)" 140 echo "# of Passed: $(expr $NO - $NG - 1)" 187 echo "# of Failed: $NG" 141 echo "# of Failed: $NG" 188 142 189 echo 143 echo 190 if [ $NG -eq 0 ]; then 144 if [ $NG -eq 0 ]; then 191 echo "All tests passed" 145 echo "All tests passed" 192 else 146 else 193 echo "$NG tests failed" 147 echo "$NG tests failed" 194 exit 1 148 exit 1 195 fi 149 fi
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.