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

Merge branch 'selftests-tc-testing-updates-and-cleanups-for-tdc'

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>

+26 -131
+3 -28
tools/testing/selftests/tc-testing/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - include ../../../scripts/Makefile.include 3 - 4 - top_srcdir = $(abspath ../../../..) 5 - APIDIR := $(top_scrdir)/include/uapi 6 - TEST_GEN_FILES = action.o 7 - 8 - include ../lib.mk 9 - 10 - PROBE := $(shell $(LLC) -march=bpf -mcpu=probe -filetype=null /dev/null 2>&1) 11 - 12 - ifeq ($(PROBE),) 13 - CPU ?= probe 14 - else 15 - CPU ?= generic 16 - endif 17 - 18 - CLANG_SYS_INCLUDES := $(shell $(CLANG) -v -E - </dev/null 2>&1 \ 19 - | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') 20 - 21 - CLANG_FLAGS = -I. -I$(APIDIR) \ 22 - $(CLANG_SYS_INCLUDES) \ 23 - -Wno-compare-distinct-pointer-types 24 - 25 - $(OUTPUT)/%.o: %.c 26 - $(CLANG) $(CLANG_FLAGS) \ 27 - -O2 --target=bpf -emit-llvm -c $< -o - | \ 28 - $(LLC) -march=bpf -mcpu=$(CPU) $(LLC_FLAGS) -filetype=obj -o $@ 29 2 30 3 TEST_PROGS += ./tdc.sh 31 - TEST_FILES := tdc*.py Tdc*.py plugins plugin-lib tc-tests scripts 4 + TEST_FILES := action-ebpf tdc*.py Tdc*.py plugins plugin-lib tc-tests scripts 5 + 6 + include ../lib.mk
-2
tools/testing/selftests/tc-testing/README
··· 195 195 and the other is a test whether the command leaked memory or not. 196 196 (This one is a preliminary version, it may not work quite right yet, 197 197 but the overall template is there and it should only need tweaks.) 198 - - buildebpfPlugin.py: 199 - builds all programs in $EBPFDIR. 200 198 201 199 202 200 ACKNOWLEDGEMENTS
tools/testing/selftests/tc-testing/action-ebpf

This is a binary file and will not be displayed.

-67
tools/testing/selftests/tc-testing/plugin-lib/buildebpfPlugin.py
··· 1 - ''' 2 - build ebpf program 3 - ''' 4 - 5 - import os 6 - import signal 7 - from string import Template 8 - import subprocess 9 - import time 10 - from TdcPlugin import TdcPlugin 11 - from tdc_config import * 12 - 13 - class SubPlugin(TdcPlugin): 14 - def __init__(self): 15 - self.sub_class = 'buildebpf/SubPlugin' 16 - self.tap = '' 17 - super().__init__() 18 - 19 - def pre_suite(self, testcount, testidlist): 20 - super().pre_suite(testcount, testidlist) 21 - 22 - if self.args.buildebpf: 23 - self._ebpf_makeall() 24 - 25 - def post_suite(self, index): 26 - super().post_suite(index) 27 - 28 - self._ebpf_makeclean() 29 - 30 - def add_args(self, parser): 31 - super().add_args(parser) 32 - 33 - self.argparser_group = self.argparser.add_argument_group( 34 - 'buildebpf', 35 - 'options for buildebpfPlugin') 36 - self.argparser_group.add_argument( 37 - '--nobuildebpf', action='store_false', default=True, 38 - dest='buildebpf', 39 - help='Don\'t build eBPF programs') 40 - 41 - return self.argparser 42 - 43 - def _ebpf_makeall(self): 44 - if self.args.buildebpf: 45 - self._make('all') 46 - 47 - def _ebpf_makeclean(self): 48 - if self.args.buildebpf: 49 - self._make('clean') 50 - 51 - def _make(self, target): 52 - command = 'make -C {} {}'.format(self.args.NAMES['EBPFDIR'], target) 53 - proc = subprocess.Popen(command, 54 - shell=True, 55 - stdout=subprocess.PIPE, 56 - stderr=subprocess.PIPE, 57 - env=os.environ.copy()) 58 - (rawout, serr) = proc.communicate() 59 - 60 - if proc.returncode != 0 and len(serr) > 0: 61 - foutput = serr.decode("utf-8") 62 - else: 63 - foutput = rawout.decode("utf-8") 64 - 65 - proc.stdout.close() 66 - proc.stderr.close() 67 - return proc, foutput
+9 -11
tools/testing/selftests/tc-testing/plugin-lib/nsPlugin.py
··· 23 23 super().__init__() 24 24 25 25 def pre_suite(self, testcount, testlist): 26 - from itertools import cycle 27 - 28 26 super().pre_suite(testcount, testlist) 29 27 30 28 def prepare_test(self, test): ··· 35 37 if netlink == True: 36 38 self._nl_ns_create() 37 39 else: 38 - self._ns_create() 40 + self._ipr2_ns_create() 39 41 40 42 # Make sure the netns is visible in the fs 41 43 ticks = 20 ··· 69 71 if netlink == True: 70 72 self._nl_ns_destroy() 71 73 else: 72 - self._ns_destroy() 74 + self._ipr2_ns_destroy() 73 75 74 76 def post_suite(self, index): 75 77 if self.args.verbose: 76 78 print('{}.post_suite'.format(self.sub_class)) 77 79 78 80 # Make sure we don't leak resources 79 - cmd = "$IP -a netns del" 81 + cmd = self._replace_keywords("$IP -a netns del") 80 82 81 83 if self.args.verbose > 3: 82 84 print('_exec_cmd: command "{}"'.format(cmd)) ··· 159 161 ticks -= 1 160 162 continue 161 163 162 - def _ns_create_cmds(self): 164 + def _ipr2_ns_create_cmds(self): 163 165 cmds = [] 164 166 165 167 ns = self.args.NAMES['NS'] ··· 179 181 180 182 return cmds 181 183 182 - def _ns_create(self): 184 + def _ipr2_ns_create(self): 183 185 ''' 184 186 Create the network namespace in which the tests will be run and set up 185 187 the required network devices for it. 186 188 ''' 187 - self._exec_cmd_batched('pre', self._ns_create_cmds()) 189 + self._exec_cmd_batched('pre', self._ipr2_ns_create_cmds()) 188 190 189 191 def _nl_ns_destroy(self): 190 192 ns = self.args.NAMES['NS'] 191 193 netns.remove(ns) 192 194 193 - def _ns_destroy_cmd(self): 195 + def _ipr2_ns_destroy_cmd(self): 194 196 return self._replace_keywords('netns delete {}'.format(self.args.NAMES['NS'])) 195 197 196 - def _ns_destroy(self): 198 + def _ipr2_ns_destroy(self): 197 199 ''' 198 200 Destroy the network namespace for testing (and any associated network 199 201 devices as well) 200 202 ''' 201 - self._exec_cmd('post', self._ns_destroy_cmd()) 203 + self._exec_cmd('post', self._ipr2_ns_destroy_cmd()) 202 204 203 205 @cached_property 204 206 def _proc(self):
+4 -10
tools/testing/selftests/tc-testing/tc-tests/actions/bpf.json
··· 54 54 "actions", 55 55 "bpf" 56 56 ], 57 - "plugins": { 58 - "requires": "buildebpfPlugin" 59 - }, 60 57 "setup": [ 61 58 [ 62 59 "$TC action flush action bpf", ··· 62 65 255 63 66 ] 64 67 ], 65 - "cmdUnderTest": "$TC action add action bpf object-file $EBPFDIR/action.o section action-ok index 667", 68 + "cmdUnderTest": "$TC action add action bpf object-file $EBPFDIR/action-ebpf section action-ok index 667", 66 69 "expExitCode": "0", 67 70 "verifyCmd": "$TC action get action bpf index 667", 68 - "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", 71 + "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", 69 72 "matchCount": "1", 70 73 "teardown": [ 71 74 "$TC action flush action bpf" ··· 78 81 "actions", 79 82 "bpf" 80 83 ], 81 - "plugins": { 82 - "requires": "buildebpfPlugin" 83 - }, 84 84 "setup": [ 85 85 [ 86 86 "$TC action flush action bpf", ··· 86 92 255 87 93 ] 88 94 ], 89 - "cmdUnderTest": "$TC action add action bpf object-file $EBPFDIR/action.o section action-ko index 667", 95 + "cmdUnderTest": "$TC action add action bpf object-file $EBPFDIR/action-ebpf section action-ko index 667", 90 96 "expExitCode": "255", 91 97 "verifyCmd": "$TC action get action bpf index 667", 92 - "matchPattern": "action order [0-9]*: bpf action.o:\\[action-ko\\] id [0-9].*index 667 ref", 98 + "matchPattern": "action order [0-9]*: bpf action-ebpf:\\[action-ko\\] id [0-9].*index 667 ref", 93 99 "matchCount": "0", 94 100 "teardown": [ 95 101 [
+4 -6
tools/testing/selftests/tc-testing/tc-tests/filters/bpf.json
··· 52 52 ], 53 53 "plugins": { 54 54 "requires": [ 55 - "buildebpfPlugin", 56 55 "nsPlugin" 57 56 ] 58 57 }, 59 58 "setup": [ 60 59 "$TC qdisc add dev $DEV1 ingress" 61 60 ], 62 - "cmdUnderTest": "$TC filter add dev $DEV1 parent ffff: handle 1 protocol ip prio 100 bpf object-file $EBPFDIR/action.o section action-ok", 61 + "cmdUnderTest": "$TC filter add dev $DEV1 parent ffff: handle 1 protocol ip prio 100 bpf object-file $EBPFDIR/action-ebpf section action-ok", 63 62 "expExitCode": "0", 64 63 "verifyCmd": "$TC filter get dev $DEV1 parent ffff: handle 1 protocol ip prio 100 bpf", 65 - "matchPattern": "filter parent ffff: protocol ip pref 100 bpf chain [0-9]+ handle 0x1 action.o:\\[action-ok\\].*tag [0-9a-f]{16}( jited)?", 64 + "matchPattern": "filter parent ffff: protocol ip pref 100 bpf chain [0-9]+ handle 0x1 action-ebpf:\\[action-ok\\].*tag [0-9a-f]{16}( jited)?", 66 65 "matchCount": "1", 67 66 "teardown": [ 68 67 "$TC qdisc del dev $DEV1 ingress" ··· 76 77 ], 77 78 "plugins": { 78 79 "requires": [ 79 - "buildebpfPlugin", 80 80 "nsPlugin" 81 81 ] 82 82 }, 83 83 "setup": [ 84 84 "$TC qdisc add dev $DEV1 ingress" 85 85 ], 86 - "cmdUnderTest": "$TC filter add dev $DEV1 parent ffff: handle 1 protocol ip prio 100 bpf object-file $EBPFDIR/action.o section action-ko", 86 + "cmdUnderTest": "$TC filter add dev $DEV1 parent ffff: handle 1 protocol ip prio 100 bpf object-file $EBPFDIR/action-ebpf section action-ko", 87 87 "expExitCode": "1", 88 88 "verifyCmd": "$TC filter get dev $DEV1 parent ffff: handle 1 protocol ip prio 100 bpf", 89 - "matchPattern": "filter parent ffff: protocol ip pref 100 bpf chain [0-9]+ handle 0x1 action.o:\\[action-ko\\].*tag [0-9a-f]{16}( jited)?", 89 + "matchPattern": "filter parent ffff: protocol ip pref 100 bpf chain [0-9]+ handle 0x1 action-ebpf:\\[action-ko\\].*tag [0-9a-f]{16}( jited)?", 90 90 "matchCount": "0", 91 91 "teardown": [ 92 92 "$TC qdisc del dev $DEV1 ingress"
+5 -6
tools/testing/selftests/tc-testing/tdc.py
··· 497 497 pm.call_post_suite(1) 498 498 return emergency_exit_message 499 499 500 - if args.verbose: 501 - print('give test rig 2 seconds to stabilize') 502 - 503 - time.sleep(2) 504 - 505 500 def purge_run(pm, index): 506 501 pm.call_post_suite(index) 507 502 ··· 1018 1023 if args.verbose > 2: 1019 1024 print('args is {}'.format(args)) 1020 1025 1021 - set_operation_mode(pm, parser, args, remaining) 1026 + try: 1027 + set_operation_mode(pm, parser, args, remaining) 1028 + except KeyboardInterrupt: 1029 + # Cleanup on Ctrl-C 1030 + pm.call_post_suite(None) 1022 1031 1023 1032 if __name__ == "__main__": 1024 1033 main()
+1 -1
tools/testing/selftests/tc-testing/tdc.sh
··· 64 64 try_modprobe sch_hhf 65 65 try_modprobe sch_htb 66 66 try_modprobe sch_teql 67 - ./tdc.py -J`nproc` -c actions --nobuildebpf 67 + ./tdc.py -J`nproc` -c actions 68 68 ./tdc.py -J`nproc` -c qdisc