lib/base: add tests for mutex and rwlock
Add a basic set of tests for the HEIMDAL_MUTEX and HEIMDAL_RWLOCK abstraction using both static and dynamic initialization. Change-Id: Iaeb16e5dfcf00d29be7eaa4f2e6970c4f1268fb0
This commit is contained in:
@@ -89,6 +89,64 @@ test_memory(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
test_mutex(void)
|
||||||
|
{
|
||||||
|
HEIMDAL_MUTEX m = HEIMDAL_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
|
HEIMDAL_MUTEX_lock(&m);
|
||||||
|
HEIMDAL_MUTEX_unlock(&m);
|
||||||
|
HEIMDAL_MUTEX_destroy(&m);
|
||||||
|
|
||||||
|
HEIMDAL_MUTEX_init(&m);
|
||||||
|
HEIMDAL_MUTEX_lock(&m);
|
||||||
|
HEIMDAL_MUTEX_unlock(&m);
|
||||||
|
HEIMDAL_MUTEX_destroy(&m);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
test_rwlock(void)
|
||||||
|
{
|
||||||
|
HEIMDAL_RWLOCK l = HEIMDAL_RWLOCK_INITIALIZER;
|
||||||
|
|
||||||
|
HEIMDAL_RWLOCK_rdlock(&l);
|
||||||
|
if (HEIMDAL_RWLOCK_trywrlock(&l))
|
||||||
|
abort();
|
||||||
|
HEIMDAL_RWLOCK_unlock(&l);
|
||||||
|
HEIMDAL_RWLOCK_wrlock(&l);
|
||||||
|
if (HEIMDAL_RWLOCK_tryrdlock(&l))
|
||||||
|
abort();
|
||||||
|
HEIMDAL_RWLOCK_unlock(&l);
|
||||||
|
if (!HEIMDAL_RWLOCK_trywrlock(&l))
|
||||||
|
abort();
|
||||||
|
HEIMDAL_RWLOCK_unlock(&l);
|
||||||
|
if (!HEIMDAL_RWLOCK_tryrdlock(&l))
|
||||||
|
abort();
|
||||||
|
HEIMDAL_RWLOCK_unlock(&l);
|
||||||
|
HEIMDAL_RWLOCK_destroy(&l);
|
||||||
|
|
||||||
|
HEIMDAL_RWLOCK_init(&l);
|
||||||
|
HEIMDAL_RWLOCK_rdlock(&l);
|
||||||
|
if (HEIMDAL_RWLOCK_trywrlock(&l))
|
||||||
|
abort();
|
||||||
|
HEIMDAL_RWLOCK_unlock(&l);
|
||||||
|
HEIMDAL_RWLOCK_wrlock(&l);
|
||||||
|
if (HEIMDAL_RWLOCK_tryrdlock(&l))
|
||||||
|
abort();
|
||||||
|
HEIMDAL_RWLOCK_unlock(&l);
|
||||||
|
if (!HEIMDAL_RWLOCK_trywrlock(&l))
|
||||||
|
abort();
|
||||||
|
HEIMDAL_RWLOCK_unlock(&l);
|
||||||
|
if (!HEIMDAL_RWLOCK_tryrdlock(&l))
|
||||||
|
abort();
|
||||||
|
HEIMDAL_RWLOCK_unlock(&l);
|
||||||
|
HEIMDAL_RWLOCK_destroy(&l);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
test_dict(void)
|
test_dict(void)
|
||||||
{
|
{
|
||||||
@@ -894,6 +952,8 @@ main(int argc, char **argv)
|
|||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
res |= test_memory();
|
res |= test_memory();
|
||||||
|
res |= test_mutex();
|
||||||
|
res |= test_rwlock();
|
||||||
res |= test_dict();
|
res |= test_dict();
|
||||||
res |= test_auto_release();
|
res |= test_auto_release();
|
||||||
res |= test_string();
|
res |= test_string();
|
||||||
|
Reference in New Issue
Block a user