Skip to content

Commit

Permalink
Merge pull request #22 from clydemcqueen/clyde_lint_and_test
Browse files Browse the repository at this point in the history
Add linters and smoke test
  • Loading branch information
clydemcqueen authored Nov 17, 2021
2 parents c4db136 + f0a6963 commit 687a975
Show file tree
Hide file tree
Showing 13 changed files with 596 additions and 408 deletions.
32 changes: 26 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ cmake_minimum_required(VERSION 3.5)
project(gscam2)

# Default to C99
if (NOT CMAKE_C_STANDARD)
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif ()
endif()

# Default to C++14
if (NOT CMAKE_CXX_STANDARD)
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif ()
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# Emulate Colcon in CLion
if ($ENV{CLION_IDE})
if($ENV{CLION_IDE})
message(STATUS "Running inside CLion")
find_package(fastrtps_cmake_module REQUIRED)
set(FastRTPS_INCLUDE_DIR "/opt/ros/foxy/include")
set(FastRTPS_LIBRARY_RELEASE "/opt/ros/foxy/lib/libfastrtps.so")
set(ros2_shared_DIR "${PROJECT_SOURCE_DIR}/../../../install/ros2_shared/share/ros2_shared/cmake")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DRUN_INSIDE_CLION")
endif ()
endif()

# Gstreamer doesn't provide CMake files
find_package(PkgConfig)
Expand Down Expand Up @@ -129,6 +129,26 @@ ament_target_dependencies(
rclcpp
)

#=============
# Test
#=============

# Load & run linters listed in package.xml
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()

find_package(ament_cmake_gtest)
ament_add_gtest(
smoke_test
test/smoke_test.cpp
ENV GSCAM_CONFIG="videotestsrc pattern=snow ! capsfilter caps=video/x-raw,width=800,height=600 ! videoconvert"
)
if(TARGET smoke_test)
target_link_libraries(smoke_test gscam_node)
endif()
endif()

#=============
# Export
# Best practice, see https://discourse.ros.org/t/ament-best-practice-for-sharing-libraries/3602
Expand Down
21 changes: 10 additions & 11 deletions include/gscam2/gscam_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@
namespace gscam2
{

class GSCamNode : public rclcpp::Node
{
// Hide implementation
class impl;
std::unique_ptr<impl> pImpl_;

void validate_parameters();
class GSCamNode : public rclcpp::Node
{
// Hide implementation
class impl;
std::unique_ptr<impl> pImpl_;

public:
void validate_parameters();

explicit GSCamNode(const rclcpp::NodeOptions &options);
public:
explicit GSCamNode(const rclcpp::NodeOptions & options);

~GSCamNode() override;
};
~GSCamNode() override;
};

}

Expand Down
17 changes: 8 additions & 9 deletions include/gscam2/subscriber_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
namespace gscam2
{

// Node that subscribes to a topic, used for testing composition and IPC
class ImageSubscriberNode : public rclcpp::Node
{
rclcpp::Subscription<sensor_msgs::msg::Image>::SharedPtr sub_;

public:
// Node that subscribes to a topic, used for testing composition and IPC
class ImageSubscriberNode : public rclcpp::Node
{
rclcpp::Subscription<sensor_msgs::msg::Image>::SharedPtr sub_;

explicit ImageSubscriberNode(const rclcpp::NodeOptions &options);
};
public:
explicit ImageSubscriberNode(const rclcpp::NodeOptions & options);
};

} // namespace gscam2

#endif //SIMPLE_SUBSCRIBER_HPP
#endif //SIMPLE_SUBSCRIBER_HPP
5 changes: 3 additions & 2 deletions launch/composition_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@


def generate_launch_description():
gscam_config = 'videotestsrc pattern=snow ! video/x-raw,width=1280,height=720 ! videoconvert'

container = ComposableNodeContainer(
name='my_container',
Expand All @@ -23,7 +24,7 @@ def generate_launch_description():
plugin='gscam2::GSCamNode',
name='image_publisher',
parameters=[{
'gscam_config': 'videotestsrc pattern=snow ! video/x-raw,width=1280,height=720 ! videoconvert',
'gscam_config': gscam_config,
}],
extra_arguments=[{'use_intra_process_comms': True}],
),
Expand All @@ -37,4 +38,4 @@ def generate_launch_description():
output='screen',
)

return LaunchDescription([container])
return LaunchDescription([container])
2 changes: 1 addition & 1 deletion launch/container_param_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
print(config_dir)

# Parameters file, see https://github.com/ros2/launch_ros/issues/156
params_file = os.path.join(config_dir, "workaround_params.yaml")
params_file = os.path.join(config_dir, 'workaround_params.yaml')
print(params_file)

# Camera calibration file
Expand Down
8 changes: 3 additions & 5 deletions launch/node_param_launch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Launch a Node with parameters and remappings.
"""
"""Launch a Node with parameters and remappings."""

import os

Expand All @@ -16,7 +14,7 @@
print(config_dir)

# Parameters file
params_file = os.path.join(config_dir, "params.yaml")
params_file = os.path.join(config_dir, 'params.yaml')
print(params_file)

# Camera calibration file
Expand All @@ -37,7 +35,7 @@ def generate_launch_description():
params_file,
# A few more parameters
{
'camera_name': camera_name, # Camera Name
'camera_name': camera_name, # Camera Name
'camera_info_url': camera_config, # Camera calibration information
},
],
Expand Down
18 changes: 18 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@

<buildtool_depend>ament_cmake</buildtool_depend>

<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_lint_auto</test_depend>

<!-- Original gscam didn't / doesn't include copyright headers, ignore for now
<test_depend>ament_cmake_copyright</test_depend>
-->

<!-- Also checks for copyright
<test_depend>ament_cmake_cpplint</test_depend>
-->

<test_depend>ament_cmake_cppcheck</test_depend>
<test_depend>ament_cmake_flake8</test_depend>
<test_depend>ament_cmake_lint_cmake</test_depend>
<test_depend>ament_cmake_pep257</test_depend>
<test_depend>ament_cmake_uncrustify</test_depend>
<test_depend>ament_cmake_xmllint</test_depend>

<depend>camera_calibration_parsers</depend>
<depend>camera_info_manager</depend>
<depend>class_loader</depend>
Expand Down
5 changes: 3 additions & 2 deletions src/gscam_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "rclcpp/rclcpp.hpp"

int main(int argc, char **argv)
int main(int argc, char ** argv)
{
// Force flush of the stdout buffer
setvbuf(stdout, nullptr, _IONBF, BUFSIZ);
Expand All @@ -17,7 +17,8 @@ int main(int argc, char **argv)
auto node = std::make_shared<gscam2::GSCamNode>(options);

// Set logging level
auto result = rcutils_logging_set_logger_level(node->get_logger().get_name(), RCUTILS_LOG_SEVERITY_INFO);
auto result = rcutils_logging_set_logger_level(
node->get_logger().get_name(), RCUTILS_LOG_SEVERITY_INFO);
(void) result;

// Spin until rclcpp::ok() returns false
Expand Down
Loading

0 comments on commit 687a975

Please sign in to comment.