-
Notifications
You must be signed in to change notification settings - Fork 449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
For-loop and for-in-loop support for P4Smith #4772
Conversation
3b9f4b8
to
d4e6e20
Compare
I know this might a weird question, but I was wondering why the code snippet above could trigger the following error? Because when I backtraced using GDB, it gives me the following, which is directly related to
The error happened when I executed |
d4e6e20
to
1bf77eb
Compare
It looks like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great that tests were added! Do they work?
One initial round of comments.
57798c9
to
09098e0
Compare
I've been stumbling on how I could properly construct a |
The first problem is that you are trying to build these in the top-level gtest directory. You need to put this in the smith-local test directory. Take a look at the testgen code to see how local gtests are instantiated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there! This is great progress.
backends/p4tools/modules/smith/targets/generic/test/P4Tests.cmake
Outdated
Show resolved
Hide resolved
…ools/modules/smith/util/util.cpp
…es/smith/util/util.h
…ools/modules/smith/common/statements.cpp and backends/p4tools/modules/smith/common/statements.h
…4tools/modules/smith/util/util.h to support more generic for-loop generations
…s in backends/p4tools/modules/smith/common/statements.cpp and backends/p4tools/modules/smith/common/statements.h
…bility should be further investigated and determined
…option) in backends/p4tools/modules/smith/util/util.cpp and backends/p4tools/modules/smith/util/util.h
…tatementOrDeclaration function in declarations.cpp, and add probability for for-loop statement(s) or declaration(s) (albeit the (precise) probability has yet to be determined)
…support for variables of more basic types)
…ns in backends/p4tools/modules/smith/util/util.cpp
…generations in backends/p4tools/modules/smith/common/statements.h and backends/p4tools/modules/smith/common/statements.cpp and ... Delete (and add annotations to consider deleting more) the support I previously added for for-loop generations in backends/p4tools/modules/smith/common/statements.h and backends/p4tools/modules/smith/common/statements.h since they seem to be redundant and useless
…e the probability for assignments or method calls (STATEMENT_ASSIGNMENTORMETHODCALL)
…genForInLoopStatement in backends/p4tools/modules/smith/common/statements.h and backends/p4tools/modules/smith/common/statements.cpp, and ... Add unit tests for for-loop statements in test/gtest/for_loop_test.cpp
… test/gtest/smith_for_loop_test.cpp, and add unit tests for for-in-loops in test/gtest/smith_for_in_loop_test.cpp
…s/modules/smith/util/util.cpp
…n/statements.cpp to make for-loop and for-in-loop statement generations possible, and ... Remove the changes I previously made in backends/p4tools/modules/smith/common/declarations.cpp since they are irrelevant
…ENT_FOR_in generations in backends/p4tools/modules/smith/common/probabilities.h (this modification should be reverted)
…ns in backends/p4tools/modules/smith/common/probabilities.h (this modification should be reverted)
…odules/smith/util/util.cpp, and intentionally insert for-loop and for-in-loop statements within the genBlockStatement function in backends/p4tools/modules/smith/common/statements.cpp (for testing purpose)
…false) with auto *applyBlock = new IR::BlockStatement(statOrDecls), where statOrDecls contains the generated for-loop and for-in-loop statements (that are pushed into statOrDecls before contrusting the block statement) in backends/p4tools/modules/smith/targets/generic/target.cpp 2. Fine-tune the local variables in the genForLoopStatement and genForInLoopStatement functions and temporarily add debugging statements to print out the randomly generated values of those variables (in backends/p4tools/modules/smith/common/statements.cpp) 3. Comment out the stale code in backends/p4tools/modules/smith/util/util.h and backends/p4tools/modules/smith/util/util.cpp
…ement functions in backends/p4tools/modules/smith/common/statements.cpp to 100 to prevent buffer overflow (further caring should be implemented in the near future)
… and backends/p4tools/modules/smith/util/util.h
…b.com> I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 18b5c4b I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 2b75a1a I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 191492c I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: f0113ed I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: b2e51b7 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 3ea729c I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: aa13f35 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: c54a7a9 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: fb447a3 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: ca8f080 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 9027e6e I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 10bb6e0 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: e1b682a I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: b8a00d3 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 0cbf8ce I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: f846b9b I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: a62ac85 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 2a897ee I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 91da15e I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 4a270ee I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: a298b0a I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 7bb07bd I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 00aa376 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 49cbc61 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: b201b92 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: ab75268 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 1bf77eb Signed-off-by: zzmic <100326374+zzmic@users.noreply.github.com>
Signed-off-by: zzmic <100326374+zzmic@users.noreply.github.com>
Signed-off-by: zzmic <100326374+zzmic@users.noreply.github.com>
…ssBlock Signed-off-by: zzmic <100326374+zzmic@users.noreply.github.com>
…n defintion in the main branch Signed-off-by: zzmic <100326374+zzmic@users.noreply.github.com>
…b.com> I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 230a1e5 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 9669bf3 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 52b1794 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 2fb9111 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 56aa342 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 4c05810 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 96fd439 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: fffb38a I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: e2eed93 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 6abf21b I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: fc34177 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 4608659 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: e1b9f97 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 804fc1c I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 5ab308a I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: a608ea7 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: b42b0a5 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 2964fdb I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: e585383 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: e5f4b52 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 9cbfc11 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: ee4bc61 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 7aa57a9 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: ca9feb1 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 15681dd I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: bcfbaa3 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 908d0c7 Signed-off-by: zzmic <100326374+zzmic@users.noreply.github.com>
…smith_for_in_loop_test.cpp and test/gtest/smith_for_loop_test.cpp Signed-off-by: zzmic <100326374+zzmic@users.noreply.github.com>
…test.cpp and test/gtest/smith_for_loop_test.cpp account for Signed-off-by: zzmic <100326374+zzmic@users.noreply.github.com>
…_loop_test.cpp from the top-level gtest directory Signed-off-by: zzmic <100326374+zzmic@users.noreply.github.com>
…p to backends/p4tools/modules/smith/targets/generic/test/ but still need to investigate its correctness Signed-off-by: zzmic <100326374+zzmic@users.noreply.github.com>
Signed-off-by: zzmic <100326374+zzmic@users.noreply.github.com>
…p4tools/modules/smith/targets/generic/test/ by referencing testgen 2. Add a comma in backends/p4tools/modules/smith/common/statements.cpp to fix the formatting Signed-off-by: zzmic <100326374+zzmic@users.noreply.github.com>
….cpp Signed-off-by: zzmic <100326374+zzmic@users.noreply.github.com>
2d48c85
to
76993d5
Compare
…b.com> I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 846ccc3 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: b80b761 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: b004a88 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: e78b3ff I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 0fb60a7 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 05039ce I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: d016970 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: c1501c6 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: bc7f396 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 057d347 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 2798935 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 6aa831d I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: c0d8cf0 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 15f735a I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 7e2f53d I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 5d9b79f I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 69497ab I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 32425f0 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 31b3c44 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: a41ffdd I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 54eb56d I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: fa8da96 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: c09186e I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 867d3ce I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 8e1d827 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: cb92632 I, zzmic <100326374+zzmic@users.noreply.github.com>, hereby add my Signed-off-by to this commit: b6723f3 Signed-off-by: zzmic <100326374+zzmic@users.noreply.github.com>
Great! We can merge this version now. |
This is a draft PR that aims to support for-loop and for-in-loop statement generations for P4Smith.
The approach I took to generate for-loop and for-in-loop statements is to intentionally replace
auto *applyBlock = statementGenerator().genBlockStatement(false)
withauto *applyBlock = new IR::BlockStatement(statOrDecls)
, wherestatOrDecls
contains the generated for-loop and for-in-loop statements (that are pushed intostatOrDecls
before constructing the block statement) in backends/p4tools/modules/smith/targets/generic/target.cpp (https://github.com/zzmic/p4c/blame/8deba9128cd8ba9ce035909824e96e9c8cad0b3c/backends/p4tools/modules/smith/targets/generic/target.cpp#L114-L125). An issue with my current implementation is that although the for-loops and for-in-loops contain block statements, the block statements do not explicitly interact with the loop-control variables.Currently, an abundant amount of
TODO
s (labeled asTODO(zzmic)
s) is in several files under thebackends/p4tools/modules/smith
directory. Most are opinion-based questions that consider what standards should be adopted for each case, such as what the upper bounds of the for-loop/for-in-loop condition should be.The time I tested the build based on the changes I've made (
make check -j$(nproc)
), it failed 512 cases, comprising 10% of the overall test cases. Most failing cases were located attestgen-p4c-bmv2-ptf
with additionalbmv2-ptf/testdata/p4_16_samples/ternary2-bmv2.p4 (Timeout)
andsmith-compile-core (Failed)
.I've attached the (abridged) testing output (which includes the indications of all the failing tests), a sample P4Smith-generated program (with for-loop and for-in-loop statements), and the specific testing output of the case
smith-compile-core
(that I believe my changes directly account for the failure) to this draft PR.failure_on_smith-compile-core.txt
make_check_abridged_output.txt
sample_p4smith_gen_prog_with_for_and_for_in_loops.txt