summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorFrantisek Sumsal <frantisek@sumsal.cz>2021-04-02 19:51:44 +0200
committerLuca Boccassi <luca.boccassi@gmail.com>2021-04-05 14:41:05 +0100
commit34fde9f898f63096262d95c61d75db85dabe6fe4 (patch)
tree058e62b9d8968dd1f0ad66899613dc0fb5234499 /tools
parent080a602771ef51230a51f247b8b728d0483e2f28 (diff)
downloadsystemd-34fde9f898f63096262d95c61d75db85dabe6fe4.tar.gz
test: check if the unit file fuzzer corpora is up to date
This follows a similar pattern we already have in place for networkd-related directives.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/check-directives.sh60
1 files changed, 47 insertions, 13 deletions
diff --git a/tools/check-directives.sh b/tools/check-directives.sh
index 1d11fa98a1..2274d36e60 100755
--- a/tools/check-directives.sh
+++ b/tools/check-directives.sh
@@ -1,37 +1,71 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
-set -e
+set -eu
-which perl &>/dev/null || exit 77
+SOURCE_ROOT="${1:?Missing argument: project source root}"
+BUILD_ROOT="${2:?Missing argument: project build root}"
+
+command -v gawk &>/dev/null || exit 77
function generate_directives() {
- perl -aF'/[\s,]+/' -ne '
- if (my ($s, $d) = ($F[0] =~ /^([^\s\.]+)\.([^\s\.]+)$/)) { $d{$s}{"$d="} = 1; }
- END { while (my ($key, $value) = each %d) {
- printf "[%s]\n%s\n", $key, join("\n", keys(%$value))
- }}' "$1"
+ gawk -v sec_rx="${2:-""}" -v unit_type="${3:-""}" '
+ match($0, /^([^ \t\.]+)\.([^ \t\.,]+)/, m) {
+ # res[section][directive] = 1
+ res[m[1]][m[2]] = 1;
+ }
+ END {
+ if (unit_type)
+ print unit_type
+
+ for (section in res) {
+ if (sec_rx && section !~ sec_rx)
+ continue
+
+ print "[" section "]";
+ for (directive in res[section]) {
+ print directive "=";
+ }
+ }
+ }
+ ' "$1"
}
ret=0
if ! diff \
- <(generate_directives "$1"/src/network/networkd-network-gperf.gperf | sort) \
- <(cat "$1"/test/fuzz/fuzz-network-parser/directives.network | sort); then
+ <(generate_directives "$SOURCE_ROOT"/src/network/networkd-network-gperf.gperf | sort) \
+ <(sort "$SOURCE_ROOT"/test/fuzz/fuzz-network-parser/directives.network); then
echo "Looks like test/fuzz/fuzz-network-parser/directives.network hasn't been updated"
ret=1
fi
if ! diff \
- <(generate_directives "$1"/src/network/netdev/netdev-gperf.gperf | sort) \
- <(cat "$1"/test/fuzz/fuzz-netdev-parser/directives.netdev | sort); then
+ <(generate_directives "$SOURCE_ROOT"/src/network/netdev/netdev-gperf.gperf | sort) \
+ <(sort "$SOURCE_ROOT"/test/fuzz/fuzz-netdev-parser/directives.netdev); then
echo "Looks like test/fuzz/fuzz-netdev-parser/directives.netdev hasn't been updated"
ret=1
fi
if ! diff \
- <(generate_directives "$1"/src/udev/net/link-config-gperf.gperf | sort) \
- <(cat "$1"/test/fuzz/fuzz-link-parser/directives.link | sort) ; then
+ <(generate_directives "$SOURCE_ROOT"/src/udev/net/link-config-gperf.gperf | sort) \
+ <(sort "$SOURCE_ROOT"/test/fuzz/fuzz-link-parser/directives.link) ; then
echo "Looks like test/fuzz/fuzz-link-parser/directives.link hasn't been updated"
ret=1
fi
+for section in Automount Mount Path Scope Slice Socket Swap Timer; do
+ if ! diff \
+ <(generate_directives "$BUILD_ROOT"/src/core/load-fragment-gperf.gperf "$section" "${section,,}" | sort) \
+ <(sort "$SOURCE_ROOT/test/fuzz/fuzz-unit-file/directives.${section,,}") ; then
+ echo "Looks like test/fuzz/fuzz-unit-file/directives.${section,,} hasn't been updated"
+ ret=1
+ fi
+done
+
+if ! diff \
+ <(generate_directives "$BUILD_ROOT"/src/core/load-fragment-gperf.gperf "(Service|Unit|Install)" "service" | sort) \
+ <(sort "$SOURCE_ROOT/test/fuzz/fuzz-unit-file/directives.service") ; then
+ echo "Looks like test/fuzz/fuzz-unit-file/directives.service hasn't been updated"
+ ret=1
+fi
+
exit $ret