summaryrefslogtreecommitdiffstats
path: root/test/hwdb
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 02:25:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 02:25:50 +0000
commit19f4f86bfed21c5326ed2acebe1163f3a83e832b (patch)
treed59b9989ce55ed23693e80974d94c856f1c2c8b1 /test/hwdb
parentInitial commit. (diff)
downloadsystemd-upstream.tar.xz
systemd-upstream.zip
Adding upstream version 241.upstream/241upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-xtest/hwdb-test.sh62
-rw-r--r--test/hwdb/10-bad.hwdb26
2 files changed, 88 insertions, 0 deletions
diff --git a/test/hwdb-test.sh b/test/hwdb-test.sh
new file mode 100755
index 0000000..05363e9
--- /dev/null
+++ b/test/hwdb-test.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+# SPDX-License-Identifier: LGPL-2.1+
+#
+# Call built systemd-hwdb update on our hwdb files to ensure that they parse
+# without error
+#
+# (C) 2016 Canonical Ltd.
+# Author: Martin Pitt <martin.pitt@ubuntu.com>
+
+set -e
+
+export SYSTEMD_LOG_LEVEL=info
+ROOTDIR=$(dirname $(dirname $(readlink -f $0)))
+SYSTEMD_HWDB=./systemd-hwdb
+
+if [ ! -x "$SYSTEMD_HWDB" ]; then
+ echo "$SYSTEMD_HWDB does not exist, please build first"
+ exit 1
+fi
+
+D=$(mktemp --directory)
+trap "rm -rf '$D'" EXIT INT QUIT PIPE
+mkdir -p "$D/etc/udev"
+ln -s "$ROOTDIR/hwdb" "$D/etc/udev/hwdb.d"
+
+# Test "good" properties" — no warnings or errors allowed
+err=$("$SYSTEMD_HWDB" update --root "$D" 2>&1 >/dev/null) && rc= || rc=$?
+if [ -n "$err" ]; then
+ echo "$err"
+ exit ${rc:-1}
+fi
+if [ -n "$rc" ]; then
+ echo "$SYSTEMD_HWDB returned $rc"
+ exit $rc
+fi
+
+if [ ! -e "$D/etc/udev/hwdb.bin" ]; then
+ echo "$D/etc/udev/hwdb.bin was not generated"
+ exit 1
+fi
+
+# Test "bad" properties" — warnings required, errors not allowed
+rm -f "$D/etc/udev/hwdb.bin" "$D/etc/udev/hwdb.d"
+
+ln -s "$ROOTDIR/test/hwdb" "$D/etc/udev/hwdb.d"
+err=$("$SYSTEMD_HWDB" update --root "$D" 2>&1 >/dev/null) && rc= || rc=$?
+if [ -n "$rc" ]; then
+ echo "$SYSTEMD_HWDB returned $rc"
+ exit $rc
+fi
+if [ -n "$err" ]; then
+ echo "Expected warnings"
+ echo "$err"
+else
+ echo "$SYSTEMD_HWDB unexpectedly printed no warnings"
+ exit 1
+fi
+
+if [ ! -e "$D/etc/udev/hwdb.bin" ]; then
+ echo "$D/etc/udev/hwdb.bin was not generated"
+ exit 1
+fi
diff --git a/test/hwdb/10-bad.hwdb b/test/hwdb/10-bad.hwdb
new file mode 100644
index 0000000..0e1e147
--- /dev/null
+++ b/test/hwdb/10-bad.hwdb
@@ -0,0 +1,26 @@
+BAD:1:no properties
+
+BAD:2:no properties
+BAD:2:no properties
+
+BAD:3:no properties
+BAD:3:no properties
+BAD:3:no properties
+
+GOOD:5:bad property
+ NO_VALUE
+
+GOOD:6:bad property
+ =NO_NAME
+ NO_VALUE=
+
+BAD:7:match at wrong place
+ X=Y
+BAD:7:match at wrong place
+
+BAD:8:match at wrong place
+ X=Y
+BAD:8:match at wrong place
+ Z=z
+
+BAD:8:match at EOF