Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libpthread more tests from kamil



details:   https://anonhg.NetBSD.org/src/rev/3e601f773dc7
branches:  trunk
changeset: 348648:3e601f773dc7
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Oct 31 23:51:20 2016 +0000

description:
more tests from kamil

diffstat:

 tests/lib/libpthread/t_mutex.c |  80 ++++++++++++++++++++++++++++++++++++++---
 1 files changed, 74 insertions(+), 6 deletions(-)

diffs (127 lines):

diff -r 24dead3858ba -r 3e601f773dc7 tests/lib/libpthread/t_mutex.c
--- a/tests/lib/libpthread/t_mutex.c    Mon Oct 31 20:22:35 2016 +0000
+++ b/tests/lib/libpthread/t_mutex.c    Mon Oct 31 23:51:20 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mutex.c,v 1.13 2016/10/31 16:23:03 christos Exp $ */
+/* $NetBSD: t_mutex.c,v 1.14 2016/10/31 23:51:20 christos Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
 #include <sys/cdefs.h>
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_mutex.c,v 1.13 2016/10/31 16:23:03 christos Exp $");
+__RCSID("$NetBSD: t_mutex.c,v 1.14 2016/10/31 23:51:20 christos Exp $");
 
 #include <pthread.h>
 #include <stdio.h>
@@ -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("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("Timed mutex-test 3\n");
+
+       PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
+
+       printf("Before acquiring mutex with timedlock\n");
+       PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
+
+       printf("Before creating new thread\n");
+       PTHREAD_REQUIRE(pthread_create(&new, NULL, timedmtx_thrdfunc, NULL));
+
+       printf("Before joining the mutex\n");
+       PTHREAD_REQUIRE(pthread_join(new, NULL));
+
+       printf("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("Timed mutex-test 4\n");
+
+       PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
+
+       printf("Before acquiring mutex with timedlock\n");
+       PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
+
+       printf("Before creating new thread\n");
+       PTHREAD_REQUIRE(pthread_create(&new, NULL, timedmtx_thrdfunc, NULL));
+
+       printf("Before joining the mutex\n");
+       PTHREAD_REQUIRE(pthread_join(new, NULL));
+
+       printf("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();



Home | Main Index | Thread Index | Old Index