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 10set -e 11 12export SYSTEMD_LOG_LEVEL=info 13ROOTDIR="$(dirname "$(dirname "$(readlink -f "$0")")")" 14SYSTEMD_HWDB="${1:?}" 15 16if [ ! -x "$SYSTEMD_HWDB" ]; then 17 echo "$SYSTEMD_HWDB is not executable" >&2 18 exit 1 19fi 20 21D="$(mktemp --tmpdir --directory "hwdb-test.XXXXXXXXXX")" 22# shellcheck disable=SC2064 23trap "rm -rf '$D'" EXIT INT QUIT PIPE 24mkdir -p "$D/etc/udev" 25ln -s "$ROOTDIR/hwdb.d" "$D/etc/udev/hwdb.d" 26 27# Test "good" properties" — no warnings or errors allowed 28err=$("$SYSTEMD_HWDB" update --root "$D" 2>&1 >/dev/null) && rc= || rc=$? 29if [ -n "$err" ]; then 30 echo "$err" 31 exit ${rc:-1} 32fi 33if [ -n "$rc" ]; then 34 echo "$SYSTEMD_HWDB returned $rc" 35 exit $rc 36fi 37 38if [ ! -e "$D/etc/udev/hwdb.bin" ]; then 39 echo "$D/etc/udev/hwdb.bin was not generated" 40 exit 1 41fi 42 43# Test "bad" properties" — warnings required, errors not allowed 44rm -f "$D/etc/udev/hwdb.bin" "$D/etc/udev/hwdb.d" 45 46ln -s "$ROOTDIR/test/hwdb.d" "$D/etc/udev/hwdb.d" 47err=$("$SYSTEMD_HWDB" update --root "$D" 2>&1 >/dev/null) && rc= || rc=$? 48if [ -n "$rc" ]; then 49 echo "$SYSTEMD_HWDB returned $rc" 50 exit $rc 51fi 52if [ -n "$err" ]; then 53 echo "Expected warnings" 54 echo "$err" 55else 56 echo "$SYSTEMD_HWDB unexpectedly printed no warnings" 57 exit 1 58fi 59 60if [ ! -e "$D/etc/udev/hwdb.bin" ]; then 61 echo "$D/etc/udev/hwdb.bin was not generated" 62 exit 1 63fi 64