xref: /openbmc/qemu/tests/docker/run (revision 785ea711)
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
21export PATH=/usr/lib/ccache:/usr/lib64/ccache:$PATH
22
23if test -n "$J"; then
24    export MAKEFLAGS="$MAKEFLAGS -j$J"
25fi
26
27# We are in the container so the whole file system belong to us
28export TEST_DIR=/tmp/qemu-test
29mkdir -p $TEST_DIR/{src,build,install}
30
31# Extract the source tarballs
32tar -C $TEST_DIR/src -xf $BASE/qemu.tar || { echo "Failed to untar source"; exit 2; }
33
34if test -n "$SHOW_ENV"; then
35    if test -f /packages.txt; then
36        echo "Packages installed:"
37        cat /packages.txt
38        echo
39    fi
40    echo "Environment variables:"
41    env
42    echo
43fi
44
45export QEMU_SRC="$TEST_DIR/src"
46export BUILD_DIR="$TEST_DIR/build"
47export INSTALL_DIR="$TEST_DIR/install"
48
49cd "$QEMU_SRC/tests/docker"
50
51CMD="./$@"
52
53if test -z "$DEBUG"; then
54    exec $CMD
55fi
56
57# DEBUG workflow
58echo "* Prepared to run command:"
59echo "  $CMD"
60echo "* Hit Ctrl-D to continue, or type 'exit 1' to abort"
61echo
62env bash --noprofile --norc
63
64if "$CMD"; then
65    exit 0
66elif test -n "$DEBUG"; then
67    echo "* Command failed:"
68    echo "  $CMD"
69    echo "* Hit Ctrl-D to exit"
70    echo
71    # Force error after shell exits
72    env bash --noprofile --norc && exit 1
73else
74    exit 1
75fi
76