Validate that RobustOwnershipTracker catches all the deaths right
This adds tests for our new robust death tracker.
Change-Id: I66e1d03df13ad873bcaeb878afe118a78d95a3a1
Co-authored-by: Austin Schuh <austin.schuh@bluerivertech.com>
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/ipc_lib/robust_ownership_tracker.h b/aos/ipc_lib/robust_ownership_tracker.h
index 6f0d222..a8bbca3 100644
--- a/aos/ipc_lib/robust_ownership_tracker.h
+++ b/aos/ipc_lib/robust_ownership_tracker.h
@@ -10,6 +10,9 @@
#include "aos/util/top.h"
namespace aos::ipc_lib {
+namespace testing {
+class RobustOwnershipTrackerTest;
+} // namespace testing
// Results of atomically loading the ownership state via RobustOwnershipTracker
// below. This allows the state to be compared and queried later.
@@ -122,6 +125,11 @@
// Returns true if this thread holds ownership.
bool IsHeldBySelf() { return death_notification_is_held(&mutex_); }
+ // Returns true if the mutex is held by the provided tid. This is primarily
+ // intended for testing. There should be no need to call this in production
+ // code.
+ bool IsHeldBy(pid_t tid) { return LoadRelaxed().tid() == tid; }
+
// Acquires ownership. Other threads will know that this thread holds the
// ownership or be notified if this thread dies.
void Acquire() {
@@ -143,18 +151,12 @@
start_time_ticks_ = kNoStartTimeTicks;
}
- // Marks the owner as dead if the specified tid is the current owner. In other
- // words, after this call, a call to `LoadAcquire().OwnerIsDead()` may start
- // returning true.
- //
- // The motivation here is for use in testing. DO NOT USE in production code.
- // The logic here is only good enough for testing.
- bool PretendThatOwnerIsDeadForTesting(pid_t tid);
-
// Returns a string representing this object.
std::string DebugString() const;
private:
+ friend class testing::RobustOwnershipTrackerTest;
+
// Robust futex to track ownership the normal way. The futex is inside the
// mutex here. We use the wrapper mutex because the death_notification_*
// functions operate on that instead of the futex directly.