Commit 54d7a90d authored by Norbert Lange via Xenomai's avatar Norbert Lange via Xenomai Committed by Jan Kiszka

smokey: add tests for mutex/condvar autoinit

add a few testcases where destroy is called as first function,
and test failure if the state is a non-standard initializer.
Signed-off-by: default avatarNorbert Lange <norbert.lange@andritz.com>
Signed-off-by: Jan Kiszka's avatarJan Kiszka <jan.kiszka@siemens.com>
parent 767d0b6f
......@@ -198,6 +198,20 @@ static void *cond_signaler(void *cookie)
return NULL;
}
static void autoinit_simple_conddestroy(void)
{
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
pthread_cond_t cond2 = PTHREAD_COND_INITIALIZER;
unsigned int invalmagic = ~0x86860505; // ~COBALT_COND_MAGIC
memcpy((char *)&cond2 + sizeof(cond2) - sizeof(invalmagic),
&invalmagic, sizeof(invalmagic));
smokey_trace("%s", __func__);
check("cond_destroy", cond_destroy(&cond), 0);
check("cond_destroy invalid", cond_destroy(&cond2), -EINVAL);
}
static void autoinit_simple_condwait(void)
{
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
......@@ -731,6 +745,7 @@ int run_posix_cond(struct smokey_test *t, int argc, char *const argv[])
sparam.sched_priority = 2;
pthread_setschedparam(pthread_self(), SCHED_FIFO, &sparam);
autoinit_simple_conddestroy();
autoinit_simple_condwait();
simple_condwait();
relative_condwait();
......
......@@ -296,6 +296,31 @@ static int do_contend(pthread_mutex_t *mutex, int type)
return 0;
}
static int do_destroy(pthread_mutex_t *mutex, pthread_mutex_t *invalmutex,
int type)
{
int ret;
if (!__T(ret, pthread_mutex_destroy(mutex)))
return ret;
if (!__F(ret, pthread_mutex_destroy(invalmutex)) &&
__Tassert(ret == -EINVAL))
return -1;
return 0;
}
static int static_init_normal_destroy(void)
{
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t invalmutex = PTHREAD_MUTEX_INITIALIZER;
unsigned int invalmagic = ~0x86860303; // ~COBALT_MUTEX_MAGIC
memcpy((char *)&invalmutex + sizeof(invalmutex) - sizeof(invalmagic),
&invalmagic, sizeof(invalmagic));
return do_destroy(&mutex, &invalmutex, PTHREAD_MUTEX_NORMAL);
}
static int static_init_normal_contend(void)
{
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
......@@ -320,6 +345,18 @@ static int dynamic_init_normal_contend(void)
return __dynamic_init_contend(PTHREAD_MUTEX_NORMAL);
}
static int static_init_recursive_destroy(void)
{
pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
pthread_mutex_t invalmutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
unsigned int invalmagic = ~0x86860303; // ~COBALT_MUTEX_MAGIC
memcpy((char *)&invalmutex + sizeof(invalmutex) - sizeof(invalmagic),
&invalmagic, sizeof(invalmagic));
return do_destroy(&mutex, &invalmutex, PTHREAD_MUTEX_RECURSIVE);
}
static int static_init_recursive_contend(void)
{
pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
......@@ -332,6 +369,18 @@ static int dynamic_init_recursive_contend(void)
return __dynamic_init_contend(PTHREAD_MUTEX_RECURSIVE);
}
static int static_init_errorcheck_destroy(void)
{
pthread_mutex_t mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
pthread_mutex_t invalmutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
unsigned int invalmagic = ~0x86860303; // ~COBALT_MUTEX_MAGIC
memcpy((char *)&invalmutex + sizeof(invalmutex) - sizeof(invalmagic),
&invalmagic, sizeof(invalmagic));
return do_destroy(&mutex, &invalmutex, PTHREAD_MUTEX_ERRORCHECK);
}
static int static_init_errorcheck_contend(void)
{
pthread_mutex_t mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
......@@ -991,10 +1040,13 @@ static int run_posix_mutex(struct smokey_test *t, int argc, char *const argv[])
SCHED_FIFO, &param)))
return ret;
do_test(static_init_normal_destroy, MAX_100_MS);
do_test(static_init_normal_contend, MAX_100_MS);
do_test(dynamic_init_normal_contend, MAX_100_MS);
do_test(static_init_recursive_destroy, MAX_100_MS);
do_test(static_init_recursive_contend, MAX_100_MS);
do_test(dynamic_init_recursive_contend, MAX_100_MS);
do_test(static_init_errorcheck_destroy, MAX_100_MS);
do_test(static_init_errorcheck_contend, MAX_100_MS);
do_test(dynamic_init_errorcheck_contend, MAX_100_MS);
do_test(timed_contend, MAX_100_MS);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment