Skip to content

Commit 4b480cf

Browse files
tammelakuba-moo
authored andcommitted
selftests: tc-testing: timeout on unbounded loops
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 <pctammela@mojatatu.com> Reviewed-by: Simon Horman <horms@kernel.org> Acked-by: Jamal Hadi Salim <jhs@mojatatu.com> Link: https://lore.kernel.org/r/20231117171208.2066136-6-pctammela@mojatatu.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 3f2d94a commit 4b480cf

File tree

1 file changed

+12
-0
lines changed
  • tools/testing/selftests/tc-testing/plugin-lib

1 file changed

+12
-0
lines changed

tools/testing/selftests/tc-testing/plugin-lib/nsPlugin.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ def prepare_test(self, test):
4040
self._ns_create()
4141

4242
# Make sure the netns is visible in the fs
43+
ticks = 20
4344
while True:
45+
if ticks == 0:
46+
raise TimeoutError
4447
self._proc_check()
4548
try:
4649
ns = self.args.NAMES['NS']
@@ -49,6 +52,7 @@ def prepare_test(self, test):
4952
break
5053
except:
5154
time.sleep(0.1)
55+
ticks -= 1
5256
continue
5357

5458
def pre_case(self, test, test_skip):
@@ -127,7 +131,10 @@ def _nl_ns_create(self):
127131
with IPRoute() as ip:
128132
ip.link('add', ifname=dev1, kind='veth', peer={'ifname': dev0, 'net_ns_fd':'/proc/1/ns/net'})
129133
ip.link('add', ifname=dummy, kind='dummy')
134+
ticks = 20
130135
while True:
136+
if ticks == 0:
137+
raise TimeoutError
131138
try:
132139
dev1_idx = ip.link_lookup(ifname=dev1)[0]
133140
dummy_idx = ip.link_lookup(ifname=dummy)[0]
@@ -136,17 +143,22 @@ def _nl_ns_create(self):
136143
break
137144
except:
138145
time.sleep(0.1)
146+
ticks -= 1
139147
continue
140148
netns.popns()
141149

142150
with IPRoute() as ip:
151+
ticks = 20
143152
while True:
153+
if ticks == 0:
154+
raise TimeoutError
144155
try:
145156
dev0_idx = ip.link_lookup(ifname=dev0)[0]
146157
ip.link('set', index=dev0_idx, state='up')
147158
break
148159
except:
149160
time.sleep(0.1)
161+
ticks -= 1
150162
continue
151163

152164
def _ns_create_cmds(self):

0 commit comments

Comments
 (0)