Package: TraceNode

TraceNode

nameinstructionbranchcomplexitylinemethod
TraceNode()
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
addVarFirst(TraceVariable)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
executeTests(TraceNode, Class, TestAccumulator, Store)
M: 251 C: 0
0%
M: 24 C: 0
0%
M: 13 C: 0
0%
M: 55 C: 0
0%
M: 1 C: 0
0%
executeTests(TraceNode, TestAccumulator, Store)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getResultStr(List, String)
M: 39 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
getVars()
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
showResults(List)
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
toStr(Object)
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: *
3: *        Copyright (C) 2008, 2009 Fujitsu Services Ltd.
4: *
5: *        Author: Nick Battle
6: *
7: *        This file is part of VDMJ.
8: *
9: *        VDMJ is free software: you can redistribute it and/or modify
10: *        it under the terms of the GNU General Public License as published by
11: *        the Free Software Foundation, either version 3 of the License, or
12: *        (at your option) any later version.
13: *
14: *        VDMJ is distributed in the hope that it will be useful,
15: *        but WITHOUT ANY WARRANTY; without even the implied warranty of
16: *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: *        GNU General Public License for more details.
18: *
19: *        You should have received a copy of the GNU General Public License
20: *        along with VDMJ. If not, see <http://www.gnu.org/licenses/>.
21: *
22: ******************************************************************************/
23:
24: package org.overture.codegen.runtime.traces;
25:
26: import java.util.LinkedList;
27: import java.util.List;
28:
29: import org.overture.codegen.runtime.Utils;
30:
31: public abstract class TraceNode
32: {
33:         private static final int ENCLOSING_MODULE_ID = -1;
34:         private static final Object NOT_AVAILABLE = new Object();
35:
36:         private CallSequence traceVars;
37:
38:         public TraceNode()
39:         {
40:                 this.traceVars = new CallSequence();
41:         }
42:
43:         public void addVarFirst(TraceVariable var)
44:         {
45:                 this.traceVars.add(0, var);
46:         }
47:
48:         public CallSequence getVars()
49:         {
50:                 CallSequence c = new CallSequence();
51:                 c.addAll(traceVars);
52:                 return c;
53:         }
54:
55:         @Override
56:         abstract public String toString();
57:
58:         abstract public TestSequence getTests();
59:
60:         // SL
61:         public static void executeTests(TraceNode trace, TestAccumulator acc,
62:                         Store store)
63:         {
64:                 executeTests(trace, null, acc, store);
65:         }
66:
67:         // PP
68:         public static void executeTests(TraceNode trace, Class<?> instanceType,
69:                         TestAccumulator acc, Store store)
70:         {
71:                 try
72:                 {
73:•                        if (instanceType != null)
74:                         {
75:                                 store.register(ENCLOSING_MODULE_ID, instanceType.newInstance());
76:                         }
77:
78:                         int testNo = 1;
79:
80:                         TestSequence tests = trace.getTests();
81:
82:                         tests.size();
83:
84:•                        for (CallSequence test : tests)
85:                         {
86:                                 /**
87:                                  * We should reset the state before running the test in case the trace variable statements have modified
88:                                  * it, e.g. let a = opWithSideEffects() in ....
89:                                  */
90:                                 store.reset();
91:                                 List<String> callStms = new LinkedList<String>();
92:                                 List<Object> callStmResults = new LinkedList<Object>();
93:
94:                                 /*
95:                                  * TODO: Type check missing here If the type check fails we would also have to do filtering
96:                                  */
97:•                                if (test.getFilter() > 0)
98:                                 {
99:                                         acc.registerTest(new TraceTest(testNo, test.toString(), "", Verdict.SKIPPED));
100:                                 } else
101:                                 {
102:                                         int callStmIdx = 0;
103:•                                        for (; callStmIdx < test.size(); callStmIdx++)
104:                                         {
105:                                                 Statement stm = test.get(callStmIdx);
106:
107:•                                                if (!(stm instanceof CallStatement))
108:                                                 {
109:                                                         continue;
110:                                                 }
111:
112:                                                 CallStatement callStm = (CallStatement) stm;
113:                                                 try
114:                                                 {
115:                                                         callStms.add(callStm.toString());
116:
117:•                                                        if (callStm instanceof CallStatementPp)
118:                                                         {
119:                                                                 ((CallStatementPp) callStm).setInstance(store.getValue(ENCLOSING_MODULE_ID));
120:                                                         }
121:
122:                                                         // TODO: To be done. Consider where the right place is to check for this.
123:•                                                        if (!callStm.isTypeCorrect()
124:•                                                                        || !callStm.meetsPreCond())
125:                                                         {
126:                                                                 // Inconclusive
127:                                                                 callStmResults.add(NOT_AVAILABLE);
128:                                                                 callStmResults.add(Verdict.INCONCLUSIVE);
129:                                                                 tests.filter(callStmResults, test, testNo);
130:                                                                 acc.registerTest(new TraceTest(testNo, test.toString(), "", Verdict.INCONCLUSIVE));
131:                                                                 break;
132:                                                         }
133:
134:                                                         Object result = callStm.execute();
135:                                                         callStmResults.add(result);
136:
137:•                                                        if (callStmIdx == test.size() - 1)
138:                                                         {
139:                                                                 callStmResults.add(Verdict.PASSED);
140:                                                                 acc.registerTest(new TraceTest(testNo, getResultStr(callStms, "; "), getResultStr(callStmResults.subList(0, callStmResults.size()
141:                                                                                 - 1), " ; "), Verdict.PASSED));
142:                                                         }
143:
144:                                                 } catch (RuntimeException | AssertionError e)
145:                                                 {
146:•                                                        for (int p = callStmIdx + 1; p < test.size(); p++)
147:                                                         {
148:                                                                 callStms.add(callStms.toString());
149:                                                         }
150:
151:•                                                        for (; callStmIdx < test.size(); callStmIdx++)
152:                                                         {
153:•                                                                if (e.getMessage() != null)
154:                                                                 {
155:                                                                         callStmResults.add(e.getClass().getSimpleName()
156:                                                                                         + ": " + e.getMessage());
157:                                                                 } else
158:                                                                 {
159:                                                                         // Happens for null pointer exceptions
160:                                                                         callStmResults.add(e.getClass().getSimpleName());
161:                                                                 }
162:                                                         }
163:
164:                                                         Verdict verdict = Verdict.FAILED;
165:
166:                                                         callStmResults.add(verdict);
167:
168:                                                         tests.filter(callStmResults, test, testNo);
169:                                                         acc.registerTest(new TraceTest(testNo, getResultStr(callStms, "; "), getResultStr(callStmResults.subList(0, callStmResults.size()
170:                                                                         - 1), " ; "), verdict));
171:                                                 }
172:
173:                                         }
174:                                 }
175:
176:                                 callStms.clear();
177:                                 callStmResults.clear();
178:
179:                                 testNo++;
180:                         }
181:
182:                 } catch (InstantiationException e)
183:                 {
184:                         e.printStackTrace();
185:                 } catch (IllegalAccessException e)
186:                 {
187:                         e.printStackTrace();
188:                 }
189:         }
190:
191:         private static String getResultStr(List<? extends Object> results,
192:                         String sep)
193:         {
194:                 StringBuilder sb = new StringBuilder();
195:
196:•                if (!results.isEmpty())
197:                 {
198:                         sb.append(toStr(results.get(0)));
199:                 }
200:
201:•                for (int i = 1; i < results.size(); i++)
202:                 {
203:                         sb.append(sep + toStr(results.get(i)));
204:                 }
205:
206:                 return sb.toString();
207:         }
208:
209:         public static void showResults(List<TraceTest> results)
210:         {
211:•                for (TraceTest testResult : results)
212:                 {
213:                         System.out.println(testResult.toString());
214:                 }
215:         }
216:
217:         private static String toStr(Object obj)
218:         {
219:•                if (obj instanceof String)
220:                 {
221:                         return obj.toString();
222:                 } else
223:                 {
224:                         return Utils.toString(obj);
225:                 }
226:         }
227: }