Search code examples
multithreadinggoogletest

Command-line options to force googletest to run in single thread


I have a suite of unit tests that is managed by googletest. These tests are run in multiple threads by default, even when I use --gtest_filter=foo.test so that it only runs a single test. This is causing ambiguity about the cause of a bug I'm trying to hammer out.

How can multithreaded testing be turned off in googletest?


Solution

  • There's no commandline switch for single/multi-threading. libgtest is built either single-threading or multi-threading.

    To make it single-threading, build gtest with ./configure --with-pthreads=no, then link your unit test app without -pthread

    If you only want single threading sometimes, then make a no-pthreads build of libgtest, call it something else, and link it when you want.