psxtmtests: added new psxtmcond04 test, fixed psxtmcond03

This commit is contained in:
Daniel Ramirez
2013-11-30 20:27:44 -06:00
committed by Gedare Bloom
parent 95d7ac7735
commit 72ff7569b0
7 changed files with 179 additions and 8 deletions

View File

@@ -10,6 +10,7 @@ SUBDIRS += psxtmbarrier04
SUBDIRS += psxtmcond01
SUBDIRS += psxtmcond02
SUBDIRS += psxtmcond03
SUBDIRS += psxtmcond04
SUBDIRS += psxtmcond05
SUBDIRS += psxtmcond08
SUBDIRS += psxtmcond09

View File

@@ -84,6 +84,7 @@ psxtmbarrier04/Makefile
psxtmcond01/Makefile
psxtmcond02/Makefile
psxtmcond03/Makefile
psxtmcond04/Makefile
psxtmcond05/Makefile
psxtmcond08/Makefile
psxtmcond09/Makefile

View File

@@ -30,8 +30,15 @@ void *Blocker(
void *argument
)
{
int status;
status = pthread_mutex_lock(&MutexID);
rtems_test_assert( status == 0 );
/* Unlock mutex, block, wait for CondID to be signaled */
pthread_cond_wait(&CondID,&MutexID);
/* should never return */
/* should never return */
rtems_test_assert( FALSE );
return NULL;
@@ -44,6 +51,8 @@ void *POSIX_Init(
int status;
pthread_t threadId;
long end_time;
struct sched_param param;
int policy;
puts( "\n\n*** POSIX TIME TEST PSXTMCOND03 ***" );
@@ -56,12 +65,6 @@ void *POSIX_Init(
status = pthread_cond_init(&CondID, NULL); /* Create condition variable */
rtems_test_assert( status == 0 );
/*
* Ensure the mutex is unavailable so the other threads block.
*/
status = pthread_mutex_lock(&MutexID);
rtems_test_assert( status == 0 );
/*
* Let the other thread start so the thread startup overhead,
* is accounted for. When we return, we can start the benchmark.
@@ -69,6 +72,13 @@ void *POSIX_Init(
sched_yield();
/* let other thread run */
/* To be extra sure we don't get preempted on the signal */
status = pthread_getschedparam(pthread_self(), &policy, &param);
rtems_test_assert( status == 0);
param.sched_priority = sched_get_priority_max(policy) - 1;
status = pthread_setschedparam(pthread_self(), policy, &param);
rtems_test_assert( status == 0);
benchmark_timer_initialize();
status = pthread_cond_signal(&CondID);
end_time = benchmark_timer_read();

View File

@@ -0,0 +1,27 @@
MANAGERS = all
rtems_tests_PROGRAMS = psxtmcond04
psxtmcond04_SOURCES = init.c
psxtmcond04_SOURCES += ../../tmtests/include/timesys.h
psxtmcond04_SOURCES += ../../support/src/tmtests_empty_function.c
psxtmcond04_SOURCES += ../../support/src/tmtests_support.c
dist_rtems_tests_DATA = psxtmcond04.doc
include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
include $(top_srcdir)/../automake/compile.am
include $(top_srcdir)/../automake/leaf.am
OPERATION_COUNT = @OPERATION_COUNT@
AM_CPPFLAGS += -I$(top_srcdir)/../tmtests/include
AM_CPPFLAGS += -DOPERATION_COUNT=$(OPERATION_COUNT)
AM_CPPFLAGS += -I$(top_srcdir)/../support/include
LINK_OBJS = $(psxtmcond04_OBJECTS) $(psxtmcond04_LDADD)
LINK_LIBS = $(psxtmcond04_LDLIBS)
psxtmcond04$(EXEEXT): $(psxtmcond04_OBJECTS) $(psxtmcond04_DEPENDENCIES)
@rm -f psxtmcond04$(EXEEXT)
$(make-exe)
include $(top_srcdir)/../automake/local.am

View File

@@ -0,0 +1,107 @@
/*
* COPYRIGHT (c) 2013.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <coverhd.h>
#include <tmacros.h>
#include <timesys.h>
#include "test_support.h"
#include <pthread.h>
#include <sched.h>
#include <rtems/timerdrv.h>
/* forward declarations to avoid warnings */
void *POSIX_Init(void *argument);
void *Blocker(void *argument);
pthread_mutex_t MutexID;
pthread_cond_t CondID;
void *Blocker(
void *argument
)
{
long end_time;
struct sched_param param;
int policy;
int status;
status = pthread_mutex_lock(&MutexID);
rtems_test_assert( status == 0 );
status = pthread_getschedparam(pthread_self(), &policy, &param);
rtems_test_assert( status == 0 );
param.sched_priority = sched_get_priority_max(policy) - 1;
status = pthread_setschedparam(pthread_self(), policy, &param);
/* Thread blocks, unlocks mutex, waits for CondID to be signaled */
pthread_cond_wait(&CondID,&MutexID);
/* Once signaled, this thread preempts POSIX_Init thread */
end_time = benchmark_timer_read();
put_time(
"pthread_cond_signal - thread waiting, preempt",
end_time,
1,
0,
0
);
puts( "*** END OF POSIX TIME TEST PSXTMCOND04 ***" );
rtems_test_exit( 0 );
return NULL;
}
void *POSIX_Init(
void *argument
)
{
int status;
pthread_t threadId;
puts( "\n\n*** POSIX TIME TEST PSXTMCOND04 ***" );
status = pthread_create( &threadId, NULL, Blocker, NULL );
rtems_test_assert( status == 0 );
status = pthread_mutex_init(&MutexID, NULL);
rtems_test_assert( status == 0 );
status = pthread_cond_init(&CondID, NULL); /* Create condition variable */
rtems_test_assert( status == 0 );
/*
* Let the other thread start so the thread startup overhead,
* is accounted for. When we return, we can start the benchmark.
*/
sched_yield();
/* let other thread run */
/* Other thread is blocked and waiting on condition to be signaled */
benchmark_timer_initialize();
status = pthread_cond_signal(&CondID);
rtems_test_assert ( status == 0 );
return NULL;
}
/* configuration information */
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
#define CONFIGURE_MAXIMUM_POSIX_THREADS 2
#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 2
#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 2
#define CONFIGURE_POSIX_INIT_THREAD_TABLE
#define CONFIGURE_INIT
#include <rtems/confdefs.h>
/* end of file */

View File

@@ -0,0 +1,25 @@
# COPYRIGHT (c) 2013
# On-Line Applications Research Corporation (OAR).
#
# The license and distribution terms for this file may be
# found in the file LICENSE in this distribution or at
# http://www.rtems.com/license/LICENSE.
#
This test benchmarks the following operations:
+ pthread_cond_signal - thread waiting: preempt
This file describes the directives and concepts tested by this test set.
test set name: psxtmcond
directives:
+ pthread_cond_signal
+ pthread_mutex_lock
+ pthread_mutex_init
+ pthread_cond_init
+ pthread_create
concepts:
+ Benchmark the call pthread_cond_signal to unlock a mutex, with a preempt.

View File

@@ -17,7 +17,7 @@
"pthread_cond_destroy","psxtmcond01","psxtmtest_init_destroy","Yes"
"pthread_cond_signal - no threads waiting","psxtmcond02","psxtmtest_single","Yes"
"pthread_cond_signal - thread waiting: no preempt","psxtmcond03","psxtmtest_unblocking_nopreempt","Yes"
"pthread_cond_signal - thread waiting: preempt","psxtmcond04","psxtmtest_unblocking_preempt","No"
"pthread_cond_signal - thread waiting: preempt","psxtmcond04","psxtmtest_unblocking_preempt","Yes"
"pthread_cond_broadcast - no threads waiting","psxtmcond05","psxtmtest_single","Yes"
"pthread_cond_broadcast - threads waiting: no preempt","psxtmcond06","psxtmtest_unblocking_nopreempt","No"
"pthread_cond_broadcast - threads waiting: preempt","psxtmcond07","psxtmtest_unblocking_preempt","No"
1 Test Case Test Template Implemented
17 pthread_cond_destroy psxtmcond01 psxtmtest_init_destroy Yes
18 pthread_cond_signal - no threads waiting psxtmcond02 psxtmtest_single Yes
19 pthread_cond_signal - thread waiting: no preempt psxtmcond03 psxtmtest_unblocking_nopreempt Yes
20 pthread_cond_signal - thread waiting: preempt psxtmcond04 psxtmtest_unblocking_preempt No Yes
21 pthread_cond_broadcast - no threads waiting psxtmcond05 psxtmtest_single Yes
22 pthread_cond_broadcast - threads waiting: no preempt psxtmcond06 psxtmtest_unblocking_nopreempt No
23 pthread_cond_broadcast - threads waiting: preempt psxtmcond07 psxtmtest_unblocking_preempt No