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

GTEST: refactor log handlers using RAII idiom #2958

Merged
merged 3 commits into from
Oct 16, 2018

Conversation

evgeny-leksikov
Copy link
Contributor

What

Replace static API for log handlers set/clean up with scoped_log_handler class

Why ?

Some tests potentially set up handlers and don't clean up them in case of exception, e.g. ucs::test_skip_exception. Tests fail when they run in some magic sequence due to lack of log handlers slots and the following test can't handle expected error:

12:59:52 [----------] 1 test from rc/test_ucp_sockaddr_with_rma_atomic
12:59:52 [ RUN      ] rc/test_ucp_sockaddr_with_rma_atomic.wireup/3
12:59:52 [     INFO ] Testing 65.65.65.12:35126
12:59:52 /scrap/jenkins/workspace/hpc-ucx-pr-2/label/r-vmb-ppc-jenkins/worker/0/contrib/../test/gtest/common/test.cc:260: Failure
12:59:52 Failed
12:59:52 Got 1 errors during the test
12:59:52 

How ?

Using RAII idiom

void test_base::wrap_errors()
{
ucs_log_push_handler(wrap_errors_logger);
test_base::scoped_log_handler::scoped_log_handler(scoped_log_handler_type_t type) {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe pass handler func ptr as a pointer? would not need switch/case, and avoid defining specific function like sockaddr_errs_detector in base class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe also add new C++ and use lambda? For example smth like

    ucs_status_t status;

    {
        scoped_log_handler hide_err(hide_errors_logger);
        status = ucp_atomic_add64(e->ep(), 0, (uintptr_t)memheap_addr + 1, rkey);
    }

    EXPECT_EQ(UCS_ERR_INVALID_PARAM, status);

may be replaced with smth like

    ucs_status_t status = [] (ucs_log_func_t log_func) {
        scoped_log_handler hide_err(log_func);
        return ucp_atomic_add64(e->ep(), 0, (uintptr_t)memheap_addr + 1, rkey);
    } (hide_errors_logger);

    EXPECT_EQ(UCS_ERR_INVALID_PARAM, status);

where hide_errors_logger also may be a local lambda when it's needed

Copy link
Contributor

Choose a reason for hiding this comment

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

i would like that, but today we don't require c11

@swx-jenkins1
Copy link

Test FAILed.
See http://bgate.mellanox.com/jenkins/job/gh-ucx-pr/5423/ for details.

@mellanox-github
Copy link
Contributor

Test FAILed.
See http://hpc-master.lab.mtl.com:8080/job/hpc-ucx-pr/7968/ for details (Mellanox internal link).

Increase scope for reqs array allocated on stack
@mellanox-github
Copy link
Contributor

Test FAILed.
See http://hpc-master.lab.mtl.com:8080/job/hpc-ucx-pr/7974/ for details (Mellanox internal link).

@swx-jenkins1
Copy link

Test FAILed.
See http://bgate.mellanox.com/jenkins/job/gh-ucx-pr/5426/ for details.

@swx-jenkins1
Copy link

Test PASSed.
See http://bgate.mellanox.com/jenkins/job/gh-ucx-pr/5428/ for details.

@mellanox-github
Copy link
Contributor

Test PASSed.
See http://hpc-master.lab.mtl.com:8080/job/hpc-ucx-pr/7976/ for details (Mellanox internal link).

Copy link
Contributor

@yosefe yosefe left a comment

Choose a reason for hiding this comment

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

there are not critical, maybe merge this PR and fix in another PR?

@@ -153,6 +153,11 @@ void ucs_log_pop_handler()
}
}

unsigned ucs_log_handlers_num()
Copy link
Contributor

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()?

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like EXPECT_EQ should be outside the scope?

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, EXPECT_EQ outside the scope

m_errors.clear();

ucs_log_pop_handler();
Copy link
Contributor

Choose a reason for hiding this comment

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

should we use RAII here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

m_errors.clear();

ucs_log_pop_handler();
if (m_num_log_handlers_before != ucs_log_handlers_num()) {
ADD_FAILURE() << "Missed log handler cleanup, "
Copy link
Contributor

Choose a reason for hiding this comment

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

unsigned num_not_removed = ucs_log_handlers_num() - m_num_log_handlers_before;
if (num_not_removed != 0) {
     ADD_FAILURE() << num_not_removed << " log handlers were not removed";
 }

@yosefe yosefe merged commit 366259b into openucx:master Oct 16, 2018
evgeny-leksikov added a commit to evgeny-leksikov/ucx that referenced this pull request Oct 16, 2018
 - address CR comments to openucx#2958
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants