Index: t_mutex.c =================================================================== RCS file: /cvsroot/src/tests/lib/libpthread/t_mutex.c,v retrieving revision 1.13 diff -u -r1.13 t_mutex.c --- t_mutex.c 31 Oct 2016 16:23:03 -0000 1.13 +++ t_mutex.c 31 Oct 2016 23:44:58 -0000 @@ -591,14 +591,14 @@ PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); - printf("Before acquiring regular mutex\n"); + printf("Before acquiring mutex\n"); PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); printf("Before endeavor to reacquire timed-mutex (timeout expected)\n"); PTHREAD_REQUIRE_STATUS(mutex_lock(&mutex, &ts_shortlived), ETIMEDOUT); - printf("Unlocking timed-mutex\n"); + printf("Unlocking mutex\n"); PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); } @@ -616,14 +616,80 @@ PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); - printf("Before acquiring timed-mutex with timedlock\n"); + printf("Before acquiring mutex with timedlock\n"); PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy)); printf("Before endeavor to reacquire timed-mutex (timeout expected)\n"); PTHREAD_REQUIRE_STATUS(mutex_lock(&mutex, &ts_shortlived), ETIMEDOUT); - printf("Unlocking timed-mutex\n"); + printf("Unlocking mutex\n"); + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); +} + +ATF_TC(timedmutex3); +ATF_TC_HEAD(timedmutex3, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Checks timeout on selflock in a new thread"); +} + +static void * +timedmtx_thrdfunc(void *arg) +{ + printf("2: Before endeavor to reacquire timed-mutex (timeout expected)\n"); + PTHREAD_REQUIRE_STATUS(mutex_lock(&mutex, &ts_shortlived), + ETIMEDOUT); + + return NULL; +} + +ATF_TC_BODY(timedmutex3, tc) +{ + pthread_t new; + + printf("1: Timed mutex-test 3\n"); + + PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); + + printf("1: Before acquiring mutex with timedlock\n"); + PTHREAD_REQUIRE(pthread_mutex_lock(&mutex)); + + printf("1: Before creating new thread\n"); + PTHREAD_REQUIRE(pthread_create(&new, NULL, timedmtx_thrdfunc, NULL)); + + printf("1: Before joining the mutex\n"); + PTHREAD_REQUIRE(pthread_join(new, NULL)); + + printf("1: Unlocking mutex\n"); + PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); +} + +ATF_TC(timedmutex4); +ATF_TC_HEAD(timedmutex4, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Checks timeout on selflock with timedlock in a new thread"); +} + +ATF_TC_BODY(timedmutex4, tc) +{ + pthread_t new; + + printf("1: Timed mutex-test 4\n"); + + PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL)); + + printf("1: Before acquiring mutex with timedlock\n"); + PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy)); + + printf("1: Before creating new thread\n"); + PTHREAD_REQUIRE(pthread_create(&new, NULL, timedmtx_thrdfunc, NULL)); + + printf("1: Before joining the mutex\n"); + PTHREAD_REQUIRE(pthread_join(new, NULL)); + + printf("1: Unlocking mutex\n"); PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex)); } #endif @@ -642,6 +708,8 @@ #ifdef TIMEDMUTEX ATF_TP_ADD_TC(tp, timedmutex1); ATF_TP_ADD_TC(tp, timedmutex2); + ATF_TP_ADD_TC(tp, timedmutex3); + ATF_TP_ADD_TC(tp, timedmutex4); #endif return atf_no_error();