Skip to content

Commit

Permalink
Add test program to verify compile-time error if no type in for-in lo…
Browse files Browse the repository at this point in the history
…op (#4812)

Signed-off-by: Andy Fingerhut <[email protected]>
  • Loading branch information
jafingerhut authored Jul 18, 2024
1 parent ad161b2 commit 0dc923d
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
91 changes: 91 additions & 0 deletions testdata/p4_16_errors/loop3-err.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
Copyright 2024 Andy Fingerhut
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>

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

struct metadata_t {
}

struct headers_t {
ethernet_t ethernet;
}

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

control ingressImpl(inout headers_t hdr,
inout metadata_t meta,
inout standard_metadata_t stdmeta)
{
bit<8> n = 0;
bit<8> i = 20;
apply {
for (i in 1..6) {
n = n + i;
}
hdr.ethernet.srcAddr[15:8] = n;
hdr.ethernet.srcAddr[7:0] = i;
stdmeta.egress_spec = 1;
}
}

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

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

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

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

V1Switch(parserImpl(),
verifyChecksum(),
ingressImpl(),
egressImpl(),
updateChecksum(),
deparserImpl()) main;
4 changes: 4 additions & 0 deletions testdata/p4_16_errors_outputs/loop3-err.p4-stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
loop3-err.p4(51):syntax error, unexpected IN
for (i in
^^
[--Werror=overlimit] error: 1 errors encountered, aborting compilation

0 comments on commit 0dc923d

Please sign in to comment.