xref: /openbmc/qemu/tests/docker/run (revision 44b1ff31)
1#!/bin/bash
2#
3# Docker test runner
4#
5# Copyright (c) 2016 Red Hat Inc.
6#
7# Authors:
8#  Fam Zheng <famz@redhat.com>
9#
10# This work is licensed under the terms of the GNU GPL, version 2
11# or (at your option) any later version. See the COPYING file in
12# the top-level directory.
13
14if test -n "$V"; then
15    set -x
16fi
17
18BASE="$(dirname $(readlink -e $0))"
19
20# Prepare the environment
21. /etc/profile
22export PATH=/usr/lib/ccache:$PATH
23
24if test -n "$J"; then
25    export MAKEFLAGS="$MAKEFLAGS -j$J"
26fi
27
28# We are in the container so the whole file system belong to us
29export TEST_DIR=/tmp/qemu-test
30mkdir -p $TEST_DIR/{src,build,install}
31
32# Extract the source tarballs
33tar -C $TEST_DIR/src -xf $BASE/qemu.tar || prep_fail "Failed to untar source"
34
35if test -n "$SHOW_ENV"; then
36    if test -f /packages.txt; then
37        echo "Packages installed:"
38        cat /packages.txt
39        echo
40    fi
41    echo "Environment variables:"
42    env
43    echo
44fi
45
46export QEMU_SRC="$TEST_DIR/src"
47export BUILD_DIR="$TEST_DIR/build"
48export INSTALL_DIR="$TEST_DIR/install"
49
50cd "$QEMU_SRC/tests/docker"
51
52CMD="./$@"
53
54if test -z "$DEBUG"; then
55    exec $CMD
56fi
57
58# DEBUG workflow
59echo "* Prepared to run command:"
60echo "  $CMD"
61echo "* Hit Ctrl-D to continue, or type 'exit 1' to abort"
62echo
63$SHELL
64
65if "$CMD"; then
66    exit 0
67elif test -n "$DEBUG"; then
68    echo "* Command failed:"
69    echo "  $CMD"
70    echo "* Hit Ctrl-D to exit"
71    echo
72    # Force error after shell exits
73    $SHELL && exit 1
74else
75    exit 1
76fi
77