xref: /openbmc/qemu/tests/docker/common.rc (revision 64ed6f92)
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()
19{
20    for c in $@; do
21        if ! echo "$FEATURES" | grep -wq -e "$c"; then
22            echo "Prerequisite '$c' not present, skip"
23            exit 0
24        fi
25    done
26}
27
28configure_qemu()
29{
30    config_opts="--enable-werror \
31                 ${TARGET_LIST:+--target-list=${TARGET_LIST}} \
32                 --prefix=$INSTALL_DIR \
33                 $QEMU_CONFIGURE_OPTS $EXTRA_CONFIGURE_OPTS \
34                 $@"
35    echo "Configure options:"
36    echo $config_opts
37    $QEMU_SRC/configure $config_opts || \
38        { cat config.log && test_fail "Failed to run 'configure'"; }
39}
40
41build_qemu()
42{
43    configure_qemu $@
44    make $MAKEFLAGS
45}
46
47check_qemu()
48{
49    # default to make check unless the caller specifies
50    if [ $# = 0 ]; then
51        INVOCATION="check"
52    else
53        INVOCATION="$@"
54    fi
55
56    make $MAKEFLAGS $INVOCATION
57}
58
59test_fail()
60{
61    echo "$@"
62    exit 1
63}
64
65prep_fail()
66{
67    echo "$@"
68    exit 2
69}
70
71install_qemu()
72{
73    make install $MAKEFLAGS DESTDIR=$PWD/=destdir
74    ret=$?
75    rm -rf $PWD/=destdir
76    return $ret
77}
78