buildebpfPlugin.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. '''
  2. build ebpf program
  3. '''
  4. import os
  5. import signal
  6. from string import Template
  7. import subprocess
  8. import time
  9. from TdcPlugin import TdcPlugin
  10. from tdc_config import *
  11. class SubPlugin(TdcPlugin):
  12. def __init__(self):
  13. self.sub_class = 'buildebpf/SubPlugin'
  14. self.tap = ''
  15. super().__init__()
  16. def pre_suite(self, testcount, testidlist):
  17. super().pre_suite(testcount, testidlist)
  18. if self.args.buildebpf:
  19. self._ebpf_makeall()
  20. def post_suite(self, index):
  21. super().post_suite(index)
  22. self._ebpf_makeclean()
  23. def add_args(self, parser):
  24. super().add_args(parser)
  25. self.argparser_group = self.argparser.add_argument_group(
  26. 'buildebpf',
  27. 'options for buildebpfPlugin')
  28. self.argparser_group.add_argument(
  29. '-B', '--buildebpf', action='store_true',
  30. help='build eBPF programs')
  31. return self.argparser
  32. def _ebpf_makeall(self):
  33. if self.args.buildebpf:
  34. self._make('all')
  35. def _ebpf_makeclean(self):
  36. if self.args.buildebpf:
  37. self._make('clean')
  38. def _make(self, target):
  39. command = 'make -C {} {}'.format(self.args.NAMES['EBPFDIR'], target)
  40. proc = subprocess.Popen(command,
  41. shell=True,
  42. stdout=subprocess.PIPE,
  43. stderr=subprocess.PIPE,
  44. env=ENVIR)
  45. (rawout, serr) = proc.communicate()
  46. if proc.returncode != 0 and len(serr) > 0:
  47. foutput = serr.decode("utf-8")
  48. else:
  49. foutput = rawout.decode("utf-8")
  50. proc.stdout.close()
  51. proc.stderr.close()
  52. return proc, foutput