Commit bd33b5ef authored by Guido Gunther's avatar Guido Gunther

Allow to test the built image via qemu

parent 677c8da0
#!/bin/bash
#
# Test the image via qemu
set -e
#KERNEL=vmlinuz-4.15.0-rc7-gffa1c3483
KERNEL=zImage
IMG=imx6.img
NETWORK=192.168.76.0/24
IP=192.168.76.15
SSH_FWD_HOST=127.0.0.1
SSH_FWD_PORT=5555
BOOT_SLEEP=45
RETRY_SLEEP=10
RETRIES=10
TOPLEVEL="${PWD}"
QEMU_PID=
function cleanup() {
if [ -n "$QEMU_PID" ]; then
echo -n "Cleaning up QEMU instance ${QEMU_PID}..."
kill -9 $QEMU_PID
echo "done."
fi
}
function do_tests() {
cd tests/
TARGET_HOST=${SSH_FWD_HOST} TARGET_PORT=${SSH_FWD_PORT} rake spec:nitrogen6
cd "${TOPLEVEL}"
}
function boot_wait() {
echo "Waiting ${BOOT_SLEEP}s for ${IMG} to boot..."
sleep ${BOOT_SLEEP}
}
function ssh_wait() {
echo -n "Waiting for ssh to become available..."
retries=${RETRIES}
while [ ${retries} -gt 0 ]; do
BANNER=$(echo | nc -vw 3 ${SSH_FWD_HOST} ${SSH_FWD_PORT} 2>/dev/null || true)
if [[ "${BANNER}" =~ "SSH" ]]; then
echo "ok."
return 0
fi
retries=$((retries-1))
echo -n "$((${RETRIES}-${retries}))."
sleep ${RETRY_SLEEP}
done
echo
echo "${IMG} not reachable via ssh" 1>&2
return 1
}
function launch_qemu() {
qemu-system-arm -M virt -m 1024 \
-kernel ${KERNEL} \
-append "console=ttyAMA0 root=/dev/vda2" \
-drive if=none,file=imx6.img,format=raw,id=hd \
-device virtio-blk-device,drive=hd \
-device virtio-net-device,netdev=net0 \
-netdev user,id=net0,hostfwd=tcp::${SSH_FWD_PORT}-:22 \
-nographic \
-snapshot \
${NULL} >& tmp/test-${IMG}.log &
QEMU_PID=$!
if ! kill -0 $QEMU_PID; then
echo "ERR: qemu did not show up." 1>&2
return 1
fi
return 0
}
trap cleanup EXIT
launch_qemu
boot_wait
ssh_wait
do_tests
require 'spec_helper'
describe service('weston') do
# the QEMU image currently has no graphics adapter so skip tests
# there for now
describe service('weston'), :unless => is_qemu do
it { should be_running.under('systemd') }
end
......@@ -5,12 +5,18 @@ set :backend, :ssh
set :sudo_password, 'purism'
host = ENV['TARGET_HOST']
port = ENV['TARGET_PORT'] || 22
options = Net::SSH::Config.for(host)
options[:user] ||= 'purism'
options[:password] ||= 'purism'
options[:port] ||= port
set :host, options[:host_name] || host
set :ssh_options, options
def is_qemu()
virt = host_inventory['virtualization']
virt ? virt[:system] == 'qemu' : false
end
Markdown is supported
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