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

[P4Testgen] Add a rudimentary P4Testgen benchmark with via GTest. #4475

Merged
merged 2 commits into from
Mar 2, 2024

Conversation

fruffy
Copy link
Collaborator

@fruffy fruffy commented Feb 27, 2024

Generate 1000 P4Testgen tests for the fabric P4 program. This should take around 30 seconds.
GTest is not really intended for this but it seems to work well enough.

@fruffy fruffy changed the title Add a rudimentary P4Testgen benchmark with via GTest. [P4Testgen] Add a rudimentary P4Testgen benchmark with via GTest. Feb 27, 2024
@fruffy fruffy added the p4tools Topics related to the P4Tools back end label Feb 27, 2024
@fruffy fruffy force-pushed the fruffy/benchmark branch 3 times, most recently from 349708c to 29822d3 Compare February 27, 2024 21:11
@fruffy fruffy marked this pull request as ready for review February 27, 2024 21:15
@fruffy
Copy link
Collaborator Author

fruffy commented Feb 27, 2024

@asl This can be another benchmarking data point. P4Testgen makes heavy use of visitors of all forms and should be affected by many of these optimizations.

@asl
Copy link
Contributor

asl commented Feb 27, 2024

@asl This can be another benchmarking data point. P4Testgen makes heavy use of visitors of all forms and should be affected by many of these optimizations.

Yes, saw this PR. Will certainly compare

@fruffy
Copy link
Collaborator Author

fruffy commented Feb 27, 2024

Yes, saw this PR. Will certainly compare

If you can get the framework to build on MacOS, never tried.

@asl
Copy link
Contributor

asl commented Feb 27, 2024

Yes, saw this PR. Will certainly compare

If you can get the framework to build on MacOS, never tried.

I can build p4test now. Let me check if I can run this :)

auto compilerOptions = CompilerOptions();
compilerOptions.target = "bmv2";
compilerOptions.arch = "v1model";
auto fabricFile = std::filesystem::path(__FILE__).replace_filename(
Copy link
Contributor

@asl asl Feb 27, 2024

Choose a reason for hiding this comment

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

Maybe there is a way to grab absolute filepath? Otherwise running from "wrong" directory by hands yields:

Note: Google Test filter = P4TestgenBenchmark.SuccessfullyGenerate1000Tests
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from P4TestgenBenchmark
[ RUN      ] P4TestgenBenchmark.SuccessfullyGenerate1000Tests
/Users/asl/Projects//p4c/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/../../../../../../../../testdata/p4_16_samples/fabric_20190420/fabric.p4:37:10: fatal error: 'core.p4' file not found
#include <core.p4>
         ^~~~~~~~~
1 error generated.
/Users/asl/Projects//p4c/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/../../../../../../../../testdata/p4_16_samples/fabric_20190420/include/control/filtering.p4(24):syntax error, unexpected IDENTIFIER "standard_metadata_t"
                   inout standard_metadata_t
                         ^^^^^^^^^^^^^^^^^^^
[--Werror=I/O error] error: Preprocessor returned exit code 256; aborting compilation
[--Werror=overlimit] error: 2 errors encountered, aborting compilation
Internal error: bad_optional_access
============ Timers ============
Total: 0 ms
[       OK ] P4TestgenBenchmark.SuccessfullyGenerate1000Tests (29 ms)
[----------] 1 test from P4TestgenBenchmark (29 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (29 ms total)
[  PASSED  ] 1 test.

Note that test passed even when it failed... :)

Copy link
Contributor

@asl asl Feb 27, 2024

Choose a reason for hiding this comment

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

Oh, I was mistaken, it's the include path issue, not the input. Looks like these are not provided. I had to run it like this:

env P4C_16_INCLUDE_PATH=p4include ./backends/p4tools/modules/testgen/testgen-gtest

Copy link
Contributor

Choose a reason for hiding this comment

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

Here we go:

Note: Google Test filter = P4TestgenBenchmark.SuccessfullyGenerate1000Tests
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from P4TestgenBenchmark
[ RUN      ] P4TestgenBenchmark.SuccessfullyGenerate1000Tests
/Users/asl/Projects//p4c/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/../../../../../../../../testdata/p4_16_samples/fabric_20190420/fabric.p4(84): [--Wwarn=invalid_header] warning: accessing a field of a potentially invalid header hdr.gtpu_ipv4
        spgw_ingress.apply(hdr.gtpu_ipv4, hdr.gtpu_udp, hdr.gtpu,
                           ^^^^^^^^^^^^^
warning: Ingress parser exception handler not fully implemented
============ Timers ============
Total: 31454 ms
branch_selection: 0 ms (0.00 % of parent)
backend: 1602 ms (5.09 % of parent)
z3: 8069 ms (25.65 % of parent)
	z3.getModel: 2045 ms (25.34 % of parent)
	z3.checkSat: 4507 ms (55.86 % of parent)
step: 17234 ms (54.79 % of parent)
[       OK ] P4TestgenBenchmark.SuccessfullyGenerate1000Tests (32215 ms)
[----------] 1 test from P4TestgenBenchmark (32215 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (32215 ms total)
[  PASSED  ] 1 test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I also need to add the include paths of the compiler here. The path is definitely awkward, maybe there is a way to add a compiler base path to the gtest utilities.

Copy link
Contributor

@asl asl left a comment

Choose a reason for hiding this comment

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

Definitely looks better now!

@fruffy fruffy added this pull request to the merge queue Mar 2, 2024
Merged via the queue into main with commit c94c0dc Mar 2, 2024
17 checks passed
@fruffy fruffy deleted the fruffy/benchmark branch March 2, 2024 20:13
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.

2 participants