Back to home page

OSCL-LXR

 
 

    


0001 '''
0002 build ebpf program
0003 '''
0004 
0005 import os
0006 import signal
0007 from string import Template
0008 import subprocess
0009 import time
0010 from TdcPlugin import TdcPlugin
0011 from tdc_config import *
0012 
0013 class SubPlugin(TdcPlugin):
0014     def __init__(self):
0015         self.sub_class = 'buildebpf/SubPlugin'
0016         self.tap = ''
0017         super().__init__()
0018 
0019     def pre_suite(self, testcount, testidlist):
0020         super().pre_suite(testcount, testidlist)
0021 
0022         if self.args.buildebpf:
0023             self._ebpf_makeall()
0024 
0025     def post_suite(self, index):
0026         super().post_suite(index)
0027 
0028         self._ebpf_makeclean()
0029 
0030     def add_args(self, parser):
0031         super().add_args(parser)
0032 
0033         self.argparser_group = self.argparser.add_argument_group(
0034             'buildebpf',
0035             'options for buildebpfPlugin')
0036         self.argparser_group.add_argument(
0037             '--nobuildebpf', action='store_false', default=True,
0038             dest='buildebpf',
0039             help='Don\'t build eBPF programs')
0040 
0041         return self.argparser
0042 
0043     def _ebpf_makeall(self):
0044         if self.args.buildebpf:
0045             self._make('all')
0046 
0047     def _ebpf_makeclean(self):
0048         if self.args.buildebpf:
0049             self._make('clean')
0050 
0051     def _make(self, target):
0052         command = 'make -C {} {}'.format(self.args.NAMES['EBPFDIR'], target)
0053         proc = subprocess.Popen(command,
0054             shell=True,
0055             stdout=subprocess.PIPE,
0056             stderr=subprocess.PIPE,
0057             env=os.environ.copy())
0058         (rawout, serr) = proc.communicate()
0059 
0060         if proc.returncode != 0 and len(serr) > 0:
0061             foutput = serr.decode("utf-8")
0062         else:
0063             foutput = rawout.decode("utf-8")
0064 
0065         proc.stdout.close()
0066         proc.stderr.close()
0067         return proc, foutput