2.5. framework module

class framework.BoolEnvironmentVariable(env_var_name, default='n', true_values=None)

Bases: object

class framework.KeepAliveReporter

Bases: object

Singleton object which reports test start to parent process

property pipe
send_keep_alive(test, desc=None)

Write current test tmpdir & desc to keep-alive pipe to signal liveness

class framework.TestCaseInfo(logger, tempdir, vpp_pid, vpp_bin_path)

Bases: object

exception framework.VppDiedError(rv=None, testcase=None, method_name=None)

Bases: Exception

exception for reporting that the subprocess has died.

signals_by_value = {<Signals.SIGHUP: 1>: 'SIGHUP', <Signals.SIGINT: 2>: 'SIGINT', <Signals.SIGQUIT: 3>: 'SIGQUIT', <Signals.SIGILL: 4>: 'SIGILL', <Signals.SIGTRAP: 5>: 'SIGTRAP', <Signals.SIGABRT: 6>: 'SIGABRT', <Signals.SIGBUS: 7>: 'SIGBUS', <Signals.SIGFPE: 8>: 'SIGFPE', <Signals.SIGKILL: 9>: 'SIGKILL', <Signals.SIGUSR1: 10>: 'SIGUSR1', <Signals.SIGSEGV: 11>: 'SIGSEGV', <Signals.SIGUSR2: 12>: 'SIGUSR2', <Signals.SIGPIPE: 13>: 'SIGPIPE', <Signals.SIGALRM: 14>: 'SIGALRM', <Signals.SIGTERM: 15>: 'SIGTERM', <Signals.SIGCHLD: 17>: 'SIGCHLD', <Signals.SIGCONT: 18>: 'SIGCONT', <Signals.SIGSTOP: 19>: 'SIGSTOP', <Signals.SIGTSTP: 20>: 'SIGTSTP', <Signals.SIGTTIN: 21>: 'SIGTTIN', <Signals.SIGTTOU: 22>: 'SIGTTOU', <Signals.SIGURG: 23>: 'SIGURG', <Signals.SIGXCPU: 24>: 'SIGXCPU', <Signals.SIGXFSZ: 25>: 'SIGXFSZ', <Signals.SIGVTALRM: 26>: 'SIGVTALRM', <Signals.SIGPROF: 27>: 'SIGPROF', <Signals.SIGWINCH: 28>: 'SIGWINCH', <Signals.SIGIO: 29>: 'SIGPOLL', <Signals.SIGPWR: 30>: 'SIGPWR', <Signals.SIGSYS: 31>: 'SIGSYS', <Signals.SIGRTMIN: 34>: 'SIGRTMIN', <Signals.SIGRTMAX: 64>: 'SIGRTMAX'}
class framework.VppTestCase(methodName='runTest')

Bases: unittest.case.TestCase

This subclass is a base class for VPP test cases that are implemented as classes. It provides methods to create and run test case.

assert_checksum_valid(received_packet, layer, field_name='chksum', ignore_zero_checksum=False)

Check checksum of received packet on given layer

assert_embedded_icmp_checksum_valid(received_packet)
assert_equal(real_value, expected_value, name_or_class=None)
assert_error_counter_equal(counter, expected_value)
assert_icmp_checksum_valid(received_packet)
assert_icmpv6_checksum_valid(pkt)
assert_in_range(real_value, expected_min, expected_max, name=None)
assert_ip_checksum_valid(received_packet, ignore_zero_checksum=False)
assert_packet_checksums_valid(packet, ignore_zero_udp_checksums=True)
assert_packet_counter_equal(counter, expected_value)
assert_tcp_checksum_valid(received_packet, ignore_zero_checksum=False)
assert_udp_checksum_valid(received_packet, ignore_zero_checksum=True)
classmethod create_bvi_interfaces(count)

Create BVI interfaces.

Parameters

count – number of interfaces created.

Returns

List of created interfaces.

classmethod create_loopback_interfaces(count)

Create loopback interfaces.

Parameters

count – number of interfaces created.

Returns

List of created interfaces.

classmethod create_packet_info(src_if, dst_if)

Create packet info object containing the source and destination indexes and add it to the testcase’s packet info list

Parameters
Returns

_PacketInfo object

classmethod create_pg_interfaces(interfaces, gso=0, gso_size=0)

Create packet-generator interfaces.

Parameters

interfaces – iterable indexes of the interfaces.

Returns

List of created interfaces.

static extend_packet(packet, size, padding=' ')

Extend packet to given size by padding with spaces or custom padding NOTE: Currently works only when Raw layer is present.

Parameters
  • packet – packet

  • size – target size

  • padding – padding used to extend the payload

extra_vpp_plugin_config = []
extra_vpp_punt_config = []
static get_least_used_cpu()
get_next_packet_info(info)

Iterate over the packet info list stored in the testcase Start iteration with first element if info is None Continue based on index in info if info is specified

Parameters

info – info or None

Returns

next info in list or None if no more infos

get_next_packet_info_for_interface(src_index, info)

Search the packet info list for the next packet info with same source interface index

Parameters
  • src_index – source interface index to search for

  • info – packet info - where to start the search

Returns

packet info or None

get_next_packet_info_for_interface2(src_index, dst_index, info)

Search the packet info list for the next packet info with same source and destination interface indexes

Parameters
  • src_index – source interface index to search for

  • dst_index – destination interface index to search for

  • info – packet info - where to start the search

Returns

packet info or None

classmethod get_packet_count_for_if_idx(dst_if_index)

Get the number of packet info for specified destination if index

get_packet_counter(counter)
classmethod get_vpp_time()
static info_to_payload(info)

Convert _PacketInfo object to packet payload

Parameters

info – _PacketInfo object

Returns

string containing serialized data from packet info

classmethod instance()

Return the instance of this testcase

logger = <Logger VppTestCase (WARNING)>
property packet_infos

List of packet infos

static payload_to_info(payload, payload_field='load')

Convert packet payload to _PacketInfo object

Parameters
  • payload (<class 'scapy.packet.Raw'>) – packet payload

  • payload_field (str) – packet fieldname of payload “load” for <class ‘scapy.packet.Raw’>

Returns

_PacketInfo object containing de-serialized data from payload

classmethod pg_enable_capture(interfaces=None)

Enable capture on packet-generator interfaces

Parameters

interfaces – iterable interface indexes (if None, use self.pg_interfaces)

pg_send(intf, pkts, worker=None)
classmethod pg_start()

Enable the PG, wait till it is done, then clean up

classmethod quit()

Disconnect vpp-api, kill vpp and cleanup shared memory files

classmethod register_capture(cap_name)

Register a capture in the testclass

classmethod reset_packet_infos()

Reset the list of packet info objects and packet counts to zero

classmethod run_vpp()
send_and_assert_no_replies(intf, pkts, remark='', timeout=None)
send_and_expect(intf, pkts, output, n_rx=None, worker=None)
send_and_expect_only(intf, pkts, output, timeout=None)
setUp()

Clear trace before running each test

classmethod setUpClass()

Perform class setup before running the testcase Remove shared memory files, start vpp and connect the vpp-api

classmethod setUpConstants()

Set-up the test case class based on environment variables

classmethod set_debug_flags(d)
show_commands_at_teardown()

Allow subclass specific teardown logging additions.

classmethod sleep(timeout, remark=None)
classmethod sleep_on_vpp_time(sec)

Sleep according to time in VPP world

tearDown()

Show various debug prints after each test

classmethod tearDownClass()

Perform final cleanup after running all tests in this test-case

vapi_response_timeout = 5
classmethod wait_for_coredump()
classmethod wait_for_enter()
class framework.VppTestResult(stream=None, descriptions=None, verbosity=None, runner=None)

Bases: unittest.result.TestResult

@property result_string

String variable to store the test case result string.

@property errors

List variable containing 2-tuples of TestCase instances and strings holding formatted tracebacks. Each tuple represents a test which raised an unexpected exception.

@property failures

List variable containing 2-tuples of TestCase instances and strings holding formatted tracebacks. Each tuple represents a test where a failure was explicitly signalled using the TestCase.assert*() methods.

addError(test, err)

Record a test error result

Parameters
  • test

  • err – error message

addFailure(test, err)

Record a test failed result

Parameters
  • test

  • err – error message

addSkip(test, reason)

Record a test skipped.

Parameters
  • test

  • reason

addSuccess(test)

Record a test succeeded result

Parameters

test

add_error(test, err, unittest_fn, error_type)
core_crash_test_cases_info = {}
current_test_case_info = None
failed_test_cases_info = {}
getDescription(test)

Get test description

Parameters

test

Returns

test description

log_error(test, err, fn_name)
printErrorList(flavour, errors)

Print error list to the output stream together with error type and test case description.

Parameters
  • flavour – error type

  • errors – iterable errors

printErrors()

Print errors from running the test case

send_result_through_pipe(test, result)
startTest(test)

Start a test

Parameters

test

stopTest(test)

Called when the given test has been run

Parameters

test

class framework.VppTestRunner(keep_alive_pipe=None, descriptions=True, verbosity=1, result_pipe=None, failfast=False, buffer=False, resultclass=None, print_summary=True, **kwargs)

Bases: unittest.runner.TextTestRunner

A basic test runner implementation which prints results to standard error.

property resultclass

Class maintaining the results of the tests

run(test)

Run the tests

Parameters

test

class framework.Worker(executable_args, logger, env=None, *args, **kwargs)

Bases: threading.Thread

run()

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

wait_for_enter()
framework.get_test_description(descriptions, test)
framework.get_testcase_doc_name(test)
framework.pump_output(testclass)

pump output from vpp stdout/stderr to proper queues