Skip to content

Commit

Permalink
Disable ptr changed checks in loan test in case address sanitizer is …
Browse files Browse the repository at this point in the history
…not enabled

Signed-off-by: Dennis Potman <[email protected]>
  • Loading branch information
dpotman committed Sep 19, 2023
1 parent 6a58899 commit 0310c89
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ if(SANITIZER)
if(san STREQUAL "address")
add_compile_options("-fno-omit-frame-pointer")
add_link_options("-fno-omit-frame-pointer")
set(DDS_BUILD_OPTION_WITH_ASAN YES)
endif()
if(san AND NOT san STREQUAL "none")
message(STATUS "Enabling sanitizer: ${san}")
Expand Down
1 change: 1 addition & 0 deletions src/core/ddsc/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ set_tests_properties(
ENVIRONMENT "${CUnit_ddsc_config_simple_udp_env}")

configure_file("deadline_update.h.in" "deadline_update.h")
configure_file("build_options.h.in" "build_options.h")

if(ENABLE_DEADLINE_MISSED)
foreach(t
Expand Down
17 changes: 17 additions & 0 deletions src/core/ddsc/tests/build_options.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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

#ifndef DDS_DDSC_TEST_BUILD_OPTIONS_H
#define DDS_DDSC_TEST_BUILD_OPTIONS_H

/* Whether or not address sanitizer is enabled */
#cmakedefine DDS_BUILD_OPTION_WITH_ASAN 1

#endif // DDS_DDSC_TEST_BUILD_OPTIONS_H
49 changes: 42 additions & 7 deletions src/core/ddsc/tests/loan.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stdio.h>
#include "dds/dds.h"
#include "test_common.h"
#include "build_options.h"

static dds_entity_t participant, topic, reader, writer, read_condition, read_condition_unread;

Expand Down Expand Up @@ -74,6 +75,7 @@ CU_Test (ddsc_loan, bad_params, .init = create_entities, .fini = delete_entities
CU_ASSERT (result == DDS_RETCODE_ILLEGAL_OPERATION);
}


CU_Test (ddsc_loan, success, .init = create_entities, .fini = delete_entities)
{
const RoundTripModule_DataType s = {
Expand Down Expand Up @@ -108,7 +110,14 @@ CU_Test (ddsc_loan, success, .init = create_entities, .fini = delete_entities)
/* read 3, return: should work fine, causes allocating new ptrs */
n = dds_read (reader, ptrs, si, 3, 3);
CU_ASSERT_FATAL (n == 3);
CU_ASSERT_FATAL (ptrs[0] != NULL && ptrs[0] != ptrscopy[0] && ptrs[1] != NULL && ptrs[2] != NULL);
CU_ASSERT_FATAL (ptrs[0] != NULL && ptrs[1] != NULL && ptrs[2] != NULL);

#ifdef DDS_BUILD_OPTION_WITH_ASAN
// only with asan a new allocation gets an address not used before in this test
CU_ASSERT_FATAL (ptrs[0] != ptrscopy[0]);
#else
(void) ptrscopy;
#endif

/* read 3, letting read allocate */
int32_t n2;
Expand Down Expand Up @@ -178,7 +187,13 @@ CU_Test (ddsc_loan, take_cleanup, .init = create_entities, .fini = delete_entiti
CU_ASSERT_FATAL (result == 0);
n = dds_take (reader, ptrs, si, 1, 1);
CU_ASSERT_FATAL (n == 1);
CU_ASSERT_FATAL (ptrs[0] != NULL && ptrs[0] != ptr0copy && ptrs[1] == NULL);
CU_ASSERT_FATAL (ptrs[0] != NULL && ptrs[1] == NULL);
#ifdef DDS_BUILD_OPTION_WITH_ASAN
// only with asan a new allocation gets an address not used before in this test
CU_ASSERT_FATAL (ptrs[0] != ptr0copy);
#else
(void) ptr0copy;
#endif
result = dds_return_loan (reader, ptrs, n);
CU_ASSERT_FATAL (result == DDS_RETCODE_OK);

Expand All @@ -193,7 +208,10 @@ CU_Test (ddsc_loan, take_cleanup, .init = create_entities, .fini = delete_entiti
CU_ASSERT_FATAL (result == 0);
n = dds_take (reader, ptrs, si, 1, 1);
CU_ASSERT_FATAL (n == 1);
CU_ASSERT_FATAL (ptrs[0] != NULL && ptrs[0] != ptr0copy && ptrs[1] == NULL);
CU_ASSERT_FATAL (ptrs[0] != NULL && ptrs[1] == NULL);
#ifdef DDS_BUILD_OPTION_WITH_ASAN
CU_ASSERT_FATAL (ptrs[0] != ptr0copy);
#endif

/* take that fails (with the loan still out) must not allocate memory */
int32_t n2;
Expand All @@ -209,7 +227,10 @@ CU_Test (ddsc_loan, take_cleanup, .init = create_entities, .fini = delete_entiti
CU_ASSERT_FATAL (result == 0);
n = dds_take (reader, ptrs, si, 1, 1);
CU_ASSERT_FATAL (n == 1);
CU_ASSERT_FATAL (ptrs[0] != NULL && ptrs[0] != ptr0copy && ptrs[1] == NULL);
CU_ASSERT_FATAL (ptrs[0] != NULL && ptrs[1] == NULL);
#ifdef DDS_BUILD_OPTION_WITH_ASAN
CU_ASSERT_FATAL (ptrs[0] != ptr0copy);
#endif
result = dds_return_loan (reader, ptrs, n);
CU_ASSERT_FATAL (result == DDS_RETCODE_OK);
}
Expand Down Expand Up @@ -252,7 +273,14 @@ CU_Test (ddsc_loan, read_cleanup, .init = create_entities, .fini = delete_entiti
CU_ASSERT_FATAL (result == 0);
n = dds_read (read_condition_unread, ptrs, si, 1, 1);
CU_ASSERT_FATAL (n == 1);
CU_ASSERT_FATAL (ptrs[0] != NULL && ptrs[0] != ptr0copy && ptrs[1] == NULL);
CU_ASSERT_FATAL (ptrs[0] != NULL && ptrs[1] == NULL);
#ifdef DDS_BUILD_OPTION_WITH_ASAN
// only with asan a new allocation gets an address not used before in this test
CU_ASSERT_FATAL (ptrs[0] != ptr0copy);
#else
(void) ptr0copy;
#endif

ptr0copy = ptrs[0];
result = dds_return_loan (reader, ptrs, n);
CU_ASSERT_FATAL (result == DDS_RETCODE_OK);
Expand All @@ -268,7 +296,10 @@ CU_Test (ddsc_loan, read_cleanup, .init = create_entities, .fini = delete_entiti
CU_ASSERT_FATAL (result == 0);
n = dds_read (read_condition_unread, ptrs, si, 1, 1);
CU_ASSERT_FATAL (n == 1);
CU_ASSERT_FATAL (ptrs[0] != NULL && ptrs[0] != ptr0copy && ptrs[1] == NULL);
CU_ASSERT_FATAL (ptrs[0] != NULL && ptrs[1] == NULL);
#ifdef DDS_BUILD_OPTION_WITH_ASAN
CU_ASSERT_FATAL (ptrs[0] != ptr0copy);
#endif

/* take that fails (with the loan still out), no memory allocated */
int32_t n2;
Expand All @@ -284,7 +315,11 @@ CU_Test (ddsc_loan, read_cleanup, .init = create_entities, .fini = delete_entiti
CU_ASSERT_FATAL (result == 0);
n = dds_read (read_condition_unread, ptrs, si, 1, 1);
CU_ASSERT_FATAL (n == 1);
CU_ASSERT_FATAL (ptrs[0] != NULL && ptrs[0] != ptr0copy && ptrs[1] == NULL);
CU_ASSERT_FATAL (ptrs[0] != NULL && ptrs[1] == NULL);
#ifdef DDS_BUILD_OPTION_WITH_ASAN
CU_ASSERT_FATAL (ptrs[0] != ptr0copy);
#endif
result = dds_return_loan (reader, ptrs, n);
CU_ASSERT_FATAL (result == DDS_RETCODE_OK);
}

0 comments on commit 0310c89

Please sign in to comment.