Subversion Repositories shark

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1085 pj 1
/*
2
 * Project: HARTIK (HA-rd R-eal TI-me K-ernel)
3
 *
4
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
5
 *               Gerardo Lamastra <gerardo@sssup.it>
6
 *
7
 * Authors     : Paolo Gai <pj@hartik.sssup.it>
8
 * (see authors.txt for full list of hartik's authors)
9
 *
10
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
11
 *
12
 * http://www.sssup.it
13
 * http://retis.sssup.it
14
 * http://hartik.sssup.it
15
 */
16
 
17
/**
18
 ------------
19
 CVS :        $Id: testq.c,v 1.1.1.1 2002-09-02 09:37:48 pj Exp $
20
 
21
 File:        $File$
22
 Revision:    $Revision: 1.1.1.1 $
23
 Last update: $Date: 2002-09-02 09:37:48 $
24
 ------------
25
 
26
 Test Number 26 (Q):
27
 
28
 This test verify the correctness of the task_join primitive.
29
 
30
 There are 4 taks, J1, J2, J3, are created as joinable, J4 as detached
31
 (the standard with hartik...)
32
 
33
 The main task:
34
   Creates J1 and J2, locks m1 (a PI mitex), creates C3.
35
   at t=0.8 sec it calls a task_join on J3 (that returns EDEADLK),
36
   it unlocks m1, then it makes task_join on J3 another time.
37
   Next it creates J4 as detached and finally it does a task_join on J4
38
   (that returns EINVAL).
39
 
40
 J1:
41
   at t=0.2 sec it calls task_join on J2, the it ends.
42
 
43
 J2:
44
   it simply waits t=0.4 sec and it ends.
45
 
46
 J3:
47
   First, it calls task_join on J1.
48
   Then, at t=0.6 sec it locks m1, then unlocks it
49
 
50
 J4:
51
   it simply waits t=1 sec and it ends.
52
 
53
**/
54
 
55
/*
56
 * Copyright (C) 2000 Paolo Gai
57
 *
58
 * This program is free software; you can redistribute it and/or modify
59
 * it under the terms of the GNU General Public License as published by
60
 * the Free Software Foundation; either version 2 of the License, or
61
 * (at your option) any later version.
62
 *
63
 * This program is distributed in the hope that it will be useful,
64
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
65
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
66
 * GNU General Public License for more details.
67
 *
68
 * You should have received a copy of the GNU General Public License
69
 * along with this program; if not, write to the Free Software
70
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
71
 *
72
 */
73
 
74
#include "kernel/kern.h"
75
#include "drivers/keyb.h"
76
 
77
#include <modules//srp.h>
78
 
79
 
80
PID j0, j1, j2, j3, j4;
81
mutex_t  m1;
82
 
83
void fine(KEY_EVT *e)
84
{
85
  sys_end();
86
}
87
 
88
TASK J1()
89
{
90
  int err;
91
  void *ret;
92
 
93
  kern_printf("J1: started, waiting 0.2 sec\n");
94
 
95
  while (sys_gettime(NULL) < 200000);
96
 
97
  kern_printf("J1: 0.2 sec reached, joining J2\n");
98
 
99
  err = task_join(j2, &ret);
100
 
101
  kern_printf("J1: join J2 returns %d error %d, exiting\n",
102
              (int)ret,err);
103
  return (void *)11;
104
}
105
 
106
TASK J2()
107
{
108
  kern_printf("J2: started, waiting 0.4 sec\n");
109
 
110
  while (sys_gettime(NULL) < 400000);
111
 
112
  kern_printf("J2: 0.4 sec reached, exiting\n");
113
 
114
  return (void *)22;
115
}
116
 
117
TASK J3()
118
{
119
  int err;
120
  void *ret;
121
 
122
  kern_printf("J3: started, joining J1\n");
123
 
124
  err = task_join(j1, &ret);
125
 
126
  kern_printf("J3: join J1 returns %d error %d, waiting 0.6sec\n", (int)ret, err);
127
 
128
  while (sys_gettime(NULL) < 600000);
129
 
130
  kern_printf("J1: 0.6 sec reached, locking m1\n");
131
 
132
  mutex_lock(&m1);
133
 
134
  kern_printf("J3: locked m1, unlocking m1\n");
135
 
136
  mutex_unlock(&m1);
137
 
138
  kern_printf("J3: unlocked m1, exiting\n");
139
 
140
  return (void *)33;
141
}
142
 
143
TASK J4()
144
{
145
  kern_printf("J4: started, waiting 1 sec\n");
146
 
147
  while (sys_gettime(NULL) < 1000000);
148
 
149
  kern_printf("J4: 1 sec reached, exiting\n");
150
 
151
  return (void *)44;
152
}
153
 
154
int main(int argc, char **argv)
155
{
156
  NRT_TASK_MODEL m;
157
 
158
  PI_mutexattr_t a;
159
 
160
  KEY_EVT emerg;
161
 
162
  int err;
163
  void *ret;
164
 
165
  //keyb_set_map(itaMap);
166
  emerg.ascii = 'x';
167
  emerg.scan = KEY_X;
168
  emerg.flag = ALTL_BIT;
169
  keyb_hook(emerg,fine);
170
 
171
  j0 = exec_shadow;
172
  nrt_task_default_model(m);
173
  nrt_task_def_joinable(m);
174
 
175
  /* ---------------------------------------------------------------------
176
     Mutex creation
177
     --------------------------------------------------------------------- */
178
 
179
  PI_mutexattr_default(a);
180
  mutex_init(&m1,&a);
181
 
182
 
183
  /* ---------------------------------------------------------------------
184
     Let's go !!!!
185
     --------------------------------------------------------------------- */
186
 
187
  kern_printf("main: creating J1,J2,J3, locking m1\n");
188
 
189
  j1 = task_create("J1", J1, &m, NULL);
190
  if (j1 == NIL) { kern_printf("Can't create J1 task...\n"); return 1; }
191
  task_activate(j1);
192
 
193
  j2 = task_create("J2", J2, &m, NULL);
194
  if (j2 == NIL) { kern_printf("Can't create J2 task...\n"); return 1; }
195
  task_activate(j2);
196
 
197
  mutex_lock(&m1);
198
 
199
  j3 = task_create("J3", J3, &m, NULL);
200
  if (j3 == NIL) { kern_printf("Can't create J3 task...\n"); return 1; }
201
  task_activate(j3);
202
 
203
  kern_printf("main: waiting t=0.8 sec\n");
204
 
205
  while (sys_gettime(NULL) < 800000);
206
 
207
  err = task_join(j3, NULL);
208
 
209
  kern_printf("main: join J3 error %d, unlocking m1\n",err);
210
 
211
  mutex_unlock(&m1);
212
 
213
  err = task_join(j3, &ret);
214
 
215
  kern_printf("main: join J3 returns %d error %d, unlocked m1, creating J4\n",
216
            (int)ret,err);
217
 
218
  nrt_task_def_unjoinable(m);
219
  j4 = task_create("J4", J4, &m, NULL);
220
  if (j4 == NIL) { kern_printf("Can't create J4 task...\n"); return 1; }
221
 
222
  task_activate(j4);
223
 
224
  err = task_join(j4,&ret);
225
 
226
  kern_printf("main: join J4 returns %d error %d, exiting\n", (int)ret, err);
227
 
228
  return 0;
229
}