2.5. framework module

class framework.KeepAliveReporter

Bases: object

Singleton object which reports test start to parent process

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

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_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)

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

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

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)
classmethod pg_start()

Remove any zombie captures and enable the packet generator

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

runTest()

unittest calls runTest when TestCase is instantiated without a test case. Use case: Writing unittests against VppTestCase

classmethod run_vpp()
send_and_assert_no_replies(intf, pkts, remark='', timeout=None)
send_and_expect(intf, pkts, output, n_rx=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)
classmethod sleep(timeout, remark=None)
tearDown()

Show various debug prints after each test

classmethod tearDownClass()

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

classmethod wait_for_enter()
classmethod wait_for_stats_socket()
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.

resultclass

Class maintaining the results of the tests

run(test)

Run the tests

Parameters

test

class framework.Worker(args, logger, env={})

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.

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

framework.running_on_centos()