Skip to content

Commit

Permalink
Apply changes
Browse files Browse the repository at this point in the history
Signed-off-by: Irene Bandera <[email protected]>
  • Loading branch information
irenebm committed Jun 21, 2023
1 parent bc1849e commit 3fb9fbf
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 9 deletions.
8 changes: 4 additions & 4 deletions fastddsspy_tool/test/application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}")

Expand Down
60 changes: 60 additions & 0 deletions fastddsspy_tool/test/application/README.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion fastddsspy_tool/test/application/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 5 additions & 4 deletions fastddsspy_tool/test/application/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 3fb9fbf

Please sign in to comment.