GCC Code Coverage Report


Directory: ./
File: TestLockable.cpp
Date: 2026-03-21 20:51:59
Exec Total Coverage
Lines: 35 35 100.0%
Functions: 21 21 100.0%
Branches: 20 34 58.8%

Line Branch Exec Source
1 #include "Lockable.hpp"
2 #include "Verbose.hpp"
3 #include "compat/gsl14.hpp"
4 #include <gtest/gtest.h>
5 #include <mutex>
6
7 using namespace testing;
8 using namespace testing::internal;
9
10 using VerboseMutex = Verbose<BasicLockable<std::mutex>>;
11
12 8 TEST(BasicLockable, lock_guard) {
13
2/4
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
6 auto&& mutex = VerboseMutex{"mutex"}; // && until C++17
14
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
4 auto&& lock = std::lock_guard<VerboseMutex>{mutex}; // && until C++17
15 2 mutex.assert_ownership();
16 4 }
17
18 8 TEST(BasicLockable, unique_lock) {
19
2/4
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
6 auto&& mutex = VerboseMutex{"mutex"}; // && until C++17
20
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
4 auto&& lock = std::unique_lock<VerboseMutex>{mutex}; // && until C++17
21 2 mutex.assert_ownership();
22 4 }
23
24 // Does not fail for RELEASE build
25 8 TEST(BasicLockable, unowned_expects) {
26 #ifdef NDEBUG
27 auto&& mutex = VerboseMutex{"mutex"}; // && until C++17
28 Expects(mutex.this_thread_is_owner()); // Expected to fail!
29 #endif // NDEBUG
30 2 }
31
32 // Does not abort for RELEASE build
33 8 TEST(BasicLockable, unowned_assert) {
34 #ifdef NDEBUG
35 auto&& mutex = VerboseMutex{"mutex"}; // && until C++17
36 mutex.assert_ownership(); // Expected to fail!
37 #endif // NDEBUG
38 2 }
39
40 #if __cplusplus >= 201703L // since C++17
41
42 8 TEST(BasicLockable, timing_assert) {
43 #ifdef NDEBUG
44 const auto limit = 100'000'000;
45 #else
46 2 const auto limit = 100'000;
47 #endif // NDEBUG
48
2/4
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
6 auto mutex = VerboseMutex{"mutex"};
49
2/2
✓ Branch 0 taken 100000 times.
✓ Branch 1 taken 1 times.
200002 for (auto i = 0; i < limit; i++) {
50
1/2
✓ Branch 2 taken 100000 times.
✗ Branch 3 not taken.
200000 auto lock = std::lock_guard{mutex};
51 200000 mutex.assert_ownership();
52 200000 }
53 4 }
54
55 8 TEST(BasicLockable, timing_expects) {
56 #ifdef NDEBUG
57 const auto limit = 100'000'000;
58 #else
59 2 const auto limit = 100'000;
60 #endif // NDEBUG
61
2/4
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
6 auto mutex = VerboseMutex{"mutex"};
62
2/2
✓ Branch 0 taken 100000 times.
✓ Branch 1 taken 1 times.
200002 for (auto i = 0; i < limit; i++) {
63
1/2
✓ Branch 2 taken 100000 times.
✗ Branch 3 not taken.
200000 auto lock = std::lock_guard{mutex};
64
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 100000 times.
200000 Expects(mutex.this_thread_is_owner());
65 200000 }
66 4 }
67
68 8 TEST(BasicLockable, timing_without) {
69 2 const auto limit = 100'000'000;
70 2 auto mutex = std::mutex{};
71
3/4
✓ Branch 2 taken 100000000 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 100000000 times.
✓ Branch 6 taken 1 times.
200000002 for (auto i = 0; i < limit; i++) { auto lock = std::lock_guard{mutex}; }
72 2 }
73
74 #endif // C++17
75