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
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):
original = obj.args.NAMES
......@@ -28,10 +36,10 @@ def prepare_suite(obj, test):
shadow['DEV2'] = original['DEV2']
obj.args.NAMES = shadow
if obj.args.namespace:
obj._ns_create()
if netlink == True:
obj._nl_ns_create()
else:
obj._ports_create()
obj._ns_create()
# Make sure the netns is visible in the fs
while True:
......@@ -70,15 +78,11 @@ class SubPlugin(TdcPlugin):
if test_skip:
return
def post_case(self):
if self.args.verbose:
print('{}.post_case'.format(self.sub_class))
if self.args.namespace:
self._ns_destroy()
else:
self._ports_destroy()
def post_suite(self, index):
if self.args.verbose:
......@@ -93,24 +97,11 @@ class SubPlugin(TdcPlugin):
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):
super().adjust_command(stage, command)
cmdform = 'list'
cmdlist = list()
if not self.args.namespace:
return command
if self.args.verbose:
print('{}.adjust_command'.format(self.sub_class))
......@@ -138,37 +129,55 @@ class SubPlugin(TdcPlugin):
print('adjust_command: return command [{}]'.format(command))
return command
def _ports_create_cmds(self):
cmds = []
cmds.append(self._replace_keywords('link add $DEV0 type veth peer name $DEV1'))
cmds.append(self._replace_keywords('link set $DEV0 up'))
cmds.append(self._replace_keywords('link add $DUMMY type dummy'))
if not self.args.namespace:
cmds.append(self._replace_keywords('link set $DEV1 up'))
def _nl_ns_create(self):
ns = self.args.NAMES["NS"];
dev0 = self.args.NAMES["DEV0"];
dev1 = self.args.NAMES["DEV1"];
dummy = self.args.NAMES["DUMMY"];
return cmds
def _ports_create(self):
self._exec_cmd_batched('pre', self._ports_create_cmds())
if self.args.verbose:
print('{}._nl_ns_create'.format(self.sub_class))
def _ports_destroy_cmd(self):
return self._replace_keywords('link del $DEV0')
netns.create(ns)
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):
self._exec_cmd('post', self._ports_destroy_cmd())
with IPRoute() as ip:
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):
cmds = []
if self.args.namespace:
ns = self.args.NAMES['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 add $DUMMY type dummy'.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 $DUMMY up'.format(ns)))
cmds.append(self._replace_keywords('link set $DEV0 up'.format(ns)))
if self.args.device:
cmds.append(self._replace_keywords('link set $DEV2 netns {}'.format(ns)))
......@@ -181,7 +190,6 @@ class SubPlugin(TdcPlugin):
Create the network namespace in which the tests will be run and set up
the required network devices for it.
'''
self._ports_create()
self._exec_cmd_batched('pre', self._ns_create_cmds())
def _ns_destroy_cmd(self):
......@@ -192,9 +200,7 @@ class SubPlugin(TdcPlugin):
Destroy the network namespace for testing (and any associated network
devices as well)
'''
if self.args.namespace:
self._exec_cmd('post', self._ns_destroy_cmd())
self._ports_destroy()
@cached_property
def _proc(self):
......
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
modprobe netdevsim
modprobe sch_teql
./tdc.py -c actions --nobuildebpf
./tdc.py -c qdisc
# If a module is required and was not compiled
# the test that requires it will fail anyways
try_modprobe() {
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