diff options
| author | Phil Sutter <phil@nwl.cc> | 2021-11-24 17:29:04 +0100 |
|---|---|---|
| committer | Phil Sutter <phil@nwl.cc> | 2026-01-27 23:01:54 +0100 |
| commit | db82466117b8bfc93923eec49114d47200f7f913 (patch) | |
| tree | 6f41eb349f97f1a64131755bc1c54fd16f40bcdf /tests | |
| parent | 0041f7189a2b9e649c3a58dcc2005eaa713bdac4 (diff) | |
tests: py: tools: Add regen_payloads.sh
Use this script to recreate all payload records.
Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/py/tools/regen_payloads.sh | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/py/tools/regen_payloads.sh b/tests/py/tools/regen_payloads.sh new file mode 100755 index 00000000..9fcbc2c0 --- /dev/null +++ b/tests/py/tools/regen_payloads.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +# update payload records in an automated fashion, trying to reduce diff sizes + + +# scan payloadfile and print record for cmd (if found) +find_payload() { # (payloadfile, cmd) + local found=false + + readarray -t pl <"$1" + for l in "${pl[@]}"; do + if [[ "$l" == "# "* ]]; then + $found && return + [[ "$l" == "$2" ]] && found=true + fi + $found && echo "$l" + done + $found || echo "Warning: Command '$2' not found in '$1'" >&2 +} + +cd $(dirname $0)/../ + +# make sure no stray output files get in the way +rm -f */*.got */*.gotgot + +# store payload records for later +# clear payload files to force regenerating (but leave them in place) +for pl in */*.payload*; do + [[ $pl == *.bak ]] && continue # ignore leftover .bak files + cp "$pl" "${pl}.bak" + echo >"$pl" +done + +# run the testsuite to create .got files +# pass -f to keep going despite missing payloads +./nft-test.py -f + +# restore old payload records +for plbak in */*.bak; do + mv "$plbak" "${plbak%.bak}" +done + +# sort created got files to match order in old payload records +for g in ${@:-*/*.payload*.got}; do + pl=${g%.got} + + [[ -f $g ]] || continue + [[ -f $pl ]] || continue + + readarray -t ploads <"$g" + readarray -t cmds <<< $(grep '^# ' $pl) + for cmd in "${cmds[@]}"; do + found=false + for l in "${ploads[@]}"; do + if [[ "$l" == "# "* ]]; then + $found && break + [[ "$l" == "$cmd" ]] && found=true + fi + $found && [[ "$l" != "" ]] && echo "$l" + done + if ! $found; then + echo "Warning: Command '$cmd' not found in '$g'" >&2 + else + echo "" + fi + done | head -n -1 >${g}got + + mv "${g}got" "${g}" +done + +# overwrite old payload records with new ones +for got in */*.payload*.got; do + mv "${got}" "${got%.got}" +done |
