xref: /openbmc/qemu/tests/docker/common.rc (revision 30b6852c)
1#!/bin/sh
2#
3# Common routines for docker test scripts.
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
14# This might be set by ENV of a docker container... it is always
15# overriden by TARGET_LIST if the user sets it.
16DEF_TARGET_LIST=${DEF_TARGET_LIST:-"x86_64-softmmu,aarch64-softmmu"}
17
18requires_binary()
19{
20    found=0
21    for c in $@; do
22        for d in /bin /usr/bin /usr/local/bin
23        do
24            if test -f "$d/$c"
25            then
26                found=1
27            fi
28        done
29    done
30    if test "$found" != "1"
31    then
32        echo "Prerequisite '$c' not present, skip"
33        exit 0
34    fi
35}
36
37configure_qemu()
38{
39    config_opts="--enable-werror \
40                 ${TARGET_LIST:+--target-list=${TARGET_LIST}} \
41                 --prefix=$INSTALL_DIR \
42                 $QEMU_CONFIGURE_OPTS $EXTRA_CONFIGURE_OPTS \
43                 $@"
44    echo "Configure options:"
45    echo $config_opts
46    $QEMU_SRC/configure $config_opts || \
47        { cat config.log && test_fail "Failed to run 'configure'"; }
48}
49
50build_qemu()
51{
52    configure_qemu $@
53    make $MAKEFLAGS
54}
55
56check_qemu()
57{
58    # default to make check unless the caller specifies
59    if [ $# = 0 ]; then
60        INVOCATION="check"
61    else
62        INVOCATION="$@"
63    fi
64
65    make $MAKEFLAGS $INVOCATION
66}
67
68test_fail()
69{
70    echo "$@"
71    exit 1
72}
73
74prep_fail()
75{
76    echo "$@"
77    exit 2
78}
79
80install_qemu()
81{
82    make install $MAKEFLAGS DESTDIR=$PWD/=destdir
83    ret=$?
84    rm -rf $PWD/=destdir
85    return $ret
86}
87