Skip to content

Commit

Permalink
Merge pull request #10024 from yosefe/topic/test-callbackq-fix-test-c…
Browse files Browse the repository at this point in the history
…allbackq-test-callbackq

TEST/CALLBACKQ: Fix test_callbackq.test_callbackq test failures
  • Loading branch information
yosefe authored Aug 29, 2024
2 parents c5d054b + ea32acd commit 173b905
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 36 deletions.
26 changes: 26 additions & 0 deletions test/gtest/common/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class test_base {

typedef std::vector<ucs_global_opts_t> config_stack_t;

static constexpr double DEFAULT_TIMEOUT_SEC = 10.0;

void SetUpProxy();
void TearDownProxy();
void TestBodyProxy();
Expand All @@ -88,6 +90,30 @@ class test_base {

virtual void test_body() = 0;

template<typename Cond, typename Wait>
void wait_for_cond(Cond cond, Wait wait,
double timeout = DEFAULT_TIMEOUT_SEC) const
{
ucs_time_t deadline = get_deadline(timeout);
while ((ucs_get_time() < deadline) && (!cond())) {
wait();
}
}

template<typename T, typename Wait>
void wait_for_value(const volatile T *var, T value, Wait wait,
double timeout = DEFAULT_TIMEOUT_SEC) const
{
wait_for_cond([var, value]() { return *var == value; }, wait, timeout);
}

template<typename T>
void wait_for_value(const volatile T *var, T value,
double timeout = DEFAULT_TIMEOUT_SEC) const
{
wait_for_value(var, value, sched_yield, timeout);
}

static ucs_log_func_rc_t
common_logger(ucs_log_level_t log_level_to_handle, bool print,
std::vector<std::string> &messages_vec, size_t limit,
Expand Down
8 changes: 7 additions & 1 deletion test/gtest/configure.m4
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ CHECK_COMPILER_FLAG([--diag_suppress 186], [--diag_suppress 186],
[AC_LANG_SOURCE([[int main(int argc, char** argv){return 0;}]])],
[GTEST_CXXFLAGS="$GTEST_CXXFLAGS --diag_suppress 186"],
[])

# error #236: controlling expression is constant
CHECK_COMPILER_FLAG([--diag_suppress 236], [--diag_suppress 236],
[AC_LANG_SOURCE([[int main(int argc, char** argv){return 0;}]])],
[GTEST_CXXFLAGS="$GTEST_CXXFLAGS --diag_suppress 236"],
[])

# Avoid warnings about C++17 mangling compatibility
CHECK_COMPILER_FLAG([-Wno-noexcept-type], [-Wno-noexcept-type],
[AC_LANG_SOURCE([[int main(int argc, char** argv){return 0;}]])],
[GTEST_CXXFLAGS="$GTEST_CXXFLAGS -Wno-noexcept-type "],
[])

AC_LANG_POP([C++])

AC_SUBST([GTEST_CXXFLAGS], [$GTEST_CXXFLAGS])
Expand Down
12 changes: 5 additions & 7 deletions test/gtest/ucp/ucp_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,12 @@ class ucp_test : public ucp_test_base,
}
}

template <typename T>
void wait_for_value(volatile T *var, T value, double timeout = 10.0) const
template<typename T>
void wait_for_value(const volatile T *var, T value,
double timeout = DEFAULT_TIMEOUT_SEC) const
{
ucs_time_t deadline = ucs_get_time() +
ucs_time_from_sec(timeout) * ucs::test_time_multiplier();
while ((ucs_get_time() < deadline) && (*var != value)) {
short_progress_loop();
}
test_base::wait_for_value(
var, value, [this]() { short_progress_loop(); }, timeout);
}

static const ucp_datatype_t DATATYPE;
Expand Down
1 change: 1 addition & 0 deletions test/gtest/ucs/test_callbackq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ UCS_MT_TEST_F(test_callbackq, oneshot_mt, 10) {

add_oneshot(&ctx);
dispatch(100);
wait_for_value(&ctx.count, 1u);
EXPECT_EQ(1u, ctx.count);
}

Expand Down
46 changes: 18 additions & 28 deletions test/gtest/uct/uct_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@


#define DEFAULT_DELAY_MS 1.0
#define DEFAULT_TIMEOUT_SEC 10.0
#define DEFAULT_VARIANT 0

#define UCT_TEST_CALL_AND_TRY_AGAIN(_func, _res) \
Expand Down Expand Up @@ -326,8 +325,8 @@ class uct_test : public testing::TestWithParam<const resource*>,
template <typename T>
void wait_for_flag(volatile T *flag, double timeout = DEFAULT_TIMEOUT_SEC) const
{
ucs_time_t deadline = ucs_get_time() +
ucs_time_from_sec(timeout) * ucs::test_time_multiplier();
using ucs::get_deadline;
ucs_time_t deadline = get_deadline(timeout);
while ((ucs_get_time() < deadline) && (!(*flag))) {
short_progress_loop();
}
Expand All @@ -337,47 +336,38 @@ class uct_test : public testing::TestWithParam<const resource*>,
void wait_for_bits(FlagType *flag, MaskType mask,
double timeout = DEFAULT_TIMEOUT_SEC) const
{
ucs_time_t deadline = ucs_get_time() +
ucs_time_from_sec(timeout) *
ucs::test_time_multiplier();
using ucs::get_deadline;
ucs_time_t deadline = get_deadline(timeout);
while ((ucs_get_time() < deadline) && (!ucs_test_all_flags(*flag, mask))) {
/* Don't do short_progress_loop() to avoid extra timings */
progress_mt();
}
}

template <typename T>
void wait_for_value(volatile T *var, T value, bool progress,
void wait_for_value(const volatile T *var, T value, bool progress,
double timeout = DEFAULT_TIMEOUT_SEC) const
{
ucs_time_t deadline = ucs_get_time() +
ucs_time_from_sec(timeout) * ucs::test_time_multiplier();
while ((ucs_get_time() < deadline) && (*var != value)) {
if (progress) {
short_progress_loop();
} else {
twait();
}
}
test_base::wait_for_value(
var, value,
[this, progress]() {
progress ? short_progress_loop() : twait();
},
timeout);
}

template <typename T>
void wait_for_value_change(volatile T *var, entity *e = NULL,
bool progress = true,
double timeout = DEFAULT_TIMEOUT_SEC) const
{
ucs_time_t deadline = ucs_get_time() +
ucs_time_from_sec(timeout) *
ucs::test_time_multiplier();
T initial_value = *var;

while ((ucs_get_time() < deadline) && (*var == initial_value)) {
if (progress) {
short_progress_loop(DEFAULT_DELAY_MS, e);
} else {
twait();
}
}
const T initial_value = *var;
wait_for_cond([var, initial_value]() { return *var != initial_value; },
[this, progress, e]() {
progress ? short_progress_loop(DEFAULT_DELAY_MS, e) :
twait();
},
timeout);
}

virtual void init();
Expand Down

0 comments on commit 173b905

Please sign in to comment.