001: //
002: // Copyright (C) 2005 United States Government as represented by the
003: // Administrator of the National Aeronautics and Space Administration
004: // (NASA). All Rights Reserved.
005: //
006: // This software is distributed under the NASA Open Source Agreement
007: // (NOSA), version 1.3. The NOSA has been approved by the Open Source
008: // Initiative. See the file NOSA-1.3-JPF at the top of the distribution
009: // directory tree for the complete NOSA document.
010: //
011: // THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
012: // KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
013: // LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
014: // SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
015: // A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
016: // THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
017: // DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
018: //
019: package DEOS;
020:
021: /**
022: * DOCUMENT ME!
023: */
024: class Assertion {
025: // static List allThreads = new ArrayList();
026: static Thread[] allThreads = new Thread[4];
027: static int[] total_time = new int[2];
028: static int num_entries = 0;
029:
030: public static void addThread(Thread t) {
031: //allThreads.add(t);
032: allThreads[num_entries] = t;
033: num_entries++;
034: }
035:
036: public static boolean check() {
037: //Verify.beginAtomic();
038: total_time[0] = 0;
039: total_time[1] = 0;
040:
041: //Iterator it = allThreads.iterator();
042: Thread current;
043:
044: //while(it.hasNext()) {
045: for (int i = 0; i < num_entries; i++) {
046: //current = (Thread)it.next();
047: current = allThreads[i];
048:
049: if (current != Scheduler.idleThread()) {
050: int cp = current.itsPeriodicEvent.currentPeriod();
051:
052: if ((current.itsLastExecution == cp)
053: && (current.itsLastCompletion != cp)) {
054: //System.out.println(" " + current + " executed current period:");
055: total_time[1] += current.itsCurrentBudget
056: .remainingBudgetInUsec();
057:
058: //System.out.println("then: " + current +
059: // " adds " + current.itsCurrentBudget.remainingBudgetInUsec() +
060: // " total = " + total_time[1]);
061: if (current.itsPeriodIndex == 0) {
062: total_time[0] += current.itsCurrentBudget
063: .remainingBudgetInUsec();
064: }
065: } else if (current.itsLastExecution != cp) {
066: total_time[1] += current.itsCurrentBudget
067: .totalBudgetInUsec();
068:
069: //System.out.println("else: " + current +
070: //" adds " + current.itsCurrentBudget.totalBudgetInUsec() +
071: //" total = " + total_time[1]);
072: if (current.itsPeriodIndex == 0) {
073: total_time[0] += current.itsCurrentBudget
074: .totalBudgetInUsec();
075: }
076: }
077:
078: if (current.itsPeriodIndex == 0) {
079: int tmp = (current.itsCurrentBudget
080: .totalBudgetInUsec())
081: * (StartOfPeriodEvent
082: .eventForPeriodIndex(1).countDown - 1);
083: total_time[1] += tmp;
084:
085: //System.out.println(current +
086: // " adds future " + tmp + " total = " + total_time[1]);
087: }
088: }
089: }
090:
091: // calculate time remaining in period
092: int period_count = StartOfPeriodEvent.eventForPeriodIndex(1).countDown - 1;
093:
094: //System.out.println("period count = " + period_count);
095: int current_period = StartOfPeriodEvent.eventForPeriodIndex(1)
096: .currentPeriod();
097:
098: //System.out.println("current period = " + current_period);
099: // Modified by ckong - June 26, 2001
100: //int remaining = (Registry.uSecsInFastestPeriod*period_count) +
101: // Registry.uSecsInFastestPeriod - Timer.Used_time;
102: if (Scheduler.currentThread() != Scheduler.idleThread()) {
103: int remaining = ((Registry.uSecsInFastestPeriod * period_count) + Registry.uSecsInFastestPeriod)
104: - DEOS.thePeriodicClock.getUsedTime();
105:
106: //System.out.println("remaining: " + remaining);
107: // THE ACTUAL ASSERTION!
108: if (total_time[1] > remaining) {
109: DEOS.println("Ooops: Time wanted " + total_time[1]
110: + " > " + remaining);
111: assert false;
112: } else {
113: //System.out.println("Fine: wanted " + total_time[1] + " <= " + remaining);
114: }
115: }
116:
117: total_time[0] = 0;
118: total_time[1] = 0;
119:
120: return true;
121: }
122:
123: public static void removeThread(Thread t) {
124: //allThreads.remove(t);
125: for (int i = 0; i < num_entries; i++) {
126: if (allThreads[i] == t) {
127: for (int j = i + 1; j < num_entries; j++) {
128: allThreads[j - 1] = allThreads[j];
129: }
130:
131: num_entries--;
132:
133: return;
134: }
135: }
136: }
137: }
|