Skip to content

Commit

Permalink
Add new test program to exercise latest code changes
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Fingerhut <[email protected]>
  • Loading branch information
jafingerhut committed Oct 21, 2024
1 parent 606300e commit 6bcb614
Show file tree
Hide file tree
Showing 4 changed files with 304 additions and 0 deletions.
130 changes: 130 additions & 0 deletions testdata/p4_16_errors/actions-with-duplicate-control-plane-names1.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
Copyright 2024 Cisco Systems, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include <core.p4>
#include <v1model.p4>

typedef bit<48> EthernetAddress;

header ethernet_t {
EthernetAddress dstAddr;
EthernetAddress srcAddr;
bit<16> etherType;
}

struct headers_t {
ethernet_t ethernet;
}

struct metadata_t {
/*
bit<4> a;
bit<4> b;
*/
}

parser parserImpl(
packet_in pkt,
out headers_t hdr,
inout metadata_t meta,
inout standard_metadata_t stdmeta)
{
state start {
pkt.extract(hdr.ethernet);
transition accept;
}
}

control verifyChecksum(
inout headers_t hdr,
inout metadata_t meta)
{
apply { }
}

action foo1() {
}

@name("foo2")
action bar() {
}

control ingressImpl(
inout headers_t hdr,
inout metadata_t meta,
inout standard_metadata_t stdmeta)

{
bit<8> tmp1;
bit<8> tmp2;

// Action a1's control plane name should conflict with the name of
// top-level action foo1, and cause a compile-time error message,
// if you enable P4Info file generation.
@name(".foo1") action a1 (bit<8> x, bit<8> y) { tmp1 = x; tmp2 = y; }

// Action a2's control plane name should conflict with the control
// plane name of top-level action bar, and cause a compile-time
// error message, if you enable P4Info file generation.
@name(".foo2") action a2 (bit<8> x, bit<8> y) { tmp1 = x; tmp2 = y; }

table t1 {
actions = { NoAction; a1; a2; foo1; bar; }
key = { hdr.ethernet.etherType: exact; }
default_action = NoAction();
size = 512;
}
apply {
tmp1 = hdr.ethernet.srcAddr[7:0];
tmp2 = hdr.ethernet.dstAddr[7:0];
t1.apply();
// This is here simply to ensure that the compiler cannot
// optimize away the effects of t1 and t2, which can only
// assign values to variables tmp1 and tmp2.
hdr.ethernet.etherType = (bit<16>) (tmp1 - tmp2);
}
}

control egressImpl(
inout headers_t hdr,
inout metadata_t meta,
inout standard_metadata_t stdmeta)
{
apply { }
}

control updateChecksum(
inout headers_t hdr,
inout metadata_t meta)
{
apply { }
}

control deparserImpl(
packet_out pkt,
in headers_t hdr)
{
apply {
pkt.emit(hdr.ethernet);
}
}

V1Switch(parserImpl(),
verifyChecksum(),
ingressImpl(),
egressImpl(),
updateChecksum(),
deparserImpl()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include <core.p4>
#define V1MODEL_VERSION 20180101
#include <v1model.p4>

typedef bit<48> EthernetAddress;
header ethernet_t {
EthernetAddress dstAddr;
EthernetAddress srcAddr;
bit<16> etherType;
}

struct headers_t {
ethernet_t ethernet;
}

struct metadata_t {
}

parser parserImpl(packet_in pkt, out headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) {
state start {
pkt.extract<ethernet_t>(hdr.ethernet);
transition accept;
}
}

control verifyChecksum(inout headers_t hdr, inout metadata_t meta) {
apply {
}
}

action foo1() {
}
@name("foo2") action bar() {
}
control ingressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) {
bit<8> tmp1;
bit<8> tmp2;
@name(".foo1") action a1(bit<8> x, bit<8> y) {
tmp1 = x;
tmp2 = y;
}
@name(".foo2") action a2(bit<8> x, bit<8> y) {
tmp1 = x;
tmp2 = y;
}
table t1 {
actions = {
NoAction();
a1();
a2();
foo1();
bar();
}
key = {
hdr.ethernet.etherType: exact @name("hdr.ethernet.etherType");
}
default_action = NoAction();
size = 512;
}
apply {
tmp1 = hdr.ethernet.srcAddr[7:0];
tmp2 = hdr.ethernet.dstAddr[7:0];
t1.apply();
hdr.ethernet.etherType = (bit<16>)(tmp1 - tmp2);
}
}

control egressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) {
apply {
}
}

control updateChecksum(inout headers_t hdr, inout metadata_t meta) {
apply {
}
}

control deparserImpl(packet_out pkt, in headers_t hdr) {
apply {
pkt.emit<ethernet_t>(hdr.ethernet);
}
}

V1Switch<headers_t, metadata_t>(parserImpl(), verifyChecksum(), ingressImpl(), egressImpl(), updateChecksum(), deparserImpl()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include <core.p4>
#define V1MODEL_VERSION 20180101
#include <v1model.p4>

typedef bit<48> EthernetAddress;
header ethernet_t {
EthernetAddress dstAddr;
EthernetAddress srcAddr;
bit<16> etherType;
}

struct headers_t {
ethernet_t ethernet;
}

struct metadata_t {
}

parser parserImpl(packet_in pkt, out headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) {
state start {
pkt.extract(hdr.ethernet);
transition accept;
}
}

control verifyChecksum(inout headers_t hdr, inout metadata_t meta) {
apply {
}
}

action foo1() {
}
@name("foo2") action bar() {
}
control ingressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) {
bit<8> tmp1;
bit<8> tmp2;
@name(".foo1") action a1(bit<8> x, bit<8> y) {
tmp1 = x;
tmp2 = y;
}
@name(".foo2") action a2(bit<8> x, bit<8> y) {
tmp1 = x;
tmp2 = y;
}
table t1 {
actions = {
NoAction;
a1;
a2;
foo1;
bar;
}
key = {
hdr.ethernet.etherType: exact;
}
default_action = NoAction();
size = 512;
}
apply {
tmp1 = hdr.ethernet.srcAddr[7:0];
tmp2 = hdr.ethernet.dstAddr[7:0];
t1.apply();
hdr.ethernet.etherType = (bit<16>)(tmp1 - tmp2);
}
}

control egressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_metadata_t stdmeta) {
apply {
}
}

control updateChecksum(inout headers_t hdr, inout metadata_t meta) {
apply {
}
}

control deparserImpl(packet_out pkt, in headers_t hdr) {
apply {
pkt.emit(hdr.ethernet);
}
}

V1Switch(parserImpl(), verifyChecksum(), ingressImpl(), egressImpl(), updateChecksum(), deparserImpl()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
actions-with-duplicate-control-plane-names1.p4(77): [--Werror=duplicate] error: .foo1: conflicting control plane name: foo1
@name(".foo1") action a1 (bit<8> x, bit<8> y) { tmp1 = x; tmp2 = y; }
^^
actions-with-duplicate-control-plane-names1.p4(58)
action foo1() {
^^^^

0 comments on commit 6bcb614

Please sign in to comment.