Subversion Repositories shark

Rev

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: test2.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 2:
27
 task_testcancel,
28
 task_delay
29
 task_setcancelstate
30
 
31
 The task 2 disappear after time 10000 because we have reactivated
32
 the cancelability and a testcancel is issued
33
 
34
**/
35
 
36
/*
37
 * Copyright (C) 2000 Paolo Gai
38
 *
39
 * This program is free software; you can redistribute it and/or modify
40
 * it under the terms of the GNU General Public License as published by
41
 * the Free Software Foundation; either version 2 of the License, or
42
 * (at your option) any later version.
43
 *
44
 * This program is distributed in the hope that it will be useful,
45
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
46
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
47
 * GNU General Public License for more details.
48
 *
49
 * You should have received a copy of the GNU General Public License
50
 * along with this program; if not, write to the Free Software
51
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
52
 *
53
 */
54
 
55
#include "kernel/kern.h"
56
 
57
#if !defined(__TEST1__)
58
  THE TEST REQUIRE THE DEFINITION __TEST1__ IN CONFIG.C
59
#endif
60
 
61
struct timespec s_stime[10000];
62
struct timespec s_send[10000];
63
TIME s_curr[10000];
64
PID  s_PID[10000];
65
int useds=0;
66
int testactive=1;
67
 
68
 
69
TASK pippo()
70
{
71
  int i;
72
  struct timespec t;
73
//  int last = 0;
74
 
75
  task_setcancelstate(TASK_CANCEL_DISABLE,&i);
76
  do {
77
    kern_cli();
78
    ll_gettime(TIME_EXACT, &t);
79
    kern_sti();
80
//    printf_xy(10,8,WHITE,"%9d s%9d n%9d",exec_shadow,t.tv_sec,t.tv_nsec);
81
 
82
    if (t.tv_nsec > 10000000)
83
    {
84
      task_setcancelstate(TASK_CANCEL_ENABLE,&i);
85
    }
86
    if (t.tv_nsec > 5000000)
87
    {
88
//      kern_printf("\n%d %dÄ", exec_shadow, proc_table[exec_shadow].control);
89
      task_testcancel();
90
    }
91
    task_delay(1000);
92
//    kern_printf("Dopo Delay %d ",exec_shadow);
93
 
94
  } while (t.tv_nsec <= 30000000L);
95
}
96
 
97
TASK pippo2()
98
{
99
  int i;
100
  struct timespec t;
101
//  int last = 0;
102
 
103
  do {
104
    kern_cli();
105
    ll_gettime(TIME_EXACT, &t);
106
    kern_sti();
107
//    printf_xy(10,9,WHITE,"%d s%9d n%9d\n",exec_shadow,t.tv_sec,t.tv_nsec);
108
//    kern_printf("Û%dÛ",proc_table[exec_shadow].control);
109
 
110
    if (t.tv_nsec > 15000000)
111
    {
112
//      kern_printf("XXXXXXXXXX");
113
      task_setcanceltype(TASK_CANCEL_ASYNCHRONOUS,&i);
114
    }
115
    task_delay(1000);
116
 
117
  } while (t.tv_nsec <= 30000000L);
118
}
119
 
120
int main(int argc, char **argv)
121
{
122
  struct timespec t;
123
  int i;
124
  NRT_TASK_MODEL m;
125
  PID p2,p3;
126
//  int k=1;
127
 
128
  nrt_task_default_model(m);
129
  nrt_task_def_group(m,1);
130
 
131
  p2 = task_create("pippo2", pippo, &m, NULL);
132
  if (p2 == NIL)
133
  { kern_printf("Can't create pippo2 task...\n"); return 1; }
134
 
135
  p3 = task_create("pippo3", pippo2, &m, NULL);
136
  if (p3 == NIL)
137
  { kern_printf("Can't create pippo3 task...\n"); return 1; }
138
 
139
  group_activate(1);
140
 
141
 
142
  task_kill(p2);
143
 
144
  NULL_TIMESPEC(&t);
145
  do {
146
    kern_cli();
147
    ll_gettime(TIME_EXACT, &t);
148
    kern_sti();
149
 
150
    task_kill(p3);
151
 
152
  } while (t.tv_nsec <= 20000000L);
153
  testactive = 0;
154
 
155
  kern_printf("FINE MAIN time=%d useds=%d\n",ll_gettime(TIME_EXACT,NULL),useds);
156
  for (i=0; i<useds; i++)
157
     kern_printf("%6d: pid %-9d stime %-9d reschedule %-9d avail %-9d\n",i,
158
               s_PID[i], s_stime[i].tv_nsec, s_send[i].tv_nsec, s_curr[i]);
159
 
160
  return 0;
161
}