2016-11-24 18:29:42 +08:00
|
|
|
#!/bin/sh
|
2020-11-09 12:23:58 +08:00
|
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
2017-11-19 01:18:16 +08:00
|
|
|
#
|
|
|
|
# Call built systemd-hwdb update on our hwdb files to ensure that they parse
|
2016-11-24 18:29:42 +08:00
|
|
|
# without error
|
|
|
|
#
|
|
|
|
# (C) 2016 Canonical Ltd.
|
|
|
|
# Author: Martin Pitt <martin.pitt@ubuntu.com>
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2017-11-25 23:01:55 +08:00
|
|
|
export SYSTEMD_LOG_LEVEL=info
|
2023-12-19 23:01:54 +08:00
|
|
|
export SYSTEMD_HWDB_UPDATE_BYPASS=0
|
2021-09-30 02:30:08 +08:00
|
|
|
ROOTDIR="$(dirname "$(dirname "$(readlink -f "$0")")")"
|
2022-05-04 14:24:06 +08:00
|
|
|
SYSTEMD_HWDB="${1:?}"
|
2016-11-24 18:29:42 +08:00
|
|
|
|
|
|
|
if [ ! -x "$SYSTEMD_HWDB" ]; then
|
2021-04-15 14:20:31 +08:00
|
|
|
echo "$SYSTEMD_HWDB is not executable" >&2
|
2016-11-24 18:29:42 +08:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-09-30 02:30:08 +08:00
|
|
|
D="$(mktemp --tmpdir --directory "hwdb-test.XXXXXXXXXX")"
|
|
|
|
# shellcheck disable=SC2064
|
2016-11-24 18:29:42 +08:00
|
|
|
trap "rm -rf '$D'" EXIT INT QUIT PIPE
|
|
|
|
mkdir -p "$D/etc/udev"
|
2022-08-22 20:06:10 +08:00
|
|
|
cp -a "$ROOTDIR/hwdb.d" "$D/etc/udev/hwdb.d"
|
2016-11-30 11:41:52 +08:00
|
|
|
|
hwdb: improve and test syntax error messages
Since syntax error are non-fatal, downgrade them to warnings.
Use log_syntax to have uniform formatting including the line number.
State machine states like DATA and MATCH are internal, user-facing
messages should use the names from hwdb(7): match, property, record.
Also change "key/value" to "key-value", since there's no alternative
here, both parts must be present.
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:2] Property expected, ignoring record with no properties
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:5] Property expected, ignoring record with no properties
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:9] Property expected, ignoring record with no properties
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:11] Key/value pair expected but got " NO_VALUE", ignoring
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:18] Property or empty line expected, got "BAD:7:match at wrong place", ignoring record
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:22] Property or empty line expected, got "BAD:8:match at wrong place", ignoring record
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:23] Match expected but got indented property " Z=z", ignoring line
squash! hwdb: improve syntax error messages
2016-12-01 23:55:32 +08:00
|
|
|
# Test "good" properties" — no warnings or errors allowed
|
2016-11-30 11:41:52 +08:00
|
|
|
err=$("$SYSTEMD_HWDB" update --root "$D" 2>&1 >/dev/null) && rc= || rc=$?
|
2016-11-24 18:29:42 +08:00
|
|
|
if [ -n "$err" ]; then
|
|
|
|
echo "$err"
|
2023-06-06 05:48:06 +08:00
|
|
|
exit "${rc:-1}"
|
2016-11-24 18:29:42 +08:00
|
|
|
fi
|
2016-11-30 11:41:52 +08:00
|
|
|
if [ -n "$rc" ]; then
|
|
|
|
echo "$SYSTEMD_HWDB returned $rc"
|
2023-06-06 05:48:06 +08:00
|
|
|
exit "$rc"
|
2016-11-30 11:41:52 +08:00
|
|
|
fi
|
|
|
|
|
2016-11-24 18:29:42 +08:00
|
|
|
if [ ! -e "$D/etc/udev/hwdb.bin" ]; then
|
|
|
|
echo "$D/etc/udev/hwdb.bin was not generated"
|
|
|
|
exit 1
|
|
|
|
fi
|
hwdb: improve and test syntax error messages
Since syntax error are non-fatal, downgrade them to warnings.
Use log_syntax to have uniform formatting including the line number.
State machine states like DATA and MATCH are internal, user-facing
messages should use the names from hwdb(7): match, property, record.
Also change "key/value" to "key-value", since there's no alternative
here, both parts must be present.
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:2] Property expected, ignoring record with no properties
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:5] Property expected, ignoring record with no properties
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:9] Property expected, ignoring record with no properties
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:11] Key/value pair expected but got " NO_VALUE", ignoring
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:18] Property or empty line expected, got "BAD:7:match at wrong place", ignoring record
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:22] Property or empty line expected, got "BAD:8:match at wrong place", ignoring record
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:23] Match expected but got indented property " Z=z", ignoring line
squash! hwdb: improve syntax error messages
2016-12-01 23:55:32 +08:00
|
|
|
|
|
|
|
# Test "bad" properties" — warnings required, errors not allowed
|
2022-08-22 20:06:10 +08:00
|
|
|
rm -rf "$D/etc/udev/hwdb.bin" "$D/etc/udev/hwdb.d"
|
hwdb: improve and test syntax error messages
Since syntax error are non-fatal, downgrade them to warnings.
Use log_syntax to have uniform formatting including the line number.
State machine states like DATA and MATCH are internal, user-facing
messages should use the names from hwdb(7): match, property, record.
Also change "key/value" to "key-value", since there's no alternative
here, both parts must be present.
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:2] Property expected, ignoring record with no properties
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:5] Property expected, ignoring record with no properties
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:9] Property expected, ignoring record with no properties
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:11] Key/value pair expected but got " NO_VALUE", ignoring
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:18] Property or empty line expected, got "BAD:7:match at wrong place", ignoring record
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:22] Property or empty line expected, got "BAD:8:match at wrong place", ignoring record
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:23] Match expected but got indented property " Z=z", ignoring line
squash! hwdb: improve syntax error messages
2016-12-01 23:55:32 +08:00
|
|
|
|
2022-08-22 20:06:10 +08:00
|
|
|
cp -a "$ROOTDIR/test/hwdb.d" "$D/etc/udev/hwdb.d"
|
hwdb: improve and test syntax error messages
Since syntax error are non-fatal, downgrade them to warnings.
Use log_syntax to have uniform formatting including the line number.
State machine states like DATA and MATCH are internal, user-facing
messages should use the names from hwdb(7): match, property, record.
Also change "key/value" to "key-value", since there's no alternative
here, both parts must be present.
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:2] Property expected, ignoring record with no properties
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:5] Property expected, ignoring record with no properties
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:9] Property expected, ignoring record with no properties
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:11] Key/value pair expected but got " NO_VALUE", ignoring
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:18] Property or empty line expected, got "BAD:7:match at wrong place", ignoring record
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:22] Property or empty line expected, got "BAD:8:match at wrong place", ignoring record
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:23] Match expected but got indented property " Z=z", ignoring line
squash! hwdb: improve syntax error messages
2016-12-01 23:55:32 +08:00
|
|
|
err=$("$SYSTEMD_HWDB" update --root "$D" 2>&1 >/dev/null) && rc= || rc=$?
|
|
|
|
if [ -n "$rc" ]; then
|
|
|
|
echo "$SYSTEMD_HWDB returned $rc"
|
2023-06-06 05:48:06 +08:00
|
|
|
exit "$rc"
|
hwdb: improve and test syntax error messages
Since syntax error are non-fatal, downgrade them to warnings.
Use log_syntax to have uniform formatting including the line number.
State machine states like DATA and MATCH are internal, user-facing
messages should use the names from hwdb(7): match, property, record.
Also change "key/value" to "key-value", since there's no alternative
here, both parts must be present.
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:2] Property expected, ignoring record with no properties
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:5] Property expected, ignoring record with no properties
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:9] Property expected, ignoring record with no properties
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:11] Key/value pair expected but got " NO_VALUE", ignoring
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:18] Property or empty line expected, got "BAD:7:match at wrong place", ignoring record
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:22] Property or empty line expected, got "BAD:8:match at wrong place", ignoring record
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:23] Match expected but got indented property " Z=z", ignoring line
squash! hwdb: improve syntax error messages
2016-12-01 23:55:32 +08:00
|
|
|
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
|