From 3fb9fbfdf551549e153ca1d5e4af0f00b1e52a25 Mon Sep 17 00:00:00 2001 From: Irene Bandera Date: Wed, 21 Jun 2023 13:18:27 +0200 Subject: [PATCH] Apply changes Signed-off-by: Irene Bandera --- .../test/application/CMakeLists.txt | 8 +-- fastddsspy_tool/test/application/README.md | 60 +++++++++++++++++++ fastddsspy_tool/test/application/test.py | 2 +- .../test_cases/one_shot__version.py | 1 + .../test/application/test_class.py | 9 +-- 5 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 fastddsspy_tool/test/application/README.md diff --git a/fastddsspy_tool/test/application/CMakeLists.txt b/fastddsspy_tool/test/application/CMakeLists.txt index 85e1d7cc..b08f0adb 100644 --- a/fastddsspy_tool/test/application/CMakeLists.txt +++ b/fastddsspy_tool/test/application/CMakeLists.txt @@ -20,13 +20,13 @@ find_package(PythonInterp 3 REQUIRED) # Name of files to test -function(GET_FILENAMES_WITHOUT_PARENT PATH_LIST RESULT_VARIABLE) +function(get_filenames_without_parent PATH_LIST RESULT_VARIABLE) set(FILENAMES "") foreach(PATH ${${PATH_LIST}}) get_filename_component(FILENAME ${PATH} NAME) - string(REGEX REPLACE "\\.[^.]*$" "" fileNameWithoutExtension ${FILENAME}) - list(APPEND FILENAMES ${fileNameWithoutExtension}) + string(REGEX REPLACE "\\.[^.]*$" "" FILE_NAME_WITHOUT_EXTENSION ${FILENAME}) + list(APPEND FILENAMES ${FILE_NAME_WITHOUT_EXTENSION}) endforeach() set(${RESULT_VARIABLE} ${FILENAMES} PARENT_SCOPE) @@ -37,7 +37,7 @@ file( "test_cases/*.py" ) -GET_FILENAMES_WITHOUT_PARENT(TEST_PATH TEST_FILENAMES) +get_filenames_without_parent(TEST_PATH TEST_FILENAMES) message(STATUS "TEST FILES NAME: ${TEST_FILENAMES}") diff --git a/fastddsspy_tool/test/application/README.md b/fastddsspy_tool/test/application/README.md new file mode 100644 index 00000000..5bd72969 --- /dev/null +++ b/fastddsspy_tool/test/application/README.md @@ -0,0 +1,60 @@ +# Fast-DDS-spy tool tests + +This module builds a test suite for the Fast DDS Spy. + +## Executable [test.py](test.py) + +The executable is responsible for running all the tests and verify that the system behaves correctly under the different conditions. + +## Executable [test_class.py](test_class.py) + +Is the base class that provides the foundation for creating test cases. +Encapsulates various methods and functionalities that enable the definition and execution of individual test cases. +By inheriting from `test_class.TestCase`, you can create custom test case classes that inherit the features and capabilities of the base class. +This inheritance allows you to leverage the provided methods and utilities within your test cases. +However, you also have the flexibility to reimplement or override those methods to tailor them to your specific test cases. + +## Add a new test case file + +To add a new test case file and define specific conditions to test, follow these steps: + +1. Create a new python file inside [test_cases](test_cases/) directory. +2. In the newly created file, create a child class that inherits from `test_class.TestCase`. +3. Customize the class by setting the desired parameters to define the conditions you want to test. + +For example, if you want to test: + + ```bash + fastddsspy --config-path fastddsspy_tool/test/application/configuration/configuration_discovery_time.yaml participants verbose + ``` + +With a DDS Publisher running: + + ```bash + AdvancedConfigurationExample publisher + ``` + +You need a class like [this](test_cases/one_shot_participants_verbose_dds.py): + + ```yaml + name='TopicsVerboseDDSCommand', + one_shot=True, + command=[], + dds=True, + config='fastddsspy_tool/test/application/configuration/configuration_discovery_time.yaml', + arguments_dds=[], + arguments_spy=['--config-path', 'configuration', 'topics', 'verbose'], + commands_spy=[], + output="""- name: HelloWorldTopic\n\ + type: HelloWorld\n\ + datawriters:\n\ + - %%guid%%\n\ + rate: %%rate%%\n\ + dynamic_type_discovered: false\n""" + ``` + +If you need to override a specific method for a particular test case, you can do so by providing an implementation within that specific test case class like [here](test_cases/one_shot__help.py) with `valid_output()`. + +## TODO + +Add a test scenario with a DataReader. diff --git a/fastddsspy_tool/test/application/test.py b/fastddsspy_tool/test/application/test.py index 925e9a0e..1f52b40c 100644 --- a/fastddsspy_tool/test/application/test.py +++ b/fastddsspy_tool/test/application/test.py @@ -108,7 +108,7 @@ def parse_options(): def get_config_path_spy(arguments_spy, exec_spy, config): """ - @brief Get the arguments for the publisher and the Spy. + @brief Get the path of the configuration of the Spy @param test_class: The test class object. @param args: The command-line arguments. diff --git a/fastddsspy_tool/test/application/test_cases/one_shot__version.py b/fastddsspy_tool/test/application/test_cases/one_shot__version.py index 68e4f3ba..08f81d9d 100644 --- a/fastddsspy_tool/test/application/test_cases/one_shot__version.py +++ b/fastddsspy_tool/test/application/test_cases/one_shot__version.py @@ -45,6 +45,7 @@ def valid_output(self, output): @brief Validate the output. @param output: The actual output obtained from executing a command. + @todo Parse the output @return Always returns True. """ return True diff --git a/fastddsspy_tool/test/application/test_class.py b/fastddsspy_tool/test/application/test_class.py index 4d899d0e..ed424c82 100644 --- a/fastddsspy_tool/test/application/test_class.py +++ b/fastddsspy_tool/test/application/test_class.py @@ -95,7 +95,7 @@ def run_tool(self): return None else: - self.read_output(proc) + self.read_command_output(proc) return proc def send_command_tool(self, proc): @@ -109,10 +109,10 @@ def send_command_tool(self, proc): proc.stdin.write((self.commands_spy[0]+'\n')) proc.stdin.flush() - output = self.read_output(proc) + output = self.read_command_output(proc) return (output) - def read_output(self, proc): + def read_command_output(self, proc): """ @brief Read the output from the subprocess. @@ -121,6 +121,7 @@ def read_output(self, proc): """ output = '' count = 0 + # max number of loops while can take to avoid waiting forever if something goes wrong max_count = 500 while True: @@ -252,7 +253,7 @@ def stop_dds(self, proc) -> int: if self.dds: try: proc.terminate() - proc.communicate(timeout=15) + proc.communicate(timeout=13) except subprocess.TimeoutExpired: proc.kill()