Changeset View
Changeset View
Standalone View
Standalone View
sbin/ping/tests/ping_test.sh
Show First 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | |||||
inject_opts_head() | inject_opts_head() | ||||
{ | { | ||||
atf_set "descr" "Inject an ECHO REPLY with IP options" | atf_set "descr" "Inject an ECHO REPLY with IP options" | ||||
atf_set "require.user" "root" | atf_set "require.user" "root" | ||||
atf_set "require.progs" "python3" "scapy" | atf_set "require.progs" "python3" "scapy" | ||||
} | } | ||||
inject_opts_body() | inject_opts_body() | ||||
{ | { | ||||
atf_check -s exit:0 -o match:"wrong total length" -o match:"NOP" python3 $(atf_get_srcdir)/injection.py opts | atf_check -s exit:0 -o match:"wrong total length" -o match:"NOP" \ | ||||
$(atf_get_srcdir)/pinger.py \ | |||||
asomers: Since you're using vnet, you really could go back to hardcoding tun0, if that would make things… | |||||
--iface tun0 \ | |||||
--src 192.0.2.1 \ | |||||
--dst 192.0.2.2 \ | |||||
--icmp_type 0 \ | |||||
--icmp_code 0 \ | |||||
--opts NOP-40 | |||||
} | } | ||||
inject_opts_cleanup() | inject_opts_cleanup() | ||||
{ | { | ||||
ifconfig `cat tun.txt` destroy | pinger_cleanup | ||||
} | } | ||||
atf_test_case "inject_pip" "cleanup" | atf_test_case "inject_pip" "cleanup" | ||||
inject_pip_head() | inject_pip_head() | ||||
{ | { | ||||
atf_set "descr" "Inject an ICMP error with a quoted packet with IP options" | atf_set "descr" "Inject an ICMP error with a quoted packet with IP options" | ||||
atf_set "require.user" "root" | atf_set "require.user" "root" | ||||
atf_set "require.progs" "python3" "scapy" | atf_set "require.progs" "python3" "scapy" | ||||
} | } | ||||
inject_pip_body() | inject_pip_body() | ||||
{ | { | ||||
atf_check -s exit:2 -o match:"Destination Host Unreachable" -o not-match:"01010101" python3 $(atf_get_srcdir)/injection.py pip | # XXX This test is wrong. It should match (not not-match) 40 NOPs. | ||||
atf_check -s exit:2 -o match:"Destination Host Unreachable" -o not-match:"01010101" \ | |||||
$(atf_get_srcdir)/pinger.py \ | |||||
--iface tun0 \ | |||||
--src 192.0.2.1 \ | |||||
--dst 192.0.2.2 \ | |||||
--icmp_type 3 \ | |||||
--icmp_code 1 \ | |||||
--opts NOP-40 | |||||
} | } | ||||
inject_pip_cleanup() | inject_pip_cleanup() | ||||
{ | { | ||||
ifconfig `cat tun.txt` destroy | pinger_cleanup | ||||
} | } | ||||
# This is redundant with the ping_ tests, but it serves to ensure that scapy.py | # This is redundant with the ping_ tests, but it serves to ensure that scapy.py | ||||
# is working correctly. | # is working correctly. | ||||
atf_test_case "inject_reply" "cleanup" | atf_test_case "inject_reply" "cleanup" | ||||
inject_reply_head() | inject_reply_head() | ||||
{ | { | ||||
atf_set "descr" "Basic ping test with packet injection" | atf_set "descr" "Basic ping test with packet injection" | ||||
atf_set "require.user" "root" | atf_set "require.user" "root" | ||||
atf_set "require.progs" "python3" "scapy" | atf_set "require.progs" "python3" "scapy" | ||||
} | } | ||||
inject_reply_body() | inject_reply_body() | ||||
{ | { | ||||
atf_check -s exit:0 -o match:"1 packets transmitted, 1 packets received" python3 $(atf_get_srcdir)/injection.py reply | atf_check -s exit:0 -o match:"1 packets transmitted, 1 packets received" \ | ||||
$(atf_get_srcdir)/pinger.py \ | |||||
--iface tun0 \ | |||||
--src 192.0.2.1 \ | |||||
--dst 192.0.2.2 \ | |||||
--icmp_type 0 \ | |||||
--icmp_code 0 | |||||
} | } | ||||
inject_reply_cleanup() | inject_reply_cleanup() | ||||
{ | { | ||||
ifconfig `cat tun.txt` destroy | pinger_cleanup | ||||
} | } | ||||
atf_init_test_cases() | atf_init_test_cases() | ||||
{ | { | ||||
atf_add_test_case ping_c1_s56_t1 | atf_add_test_case ping_c1_s56_t1 | ||||
atf_add_test_case ping_c1_s56_t1_S127 | atf_add_test_case ping_c1_s56_t1_S127 | ||||
atf_add_test_case ping_6_c1_s8_t1 | atf_add_test_case ping_6_c1_s8_t1 | ||||
atf_add_test_case ping_c1_s8_t1_S1 | atf_add_test_case ping_c1_s8_t1_S1 | ||||
Show All 12 Lines | check_ping_statistics() | ||||
sed -e 's/0.[0-9]\{3\}//g' \ | sed -e 's/0.[0-9]\{3\}//g' \ | ||||
-e 's/[1-9][0-9]*.[0-9]\{3\}//g' \ | -e 's/[1-9][0-9]*.[0-9]\{3\}//g' \ | ||||
-e 's/localhost ([0-9]\{1,3\}\(\.[0-9]\{1,3\}\)\{1,3\})/localhost/' \ | -e 's/localhost ([0-9]\{1,3\}\(\.[0-9]\{1,3\}\)\{1,3\})/localhost/' \ | ||||
-e 's/from [0-9]\{1,3\}\(\.[0-9]\{1,3\}\)\{1,3\}/from/' \ | -e 's/from [0-9]\{1,3\}\(\.[0-9]\{1,3\}\)\{1,3\}/from/' \ | ||||
-e 's/ttl=[0-9][0-9]*/ttl=/' \ | -e 's/ttl=[0-9][0-9]*/ttl=/' \ | ||||
-e 's/hlim=[0-9][0-9]*/hlim=/' \ | -e 's/hlim=[0-9][0-9]*/hlim=/' \ | ||||
"$1" >"$1".filtered | "$1" >"$1".filtered | ||||
atf_check -s exit:0 diff -u "$1".filtered "$2" | atf_check -s exit:0 diff -u "$1".filtered "$2" | ||||
} | |||||
pinger_cleanup() | |||||
{ | |||||
if [ -f created_interfaces.lst ]; then | |||||
for ifname in `cat created_interfaces.lst` | |||||
do | |||||
ifconfig ${ifname} destroy | |||||
done | |||||
fi | |||||
Done Inline ActionsExplicitly deleting files is unnecessary, because Kyua uses a per-testcase tempdir. asomers: Explicitly deleting files is unnecessary, because Kyua uses a per-testcase tempdir. | |||||
Done Inline ActionsOK, I'll remove it, if a test fails, it complains about it having "Files left in work directory after failure". I thought it was a common courtesy to remove them anyways. jlduran_gmail.com: OK, I'll remove it, if a test fails, it complains about it having "Files left in work directory… | |||||
Done Inline ActionsI can't edit comments. For self reference: 96b90524d155bdd2d3f78a0a50cf250164bfbf6c jlduran_gmail.com: I can't edit comments. For self reference: 96b90524d155bdd2d3f78a0a50cf250164bfbf6c | |||||
} | } |
Since you're using vnet, you really could go back to hardcoding tun0, if that would make things easier. But it's probably best not to, in case future developers want to disable the vnet part for some reason. It's more robust this way.