about summary refs log tree commit diff
path: root/test/run.sh
blob: 915c728ac413e24418272e1649e7278ef388a941 (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
#!/bin/sh
# run.sh — build and run the run-guix-container unit tests.
#
# Usage: ./run.sh

set -e

here=$(cd "$(dirname "$0")" && pwd)
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT

# Find a real generated container script in the store, if any.
container=$(ls /gnu/store | grep -E '^[0-9a-z]{32}-run-container$' | head -1)
if [ -n "$container" ]; then
    container="/gnu/store/$container"
fi

cc -O2 -Wall -o "$tmp/test" "$here/test.c"
cc -O2 -Wall -o "$tmp/daemon" "$here/../bin/run-guix-system-container.c"

# The daemon's own switches: --log-dir must stay advertised (it is how a host
# with a read-only /var keeps container logs), and anything unknown must
# print the usage rather than start a half-configured daemon.
echo "daemon switches:"
if "$tmp/daemon" --help 2>&1 | grep -q -- "--log-dir"; then
    echo "  ok   --log-dir advertised"
else
    echo "  FAIL --log-dir missing from --help"; exit 1
fi
# ... and the chosen directory must actually reach the daemon: it names it at
# startup, which is observable without root.
if "$tmp/daemon" --log-dir /tmp/rgsc-test-logs --port 8994 2>&1 \
        | grep -q "container logs: /tmp/rgsc-test-logs"; then
    echo "  ok   --log-dir reaches the daemon"
else
    echo "  FAIL --log-dir did not reach the daemon"; exit 1
fi
if GUIX_CONTAINER_LOG_DIR=/tmp/rgsc-env-logs "$tmp/daemon" --port 8994 2>&1 \
        | grep -q "container logs: /tmp/rgsc-env-logs"; then
    echo "  ok   GUIX_CONTAINER_LOG_DIR reaches the daemon"
else
    echo "  FAIL GUIX_CONTAINER_LOG_DIR did not reach the daemon"; exit 1
fi
if "$tmp/daemon" --no-such-option >/dev/null 2>&1; then
    echo "  FAIL unknown option accepted"; exit 1
else
    echo "  ok   unknown option refused"
fi

"$tmp/test" "$container" "$tmp"