]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/hwdb-test.sh
Merge pull request #7198 from poettering/stdin-stdout
[thirdparty/systemd.git] / test / hwdb-test.sh
1 #!/bin/sh
2 # SPDX-License-Identifier: LGPL-2.1+
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 # systemd is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU Lesser General Public License as published by
12 # the Free Software Foundation; either version 2.1 of the License, or
13 # (at your option) any later version.
14 #
15 # systemd is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 # Lesser General Public License for more details.
19 #
20 # You should have received a copy of the GNU Lesser General Public License
21 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
22
23 set -e
24
25 ROOTDIR=$(dirname $(dirname $(readlink -f $0)))
26 SYSTEMD_HWDB=./systemd-hwdb
27
28 if [ ! -x "$SYSTEMD_HWDB" ]; then
29 echo "$SYSTEMD_HWDB does not exist, please build first"
30 exit 1
31 fi
32
33 D=$(mktemp --directory)
34 trap "rm -rf '$D'" EXIT INT QUIT PIPE
35 mkdir -p "$D/etc/udev"
36 ln -s "$ROOTDIR/hwdb" "$D/etc/udev/hwdb.d"
37
38 # Test "good" properties" — no warnings or errors allowed
39 err=$("$SYSTEMD_HWDB" update --root "$D" 2>&1 >/dev/null) && rc= || rc=$?
40 if [ -n "$err" ]; then
41 echo "$err"
42 exit ${rc:-1}
43 fi
44 if [ -n "$rc" ]; then
45 echo "$SYSTEMD_HWDB returned $rc"
46 exit $rc
47 fi
48
49 if [ ! -e "$D/etc/udev/hwdb.bin" ]; then
50 echo "$D/etc/udev/hwdb.bin was not generated"
51 exit 1
52 fi
53
54 # Test "bad" properties" — warnings required, errors not allowed
55 rm -f "$D/etc/udev/hwdb.bin" "$D/etc/udev/hwdb.d"
56
57 ln -s "$ROOTDIR/test/hwdb" "$D/etc/udev/hwdb.d"
58 err=$("$SYSTEMD_HWDB" update --root "$D" 2>&1 >/dev/null) && rc= || rc=$?
59 if [ -n "$rc" ]; then
60 echo "$SYSTEMD_HWDB returned $rc"
61 exit $rc
62 fi
63 if [ -n "$err" ]; then
64 echo "Expected warnings"
65 echo "$err"
66 else
67 echo "$SYSTEMD_HWDB unexpectedly printed no warnings"
68 exit 1
69 fi
70
71 if [ ! -e "$D/etc/udev/hwdb.bin" ]; then
72 echo "$D/etc/udev/hwdb.bin was not generated"
73 exit 1
74 fi