Skip to content

Commit

Permalink
Process an empty YAML when a configuration file isn't provided (#62)
Browse files Browse the repository at this point in the history
* Process an empty YAML when no YAML file is given

Signed-off-by: tempate <[email protected]>

* Tests

Signed-off-by: tempate <[email protected]>

* Fix python linter

Signed-off-by: tempate <[email protected]>

* Fix errors in tool_topics_dds_no_config test

Signed-off-by: tempate <[email protected]>

* Include the new tests in XTSAN

Signed-off-by: tempate <[email protected]>

* Update the year from 2023 to 2024

Signed-off-by: tempate <[email protected]>

---------

Signed-off-by: tempate <[email protected]>
  • Loading branch information
Tempate authored Jan 8, 2024
1 parent 774268b commit 3b76649
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 12 deletions.
5 changes: 2 additions & 3 deletions fastddsspy_tool/src/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,15 @@ int main(
// Fast DDS Spy Initialization

// Default configuration. Load it from file if file exists
eprosima::spy::yaml::Configuration configuration;

if (file_path != "")
{
logInfo(
FASTDDSSPY_TOOL,
"Loading configuration from file '" << file_path << "' .");
configuration = eprosima::spy::yaml::Configuration(file_path);
}

eprosima::spy::yaml::Configuration configuration = eprosima::spy::yaml::Configuration(file_path);

// Create the Spy
eprosima::spy::Controller spy(configuration);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima).
#
# 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.

"""Tests for the fastddsspy executable."""

import test_class


class TestCase_instance (test_class.TestCase):
"""@brief A subclass of `test_class.TestCase` representing a specific test case."""

def __init__(self):
"""
@brief Initialize the TestCase_instance object.
Launch this test with:
fastddsspy
AdvancedConfigurationExample publisher
"""
super().__init__(
name='TopicsDDSNoConfigCommand',
one_shot=True,
command=[],
dds=True,
config='',
arguments_dds=[],
arguments_spy=['topics'],
commands_spy=[],
output="""- name: HelloWorldTopic\n\
type: HelloWorld\n\
datawriters: 1\n\
datareaders: 0\n\
rate: %%rate%%\n"""
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima).
#
# 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.

"""Tests for the fastddsspy executable."""

import test_class


class TestCase_instance (test_class.TestCase):
"""@brief A subclass of `test_class.TestCase` representing a specific test case."""

def __init__(self):
"""
@brief Initialize the TestCase_instance object.
This test is launched with:
fastddsspy
>> topics
AdvancedConfigurationExample publisher
"""
super().__init__(
name='ToolShowTopicDDSCommand',
one_shot=False,
command=[],
dds=True,
config='',
arguments_dds=[],
arguments_spy=[],
commands_spy=['topics'],
output=""">> \x1b[0m- name: HelloWorldTopic\n\
\n\
type: HelloWorld\n\
\n\
datawriters: 1\n\
\n\
datareaders: 0\n\
\n\
rate: %%rate%%\n"""
)
13 changes: 7 additions & 6 deletions fastddsspy_tool/test/application/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,13 @@ def valid_rate(self, rate) -> bool:
@param rate: The rate to check.
@return Returns True if the rate is valid, False otherwise.
"""
pattern_1 = r'^(\d*\.?\d*\s(Hz))$' # rate: 10.5 Hz
pattern_2 = r'^((inf)\s(Hz))$' # rate: inf Hz
if re.match(pattern_1, rate):
return True
if re.match(pattern_2, rate):
return True
pattern = r'^(\d+(\.\d+)?|inf)\sHz$' # rate: (10.5 | inf) Hz

match = re.match(pattern, rate)

if match:
return match.group(1) == 'inf' or float(match.group(1)) > 0

print('Not valid rate: ')
print(rate)
return False
Expand Down
2 changes: 2 additions & 0 deletions fastddsspy_tool/test/labels/XTSAN.list
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ tool.application.fastddsspy.test.test_cases.one_shot_participants_guid_dds
tool.application.fastddsspy.test.test_cases.one_shot_participants_verbose_dds
tool.application.fastddsspy.test.test_cases.one_shot_quit_dds
tool.application.fastddsspy.test.test_cases.one_shot_topics_dds
tool.application.fastddsspy.test.test_cases.one_shot_topics_dds_no_config
tool.application.fastddsspy.test.test_cases.one_shot_topics_name_dds
tool.application.fastddsspy.test.test_cases.one_shot_topics_verbose_dds
tool.application.fastddsspy.test.test_cases.tool_datareader_dds
Expand All @@ -19,6 +20,7 @@ tool.application.fastddsspy.test.test_cases.tool_help_dds
tool.application.fastddsspy.test.test_cases.tool_participants_dds
tool.application.fastddsspy.test.test_cases.tool_show_topic_dds
tool.application.fastddsspy.test.test_cases.tool_topics_dds
tool.application.fastddsspy.test.test_cases.tool_topics_dds_no_config
tool.application.fastddsspy.test.test_cases.one_shot__config
tool.application.fastddsspy.test.test_cases.one_shot__config_fail_file
tool.application.fastddsspy.test.test_cases.one_shot__config_fail_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class Configuration : ddspipe::core::IConfiguration
void load_dds_configuration_(
const Yaml& yml,
const ddspipe::yaml::YamlReaderVersion& version);

void load_configuration_from_file_(
const std::string& file_path);
};

} /* namespace yaml */
Expand Down
29 changes: 26 additions & 3 deletions fastddsspy_yaml/src/cpp/YamlReaderConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ Configuration::Configuration(

Configuration::Configuration(
const std::string& file_path)
: Configuration(YamlManager::load_file(file_path))
: Configuration()
{
// Do nothing
load_configuration_from_file_(file_path);
}

void Configuration::load_configuration_(
Expand Down Expand Up @@ -105,7 +105,7 @@ void Configuration::load_configuration_(
ddspipe_configuration.blocklist.insert(
utils::Heritable<WildcardDdsFilterTopic>::make_heritable(rpc_response_topic));

// Only trigger the DdsPipe's callbacks with the discovery (and removal) of writers.
// Only trigger the DdsPipe's callbacks when discovering or removing writers
ddspipe_configuration.discovery_trigger = DiscoveryTrigger::WRITER;
}
catch (const std::exception& e)
Expand Down Expand Up @@ -215,6 +215,29 @@ void Configuration::load_specs_configuration_(
}
}

void Configuration::load_configuration_from_file_(
const std::string& file_path)
{
Yaml yml;

// Load file
try
{
if (!file_path.empty())
{
yml = YamlManager::load_file(file_path);
}
}
catch (const std::exception& e)
{
throw eprosima::utils::ConfigurationException(
utils::Formatter() << "Error loading Fast-DDS Spy configuration from file: <" << file_path <<
"> :\n " << e.what());
}

load_configuration_(yml);
}

bool Configuration::is_valid(
utils::Formatter& error_msg) const noexcept
{
Expand Down

0 comments on commit 3b76649

Please sign in to comment.