Skip to content

Commit

Permalink
selftests: tc-testing: timeout on unbounded loops
Browse files Browse the repository at this point in the history
In the spirit of failing early, timeout on unbounded loops that take
longer than 20 ticks to complete. Such loops are to ensure that objects
created are already visible so tests can proceed without any issues.

If a test setup takes more than 20 ticks to see an object, there's
definetely something wrong.

Signed-off-by: Pedro Tammela <[email protected]>
Reviewed-by: Simon Horman <[email protected]>
Acked-by: Jamal Hadi Salim <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
tammela authored and kuba-moo committed Nov 21, 2023
1 parent 3f2d94a commit 4b480cf
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tools/testing/selftests/tc-testing/plugin-lib/nsPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ def prepare_test(self, test):
self._ns_create()

# Make sure the netns is visible in the fs
ticks = 20
while True:
if ticks == 0:
raise TimeoutError
self._proc_check()
try:
ns = self.args.NAMES['NS']
Expand All @@ -49,6 +52,7 @@ def prepare_test(self, test):
break
except:
time.sleep(0.1)
ticks -= 1
continue

def pre_case(self, test, test_skip):
Expand Down Expand Up @@ -127,7 +131,10 @@ def _nl_ns_create(self):
with IPRoute() as ip:
ip.link('add', ifname=dev1, kind='veth', peer={'ifname': dev0, 'net_ns_fd':'/proc/1/ns/net'})
ip.link('add', ifname=dummy, kind='dummy')
ticks = 20
while True:
if ticks == 0:
raise TimeoutError
try:
dev1_idx = ip.link_lookup(ifname=dev1)[0]
dummy_idx = ip.link_lookup(ifname=dummy)[0]
Expand All @@ -136,17 +143,22 @@ def _nl_ns_create(self):
break
except:
time.sleep(0.1)
ticks -= 1
continue
netns.popns()

with IPRoute() as ip:
ticks = 20
while True:
if ticks == 0:
raise TimeoutError
try:
dev0_idx = ip.link_lookup(ifname=dev0)[0]
ip.link('set', index=dev0_idx, state='up')
break
except:
time.sleep(0.1)
ticks -= 1
continue

def _ns_create_cmds(self):
Expand Down

0 comments on commit 4b480cf

Please sign in to comment.