Skip to content

[bmv2] path fixes for finding BMv2 #5228

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

Merged
merged 2 commits into from
Apr 13, 2025
Merged

Conversation

grg
Copy link
Contributor

@grg grg commented Apr 10, 2025

Two changes for finding BMv2:

  • Remove "build" from the search paths. BMv2 targets are built in behavioral-model/targets/... and not in behavioral-model/build/targets/...
  • Correct search path variable name in pna_nic error message.

Is there any env where BMv2 targets are built in build/targets? The README.md instructions always build in targets.

@github-actions github-actions bot added the bmv2 Topics related to BMv2 or v1model label Apr 10, 2025
@grg grg force-pushed the gleng/find_bmv2_fix branch from 0f56289 to b50439c Compare April 10, 2025 19:57
@jafingerhut
Copy link
Contributor

It looks like these are paths searching for simple_switch and/or simple_switch_grpc executable programs on the system where p4c is being built?

And I guess the purpose is to run those programs for the subset of backend BMv2 tests that run the BMv2 software switch, e.g. the BMv2 P4 programs that have STF tests checked in?

I often run such tests on Ubuntu Linux systems that I install BMv2 and p4c from source, but I also always install the simple_switch and simple_switch_grpc executables in my /usr/local/bin directory, so might never have run the tests in a scenario where the paths you are changing here failed to find those executables.

@grg
Copy link
Contributor Author

grg commented Apr 10, 2025

It looks like these are paths searching for simple_switch and/or simple_switch_grpc executable programs on the system where p4c is being built?

And I guess the purpose is to run those programs for the subset of backend BMv2 tests that run the BMv2 software switch, e.g. the BMv2 P4 programs that have STF tests checked in?

I often run such tests on Ubuntu Linux systems that I install BMv2 and p4c from source, but I also always install the simple_switch and simple_switch_grpc executables in my /usr/local/bin directory, so might never have run the tests in a scenario where the paths you are changing here failed to find those executables.

Yes, I believe this is for the case where the programs are compiled but not installed. Potentially useful for developers who don't want to have to do an install each time they rebuild the model 🙂

The cmake find_program documentation describes what additional paths are searched, in addition to those passed in via the PATHS parameter. Since we don't pass in parameters include NO_DEFAULT_PATH and NO_SYSTEM_ENVIRONMENT_PATH, it ends up searching the directories set in your environment.

@@ -1,7 +1,7 @@
set(BMV2_SIMPLE_SWITCH_SEARCH_PATHS
${CMAKE_INSTALL_PREFIX}/bin
${P4C_SOURCE_DIR}/../behavioral-model/build/targets/simple_switch
${P4C_SOURCE_DIR}/../../behavioral-model/build/targets/simple_switch)
${P4C_SOURCE_DIR}/../behavioral-model/targets/simple_switch
Copy link
Collaborator

Choose a reason for hiding this comment

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

Kind of hacky but not worse than before...
These path hints should probably be an option you can pass to CMake.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm happy to clean this up a little before merging.

Here are a couple of possibilities for how change the set statement:

set(BMV2_SIMPLE_SWITCH_SEARCH_PATHS
  ${CMAKE_INSTALL_PREFIX}/bin)
  ${BMV2_SOURCE_DIR}/targets/simple_switch)

set(BMV2_SIMPLE_SWITCH_SEARCH_PATHS
  ${CMAKE_INSTALL_PREFIX}/bin)
if(DEFINED BMV2_SOURCE_DIR)
  set(BMV2_SIMPLE_SWITCH_SEARCH_PATHS
    ${BMV2_SIMPLE_SWITCH_SEARCH_PATHS}
    ${BMV2_SOURCE_DIR}/targets/simple_switch )
endif()

The first is simple and easy to read, but it has the downside of searching /targets/simple_switch if BMV2_SOURCE_DIR is set. The second is quite a bit more verbose but it avoids adding a phantom search directory when BMV2_SOURCE_DIR it not set.

Do you have a preference? Or do you have an alternative style suggestion?

Copy link
Collaborator

@fruffy fruffy Apr 12, 2025

Choose a reason for hiding this comment

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

Second option sounds good to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've pushed a new commit that implements this.

grg added 2 commits April 12, 2025 17:38
Two changes for finding BMv2:
 - Remove "build" from the search paths. BMv2 targets are built in
   behavioral-model/targets/... and not in
   behavioral-model/build/targets/...
 - Correct search path variable name in pna_nic error message.

Signed-off-by: Glen Gibb <gleng@ai-fabrics.com>
Look in BMV2_SOURCE_DIR/targets/... for BMv2 programs if the variable is
set.
@grg grg force-pushed the gleng/find_bmv2_fix branch from b50439c to 07dc086 Compare April 13, 2025 00:38
@grg grg marked this pull request as ready for review April 13, 2025 17:03
@grg grg added this pull request to the merge queue Apr 13, 2025
Merged via the queue into p4lang:main with commit 4f52d3e Apr 13, 2025
20 of 21 checks passed
@grg grg deleted the gleng/find_bmv2_fix branch April 13, 2025 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bmv2 Topics related to BMv2 or v1model
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants