2018-03-27 14:30:46 -04:00
|
|
|
"""The unittest.TestCase for C++ unit tests."""
|
2024-05-16 18:00:17 -04:00
|
|
|
|
2021-06-15 17:51:01 -04:00
|
|
|
import os
|
2024-05-14 11:07:04 -07:00
|
|
|
from typing import Optional
|
2017-06-14 20:44:52 -04:00
|
|
|
|
2024-05-14 11:07:04 -07:00
|
|
|
from buildscripts.resmokelib import config, core, utils, logging
|
2020-06-17 17:41:54 +03:00
|
|
|
from buildscripts.resmokelib.testing.testcases import interface
|
2017-06-14 20:44:52 -04:00
|
|
|
|
|
|
|
|
|
2018-03-06 16:28:23 -05:00
|
|
|
class CPPUnitTestCase(interface.ProcessTestCase):
|
2018-03-27 14:30:46 -04:00
|
|
|
"""A C++ unit test to execute."""
|
2017-06-14 20:44:52 -04:00
|
|
|
|
|
|
|
|
REGISTERED_NAME = "cpp_unit_test"
|
|
|
|
|
|
2024-05-16 18:00:17 -04:00
|
|
|
def __init__(
|
|
|
|
|
self,
|
|
|
|
|
logger: logging.Logger,
|
|
|
|
|
program_executables: list[str],
|
|
|
|
|
program_options: Optional[dict] = None,
|
|
|
|
|
):
|
2018-03-27 14:30:46 -04:00
|
|
|
"""Initialize the CPPUnitTestCase with the executable to run."""
|
2017-06-14 20:44:52 -04:00
|
|
|
|
2024-05-14 11:07:04 -07:00
|
|
|
assert len(program_executables) == 1
|
|
|
|
|
interface.ProcessTestCase.__init__(self, logger, "C++ unit test", program_executables[0])
|
2017-06-14 20:44:52 -04:00
|
|
|
|
2024-05-14 11:07:04 -07:00
|
|
|
self.program_executable = program_executables[0]
|
2017-06-14 20:44:52 -04:00
|
|
|
self.program_options = utils.default_if_none(program_options, {}).copy()
|
|
|
|
|
|
2021-06-15 17:51:01 -04:00
|
|
|
def run_test(self):
|
|
|
|
|
"""Run the test."""
|
|
|
|
|
try:
|
|
|
|
|
super().run_test()
|
|
|
|
|
except self.failureException:
|
|
|
|
|
if config.UNDO_RECORDER_PATH:
|
|
|
|
|
# Record the list of failed tests so we can upload them to the Evergreen task.
|
|
|
|
|
# Non-recorded tests rely on the core dump content to identify the test binaries.
|
2024-05-16 18:00:17 -04:00
|
|
|
with open("failed_recorded_tests.txt", "a") as failure_list:
|
2021-06-15 17:51:01 -04:00
|
|
|
failure_list.write(self.program_executable)
|
|
|
|
|
failure_list.write("\n")
|
|
|
|
|
self.logger.exception(
|
|
|
|
|
"*** Failed test run was recorded. ***\n"
|
|
|
|
|
"For instructions on using the recording instead of core dumps, see\n"
|
|
|
|
|
"https://wiki.corp.mongodb.com/display/COREENG/Time+Travel+Debugging+in+MongoDB\n"
|
2024-05-16 18:00:17 -04:00
|
|
|
"For questions or bug reports, please reach out in #server-testing"
|
|
|
|
|
)
|
2021-06-15 17:51:01 -04:00
|
|
|
|
|
|
|
|
# Archive any available recordings if there's any failure. It's possible a problem
|
|
|
|
|
# with the recorder will cause no recordings to be generated.
|
|
|
|
|
self._cull_recordings(os.path.basename(self.program_executable))
|
|
|
|
|
raise
|
|
|
|
|
|
2017-06-14 20:44:52 -04:00
|
|
|
def _make_process(self):
|
2024-05-16 18:00:17 -04:00
|
|
|
return core.programs.make_process(
|
|
|
|
|
self.logger, [self.program_executable], **self.program_options
|
|
|
|
|
)
|