DescriptionThis code modifies gtest to run each test in a separate process. This forces the OS to cleanup (release memory, release handles) after every test. It also protects the main process against a test crashing. Please see my original mailing list post for more information: http://groups.google.com/group/googletestframework/browse_thread/thread/5690c5cc91065ce0#
This implementation:
- Changes class Test to pure-virtual
- Adds class NormalTest with the original Test::Run() behavior
- Adds class SeparateProcessTest with a new Run() that executes TestBody() in a child process.
- Adds class ChildProcessPerThreadTestPartResultReportHelper which is a listener (in the child) that sends each assertion results across the pipe to the parent.
This effort started as a copy of Death Tests, so many of the same restrictions apply. Some known issues:
- Has only been tested on my PC with VS2010
- Assumes SeparateProcessTest, doesn't have a way to choose between SeparateProcessTest and NormalTest
- Doesn't compile using gtest-all.cc due to namespace collisions. For now just gtest-separateprocess-test.cc to the *.vcproj
- In case of crash, the AssertHelper output will have a bogus file and line number. There's no way to know what was excuting at the time of crash.
- Run() doesn't work with SEH since the child's result forwarder is on the stack. Uses the non-SEH version now.
- RecordProperty doesn't seem to work, I suppose it doesn't go through the listener api?
- SetUp and TearDown run in both parent and child, they should probably run only once (in the child)
- Some conditions (sometimes ctrl-c in parent) will hang the child process. Use task manager to terminate it manually.
- TestWithParam is hardcoded because it needs to derive from either NormalTest or SeparateProcessTest. This is not very clean.
- Debugging can be quite difficult, since it's attached to the parent process. Need to run as a NormalTest if you expect to hit breakpoints within the test.
- Didn't understand the factory, so I just tried my best to imitate how the private bits get hidden.
Please take a look and comment.
Patch Set 1 #
MessagesTotal messages: 3
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||