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

tc-testing: use a plugin to build eBPF program

use a TDC plugin, instead of building eBPF programs in the 'setup' stage.
'-B' argument can be used to build eBPF programs in $EBPFDIR directory,
in the 'pre-suite' stage. Binaries are then cleaned in 'post-suite' stage.

Signed-off-by: Davide Caratti <dcaratti@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Davide Caratti and committed by
David S. Miller
4c2d39bd cf5eafbf

+70 -6
+2
tools/testing/selftests/tc-testing/README
··· 232 232 and the other is a test whether the command leaked memory or not. 233 233 (This one is a preliminary version, it may not work quite right yet, 234 234 but the overall template is there and it should only need tweaks.) 235 + - buildebpfPlugin.py: 236 + builds all programs in $EBPFDIR. 235 237 236 238 237 239 ACKNOWLEDGEMENTS
+66
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 + '-B', '--buildebpf', action='store_true', 38 + help='build eBPF programs') 39 + 40 + return self.argparser 41 + 42 + def _ebpf_makeall(self): 43 + if self.args.buildebpf: 44 + self._make('all') 45 + 46 + def _ebpf_makeclean(self): 47 + if self.args.buildebpf: 48 + self._make('clean') 49 + 50 + def _make(self, target): 51 + command = 'make -C {} {}'.format(self.args.NAMES['EBPFDIR'], target) 52 + proc = subprocess.Popen(command, 53 + shell=True, 54 + stdout=subprocess.PIPE, 55 + stderr=subprocess.PIPE, 56 + env=ENVIR) 57 + (rawout, serr) = proc.communicate() 58 + 59 + if proc.returncode != 0 and len(serr) > 0: 60 + foutput = serr.decode("utf-8") 61 + else: 62 + foutput = rawout.decode("utf-8") 63 + 64 + proc.stdout.close() 65 + proc.stderr.close() 66 + return proc, foutput
+2 -6
tools/testing/selftests/tc-testing/tc-tests/actions/bpf.json
··· 55 55 "bpf" 56 56 ], 57 57 "setup": [ 58 - "make -C bpf", 59 58 [ 60 59 "$TC action flush action bpf", 61 60 0, ··· 68 69 "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", 69 70 "matchCount": "1", 70 71 "teardown": [ 71 - "$TC action flush action bpf", 72 - "make -C bpf clean" 72 + "$TC action flush action bpf" 73 73 ] 74 74 }, 75 75 { ··· 79 81 "bpf" 80 82 ], 81 83 "setup": [ 82 - "make -C bpf", 83 84 [ 84 85 "$TC action flush action bpf", 85 86 0, ··· 97 100 0, 98 101 1, 99 102 255 100 - ], 101 - "make -C bpf clean" 103 + ] 102 104 ] 103 105 }, 104 106 {