-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test load and lookup functionality. (#135)
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
- Loading branch information
Showing
6 changed files
with
234 additions
and
39 deletions.
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
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,30 @@ | ||
// 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 FUNCTIONS_HPP_ | ||
#define FUNCTIONS_HPP_ | ||
|
||
#include <memory> | ||
|
||
#include "rcpputils/shared_library.hpp" | ||
|
||
#include "./visibility_control.h" | ||
|
||
RMW_IMPLEMENTATION_DEFAULT_VISIBILITY | ||
std::shared_ptr<rcpputils::SharedLibrary> load_library(); | ||
|
||
RMW_IMPLEMENTATION_DEFAULT_VISIBILITY | ||
void * lookup_symbol(std::shared_ptr<rcpputils::SharedLibrary> lib, const char * symbol_name); | ||
|
||
#endif // 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,62 @@ | ||
// 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 VISIBILITY_CONTROL_H_ | ||
#define 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 | ||
|
||
#ifndef RMW_IMPLEMENTATION_DEFAULT_VISIBILITY | ||
#define RMW_IMPLEMENTATION_DEFAULT_VISIBILITY | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // 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,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 "../src/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(); | ||
} | ||
}); | ||
} |