-
Notifications
You must be signed in to change notification settings - Fork 48
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
Default ROS_HOME and ROS_LOG_DIR env vars in ros2_cpp_test #100
Default ROS_HOME and ROS_LOG_DIR env vars in ros2_cpp_test #100
Conversation
bc07f3a
to
a4a0435
Compare
Your observation regarding TEST_UNDECLARED_OUTPUTS_DIR is spot-on. I would leave Bazel macro as-is, and change the templates (test.py.tpl and pytest_wrapper.py.tpl) directly instead. E.g. test_outputs_dir = os.environ.get('TEST_UNDECLARED_OUTPUTS_DIR')
if test_outputs_dir is None:
test_outputs_dir = os.environ.get('TEST_TMPDIR')
if test_outputs_dir is None:
test_outputs_dir = os.getcwd()
os.environ['ROS_HOME'] = test_outputs_dir
os.environ['ROS_LOG_DIR'] = test_outputs_dir The second The rclcpp test is fine for me. |
81118f5
to
1bfe4fb
Compare
Thanks for the feedback! This was a lot more difficult than I anticipated at first :D I wanted to make the setting up ROS_HOME in tests the default, but it wasn't super straightforward to just default set_up_ament to True to actually use the wrapper for all tests: There are some Anyways, let me know what you think about this new version :) Btw, I checked and when you |
1bfe4fb
to
54908cb
Compare
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.
OK, I think you want to be able to override ROS_HOME and ROS_LOG_DIR, even outside the sandbox.
I think the following would do the job in templates (test.py.tpl and pytest_wrapper.py.tpl):
test_outputs_dir = os.environ.get('TEST_UNDECLARED_OUTPUTS_DIR')
if test_outputs_dir is None:
test_outputs_dir = os.environ.get('TEST_TMPDIR')
if os.environ.get('ROS_HOME') is not None:
os.environ['ROS_HOME'] = test_outputs_dir
if os.environ.get('ROS_LOG_DIR') is not None:
os.environ['ROS_LOG_DIR'] = test_outputs_dir
then you can override the both with e.g. --test_env=ROS_HOME=/my/custom/path
. This looks to me as a very general approach and avoids a lot of other changes in this PR.
Please take a look at my last comment, where I suggested another setup of relevant ROS env vars.
|
This is in the templates now: test_outputs_dir = os.environ.get('TEST_UNDECLARED_OUTPUTS_DIR')
if test_outputs_dir is None:
test_outputs_dir = os.environ.get('TEST_TMPDIR')
if test_outputs_dir:
if 'ROS_HOME' not in os.environ and 'ROS_LOG_DIR' not in os.environ:
os.environ['ROS_HOME'] = test_outputs_dir
os.environ['ROS_LOG_DIR'] = test_outputs_dir (I'm now seeing that the second if should also get the The fallback from What's different is that I set both |
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.
IMO, set_up_ros_home
arg in set_up_ros_home can be avoided. Please take a look at my comments.
ros2/test.py.tpl
Outdated
if 'ROS_HOME' not in os.environ and 'ROS_LOG_DIR' not in os.environ: | ||
os.environ['ROS_HOME'] = test_outputs_dir | ||
os.environ['ROS_LOG_DIR'] = test_outputs_dir |
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.
Why not treat them separately as I suggested?
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.
tbh I think the best way would be to set only ROS_HOME when neither ROS_HOME nor ROS_LOG_DIR is set. But as I said, this isn't the current behavior of the pytest wrapper template, and it seems like a good idea to be consistent with that
I've simplified the wrapper setup to remove the setup_ros_home arg, and changed the tests to make sure each of the three test drivers is verified:
|
Btw, I think something is wrong with the CI setup, maybe you could check?
|
https://github.com/mvukov/rules_ros2/pull/102/files might make problems... I need to investigate this further. The API key for buildbuddy remote cache is stored as a GH secret and it might be that with the new config it's not not available any more -- hence, the error. You can try to revert that in your branch and see if the CI works then. |
Just took a look at https://github.com/aspect-build/rules_js/blob/main/.github/workflows/ci.yaml. I need to fix CI config to work on pull requests from forks w/o github secrets. |
…st-env-for-ros2-cpp-test
ab04275
to
8362e00
Compare
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.
To summarize, this PR addresses 3 issues:
- Test size routing in custom test macros was missing, this is fixed now.
- Without proper handling of ROS_HOME and ROS_LOGGING_DIR, some tests could escape the sandbox. This PR will fix that.
- Besides this, it looks like there are cases when users want to set ROS_HOME and ROS_LOGGING_DIR explicitly in tests. This PR will also allow that.
ros2/cc_defs.bzl
Outdated
@@ -112,7 +114,7 @@ def ros2_cpp_binary(name, ros2_package_name = None, set_up_ament = False, **kwar | |||
""" | |||
_ros2_cpp_exec(cc_binary, name, ros2_package_name, set_up_ament, **kwargs) | |||
|
|||
def ros2_cpp_test(name, ros2_package_name = None, set_up_ament = False, **kwargs): | |||
def ros2_cpp_test(name, ros2_package_name = None, set_up_ament = True, **kwargs): |
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.
IMO, this change is irrelevant to this PR and we can discuss it in a follow up.
ros2/launch.sh.tpl
Outdated
@@ -2,6 +2,13 @@ | |||
|
|||
set -o errexit -o nounset -o pipefail | |||
|
|||
if [ -z "${ROS_HOME:-}" ] && [ -z "${ROS_LOG_DIR:-}" ]; then |
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.
For relation(s) between ROS_HOME and ROS_LOG_DIR folks should read ROS docs, not docs/impl of this repo. Here we should tend to be as general as possible and avoid introducing hidden functionality. Therefore, I'd ask again for separate setup of those two env vars like I explained earlier.
Next to this, this piece of code is only relevant for tests. Thus, this should look like (for better explicitness IMO):
if [[ ! -z "${BAZEL_TEST}" ]]; then
bazel_test_output_dir="${TEST_UNDECLARED_OUTPUTS_DIR:-${TEST_TMPDIR}}"
if [[ -z "${ROS_HOME:-}" ]]; then
export ROS_HOME="${bazel_test_output_dir}"
fi
if [[ -z "${ROS_LOG_DIR:-}" ]]; then
export ROS_LOG_DIR="${bazel_test_output_dir}"
fi
fi
ros2/py_defs.bzl
Outdated
@@ -59,7 +61,7 @@ def ros2_py_binary(name, srcs, main, set_up_ament = False, **kwargs): | |||
""" | |||
_ros2_py_exec(py_binary, name, srcs, main, set_up_ament, **kwargs) | |||
|
|||
def ros2_py_test(name, srcs, main, set_up_ament = False, **kwargs): | |||
def ros2_py_test(name, srcs, main, set_up_ament = True, **kwargs): |
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.
Same here: this is for a follow-up PR.
ros2/pytest_wrapper.py.tpl
Outdated
if 'ROS_HOME' not in os.environ and 'ROS_LOG_DIR' not in os.environ: | ||
ros_output_dir = os.environ.get('TEST_UNDECLARED_OUTPUTS_DIR') | ||
if ros_output_dir is None: | ||
ros_output_dir = os.environ.get('TEST_TMPDIR') | ||
if ros_output_dir is not None: | ||
os.environ['ROS_HOME'] = ros_output_dir |
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.
Please use a snippet I posted earlier. Same reasoning as for launch.sh.tpl.
ros2/test.py.tpl
Outdated
if test_outputs_dir: | ||
os.environ['ROS_HOME'] = test_outputs_dir | ||
os.environ['ROS_LOG_DIR'] = test_outputs_dir | ||
if 'ROS_HOME' not in os.environ and 'ROS_LOG_DIR' not in os.environ: |
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.
Please use a snippet I posted earlier.
ros2/test/BUILD.bazel
Outdated
) | ||
load("@com_github_mvukov_rules_ros2//ros2:cc_defs.bzl", "ros2_cpp_test") | ||
load("@com_github_mvukov_rules_ros2//ros2:interfaces.bzl", "py_ros2_interface_library", "ros2_interface_library") | ||
load("@com_github_mvukov_rules_ros2//ros2:py_defs.bzl", "ros2_py_test") |
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.
Not needed.
ros2/test/BUILD.bazel
Outdated
"ros2_interface_library", | ||
) | ||
load("@com_github_mvukov_rules_ros2//ros2:cc_defs.bzl", "ros2_cpp_test") | ||
load("@com_github_mvukov_rules_ros2//ros2:interfaces.bzl", "py_ros2_interface_library", "ros2_interface_library") |
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.
Please revert formatting as in original.
ros2/pytest_wrapper.py.tpl
Outdated
ros_output_dir = os.environ.get('TEST_UNDECLARED_OUTPUTS_DIR') | ||
if ros_output_dir is None: | ||
ros_output_dir = os.environ.get('TEST_TMPDIR') | ||
if ros_output_dir is not None: |
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.
TEST_TMPDIR is always defined, we don't need this if-
clause here. The previous line should read: ros_output_dir = os.environ['TEST_TMPDIR']
.
BTW, I would rename ros_output_dir to bazel_test_output_dir for more explicitness.
ros2/test/test_rclcpp.cpp
Outdated
// 'Failed to get logging directory, at external/ros2_rcl_logging/rcl_logging_spdlog/src/rcl_logging_spdlog.cpp:83' // NOLINT | ||
// clang-format on | ||
rclcpp::init(argc, argv); | ||
return 0; |
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.
Maybe return rclcpp::shutdown()
?
The PR is in good shape now IMO. Thanks for your efforts! |
Default
ROS_HOME
andROS_LOG_DIR
env vars inros2_cpp_test
toTEST_UNDECLARED_OUTPUTS_DIR
.This is of course inspired by
rules_ros2/ros2/pytest_wrapper.py.tpl
Lines 38 to 39 in c345187
TEST_UNDECLARED_OUTPUTS_DIR
is optional(https://bazel.build/reference/test-encyclopedia#initial-conditions), onlyTEST_TMPDIR
is required to be present. However I would argue that currently users have to set this manually already via theenv
attribute, so there just would not be any change for users where the var is not available.