-
Notifications
You must be signed in to change notification settings - Fork 423
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
GTEST: refactor log handlers using RAII idiom #2958
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,8 @@ test_base::test_base() : | |
m_num_threads(1), | ||
m_num_valgrind_errors_before(0), | ||
m_num_errors_before(0), | ||
m_num_warnings_before(0) | ||
m_num_warnings_before(0), | ||
m_num_log_handlers_before(0) | ||
{ | ||
push_config(); | ||
} | ||
|
@@ -123,26 +124,6 @@ void test_base::pop_config() | |
m_config_stack.pop_back(); | ||
} | ||
|
||
void test_base::hide_errors() | ||
{ | ||
ucs_log_push_handler(hide_errors_logger); | ||
} | ||
|
||
void test_base::hide_warnings() | ||
{ | ||
ucs_log_push_handler(hide_warns_logger); | ||
} | ||
|
||
void test_base::wrap_errors() | ||
{ | ||
ucs_log_push_handler(wrap_errors_logger); | ||
} | ||
|
||
void test_base::restore_errors() | ||
{ | ||
ucs_log_pop_handler(); | ||
} | ||
|
||
ucs_log_func_rc_t | ||
test_base::count_warns_logger(const char *file, unsigned line, const char *function, | ||
ucs_log_level_t level, const char *message, va_list ap) | ||
|
@@ -224,6 +205,7 @@ void test_base::SetUpProxy() { | |
m_num_errors_before = m_total_errors; | ||
|
||
m_errors.clear(); | ||
m_num_log_handlers_before = ucs_log_handlers_num(); | ||
ucs_log_push_handler(count_warns_logger); | ||
|
||
try { | ||
|
@@ -248,9 +230,15 @@ void test_base::TearDownProxy() { | |
cleanup(); | ||
} | ||
|
||
ucs_log_pop_handler(); | ||
m_errors.clear(); | ||
|
||
ucs_log_pop_handler(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we use RAII here too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that calling destructor implicitly is a RAII... more classes in inheritance to define ordering of destructors will only complicate the code. Do you know how to use it other way? |
||
if (m_num_log_handlers_before != ucs_log_handlers_num()) { | ||
ADD_FAILURE() << "Missed log handler cleanup, " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
<< m_num_log_handlers_before << " != " | ||
<< ucs_log_handlers_num(); | ||
} | ||
|
||
int num_valgrind_errors = VALGRIND_COUNT_ERRORS - m_num_valgrind_errors_before; | ||
if (num_valgrind_errors > 0) { | ||
ADD_FAILURE() << "Got " << num_valgrind_errors << " valgrind errors during the test"; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,12 +63,13 @@ void test_ucp_atomic::unaligned_blocking_add64(entity *e, size_t max_size, | |
void *memheap_addr, ucp_rkey_h rkey, | ||
std::string& expected_data) | ||
{ | ||
/* Test that unaligned addresses generate error */ | ||
ucs_status_t status; | ||
hide_errors(); | ||
status = ucp_atomic_add64(e->ep(), 0, (uintptr_t)memheap_addr + 1, rkey); | ||
restore_errors(); | ||
EXPECT_EQ(UCS_ERR_INVALID_PARAM, status); | ||
{ | ||
/* Test that unaligned addresses generate error */ | ||
scoped_log_handler slh(hide_errors_logger); | ||
ucs_status_t status = ucp_atomic_add64(e->ep(), 0, | ||
(uintptr_t)memheap_addr + 1, rkey); | ||
EXPECT_EQ(UCS_ERR_INVALID_PARAM, status); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like EXPECT_EQ should be outside the scope? |
||
} | ||
expected_data.clear(); | ||
} | ||
|
||
|
@@ -106,15 +107,13 @@ void test_ucp_atomic::unaligned_nb_post(entity *e, size_t max_size, | |
void *memheap_addr, ucp_rkey_h rkey, | ||
std::string& expected_data) | ||
{ | ||
/* Test that unaligned addresses generate error */ | ||
ucs_status_t status; | ||
|
||
hide_errors(); | ||
status = test_ucp_atomic::ucp_atomic_post_nbi<uint64_t>(e->ep(), OP, 0, | ||
(void *)((uintptr_t)memheap_addr + 1), | ||
rkey); | ||
restore_errors(); | ||
EXPECT_EQ(UCS_ERR_INVALID_PARAM, status); | ||
{ | ||
/* Test that unaligned addresses generate error */ | ||
scoped_log_handler slh(hide_errors_logger); | ||
ucs_status_t status = test_ucp_atomic::ucp_atomic_post_nbi<uint64_t> | ||
(e->ep(), OP, 0, (void *)((uintptr_t)memheap_addr + 1), rkey); | ||
EXPECT_EQ(UCS_ERR_INVALID_PARAM, status); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, EXPECT_EQ outside the scope |
||
} | ||
expected_data.clear(); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe ucs_log_num_handlers()?