Ticket #3334: Add-test-executing-interlocking-pthread_once.patch
File Add-test-executing-interlocking-pthread_once.patch, 11.8 KB (added by Stavros Passas, on 03/13/18 at 13:19:22) |
---|
-
testsuites/configure.ac
From 1a5bb3da9a61bea92e88a13c901203212531ae0b Mon Sep 17 00:00:00 2001 From: seamusakelly <seamus.kelly@intel.com> Date: Fri, 9 Mar 2018 11:08:54 +0000 Subject: Add test executing interlocking pthread_once --- testsuites/configure.ac | 2 +- testsuites/movitests/Makefile.am | 11 +++ testsuites/movitests/configure.ac | 113 +++++++++++++++++++++++ testsuites/movitests/pthreadonce/Makefile.am | 21 +++++ testsuites/movitests/pthreadonce/init.c | 24 +++++ testsuites/movitests/pthreadonce/pthreadonce.doc | 16 ++++ testsuites/movitests/pthreadonce/pthreadonce.scn | 7 ++ testsuites/movitests/pthreadonce/system.h | 42 +++++++++ testsuites/movitests/pthreadonce/test.cpp | 62 +++++++++++++ 9 files changed, 297 insertions(+), 1 deletion(-) create mode 100644 testsuites/movitests/Makefile.am create mode 100644 testsuites/movitests/configure.ac create mode 100644 testsuites/movitests/pthreadonce/Makefile.am create mode 100644 testsuites/movitests/pthreadonce/init.c create mode 100644 testsuites/movitests/pthreadonce/pthreadonce.doc create mode 100644 testsuites/movitests/pthreadonce/pthreadonce.scn create mode 100644 testsuites/movitests/pthreadonce/system.h create mode 100644 testsuites/movitests/pthreadonce/test.cpp diff --git a/testsuites/configure.ac b/testsuites/configure.ac index ab8aab8e..aab277a 100644
a b esac 37 37 38 38 if test "$enable_tests" = "yes"; then 39 39 # do functionality tests first, then performance tests 40 AC_CONFIG_SUBDIRS(libtests sptests fstests psxtests )40 AC_CONFIG_SUBDIRS(libtests sptests fstests psxtests movitests) 41 41 if test "$rtems_cv_RTEMS_MULTIPROCESSING" = "yes"; then 42 42 AC_CONFIG_SUBDIRS(mptests) 43 43 fi -
new file testsuites/movitests/Makefile.am
diff --git a/testsuites/movitests/Makefile.am b/testsuites/movitests/Makefile.am new file mode 100644 index 0000000..c09b2cc
- + 1 ACLOCAL_AMFLAGS = -I ../aclocal 2 3 ## Some of the tests need other POSIX features to work while some do not. 4 5 _SUBDIRS = 6 if HAS_POSIX 7 _SUBDIRS += pthreadonce 8 endif 9 10 include $(top_srcdir)/../automake/subdirs.am 11 include $(top_srcdir)/../automake/local.am -
new file testsuites/movitests/configure.ac
diff --git a/testsuites/movitests/configure.ac b/testsuites/movitests/configure.ac new file mode 100644 index 0000000..e3b60f7
- + 1 ## Process this file with autoconf to produce a configure script. 2 3 AC_PREREQ([2.69]) 4 AC_INIT([rtems-c-src-tests-movitests],[_RTEMS_VERSION],[https://devel.rtems.org/newticket]) 5 AC_CONFIG_SRCDIR([pthreadonce]) 6 AC_CONFIG_HEADER([config.h]) 7 RTEMS_TOP([../..],[..]) 8 9 RTEMS_CANONICAL_TARGET_CPU 10 11 AM_INIT_AUTOMAKE([no-define foreign 1.12.2]) 12 AM_MAINTAINER_MODE 13 14 RTEMS_ENABLE_CXX 15 16 RTEMS_ENV_RTEMSBSP 17 18 RTEMS_PROJECT_ROOT 19 20 RTEMS_PROG_CC_FOR_TARGET 21 RTEMS_PROG_CXX_FOR_TARGET 22 23 RTEMS_CANONICALIZE_TOOLS 24 25 RTEMS_CHECK_CUSTOM_BSP(RTEMS_BSP) 26 RTEMS_CHECK_CXX(RTEMS_BSP) 27 RTEMS_CHECK_CPUOPTS([RTEMS_POSIX_API]) 28 RTEMS_CHECK_CPUOPTS([RTEMS_NETWORKING]) 29 30 AM_CONDITIONAL(HAS_CXX,test "$rtems_cv_HAS_CPLUSPLUS" = "yes") 31 AM_CONDITIONAL([HAS_NETWORKING],test "$rtems_cv_RTEMS_NETWORKING" = "yes") 32 AM_CONDITIONAL([HAS_CPLUSPLUS],[test x"$HAS_CPLUSPLUS" = x"yes"]) 33 34 RTEMS_CHECK_CPUOPTS([RTEMS_POSIX_API]) 35 AM_CONDITIONAL(HAS_POSIX,test x"${rtems_cv_RTEMS_POSIX_API}" = x"yes") 36 37 # FIXME: IEEE Std 1003.1-2008 mandates sys/mman.h, 38 # but newlib doesn't have sys/mman.h 39 AC_CHECK_HEADERS([sys/mman.h]) 40 41 # FIXME: newlib should supply declaration of pthread_rwlock_unlock() 42 AC_CHECK_DECLS([pthread_rwlock_unlock],[],[],[[#include <pthread.h>]]) 43 44 # FIXME: newlib should supply declaration of pthread_atfork() 45 AC_CHECK_DECLS([pthread_atfork],[],[],[[#include <pthread.h>]]) 46 47 # Added to pthreads after initial revision. May not be in toolset 48 AC_CHECK_DECLS([pthread_attr_getstack],[],[],[[#include <pthread.h>]]) 49 50 # Added to pthreads after initial revision. May not be in toolset 51 AC_CHECK_DECLS([pthread_attr_setstack],[],[],[[#include <pthread.h>]]) 52 53 # Added to pthreads after initial revision. May not be in toolset 54 AC_CHECK_DECLS([pthread_attr_getguardsize],[],[],[[#include <pthread.h>]]) 55 56 # Added to pthreads after initial revision. May not be in toolset 57 AC_CHECK_DECLS([pthread_attr_setguardsize],[],[],[[#include <pthread.h>]]) 58 59 # Added to newlib pthreads for RTEMS SMP (np), may not be present 60 AC_CHECK_DECLS([pthread_attr_setaffinity_np],[],[],[[ 61 #define _GNU_SOURCE 62 #include <pthread.h>]]) 63 64 # Added to newlib pthreads for RTEMS SMP (np), may not be present 65 AC_CHECK_DECLS([pthread_attr_getaffinity_np],[],[],[[ 66 #define _GNU_SOURCE 67 #include <pthread.h>]]) 68 69 # Added to newlib pthreads for RTEMS SMP (np), may not be present 70 AC_CHECK_DECLS([pthread_setaffinity_np],[],[],[[ 71 #define _GNU_SOURCE 72 #include <pthread.h>]]) 73 74 # Added to newlib pthreads for RTEMS SMP (np), may not be present 75 AC_CHECK_DECLS([pthread_getaffinity_np],[],[],[[ 76 #define _GNU_SOURCE 77 #include <pthread.h>]]) 78 79 # Added to newlib pthreads for RTEMS SMP (np), may not be present 80 AC_CHECK_DECLS([pthread_getattr_np],[],[],[[ 81 #define _GNU_SOURCE 82 #include <pthread.h>]]) 83 84 # Mandated by POSIX, not declared in some versions of newlib. 85 AC_CHECK_DECLS([getrusage],,,[#include sys/resource.h]) 86 87 # Mandated by POSIX, not declared in some versions of newlib. 88 AC_CHECK_DECLS([getrusage],,,[#include sys/resource.h]) 89 90 # FIXME: adjtime is a non-standardized BSD/Linux extension 91 # RTEMS should not rely on adjtime 92 AC_CHECK_DECLS([adjtime],[],[],[[#include <sys/time.h>]]) 93 94 # FIXME: IEEE Std 1003.1-2008 mandates mprotect in sys/mman.h, 95 # RTEMS provides a stub, despite newlib doesn't have sys/mman.h 96 AC_CHECK_DECLS([mprotect],[],[],[[#include <sys/mman.h>]]) 97 98 # FIXME: IEEE Std 1003.1-2008 mandates seteuid in unistd.h 99 # RTEMS provides it, despite newlib doesn't declare it. 100 AC_CHECK_DECLS([seteuid],[],[],[#include <unistd.h>]) 101 102 # FIXME: We should get rid of this. It's a cludge. 103 AC_CHECK_SIZEOF([off_t]) 104 AC_CHECK_SIZEOF([blksize_t]) 105 AC_CHECK_SIZEOF([blkcnt_t]) 106 AC_CHECK_SIZEOF([time_t]) 107 AC_CHECK_SIZEOF([mode_t]) 108 109 # Explicitly list all Makefiles here 110 AC_CONFIG_FILES([Makefile 111 pthreadonce/Makefile 112 ]) 113 AC_OUTPUT -
new file testsuites/movitests/pthreadonce/Makefile.am
diff --git a/testsuites/movitests/pthreadonce/Makefile.am b/testsuites/movitests/pthreadonce/Makefile.am new file mode 100644 index 0000000..4c53092
- + 1 rtems_tests_PROGRAMS = pthreadonce 2 pthreadonce_SOURCES = init.c test.cpp system.h 3 4 dist_rtems_tests_DATA = pthreadonce.scn 5 6 include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg 7 include $(top_srcdir)/../automake/compile.am 8 include $(top_srcdir)/../automake/leaf.am 9 10 11 AM_CPPFLAGS += -I$(top_srcdir)/include 12 AM_CPPFLAGS += -I$(top_srcdir)/../support/include 13 14 LINK_OBJS = $(pthreadonce_OBJECTS) 15 LINK_LIBS = $(pthreadonce_LDLIBS) 16 17 psxonce01$(EXEEXT): $(pthreadonce_OBJECTS) $(pthreadonce_DEPENDENCIES) 18 @rm -f pthreadonce$(EXEEXT) 19 $(make-exe) 20 21 include $(top_srcdir)/../automake/local.am -
new file testsuites/movitests/pthreadonce/init.c
diff --git a/testsuites/movitests/pthreadonce/init.c b/testsuites/movitests/pthreadonce/init.c new file mode 100644 index 0000000..82efee9
- + 1 /// 2 /// @file 3 /// @copyright All code copyright Movidius Ltd 2018, all rights reserved. 4 /// For License Warranty see: common/license.txt 5 /// 6 /// @brief pthread_once test 7 /// 8 // 1: Includes 9 // ---------------------------------------------------------------------------- 10 #ifdef HAVE_CONFIG_H 11 #include "config.h" 12 #endif 13 #define CONFIGURE_INIT 14 #include "system.h" 15 16 const char rtems_test_name[] = "pthreadOnce"; 17 18 void *POSIX_Init(void *argument) 19 { 20 TEST_BEGIN(); 21 test_pthreadonce(); 22 TEST_END(); 23 return NULL; /* just so the compiler thinks we returned something */ 24 } -
new file testsuites/movitests/pthreadonce/pthreadonce.doc
diff --git a/testsuites/movitests/pthreadonce/pthreadonce.doc b/testsuites/movitests/pthreadonce/pthreadonce.doc new file mode 100644 index 0000000..2f67894
- + 1 # 2 # @copyright All code copyright Movidius Ltd 2018, all rights reserved. 3 # For License Warranty see: common/license.txt 4 # 5 This file describes the directives and concepts tested by this test set. 6 7 test set name: pthreadonce 8 9 directives: 10 pthread_once 11 12 concepts: 13 + Verify that pthread_once doesn't deadlock if the same once control 14 is used by different threads and the init_routine hasn't completed 15 from the first call 16 -
new file testsuites/movitests/pthreadonce/pthreadonce.scn
diff --git a/testsuites/movitests/pthreadonce/pthreadonce.scn b/testsuites/movitests/pthreadonce/pthreadonce.scn new file mode 100644 index 0000000..8326481
- + 1 2 *** BEGIN OF TEST pthreadOnce *** 3 Async thread launched 4 Call future to retrieve result 5 Async function called 6 Test complete - Result retrieved- Pass 7 *** END OF TEST pthreadOnce *** -
new file testsuites/movitests/pthreadonce/system.h
diff --git a/testsuites/movitests/pthreadonce/system.h b/testsuites/movitests/pthreadonce/system.h new file mode 100644 index 0000000..ec3fca4
- + 1 /* system.h 2 * 3 * This include file contains information that is included in every 4 * function in the test set. 5 * 6 * COPYRIGHT (c) 1989-1999. 7 * On-Line Applications Research Corporation (OAR). 8 * 9 * The license and distribution terms for this file may be 10 * found in the file LICENSE in this distribution or at 11 * http://www.rtems.org/license/LICENSE. 12 */ 13 14 /* functions */ 15 16 #include <buffer_test_io.h> 17 #include <unistd.h> 18 #include <errno.h> 19 #include <sched.h> 20 21 void *POSIX_Init( 22 void *argument 23 ); 24 /* configuration information */ 25 #ifndef RTEMS_POSIX_API 26 #define RTEMS_POSIX_API 27 #endif 28 29 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER 30 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER 31 32 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION 33 34 #define CONFIGURE_MAXIMUM_POSIX_THREADS 3 35 36 #define CONFIGURE_POSIX_INIT_THREAD_TABLE 37 38 #include <rtems/confdefs.h> 39 40 void test_pthreadonce(void); 41 42 /* end of include file */ -
new file testsuites/movitests/pthreadonce/test.cpp
diff --git a/testsuites/movitests/pthreadonce/test.cpp b/testsuites/movitests/pthreadonce/test.cpp new file mode 100644 index 0000000..9f8b2c2
- + 1 #include <stdio.h> 2 3 #include <tmacros.h> 4 5 #include <thread> 6 #include <future> 7 8 #define WAIT_TIME 2 /* seconds to wait for async function to complete */ 9 10 using namespace std; 11 12 static bool test_complete = false; 13 static bool deadlock = false; 14 15 static bool functionA() 16 { 17 18 printf("Async function called\n"); 19 20 return true; 21 } 22 23 static void *check_for_deadlock(void *argument) 24 { 25 26 /* allow time for first thread to complete */ 27 sleep(WAIT_TIME); 28 if(!test_complete){ 29 /* Test has failed with a deadlock in once.c */ 30 printf("Test complete - DEADLOCK\n"); 31 rtems_test_assert( test_complete ); 32 deadlock = true; 33 } 34 return NULL; 35 } 36 37 /* 38 * This function tests the behavior of the once control 39 */ 40 extern "C" void test_pthreadonce() 41 { 42 43 int status; 44 pthread_t thread_id; 45 46 /* create a thread that can check for deadlock in the following 47 * async/future transaction 48 */ 49 status = pthread_create( &thread_id, NULL, check_for_deadlock, NULL ); 50 rtems_test_assert( !status ); 51 52 std::future<bool> fA = std::async(std::launch::async ,functionA); 53 54 printf("Async thread launched\n"); 55 printf("Call future to retrieve result\n"); 56 fA.get(); 57 test_complete = true; 58 pthread_join(thread_id, NULL); 59 /* If we get here then the test has passed */ 60 printf("Test complete - Result retrieved- Pass\n"); 61 62 }