Skip to content

Commit

Permalink
Add a testgen.p4 file with custom extern definitions such as testgen_…
Browse files Browse the repository at this point in the history
…assert and testgen_assume. (#4214)
  • Loading branch information
fruffy authored Nov 2, 2023
1 parent 0ba4abc commit 14a64e4
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 27 deletions.
6 changes: 4 additions & 2 deletions backends/p4tools/modules/testgen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@ target_link_libraries(

add_custom_target(
linkp4testgen
# Add some convenience links for invoking p4testgen.
# TODO: How to best handle includes?
# Add some convenience links for invoking P4Testgen.
COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_BINARY_DIR}/p4testgen ${P4C_BINARY_DIR}/p4testgen
COMMAND ${CMAKE_COMMAND} -E make_directory ${P4C_BINARY_DIR}/p4include &&
${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/p4include/*.p4 ${P4C_BINARY_DIR}/p4include
COMMAND ${CMAKE_COMMAND} -E create_symlink ${P4C_BINARY_DIR}/p4include ${CMAKE_CURRENT_BINARY_DIR}/p4include
DEPENDS update_includes
COMMENT "Setting P4Testgen include and binary symlinks."
)

add_dependencies(p4testgen linkp4testgen)
Expand Down
14 changes: 14 additions & 0 deletions backends/p4tools/modules/testgen/p4include/testgen.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef _TOOLS_TESTGEN_P4_
#define _TOOLS_TESTGEN_P4_

/// Add @param check as a necessary path constraint for all subsequent executions in the program.
/// Enabled by default, unless `--disable-assumption-mode` is toggled.
extern void testgen_assume(in bool assumption);

/// Add @param check as a necessary path constraint for all subsequent executions in the program.
/// Enabled by default, unless `--disable-assumption-mode` is toggled.
/// If `--assertion-mode` is toggled, P4Testgen will not apply the condition to the path
/// constraints, but instead will try to only generate tests that violate this assumption.
extern void testgen_assert(in bool assumption);

#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <v1model.p4>
#include <testgen.p4>

header ethernet_t {
bit<48> dst_addr;
Expand All @@ -19,11 +20,6 @@ struct Headers {

struct Meta {}

// Custom extern definitions.
extern void testgen_assert(in bool check);
extern void testgen_assume(in bool check);


parser p(packet_in pkt, out Headers h, inout Meta meta, inout standard_metadata_t stdmeta) {
state start {
pkt.extract(h.eth_hdr);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <v1model.p4>
#include <testgen.p4>

header ethernet_t {
bit<48> dst_addr;
Expand All @@ -19,11 +20,6 @@ struct Headers {

struct Meta {}

// Custom extern definitions.
extern void testgen_assert(in bool check);
extern void testgen_assume(in bool check);


parser p(packet_in pkt, out Headers h, inout Meta meta, inout standard_metadata_t stdmeta) {
state start {
pkt.extract(h.eth_hdr);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <v1model.p4>
#include <testgen.p4>

header ethernet_t {
bit<48> dst_addr;
Expand All @@ -19,11 +20,6 @@ struct Headers {

struct Meta {}

// Custom extern definitions.
extern void testgen_assert(in bool check);
extern void testgen_assume(in bool check);


parser p(packet_in pkt, out Headers h, inout Meta meta, inout standard_metadata_t stdmeta) {
state start {
pkt.extract(h.eth_hdr);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <v1model.p4>
#include <testgen.p4>

header ethernet_t {
bit<48> dst_addr;
Expand All @@ -19,11 +20,6 @@ struct Headers {

struct Meta {}

// Custom extern definitions.
extern void testgen_assert(in bool check);
extern void testgen_assume(in bool check);


parser p(packet_in pkt, out Headers h, inout Meta meta, inout standard_metadata_t stdmeta) {
state start {
pkt.extract(h.eth_hdr);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <v1model.p4>
#include <testgen.p4>

header ethernet_t {
bit<48> dst_addr;
Expand All @@ -19,11 +20,6 @@ struct Headers {

struct Meta {}

// Custom extern definitions.
extern void testgen_assert(in bool check);
extern void testgen_assume(in bool check);


parser p(packet_in pkt, out Headers h, inout Meta meta, inout standard_metadata_t stdmeta) {
state start {
pkt.extract(h.eth_hdr);
Expand Down

0 comments on commit 14a64e4

Please sign in to comment.