Skip to content

Commit

Permalink
Add test for add_analyzer at runtime, remove unnecessary ros info log…
Browse files Browse the repository at this point in the history
…ger, remove unnecessary hardcoded namespace from yaml files
  • Loading branch information
MartinCornelis2 committed Mar 1, 2024
1 parent b66a4ce commit 4af79fc
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 7 deletions.
22 changes: 22 additions & 0 deletions diagnostic_aggregator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ if(BUILD_TESTING)
find_package(launch_testing_ament_cmake REQUIRED)

file(TO_CMAKE_PATH "${CMAKE_INSTALL_PREFIX}/lib/${PROJECT_NAME}/aggregator_node" AGGREGATOR_NODE)
file(TO_CMAKE_PATH "${CMAKE_INSTALL_PREFIX}/lib/${PROJECT_NAME}/add_analyzer" ADD_ANALYZER)
file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/test/test_listener.py" TEST_LISTENER)
set(create_analyzers_tests
"primitive_analyzers"
Expand Down Expand Up @@ -129,6 +130,27 @@ if(BUILD_TESTING)
)
endforeach()

set(add_analyzers_tests
"all_analyzers")

foreach(test_name ${add_analyzers_tests})
file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/test/default.yaml" PARAMETER_FILE)
file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/test/${test_name}.yaml" ADD_PARAMETER_FILE)
file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/test/expected_output/add_${test_name}" EXPECTED_OUTPUT)

configure_file(
"test/add_analyzers.launch.py.in"
"test_add_${test_name}.launch.py"
@ONLY
)
add_launch_test(
"${CMAKE_CURRENT_BINARY_DIR}/test_add_${test_name}.launch.py"
TARGET "test_add_${test_name}"
TIMEOUT 30
ENV
)
endforeach()

add_launch_test(
test/test_critical_pub.py
TIMEOUT 30
Expand Down
1 change: 0 additions & 1 deletion diagnostic_aggregator/src/add_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class AddAnalyzer : public rclcpp::Node
// Check in map if the stripped param name with the added suffix "path" exists
// This indicates the parameter is part of an analyzer description
if (parameters.count(stripped_param_name + ".path") > 0) {
RCLCPP_INFO(this->get_logger(), param_name.c_str());
auto parameter_msg = param.to_parameter_msg();
request->parameters.push_back(parameter_msg);
}
Expand Down
74 changes: 74 additions & 0 deletions diagnostic_aggregator/test/add_analyzers.launch.py.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import os

import unittest

from launch import LaunchDescription
from launch.actions import ExecuteProcess
from launch.events import matches_action
from launch.events.process import ShutdownProcess

import launch_testing
import launch_testing.actions
import launch_testing.asserts
import launch_testing.util
import launch_testing_ros


def generate_test_description():
os.environ['OSPL_VERBOSITY'] = '8'
os.environ['RCUTILS_CONSOLE_OUTPUT_FORMAT'] = '{message}'

aggregator_node = ExecuteProcess(
cmd=[
"@AGGREGATOR_NODE@",
"--ros-args",
"--params-file",
"@PARAMETER_FILE@"
],
name='aggregator_node',
emulate_tty=True,
output='screen')

add_analyzer = ExecuteProcess(
cmd=[
"@ADD_ANALYZER@",
"--ros-args",
"--params-file",
"@ADD_PARAMETER_FILE@"
],
name='add_analyzer',
emulate_tty=True,
output='screen')

launch_description = LaunchDescription()
launch_description.add_action(aggregator_node)
launch_description.add_action(add_analyzer)
launch_description.add_action(launch_testing.util.KeepAliveProc())
launch_description.add_action(launch_testing.actions.ReadyToTest())
return launch_description, locals()

class TestAggregator(unittest.TestCase):

def test_processes_output(self, proc_output, aggregator_node):
"""Check aggregator logging output for expected strings."""

from launch_testing.tools.output import get_default_filtered_prefixes
output_filter = launch_testing_ros.tools.basic_output_filter(
filtered_prefixes=get_default_filtered_prefixes() + ['service not available, waiting...'],
filtered_rmw_implementation='@rmw_implementation@'
)
proc_output.assertWaitFor(
expected_output=launch_testing.tools.expected_output_from_file(path="@EXPECTED_OUTPUT@"),
process=aggregator_node,
output_filter=output_filter,
timeout=15
)

import time
time.sleep(1)

@launch_testing.post_shutdown_test()
class TestAggregatorShutdown(unittest.TestCase):

def test_last_process_exit_code(self, proc_info, aggregator_node):
launch_testing.asserts.assertExitCodes(proc_info, process=aggregator_node)
2 changes: 1 addition & 1 deletion diagnostic_aggregator/test/all_analyzers.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
analyzers:
/**:
ros__parameters:
path: BASIC
prefix1:
Expand Down
2 changes: 1 addition & 1 deletion diagnostic_aggregator/test/analyzer_group.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
analyzers:
/**:
ros__parameters:
path: TEST
primary:
Expand Down
9 changes: 9 additions & 0 deletions diagnostic_aggregator/test/default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**:
ros__parameters:
path: BASIC
prefix0:
type: diagnostic_aggregator/GenericAnalyzer
path: Zeroth
contains: [
'contain0a',
'contain0b' ]
2 changes: 1 addition & 1 deletion diagnostic_aggregator/test/empty_root_path.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
analyzers:
/**:
ros__parameters:
primary:
type: 'diagnostic_aggregator/AnalyzerGroup'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/BASIC/Zeroth
prefix0
/BASIC/First
prefix1
/BASIC/Third
prefix3
2 changes: 1 addition & 1 deletion diagnostic_aggregator/test/expected_stale_analyzers.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
analyzers:
/**:
my_path:
type: diagnostic_aggregator/GenericAnalyzer
path: My Path
Expand Down
2 changes: 1 addition & 1 deletion diagnostic_aggregator/test/multiple_match_analyzers.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
analyzers:
/**:
my_path:
type: diagnostic_aggregator/GenericAnalyzer
path: Header1
Expand Down
2 changes: 1 addition & 1 deletion diagnostic_aggregator/test/primitive_analyzers.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
analyzers:
/**:
ros__parameters:
log_level: debug
primary:
Expand Down

0 comments on commit 4af79fc

Please sign in to comment.