Skip to content

Commit

Permalink
test: ipv4_autoconf: Fix racecondition on slow test-PCs
Browse files Browse the repository at this point in the history
Refactor test, remove fragile solution with tcpdump started AFTER
the linklocal was activated, this opened for a race condition since
it was listening for a message sent once.

Now wait for the linklocal address instead.
  • Loading branch information
mattiaswal authored and troglobit committed Feb 28, 2024
1 parent ac97ce0 commit 2bf6ec7
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions test/case/infix_interfaces/ipv4_autoconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@
#

import infamy
import time
import infamy.iface

from infamy.util import until

def has_linklocal(target, iface):
"""Check if interface as a linklocal address"""
addrs = infamy.iface.get_ipv4_address(target, iface)
if not addrs:
return False
for addr in addrs:
if addr['origin'] == "random":
return True

with infamy.Test() as test:
with test.step("Initialize"):
Expand All @@ -29,23 +42,7 @@
}
})

with test.step("Wait for mDNS message from a 169.254 address ..."):
_, hport = env.ltop.xlate("host", "data")

with infamy.IsolatedMacVlan(hport) as ns:
vrfy = ns.runsh("""
set -ex
ip link set iface up
ip addr add 10.0.0.1/24 dev iface
fakeroot tcpdump -q -i iface -c 1 -n host 224.0.0.251 and port 5353 --print 2>/dev/null \
| awk 'match($0,/169\\.254\\.[0-9]+\\.[0-9]+/) {print substr($0,RSTART,RLENGTH)}' \
| grep . || exit 1
""")

if vrfy.returncode:
print(vrfy.stdout)
test.fail()
with test.step("Wait for linklocal address on interface"):
until(lambda: has_linklocal(target, tport), attempts=10)

test.succeed()

0 comments on commit 2bf6ec7

Please sign in to comment.