-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_determine_max_packet_size.sh
More file actions
executable file
·94 lines (74 loc) · 2.21 KB
/
Copy pathtest_determine_max_packet_size.sh
File metadata and controls
executable file
·94 lines (74 loc) · 2.21 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/sh
# Test wrapper for determine_max_packet_size
set -u
SCRIPT="$(PWD)/determine_max_packet_size"
TMPDIR=/tmp/mtu_test_$$
mkdir -p "$TMPDIR"
trap 'rm -rf "$TMPDIR"' EXIT
LOG="$TMPDIR/test.log"
ERR="$TMPDIR/test.err"
echo "============================================"
echo " MTU checker v4 - Test Suite"
echo "============================================"
echo ""
count=0
pass=0
fail=0
run_test() {
_name="$1"
_args="$2"
_min_ok="$3" # 0=exit ok, 1=exit fail
_should_contain="$4" # string that must appear in stdout
count=$((count + 1))
printf 'Test %d: %-40s ' "$count" "$_name"
if ! [ -x "$SCRIPT" ]; then
echo "FAIL (script not executable)"
fail=$((fail + 1))
return
fi
_rc=0
"$SCRIPT" $_args >"$LOG" 2>"$ERR" || _rc=1
if [ "$_min_ok" -eq 0 ] && [ "$_rc" -ne 0 ]; then
echo "FAIL (exit $_rc, expected 0)"
fail=$((fail + 1))
return
fi
if [ "$_min_ok" -eq 1 ] && [ "$_rc" -eq 0 ]; then
echo "FAIL (exit 0, expected non-zero)"
fail=$((fail + 1))
return
fi
if ! grep -q "$_should_contain" "$LOG" "$ERR"; then
echo "FAIL (missing '$_should_contain')"
fail=$((fail + 1))
return
fi
echo "PASS"
pass=$((pass + 1))
}
# 1. Localhost - must succeed, obviously reachable
run_test "localhost (IPv4+IPv6)" "localhost" 0 "IPv4:"
# 2. Google DNS IPv4
run_test "8.8.8.8 (IPv4 literal)" "8.8.8.8" 0 "IPv4:"
# 3. Google DNS IPv6
run_test "2001:4860:4860::8888 (IPv6 literal)" "2001:4860:4860::8888" 0 "IPv6:"
# 4. Google.com by name (dual stack)
run_test "google.com (dual stack)" "google.com" 0 "IPv4:"
# 5. Bad hostname
run_test "invalid.bad.tld (DNS fail)" "invalid.bad.tld" 1 "failed entirely"
# 6. Verbose mode on working host (must contain debug output)
run_test "localhost -v (verbose)" "-v localhost" 0 "Checking"
echo ""
echo "============================================"
printf " Results: %d passed, %d failed, %d total\n" "$pass" "$fail" "$count"
echo "============================================"
if [ "$fail" -gt 0 ]; then
echo ""
echo "--- Last stdout ---"
cat "$LOG"
echo ""
echo "--- Last stderr ---"
cat "$ERR"
exit 1
fi
exit 0