aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/tc-testing/plugin-lib/buildebpfPlugin.py
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 /tools/testing/selftests/tc-testing/plugin-lib/buildebpfPlugin.py
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>
Diffstat (limited to 'tools/testing/selftests/tc-testing/plugin-lib/buildebpfPlugin.py')
-rw-r--r--tools/testing/selftests/tc-testing/plugin-lib/buildebpfPlugin.py66
1 files changed, 66 insertions, 0 deletions
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