Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include type-info in sertype_equal for default sertype implementation #1698

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/core/ddsc/src/dds_sertype_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,29 @@ static bool sertype_default_equal (const struct ddsi_sertype *acmn, const struct
return false;
assert (a->type.opt_size_xcdr1 == b->type.opt_size_xcdr1);
assert (a->type.opt_size_xcdr2 == b->type.opt_size_xcdr2);

#ifdef DDS_HAS_TYPE_DISCOVERY
if (a->type.flagset & DDS_TOPIC_XTYPES_METADATA)
{
ddsi_typeinfo_t *ti_a, *ti_b;
ti_a = ddsi_typeinfo_deser (a->typeinfo_ser.data, a->typeinfo_ser.sz);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to deserialize here? Or can we get away with comparing the serialised representation?

For that, we would have to be certain about the endianness and padding, and perhaps something else. The first two are reasonably easy to deal with, the third is of course tricky 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is the set of hash type identifiers the type depends on, that is included in a type-info object. The spec (7.6.3.2.1) does not specify any ordering for this list (TypeInformation.[minimal/complete].dependent_typeids), and it is also allowed to leave out one or more type identifiers, as long as the dependent type count is correct (TypeInformation.[minimal/complete].dependent_typeid_count).

ti_b = ddsi_typeinfo_deser (b->typeinfo_ser.data, b->typeinfo_ser.sz);
bool ti_eq = ti_a != NULL && ti_b != NULL && ddsi_typeinfo_equal (ti_a, ti_b, DDSI_TYPE_IGNORE_DEPS);
if (ti_a != NULL)
{
ddsi_typeinfo_fini (ti_a);
ddsrt_free (ti_a);
}
if (ti_b != NULL)
{
ddsi_typeinfo_fini (ti_b);
ddsrt_free (ti_b);
}
if (!ti_eq)
return false;
}
#endif

return true;
}

Expand Down
4 changes: 3 additions & 1 deletion src/core/ddsc/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ idlc_generate(TARGET DataRepresentationTypes FILES DataRepresentationTypes.idl W
idlc_generate(TARGET MinXcdrVersion FILES MinXcdrVersion.idl)
idlc_generate(TARGET CdrStreamOptimize FILES CdrStreamOptimize.idl WARNINGS no-implicit-extensibility)
idlc_generate(TARGET CdrStreamSkipDefault FILES CdrStreamSkipDefault.idl)
idlc_generate(TARGET SertypeData FILES SertypeData.idl)
if(ENABLE_TYPE_DISCOVERY)
idlc_generate(TARGET XSpace FILES XSpace.idl XSpaceEnum.idl XSpaceMustUnderstand.idl XSpaceTypeConsistencyEnforcement.idl WARNINGS no-implicit-extensibility no-inherit-appendable)
idlc_generate(TARGET XSpaceNoTypeInfo FILES XSpaceNoTypeInfo.idl NO_TYPE_INFO WARNINGS no-implicit-extensibility)
Expand Down Expand Up @@ -89,6 +90,7 @@ set(ddsc_test_sources
"test_oneliner.c"
"test_oneliner.h"
"cdrstream.c"
"sertype.c"
)

if(ENABLE_LIFESPAN)
Expand Down Expand Up @@ -130,7 +132,7 @@ if(ENABLE_SHM)
endif()

target_link_libraries(cunit_ddsc PRIVATE
RoundTrip Space TypesArrayKey WriteTypes InstanceHandleTypes RWData CreateWriter DataRepresentationTypes MinXcdrVersion CdrStreamOptimize CdrStreamSkipDefault ddsc)
RoundTrip Space TypesArrayKey WriteTypes InstanceHandleTypes RWData CreateWriter DataRepresentationTypes MinXcdrVersion CdrStreamOptimize CdrStreamSkipDefault SertypeData ddsc)

if(ENABLE_TYPE_DISCOVERY)
target_link_libraries(cunit_ddsc PRIVATE
Expand Down
20 changes: 20 additions & 0 deletions src/core/ddsc/tests/SertypeData.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright(c) 2023 ZettaScale Technology and others
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
// v. 1.0 which is available at
// http://www.eclipse.org/org/documents/edl-v10.php.
//
// SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause

@final
struct SertypeDefaultCompare1 {
long f1;
};

@final
struct SertypeDefaultCompare2 {
@min(1) @max(10)
long f1;
};
77 changes: 77 additions & 0 deletions src/core/ddsc/tests/sertype.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright(c) 2023 ZettaScale Technology and others
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
// v. 1.0 which is available at
// http://www.eclipse.org/org/documents/edl-v10.php.
//
// SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause

#include "CUnit/Theory.h"
#include "dds/dds.h"
#include "dds/ddsi/ddsi_typelib.h"
#include "dds/ddsi/ddsi_typewrap.h"
#include "test_common.h"
#include "test_util.h"
#include "SertypeData.h"

CU_Test (ddsc_sertype_default, compare)
{
dds_return_t ret;
dds_entity_t domain = dds_create_domain (0, NULL);
CU_ASSERT_FATAL (domain >= 0);
dds_entity_t participant = dds_create_participant (0, NULL, NULL);
CU_ASSERT_FATAL (participant >= 0);

char topic_name[100];
create_unique_topic_name ("ddsc_dynamic_type", topic_name, sizeof (topic_name));

dds_topic_descriptor_t SertypeDefaultCompare1a_desc = SertypeDefaultCompare2_desc;
SertypeDefaultCompare1a_desc.m_typename = "SertypeDefaultCompare1";
dds_entity_t topic1 = dds_create_topic (participant, &SertypeDefaultCompare1_desc, topic_name, NULL, NULL);
dds_entity_t topic2 = dds_create_topic (participant, &SertypeDefaultCompare1a_desc, topic_name, NULL, NULL);

dds_entity_t rd = dds_create_reader (participant, topic1, NULL, NULL);
dds_entity_t wr = dds_create_writer (participant, topic2, NULL, NULL);
sync_reader_writer (participant, rd, participant, wr);

dds_typeinfo_t *rd_type_info, *wr_type_info;
const struct ddsi_sertype *rd_sertype, *wr_sertype;

ret = dds_get_entity_sertype (rd, &rd_sertype);
CU_ASSERT_EQUAL (ret, DDS_RETCODE_OK);
ret = dds_get_entity_sertype (wr, &wr_sertype);
CU_ASSERT_EQUAL (ret, DDS_RETCODE_OK);

#ifdef DDS_HAS_TYPE_DISCOVERY
ret = dds_get_typeinfo (rd, &rd_type_info);
CU_ASSERT_EQUAL_FATAL (ret, DDS_RETCODE_OK);
ret = dds_get_typeinfo (wr, &wr_type_info);
CU_ASSERT_EQUAL_FATAL (ret, DDS_RETCODE_OK);

// Minimal types should be equal, but complete types different because of annotation on type 1a
const ddsi_typeid_t * rd_type_min = ddsi_typeinfo_minimal_typeid (rd_type_info);
const ddsi_typeid_t * wr_type_min = ddsi_typeinfo_minimal_typeid (wr_type_info);
const ddsi_typeid_t * rd_type_compl = ddsi_typeinfo_complete_typeid (rd_type_info);
const ddsi_typeid_t * wr_type_compl = ddsi_typeinfo_complete_typeid (wr_type_info);

CU_ASSERT (ddsi_typeid_compare (rd_type_min, wr_type_min) == 0);
CU_ASSERT (ddsi_typeid_compare (rd_type_compl, wr_type_compl) != 0);

// Sertypes should be different, because of different complete types
CU_ASSERT_NOT_EQUAL (rd_sertype, wr_sertype);
#else
ret = dds_get_typeinfo (rd, &rd_type_info);
CU_ASSERT_NOT_EQUAL_FATAL (ret, DDS_RETCODE_OK);
ret = dds_get_typeinfo (rd, &wr_type_info);
CU_ASSERT_NOT_EQUAL_FATAL (ret, DDS_RETCODE_OK);

// Sertypes should be the same, because other than type-info, types are equal
CU_ASSERT_EQUAL (rd_sertype, wr_sertype);
#endif

dds_free_typeinfo (rd_type_info);
dds_free_typeinfo (wr_type_info);
}