-
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
Test load and lookup functionality. #135
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
rmw_implementation/include/rmw_implementation/functions.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2020 Open Source Robotics Foundation, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef RMW_IMPLEMENTATION__FUNCTIONS_HPP_ | ||
#define RMW_IMPLEMENTATION__FUNCTIONS_HPP_ | ||
|
||
#include <memory> | ||
|
||
#include "rcpputils/shared_library.hpp" | ||
|
||
#include "rmw_implementation/visibility_control.h" | ||
|
||
RMW_IMPLEMENTATION_PUBLIC | ||
std::shared_ptr<rcpputils::SharedLibrary> | ||
load_library(); | ||
|
||
RMW_IMPLEMENTATION_PUBLIC | ||
void * | ||
lookup_symbol(std::shared_ptr<rcpputils::SharedLibrary> lib, const char * symbol_name); | ||
|
||
#endif // RMW_IMPLEMENTATION__FUNCTIONS_HPP_ |
58 changes: 58 additions & 0 deletions
58
rmw_implementation/include/rmw_implementation/visibility_control.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2020 Open Source Robotics Foundation, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef RMW_IMPLEMENTATION__VISIBILITY_CONTROL_H_ | ||
#define RMW_IMPLEMENTATION__VISIBILITY_CONTROL_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
// This logic was borrowed (then namespaced) from the examples on the gcc wiki: | ||
// https://gcc.gnu.org/wiki/Visibility | ||
|
||
#if defined _WIN32 || defined __CYGWIN__ | ||
#ifdef __GNUC__ | ||
#define RMW_IMPLEMENTATION_EXPORT __attribute__ ((dllexport)) | ||
#define RMW_IMPLEMENTATION_IMPORT __attribute__ ((dllimport)) | ||
#else | ||
#define RMW_IMPLEMENTATION_EXPORT __declspec(dllexport) | ||
#define RMW_IMPLEMENTATION_IMPORT __declspec(dllimport) | ||
#endif | ||
#ifdef RMW_IMPLEMENTATION_BUILDING_DLL | ||
#define RMW_IMPLEMENTATION_PUBLIC RMW_IMPLEMENTATION_EXPORT | ||
#else | ||
#define RMW_IMPLEMENTATION_PUBLIC RMW_IMPLEMENTATION_IMPORT | ||
#endif | ||
#define RMW_IMPLEMENTATION_PUBLIC_TYPE RMW_IMPLEMENTATION_PUBLIC | ||
#define RMW_IMPLEMENTATION_LOCAL | ||
#else | ||
#define RMW_IMPLEMENTATION_EXPORT __attribute__ ((visibility("default"))) | ||
#define RMW_IMPLEMENTATION_IMPORT | ||
#if __GNUC__ >= 4 | ||
#define RMW_IMPLEMENTATION_PUBLIC __attribute__ ((visibility("default"))) | ||
#define RMW_IMPLEMENTATION_LOCAL __attribute__ ((visibility("hidden"))) | ||
#else | ||
#define RMW_IMPLEMENTATION_PUBLIC | ||
#define RMW_IMPLEMENTATION_LOCAL | ||
#endif | ||
#define RMW_IMPLEMENTATION_PUBLIC_TYPE | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // RMW_IMPLEMENTATION__VISIBILITY_CONTROL_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2020 Open Source Robotics Foundation, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <memory> | ||
|
||
#include "rcutils/env.h" | ||
#include "rcutils/get_env.h" | ||
#include "rcutils/testing/fault_injection.h" | ||
|
||
#include "rmw/error_handling.h" | ||
|
||
#include "rmw_implementation/functions.hpp" | ||
|
||
TEST(Functions, bad_load) { | ||
const char * rmw_implementation = nullptr; | ||
ASSERT_EQ(nullptr, rcutils_get_env("RMW_IMPLEMENTATION", &rmw_implementation)); | ||
EXPECT_TRUE(rcutils_set_env("RMW_IMPLEMENTATION", "not_an_rmw_implementation")); | ||
|
||
EXPECT_EQ(nullptr, load_library()); | ||
EXPECT_TRUE(rmw_error_is_set()); | ||
rmw_reset_error(); | ||
|
||
EXPECT_TRUE(rcutils_set_env("RMW_IMPLEMENTATION", rmw_implementation)); | ||
} | ||
|
||
TEST(Functions, nominal_load_and_lookup) { | ||
std::shared_ptr<rcpputils::SharedLibrary> lib = load_library(); | ||
ASSERT_NE(nullptr, lib) << rmw_get_error_string().str; | ||
EXPECT_NE(nullptr, lookup_symbol(lib, "rmw_init")) << rmw_get_error_string().str; | ||
EXPECT_EQ(nullptr, lookup_symbol(lib, "not_an_rmw_function")); | ||
EXPECT_TRUE(rmw_error_is_set()); | ||
rmw_reset_error(); | ||
} | ||
|
||
TEST(Functions, load_and_lookup_with_internal_errors) { | ||
RCUTILS_FAULT_INJECTION_TEST( | ||
{ | ||
void * symbol = lookup_symbol(load_library(), "rmw_init"); | ||
if (!symbol) { | ||
EXPECT_TRUE(rmw_error_is_set()); | ||
rmw_reset_error(); | ||
} | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I have to say that I'm a bit concerned about making this header file "public". If we put this in, then it seems like
load_library
andlookup_symbol
are APIs that downstream consumers should be able to call. And as far as I can tell, that is not the case.One alternative here is to do something similar to what rviz_default_plugins does. That is, put the header file in the src directory, and don't install it. Then have the tests include the header file via relative paths. I don't love that scheme, but it has the property that it keeps this implementation private (as it looks like it should be), but also makes the symbols available to tests. What do you think?
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.
I don't have a strong opinion in favor or against exposing
rmw
implementation lookup.I'm OK with that scheme too.
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.
Though that doesn't change the fact that the symbols will be public.
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.
Just to recap a private conversation: while that is true, it is more around the messaging to external consumers. If a function is in a publicly-accessible, installed header, then that seems like something a user might want to call. If it is hidden away in a
src
directory, and the user has to go looking through symbols to find it, then it is pretty clear they are doing something unsupported.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.
Agreed. See b885711. Went the extra mile to only make symbols public if building for testing.