aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/tc-testing/plugin-lib/buildebpfPlugin.py
blob: 9f0ba10c44b42a32761dc9d02699e652eeff78fe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'''
build ebpf program
'''

import os
import signal
from string import Template
import subprocess
import time
from TdcPlugin import TdcPlugin
from tdc_config import *

class SubPlugin(TdcPlugin):
    def __init__(self):
        self.sub_class = 'buildebpf/SubPlugin'
        self.tap = ''
        super().__init__()

    def pre_suite(self, testcount, testidlist):
        super().pre_suite(testcount, testidlist)

        if self.args.buildebpf:
            self._ebpf_makeall()

    def post_suite(self, index):
        super().post_suite(index)

        self._ebpf_makeclean()

    def add_args(self, parser):
        super().add_args(parser)

        self.argparser_group = self.argparser.add_argument_group(
            'buildebpf',
            'options for buildebpfPlugin')
        self.argparser_group.add_argument(
            '-B', '--buildebpf', action='store_true',
            help='build eBPF programs')

        return self.argparser

    def _ebpf_makeall(self):
        if self.args.buildebpf:
            self._make('all')

    def _ebpf_makeclean(self):
        if self.args.buildebpf:
            self._make('clean')

    def _make(self, target):
        command = 'make -C {} {}'.format(self.args.NAMES['EBPFDIR'], target)
        proc = subprocess.Popen(command,
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            env=ENVIR)
        (rawout, serr) = proc.communicate()

        if proc.returncode != 0 and len(serr) > 0:
            foutput = serr.decode("utf-8")
        else:
            foutput = rawout.decode("utf-8")

        proc.stdout.close()
        proc.stderr.close()
        return proc, foutput