Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #348 from sifive/qemu-test-script-1908
Browse files Browse the repository at this point in the history
[19.08 Backport] Run QEMU targets in Travis
  • Loading branch information
nategraff-sifive authored Aug 19, 2019
2 parents 8b31f54 + 669bf01 commit 46742d9
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@ install:
- docker exec -t host bash -c "yes | apt-get update"
- docker exec -t host bash -c "yes | apt-get upgrade"
- docker exec -t host bash -c "yes | apt-get install build-essential git wget"
# Install QEMU dependencies
- docker exec -t host bash -c "yes | apt-get install libpixman-1-0 libnuma1 libpng12-0 libglib2.0-0"
# Download RISC-V embedded toolchain
- docker exec -t host bash -c "cd /travis && wget https://static.dev.sifive.com/dev-tools/riscv64-unknown-elf-gcc-8.2.0-2019.05.3-x86_64-linux-ubuntu14.tar.gz"
- docker exec -t host bash -c "cd /travis && tar xzvf riscv64-unknown-elf-gcc-8.2.0-2019.05.3-x86_64-linux-ubuntu14.tar.gz"
# Download RISC-V QEMU
- docker exec -t host bash -c "cd /travis && wget https://static.dev.sifive.com/dev-tools/riscv-qemu-3.1.0-2019.05.1-x86_64-linux-ubuntu14.tar.gz"
- docker exec -t host bash -c "cd /travis && tar xzvf riscv-qemu-3.1.0-2019.05.1-x86_64-linux-ubuntu14.tar.gz"

# Here's where we actually run the test.
script:
# Build all software for all targets
- docker exec -t host bash -c "export RISCV_PATH=/travis/riscv64-unknown-elf-gcc-8.2.0-2019.05.3-x86_64-linux-ubuntu14 && cd /travis && ./scripts/all-targets-build"
# Test by running software on all QEMU targets
- docker exec -t host bash -c "export RISCV_PATH=/travis/riscv64-unknown-elf-gcc-8.2.0-2019.05.3-x86_64-linux-ubuntu14 && export PATH=$PATH:/travis/riscv-qemu-3.1.0-2019.05.1-x86_64-linux-ubuntu14/bin && cd /travis && ./scripts/test-qemu-targets"
58 changes: 58 additions & 0 deletions scripts/test-qemu-targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

# Sets the timeout for our asynchronous polling and for the subshell command
TIMEOUT_SECONDS=300

TARGETS=(qemu-sifive-e31 qemu-sifive-s51 qemu-sifive-u54 )
PROGRAMS=(hello )

for target in ${TARGETS[@]} ; do
for program in ${PROGRAMS[@]} ; do

output_file=$( mktemp -p ./ tmp.${target}.${program}.XXXXXXXXXX)

case $program in
hello) expected_output="Hello, World!";;
*) expected_output="";;
esac

>&2 echo "Running ${program} on ${target}"

start_time=$(date +%s)
timeout=$(( start_time + ${TIMEOUT_SECONDS} ))

# Run the build and simulation in a subshell and pipe the output into
# the temporariy output file so that we can asynchronously look for
# the expected output
( timeout ${TIMEOUT_SECONDS}s make TARGET=${target} PROGRAM=${program} simulate 2>/dev/null >${output_file} ) &

while true; do

# If the expected output is found, kill the subshell and continue
# to the next test
if [ -f ${output_file} -a `cat ${output_file} | grep -c "${expected_output}"` -ne 0 ] ; then
kill $(jobs -p)

cat ${output_file}
>&2 echo "${program} on ${target} was successful"

break
fi

# If the test times out, report the failure and exit
if [ `date +%s` -gt $timeout ] ; then
kill $(jobs -p)

cat ${output_file}
>&2 echo "${program} on ${target} timed out without producing expected output"

exit 1
fi
done

# Make sure we clean up after ourselves
make TARGET=${target} PROGRAM=${program} clean 2>&1 >/dev/null
done
done

>&2 echo "All tests passed on QEMU"

0 comments on commit 46742d9

Please sign in to comment.