aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavide Caratti <dcaratti@redhat.com>2018-10-04 12:34:39 -0400
committerDavid S. Miller <davem@davemloft.net>2018-10-05 17:44:56 -0400
commit4c2d39bd40c1f34975bec070a8e43fa573a9c327 (patch)
tree766db935876b24122b6f16edb824a380e578dbff
parentcf5eafbfa586d030f9321cee516b91d089e38280 (diff)
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>
-rw-r--r--tools/testing/selftests/tc-testing/README2
-rw-r--r--tools/testing/selftests/tc-testing/plugin-lib/buildebpfPlugin.py66
-rw-r--r--tools/testing/selftests/tc-testing/tc-tests/actions/bpf.json8
3 files changed, 70 insertions, 6 deletions
diff --git a/tools/testing/selftests/tc-testing/README b/tools/testing/selftests/tc-testing/README
index 49a6f8c3fdae..f9281e8aa313 100644
--- a/tools/testing/selftests/tc-testing/README
+++ b/tools/testing/selftests/tc-testing/README
@@ -232,6 +232,8 @@ directory:
232 and the other is a test whether the command leaked memory or not. 232 and the other is a test whether the command leaked memory or not.
233 (This one is a preliminary version, it may not work quite right yet, 233 (This one is a preliminary version, it may not work quite right yet,
234 but the overall template is there and it should only need tweaks.) 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
237ACKNOWLEDGEMENTS 239ACKNOWLEDGEMENTS
diff --git a/tools/testing/selftests/tc-testing/plugin-lib/buildebpfPlugin.py b/tools/testing/selftests/tc-testing/plugin-lib/buildebpfPlugin.py
new file mode 100644
index 000000000000..9f0ba10c44b4
--- /dev/null
+++ b/tools/testing/selftests/tc-testing/plugin-lib/buildebpfPlugin.py
@@ -0,0 +1,66 @@
1'''
2build ebpf program
3'''
4
5import os
6import signal
7from string import Template
8import subprocess
9import time
10from TdcPlugin import TdcPlugin
11from tdc_config import *
12
13class 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
diff --git a/tools/testing/selftests/tc-testing/tc-tests/actions/bpf.json b/tools/testing/selftests/tc-testing/tc-tests/actions/bpf.json
index 1a9b282dd0be..5970cee6d05f 100644
--- a/tools/testing/selftests/tc-testing/tc-tests/actions/bpf.json
+++ b/tools/testing/selftests/tc-testing/tc-tests/actions/bpf.json
@@ -55,7 +55,6 @@
55 "bpf" 55 "bpf"
56 ], 56 ],
57 "setup": [ 57 "setup": [
58 "make -C bpf",
59 [ 58 [
60 "$TC action flush action bpf", 59 "$TC action flush action bpf",
61 0, 60 0,
@@ -69,8 +68,7 @@
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", 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",
70 "matchCount": "1", 69 "matchCount": "1",
71 "teardown": [ 70 "teardown": [
72 "$TC action flush action bpf", 71 "$TC action flush action bpf"
73 "make -C bpf clean"
74 ] 72 ]
75 }, 73 },
76 { 74 {
@@ -81,7 +79,6 @@
81 "bpf" 79 "bpf"
82 ], 80 ],
83 "setup": [ 81 "setup": [
84 "make -C bpf",
85 [ 82 [
86 "$TC action flush action bpf", 83 "$TC action flush action bpf",
87 0, 84 0,
@@ -100,8 +97,7 @@
100 0, 97 0,
101 1, 98 1,
102 255 99 255
103 ], 100 ]
104 "make -C bpf clean"
105 ] 101 ]
106 }, 102 },
107 { 103 {