source: rtems/testsuites/psxtests/psxcancel/init.c @ d802489

4.104.114.84.95
Last change on this file since d802489 was d802489, checked in by Joel Sherrill <joel.sherrill@…>, on 08/02/02 at 00:53:21

2002-08-01 Joel Sherrill <joel@…>

  • Per PR47 add support for buffered test output. This involved adding defines to redirect output to a buffer and dump it when full, at "test pause", and at exit. To avoid problems when redefining exit(), all tests were modified to call rtems_test_exit(). Some tests, notable psxtests, had to be modified to include the standard test macro .h file (pmacros.h or tmacros.h) to enable this support.
  • include/pmacros.h, psx01/task.c, psx02/init.c, psx02/task.c, psx03/init.c, psx04/init.c, psx05/init.c, psx06/init.c, psx07/init.c, psx08/task3.c, psx09/init.c, psx10/init.c, psx11/init.c, psx12/init.c, psx13/Makefile.am, psx13/main.c, psx13/test.c, psxcancel/init.c, psxchroot01/Makefile.am, psxchroot01/main.c, psxchroot01/test.c, psxfile01/Makefile.am, psxfile01/main.c, psxfile01/test.c, psxfile01/test_cat.c, psxfile01/test_extend.c, psxfile01/test_write.c, psxmount/Makefile.am, psxmount/main.c, psxmount/test.c, psxmsgq01/init.c, psxreaddir/Makefile.am, psxreaddir/main.c, psxreaddir/test.c, psxsem01/init.c, psxstat/Makefile.am, psxstat/main.c, psxstat/test.c, psxtime/main.c, psxtime/test.c, psxtimer/psxtimer.c: Modified.
  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 * Thread Test Program
3 *
4 *  - test of POSIX's pthread_init() function from rtemstask Init()
5 *
6 *     ott@linux.thai.net
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14
15
16#include <stdio.h>
17#include <stdlib.h>
18#include <pthread.h>
19#include <sys/time.h>
20
21#ifdef __rtems__
22#include <rtems.h>
23/* configuration information */
24
25#define CONFIGURE_INIT
26
27#include <unistd.h>
28#include <errno.h>
29#include <sched.h>
30
31#include <bsp.h> /* for device driver prototypes */
32#include <pmacros.h>
33
34rtems_task Init( rtems_task_argument argument);
35
36/* configuration information */
37
38#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
39#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
40
41#define CONFIGURE_MAXIMUM_TASKS             3
42#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
43#define CONFIGURE_EXTRA_TASK_STACKS         (3 * RTEMS_MINIMUM_STACK_SIZE)
44
45#define CONFIGURE_MAXIMUM_POSIX_THREADS 5
46#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 5
47#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 5
48
49#include <console.h>
50#include <confdefs.h>
51
52#endif /* __rtems__ */
53
54void countTaskDeferred() {
55  int i=0;
56  int type,state;
57
58  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &type);
59  pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &state);
60  while (1) {
61    printf("countTaskDeferred: elapsed time (second): %2d\n", i++ );
62    sleep(1);
63    pthread_testcancel();
64    }
65}
66
67void countTaskAsync() {
68  int i=0;
69  int type,state;
70
71  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &type);
72  pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &state);
73  while (1) {
74    printf("countTaskAsync: elapsed time (second): %2d\n", i++ );
75    sleep(1);
76    }
77}
78
79#ifdef __linux__
80int main(){
81#else
82  rtems_task Init( rtems_task_argument ignored ) {
83#endif
84
85  pthread_t count;
86  int taskparameter = 0;
87
88  puts( "\n\n*** POSIX CANCEL TEST ***" );
89
90  /* Start countTask deferred */
91  {
92    int task_ret;
93    task_ret = pthread_create(&count, NULL, (void *) countTaskDeferred, (void *) &taskparameter);
94    if (task_ret) {
95      perror("pthread_create: countTask");
96      rtems_test_exit(EXIT_FAILURE);
97    }
98    /* sleep for 5 seconds, then cancel it */
99    sleep(5);
100    pthread_cancel(count);
101    pthread_join(count,NULL);
102  }
103
104  /* Start countTask asynchronous */
105  {
106    int task_ret;
107    task_ret = pthread_create(&count, NULL, (void *) countTaskAsync, (void *) &taskparameter);
108    if (task_ret) {
109      perror("pthread_create: countTask");
110      rtems_test_exit(EXIT_FAILURE);
111    }
112    /* sleep for 5 seconds, then cancel it */
113    sleep(5);
114    pthread_cancel(count);
115    pthread_join(count,NULL);
116  }
117
118
119  puts( "*** END OF POSIX CANCEL TEST ***" );
120
121#ifdef __linux__
122  return 0;
123#else
124  rtems_test_exit(EXIT_SUCCESS);
125#endif
126}
127
Note: See TracBrowser for help on using the repository browser.