Skip to content

Commit

Permalink
Added testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDodd committed Apr 4, 2024
1 parent e34ef1d commit 101e00d
Show file tree
Hide file tree
Showing 13 changed files with 442 additions and 3 deletions.
31 changes: 31 additions & 0 deletions testdata/p4_16_samples/forloop2.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <core.p4>
control generic<M>(inout M m);
package top<M>(generic<M> c);

header t1 {
bit<64> v;
}

struct headers_t {
t1 t1;
}

bit<64> _popcount(in bit<64> val) {
bit<64> n = 0;
bit<64> v = val;
for (bit<64> popcnti in 1 .. 64w63) {
if (v == 0)
return n;
n = n + 1;
v = v & (v - 1);
}
return n;
}

control c(inout headers_t hdrs) {
apply {
hdrs.t1.v = _popcount(hdrs.t1.v);
}
}

top(c()) main;
37 changes: 37 additions & 0 deletions testdata/p4_16_samples/forloop3.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <core.p4>
control generic<M>(inout M m);
package top<M>(generic<M> c);

extern T foo<T>(in T x);

header t1 {
bit<32> x;
}

struct headers_t {
t1 t1;
}

control c(inout headers_t hdrs) {
action a0(bit<8> x, bit<8> y) {
bit<8> idx = 255;
for (bit<8> i1 in 0 .. x) {
for (bit<8> j in i1 .. y) {
idx = foo(j);
if (idx == 255)
break;
}
}
}

table test {
key = { hdrs.t1.x: exact; }
actions = { a0; }
}

apply {
test.apply();
}
}

top(c()) main;
3 changes: 0 additions & 3 deletions testdata/p4_16_samples_outputs/forloop1.p4-stderr
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
forloop1.p4(24): [--Wwarn=uninitialized_use] warning: v.x may be uninitialized
hdrs.head.f1 = hdrs.head.f1 + v.x;
^^^
31 changes: 31 additions & 0 deletions testdata/p4_16_samples_outputs/forloop2-first.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <core.p4>

control generic<M>(inout M m);
package top<M>(generic<M> c);
header t1 {
bit<64> v;
}

struct headers_t {
t1 t1;
}

bit<64> _popcount(in bit<64> val) {
bit<64> n = 64w0;
bit<64> v = val;
for (bit<64> popcnti in 64w1 .. 64w63) {
if (v == 64w0) {
return n;
}
n = n + 64w1;
v = v & v + 64w18446744073709551615;
}
return n;
}
control c(inout headers_t hdrs) {
apply {
hdrs.t1.v = _popcount(hdrs.t1.v);
}
}

top<headers_t>(c()) main;
43 changes: 43 additions & 0 deletions testdata/p4_16_samples_outputs/forloop2-frontend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <core.p4>

control generic<M>(inout M m);
package top<M>(generic<M> c);
header t1 {
bit<64> v;
}

struct headers_t {
t1 t1;
}

control c(inout headers_t hdrs) {
@name("c.hasReturned") bool hasReturned;
@name("c.retval") bit<64> retval;
@name("c.n") bit<64> n_0;
@name("c.v") bit<64> v_0;
@name("c.popcnti") bit<64> popcnti_0;
apply {
hasReturned = false;
n_0 = 64w0;
for (popcnti_0 in 64w1 .. 64w63) {
if (v_0 == 64w0) {
hasReturned = true;
retval = n_0;
}
if (hasReturned) {
;
} else {
n_0 = n_0 + 64w1;
v_0 = v_0 & v_0 + 64w18446744073709551615;
}
}
if (hasReturned) {
;
} else {
retval = n_0;
}
hdrs.t1.v = retval;
}
}

top<headers_t>(c()) main;
88 changes: 88 additions & 0 deletions testdata/p4_16_samples_outputs/forloop2-midend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include <core.p4>

control generic<M>(inout M m);
package top<M>(generic<M> c);
header t1 {
bit<64> v;
}

struct headers_t {
t1 t1;
}

control c(inout headers_t hdrs) {
@name("c.hasReturned") bool hasReturned;
@name("c.retval") bit<64> retval;
@name("c.n") bit<64> n_0;
@name("c.v") bit<64> v_0;
@name("c.popcnti") bit<64> popcnti_0;
@hidden action forloop2l18() {
hasReturned = true;
retval = n_0;
}
@hidden action forloop2l19() {
n_0 = n_0 + 64w1;
v_0 = v_0 & v_0 + 64w18446744073709551615;
}
@hidden action forloop2l14() {
hasReturned = false;
n_0 = 64w0;
}
@hidden action forloop2l22() {
retval = n_0;
}
@hidden action forloop2l27() {
hdrs.t1.v = retval;
}
@hidden table tbl_forloop2l14 {
actions = {
forloop2l14();
}
const default_action = forloop2l14();
}
@hidden table tbl_forloop2l18 {
actions = {
forloop2l18();
}
const default_action = forloop2l18();
}
@hidden table tbl_forloop2l19 {
actions = {
forloop2l19();
}
const default_action = forloop2l19();
}
@hidden table tbl_forloop2l22 {
actions = {
forloop2l22();
}
const default_action = forloop2l22();
}
@hidden table tbl_forloop2l27 {
actions = {
forloop2l27();
}
const default_action = forloop2l27();
}
apply {
tbl_forloop2l14.apply();
for (popcnti_0 in 64w1 .. 64w63) {
if (v_0 == 64w0) {
tbl_forloop2l18.apply();
}
if (hasReturned) {
;
} else {
tbl_forloop2l19.apply();
}
}
if (hasReturned) {
;
} else {
tbl_forloop2l22.apply();
}
tbl_forloop2l27.apply();
}
}

top<headers_t>(c()) main;
31 changes: 31 additions & 0 deletions testdata/p4_16_samples_outputs/forloop2.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <core.p4>

control generic<M>(inout M m);
package top<M>(generic<M> c);
header t1 {
bit<64> v;
}

struct headers_t {
t1 t1;
}

bit<64> _popcount(in bit<64> val) {
bit<64> n = 0;
bit<64> v = val;
for (bit<64> popcnti in 1 .. 64w63) {
if (v == 0) {
return n;
}
n = n + 1;
v = v & v - 1;
}
return n;
}
control c(inout headers_t hdrs) {
apply {
hdrs.t1.v = _popcount(hdrs.t1.v);
}
}

top(c()) main;
11 changes: 11 additions & 0 deletions testdata/p4_16_samples_outputs/forloop2.p4-stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
forloop2.p4(17): [--Wwarn=uninitialized_use] warning: v may be uninitialized
if (v == 0)
^
forloop2.p4(20): [--Wwarn=uninitialized_use] warning: v may be uninitialized
v = v & (v - 1);
^
forloop2.p4(20): [--Wwarn=uninitialized_use] warning: v may be uninitialized
v = v & (v - 1);
^
[--Wwarn=uninitialized_use] warning: retval may be uninitialized
[--Wwarn=uninitialized_use] warning: retval may be uninitialized
41 changes: 41 additions & 0 deletions testdata/p4_16_samples_outputs/forloop3-first.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <core.p4>

control generic<M>(inout M m);
package top<M>(generic<M> c);
extern T foo<T>(in T x);
header t1 {
bit<32> x;
}

struct headers_t {
t1 t1;
}

control c(inout headers_t hdrs) {
action a0(bit<8> x, bit<8> y) {
bit<8> idx = 8w255;
for (bit<8> i1 in 8w0 .. x) {
for (bit<8> j in i1 .. y) {
idx = foo<bit<8>>(j);
if (idx == 8w255) {

}
}
}
}
table test {
key = {
hdrs.t1.x: exact @name("hdrs.t1.x");
}
actions = {
a0();
@defaultonly NoAction();
}
default_action = NoAction();
}
apply {
test.apply();
}
}

top<headers_t>(c()) main;
45 changes: 45 additions & 0 deletions testdata/p4_16_samples_outputs/forloop3-frontend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <core.p4>

control generic<M>(inout M m);
package top<M>(generic<M> c);
extern T foo<T>(in T x);
header t1 {
bit<32> x;
}

struct headers_t {
t1 t1;
}

control c(inout headers_t hdrs) {
@name("c.idx") bit<8> idx_0;
@name("c.i1") bit<8> i1_0;
@name("c.j") bit<8> j_0;
@noWarn("unused") @name(".NoAction") action NoAction_1() {
}
@name("c.a0") action a0(@name("x") bit<8> x_1, @name("y") bit<8> y) {
for (i1_0 in 8w0 .. x_1) {
for (j_0 in i1_0 .. y) {
idx_0 = foo<bit<8>>(j_0);
if (idx_0 == 8w255) {

}
}
}
}
@name("c.test") table test_0 {
key = {
hdrs.t1.x: exact @name("hdrs.t1.x");
}
actions = {
a0();
@defaultonly NoAction_1();
}
default_action = NoAction_1();
}
apply {
test_0.apply();
}
}

top<headers_t>(c()) main;
Loading

0 comments on commit 101e00d

Please sign in to comment.