[all-commits] [llvm/llvm-project] dfbcee: Prevent deadlocks in death tests.

martinboehme via All-commits all-commits at lists.llvm.org
Wed Jun 14 21:29:19 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: dfbcee286b9b96751014ebc5ba5290e42796be37
      https://github.com/llvm/llvm-project/commit/dfbcee286b9b96751014ebc5ba5290e42796be37
  Author: Martin Braenne <mboehme at google.com>
  Date:   2023-06-15 (Thu, 15 Jun 2023)

  Changed paths:
    M third-party/unittest/UnitTestMain/TestMain.cpp

  Log Message:
  -----------
  Prevent deadlocks in death tests.

We have recently started seeing deadlocks in death tests while running in an internal test environment.

Per the documentation here, there are issues with death tests in the presence of threads:

https://github.com/google/googletest/blob/main/docs/advanced.md#death-tests-and-threads

To avoid the deadlocks, I first tried appending `DeathTest` to the relevant test suite names, which has the effect of running these test suites before all other tests. However, this did not prevent the deadlocks.

This patch therefore uses the option of setting the `death_test_style` flag to `"threadsafe"` (see description in the page linked above under "Death Test Styles"), and this prevents the deadlocks.

The documentation notes that the "threadsafe" death test style "trades increased test execution time (potentially dramatically so) for improved thread safety". This is because, to execute a death test, "threadsafe" does a "fork + exec", then re-executes the current test in the child process, whereas the default "fast" death test style does only a fork (on those platforms that support it). However, as we have relatively few death tests, the increased execution time does not make a big difference in total test execution time in my testing.

Note that other projects, such as Chromium, also choose to set the "threadsafe" death test style globally:

https://source.chromium.org/chromium/chromium/src/+/main:base/test/test_suite.cc;l=367

Reviewed By: hans

Differential Revision: https://reviews.llvm.org/D152696




More information about the All-commits mailing list