KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > DEOS > Assertion


1 //
2
// Copyright (C) 2005 United States Government as represented by the
3
// Administrator of the National Aeronautics and Space Administration
4
// (NASA). All Rights Reserved.
5
//
6
// This software is distributed under the NASA Open Source Agreement
7
// (NOSA), version 1.3. The NOSA has been approved by the Open Source
8
// Initiative. See the file NOSA-1.3-JPF at the top of the distribution
9
// directory tree for the complete NOSA document.
10
//
11
// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
12
// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
13
// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
14
// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
15
// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
16
// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
17
// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
18
//
19
package DEOS;
20
21 /**
22  * DOCUMENT ME!
23  */

24 class Assertion {
25   // static List allThreads = new ArrayList();
26
static Thread JavaDoc[] allThreads = new Thread JavaDoc[4];
27   static int[] total_time = new int[2];
28   static int num_entries = 0;
29
30   public static void addThread (Thread JavaDoc t) {
31     //allThreads.add(t);
32
allThreads[num_entries] = t;
33     num_entries++;
34   }
35
36   public static boolean check () {
37     //Verify.beginAtomic();
38
total_time[0] = 0;
39     total_time[1] = 0;
40
41     //Iterator it = allThreads.iterator();
42
Thread JavaDoc current;
43
44     //while(it.hasNext()) {
45
for (int i = 0; i < num_entries; i++) {
46       //current = (Thread)it.next();
47
current = allThreads[i];
48
49       if (current != Scheduler.idleThread()) {
50         int cp = current.itsPeriodicEvent.currentPeriod();
51
52         if ((current.itsLastExecution == cp) &&
53                 (current.itsLastCompletion != cp)) {
54           //System.out.println(" " + current + " executed current period:");
55
total_time[1] += current.itsCurrentBudget.remainingBudgetInUsec();
56
57           //System.out.println("then: " + current +
58
// " adds " + current.itsCurrentBudget.remainingBudgetInUsec() +
59
// " total = " + total_time[1]);
60
if (current.itsPeriodIndex == 0) {
61             total_time[0] += current.itsCurrentBudget.remainingBudgetInUsec();
62           }
63         } else if (current.itsLastExecution != cp) {
64           total_time[1] += current.itsCurrentBudget.totalBudgetInUsec();
65
66           //System.out.println("else: " + current +
67
//" adds " + current.itsCurrentBudget.totalBudgetInUsec() +
68
//" total = " + total_time[1]);
69
if (current.itsPeriodIndex == 0) {
70             total_time[0] += current.itsCurrentBudget.totalBudgetInUsec();
71           }
72         }
73
74         if (current.itsPeriodIndex == 0) {
75           int tmp = (current.itsCurrentBudget.totalBudgetInUsec()) * (StartOfPeriodEvent.eventForPeriodIndex(1).countDown - 1);
76           total_time[1] += tmp;
77
78           //System.out.println(current +
79
// " adds future " + tmp + " total = " + total_time[1]);
80
}
81       }
82     }
83
84     // calculate time remaining in period
85
int period_count = StartOfPeriodEvent.eventForPeriodIndex(1).countDown - 1;
86
87     //System.out.println("period count = " + period_count);
88
int current_period = StartOfPeriodEvent.eventForPeriodIndex(1)
89                                            .currentPeriod();
90
91     //System.out.println("current period = " + current_period);
92
// Modified by ckong - June 26, 2001
93
//int remaining = (Registry.uSecsInFastestPeriod*period_count) +
94
// Registry.uSecsInFastestPeriod - Timer.Used_time;
95
if (Scheduler.currentThread() != Scheduler.idleThread()) {
96       int remaining = ((Registry.uSecsInFastestPeriod * period_count) +
97                       Registry.uSecsInFastestPeriod) -
98                       DEOS.thePeriodicClock.getUsedTime();
99
100       //System.out.println("remaining: " + remaining);
101
// THE ACTUAL ASSERTION!
102
if (total_time[1] > remaining) {
103         DEOS.println("Ooops: Time wanted " + total_time[1] + " > " +
104                      remaining);
105         assert false;
106       } else {
107         //System.out.println("Fine: wanted " + total_time[1] + " <= " + remaining);
108
}
109     }
110
111     total_time[0] = 0;
112     total_time[1] = 0;
113
114     return true;
115   }
116
117   public static void removeThread (Thread JavaDoc t) {
118     //allThreads.remove(t);
119
for (int i = 0; i < num_entries; i++) {
120       if (allThreads[i] == t) {
121         for (int j = i + 1; j < num_entries; j++) {
122           allThreads[j - 1] = allThreads[j];
123         }
124
125         num_entries--;
126
127         return;
128       }
129     }
130   }
131 }
Popular Tags