Skip to content
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

Add P4Smith, a random program generator to the P4Tools framework #4182

Merged
merged 2 commits into from
Jun 7, 2024

Conversation

fruffy
Copy link
Collaborator

@fruffy fruffy commented Oct 2, 2023

This is a port of Bludgeon, which has initially been written for Gauntlet.
Bludgeon is a P4 random program generator in the spirit of CSmith. It can generate random programs for p4test, p4c-bm2-ss, p4c-bm2-psa, and for the Tofino compiler.

Porting Bludgeon to the P4Tools framework will make it more extensible and improve its support for P4 targets. The new name of this tool is now P4Smith. This version is simple but can already generate random programs for:

  • v1model1 and psa on BMv2.
  • tna on Tofino 1
  • pna on DPDK
  • Generic programs for p4test

There is currently a lot of code duplication etc happening. That is an artifact of the port. Also this is still a port of graduate student code, so there is a lot of constructs that could be improved. I am hoping that this initial version is enough to build a common platform for a P4 fuzzer.

@fruffy fruffy added the p4tools Topics related to the P4Tools back end label Oct 2, 2023
@fruffy fruffy changed the title [WiP] Add Smith random program generator to the P4Tools framework [WiP] Add random program generator to the P4Tools framework Oct 2, 2023
@vlstill
Copy link
Contributor

vlstill commented Dec 14, 2023

Hi! This looks like quite an interesting idea. Would this allow easily adding target platforms similarly to P4 testgen? What is currently missing for this to be non-WIP?

@fruffy
Copy link
Collaborator Author

fruffy commented Dec 14, 2023

Hi! This looks like quite an interesting idea. Would this allow easily adding target platforms similarly to P4 testgen? What is currently missing for this to be non-WIP?

There is not much work left, you can already generate random programs. I just need to finish the target-specific instantiation to make it possible to produce custom code per target.

@fruffy fruffy force-pushed the fruffy/smith_mutate_emi branch 6 times, most recently from f3e8b01 to 1222914 Compare May 3, 2024 22:59
@fruffy fruffy changed the title [WiP] Add random program generator to the P4Tools framework Add random program generator to the P4Tools framework May 3, 2024
@fruffy fruffy changed the title Add random program generator to the P4Tools framework Add a random program generator to the P4Tools framework May 4, 2024
@fruffy fruffy force-pushed the fruffy/smith_mutate_emi branch 4 times, most recently from 48a1e94 to 5bb3127 Compare May 5, 2024 21:14
@fruffy
Copy link
Collaborator Author

fruffy commented May 5, 2024

Depends on #4650.

@fruffy fruffy marked this pull request as ready for review May 13, 2024 19:22
@fruffy fruffy requested a review from vlstill May 13, 2024 19:22
@fruffy
Copy link
Collaborator Author

fruffy commented May 13, 2024

@asl @ChrisDodd We might be able to use this to fuzz #4562.

@asl
Copy link
Contributor

asl commented May 13, 2024

@fruffy Does it support loop?

@fruffy
Copy link
Collaborator Author

fruffy commented May 13, 2024

@fruffy Does it support loop?

Not yet, this random program generator uses the P4C IR to generate elements. But it could be extended to support loops.

@fruffy fruffy force-pushed the fruffy/smith_mutate_emi branch 2 times, most recently from c8a1660 to 5036177 Compare May 16, 2024 18:43
@fruffy fruffy force-pushed the fruffy/smith_mutate_emi branch 4 times, most recently from 93d7990 to 65ecdb8 Compare May 29, 2024 01:18
@fruffy fruffy changed the title Add a random program generator to the P4Tools framework Add P4Smith, a random program generator to the P4Tools framework Jun 6, 2024
@fruffy
Copy link
Collaborator Author

fruffy commented Jun 6, 2024

@asl @vlstill @jafingerhut Requesting a review on this contribution to the P4Tools framework.

This is getting increasingly hard for me to keep in sync with the compiler changes. I think it makes sense to get the initial version of this fuzzer in, then we can iteratively improve it. There are still many things that should be done here, but a rewrite in bulk is currently impractical for me.

Copy link
Contributor

@jafingerhut jafingerhut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have only reviewed the two README.md files, and they look good. As far as the C++ code, I am happy to try to build it when this is merged in, and try it out a little bit to see whether it generates some random programs for me.

@fruffy
Copy link
Collaborator Author

fruffy commented Jun 7, 2024

I have only reviewed the two README.md files, and they look good. As far as the C++ code, I am happy to try to build it when this is merged in, and try it out a little bit to see whether it generates some random programs for me.

The tool itself also includes some compilation tests. But they are currently disabled because they are producing Compiler BUGs in the current compiler.

@fruffy fruffy added this pull request to the merge queue Jun 7, 2024
Merged via the queue into main with commit 8d6bb9d Jun 7, 2024
17 checks passed
@fruffy fruffy deleted the fruffy/smith_mutate_emi branch June 7, 2024 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p4tools Topics related to the P4Tools back end
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants