Skip to content

Commit

Permalink
Added qemu-test.sh for FileCheck testing, updated run-qemu.sh to chec…
Browse files Browse the repository at this point in the history
…k for missing ELF file
  • Loading branch information
martinbond7 committed Mar 26, 2024
1 parent 9c41406 commit 1fc78bc
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 9 deletions.
58 changes: 58 additions & 0 deletions qemu-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash
# QEMU Invocation for testing without graphics
# see https://www.qemu.org/docs/master/system/invocation.html

set -o nounset
set -o errexit

QEMU_PATH="xpack-qemu-arm-2.8.0-9/bin/qemu-system-gnuarmeclipse"
QEMU_DIRS=". $HOME /opt"

TARGET=Application.elf
IMAGE=./build/debug/$TARGET

function usage {
cat <<EOT
Usage: ${0#.*/} [elf-image]
Launch QEMU from either local sub-directory, home or /opt directory.
Filters startup diagnostic messages so output suitable for FileCheck testing
Options:
--help -- this help information also -h -?
Use Ctrl-A X to quit QEMU.
EOT
exit 1
}

DIAG='-serial telnet:localhost:8888,server,nodelay'
SERIAL='-serial tcp::7777,server,nodelay'

for arg; do
case "$arg" in
*.ELF|*.elf) IMAGE="$arg" ;;
*) echo "Unrecognised command argument: $arg" >&2
usage ;;
esac
done

for dir in $QEMU_DIRS; do
QEMU="$dir/$QEMU_PATH"
[[ -x $QEMU ]] && break
QEMU=
done

if [[ -z $QEMU ]]; then
echo "Cannot find QEMU in standard locations: $QEMU_DIRS" >&2
exit 1
fi

if [[ ! -f "$IMAGE" ]]; then
echo "Missing image file: $IMAGE" >&2
exit 1
fi

$QEMU --board Feabhas-WMS -d unimp,guest_errors \
--semihosting-config enable=on,target=native \
-nographic \
--image "$IMAGE" 2>&1 \
| sed -e '1,/^(qemu) diagnostic/d'

28 changes: 19 additions & 9 deletions run-qemu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
# QEMU Invocation
# see https://www.qemu.org/docs/master/system/invocation.html

set -o nounset
set -o errexit

TARGET=Application.elf
IMAGE=./build/debug/$TARGET

QEMU_PATH="xpack-qemu-arm-2.8.0-9/bin/qemu-system-gnuarmeclipse"
QEMU_DIRS=". $HOME /opt"

function usage {
cat <<EOT
Usage: ${0#.*/} [qemu-options] [diag] [gdb] [serial] [elf-image]
Expand All @@ -15,14 +21,12 @@ Usage: ${0#.*/} [qemu-options] [diag] [gdb] [serial] [elf-image]
gdb - start GDB server on port 1234
--nographic - switch off graphic support
--sdl2 - use built-in graphics instead of remote port 8888
--help -- this help information also -h -?
Use Ctrl-A X to quit QEMU if using --nographic.
EOT
exit 1
}

QEMU_PATH="xpack-qemu-arm-2.8.0-9/bin/qemu-system-gnuarmeclipse"
QEMU_DIRS=". $HOME /opt"

DIAG='-serial telnet:localhost:8888,server,nodelay'
GRAPHIC=
GDB=
Expand All @@ -40,7 +44,7 @@ for arg; do
--sdl2) GRAPHIC=y; DIAG= ;;
-*) OPTIONS="$OPTIONS $arg" ;;
*) echo "Unrecognised command argument: $arg" >&2
usage ;;
usage ;;
esac
done

Expand All @@ -50,17 +54,23 @@ for dir in $QEMU_DIRS; do
QEMU=
done

if [[ -z $QEMU ]]; then
if [[ -z "$QEMU" ]]; then
echo "Cannot find QEMU in standard locations: $QEMU_DIRS" >&2
exit 1
fi

if [[ ! -f "$IMAGE" ]]; then
echo "Missing image file: $IMAGE" >&2
exit 1
fi

if [[ -z "$GRAPHIC" ]]; then
OPTIONS="$OPTIONS -nographic --chardev file,path=/dev/tty,mux=on,id=c0 -mon chardev=c0 -serial chardev:c0"
fi

set -x
$QEMU --verbose --board Feabhas-WMS -d unimp,guest_errors \
--semihosting-config enable=on,target=native \
$OPTIONS $GDB $SERIAL $DIAG \
--image $IMAGE
"$QEMU" --verbose --board Feabhas-WMS -d unimp,guest_errors \
--semihosting-config enable=on,target=native \
$OPTIONS $GDB $SERIAL $DIAG \
--image "$IMAGE"

0 comments on commit 1fc78bc

Please sign in to comment.