aboutsummaryrefslogtreecommitdiff
path: root/pw_sync/mutex_facade_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'pw_sync/mutex_facade_test.cc')
-rw-r--r--pw_sync/mutex_facade_test.cc38
1 files changed, 26 insertions, 12 deletions
diff --git a/pw_sync/mutex_facade_test.cc b/pw_sync/mutex_facade_test.cc
index 4c7cdd03a..71ca94649 100644
--- a/pw_sync/mutex_facade_test.cc
+++ b/pw_sync/mutex_facade_test.cc
@@ -16,6 +16,7 @@
#include "gtest/gtest.h"
#include "pw_sync/mutex.h"
+#include "pw_sync_private/borrow_lockable_tests.h"
namespace pw::sync {
namespace {
@@ -29,12 +30,12 @@ void pw_sync_Mutex_CallUnlock(pw_sync_Mutex* mutex);
} // extern "C"
-// TODO(b/235284163): Add real concurrency tests once we have pw::thread.
+// TODO: b/235284163 - Add real concurrency tests once we have pw::thread.
TEST(Mutex, LockUnlock) {
- pw::sync::Mutex mutex;
+ Mutex mutex;
mutex.lock();
- // TODO(b/235284163): Ensure it fails to lock when already held.
+ // TODO: b/235284163 - Ensure it fails to lock when already held.
// EXPECT_FALSE(mutex.try_lock());
mutex.unlock();
}
@@ -42,26 +43,28 @@ TEST(Mutex, LockUnlock) {
Mutex static_mutex;
TEST(Mutex, LockUnlockStatic) {
static_mutex.lock();
- // TODO(b/235284163): Ensure it fails to lock when already held.
+ // TODO: b/235284163 - Ensure it fails to lock when already held.
// EXPECT_FALSE(static_mutex.try_lock());
static_mutex.unlock();
}
TEST(Mutex, TryLockUnlock) {
- pw::sync::Mutex mutex;
+ Mutex mutex;
const bool locked = mutex.try_lock();
EXPECT_TRUE(locked);
if (locked) {
- // TODO(b/235284163): Ensure it fails to lock when already held.
+ // TODO: b/235284163 - Ensure it fails to lock when already held.
// EXPECT_FALSE(mutex.try_lock());
mutex.unlock();
}
}
+PW_SYNC_ADD_BORROWABLE_LOCK_NAMED_TESTS(BorrowableMutex, Mutex);
+
TEST(VirtualMutex, LockUnlock) {
- pw::sync::VirtualMutex mutex;
+ VirtualMutex mutex;
mutex.lock();
- // TODO(b/235284163): Ensure it fails to lock when already held.
+ // TODO: b/235284163 - Ensure it fails to lock when already held.
// EXPECT_FALSE(mutex.try_lock());
mutex.unlock();
}
@@ -69,21 +72,32 @@ TEST(VirtualMutex, LockUnlock) {
VirtualMutex static_virtual_mutex;
TEST(VirtualMutex, LockUnlockStatic) {
static_virtual_mutex.lock();
- // TODO(b/235284163): Ensure it fails to lock when already held.
+ // TODO: b/235284163 - Ensure it fails to lock when already held.
// EXPECT_FALSE(static_virtual_mutex.try_lock());
static_virtual_mutex.unlock();
}
+TEST(VirtualMutex, LockUnlockExternal) {
+ VirtualMutex virtual_mutex;
+ auto& mutex = virtual_mutex.mutex();
+ mutex.lock();
+ // TODO: b/235284163 - Ensure it fails to lock when already held.
+ // EXPECT_FALSE(mutex.try_lock());
+ mutex.unlock();
+}
+
+PW_SYNC_ADD_BORROWABLE_LOCK_NAMED_TESTS(BorrowableVirtualMutex, VirtualMutex);
+
TEST(Mutex, LockUnlockInC) {
- pw::sync::Mutex mutex;
+ Mutex mutex;
pw_sync_Mutex_CallLock(&mutex);
pw_sync_Mutex_CallUnlock(&mutex);
}
TEST(Mutex, TryLockUnlockInC) {
- pw::sync::Mutex mutex;
+ Mutex mutex;
ASSERT_TRUE(pw_sync_Mutex_CallTryLock(&mutex));
- // TODO(b/235284163): Ensure it fails to lock when already held.
+ // TODO: b/235284163 - Ensure it fails to lock when already held.
// EXPECT_FALSE(pw_sync_Mutex_CallTryLock(&mutex));
pw_sync_Mutex_CallUnlock(&mutex);
}