![]() |
P4C
The P4 Compiler
|
P4Tools is the P4C subproject that bundles tooling for testing and fuzzing P4 programs. It ships two main tools:
backends/p4tools/ contains:
cmake/: CMake helper modules for building P4Tools and its tests.common/: shared C++ infrastructure used by all tools.compiler/: P4 compiler passes and midend helpers.control_plane/: control-plane modeling utilities.core/: core abstractions (targets, Z3 solver, execution state).lib/: reusable data structures and utilities.modules/: tool implementations and their targets.testgen/: P4Testgen implementation.smith/: P4Smith implementation.p4tools.def: IR extensions used by P4Tools.CMakeLists.txt: top-level CMake wiring and module discovery.BUILD.bazel: Bazel build rules (limited scope).p4tools.def adds custom IR nodes such as StateVariable, TaintExpression, Extracted_Varbits, and ConcolicVariable. These are compiled into the P4C IR via IR_DEF_FILES.common/ hosts libraries, solver bindings, and compiler helpers used by both tools.modules/*/targets/, each providing a register.h.Top-level CMake behavior:
CMakeLists.txt auto-discovers tool modules under modules/*.ENABLE_TOOLS_MODULE_<NAME>.modules/<tool>/targets/* and creates ENABLE_TOOLS_TARGET_<TARGET> toggles.common/CMakeLists.txt fetches Z3 via cmake/Z3.cmake and exports it with the p4tools-common library.P4Testgen specifics:
modules/testgen/CMakeLists.txt fetches inja and wires p4testgen.linkp4testgen creates symlinks for the binary and p4include.testgen-gtest when ENABLE_GTESTS=ON.P4Smith specifics:
modules/smith/CMakeLists.txt wires p4smith and generates version.h.Build enablement:
-DENABLE_TEST_TOOLS=ON.README.md).BUILD.bazel provides a limited Bazel build:
p4testgen is wired by default.TESTGEN_TARGETS currently includes only bmv2.modules/testgen/register.h via a Bazel genrule. If you add a new Testgen target and need Bazel support, extend TESTGEN_TARGETS and the corresponding filegroup/genrule.To add a new target:
modules/testgen/targets/<name>/ or modules/smith/targets/<name>/.CMakeLists.txt and a register.h.register.h.BUILD.bazel (TESTGEN_TARGETS).testgen-gtest is built when ENABLE_GTESTS=ON.ctest --test-dir build -j<N> --output-on-failure -R testgen ctest --test-dir build -j<N> --output-on-failure -R smithmodules/testgen/targets/*.modules/testgen/benchmarks/.backends/p4tools/modules/testgen/**, rebuild p4testgen explicitly (cmake --build build --target p4testgen -j<N>) before trusting test results.ctest --test-dir build --output-on-failure -R testgen-p4c-ebpf/<name>.p4 for quick iteration.build/testgen/testgen-p4c-<target>/<program>.out/ and are often the fastest way to diagnose mismatches between symbolic traces and emitted control-plane commands.pynng in the active environment and run BMv2 PTF tests with nanomsg mode (the testgen runner already passes --use-nanomsg), so uv run ctest ... works without sudo.TestSpec objects to target-specific artifacts under modules/testgen/targets/<target>/ (for example STF, PTF, metadata, or protobuf emitters).README.md: overview, dependencies, and layout.modules/testgen/README.md: P4Testgen usage, extensions, and limitations.modules/smith/README.md: P4Smith usage and extension notes.CMakeLists.txt: module/target discovery and build wiring.p4tools.def: IR extensions used across tools.