Subversion Repositories shark

Rev

Rev 1085 | Rev 1450 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1085 pj 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   (see the web pages for full authors list)
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
/**
20
 ------------
21
 CVS :        $Id: ptest1.c,v 1.1.1.1 2002-09-02 09:37:47 pj Exp $
22
 
23
 File:        $File$
24
 Revision:    $Revision: 1.1.1.1 $
25
 Last update: $Date: 2002-09-02 09:37:47 $
26
 ------------
27
 
28
 Posix test 1:
29
 
30
   the main task create 4 tasks, J1, J2, J3, J4
31
     at t = 0.2 sec. it raise a signal to J1
32
     at t = 0.4 sec. it raise a signal to J2
33
     at t = 0.8 sec. it kill J4
34
 
35
   J1: it simply calls sigwait
36
 
37
   J2: it simply calls sigwaitinfo
38
 
39
   J3: it simply calls sigtimedwait with a timeout of 0.5 sec.
40
 
41
   J4: it simply calls sigtimedwait with a -long- timeout
42
       (J4 will be killed by main)
43
 
44
 non standard function used:
45
   cprintf
46
   sys_gettime
47
   keyboard stuffs
48
   sys_end
49
 
50
**/
51
 
52
/*
53
 * Copyright (C) 2000 Paolo Gai
54
 *
55
 * This program is free software; you can redistribute it and/or modify
56
 * it under the terms of the GNU General Public License as published by
57
 * the Free Software Foundation; either version 2 of the License, or
58
 * (at your option) any later version.
59
 *
60
 * This program is distributed in the hope that it will be useful,
61
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
62
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
63
 * GNU General Public License for more details.
64
 *
65
 * You should have received a copy of the GNU General Public License
66
 * along with this program; if not, write to the Free Software
67
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
68
 *
69
 */
70
 
71
#include <sys/types.h>
72
#include <pthread.h>
73
#include <signal.h>
74
 
75
#include <kernel/kern.h>
76
#include <drivers/keyb.h>
77
 
78
void *J1(void *arg)
79
{
80
  int sig, err;
81
  sigset_t mask;
82
 
83
  cprintf("J1 starts and call sigwait(31)\n");
84
 
85
  sigemptyset(&mask);
86
  sigaddset(&mask,31);
87
  err = sigwait(&mask,&sig);
88
 
89
  cprintf("J1 exit from sigwait(), err=%d, sig=%d\n", err, sig);
90
 
91
  return 0;
92
}
93
 
94
void *J2(void *arg)
95
{
96
  int err;
97
  siginfo_t info;
98
  sigset_t mask;
99
 
100
  cprintf("J2 starts and call sigwaitinfo(30)\n");
101
 
102
  sigemptyset(&mask);
103
  sigaddset(&mask,30);
104
  err = sigwaitinfo(&mask,&info);
105
 
106
  cprintf("J2 exit from sigwaitinfo(), err=%d, signo=%d code=%d value=%d\n",
107
              err, info.si_signo, info.si_code, info.si_value.sival_int);
108
 
109
  return 0;
110
}
111
 
112
void *J3(void *arg)
113
{
114
  int err;
115
  siginfo_t info;
116
  sigset_t mask;
117
  struct timespec t;
118
 
119
  cprintf("J3 starts and call sigtimedwait(29)\n");
120
 
121
  sigemptyset(&mask);
122
  sigaddset(&mask,29);
123
  t.tv_sec = 0;
124
  t.tv_nsec = 300000000;
125
  err = sigtimedwait(&mask,&info,&t);
126
 
127
  cprintf("J3 exit from sigtimedwait(), err=%d, signo=%d code=%d value=%d\n",
128
              err, info.si_signo, info.si_code, info.si_value.sival_int);
129
 
130
  return 0;
131
}
132
 
133
void uscitaJ4(void *arg)
134
{
135
  cprintf("J4: AAAARRRRGGGHHH!!! killed by someone...\n");
136
}
137
 
138
void *J4(void *arg)
139
{
140
  int err;
141
  siginfo_t info;
142
  sigset_t mask;
143
  struct timespec t;
144
 
145
  cprintf("J4 starts and call sigtimedwait(28)\n");
146
 
147
  sigemptyset(&mask);
148
  sigaddset(&mask,28);
149
  t.tv_sec = 10;
150
  t.tv_nsec = 0;
151
 
152
  pthread_cleanup_push(uscitaJ4,NULL);
153
  err = sigtimedwait(&mask,&info,&t);
154
  pthread_cleanup_pop(0);
155
 
156
  cprintf("J4 exit from sigtimedwait(), err=%d, signo=%d code=%d value=%d\n",
157
              err, info.si_signo, info.si_code, info.si_value.sival_int);
158
 
159
  return 0;
160
}
161
 
162
void fine(KEY_EVT *e)
163
{
164
  sys_end();
165
}
166
 
167
 
168
int main(int argc, char **argv)
169
{
170
  int err;
171
  sigset_t mask;
172
  pthread_t j1, j2, j3, j4;
173
  union sigval value;
174
 
175
    KEY_EVT emerg;
176
    //keyb_set_map(itaMap);
177
    emerg.ascii = 'x';
178
    emerg.scan = KEY_X;
179
    emerg.flag = ALTL_BIT;
180
    keyb_hook(emerg,fine);
181
 
182
 
183
  /* main blocks signals for all the tasks */
184
  sigfillset(&mask);
185
  pthread_sigmask(SIG_BLOCK, &mask, NULL);
186
 
187
  cprintf("main: creating J1\n");
188
  err = pthread_create(&j1, NULL, J1, NULL);
189
  if (err) cprintf("Error creating J1\n");
190
 
191
  cprintf("main: creating J2\n");
192
  err = pthread_create(&j2, NULL, J2, NULL);
193
  if (err) cprintf("Error creating J2\n");
194
 
195
  cprintf("main: creating J3\n");
196
  err = pthread_create(&j3, NULL, J3, NULL);
197
  if (err) cprintf("Error creating J3\n");
198
 
199
  cprintf("main: creating J4\n");
200
  err = pthread_create(&j4, NULL, J4, NULL);
201
  if (err) cprintf("Error creating J4\n");
202
 
203
  cprintf("main: waiting 0.2 sec\n");
204
  while (sys_gettime(NULL) < 200000);
205
 
206
  cprintf("main: kill(31), then wait until t=0.4 sec \n");
207
  kill(0, 31);
208
 
209
  while (sys_gettime(NULL) < 400000);
210
  cprintf("main: sigqueue(30), then wait until t=0.8 sec \n");
211
  value.sival_int = 300;
212
  sigqueue(0, 30, value);
213
 
214
  while (sys_gettime(NULL) < 800000);
215
  cprintf("main: kill(J4)\n");
216
  pthread_cancel(j4);
217
 
218
  cprintf("main: ending...\n");
219
 
220
  return 0;
221
}