P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::P4Tools::P4Testgen::TestFramework Class Referenceabstract

#include <test_framework.h>

Inheritance diagram for P4::P4Tools::P4Testgen::TestFramework:
[legend]

Public Member Functions

bool isInFileMode () const
 @Returns true if the test framework is configured to write to a file.
 
virtual AbstractTestReferenceOrError produceTest (const TestSpec *spec, cstring selectedBranches, size_t testIdx, float currentCoverage)
 
virtual void writeTestToFile (const TestSpec *spec, cstring selectedBranches, size_t testIdx, float currentCoverage)=0
 

Protected Member Functions

 TestFramework (const TestBackendConfiguration &testBackendConfiguration)
 Creates a generic test framework.
 
const TestBackendConfigurationgetTestBackendConfiguration () const
 Returns the configuration options for the test back end.
 

Static Protected Member Functions

static void checkForDefaultActionOverride (inja::json &tblJson, const TableConfig *tblConfig)
 
template<class ProfileType , class SelectorType >
static void checkForTableActionProfile (inja::json &tblJson, std::map< cstring, cstring > &apAsMap, const TableConfig *tblConfig)
 
template<class ProfileType >
static void collectActionProfileDeclarations (const TestSpec *testSpec, inja::json &controlPlaneJson, const std::map< cstring, cstring > &apAsMap)
 Collect all the action profile objects. These will have to be declared in the test.
 
static inja::json getTrace (const TestSpec *testSpec)
 Converts the traces of this test into a string representation and Inja object.
 

Detailed Description

THe default base class for the various test frameworks. Every test framework has a test name and a seed associated with it. Also contains a variety of common utility functions.

Member Function Documentation

◆ checkForDefaultActionOverride()

static void P4::P4Tools::P4Testgen::TestFramework::checkForDefaultActionOverride ( inja::json & tblJson,
const TableConfig * tblConfig )
inlinestaticprotected

Check whether the table object has an overridden default action. In this case, we assume there are no keys and we just set the default action of the table.

◆ checkForTableActionProfile()

template<class ProfileType , class SelectorType >
static void P4::P4Tools::P4Testgen::TestFramework::checkForTableActionProfile ( inja::json & tblJson,
std::map< cstring, cstring > & apAsMap,
const TableConfig * tblConfig )
inlinestaticprotected

Checks whether a table object has an action profile or selector associated with it. If that is the case, we set a boolean flag for this particular inja object.

◆ produceTest()

AbstractTestReferenceOrError P4::P4Tools::P4Testgen::TestFramework::produceTest ( const TestSpec * spec,
cstring selectedBranches,
size_t testIdx,
float currentCoverage )
virtual

The method used to return the test case. This method is optional to each test framework.

Parameters
specthe testcase specification to be outputted.
selectedBranchesstring describing branches selected for this testcase.
testIdxtestcase unique number identifier. TODO: Make this a member?
currentCoveragecurrent coverage ratio (between 0.0 and 1.0).

Reimplemented in P4::P4Tools::P4Testgen::Bmv2::Protobuf, and P4::P4Tools::P4Testgen::Bmv2::ProtobufIr.

◆ writeTestToFile()

virtual void P4::P4Tools::P4Testgen::TestFramework::writeTestToFile ( const TestSpec * spec,
cstring selectedBranches,
size_t testIdx,
float currentCoverage )
pure virtual

The method used to output the test case to be implemented by all the test frameworks (eg. STF, PTF, etc.).

Parameters
specthe testcase specification to be outputted.
selectedBranchesstring describing branches selected for this testcase.
testIdxtestcase unique number identifier. TODO: Make this a member?
currentCoveragecurrent coverage ratio (between 0.0 and 1.0) TODO (https://github.com/p4lang/p4c/issues/4403): This should not return void but instead a status.

Implemented in P4::P4Tools::P4Testgen::Bmv2::Metadata, P4::P4Tools::P4Testgen::Bmv2::Protobuf, P4::P4Tools::P4Testgen::Bmv2::ProtobufIr, P4::P4Tools::P4Testgen::Bmv2::PTF, P4::P4Tools::P4Testgen::Bmv2::STF, P4::P4Tools::P4Testgen::EBPF::STF, P4::P4Tools::P4Testgen::Pna::Metadata, and P4::P4Tools::P4Testgen::Pna::PTF.