Skip to content

Commit

Permalink
Merge branch 'selftests-tc-testing-updates-and-cleanups-for-tdc'
Browse files Browse the repository at this point in the history
Pedro Tammela says:

====================
selftests: tc-testing: updates and cleanups for tdc

Address the recommendations from the previous series and cleanup some
leftovers.
====================

Link: https://lore.kernel.org/r/20231124154248.315470-1-pctammela@mojatatu.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Nov 28, 2023
2 parents cae0de4 + ed346fc commit 2df6bde
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 130 deletions.
29 changes: 2 additions & 27 deletions tools/testing/selftests/tc-testing/Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
include ../../../scripts/Makefile.include

top_srcdir = $(abspath ../../../..)
APIDIR := $(top_scrdir)/include/uapi
TEST_GEN_FILES = action.o
TEST_PROGS += ./tdc.sh
TEST_FILES := action-ebpf tdc*.py Tdc*.py plugins plugin-lib tc-tests scripts

include ../lib.mk

PROBE := $(shell $(LLC) -march=bpf -mcpu=probe -filetype=null /dev/null 2>&1)

ifeq ($(PROBE),)
CPU ?= probe
else
CPU ?= generic
endif

CLANG_SYS_INCLUDES := $(shell $(CLANG) -v -E - </dev/null 2>&1 \
| sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }')

CLANG_FLAGS = -I. -I$(APIDIR) \
$(CLANG_SYS_INCLUDES) \
-Wno-compare-distinct-pointer-types

$(OUTPUT)/%.o: %.c
$(CLANG) $(CLANG_FLAGS) \
-O2 --target=bpf -emit-llvm -c $< -o - | \
$(LLC) -march=bpf -mcpu=$(CPU) $(LLC_FLAGS) -filetype=obj -o $@

TEST_PROGS += ./tdc.sh
TEST_FILES := tdc*.py Tdc*.py plugins plugin-lib tc-tests scripts
2 changes: 0 additions & 2 deletions tools/testing/selftests/tc-testing/README
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ directory:
and the other is a test whether the command leaked memory or not.
(This one is a preliminary version, it may not work quite right yet,
but the overall template is there and it should only need tweaks.)
- buildebpfPlugin.py:
builds all programs in $EBPFDIR.


ACKNOWLEDGEMENTS
Expand Down
Binary file added tools/testing/selftests/tc-testing/action-ebpf
Binary file not shown.
67 changes: 0 additions & 67 deletions tools/testing/selftests/tc-testing/plugin-lib/buildebpfPlugin.py

This file was deleted.

20 changes: 9 additions & 11 deletions tools/testing/selftests/tc-testing/plugin-lib/nsPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ def __init__(self):
super().__init__()

def pre_suite(self, testcount, testlist):
from itertools import cycle

super().pre_suite(testcount, testlist)

def prepare_test(self, test):
Expand All @@ -37,7 +35,7 @@ def prepare_test(self, test):
if netlink == True:
self._nl_ns_create()
else:
self._ns_create()
self._ipr2_ns_create()

# Make sure the netns is visible in the fs
ticks = 20
Expand Down Expand Up @@ -71,14 +69,14 @@ def post_case(self):
if netlink == True:
self._nl_ns_destroy()
else:
self._ns_destroy()
self._ipr2_ns_destroy()

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

# Make sure we don't leak resources
cmd = "$IP -a netns del"
cmd = self._replace_keywords("$IP -a netns del")

if self.args.verbose > 3:
print('_exec_cmd: command "{}"'.format(cmd))
Expand Down Expand Up @@ -161,7 +159,7 @@ def _nl_ns_create(self):
ticks -= 1
continue

def _ns_create_cmds(self):
def _ipr2_ns_create_cmds(self):
cmds = []

ns = self.args.NAMES['NS']
Expand All @@ -181,26 +179,26 @@ def _ns_create_cmds(self):

return cmds

def _ns_create(self):
def _ipr2_ns_create(self):
'''
Create the network namespace in which the tests will be run and set up
the required network devices for it.
'''
self._exec_cmd_batched('pre', self._ns_create_cmds())
self._exec_cmd_batched('pre', self._ipr2_ns_create_cmds())

def _nl_ns_destroy(self):
ns = self.args.NAMES['NS']
netns.remove(ns)

def _ns_destroy_cmd(self):
def _ipr2_ns_destroy_cmd(self):
return self._replace_keywords('netns delete {}'.format(self.args.NAMES['NS']))

def _ns_destroy(self):
def _ipr2_ns_destroy(self):
'''
Destroy the network namespace for testing (and any associated network
devices as well)
'''
self._exec_cmd('post', self._ns_destroy_cmd())
self._exec_cmd('post', self._ipr2_ns_destroy_cmd())

@cached_property
def _proc(self):
Expand Down
14 changes: 4 additions & 10 deletions tools/testing/selftests/tc-testing/tc-tests/actions/bpf.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@
"actions",
"bpf"
],
"plugins": {
"requires": "buildebpfPlugin"
},
"setup": [
[
"$TC action flush action bpf",
Expand All @@ -65,10 +62,10 @@
255
]
],
"cmdUnderTest": "$TC action add action bpf object-file $EBPFDIR/action.o section action-ok index 667",
"cmdUnderTest": "$TC action add action bpf object-file $EBPFDIR/action-ebpf section action-ok index 667",
"expExitCode": "0",
"verifyCmd": "$TC action get action bpf index 667",
"matchPattern": "action order [0-9]*: bpf action.o:\\[action-ok\\] id [0-9].* tag [0-9a-f]{16}( jited)? default-action pipe.*index 667 ref",
"matchPattern": "action order [0-9]*: bpf action-ebpf:\\[action-ok\\] id [0-9].* tag [0-9a-f]{16}( jited)? default-action pipe.*index 667 ref",
"matchCount": "1",
"teardown": [
"$TC action flush action bpf"
Expand All @@ -81,9 +78,6 @@
"actions",
"bpf"
],
"plugins": {
"requires": "buildebpfPlugin"
},
"setup": [
[
"$TC action flush action bpf",
Expand All @@ -92,10 +86,10 @@
255
]
],
"cmdUnderTest": "$TC action add action bpf object-file $EBPFDIR/action.o section action-ko index 667",
"cmdUnderTest": "$TC action add action bpf object-file $EBPFDIR/action-ebpf section action-ko index 667",
"expExitCode": "255",
"verifyCmd": "$TC action get action bpf index 667",
"matchPattern": "action order [0-9]*: bpf action.o:\\[action-ko\\] id [0-9].*index 667 ref",
"matchPattern": "action order [0-9]*: bpf action-ebpf:\\[action-ko\\] id [0-9].*index 667 ref",
"matchCount": "0",
"teardown": [
[
Expand Down
10 changes: 4 additions & 6 deletions tools/testing/selftests/tc-testing/tc-tests/filters/bpf.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,16 @@
],
"plugins": {
"requires": [
"buildebpfPlugin",
"nsPlugin"
]
},
"setup": [
"$TC qdisc add dev $DEV1 ingress"
],
"cmdUnderTest": "$TC filter add dev $DEV1 parent ffff: handle 1 protocol ip prio 100 bpf object-file $EBPFDIR/action.o section action-ok",
"cmdUnderTest": "$TC filter add dev $DEV1 parent ffff: handle 1 protocol ip prio 100 bpf object-file $EBPFDIR/action-ebpf section action-ok",
"expExitCode": "0",
"verifyCmd": "$TC filter get dev $DEV1 parent ffff: handle 1 protocol ip prio 100 bpf",
"matchPattern": "filter parent ffff: protocol ip pref 100 bpf chain [0-9]+ handle 0x1 action.o:\\[action-ok\\].*tag [0-9a-f]{16}( jited)?",
"matchPattern": "filter parent ffff: protocol ip pref 100 bpf chain [0-9]+ handle 0x1 action-ebpf:\\[action-ok\\].*tag [0-9a-f]{16}( jited)?",
"matchCount": "1",
"teardown": [
"$TC qdisc del dev $DEV1 ingress"
Expand All @@ -77,17 +76,16 @@
],
"plugins": {
"requires": [
"buildebpfPlugin",
"nsPlugin"
]
},
"setup": [
"$TC qdisc add dev $DEV1 ingress"
],
"cmdUnderTest": "$TC filter add dev $DEV1 parent ffff: handle 1 protocol ip prio 100 bpf object-file $EBPFDIR/action.o section action-ko",
"cmdUnderTest": "$TC filter add dev $DEV1 parent ffff: handle 1 protocol ip prio 100 bpf object-file $EBPFDIR/action-ebpf section action-ko",
"expExitCode": "1",
"verifyCmd": "$TC filter get dev $DEV1 parent ffff: handle 1 protocol ip prio 100 bpf",
"matchPattern": "filter parent ffff: protocol ip pref 100 bpf chain [0-9]+ handle 0x1 action.o:\\[action-ko\\].*tag [0-9a-f]{16}( jited)?",
"matchPattern": "filter parent ffff: protocol ip pref 100 bpf chain [0-9]+ handle 0x1 action-ebpf:\\[action-ko\\].*tag [0-9a-f]{16}( jited)?",
"matchCount": "0",
"teardown": [
"$TC qdisc del dev $DEV1 ingress"
Expand Down
11 changes: 5 additions & 6 deletions tools/testing/selftests/tc-testing/tdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,6 @@ def prepare_run(pm, args, testlist):
pm.call_post_suite(1)
return emergency_exit_message

if args.verbose:
print('give test rig 2 seconds to stabilize')

time.sleep(2)

def purge_run(pm, index):
pm.call_post_suite(index)

Expand Down Expand Up @@ -1023,7 +1018,11 @@ def main():
if args.verbose > 2:
print('args is {}'.format(args))

set_operation_mode(pm, parser, args, remaining)
try:
set_operation_mode(pm, parser, args, remaining)
except KeyboardInterrupt:
# Cleanup on Ctrl-C
pm.call_post_suite(None)

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion tools/testing/selftests/tc-testing/tdc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ 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 actions
./tdc.py -J`nproc` -c qdisc

0 comments on commit 2df6bde

Please sign in to comment.