blob: df2670b159d4ce6059591da1e5135d2fb2b0bccb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#!/bin/bash
# Configuration
TESTDIR="./"
RETURNCODE_SEPARATOR="_"
msg_error() {
echo "E: $1 ..." >&2
exit 1
}
msg_warn() {
echo "W: $1" >&2
}
msg_info() {
echo "I: $1"
}
if [ "$(id -u)" != "0" ] ; then
msg_error "this requires root!"
fi
[ -z "$NFT" ] && NFT="$(which nft)"
if [ ! -x "$NFT" ] ; then
msg_error "no nft binary!"
else
msg_info "using nft binary $NFT"
fi
if [ ! -d "$TESTDIR" ] ; then
msg_error "missing testdir $TESTDIR"
fi
FIND="$(which find)"
if [ ! -x "$FIND" ] ; then
msg_error "no find binary found"
fi
if [ "$1" == "-v" ] ; then
VERBOSE=y
fi
echo ""
ok=0
failed=0
for testfile in $(${FIND} ${TESTDIR} -executable -regex .*${RETURNCODE_SEPARATOR}[0-9]+)
do
$NFT flush ruleset
rc_spec=$(awk -F${RETURNCODE_SEPARATOR} '{print $NF}' <<< $testfile)
test_output=$(NFT=$NFT ${testfile} ${TESTS_OUTPUT} 2>&1)
rc_got=$?
if [ "$rc_got" == "$rc_spec" ] ; then
msg_info "[OK] $testfile"
[ "$VERBOSE" == "y" ] && [ ! -z "$test_output" ] && echo "$test_output"
((ok++))
else
((failed++))
if [ "$VERBOSE" == "y" ] ; then
msg_warn "[FAILED] $testfile: expected $rc_spec but got $rc_got"
[ ! -z "$test_output" ] && echo "$test_output"
else
msg_warn "[FAILED] $testfile"
fi
fi
done
echo ""
msg_info "results: [OK] $ok [FAILED] $failed [TOTAL] $((ok+failed))"
$NFT flush ruleset
|