]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/hwdb-test.sh
man/systemd.mount: tmpfs automatically gains After=swap.target dep
[thirdparty/systemd.git] / test / hwdb-test.sh
1 #!/bin/sh
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 #
4 # Call built systemd-hwdb update on our hwdb files to ensure that they parse
5 # without error
6 #
7 # (C) 2016 Canonical Ltd.
8 # Author: Martin Pitt <martin.pitt@ubuntu.com>
9
10 set -e
11
12 export SYSTEMD_LOG_LEVEL=info
13 ROOTDIR="$(dirname "$(dirname "$(readlink -f "$0")")")"
14 SYSTEMD_HWDB="${1:?}"
15
16 if [ ! -x "$SYSTEMD_HWDB" ]; then
17 echo "$SYSTEMD_HWDB is not executable" >&2
18 exit 1
19 fi
20
21 D="$(mktemp --tmpdir --directory "hwdb-test.XXXXXXXXXX")"
22 # shellcheck disable=SC2064
23 trap "rm -rf '$D'" EXIT INT QUIT PIPE
24 mkdir -p "$D/etc/udev"
25 cp -a "$ROOTDIR/hwdb.d" "$D/etc/udev/hwdb.d"
26
27 # Test "good" properties" — no warnings or errors allowed
28 err=$("$SYSTEMD_HWDB" update --root "$D" 2>&1 >/dev/null) && rc= || rc=$?
29 if [ -n "$err" ]; then
30 echo "$err"
31 exit "${rc:-1}"
32 fi
33 if [ -n "$rc" ]; then
34 echo "$SYSTEMD_HWDB returned $rc"
35 exit "$rc"
36 fi
37
38 if [ ! -e "$D/etc/udev/hwdb.bin" ]; then
39 echo "$D/etc/udev/hwdb.bin was not generated"
40 exit 1
41 fi
42
43 # Test "bad" properties" — warnings required, errors not allowed
44 rm -rf "$D/etc/udev/hwdb.bin" "$D/etc/udev/hwdb.d"
45
46 cp -a "$ROOTDIR/test/hwdb.d" "$D/etc/udev/hwdb.d"
47 err=$("$SYSTEMD_HWDB" update --root "$D" 2>&1 >/dev/null) && rc= || rc=$?
48 if [ -n "$rc" ]; then
49 echo "$SYSTEMD_HWDB returned $rc"
50 exit "$rc"
51 fi
52 if [ -n "$err" ]; then
53 echo "Expected warnings"
54 echo "$err"
55 else
56 echo "$SYSTEMD_HWDB unexpectedly printed no warnings"
57 exit 1
58 fi
59
60 if [ ! -e "$D/etc/udev/hwdb.bin" ]; then
61 echo "$D/etc/udev/hwdb.bin was not generated"
62 exit 1
63 fi