Subversion Repositories shark

Rev

Rev 1085 | Details | Compare with Previous | 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: test1.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 1:
27
 
28
 this test is a simple main() function with other 2 task
29
 
30
 This test has to be compiled with init1.c, that introduce 2 RR levels
31
 with a timeslice of 300us (!)
32
 
33
 This test can be useful to test functions like
34
 
35
 task_nopreempt
36
 task_preempt
37
 task_create
38
 task_activate
39
 task_delay
40
 group_activate
41
 normal task termination (task_abort)
42
 normal system termination (sys_end)
43
 standard atexit functions (the keyboard...)
44
 
45
 
46
**/
47
 
48
/*
49
 * Copyright (C) 2000 Paolo Gai
50
 *
51
 * This program is free software; you can redistribute it and/or modify
52
 * it under the terms of the GNU General Public License as published by
53
 * the Free Software Foundation; either version 2 of the License, or
54
 * (at your option) any later version.
55
 *
56
 * This program is distributed in the hope that it will be useful,
57
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
58
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
59
 * GNU General Public License for more details.
60
 *
61
 * You should have received a copy of the GNU General Public License
62
 * along with this program; if not, write to the Free Software
63
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
64
 *
65
 */
66
 
67
#include "kernel/kern.h"
68
 
69
// for min
70
#include "ll/stdlib.h"
71
 
72
#include "ll/stdio.h"
73
 
74
 
75
#if !defined(__TEST1__)
76
  THE TEST REQUIRE THE DEFINITION __TEST1__ IN CONFIG.C
77
#endif
78
 
79
struct timespec s_stime[10000];
80
struct timespec s_send[10000];
81
TIME s_curr[10000];
82
PID  s_PID[10000];
83
int useds=0;
84
int testactive=1;
85
 
86
 
87
TASK pippo()
88
{
89
//  int i;
90
  struct timespec t;
91
  int last = 0;
92
 
93
  do {
94
//kern_printf("!");
95
    kern_cli();
96
    ll_gettime(TIME_EXACT, &t);
97
    kern_sti();
98
 
99
    if ((t.tv_nsec/1000000) != last) { //ogni 7000
100
//    kern_printf("%d",t);
101
      last = t.tv_nsec/1000000;
102
//    task_delay(3000000);
103
    }
104
 
105
  } while (t.tv_nsec <= 20000000L);
106
}
107
 
108
TASK pippo2()
109
{
110
  struct timespec t;
111
  do {
112
//    kern_printf("pippo2");
113
    kern_cli();
114
    ll_gettime(TIME_EXACT, &t);
115
    kern_sti();
116
    if (t.tv_nsec > 5000000 && t.tv_nsec <= 12000000) task_nopreempt();
117
    if (t.tv_nsec > 12000000) task_preempt();
118
 
119
  } while (t.tv_nsec <= 20000000L);
120
}
121
 
122
int main(int argc, char **argv)
123
{
124
  struct timespec t;
125
  int i;
126
  NRT_TASK_MODEL m;
127
  PID p2,p3;
128
 
129
  nrt_task_default_model(m);
130
  nrt_task_def_group(m,1);
131
 
132
  p2 = task_createn("pippo", pippo, &m, NULL);
133
  if (p2 == NIL)
134
  { kern_printf("Can't create pippo task...\n"); return 1; }
135
 
136
  p3 = task_createn("pippo2", pippo2, &m, NULL);
137
  if (p3 == NIL)
138
  { kern_printf("Can't create pippo2 task...\n"); return 1; }
139
 
140
  group_activate(1);
141
 
142
 
143
  kern_printf("DENTRO MAIN %d\n",ll_context_save());
144
 
145
//  testactive = 1;
146
  NULL_TIMESPEC(&t);
147
  do {
148
    kern_cli();
149
    ll_gettime(TIME_EXACT, &t);
150
    kern_sti();
151
//    task_delay(14000);
152
 
153
  } while (t.tv_nsec <= 40000000L);
154
  testactive = 0;
155
 
156
//  sys_status(0xFFFF);
157
//  return 0;
158
 
159
  kern_printf("FINE MAIN time=%d useds=%d\n",ll_gettime(TIME_EXACT,NULL),useds);
160
  for (i=0; i<min(useds,20); i++)
161
     kern_printf("%6d: pid %6d stime %-9d reschedule %-9d avail %-9d\n",i,
162
               s_PID[i], s_stime[i].tv_nsec, s_send[i].tv_nsec, s_curr[i]);
163
//  sys_end();
164
 
165
  kern_printf("DENTRO MAIN %d\n",ll_context_save());
166
  return 0;
167
}