Skip to content

Commit

Permalink
Add python modules tests (#54)
Browse files Browse the repository at this point in the history
* Add types with modules to api tests

Signed-off-by: Raul Sanchez-Mateos <[email protected]>

* Update Participant tests to use the right type name

Signed-off-by: Raul Sanchez-Mateos <[email protected]>

* Add Windows LoadLibrary for moduled types

Signed-off-by: Raul Sanchez-Mateos <[email protected]>

* Add README.md with the guide to re-generate the types

Signed-off-by: Raul Sanchez-Mateos <[email protected]>

* Use types from modules in complete type

Signed-off-by: Raul Sanchez-Mateos <[email protected]>

* Uncomment sequence<boolean> types

Signed-off-by: Raul Sanchez-Mateos <[email protected]>

* Fix README.md with correct path

Signed-off-by: Raul Sanchez-Mateos <[email protected]>

* Update generated types

Signed-off-by: Raul Sanchez-Mateos <[email protected]>

* Regenerate tests types code with Fast DDS Gen v3.0.0

Signed-off-by: Raul Sanchez-Mateos <[email protected]>

* Regenerate test data types after rebase

Signed-off-by: Raul Sanchez-Mateos <[email protected]>

* Do not compile test by default

Signed-off-by: Raul Sanchez-Mateos <[email protected]>

* Compile tests only for fastdds_python

Signed-off-by: Raul Sanchez-Mateos <[email protected]>

* Add missing changes in auto-generated data types

Signed-off-by: Raul Sanchez-Mateos <[email protected]>

* Fix generation of IDL files

Signed-off-by: Ricardo González Moreno <[email protected]>

* Refs #18687. Fix cmakelists.txt

Signed-off-by: Ricardo González <[email protected]>

* Fix tests on windows

Signed-off-by: Ricardo González <[email protected]>

---------

Signed-off-by: Raul Sanchez-Mateos <[email protected]>
Signed-off-by: Ricardo González Moreno <[email protected]>
Signed-off-by: Ricardo González <[email protected]>
Co-authored-by: Ricardo González Moreno <[email protected]>
Co-authored-by: Ricardo González <[email protected]>
  • Loading branch information
3 people authored Oct 2, 2023
1 parent bbb019c commit bc064cd
Show file tree
Hide file tree
Showing 37 changed files with 15,848 additions and 123 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ jobs:

- name: Build workspace
run: >
colcon build --event-handlers=console_direct+ --metas ./src/fastdds_python/.github/workflows/test.meta \
--cmake-args -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
colcon build \
--event-handlers=console_direct+ \
--metas ./src/fastdds_python/.github/workflows/test.meta \
--cmake-args \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
- name: Run tests
run: |
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/test.meta
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
{
"names":
{
"fastrtps" :
"fastrtps":
{
"cmake-args": [
"-DTHIRDPARTY=ON",
"-DSECURITY=ON",
]
},
"fastdds_python":
{
"cmake-args": [
"-DBUILD_TESTING=ON"
]
}
}
}
11 changes: 10 additions & 1 deletion fastdds_python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ endif()

project(fastdds_python VERSION 1.2.2)

# Set BUILD_TESTING to OFF by default.
if(NOT BUILD_TESTING)
message(STATUS "Tests not compiled by default")
set(BUILD_TESTING OFF CACHE BOOL "Enable testing" FORCE)
endif()

###############################################################################
# Dependencies
###############################################################################
Expand All @@ -50,4 +56,7 @@ add_subdirectory(src/swig)
###############################################################################
enable_testing()
include(CTest)
add_subdirectory(test)

if (BUILD_TESTING)
add_subdirectory(test)
endif()
8 changes: 8 additions & 0 deletions fastdds_python/test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# How to re-generate data types for python

1. Navigate to `fastdds_python/test/types`
2. Run Fast DDS Gen script

```bash
fastddsgen -python -replace test_complete.idl test_modules.idl
```
59 changes: 32 additions & 27 deletions fastdds_python/test/api/test_datareader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,44 @@
if os.name == 'nt':
import win32api
win32api.LoadLibrary('test_complete')
win32api.LoadLibrary('test_modules')

import fastdds
import pytest
import test_complete
import time


class DataReaderListener (fastdds.DataReaderListener):
def __init__(self):
super().__init__()

@pytest.fixture(params=['no_module', 'module'], autouse=True)
def data_type(request):
if request.param == 'no_module':
pytest.dds_type = __import__("test_complete")
else:
pytest.dds_type = __import__("eprosima.test.test_modules",
fromlist=[None])

@pytest.fixture
def participant():
factory = fastdds.DomainParticipantFactory.get_instance()
return factory.create_participant(
0, fastdds.PARTICIPANT_QOS_DEFAULT)


@pytest.fixture
def subscriber(participant):
return participant.create_subscriber(fastdds.SUBSCRIBER_QOS_DEFAULT)


@pytest.fixture
def test_type():
return fastdds.TypeSupport(
test_complete.CompleteTestTypePubSubType())
return fastdds.TypeSupport(pytest.dds_type.CompleteTestTypePubSubType())


@pytest.fixture
def test_keyed_type(test_type):
test_type.set(test_complete.KeyedCompleteTestTypePubSubType())
test_type.set(pytest.dds_type.KeyedCompleteTestTypePubSubType())


@pytest.fixture
Expand Down Expand Up @@ -161,7 +166,7 @@ def test_get_first_untaken(transient_datareader_qos, datareader,
qos = datawriter.get_qos()
assert(fastdds.TRANSIENT_LOCAL_DURABILITY_QOS == qos.durability().kind)

sample = test_complete.CompleteTestType()
sample = pytest.dds_type.CompleteTestType()
sample.int16_field(255)
assert(datawriter.write(sample))

Expand Down Expand Up @@ -195,7 +200,7 @@ def test_get_key_value(test_keyed_type, datareader):
This test checks:
- DataReader::get_key_value
"""
sample = test_complete.KeyedCompleteTestType()
sample = pytest.dds_type.KeyedCompleteTestType()
sample.id(255)
ih = fastdds.InstanceHandle_t()
assert(fastdds.ReturnCode_t.RETCODE_UNSUPPORTED ==
Expand Down Expand Up @@ -444,7 +449,7 @@ def test_get_unread_count(transient_datareader_qos, datareader,
"""
assert(0 == datareader.get_unread_count())

sample = test_complete.CompleteTestType()
sample = pytest.dds_type.CompleteTestType()
sample.int16_field(255)
assert(datawriter.write(sample))

Expand All @@ -459,13 +464,13 @@ def test_is_sample_valid(transient_datareader_qos, datareader,
This test checks:
- DataReader::is_sample_valid
"""
sample = test_complete.CompleteTestType()
sample = pytest.dds_type.CompleteTestType()
sample.int16_field(255)
assert(datawriter.write(sample))

assert(datareader.wait_for_unread_message(
fastdds.Duration_t(5, 0)))
data = test_complete.CompleteTestType()
data = pytest.dds_type.CompleteTestType()
info = fastdds.SampleInfo()
assert(fastdds.ReturnCode_t.RETCODE_OK ==
datareader.read_next_sample(data, info))
Expand All @@ -485,7 +490,7 @@ def test_lookup_instance(transient_datareader_qos, test_keyed_type, datareader,
assert(fastdds.c_InstanceHandle_Unknown == ih)

# Test when instance is not registered
sample = test_complete.KeyedCompleteTestType()
sample = pytest.dds_type.KeyedCompleteTestType()
sample.id(3)
ih = datareader.lookup_instance(sample)
assert(fastdds.c_InstanceHandle_Unknown == ih)
Expand All @@ -509,7 +514,7 @@ def test_read(transient_datareader_qos, datareader,
- DataReader::read
- DataReader::return_loan
"""
data_seq = test_complete.CompleteTestTypeSeq()
data_seq = pytest.dds_type.CompleteTestTypeSeq()
info_seq = fastdds.SampleInfoSeq()
assert(fastdds.ReturnCode_t.RETCODE_NO_DATA ==
datareader.read(
Expand All @@ -519,7 +524,7 @@ def test_read(transient_datareader_qos, datareader,
assert(0 == len(data_seq))
assert(0 == len(info_seq))

sample = test_complete.CompleteTestType()
sample = pytest.dds_type.CompleteTestType()
sample.int16_field(255)
assert(datawriter.write(sample))

Expand All @@ -544,7 +549,7 @@ def test_read_instance(transient_datareader_qos, test_keyed_type,
- DataReader::read_instance
- DataReader::return_loan
"""
data_seq = test_complete.KeyedCompleteTestTypeSeq()
data_seq = pytest.dds_type.KeyedCompleteTestTypeSeq()
info_seq = fastdds.SampleInfoSeq()
ih = fastdds.InstanceHandle_t()
assert(fastdds.ReturnCode_t.RETCODE_BAD_PARAMETER ==
Expand All @@ -555,7 +560,7 @@ def test_read_instance(transient_datareader_qos, test_keyed_type,
assert(0 == len(data_seq))
assert(0 == len(info_seq))

sample = test_complete.KeyedCompleteTestType()
sample = pytest.dds_type.KeyedCompleteTestType()
sample.id(255)
ih = datawriter.register_instance(sample)
assert(datawriter.write(sample, ih))
Expand All @@ -582,7 +587,7 @@ def test_read_next_instance(transient_datareader_qos, test_keyed_type,
- DataReader::read_next_instance
- DataReader::return_loan
"""
data_seq = test_complete.KeyedCompleteTestTypeSeq()
data_seq = pytest.dds_type.KeyedCompleteTestTypeSeq()
info_seq = fastdds.SampleInfoSeq()
ih = fastdds.InstanceHandle_t()
assert(fastdds.ReturnCode_t.RETCODE_NO_DATA ==
Expand All @@ -593,7 +598,7 @@ def test_read_next_instance(transient_datareader_qos, test_keyed_type,
assert(0 == len(data_seq))
assert(0 == len(info_seq))

sample = test_complete.KeyedCompleteTestType()
sample = pytest.dds_type.KeyedCompleteTestType()
sample.id(255)
assert(datawriter.write(sample))

Expand All @@ -618,13 +623,13 @@ def test_read_next_sample(transient_datareader_qos, datareader,
This test checks:
- DataReader::read_next_sample
"""
data = test_complete.CompleteTestType()
data = pytest.dds_type.CompleteTestType()
info = fastdds.SampleInfo()
assert(fastdds.ReturnCode_t.RETCODE_NO_DATA ==
datareader.read_next_sample(
data, info))

sample = test_complete.CompleteTestType()
sample = pytest.dds_type.CompleteTestType()
sample.int16_field(255)
assert(datawriter.write(sample))

Expand All @@ -643,7 +648,7 @@ def test_take(transient_datareader_qos, datareader,
- DataReader::take
- DataReader::return_loan
"""
data_seq = test_complete.CompleteTestTypeSeq()
data_seq = pytest.dds_type.CompleteTestTypeSeq()
info_seq = fastdds.SampleInfoSeq()
assert(fastdds.ReturnCode_t.RETCODE_NO_DATA ==
datareader.take(
Expand All @@ -653,7 +658,7 @@ def test_take(transient_datareader_qos, datareader,
assert(0 == len(data_seq))
assert(0 == len(info_seq))

sample = test_complete.CompleteTestType()
sample = pytest.dds_type.CompleteTestType()
sample.int16_field(255)
assert(datawriter.write(sample))

Expand All @@ -678,7 +683,7 @@ def test_take_instance(transient_datareader_qos, test_keyed_type,
- DataReader::take_instance
- DataReader::return_loan
"""
data_seq = test_complete.KeyedCompleteTestTypeSeq()
data_seq = pytest.dds_type.KeyedCompleteTestTypeSeq()
info_seq = fastdds.SampleInfoSeq()
ih = fastdds.InstanceHandle_t()
assert(fastdds.ReturnCode_t.RETCODE_BAD_PARAMETER ==
Expand All @@ -689,7 +694,7 @@ def test_take_instance(transient_datareader_qos, test_keyed_type,
assert(0 == len(data_seq))
assert(0 == len(info_seq))

sample = test_complete.KeyedCompleteTestType()
sample = pytest.dds_type.KeyedCompleteTestType()
sample.id(255)
ih = datawriter.register_instance(sample)
assert(datawriter.write(sample, ih))
Expand All @@ -716,7 +721,7 @@ def test_take_next_instance(transient_datareader_qos, test_keyed_type,
- DataReader::take_next_instance
- DataReader::return_loan
"""
data_seq = test_complete.KeyedCompleteTestTypeSeq()
data_seq = pytest.dds_type.KeyedCompleteTestTypeSeq()
info_seq = fastdds.SampleInfoSeq()
ih = fastdds.InstanceHandle_t()
assert(fastdds.ReturnCode_t.RETCODE_NO_DATA ==
Expand All @@ -727,7 +732,7 @@ def test_take_next_instance(transient_datareader_qos, test_keyed_type,
assert(0 == len(data_seq))
assert(0 == len(info_seq))

sample = test_complete.KeyedCompleteTestType()
sample = pytest.dds_type.KeyedCompleteTestType()
sample.id(255)
assert(datawriter.write(sample))

Expand All @@ -752,13 +757,13 @@ def test_take_next_sample(transient_datareader_qos, datareader,
This test checks:
- DataReader::take_next_sample
"""
data = test_complete.CompleteTestType()
data = pytest.dds_type.CompleteTestType()
info = fastdds.SampleInfo()
assert(fastdds.ReturnCode_t.RETCODE_NO_DATA ==
datareader.take_next_sample(
data, info))

sample = test_complete.CompleteTestType()
sample = pytest.dds_type.CompleteTestType()
sample.int16_field(255)
assert(datawriter.write(sample))

Expand Down
Loading

0 comments on commit bc064cd

Please sign in to comment.