1 // Copyright 2018 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "../condition-generic/condition-generic.h" 6 7 #include <lib/sync/condition.h> 8 9 struct MutexWrapper { 10 sync_mutex_t mtx; 11 lockMutexWrapper12 void lock() __TA_ACQUIRE(mtx) { 13 sync_mutex_lock(&mtx); 14 } 15 unlockMutexWrapper16 void unlock() __TA_RELEASE(mtx) { 17 sync_mutex_unlock(&mtx); 18 } 19 }; 20 21 struct ConditionWrapper { 22 sync_condition_t condition; 23 signalConditionWrapper24 void signal() { 25 sync_condition_signal(&condition); 26 } 27 broadcastConditionWrapper28 void broadcast() { 29 sync_condition_broadcast(&condition); 30 } 31 waitConditionWrapper32 void wait(MutexWrapper* mtx) { 33 sync_condition_wait(&condition, &mtx->mtx); 34 } 35 timedwaitConditionWrapper36 zx_status_t timedwait(MutexWrapper* mtx, zx_duration_t timeout) { 37 return sync_condition_timedwait(&condition, &mtx->mtx, zx_deadline_after(timeout)); 38 } 39 }; 40 41 using Condition = GenericConditionTest<MutexWrapper, ConditionWrapper>; 42 43 BEGIN_TEST_CASE(sync_condition_tests) 44 RUN_TEST(Condition::condition_test); 45 RUN_TEST(Condition::condition_timeout_test); END_TEST_CASE(sync_condition_tests)46END_TEST_CASE(sync_condition_tests) 47 48 #ifndef BUILD_COMBINED_TESTS 49 int main(int argc, char** argv) { 50 bool success = unittest_run_all_tests(argc, argv); 51 return success ? 0 : -1; 52 } 53 #endif 54