Package: VdmjTracesHelper

VdmjTracesHelper

nameinstructionbranchcomplexitylinemethod
VdmjTracesHelper(Shell, IVdmProject)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
consolePrint(String)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
copySourceFilesForCoverage(File)
M: 31 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
evaluateTraces(INode, ANamedTraceDefinition, IProgressMonitor, ITracesDisplay)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
evaluateTraces(INode, ANamedTraceDefinition, float, TraceReductionType, long, IProgressMonitor, ITracesDisplay)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
evaluateTraces(INode, ANamedTraceDefinition, float, TraceReductionType, long, IProgressMonitor, ITracesDisplay, boolean)
M: 140 C: 0
0%
M: 12 C: 0
0%
M: 7 C: 0
0%
M: 20 C: 0
0%
M: 1 C: 0
0%
execute(IProgressMonitor, ITracesDisplay, List)
M: 47 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
findConsole(String)
M: 44 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
getCTRunCoverageDir()
M: 34 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
getContent(IVdmSourceUnit)
M: 26 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
writeFile(File, String, String)
M: 20 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * Combinatorial Testing
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.plugins.combinatorialtesting.internal;
23:
24: import java.io.BufferedWriter;
25: import java.io.File;
26: import java.io.FileWriter;
27: import java.io.IOException;
28: import java.io.InputStreamReader;
29: import java.text.DateFormat;
30: import java.text.SimpleDateFormat;
31: import java.util.Date;
32: import java.util.HashMap;
33: import java.util.List;
34: import java.util.Map;
35: import java.util.Vector;
36:
37: import org.eclipse.core.resources.IProject;
38: import org.eclipse.core.resources.IResource;
39: import org.eclipse.core.runtime.CoreException;
40: import org.eclipse.core.runtime.IProgressMonitor;
41: import org.eclipse.swt.widgets.Shell;
42: import org.eclipse.ui.console.ConsolePlugin;
43: import org.eclipse.ui.console.IConsole;
44: import org.eclipse.ui.console.IConsoleManager;
45: import org.eclipse.ui.console.MessageConsole;
46: import org.eclipse.ui.console.MessageConsoleStream;
47: import org.overture.ast.definitions.ANamedTraceDefinition;
48: import org.overture.ast.node.INode;
49: import org.overture.ide.core.resources.IVdmProject;
50: import org.overture.ide.core.resources.IVdmSourceUnit;
51: import org.overture.ide.plugins.combinatorialtesting.TracesXmlStoreReader;
52: import org.overture.ide.plugins.combinatorialtesting.views.TraceAstUtility;
53: import org.overture.interpreter.traces.TraceReductionType;
54:
55: public class VdmjTracesHelper
56: {
57:         final String COVERAGE_DIR_NAME = "generated/coverage";
58:         public final IVdmProject project;
59:         Map<String, TracesXmlStoreReader> classTraceReaders = new HashMap<String, TracesXmlStoreReader>();
60:         Shell shell;
61:
62:         public VdmjTracesHelper(Shell shell, IVdmProject vdmProject)
63:                         throws Exception
64:         {
65:                 this.project = vdmProject;
66:                 this.shell = shell;
67:         }
68:
69:         public File getCTRunCoverageDir()
70:         {
71:                 DateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
72:                 File coverageDir = new File(project.getModelBuildPath().getOutput().getLocation().toFile(), "CT_"
73:                                 + dateFormat.format(new Date()));
74:
75:•                if (!coverageDir.exists())
76:                 {
77:                         coverageDir.mkdirs();
78:                 }
79:
80:                 return coverageDir;
81:         }
82:
83:         private void copySourceFilesForCoverage(File coverageDir)
84:                         throws IOException, CoreException
85:         {
86:•                for (IVdmSourceUnit source : this.project.getSpecFiles())
87:                 {
88:                         String name = source.getSystemFile().getName();
89:
90:                         writeFile(coverageDir, name + "cov", getContent(source));
91:                 }
92:         }
93:
94:         private String getContent(IVdmSourceUnit source) throws CoreException,
95:                         IOException
96:         {
97:                 InputStreamReader reader = new InputStreamReader(source.getFile().getContents());
98:                 StringBuilder sb = new StringBuilder();
99:
100:                 int inLine;
101:•                while ((inLine = reader.read()) != -1)
102:                 {
103:                         sb.append((char) inLine);
104:                 }
105:                 return sb.toString();
106:         }
107:
108:         public static void writeFile(File outputFolder, String fileName,
109:                         String content) throws IOException
110:         {
111:                 FileWriter outputFileReader = new FileWriter(new File(outputFolder, fileName));
112:                 BufferedWriter outputStream = new BufferedWriter(outputFileReader);
113:                 outputStream.write(content);
114:                 outputStream.close();
115:         }
116:
117:         public void consolePrint(String message)
118:         {
119:
120:                 MessageConsole myConsole = findConsole("Combinatorial Testing");
121:                 MessageConsoleStream out = myConsole.newMessageStream();
122:                 out.println(message);
123:
124:         }
125:
126:         public static MessageConsole findConsole(String name)
127:         {
128:                 ConsolePlugin plugin = ConsolePlugin.getDefault();
129:                 IConsoleManager conMan = plugin.getConsoleManager();
130:                 IConsole[] existing = conMan.getConsoles();
131:•                for (int i = 0; i < existing.length; i++)
132:                 {
133:•                        if (name.equals(existing[i].getName()))
134:                         {
135:                                 return (MessageConsole) existing[i];
136:                         }
137:                 }
138:                 // no console found, so create a new one
139:                 MessageConsole myConsole = new MessageConsole(name, null);
140:                 conMan.addConsoles(new IConsole[] { myConsole });
141:                 return myConsole;
142:         }
143:
144:         public void evaluateTraces(INode container, ANamedTraceDefinition traceDef,
145:                         IProgressMonitor monitor, ITracesDisplay display)
146:                         throws IOException, CoreException
147:         {
148:                 evaluateTraces(container, traceDef, 0, null, 0, monitor, display, false);
149:         }
150:
151:         public void evaluateTraces(INode container, ANamedTraceDefinition traceDef,
152:                         float subset, TraceReductionType traceReductionType, long seed,
153:                         IProgressMonitor monitor, ITracesDisplay display)
154:                         throws IOException, CoreException
155:         {
156:                 evaluateTraces(container, traceDef, subset, traceReductionType, seed, monitor, display, true);
157:         }
158:
159:         private void evaluateTraces(INode container,
160:                         ANamedTraceDefinition traceDef, float subset,
161:                         TraceReductionType traceReductionType, long seed,
162:                         IProgressMonitor monitor, ITracesDisplay display,
163:                         boolean useReduction) throws IOException, CoreException
164:         {
165:                 List<TraceExecutionSetup> traceSetups = new Vector<TraceExecutionSetup>();
166:
167:•                if (container != null)
168:                 {
169:•                        if (traceDef != null)
170:                         {
171:                                 TraceExecutionSetup texe = new TraceExecutionSetup(project, TraceAstUtility.getContainerName(container), traceDef.getName().getName(), getCTRunCoverageDir(), subset, traceReductionType, seed, useReduction);
172:                                 traceSetups.add(texe);
173:                         } else
174:                         {
175:•                                for (ANamedTraceDefinition tDef : TraceAstUtility.getTraceDefinitions(container))
176:                                 {
177:                                         TraceExecutionSetup texe = new TraceExecutionSetup(project, TraceAstUtility.getContainerName(container), tDef.getName().getName(), getCTRunCoverageDir(), subset, traceReductionType, seed, useReduction);
178:                                         traceSetups.add(texe);
179:                                 }
180:                         }
181:                 } else
182:                 {
183:•                        for (INode c : TraceAstUtility.getTraceContainers(project))
184:                         {
185:•                                if (traceDef != null)
186:                                 {
187:                                         TraceExecutionSetup texe = new TraceExecutionSetup(project, TraceAstUtility.getContainerName(c), traceDef.getName().getName(), getCTRunCoverageDir(), subset, traceReductionType, seed, useReduction);
188:                                         traceSetups.add(texe);
189:                                 } else
190:                                 {
191:•                                        for (ANamedTraceDefinition tDef : TraceAstUtility.getTraceDefinitions(c))
192:                                         {
193:                                                 TraceExecutionSetup texe = new TraceExecutionSetup(project, TraceAstUtility.getContainerName(c), tDef.getName().getName(), getCTRunCoverageDir(), subset, traceReductionType, seed, useReduction);
194:                                                 traceSetups.add(texe);
195:                                         }
196:                                 }
197:                         }
198:                 }
199:
200:                 execute(monitor, display, traceSetups);
201:         }
202:
203:         private void execute(IProgressMonitor monitor, ITracesDisplay display,
204:                         List<TraceExecutionSetup> texe) throws IOException, CoreException
205:         {
206:                 IProject p = (IProject) project.getAdapter(IProject.class);
207:
208:                 MessageConsole myConsole = findConsole("TracesConsole");
209:                 MessageConsoleStream out = myConsole.newMessageStream();
210:                 out.setEncoding(p.getDefaultCharset());
211:                 myConsole.activate();
212:
213:•                for (TraceExecutionSetup traceExecutionSetup : texe)
214:                 {
215:                         new TraceTestEngine().launch(traceExecutionSetup, out, display);
216:                         copySourceFilesForCoverage(traceExecutionSetup.coverageFolder);
217:                 }
218:
219:                 try
220:                 {
221:                         p.refreshLocal(IResource.DEPTH_INFINITE, null);
222:                 } catch (CoreException e)
223:                 {
224:
225:                 }
226:         }
227:
228: }