Commit 2b30b764 authored by Andrew Jones's avatar Andrew Jones Committed by Paolo Bonzini
Browse files

scripts: Introduce mkstandalone.sh



This is a pretty ugly bash script, wrapped around a couple ugly
bash scripts, and it generates an ugly sh script. But, it gets the
job done. What's the job? Take a unit test and generate a standalone
script that can be run on any appropriate system with an appropriate
qemu. This makes distributing single, pre-compiled, unit tests easy,
even through email, which can be useful for getting test results from
a variety of users, or even for deploying the unit test as utility
(if it works that way) in a distribution. "Packaging" works like shar,
but doesn't use shar, as it's better to avoid the dependency. Can be
used to create just one unit test, or all of them ('make standalone').
The standalone test(s) are placed in ./tests.

Signed-off-by: Andrew Jones's avatarAndrew Jones <drjones@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 92a1afcb
......@@ -14,3 +14,4 @@ cscope.*
/*-run
/test.log
/msr.out
/tests
......@@ -64,6 +64,9 @@ $(LIBFDT_archive): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS))
-include */.*.d */*/.*.d
standalone: all
@scripts/mkstandalone.sh
install:
mkdir -p $(DESTDIR)
install $(tests_and_config) $(DESTDIR)
......@@ -78,6 +81,7 @@ libfdt_clean:
distclean: clean libfdt_clean
$(RM) lib/asm config.mak $(TEST_DIR)-run test.log msr.out cscope.*
$(RM) -r tests
cscope: common_dirs = lib lib/libfdt lib/asm lib/asm-generic
cscope:
......
#!/bin/bash
if [ ! -f config.mak ]; then
echo "run ./configure && make first. See ./configure -h"
exit
fi
source config.mak
source scripts/functions.bash
one_kernel="$1"
[ "$one_kernel" ] && one_kernel_base=$(basename $one_kernel)
one_testname="$2"
if [ -n "$one_kernel" ] && [ ! -f $one_kernel ]; then
echo "$one_kernel doesn't exist"
exit 1
elif [ -n "$one_kernel" ] && [ -z "$one_testname" ]; then
one_testname="${one_kernel_base%.*}"
fi
unittests=$TEST_DIR/unittests.cfg
mkdir -p tests
function mkstandalone()
{
local testname="$1"
local groups="$2"
local smp="$3"
local kernel="$4"
local opts="$5"
local arch="$6"
local check="$7"
if [ -z "$testname" ]; then
return 1
fi
if [ -n "$one_testname" ] && [ "$testname" != "$one_testname" ]; then
return 1
fi
standalone=tests/$testname
cmdline=$(DRYRUN=yes ./$TEST_DIR-run $kernel)
if [ $? -ne 0 ]; then
echo $cmdline
exit 1
fi
qemu=$(cut -d' ' -f1 <<< "$cmdline")
cmdline=$(cut -d' ' -f2- <<< "$cmdline")
cat <<EOF > $standalone
#!/bin/sh
EOF
if [ "$arch" ]; then
cat <<EOF >> $standalone
ARCH=\`uname -m | sed -e s/i.86/i386/ | sed -e 's/arm.*/arm/'\`
[ "\$ARCH" = "aarch64" ] && ARCH="arm64"
if [ "\$ARCH" != "$arch" ]; then
echo "skip $testname ($arch only)" 1>&2
exit 1
fi
EOF
fi
if [ "$check" ]; then
cat <<EOF >> $standalone
for param in $check; do
path=\`echo \$param | cut -d= -f1\`
value=\`echo \$param | cut -d= -f2\`
if [ -f "\$path" ] && [ "\`cat \$path\`" != "\$value" ]; then
echo "skip $testname (\$path not equal to \$value)" 1>&2
exit 1
fi
done
EOF
fi
if [ ! -f $kernel ]; then
cat <<EOF >> $standalone
echo "skip $testname (test kernel not present)" 1>&2
exit 1
EOF
else
cat <<EOF >> $standalone
trap 'rm -f \$bin; exit 1' HUP INT TERM
bin=\`mktemp\`
base64 -d << 'BIN_EOF' | zcat > \$bin &&
EOF
gzip - < $kernel | base64 >> $standalone
cat <<EOF >> $standalone
BIN_EOF
qemu="$qemu"
if [ "\$QEMU" ]; then
qemu="\$QEMU"
fi
cmdline="\`echo '$cmdline' | sed s%$kernel%\$bin%\`"
echo \$qemu $cmdline -smp $smp $opts
\$qemu \$cmdline -smp $smp $opts
ret=\$?
echo Return value from qemu: \$ret
if [ \$ret -le 1 ]; then
echo PASS $testname 1>&2
else
echo FAIL $testname 1>&2
fi
rm -f \$bin
exit 0
EOF
fi
chmod +x $standalone
return 0
}
trap 'rm -f $cfg; exit 1' HUP INT TERM
trap 'rm -f $cfg' EXIT
cfg=$(mktemp)
if [ -n "$one_testname" ]; then
if grep -q "\[$one_testname\]" $unittests; then
sed -n "/\\[$one_testname\\]/,/^\\[/p" $unittests \
| awk '!/^\[/ || NR == 1' > $cfg
else
echo "[$one_testname]" > $cfg
echo "file = $one_kernel_base" >> $cfg
fi
else
cp -f $unittests $cfg
fi
for_each_unittest $cfg mkstandalone
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment