Module: xenomai-2.6 Branch: master Commit: 5a885cfabbb24b8e27405fd7fb91b59cb0d0f180 URL: http://git.xenomai.org/?p=xenomai-2.6.git;a=commit;h=5a885cfabbb24b8e27405fd7fb91b59cb0d0f180
Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org> Date: Sun Sep 23 18:04:10 2012 +0200 testsuite/regression: add test for thread exit under PIP --- src/testsuite/regression/posix/Makefile.am | 2 +- src/testsuite/regression/posix/Makefile.in | 17 ++++- src/testsuite/regression/posix/test_pip_exit.c | 71 ++++++++++++++++++++++ src/testsuite/regression/xeno-regression-test.in | 1 + 4 files changed, 87 insertions(+), 4 deletions(-) diff --git a/src/testsuite/regression/posix/Makefile.am b/src/testsuite/regression/posix/Makefile.am index bd3c1cf..49102ed 100644 --- a/src/testsuite/regression/posix/Makefile.am +++ b/src/testsuite/regression/posix/Makefile.am @@ -4,7 +4,7 @@ noinst_HEADERS = check.h CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC) -tst_PROGRAMS = leaks shm mprotect nano_test xddp_test +tst_PROGRAMS = leaks shm mprotect nano_test xddp_test test_pip_exit CPPFLAGS = $(XENO_USER_CFLAGS) \ -I$(top_srcdir)/include/posix \ diff --git a/src/testsuite/regression/posix/Makefile.in b/src/testsuite/regression/posix/Makefile.in index da24e2f..4a2a6b7 100644 --- a/src/testsuite/regression/posix/Makefile.in +++ b/src/testsuite/regression/posix/Makefile.in @@ -37,7 +37,7 @@ build_triplet = @build@ host_triplet = @host@ target_triplet = @target@ tst_PROGRAMS = leaks$(EXEEXT) shm$(EXEEXT) mprotect$(EXEEXT) \ - nano_test$(EXEEXT) xddp_test$(EXEEXT) + nano_test$(EXEEXT) xddp_test$(EXEEXT) test_pip_exit$(EXEEXT) subdir = src/testsuite/regression/posix DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \ $(srcdir)/Makefile.in @@ -78,6 +78,11 @@ shm_OBJECTS = shm.$(OBJEXT) shm_LDADD = $(LDADD) shm_DEPENDENCIES = ../../../skins/posix/libpthread_rt.la \ ../../../skins/common/libxenomai.la +test_pip_exit_SOURCES = test_pip_exit.c +test_pip_exit_OBJECTS = test_pip_exit.$(OBJEXT) +test_pip_exit_LDADD = $(LDADD) +test_pip_exit_DEPENDENCIES = ../../../skins/posix/libpthread_rt.la \ + ../../../skins/common/libxenomai.la xddp_test_SOURCES = xddp_test.c xddp_test_OBJECTS = xddp_test.$(OBJEXT) xddp_test_LDADD = $(LDADD) @@ -95,8 +100,10 @@ LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ $(LDFLAGS) -o $@ -SOURCES = leaks.c mprotect.c nano_test.c shm.c xddp_test.c -DIST_SOURCES = leaks.c mprotect.c nano_test.c shm.c xddp_test.c +SOURCES = leaks.c mprotect.c nano_test.c shm.c test_pip_exit.c \ + xddp_test.c +DIST_SOURCES = leaks.c mprotect.c nano_test.c shm.c test_pip_exit.c \ + xddp_test.c HEADERS = $(noinst_HEADERS) ETAGS = etags CTAGS = ctags @@ -363,6 +370,9 @@ nano_test$(EXEEXT): $(nano_test_OBJECTS) $(nano_test_DEPENDENCIES) shm$(EXEEXT): $(shm_OBJECTS) $(shm_DEPENDENCIES) @rm -f shm$(EXEEXT) $(LINK) $(shm_OBJECTS) $(shm_LDADD) $(LIBS) +test_pip_exit$(EXEEXT): $(test_pip_exit_OBJECTS) $(test_pip_exit_DEPENDENCIES) + @rm -f test_pip_exit$(EXEEXT) + $(LINK) $(test_pip_exit_OBJECTS) $(test_pip_exit_LDADD) $(LIBS) xddp_test$(EXEEXT): $(xddp_test_OBJECTS) $(xddp_test_DEPENDENCIES) @rm -f xddp_test$(EXEEXT) $(LINK) $(xddp_test_OBJECTS) $(xddp_test_LDADD) $(LIBS) @@ -377,6 +387,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mprotect.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nano_test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shm.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_pip_exit.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xddp_test.Po@am__quote@ .c.o: diff --git a/src/testsuite/regression/posix/test_pip_exit.c b/src/testsuite/regression/posix/test_pip_exit.c new file mode 100644 index 0000000..17f3077 --- /dev/null +++ b/src/testsuite/regression/posix/test_pip_exit.c @@ -0,0 +1,71 @@ +/* + * Test exiting a thread while holding a mutex with priority + * inheritance enabled (and active). + * + * From a bug reported by Henri Roosen: + * http://www.xenomai.org/pipermail/xenomai/2012-September/026073.html + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <unistd.h> +#include <sys/mman.h> +#include <pthread.h> +#include <semaphore.h> +#include "check.h" + +static pthread_mutex_t mutex; +static sem_t ready; + +static void locker(void) +{ + check_pthread(pthread_set_name_np(pthread_self(), "locker")); + check_pthread(pthread_mutex_lock(&mutex)); + check_unix(sem_post(&ready)); +} + +static void waiter(void) +{ + check_pthread(pthread_set_name_np(pthread_self(), "waiter")); + check_unix(sem_wait(&ready)); + check_pthread(pthread_mutex_lock(&mutex)); +} + +static void *thread(void *cookie) +{ + locker(); + /* Now let the waiter enter pthread_mutex_lock and cause the + PIP boost */ + sleep(1); + return cookie; +} + +int main(void) +{ + pthread_mutexattr_t mattr; + struct sched_param sp; + pthread_t tid; + + check_unix(mlockall(MCL_CURRENT | MCL_FUTURE)); + + check_pthread(pthread_mutexattr_init(&mattr)); + check_pthread(pthread_mutexattr_setprotocol(&mattr, + PTHREAD_PRIO_INHERIT)); + + check_pthread(pthread_mutex_init(&mutex, &mattr)); + check_pthread(pthread_mutexattr_destroy(&mattr)); + + check_unix(sem_init(&ready, 0, 0)); + + check_pthread(pthread_create(&tid, NULL, thread, NULL)); + + sp.sched_priority = 99; + check_pthread(pthread_setschedparam(pthread_self(), SCHED_FIFO, &sp)); + + waiter(); + + fprintf(stderr, "Test OK\n"); + exit(EXIT_SUCCESS); +} diff --git a/src/testsuite/regression/xeno-regression-test.in b/src/testsuite/regression/xeno-regression-test.in index 6fa81f0..e25ee39 100644 --- a/src/testsuite/regression/xeno-regression-test.in +++ b/src/testsuite/regression/xeno-regression-test.in @@ -49,6 +49,7 @@ echo 0 > /proc/xenomai/latency || : @testdir@/regression/posix/nano_test @testdir@/regression/posix/shm @testdir@/regression/posix/xddp_test +@testdir@/regression/posix/test_pip_exit @testdir@/regression/native/heap @testdir@/regression/native/leaks @testdir@/regression/native/sigdebug _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git