RippeR37/libbase

BarrierClosure tests are not executed and BarrierClosureTest.MultipleRuns crashes

Closed this issue · 1 comments

New unit tests for base::BarrierClosure helper was not added to CMakeLists script which means that they are not built and executed.
Once added, the MultipleRuns test crashes with this stack trace;

[ RUN      ] BarrierCallbackTest.MultipleRuns
/home/ripper37/dev/libbase/tests/unit/base/barrier_closure_unittests.cc:52: Failure
Value of: verification_done
  Actual: true
Expected: false
F20220313 15:01:51.917205  8279 barrier_closure.cc:16] Check failed: runs_left >= 0 (-1 vs. 0) 
*** Check failure stack trace: ***
    @     0x5635330763d3  google::LogMessage::Fail()
    @     0x563533076314  google::LogMessage::SendToLog()
    @     0x563533075bf7  google::LogMessage::Flush()
    @     0x563533079758  google::LogMessageFatal::~LogMessageFatal()
    @     0x563533002d72  base::(anonymous namespace)::BarrierClosureHelper::Run()
    @     0x563533004cd0  std::__invoke_impl<>()
    @     0x563533004c2a  std::__invoke<>()
    @     0x5635330049f0  std::invoke<>()
    @     0x5635330047c0  _ZN4base6detailL20MemberFunctionInvokeIRMNS_12_GLOBAL__N_120BarrierClosureHelperEFvvES3_JEEEDcOT_RKNS0_12OwnedWrapperIT0_EEDpOT1_
    @     0x563533004802  _ZN4base6detail13FunctorTraitsIMNS_12_GLOBAL__N_120BarrierClosureHelperEFvvEvE6InvokeIRS5_JLm0EERSt5tupleIJNS0_12OwnedWrapperIS3_EEEEJEEEDcOT_St16integer_sequenceImJXspT0_EEEOT1_DpOT2_
    @     0x563533004835  base::detail::FunctorCallback<>::Run()
    @     0x563532f07119  _ZNKR4base17RepeatingCallbackIFvvEE3RunEv
    @     0x563532f03b14  (anonymous namespace)::BarrierCallbackTest_MultipleRuns_Test::TestBody()
    @     0x56353304b3f6  testing::internal::HandleSehExceptionsInMethodIfSupported<>()
    @     0x563533043ab5  testing::internal::HandleExceptionsInMethodIfSupported<>()
    @     0x5635330195bc  testing::Test::Run()
    @     0x563533019ffe  testing::TestInfo::Run()
    @     0x56353301a8fb  testing::TestSuite::Run()
    @     0x56353302a28d  testing::internal::UnitTestImpl::RunAllTests()
    @     0x56353304c836  testing::internal::HandleSehExceptionsInMethodIfSupported<>()
    @     0x563533044baf  testing::internal::HandleExceptionsInMethodIfSupported<>()
    @     0x5635330289f2  testing::UnitTest::Run()
    @     0x563533002c58  RUN_ALL_TESTS()
    @     0x563533002bd0  main
    @     0x7f95f79430b3  __libc_start_main
    @     0x563532ee97ce  _start
Aborted

This seems to be caused by a bug in TC.

The intention was to do:

  • Expect N runs
  • Run N-1 times
  • Verify that the original callback hasn't been executed yet
  • Run Nth time
  • Verify that the original callback has been executed now

Unfortunately, the loop executes callback N times instead of N-1 times, which triggers CHECK in the last step (now N+1th instead of Nth).