-
Notifications
You must be signed in to change notification settings - Fork 297
Avoid memory leak in unit test driver #4249
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
base: devel
Are you sure you want to change the base?
Conversation
If we add only a subset of tests to the runner (via --re or --deny_re options), we're careful to move the other tests to a "rejects" suite so they'll get deleted there, but the "supertest", the suite holding all the other tests, wasn't getting deleted in those cases. This (on top of my earlier fixes, and using the MOOSE suppressions file for third-party library issues) gets selective valgrind runs of our unit tests clean for me.
Scratch "gets selective valgrind runs of our unit tests clean for me" - I'm still seeing something else, and I'm not sure if it's just something I missed before or a regression from this PR. |
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.
I had some questions that could probably be cleared up if I read the cppunit docs, but I chose not to 🤷♂️
allow_regex_string, allow_regex, | ||
deny_regex_string, deny_regex, | ||
runner, rejects); | ||
if (n_tests_added >= 0) | ||
libMesh::out << "--- Running " << n_tests_added << " tests in total." << std::endl; | ||
if (n_tests_added != -12345) |
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.
Minor comment, but since this is our own magic number that we now actually have to refer to, it might make sense to use libMesh::invalid_uint
or some other named constant.
allow_regex_string, allow_regex, | ||
deny_regex_string, deny_regex, | ||
runner, rejects); | ||
if (n_tests_added >= 0) | ||
libMesh::out << "--- Running " << n_tests_added << " tests in total." << std::endl; | ||
if (n_tests_added != -12345) | ||
owned_suite.reset(suite); |
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.
I guess I don't understand why we don't need to clean up suite
when there's no tests added? From a surface level reading of the code it just looks like registry.makeTest()
returns a dumb pointer whose lifetime we are expected to manage, and we were always leaking it before...
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.
This should clean up suite
when there's no tests added. That'll return n_tests_added == 0
, and 0 != -12345
, so we put suite
in our unique_ptr
and it gets cleaned up.
There's definitely something weird going on here. This patch cleans up the leaked suite from If every test class was complaining then I'd be sure I'm trying to do a double-free here, once from the runner and then once from recursive destruction from the suite, but it's just No, wait, it's too much of a coincidence that the failing |
If we add only a subset of tests to the runner (via --re or --deny_re options), we're careful to move the other tests to a "rejects" suite so they'll get deleted there, but the "supertest", the suite holding all the other tests, wasn't getting deleted in those cases.
This (on top of my earlier fixes, and using the MOOSE suppressions file for third-party library issues) gets selective valgrind runs of our unit tests clean for me. (all-tests runs are clean either way)
This isn't urgent to merge; I still need to run through our examples to look for valgrind issues too. This tiny leak is only a problem because it upsets valgrind, and until we're sure we're ready to make that be a big deal (add a
--error-exitcode=
option to our valgrind recipes), "do our unit tests upset valgrind" isn't a critical question.