Skip to content

Commit

Permalink
Support valgrind-aware builds and fix accidental reads from uninitial…
Browse files Browse the repository at this point in the history
…ized data when hashing ntsa::DomainName
  • Loading branch information
mattrm456 authored Aug 26, 2024
1 parent 02da370 commit 47463b0
Show file tree
Hide file tree
Showing 13 changed files with 329 additions and 43 deletions.
3 changes: 3 additions & 0 deletions cmake/templates/ntccfg_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ namespace ntccfg {
// Build with compiler instrumentation for code coverage.
#define NTC_BUILD_WITH_COVERAGE @NTF_BUILD_WITH_COVERAGE@

// Build with the expectation that executables are run under valgrind.
#define NTC_BUILD_WITH_VALGRIND @NTF_BUILD_WITH_VALGRIND@

// Build from a packaging environment.
#define NTC_BUILD_FROM_PACKAGING @NTF_BUILD_FROM_PACKAGING@

Expand Down
3 changes: 3 additions & 0 deletions cmake/templates/ntscfg_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ namespace ntscfg {
// Build with compiler instrumentation for code coverage.
#define NTS_BUILD_WITH_COVERAGE @NTF_BUILD_WITH_COVERAGE@

// Build with the expectation that executables are run under valgrind.
#define NTS_BUILD_WITH_VALGRIND @NTF_BUILD_WITH_VALGRIND@

// Build from a packaging environment.
#define NTS_BUILD_FROM_PACKAGING @NTF_BUILD_FROM_PACKAGING@

Expand Down
10 changes: 10 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ if [[ -z "${NTF_CONFIGURE_WITH_COVERAGE}" ]]; then
NTF_CONFIGURE_WITH_COVERAGE=0
fi

if [[ -z "${NTF_CONFIGURE_WITH_VALGRIND}" ]]; then
NTF_CONFIGURE_WITH_VALGRIND=0
fi

if [[ -z "${NTF_CONFIGURE_WITH_DOCUMENTATION}" ]]; then
NTF_CONFIGURE_WITH_DOCUMENTATION=0
fi
Expand Down Expand Up @@ -499,6 +503,7 @@ usage()
echo " --with-time-trace Build with time traces enabled [${NTF_CONFIGURE_WITH_TIME_TRACE}]"
echo " --with-time-report Build with time reports enabled [${NTF_CONFIGURE_WITH_TIME_REPORT}]"
echo " --with-coverage Build with code coverage enabled [${NTF_CONFIGURE_WITH_COVERAGE}]"
echo " --with-valgrind Build with tests running under valgrind [${NTF_CONFIGURE_WITH_VALGRIND}]"

echo " --with-applications Build applications [${NTF_CONFIGURE_WITH_APPLICATIONS}]"
echo " --with-usage-examples Build usage examples [${NTF_CONFIGURE_WITH_USAGE_EXAMPLES}]"
Expand Down Expand Up @@ -592,6 +597,8 @@ while true ; do
NTF_CONFIGURE_WITH_TIME_REPORT=1 ; shift ;;
--with-coverage)
NTF_CONFIGURE_WITH_COVERAGE=1 ; shift ;;
--with-valgrind)
NTF_CONFIGURE_WITH_VALGRIND=1 ; shift ;;

--with-bsl)
NTF_CONFIGURE_WITH_BSL=1 ; shift ;;
Expand Down Expand Up @@ -699,6 +706,8 @@ while true ; do
NTF_CONFIGURE_WITH_TIME_REPORT=0 ; shift ;;
--without-coverage)
NTF_CONFIGURE_WITH_COVERAGE=0 ; shift ;;
--without-valgrind)
NTF_CONFIGURE_WITH_VALGRIND=0 ; shift ;;

--without-bsl)
NTF_CONFIGURE_WITH_BSL=0 ; shift ;;
Expand Down Expand Up @@ -844,6 +853,7 @@ export NTF_CONFIGURE_WITH_WARNINGS_AS_ERRORS
export NTF_CONFIGURE_WITH_TIME_TRACE
export NTF_CONFIGURE_WITH_TIME_REPORT
export NTF_CONFIGURE_WITH_COVERAGE
export NTF_CONFIGURE_WITH_VALGRIND

export NTF_CONFIGURE_WITH_BSL
export NTF_CONFIGURE_WITH_BDL
Expand Down
44 changes: 44 additions & 0 deletions configure.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,22 @@ IF NOT DEFINED NTF_CONFIGURE_WITH_WARNINGS_AS_ERRORS (
set NTF_CONFIGURE_WITH_WARNINGS_AS_ERRORS=1
)

IF NOT DEFINED NTF_CONFIGURE_WITH_TIME_TRACE (
set NTF_CONFIGURE_WITH_TIME_TRACE=0
)

IF NOT DEFINED NTF_CONFIGURE_WITH_TIME_REPORT (
set NTF_CONFIGURE_WITH_TIME_REPORT=0
)

IF NOT DEFINED NTF_CONFIGURE_WITH_COVERAGE (
set NTF_CONFIGURE_WITH_COVERAGE=0
)

IF NOT DEFINED NTF_CONFIGURE_WITH_VALGRIND (
set NTF_CONFIGURE_WITH_VALGRIND=0
)

IF NOT DEFINED NTF_CONFIGURE_WITH_DOCUMENTATION (
set NTF_CONFIGURE_WITH_DOCUMENTATION=0
)
Expand Down Expand Up @@ -245,6 +261,18 @@ if not "%1"=="" (
if "%1"=="--with-warnings-as-errors" (
set NTF_CONFIGURE_WITH_WARNINGS_AS_ERRORS=1
)
if "%1"=="--with-time-trace" (
set NTF_CONFIGURE_WITH_TIME_TRACE=1
)
if "%1"=="--with-time-reports" (
set NTF_CONFIGURE_WITH_TIME_REPORTS=1
)
if "%1"=="--with-coverage" (
set NTF_CONFIGURE_WITH_COVERAGE=1
)
if "%1"=="--with-valgrind" (
set NTF_CONFIGURE_WITH_VALGRIND=1
)

if "%1"=="--with-bsl" (
set NTF_CONFIGURE_WITH_BSL=1
Expand Down Expand Up @@ -361,6 +389,18 @@ if not "%1"=="" (
if "%1"=="--without-warnings-as-errors" (
set NTF_CONFIGURE_WITH_WARNINGS_AS_ERRORS=0
)
if "%1"=="--without-time-trace" (
set NTF_CONFIGURE_WITH_TIME_TRACE=0
)
if "%1"=="--without-time-report" (
set NTF_CONFIGURE_WITH_TIME_REPORT=0
)
if "%1"=="--without-coverage" (
set NTF_CONFIGURE_WITH_COVERAGE=0
)
if "%1"=="--without-valgrind" (
set NTF_CONFIGURE_WITH_VALGRIND=0
)

if "%1"=="--without-bsl" (
set NTF_CONFIGURE_WITH_BSL=0
Expand Down Expand Up @@ -810,6 +850,10 @@ echo --with-spin-locks Build with mutually-exclusive locks im
echo --with-recursive-mutexes Build with mutually-exclusive locks implemented as recursive mutexes
echo --with-warnings Build with warnings enabled
echo --with-warnings-as-errors Build with warnings as errors
echo --with-time-trace Build with time traces enabled
echo --with-time-report Build with time reports enabled
echo --with-coverage Build with code coverage enabled
echo --with-valgrind Build with tests running under valgrind

echo --with-documentation Build documentation
echo --with-documentation-internal Build documentation of internals
Expand Down
5 changes: 5 additions & 0 deletions groups/ntc/ntca/ntca_interfaceconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,11 @@ class InterfaceConfig
bsl::ostream& print(bsl::ostream& stream,
int level = 0,
int spacesPerLevel = 4) const;

/// Defines the traits of this type. These traits can be used to select,
/// at compile-time, the most efficient algorithm to manipulate objects
/// of this type.
NTCCFG_DECLARE_NESTED_USES_ALLOCATOR_TRAITS(InterfaceConfig);
};

/// Format the specified 'object' to the specified output 'stream' and
Expand Down
58 changes: 58 additions & 0 deletions groups/ntc/ntcf/ntcf_system.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7129,7 +7129,12 @@ void concernConnectAndShutdown(
// even if connection is not refused or shutdown is called not during
// socket detachment process

#if NTC_BUILD_WITH_VALGRIND
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 10;
#else
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 100;
#endif

const int k_TIMEOUT_MICROSEC = 100;
const char* address = "127.0.0.1:51";

Expand Down Expand Up @@ -7167,7 +7172,11 @@ void concernConnectEndpoint1(const bsl::shared_ptr<ntci::Scheduler>& scheduler,
// Concern: Connect to endpoint periodically fails but eventually succeeds
// Testing: ECONNREFUSED, connection established

#if NTC_BUILD_WITH_VALGRIND
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 10;
#else
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 100;
#endif

const double k_RETRY_INTERVAL_SECONDS = 0.1;

Expand Down Expand Up @@ -7572,7 +7581,11 @@ void concernConnectEndpoint4(const bsl::shared_ptr<ntci::Scheduler>& scheduler,

BSLS_LOG_WARN("ECONNREFUSED (x4), ECANCELED");

#if NTC_BUILD_WITH_VALGRIND
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 10;
#else
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 100;
#endif

const double k_RETRY_INTERVAL_SECONDS = 0.1;

Expand Down Expand Up @@ -7729,7 +7742,11 @@ void concernConnectEndpoint5(const bsl::shared_ptr<ntci::Scheduler>& scheduler,

BSLS_LOG_WARN("ETIMEDOUT (x4), ECANCELED");

#if NTC_BUILD_WITH_VALGRIND
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 10;
#else
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 100;
#endif

const double k_RETRY_INTERVAL_SECONDS = 0.1;

Expand Down Expand Up @@ -7889,7 +7906,11 @@ void concernConnectEndpoint6(const bsl::shared_ptr<ntci::Scheduler>& scheduler,

BSLS_LOG_WARN("ECONNREFUSED (x4), ETIMEDOUT/ECANCELED");

#if NTC_BUILD_WITH_VALGRIND
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 10;
#else
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 100;
#endif

const double k_RETRY_INTERVAL_SECONDS = 0.1;

Expand Down Expand Up @@ -8015,7 +8036,11 @@ void concernConnectEndpoint7(const bsl::shared_ptr<ntci::Scheduler>& scheduler,

BSLS_LOG_WARN("ETIMEDOUT (x4), ETIMEDOUT/ECANCELED");

#if NTC_BUILD_WITH_VALGRIND
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 10;
#else
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 100;
#endif

const double k_RETRY_INTERVAL_SECONDS = 0.1;

Expand Down Expand Up @@ -8145,7 +8170,11 @@ void concernConnectEndpoint8(const bsl::shared_ptr<ntci::Scheduler>& scheduler,
BSLS_LOG_WARN(
"ETIMEDOUT/ECONNREFUSED/ECONNABORTED (x100) (instantaneous)");

#if NTC_BUILD_WITH_VALGRIND
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 10;
#else
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 100;
#endif

const double k_RETRY_INTERVAL_SECONDS = 0.1;

Expand Down Expand Up @@ -8244,7 +8273,11 @@ void concernConnectName1(const bsl::shared_ptr<ntci::Scheduler>& scheduler,
// Concern: Connect to name periodically fails but eventually succeeds
// Testing: ECONNREFUSED, connection established

#if NTC_BUILD_WITH_VALGRIND
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 10;
#else
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 100;
#endif

const double k_RETRY_INTERVAL_SECONDS = 0.1;

Expand Down Expand Up @@ -8662,7 +8695,11 @@ void concernConnectName4(const bsl::shared_ptr<ntci::Scheduler>& scheduler,

BSLS_LOG_WARN("ECONNREFUSED (x4), ECANCELED");

#if NTC_BUILD_WITH_VALGRIND
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 10;
#else
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 100;
#endif

const double k_RETRY_INTERVAL_SECONDS = 0.1;

Expand Down Expand Up @@ -8819,7 +8856,11 @@ void concernConnectName5(const bsl::shared_ptr<ntci::Scheduler>& scheduler,

BSLS_LOG_WARN("ETIMEDOUT (x4), ECANCELED");

#if NTC_BUILD_WITH_VALGRIND
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 10;
#else
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 100;
#endif

const double k_RETRY_INTERVAL_SECONDS = 0.1;

Expand Down Expand Up @@ -8991,7 +9032,11 @@ void concernConnectName6(const bsl::shared_ptr<ntci::Scheduler>& scheduler,

BSLS_LOG_WARN("ECONNREFUSED (x4), ETIMEDOUT/ECANCELED");

#if NTC_BUILD_WITH_VALGRIND
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 10;
#else
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 100;
#endif

const double k_RETRY_INTERVAL_SECONDS = 0.1;

Expand Down Expand Up @@ -9116,7 +9161,11 @@ void concernConnectName7(const bsl::shared_ptr<ntci::Scheduler>& scheduler,

BSLS_LOG_WARN("ETIMEDOUT (x4), ETIMEDOUT/ECANCELED");

#if NTC_BUILD_WITH_VALGRIND
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 10;
#else
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 100;
#endif

const double k_RETRY_INTERVAL_SECONDS = 0.1;

Expand Down Expand Up @@ -9260,7 +9309,11 @@ void concernConnectName8(const bsl::shared_ptr<ntci::Scheduler>& scheduler,
BSLS_LOG_WARN(
"ETIMEDOUT/ECONNREFUSED/ECONNABORTED (x100) (instantaneous)");

#if NTC_BUILD_WITH_VALGRIND
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 10;
#else
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 100;
#endif

const double k_RETRY_INTERVAL_SECONDS = 0.1;

Expand Down Expand Up @@ -12355,7 +12408,12 @@ void concernStreamSocketConnectDeadlineTimerClose(
// Concern: validate that connect deadline timer is automatically closed
// when the socket is closed and then destroyed

#if NTC_BUILD_WITH_VALGRIND
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 6;
#else
const bsl::size_t k_MAX_CONNECTION_ATTEMPTS = 60;
#endif

const int k_DEADLINE_INTERVAL_HOURS = 1;
const int k_RETRY_INTERVAL_MINUTES = 1;

Expand Down
Loading

0 comments on commit 47463b0

Please sign in to comment.