Commit e47ef9eb authored by David S. Miller's avatar David S. Miller

Merge branch 'tc-testing-tdc-updates'

Pedro Tammela says:

====================
selftests: tc-testing: updates to tdc

- Patch 1 removes an obscure feature from tdc
- Patch 2 reworks the namespace and devices setup giving a nice speed
boost
- Patch 3 preloads all tc modules when running kselftests
- Patch 4 turns on parallel testing in kselftests
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 0fbe92b9 04fd47bf
...@@ -9,6 +9,14 @@ from TdcPlugin import TdcPlugin ...@@ -9,6 +9,14 @@ from TdcPlugin import TdcPlugin
from tdc_config import * from tdc_config import *
try:
from pyroute2 import netns
from pyroute2 import IPRoute
netlink = True
except ImportError:
netlink = False
print("!!! Consider installing pyroute2 !!!")
def prepare_suite(obj, test): def prepare_suite(obj, test):
original = obj.args.NAMES original = obj.args.NAMES
...@@ -28,10 +36,10 @@ def prepare_suite(obj, test): ...@@ -28,10 +36,10 @@ def prepare_suite(obj, test):
shadow['DEV2'] = original['DEV2'] shadow['DEV2'] = original['DEV2']
obj.args.NAMES = shadow obj.args.NAMES = shadow
if obj.args.namespace: if netlink == True:
obj._ns_create() obj._nl_ns_create()
else: else:
obj._ports_create() obj._ns_create()
# Make sure the netns is visible in the fs # Make sure the netns is visible in the fs
while True: while True:
...@@ -70,15 +78,11 @@ class SubPlugin(TdcPlugin): ...@@ -70,15 +78,11 @@ class SubPlugin(TdcPlugin):
if test_skip: if test_skip:
return return
def post_case(self): def post_case(self):
if self.args.verbose: if self.args.verbose:
print('{}.post_case'.format(self.sub_class)) print('{}.post_case'.format(self.sub_class))
if self.args.namespace:
self._ns_destroy() self._ns_destroy()
else:
self._ports_destroy()
def post_suite(self, index): def post_suite(self, index):
if self.args.verbose: if self.args.verbose:
...@@ -93,24 +97,11 @@ class SubPlugin(TdcPlugin): ...@@ -93,24 +97,11 @@ class SubPlugin(TdcPlugin):
subprocess.run(cmd, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) subprocess.run(cmd, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
def add_args(self, parser):
super().add_args(parser)
self.argparser_group = self.argparser.add_argument_group(
'netns',
'options for nsPlugin(run commands in net namespace)')
self.argparser_group.add_argument(
'-N', '--no-namespace', action='store_false', default=True,
dest='namespace', help='Don\'t run commands in namespace')
return self.argparser
def adjust_command(self, stage, command): def adjust_command(self, stage, command):
super().adjust_command(stage, command) super().adjust_command(stage, command)
cmdform = 'list' cmdform = 'list'
cmdlist = list() cmdlist = list()
if not self.args.namespace:
return command
if self.args.verbose: if self.args.verbose:
print('{}.adjust_command'.format(self.sub_class)) print('{}.adjust_command'.format(self.sub_class))
...@@ -138,37 +129,55 @@ class SubPlugin(TdcPlugin): ...@@ -138,37 +129,55 @@ class SubPlugin(TdcPlugin):
print('adjust_command: return command [{}]'.format(command)) print('adjust_command: return command [{}]'.format(command))
return command return command
def _ports_create_cmds(self): def _nl_ns_create(self):
cmds = [] ns = self.args.NAMES["NS"];
dev0 = self.args.NAMES["DEV0"];
cmds.append(self._replace_keywords('link add $DEV0 type veth peer name $DEV1')) dev1 = self.args.NAMES["DEV1"];
cmds.append(self._replace_keywords('link set $DEV0 up')) dummy = self.args.NAMES["DUMMY"];
cmds.append(self._replace_keywords('link add $DUMMY type dummy'))
if not self.args.namespace:
cmds.append(self._replace_keywords('link set $DEV1 up'))
return cmds if self.args.verbose:
print('{}._nl_ns_create'.format(self.sub_class))
def _ports_create(self):
self._exec_cmd_batched('pre', self._ports_create_cmds())
def _ports_destroy_cmd(self): netns.create(ns)
return self._replace_keywords('link del $DEV0') netns.pushns(newns=ns)
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')
while True:
try:
dev1_idx = ip.link_lookup(ifname=dev1)[0]
dummy_idx = ip.link_lookup(ifname=dummy)[0]
ip.link('set', index=dev1_idx, state='up')
ip.link('set', index=dummy_idx, state='up')
break
except:
time.sleep(0.1)
continue
netns.popns()
def _ports_destroy(self): with IPRoute() as ip:
self._exec_cmd('post', self._ports_destroy_cmd()) while True:
try:
dev0_idx = ip.link_lookup(ifname=dev0)[0]
ip.link('set', index=dev0_idx, state='up')
break
except:
time.sleep(0.1)
continue
def _ns_create_cmds(self): def _ns_create_cmds(self):
cmds = [] cmds = []
if self.args.namespace:
ns = self.args.NAMES['NS'] ns = self.args.NAMES['NS']
cmds.append(self._replace_keywords('netns add {}'.format(ns))) cmds.append(self._replace_keywords('netns add {}'.format(ns)))
cmds.append(self._replace_keywords('link add $DEV1 type veth peer name $DEV0'))
cmds.append(self._replace_keywords('link set $DEV1 netns {}'.format(ns))) cmds.append(self._replace_keywords('link set $DEV1 netns {}'.format(ns)))
cmds.append(self._replace_keywords('link add $DUMMY type dummy'.format(ns)))
cmds.append(self._replace_keywords('link set $DUMMY netns {}'.format(ns))) cmds.append(self._replace_keywords('link set $DUMMY netns {}'.format(ns)))
cmds.append(self._replace_keywords('netns exec {} $IP link set $DEV1 up'.format(ns))) cmds.append(self._replace_keywords('netns exec {} $IP link set $DEV1 up'.format(ns)))
cmds.append(self._replace_keywords('netns exec {} $IP link set $DUMMY up'.format(ns))) cmds.append(self._replace_keywords('netns exec {} $IP link set $DUMMY up'.format(ns)))
cmds.append(self._replace_keywords('link set $DEV0 up'.format(ns)))
if self.args.device: if self.args.device:
cmds.append(self._replace_keywords('link set $DEV2 netns {}'.format(ns))) cmds.append(self._replace_keywords('link set $DEV2 netns {}'.format(ns)))
...@@ -181,7 +190,6 @@ class SubPlugin(TdcPlugin): ...@@ -181,7 +190,6 @@ class SubPlugin(TdcPlugin):
Create the network namespace in which the tests will be run and set up Create the network namespace in which the tests will be run and set up
the required network devices for it. the required network devices for it.
''' '''
self._ports_create()
self._exec_cmd_batched('pre', self._ns_create_cmds()) self._exec_cmd_batched('pre', self._ns_create_cmds())
def _ns_destroy_cmd(self): def _ns_destroy_cmd(self):
...@@ -192,9 +200,7 @@ class SubPlugin(TdcPlugin): ...@@ -192,9 +200,7 @@ class SubPlugin(TdcPlugin):
Destroy the network namespace for testing (and any associated network Destroy the network namespace for testing (and any associated network
devices as well) devices as well)
''' '''
if self.args.namespace:
self._exec_cmd('post', self._ns_destroy_cmd()) self._exec_cmd('post', self._ns_destroy_cmd())
self._ports_destroy()
@cached_property @cached_property
def _proc(self): def _proc(self):
......
#!/bin/sh #!/bin/sh
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
modprobe netdevsim # If a module is required and was not compiled
modprobe sch_teql # the test that requires it will fail anyways
./tdc.py -c actions --nobuildebpf try_modprobe() {
./tdc.py -c qdisc modprobe -q -R "$1"
if [ $? -ne 0 ]; then
echo "Module $1 not found... skipping."
else
modprobe "$1"
fi
}
try_modprobe netdevsim
try_modprobe act_bpf
try_modprobe act_connmark
try_modprobe act_csum
try_modprobe act_ct
try_modprobe act_ctinfo
try_modprobe act_gact
try_modprobe act_gate
try_modprobe act_ipt
try_modprobe act_mirred
try_modprobe act_mpls
try_modprobe act_nat
try_modprobe act_pedit
try_modprobe act_police
try_modprobe act_sample
try_modprobe act_simple
try_modprobe act_skbedit
try_modprobe act_skbmod
try_modprobe act_tunnel_key
try_modprobe act_vlan
try_modprobe cls_basic
try_modprobe cls_bpf
try_modprobe cls_cgroup
try_modprobe cls_flow
try_modprobe cls_flower
try_modprobe cls_fw
try_modprobe cls_matchall
try_modprobe cls_route
try_modprobe cls_u32
try_modprobe em_canid
try_modprobe em_cmp
try_modprobe em_ipset
try_modprobe em_ipt
try_modprobe em_meta
try_modprobe em_nbyte
try_modprobe em_text
try_modprobe em_u32
try_modprobe sch_cake
try_modprobe sch_cbs
try_modprobe sch_choke
try_modprobe sch_codel
try_modprobe sch_drr
try_modprobe sch_etf
try_modprobe sch_ets
try_modprobe sch_fq
try_modprobe sch_fq_codel
try_modprobe sch_fq_pie
try_modprobe sch_gred
try_modprobe sch_hfsc
try_modprobe sch_hhf
try_modprobe sch_htb
try_modprobe sch_teql
./tdc.py -J`nproc` -c actions --nobuildebpf
./tdc.py -J`nproc` -c qdisc
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment