-
Notifications
You must be signed in to change notification settings - Fork 91
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
Dead code in dash_pipeline.p4 PNA version #399
Comments
@marian-pritsak please take a look, thanks |
@fruffy Thanks for reporting this. I would like to understand how you ran this test and if it might be something we can incorporate into the DASH CI/CD pipeline? In DASH we use a p4c docker container which is a slimmed-down version of p4lang/p4c derived by taking only the one bmv2 backend (to keep the image smaller). It would not be too hard to add in the p4testgen backend and call it upon every build, if it would catch dead code like this. Can you provide instructions on how you ran p4testgen to expose this dead code? Thanks! |
P4Testgen supports monitoring of statement coverage (and other P4 nodes) when generating tests. With that we can also implement different types of test-case-generation strategies to produce more targeted tests. For example,
will try to cover all statements in the program and then stop once it has achieved that. For this particular program achieving full coverage was not possible and test-case-generation did not terminate. We could use P4Testgen to check that we can cover everything but that is subject to a bunch of limitations:
|
In parallel, I have been working on a tool that can provably detect this type of dead-code (and other missing optimizations). https://github.com/fruffy/flay |
|
P4Testgen will generate tests until there are no more paths. For programs such as The best solution is probably to expect full statement coverage within a reasonable amount of tests (maybe a thousand?). But since the algorithm is still a heuristic that could also fail if the program changes. That is something we would have to try out. |
Just wanted to chime in to say that this is awesome! |
Any HW can use this tool to exercise the paths - thank you! |
Not sure if I understand correctly. Are you asking about ways to generate tests that could exercise the paths we try to cover? Unfortunately, the DPDK PNA target does not yet have a testing pipeline, but we are working on one. |
hi @fruffy - we were just looking and this (and grateful for the contribution) in the DASH Community Call :) |
Has this been confirmed or is there an easy fix to this? I am maintaining a PR on P4C which contributes a snapshot of the dash program as a compiler test. I would like to contribute the version without dead code. Mostly for selfish reasons, we are planning to run testing benchmarks on this particular version. |
@marian-pritsak Have you had a chance to look at this? Thanks. |
@jfingerh I took a closer look at this and I have a suspicion this is actually an artifact of translating DASH/dash-pipeline/bmv2/dash_nvgre.p4 Line 36 in 1756b49
if s and expressions which are later added up in DASH/dash-pipeline/bmv2/dash_nvgre.p4 Line 55 in 1756b49
So, we could change the code to remove all the IPv4 components because per @fruffy 's observations, this is never called for IPv4 case. I'd want to leave a comment in the code mentioning it would need to be revised to handle IPv4. Thoughts? |
So my attempt in writing the version of the code with Any tool that checks "line coverage" will get 100% coverage for the original, but not my modified version. A tool that somehow decided to check that all possible values of sub-expressions like If there is dead code in my translated version, I believe there are also "dead sub-expressions" in the original code that could be removed. |
Agreed. @marian-pritsak could you please comment? Thanks. |
I would also guess that in future versions of the DASH P4 code, the branches that are currently dead code could easily become live code again, if additional packet handling cases are added in other parts of the program executed before this code is executed. |
Is this version local or part of a PR? |
It is a few lines earlier than the link to a line of code you gave in the original issue, here: https://github.com/sonic-net/DASH/blob/main/dash-pipeline/bmv2/dash_nvgre.p4#L35-L42 That code is only compiled if you #define the symbol TARGET_BMV2_V1MODEL, whereas the code with the if statement version is only compiled if you #define the symbol TARGET_DPDK_PNA. The reason for the #ifdef is that as of 2023-Apr when I created the TARGET_DPDK_PNA version, p4c-dpdk did not support multiplication of 2 run-time variables (and probably still does not). The p4c BMv2 back end does not fully support if statements within action bodies. If you want to experiment with the TARGET_BMV2_V1MODEL version of the code with p4testgen, I would guess that you need to define that symbol, and NOT define TARGET_DPDK_PNA, and then you will get a different version of the P4 program. |
Oh, I see what you mean. Yes, for the v1model version we cover all statements, but not for the pna version because of the way the code is structured. In some case that exposed a dormant issue. |
Right. There are I think Verilog coverage tools that go more detailed than line coverage, and check for something like "subexpression coverage", that might expose the "dead cases" in the TARGET_BMV2_V1MODEL version of the code. There is probably a widely-accepted name for what I am calling "subexpression coverage", but if so, I do not know that name. I asked one hardware verification person for names of other kinds of code coverage, and he mentioned these:
I do not have definitions of all of those, but the Wikipedia page on code coverage describes a few others besides function and line coverage with examples: https://en.wikipedia.org/wiki/Code_coverage I mention these not because I think p4testgen ought to do all of these things, by the way. Mainly just for me looking for the right widely-used terms (if any) for the more detailed kinds of coverage that have been implemented for other programming languages. |
@fruffy We discussed at length in today's WG meeting (myself, @jafingerhut, @marian-pritsak) and the consensus was:
All this means for you is you can decide how to handle the dead-code detection in your use of DASH code as a test case. Perhaps you want to "expect" this and not "hard-fail." We hope you do decide to use DASH code as a test case. In fact at some point we could add p4testgen to our CI pipeline. Let us know how the effort described in #399 (comment) proceeds. We appreciate your bringing this to our attention, it resulted in better awareness and demonstrates the power of your tool. I am closing this issue, but feel free to add to the conversation thread here. |
Thanks for keeping me posted on this! I will merge a patched version to the p4c repository. |
@r12f for visibility |
I ran some coverage benchmarks on the
dash_pipeline.p4
program using P4Testgen and I noticed that there is some dead code in the dash PNA pipeline.In the
nrve_encap
action there is this check:https://github.com/sonic-net/DASH/blob/main/dash-pipeline/bmv2/dash_nvgre.p4#L48
However, this code can never be executed.
nrve_encap
is only called whenroute_service_tunnel
was previously executed. Androute_service_tunnel
always sets the IPv4 header invalid here when it calls service_tunnel_encode.Is this because
dash_pipeline.p4
is not complete yet? What is the intended behavior?The text was updated successfully, but these errors were encountered: