Commit 2df6bde3 authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files

Merge branch 'selftests-tc-testing-updates-and-cleanups-for-tdc'

Pedro Tammela says:

====================
selftests: tc-testing: updates and cleanups for tdc

Address the recommendations from the previous series and cleanup some
leftovers.
====================

Link: https://lore.kernel.org/r/20231124154248.315470-1-pctammela@mojatatu.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents cae0de45 ed346fcc
Loading
Loading
Loading
Loading
+2 −27
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0
include ../../../scripts/Makefile.include

top_srcdir = $(abspath ../../../..)
APIDIR := $(top_scrdir)/include/uapi
TEST_GEN_FILES = action.o
TEST_PROGS += ./tdc.sh
TEST_FILES := action-ebpf tdc*.py Tdc*.py plugins plugin-lib tc-tests scripts

include ../lib.mk

PROBE := $(shell $(LLC) -march=bpf -mcpu=probe -filetype=null /dev/null 2>&1)

ifeq ($(PROBE),)
  CPU ?= probe
else
  CPU ?= generic
endif

CLANG_SYS_INCLUDES := $(shell $(CLANG) -v -E - </dev/null 2>&1 \
	| sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }')

CLANG_FLAGS = -I. -I$(APIDIR) \
	      $(CLANG_SYS_INCLUDES) \
	      -Wno-compare-distinct-pointer-types

$(OUTPUT)/%.o: %.c
	$(CLANG) $(CLANG_FLAGS) \
		 -O2 --target=bpf -emit-llvm -c $< -o - |      \
	$(LLC) -march=bpf -mcpu=$(CPU) $(LLC_FLAGS) -filetype=obj -o $@

TEST_PROGS += ./tdc.sh
TEST_FILES := tdc*.py Tdc*.py plugins plugin-lib tc-tests scripts
+0 −2
Original line number Diff line number Diff line
@@ -195,8 +195,6 @@ directory:
      and the other is a test whether the command leaked memory or not.
      (This one is a preliminary version, it may not work quite right yet,
      but the overall template is there and it should only need tweaks.)
  - buildebpfPlugin.py:
      builds all programs in $EBPFDIR.


ACKNOWLEDGEMENTS
+856 B

File added.

No diff preview for this file type.

+0 −67
Original line number Diff line number Diff line
'''
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(
            '--nobuildebpf', action='store_false', default=True,
            dest='buildebpf',
            help='Don\'t 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=os.environ.copy())
        (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
+9 −11
Original line number Diff line number Diff line
@@ -23,8 +23,6 @@ class SubPlugin(TdcPlugin):
        super().__init__()

    def pre_suite(self, testcount, testlist):
        from itertools import cycle

        super().pre_suite(testcount, testlist)

    def prepare_test(self, test):
@@ -37,7 +35,7 @@ class SubPlugin(TdcPlugin):
        if netlink == True:
            self._nl_ns_create()
        else:
            self._ns_create()
            self._ipr2_ns_create()

        # Make sure the netns is visible in the fs
        ticks = 20
@@ -71,14 +69,14 @@ class SubPlugin(TdcPlugin):
        if netlink == True:
            self._nl_ns_destroy()
        else:
            self._ns_destroy()
            self._ipr2_ns_destroy()

    def post_suite(self, index):
        if self.args.verbose:
            print('{}.post_suite'.format(self.sub_class))

        # Make sure we don't leak resources
        cmd = "$IP -a netns del"
        cmd = self._replace_keywords("$IP -a netns del")

        if self.args.verbose > 3:
            print('_exec_cmd:  command "{}"'.format(cmd))
@@ -161,7 +159,7 @@ class SubPlugin(TdcPlugin):
                    ticks -= 1
                    continue

    def _ns_create_cmds(self):
    def _ipr2_ns_create_cmds(self):
        cmds = []

        ns = self.args.NAMES['NS']
@@ -181,26 +179,26 @@ class SubPlugin(TdcPlugin):

        return cmds

    def _ns_create(self):
    def _ipr2_ns_create(self):
        '''
        Create the network namespace in which the tests will be run and set up
        the required network devices for it.
        '''
        self._exec_cmd_batched('pre', self._ns_create_cmds())
        self._exec_cmd_batched('pre', self._ipr2_ns_create_cmds())

    def _nl_ns_destroy(self):
        ns = self.args.NAMES['NS']
        netns.remove(ns)

    def _ns_destroy_cmd(self):
    def _ipr2_ns_destroy_cmd(self):
        return self._replace_keywords('netns delete {}'.format(self.args.NAMES['NS']))

    def _ns_destroy(self):
    def _ipr2_ns_destroy(self):
        '''
        Destroy the network namespace for testing (and any associated network
        devices as well)
        '''
        self._exec_cmd('post', self._ns_destroy_cmd())
        self._exec_cmd('post', self._ipr2_ns_destroy_cmd())

    @cached_property
    def _proc(self):
Loading