source: rtems/testsuites/psxtests/psxcond01/init.c @ c4b8b147

5
Last change on this file since c4b8b147 was c4b8b147, checked in by Sebastian Huber <sebastian.huber@…>, on 11/03/17 at 07:35:38

tests: Use simple console driver

Update #3170.
Update #3199.

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2013.
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.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#include "tmacros.h"
15#include <pthread.h>
16#include <errno.h>
17
18const char rtems_test_name[] = "PSXCOND 1";
19
20/* forward declarations to avoid warnings */
21void *POSIX_Init(void *argument);
22void *BlockingThread(void *argument);
23
24pthread_cond_t  Condition;
25pthread_mutex_t Mutex1;
26pthread_mutex_t Mutex2;
27
28void *BlockingThread(
29  void *argument
30)
31{
32  int sc;
33
34  puts( "BlockingThread - pthread_cond_wait with mutex not locked - EPERM" );
35  sc = pthread_cond_wait( &Condition, &Mutex1 );
36  fatal_posix_service_status( sc, EPERM, "mutex1 not locked" );
37
38  sc = pthread_mutex_lock( &Mutex1 );
39  fatal_posix_service_status( sc, 0, "mutex1 lock" );
40 
41  puts( "BlockingThread - pthread_cond_wait on Mutex1 - OK" );
42  sc = pthread_cond_wait( &Condition, &Mutex1 );
43
44  printf(
45    "ERROR - BlockingThread returned from pthread_cond_wait! (rc=%d/%s)\n",
46    sc,
47    strerror(sc)
48  );
49  rtems_test_exit( 0 );
50
51  return NULL;
52}
53
54void *POSIX_Init(
55  void *argument
56)
57{
58  int        sc;
59  pthread_t  Thread;
60
61  TEST_BEGIN();
62
63  puts( "Init - pthread_mutex_init - Mutex1 - OK" );
64  sc = pthread_mutex_init( &Mutex1, NULL );
65  fatal_posix_service_status( sc, 0, "mutex1 create ok" );
66
67  puts( "Init - pthread_mutex_init - Mutex2 - OK" );
68  sc = pthread_mutex_init( &Mutex2, NULL );
69  fatal_posix_service_status( sc, 0, "mutex2 create ok" );
70
71  puts( "Init - pthread_cond_init - Condition - OK" );
72  sc = pthread_cond_init( &Condition, NULL );
73  fatal_posix_service_status( sc, 0, "Condition create ok" );
74
75  puts( "Init -  pthread_create - OK" );
76  sc = pthread_create( &Thread, NULL, BlockingThread, NULL );
77  fatal_posix_service_status( sc, 0, "Thread create ok" );
78
79  puts( "Init - sleep to let BlockingThread run" );
80  sleep(1);
81
82  puts( "Init - pthread_cond_wait on Mutex2 - EINVAL" );
83  sc = pthread_cond_wait( &Condition, &Mutex2 );
84  fatal_posix_service_status( sc, EINVAL, "cond_wait EINVAL" );
85
86  TEST_END();
87  rtems_test_exit( 0 );
88
89  return NULL; /* just so the compiler thinks we returned something */
90}
91
92#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
93#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
94
95#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
96
97#define CONFIGURE_MAXIMUM_POSIX_THREADS 2
98
99#define CONFIGURE_POSIX_INIT_THREAD_TABLE
100
101#define CONFIGURE_INIT
102#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.