Skip to content

Commit

Permalink
Rework tests to actually check something
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Mar 16, 2024
1 parent 3ceb468 commit d966a9b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 15 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ on:
paths:
- 'src/**.[ch]'
- '**/Makefile'
- 'util/**.sh'
- '.github/workflows/**.yml'
pull_request:
paths:
- 'src/**.[ch]'
- '**/Makefile'
- 'util/**.sh'
- '.github/workflows/**.yml'

jobs:
Expand All @@ -30,7 +32,11 @@ jobs:

- name: Test
run: |
sudo ./util/ci-test.sh
./util/ci-test.sh
- name: Test 2
run: |
sudo ./util/ci-test2.sh
clang:
Expand All @@ -50,4 +56,8 @@ jobs:

- name: Test
run: |
sudo ./util/ci-test.sh
./util/ci-test.sh
- name: Test 2
run: |
sudo ./util/ci-test2.sh
54 changes: 41 additions & 13 deletions util/ci-test.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,50 @@
#!/bin/bash -e
if=dummy0
if [ ! -e /sys/class/net/$if ]; then
ip l add $if type dummy
ip l set $if up
ip r add 100::/64 dev $if
fi
pcap=test.pcap
log=out.txt

args=(
--interface $if
--quiet
--interface "dump:$pcap"
--source-mac 02:00:00:00:00:f0
--router-mac 02-00-00-00-00-0F
--source-ip 2001:db8::1
--source-port 64000
)

echo "ICMP:"
./fi6s "${args[@]}" --icmp 100::x
echo "TCP:"
./fi6s "${args[@]}" -b -p 1 100::x
echo "UDP:"
./fi6s "${args[@]}" -bu -p 53 100::x
ecode=0
dotest () {
echo "=== Running test: $id ==="
./fi6s "${args[@]}" "${args2[@]}" || :
tcpdump -nn -v -r "$pcap" >$log 2>/dev/null
if ! grep -aP "$regex" $log; then
echo "FAILED, actual dump:"
cat $log
ecode=1
else
echo "Passed."
fi
echo
}

##

id="ICMP"
args2=(--icmp 100::x)
regex='2001:db8::1 > 100::a: \[icmp6 sum ok\] ICMP6, echo request'
dotest

id="TCP"
args2=(-b -p 1 100::x)
regex='2001:db8::1\.64000 > 100::b\.1: Flags \[S\], cksum [^ ]+ \(correct\).*, length 0'
dotest

id="UDP 53"
args2=(-bu -p 53 100::x)
regex='2001:db8::1\.64000 > 100::c\.53: \[udp sum ok\] [^ ]+ TXT [^ ]+ version\.bind\.'
dotest

##

echo "=== Done ==="
rm -f $pcap $log
exit $ecode
14 changes: 14 additions & 0 deletions util/ci-test2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash -e
args=(
--interface lo
--router-mac 01:01:01:01:01:01
--source-ip ::1
)

./fi6s "${args[@]}" --icmp ::1 | tee out.txt
if ! grep -q "^icmp up 0 ::1 " out.txt; then
echo "FAILED!"
exit 1
fi
echo "Passed."
exit 0

0 comments on commit d966a9b

Please sign in to comment.