about summary refs log tree commit diff
path: root/src/tests/client/test-client.sh
blob: ac07dd20a7d229bc1d9147cea8101ff522a19d83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash

# Runs the "test-python.sh" test, setting proper environment variables
# for the build tree.
#
# - the first three arguments are the BUILDDIR, SRCDIR and PYTHON paths.
#   The following arguments are passed on to "test-python.sh".
#
# - you can use "--" to separate the extra arguments.
#
# The full format is
#
#   $ src/tests/client/test-client.sh "$BUILDDIR" "$SRCDIR" "$PYTHON" -- "${EXTRA[@]}"
#
# - "$BUILDDIR" "$SRCDIR" and "$PYTHON" can be set to "", to fallback
#   to a default.
#
# The safe way to call it is thus
#
#     $ src/tests/client/test-client.sh "" "" "" -- "${EXTRA[@]}"
#
# but for brevity, you can also call
#
#     $ src/tests/client/test-client.sh -- "${EXTRA[@]}"
#
# if (and only if) "${EXTRA[@]}" does not contain "--".

set -e

die() {
    printf '%s\n' "$@"
    exit 1
}

if [ "$4" = "--" ] ; then
    ARGS=("${@:1:3}")
    EXTRA=("${@:5}")
elif [ "$3" = "--" ]; then
    ARGS=("${@:1:2}")
    EXTRA=("${@:4}")
elif [ "$2" = "--" ]; then
    ARGS=("${@:1:1}")
    EXTRA=("${@:3}")
elif [ "$1" = "--" ]; then
    ARGS=()
    EXTRA=("${@:2}")
else
    ARGS=("${@:1:3}")
    EXTRA=("${@:4}")
fi

if [ "${ARGS[1]}" != "" ]; then
    SRCDIR="$(realpath "${ARGS[1]}")"
else
    SRCDIR="$(realpath "$(dirname "$BASH_SOURCE")/../../..")"
fi

if [ "${ARGS[0]}" != "" ]; then
    BUILDDIR="$(realpath "${ARGS[0]}")"
elif test -d "$SRCDIR/build" ; then
    BUILDDIR="$(realpath "$SRCDIR/build")"
else
    BUILDDIR="$SRCDIR"
fi

if [ "${ARGS[2]}" != "" ]; then
    PYTHON="${ARGS[2]}"
elif [ "$PYTHON" == "" ]; then
    PYTHON="$(command -v python)" || die "python not found?"
fi

test -d "$BUILDDIR" || die "BUILDDIR \"$BUILDDIR\" does not exist?"
test -d "$SRCDIR" || die "SRCDIR \"$SRCDIR\" does not exist?"

if test -f "$BUILDDIR/src/libnm-client-impl/libnm.so" ; then
    LIBDIR="$BUILDDIR/src/libnm-client-impl"
else
    die "libnm.so does not exist under expected paths in \"$BUILDDIR/src/libnm-client-impl/\""
fi

mkdir -p "$BUILDDIR/src/tests/client/" || die "failure to create build output directory \"$BUILDDIR/src/tests/client/\""

export NM_TEST_CLIENT_NMCLI_PATH="$BUILDDIR/src/nmcli/nmcli"
export NM_TEST_CLIENT_CLOUD_SETUP_PATH="$BUILDDIR/src/nm-cloud-setup/nm-cloud-setup"
export GI_TYPELIB_PATH="$BUILDDIR/src/libnm-client-impl${GI_TYPELIB_PATH:+:$GI_TYPELIB_PATH}"
export LD_LIBRARY_PATH="$LIBDIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export NM_TEST_CLIENT_BUILDDIR="$BUILDDIR"

# we first collect all the output in "test-client.log" and print it at once
# afterwards. The only reason is that when you run with `make -j` that the
# test output is grouped together.

r="ok"
"$PYTHON" "$SRCDIR/src/tests/client/test-client.py" -v "${EXTRA[@]}" &> "$BUILDDIR/src/tests/client/test-client.log" || r=fail

cat "$BUILDDIR/src/tests/client/test-client.log"

test "$r" = ok || die "test-client.py failed!!"