Skip to content

Commit a141656

Browse files
committed
tools/bootconfig: Replace some echo with printf for more portability
Since echo is not portable, use printf instead. This fixes a wrong test result formatting in some environment. (showing "\t\t[OK]") Also this uses printf command for generating test data instead of echo. Link: https://lore.kernel.org/all/175211424942.2591046.5439447789303314213.stgit@mhiramat.tok.corp.google.com/ Signed-off-by: Masami Hiramatsu (Google) <[email protected]>
1 parent bfed3dd commit a141656

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

tools/bootconfig/test-bootconfig.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ NO=1
2727

2828
xpass() { # pass test command
2929
echo "test case $NO ($*)... "
30-
if ! ($@ && echo "\t\t[OK]"); then
31-
echo "\t\t[NG]"; NG=$((NG + 1))
30+
if ! ($@ && printf "\t\t[OK]\n"); then
31+
printf "\t\t[NG]\n"; NG=$((NG + 1))
3232
fi
3333
NO=$((NO + 1))
3434
}
3535

3636
xfail() { # fail test command
3737
echo "test case $NO ($*)... "
38-
if ! (! $@ && echo "\t\t[OK]"); then
39-
echo "\t\t[NG]"; NG=$((NG + 1))
38+
if ! (! $@ && printf "\t\t[OK]\n"); then
39+
printf "\t\t[NG]\n"; NG=$((NG + 1))
4040
fi
4141
NO=$((NO + 1))
4242
}
@@ -48,7 +48,7 @@ echo "Delete command should success without bootconfig"
4848
xpass $BOOTCONF -d $INITRD
4949

5050
dd if=/dev/zero of=$INITRD bs=4096 count=1
51-
echo "key = value;" > $TEMPCONF
51+
printf "key = value;" > $TEMPCONF
5252
bconf_size=$(wc -c < $TEMPCONF)
5353
initrd_size=$(wc -c < $INITRD)
5454

@@ -97,20 +97,20 @@ BEGIN {
9797
' > $TEMPCONF
9898
xpass $BOOTCONF -a $TEMPCONF $INITRD
9999

100-
echo "badnode" >> $TEMPCONF
100+
printf "badnode\n" >> $TEMPCONF
101101
xfail $BOOTCONF -a $TEMPCONF $INITRD
102102

103103
echo "Max filesize check"
104104

105105
# Max size is 32767 (including terminal byte)
106-
echo -n "data = \"" > $TEMPCONF
106+
printf "data = \"" > $TEMPCONF
107107
dd if=/dev/urandom bs=768 count=32 | base64 -w0 >> $TEMPCONF
108-
echo "\"" >> $TEMPCONF
108+
printf "\"\n" >> $TEMPCONF
109109
xfail $BOOTCONF -a $TEMPCONF $INITRD
110110

111111
dd if=$TEMPCONF of=$OUTFILE bs=1 count=32764
112112
cp $OUTFILE $TEMPCONF
113-
echo "\"" >> $TEMPCONF # add 2 bytes + terminal ('\"\n\0')
113+
printf "\"\n" >> $TEMPCONF # add 2 bytes + terminal ('\"\n\0')
114114
xpass $BOOTCONF -a $TEMPCONF $INITRD
115115

116116
echo "Adding same-key values"
@@ -140,7 +140,7 @@ xfail grep -q "baz" $OUTFILE
140140
xpass grep -q "qux" $OUTFILE
141141

142142
echo "Double/single quotes test"
143-
echo "key = '\"string\"';" > $TEMPCONF
143+
printf "key = '\"string\"';" > $TEMPCONF
144144
$BOOTCONF -a $TEMPCONF $INITRD
145145
$BOOTCONF $INITRD > $TEMPCONF
146146
cat $TEMPCONF

0 commit comments

Comments
 (0)