Bug 1419196 - Use the "threadsafe" variant of gtest death tests. r=ted draft
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 24 Nov 2017 14:22:20 +0900
changeset 703839 84d696678ee69ee2bf6f6d999cf6a90bfa3d3f82
parent 703796 895e1f5cc6170e8bf4497a533aaed00d37797aa0
child 741925 963d4219af6c344d562db5f502d716a6e6149274
push id90988
push userbmo:mh+mozilla@glandium.org
push dateMon, 27 Nov 2017 21:34:18 +0000
reviewersted
bugs1419196
milestone59.0a1
Bug 1419196 - Use the "threadsafe" variant of gtest death tests. r=ted Because the default "fast" variant uses fork() on !windows, death tests are dangerous, as they themselves say. There are race conditions involving locks that lead to dead locks in the death test process while disabling the crash reporter (currently, but this could happen for different code, even the tested code itself). See https://bugzilla.mozilla.org/show_bug.cgi?id=1419196#c7 for details. Using the "threadsafe" variant creates new processes for each death test. This is notably slower, but can't dead-lock because of some random lock being held by some random other thread at the moment fork occurred.
python/mozbuild/mozbuild/mach_commands.py
testing/gtest/rungtests.py
--- a/python/mozbuild/mozbuild/mach_commands.py
+++ b/python/mozbuild/mozbuild/mach_commands.py
@@ -553,17 +553,17 @@ class GTestCommands(MachCommandBase):
     def gtest(self, shuffle, jobs, gtest_filter, tbpl_parser, debug, debugger,
               debugger_args):
 
         # We lazy build gtest because it's slow to link
         self._run_make(directory="testing/gtest", target='gtest',
                        print_directory=False, ensure_exit_code=True)
 
         app_path = self.get_binary_path('app')
-        args = [app_path, '-unittest'];
+        args = [app_path, '-unittest', '--gtest_death_test_style=threadsafe'];
 
         if debug or debugger or debugger_args:
             args = self.prepend_debugger_args(args, debugger, debugger_args)
 
         cwd = os.path.join(self.topobjdir, '_tests', 'gtest')
 
         if not os.path.isdir(cwd):
             os.makedirs(cwd)
--- a/testing/gtest/rungtests.py
+++ b/testing/gtest/rungtests.py
@@ -52,17 +52,18 @@ class GTests(object):
         stream_output = mozprocess.StreamOutput(sys.stdout)
         process_output = stream_output
         if utility_path:
             stack_fixer = get_stack_fixer_function(utility_path, symbols_path)
             if stack_fixer:
                 process_output = lambda line: stream_output(stack_fixer(line))
 
 
-        proc = mozprocess.ProcessHandler([prog, "-unittest"],
+        proc = mozprocess.ProcessHandler([prog, "-unittest",
+                                         "--gtest_death_test_style=threadsafe"],
                                          cwd=cwd,
                                          env=env,
                                          processOutputLine=process_output)
         #TODO: After bug 811320 is fixed, don't let .run() kill the process,
         # instead use a timeout in .wait() and then kill to get a stack.
         proc.run(timeout=GTests.TEST_PROC_TIMEOUT,
                  outputTimeout=GTests.TEST_PROC_NO_OUTPUT_TIMEOUT)
         proc.wait()