source: rtems/testsuites/psxtests/psxcond01/init.c @ 14d3ad4f

4.104.115
Last change on this file since 14d3ad4f was 14d3ad4f, checked in by Joel Sherrill <joel.sherrill@…>, on 07/21/09 at 15:07:26

2009-07-21 Joel Sherrill <joel.sherrill@…>

  • Makefile.am, configure.ac: Add new test to exercise error case for when a task is blocked on a condition variable with one mutex and another task attempts to block on the same condition variable with another mutex.
  • psxcond01/.cvsignore, psxcond01/Makefile.am, psxcond01/init.c, psxcond01/psxcond01.doc, psxcond01/psxcond01.scn: New files.
  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2009.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#include "tmacros.h"
13#include <pthread.h>
14#include <errno.h>
15
16pthread_cond_t  Condition;
17pthread_mutex_t Mutex1;
18pthread_mutex_t Mutex2;
19
20void *BlockingThread(
21  void *argument
22)
23{
24  puts( "BlockingThread - pthread_cond_wait on Mutex1 - OK" );
25  (void) pthread_cond_wait( &Condition, &Mutex1 );
26
27  puts( "ERROR - BlockingThread returned from pthread_cond_wait!" );
28  rtems_test_exit( 0 );
29
30  return NULL;
31}
32
33void *POSIX_Init(
34  void *argument
35)
36{
37  int        sc;
38  pthread_t  Thread;
39
40  puts( "\n\n*** POSIX TEST -- CONDITION VARIABLE 01 ***" );
41
42  puts( "Init - pthread_mutex_init - Mutex1 - OK" );
43  sc = pthread_mutex_init( &Mutex1, NULL );
44  fatal_posix_service_status( sc, 0, "mutex1 create ok" );
45
46  puts( "Init - pthread_mutex_init - Mutex2 - OK" );
47  sc = pthread_mutex_init( &Mutex2, NULL );
48  fatal_posix_service_status( sc, 0, "mutex2 create ok" );
49
50  puts( "Init - pthread_cond_init - Condition - OK" );
51  sc = pthread_cond_init( &Condition, NULL );
52  fatal_posix_service_status( sc, 0, "Condition create ok" );
53
54  puts( "Init -  pthread_create - OK" );
55  sc = pthread_create( &Thread, NULL, BlockingThread, NULL );
56  fatal_posix_service_status( sc, 0, "Thread create ok" );
57 
58  puts( "Init - sleep to let BlockingThread run" );
59  sleep(1);
60
61  puts( "Init - pthread_cond_wait on Mutex2 - EINVAL" );
62  sc = pthread_cond_wait( &Condition, &Mutex2 );
63  fatal_posix_service_status( sc, EINVAL, "cond_wait EINVAL" );
64
65  puts( "*** END OF POSIX TEST CONDITION VARIABLE 01 ***" );
66  rtems_test_exit( 0 );
67
68  return NULL; /* just so the compiler thinks we returned something */
69}
70
71#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
72#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
73
74#define CONFIGURE_MAXIMUM_POSIX_THREADS 2
75#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 2
76#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 1
77
78#define CONFIGURE_POSIX_INIT_THREAD_TABLE
79
80#define CONFIGURE_INIT
81#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.