Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+51 -50
+49 -49
tools/testing/selftests/tc-testing/plugin-lib/nsPlugin.py
··· 17 17 netlink = False 18 18 print("!!! Consider installing pyroute2 !!!") 19 19 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 - 58 20 class SubPlugin(TdcPlugin): 59 21 def __init__(self): 60 22 self.sub_class = 'ns/SubPlugin' ··· 27 65 28 66 super().pre_suite(testcount, testlist) 29 67 30 - print("Setting up namespaces and devices...") 68 + def prepare_test(self, test): 69 + if 'skip' in test and test['skip'] == 'yes': 70 + return 31 71 32 - with Pool(self.args.mp) as p: 33 - it = zip(cycle([self]), testlist) 34 - p.starmap(prepare_suite, it) 72 + if 'nsPlugin' not in test['plugins']: 73 + return 35 74 36 - def pre_case(self, caseinfo, test_skip): 75 + if netlink == True: 76 + self._nl_ns_create() 77 + else: 78 + self._ns_create() 79 + 80 + # Make sure the netns is visible in the fs 81 + ticks = 20 82 + while True: 83 + if ticks == 0: 84 + raise TimeoutError 85 + self._proc_check() 86 + try: 87 + ns = self.args.NAMES['NS'] 88 + f = open('/run/netns/{}'.format(ns)) 89 + f.close() 90 + break 91 + except: 92 + time.sleep(0.1) 93 + ticks -= 1 94 + continue 95 + 96 + def pre_case(self, test, test_skip): 37 97 if self.args.verbose: 38 98 print('{}.pre_case'.format(self.sub_class)) 39 99 40 100 if test_skip: 41 101 return 42 102 103 + self.prepare_test(test) 104 + 43 105 def post_case(self): 44 106 if self.args.verbose: 45 107 print('{}.post_case'.format(self.sub_class)) 46 108 47 - self._ns_destroy() 109 + if netlink == True: 110 + self._nl_ns_destroy() 111 + else: 112 + self._ns_destroy() 48 113 49 114 def post_suite(self, index): 50 115 if self.args.verbose: 51 116 print('{}.post_suite'.format(self.sub_class)) 52 117 53 118 # Make sure we don't leak resources 54 - for f in os.listdir('/run/netns/'): 55 - cmd = self._replace_keywords("$IP netns del {}".format(f)) 119 + cmd = "$IP -a netns del" 56 120 57 - if self.args.verbose > 3: 58 - print('_exec_cmd: command "{}"'.format(cmd)) 121 + if self.args.verbose > 3: 122 + print('_exec_cmd: command "{}"'.format(cmd)) 59 123 60 - subprocess.run(cmd, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) 124 + subprocess.run(cmd, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) 61 125 62 126 def adjust_command(self, stage, command): 63 127 super().adjust_command(stage, command) ··· 131 143 with IPRoute() as ip: 132 144 ip.link('add', ifname=dev1, kind='veth', peer={'ifname': dev0, 'net_ns_fd':'/proc/1/ns/net'}) 133 145 ip.link('add', ifname=dummy, kind='dummy') 146 + ticks = 20 134 147 while True: 148 + if ticks == 0: 149 + raise TimeoutError 135 150 try: 136 151 dev1_idx = ip.link_lookup(ifname=dev1)[0] 137 152 dummy_idx = ip.link_lookup(ifname=dummy)[0] ··· 143 152 break 144 153 except: 145 154 time.sleep(0.1) 155 + ticks -= 1 146 156 continue 147 157 netns.popns() 148 158 149 159 with IPRoute() as ip: 160 + ticks = 20 150 161 while True: 162 + if ticks == 0: 163 + raise TimeoutError 151 164 try: 152 165 dev0_idx = ip.link_lookup(ifname=dev0)[0] 153 166 ip.link('set', index=dev0_idx, state='up') 154 167 break 155 168 except: 156 169 time.sleep(0.1) 170 + ticks -= 1 157 171 continue 158 172 159 173 def _ns_create_cmds(self): ··· 187 191 the required network devices for it. 188 192 ''' 189 193 self._exec_cmd_batched('pre', self._ns_create_cmds()) 194 + 195 + def _nl_ns_destroy(self): 196 + ns = self.args.NAMES['NS'] 197 + netns.remove(ns) 190 198 191 199 def _ns_destroy_cmd(self): 192 200 return self._replace_keywords('netns delete {}'.format(self.args.NAMES['NS']))
+2 -1
tools/testing/selftests/tc-testing/tdc.py
··· 616 616 batches.insert(0, serial) 617 617 618 618 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)) 620 620 621 621 # We can't pickle these objects so workaround them 622 622 global mp_pm ··· 1017 1017 parser = pm.call_add_args(parser) 1018 1018 (args, remaining) = parser.parse_known_args() 1019 1019 args.NAMES = NAMES 1020 + args.mp = min(args.mp, 4) 1020 1021 pm.set_args(args) 1021 1022 check_default_settings(args, remaining, pm) 1022 1023 if args.verbose > 2: