Skip to content

Commit 4da325c

Browse files
committed
Merge branch 'selftests-tc-testing-more-updates-to-tdc'
Pedro Tammela says: ==================== selftests: tc-testing: more updates to tdc Address the issues making tdc timeout on downstream CIs like lkp and tuxsuite. ==================== Link: https://lore.kernel.org/r/20231117171208.2066136-1-pctammela@mojatatu.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents b1711d4 + 4968afa commit 4da325c

File tree

2 files changed

+51
-50
lines changed

2 files changed

+51
-50
lines changed

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

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,6 @@
1717
netlink = False
1818
print("!!! Consider installing pyroute2 !!!")
1919

20-
def prepare_suite(obj, test):
21-
original = obj.args.NAMES
22-
23-
if 'skip' in test and test['skip'] == 'yes':
24-
return
25-
26-
if 'nsPlugin' not in test['plugins']:
27-
return
28-
29-
shadow = {}
30-
shadow['IP'] = original['IP']
31-
shadow['TC'] = original['TC']
32-
shadow['NS'] = '{}-{}'.format(original['NS'], test['random'])
33-
shadow['DEV0'] = '{}id{}'.format(original['DEV0'], test['id'])
34-
shadow['DEV1'] = '{}id{}'.format(original['DEV1'], test['id'])
35-
shadow['DUMMY'] = '{}id{}'.format(original['DUMMY'], test['id'])
36-
shadow['DEV2'] = original['DEV2']
37-
obj.args.NAMES = shadow
38-
39-
if netlink == True:
40-
obj._nl_ns_create()
41-
else:
42-
obj._ns_create()
43-
44-
# Make sure the netns is visible in the fs
45-
while True:
46-
obj._proc_check()
47-
try:
48-
ns = obj.args.NAMES['NS']
49-
f = open('/run/netns/{}'.format(ns))
50-
f.close()
51-
break
52-
except:
53-
time.sleep(0.1)
54-
continue
55-
56-
obj.args.NAMES = original
57-
5820
class SubPlugin(TdcPlugin):
5921
def __init__(self):
6022
self.sub_class = 'ns/SubPlugin'
@@ -65,37 +27,63 @@ def pre_suite(self, testcount, testlist):
6527

6628
super().pre_suite(testcount, testlist)
6729

68-
print("Setting up namespaces and devices...")
30+
def prepare_test(self, test):
31+
if 'skip' in test and test['skip'] == 'yes':
32+
return
6933

70-
with Pool(self.args.mp) as p:
71-
it = zip(cycle([self]), testlist)
72-
p.starmap(prepare_suite, it)
34+
if 'nsPlugin' not in test['plugins']:
35+
return
7336

74-
def pre_case(self, caseinfo, test_skip):
37+
if netlink == True:
38+
self._nl_ns_create()
39+
else:
40+
self._ns_create()
41+
42+
# Make sure the netns is visible in the fs
43+
ticks = 20
44+
while True:
45+
if ticks == 0:
46+
raise TimeoutError
47+
self._proc_check()
48+
try:
49+
ns = self.args.NAMES['NS']
50+
f = open('/run/netns/{}'.format(ns))
51+
f.close()
52+
break
53+
except:
54+
time.sleep(0.1)
55+
ticks -= 1
56+
continue
57+
58+
def pre_case(self, test, test_skip):
7559
if self.args.verbose:
7660
print('{}.pre_case'.format(self.sub_class))
7761

7862
if test_skip:
7963
return
8064

65+
self.prepare_test(test)
66+
8167
def post_case(self):
8268
if self.args.verbose:
8369
print('{}.post_case'.format(self.sub_class))
8470

85-
self._ns_destroy()
71+
if netlink == True:
72+
self._nl_ns_destroy()
73+
else:
74+
self._ns_destroy()
8675

8776
def post_suite(self, index):
8877
if self.args.verbose:
8978
print('{}.post_suite'.format(self.sub_class))
9079

9180
# Make sure we don't leak resources
92-
for f in os.listdir('/run/netns/'):
93-
cmd = self._replace_keywords("$IP netns del {}".format(f))
81+
cmd = "$IP -a netns del"
9482

95-
if self.args.verbose > 3:
96-
print('_exec_cmd: command "{}"'.format(cmd))
83+
if self.args.verbose > 3:
84+
print('_exec_cmd: command "{}"'.format(cmd))
9785

98-
subprocess.run(cmd, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
86+
subprocess.run(cmd, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
9987

10088
def adjust_command(self, stage, command):
10189
super().adjust_command(stage, command)
@@ -143,7 +131,10 @@ def _nl_ns_create(self):
143131
with IPRoute() as ip:
144132
ip.link('add', ifname=dev1, kind='veth', peer={'ifname': dev0, 'net_ns_fd':'/proc/1/ns/net'})
145133
ip.link('add', ifname=dummy, kind='dummy')
134+
ticks = 20
146135
while True:
136+
if ticks == 0:
137+
raise TimeoutError
147138
try:
148139
dev1_idx = ip.link_lookup(ifname=dev1)[0]
149140
dummy_idx = ip.link_lookup(ifname=dummy)[0]
@@ -152,17 +143,22 @@ def _nl_ns_create(self):
152143
break
153144
except:
154145
time.sleep(0.1)
146+
ticks -= 1
155147
continue
156148
netns.popns()
157149

158150
with IPRoute() as ip:
151+
ticks = 20
159152
while True:
153+
if ticks == 0:
154+
raise TimeoutError
160155
try:
161156
dev0_idx = ip.link_lookup(ifname=dev0)[0]
162157
ip.link('set', index=dev0_idx, state='up')
163158
break
164159
except:
165160
time.sleep(0.1)
161+
ticks -= 1
166162
continue
167163

168164
def _ns_create_cmds(self):
@@ -192,6 +188,10 @@ def _ns_create(self):
192188
'''
193189
self._exec_cmd_batched('pre', self._ns_create_cmds())
194190

191+
def _nl_ns_destroy(self):
192+
ns = self.args.NAMES['NS']
193+
netns.remove(ns)
194+
195195
def _ns_destroy_cmd(self):
196196
return self._replace_keywords('netns delete {}'.format(self.args.NAMES['NS']))
197197

tools/testing/selftests/tc-testing/tdc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ def test_runner_mp(pm, args, alltests):
616616
batches.insert(0, serial)
617617

618618
print("Executing {} tests in parallel and {} in serial".format(len(parallel), len(serial)))
619-
print("Using {} batches".format(len(batches)))
619+
print("Using {} batches and {} workers".format(len(batches), args.mp))
620620

621621
# We can't pickle these objects so workaround them
622622
global mp_pm
@@ -1017,6 +1017,7 @@ def main():
10171017
parser = pm.call_add_args(parser)
10181018
(args, remaining) = parser.parse_known_args()
10191019
args.NAMES = NAMES
1020+
args.mp = min(args.mp, 4)
10201021
pm.set_args(args)
10211022
check_default_settings(args, remaining, pm)
10221023
if args.verbose > 2:

0 commit comments

Comments
 (0)