blob: d4f9197e3992c249e5342fbcd7d464105dd5b515 [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5package tai_ofa;
6
7/**
8 *
9 * @author Raghavkashyap (raghavkashyap@paxterra.com)
10
11
12 * TestON is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 2 of the License, or
15 * (at your option) any later version.
16
17 * TestON is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21
22 * You should have received a copy of the GNU General Public License
23 * along with TestON. If not, see <http://www.gnu.org/licenses/>.
24
25 */
26// Import the Java classes
27import com.sun.javafx.scene.layout.region.BackgroundFill;
28import com.sun.org.apache.bcel.internal.generic.LoadInstruction;
29import java.awt.TextArea;
30import java.util.*;
31import java.util.regex.Matcher;
32import java.util.regex.Pattern;
33import java.io.*;
34import java.net.MalformedURLException;
35import java.nio.file.WatchService;
36import java.text.SimpleDateFormat;
37import java.util.logging.Level;
38import java.util.logging.Logger;
39import javafx.application.Platform;
40import javafx.beans.value.ChangeListener;
41import javafx.beans.value.ObservableValue;
42import javafx.collections.FXCollections;
43import javafx.collections.ObservableList;
44import javafx.event.EventHandler;
45import javafx.geometry.Insets;
46import javafx.scene.chart.PieChart;
47import javafx.scene.control.Button;
48import javafx.scene.control.CheckBox;
49import javafx.scene.control.Label;
50import javafx.scene.control.Tab;
51import javafx.scene.control.TabPane;
52import javafx.scene.control.TableView;
53import javafx.scene.control.TextAreaBuilder;
54import javafx.scene.effect.BlendMode;
55import javafx.scene.image.Image;
56import javafx.scene.image.ImageView;
57import javafx.scene.input.ScrollEvent;
58import javafx.scene.layout.HBox;
59import javafx.scene.layout.StackPane;
60import javafx.scene.paint.Color;
61import javafx.scene.paint.Paint;
62import javafx.stage.Popup;
63import javafx.stage.Stage;
64import org.apache.xmlrpc.XmlRpcClient;
65import org.apache.xmlrpc.XmlRpcException;
66
67public class ExecuteTest {
68
69 Pattern stepPatt, casePatt, resultPatt, namePatt, summaryPatt, testStartPatt, testEndPatt, testExecutionTimePatt, testsPlannedPatt,
70 testsRunPatt, totalPassPatt, totalFailPatt, noResultPatt, totalAbortPatt, execPercentagePatt, successPercentagePatt, assertionPatt, totalreRun;
71 TableView summaryTable, finalSummaryTable, stepTable;
72 public static int noOfPassed = 0, noOfFailed = 0, noOfAborted = 0, noOfNoResult = 0, failed = 0, passed = 0, noResults = 0, aboarted = 0;
73 String summary, testStart, testEnd, testExecutionTime, testsPlanned, testsRun, totalPass,
74 totalFail, noResult, totalAbort, execPercentage, successPercentage;
75 ObservableList<SummaryTable> data;
76 ObservableList<FinalSummaryTable> finalSummaryData;
77 ObservableList<StepTable> stepSummaryData;
78 //AutoMateTestSummary summaryWindow ;
79 StackPane summaryTableRoot;
80 TreeMap<String, String> stepHash = new TreeMap<String, String>();
81 TreeMap<String, String> caseNameHash = new TreeMap<String, String>();
82 Matcher m;
83 int tableIndex = -1;
84 int stepTableIndex = -1;
85 Runnable r3;
86 Button viewLogsButton;
87 PieChart summaryChart;
88 PieChart.Data passData, failData, abortData, noResultData;
89 String selectedTest;
90 ObservableList<PieChart.Data> pieChartData;
91 javafx.scene.control.TextArea compononetLogText = TextAreaBuilder.create().build();
92 javafx.scene.control.TextArea flowVisorSessionText = TextAreaBuilder.create().build();
93 javafx.scene.control.TextArea poxSessionText = TextAreaBuilder.create().build();
94 javafx.scene.control.TextArea mininetSessionText = TextAreaBuilder.create().build();
95 Label statusImage;
96 TAILocale label = new TAILocale(Locale.ENGLISH);
97
98 public ExecuteTest(TableView summary, ObservableList<SummaryTable> dataInstance,
99 PieChart chart, TableView finalSummary, ObservableList<FinalSummaryTable> finalSummaryDataInstance,
100 Button viewLogs, ObservableList<PieChart.Data> pieChartData,
101 PieChart.Data passData, PieChart.Data failData, PieChart.Data abortData, PieChart.Data noResultData, String testName, javafx.scene.control.TextArea componentLogText,
102 TableView stepTable, ObservableList<StepTable> stepTableData, javafx.scene.control.TextArea poxText, javafx.scene.control.TextArea mininetText, javafx.scene.control.TextArea flowText) {
103 this.summaryTable = summary;
104 data = dataInstance;
105 summaryChart = chart;
106 finalSummaryTable = finalSummary;
107 finalSummaryData = finalSummaryDataInstance;
108 viewLogsButton = viewLogs;
109 this.pieChartData = pieChartData;
110 this.passData = passData;
111 this.failData = failData;
112 this.abortData = abortData;
113 this.noResultData = noResultData;
114 this.selectedTest = testName;
115 this.compononetLogText = componentLogText;
116 this.stepTable = stepTable;
117 this.stepSummaryData = stepTableData;
118 this.poxSessionText = poxText;
119 this.mininetSessionText = mininetText;
120 this.flowVisorSessionText = flowText;
121
122 }
123 String currentTestCase, testCaseName, testCaseStatus, testCaseStartTime, testCaseEndTime;
124
125 public void runTest() {
126
127
128
129 try {
130
131 summaryTable.setVisible(true);
132 getCaseName();
133 Iterator entries = caseNameHash.entrySet().iterator();
134 data = FXCollections.observableArrayList();
135 int index = 0;
136 while (entries.hasNext()) {
137 index++;
138 Map.Entry entry = (Map.Entry) entries.next();
139 String key = (String) entry.getKey();
140 String value = (String) entry.getValue();
141 Image image = new Image(getClass().getResourceAsStream("/images/loading.gif"), 10, 10, true, true);
142 data.add(new SummaryTable(new Label(key), new Label(value), new Label("", new ImageView(image)), new Label(), new Label()));
143 }
144 summaryTable.setItems(data);
145 File file = new File(selectedTest);
146 String[] runThisFile = file.getName().split("\\.");
147 try {
148 XmlRpcClient server = new XmlRpcClient("http://localhost:9000");
149 Vector params = new Vector();
150 params.add(new String(selectedTest));
151 final Object result = server.execute("runTest", params);
152 new Thread(new Runnable() {
153 @Override
154 public void run() {
155 ProcessBuilder header = new ProcessBuilder("/bin/sh", "-c", "head -20 " + result.toString());
156 Process headProcess;
157 try {
158 headProcess = header.start();
159 BufferedReader inputHeader = new BufferedReader(new InputStreamReader(headProcess.getInputStream()));
160 String lines;
161 String totalText = "";
162 while ((lines = inputHeader.readLine()) != null) {
163 try {
164 totalText = totalText + "\n" + lines;
165 updateData(lines);
166 } catch (Exception e) {
167 }
168 }
169 compononetLogText.appendText(totalText);
170 headProcess.destroy();
171 } catch (IOException ex) {
172 Logger.getLogger(ExecuteTest.class.getName()).log(Level.SEVERE, null, ex);
173 }
174 String command = "tail -f " + result.toString();
175 File dir = new File(result.toString());
176 String parentPath = dir.getParent();
177 ProcessBuilder tail = new ProcessBuilder("/bin/sh", "-c", "tail -f " + result.toString());
178 Process process;
179 int nullcount = 0;
180 try {
181 while (true) {
182 process = tail.start();
183 BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
184 String line;
185 try {
186 while ((line = input.readLine()) != null) {
187 compononetLogText.appendText("\n" + line + "\n");
188 updateData(line);
189 }
190 if (input.readLine() == null) {
191 nullcount++;
192 }
193 if (nullcount == 2) {
194 process.destroy();
195 }
196
197 } catch (Exception e) {
198 }
199 }
200 } catch (IOException ex) {
201 Logger.getLogger(ExecuteTest.class.getName()).log(Level.SEVERE, null, ex);
202 }
203 String poxFileName = parentPath + "/" + "POX2.session";
204 String flowFileName = parentPath + "/" + "FlowVisor1.session";
205 String mininetFileName = parentPath + "/" + "Mininet1.session";
206 ProcessBuilder tailpox = new ProcessBuilder("/bin/sh", "-c", "tail -f " + poxFileName);
207 }
208 }).start();
209
210 r3 = new Runnable() {
211 public void run() {
212 try {
213 summaryChart.setVisible(true);
214 try {
215 pieChartData.set(0, new PieChart.Data("Pass", ExecuteTest.noOfPassed));
216 pieChartData.set(1, new PieChart.Data("Fail", ExecuteTest.noOfFailed));
217 pieChartData.set(2, new PieChart.Data("Abort", ExecuteTest.noOfAborted));
218 passData.setPieValue(1);
219 failData.setPieValue(0);
220 abortData.setPieValue(0);
221 noResultData.setPieValue(0);
222 summaryChart.getStylesheets().add(getClass().getResource("test.css").toExternalForm());
223 summaryChart.setData(pieChartData);
224 } catch (Exception e) {
225 e.printStackTrace();
226 }
227 } catch (Exception e) {
228 e.printStackTrace();
229 }
230 }
231 };
232 } catch (Exception e) {
233 e.printStackTrace();
234 }
235 } catch (Exception e) {
236 e.printStackTrace();
237 }
238 }
239
240 public void updateData(String line) {
241
242 casePatt = Pattern.compile("\\s*Result\\s+summary\\s+for\\s+Testcase(\\d+)");
243 m = casePatt.matcher(line);
244 if (m.find()) {
245 Date dNow = new Date();
246 SimpleDateFormat ft = new SimpleDateFormat("hh:mm:ss a zzz dd.MM.yyyy");
247 testCaseStartTime = ft.format(dNow);
248 currentTestCase = m.group(1);
249 stepHash.clear();
250 getTestSteps(m.group(1));
251 Image image = new Image(getClass().getResourceAsStream("/images/loading.gif"), 10, 10, true, true);
252 Label statusImage = new Label("", new ImageView(image));
253 stepSummaryData = FXCollections.observableArrayList(new StepTable(new Label(""), new Label(""), new Label("")));
254 Iterator entries = stepHash.entrySet().iterator();
255 while (entries.hasNext()) {
256 Map.Entry entry = (Map.Entry) entries.next();
257 String key = (String) entry.getKey();
258 String value = (String) entry.getValue();
259 stepSummaryData.add(new StepTable(new Label(key), new Label(value), new Label("", new ImageView(image))));
260 }
261 stepTable.setItems(stepSummaryData);
262 }
263
264 namePatt = Pattern.compile("\\[(.*)\\]\\s*\\[(.*)\\]\\s*\\[\\s*CASE\\s*\\](.*)\\s*");
265 m = namePatt.matcher(line);
266
267 if (m.find()) {
268 testCaseName = m.group(3);
269 Image image = new Image(getClass().getResourceAsStream("/images/progress.png"));
270 statusImage = new Label("", new ImageView(image));
271 if (tableIndex < 0) {
272 data = FXCollections.observableArrayList(new SummaryTable(new Label(currentTestCase), new Label(testCaseName),
273 statusImage, new Label(testCaseStartTime), new Label()));
274 } else {
275 data.add(new SummaryTable(new Label(currentTestCase), new Label(testCaseName), statusImage,
276 new Label(testCaseStartTime), new Label("")));
277 }
278 tableIndex++;
279 }
280
281 stepPatt = Pattern.compile("\\[(.*)\\]\\s*\\[(.*)\\]\\s*\\[\\s*STEP\\s*\\]\\s*(\\d+)\\.(\\d+):(.*)\\s*");
282
283 m = stepPatt.matcher(line);
284 if (m.find()) {
285 String currentStepNumber = m.group(3) + "." + m.group(4);
286 for (int i = 1; i < stepSummaryData.size(); i++) {
287 if (stepSummaryData.get(i).getTestStepId().getText().equals(currentStepNumber)) {
288 Image image = new Image(getClass().getResourceAsStream("/images/progress.png"));
289 stepTableIndex = i;
290 stepSummaryData.set(i, new StepTable(new Label(stepSummaryData.get(i).getTestStepId().getText()), new Label(stepSummaryData.get(i).getTestStepName().getText()), new Label("", new ImageView(image))));
291 Image images = new Image(getClass().getResourceAsStream("/images/Pass_Icon.png"));
292 }
293 }
294
295 }
296
297 assertionPatt = Pattern.compile("\\s*(.*)\\s*-\\s*(\\w+)\\s*-\\s*(\\w+)\\s*-\\s*(.*)\\s*");
298 m = assertionPatt.matcher(line);
299 if (m.find() && stepTableIndex > -1) {
300 if (m.group(3).equals("INFO") && m.group(4).equals("Assertion Passed")) {
301 Image image = new Image(getClass().getResourceAsStream("/images/Pass_Icon.png"));
302 stepSummaryData.set(stepTableIndex, new StepTable(new Label(stepSummaryData.get(stepTableIndex).getTestStepId().getText()),
303 new Label(stepSummaryData.get(stepTableIndex).getTestStepName().getText()), new Label("", new ImageView(image))));
304 } else if (m.group(3).equals("WARNING") && m.group(4).equals("Assertion Failed")) {
305 Image image = new Image(getClass().getResourceAsStream("/images/Fail_Icon.png"));
306 stepSummaryData.set(stepTableIndex, new StepTable(new Label(stepSummaryData.get(stepTableIndex).getTestStepId().getText()),
307 new Label(stepSummaryData.get(stepTableIndex).getTestStepName().getText()), new Label("", new ImageView(image))));
308 XmlRpcClient server;
309 }
310
311 }
312
313 resultPatt = Pattern.compile("\\s*Result:\\s+(\\w+)\\s*");
314 m = resultPatt.matcher(line);
315 if (m.find()) {
316 testCaseStatus = m.group(1);
317 Date dNow = new Date();
318 Image image;
319 SimpleDateFormat ft = new SimpleDateFormat("hh:mm:ss a zzz dd.MM.yyyy");
320 testCaseEndTime = ft.format(dNow);
321 if (testCaseStatus.equalsIgnoreCase("No result")) {
322 image = new Image(getClass().getResourceAsStream("/images/noResult.png"));
323 statusImage = new Label("", new ImageView(image));;
324 ExecuteTest.noOfNoResult++;
325 }
326
327 if (testCaseStatus.equalsIgnoreCase("Pass")) {
328 image = new Image(getClass().getResourceAsStream("/images/Pass_Icon.png"));
329 statusImage = new Label("", new ImageView(image));
330 ExecuteTest.noOfPassed++;
331 }
332 if (testCaseStatus.equals("Failed")) {
333 image = new Image(getClass().getResourceAsStream("/images/Fail_Icon.png"));
334 statusImage = new Label("", new ImageView(image));
335 ExecuteTest.noOfFailed++;
336 } else if (testCaseStatus.equals("Aborted")) {
337 image = new Image(getClass().getResourceAsStream("/images/Abort_Icon.png"));
338 statusImage = new Label("", new ImageView(image));
339 this.noOfAborted++;
340 }
341 data.set(tableIndex, new SummaryTable(new Label(currentTestCase), new Label(testCaseName),
342 statusImage, new Label(testCaseStartTime), new Label(testCaseEndTime)));
343 summaryTable.setItems(data);
344 }
345
346 summaryPatt = Pattern.compile("\\s*Test+\\s+Execution(.*)");
347 m = summaryPatt.matcher(line);
348 if (m.find()) {
349 }
350
351 testStartPatt = Pattern.compile("Test\\s+Start\\s+\\:\\s+(.*)");
352 m = testStartPatt.matcher(line);
353 if (m.find()) {
354 Image image = new Image(getClass().getResourceAsStream("/images/Pass_Icon.png"));
355 statusImage = new Label("", new ImageView(image));
356 data.set(tableIndex, new SummaryTable(new Label(currentTestCase), new Label(testCaseName),
357 statusImage, new Label(testCaseStartTime), new Label(testCaseEndTime)));
358 stepTable.setVisible(false);
359 finalSummaryTable.setVisible(true);
360 summaryChart.setVisible(true);
361 finalSummaryData = FXCollections.observableArrayList(new FinalSummaryTable(new Label(""), new Label("")));
362 finalSummaryTable.setItems(finalSummaryData);
363 testStart = m.group(1);
364 finalSummaryData.set(0, new FinalSummaryTable(new Label("Test Start"), new Label(testStart)));
365 finalSummaryTable.setItems(finalSummaryData);
366 }
367 testEndPatt = Pattern.compile("Test\\s+End\\s+\\:\\s+(.*)");
368 m = testEndPatt.matcher(line);
369 if (m.find()) {
370 testEnd = m.group(1);
371 finalSummaryData.add(new FinalSummaryTable(new Label("Test End"), new Label(testEnd)));
372 finalSummaryTable.setItems(finalSummaryData);
373 }
374 testExecutionTimePatt = Pattern.compile("\\s*Execution\\s+Time\\s+\\:\\s+(.*)");
375 m = testExecutionTimePatt.matcher(line);
376 if (m.find()) {
377 testExecutionTime = m.group(1);
378 finalSummaryData.add(new FinalSummaryTable(new Label("Execution Time"), new Label(testExecutionTime)));
379 finalSummaryTable.setItems(finalSummaryData);
380 }
381 testsPlannedPatt = Pattern.compile("\\s*Total\\s+tests\\s+planned\\s+\\:\\s*(.*)");
382 m = testsPlannedPatt.matcher(line);
383 if (m.find()) {
384 testsPlanned = m.group(1);
385 finalSummaryData.add(new FinalSummaryTable(new Label("Total Tests Planned"), new Label(testsPlanned)));
386 finalSummaryTable.setItems(finalSummaryData);
387 }
388
389 testsRunPatt = Pattern.compile("\\s*Total\\s+tests\\s+Run\\s+\\:\\s+(.*)");
390 m = testsRunPatt.matcher(line);
391 if (m.find()) {
392 testsRun = m.group(1);
393 finalSummaryData.add(new FinalSummaryTable(new Label("Total Tests Run"), new Label(testsRun)));
394 finalSummaryTable.setItems(finalSummaryData);
395 }
396 totalPassPatt = Pattern.compile("Total\\s+Pass\\s+\\:\\s+(.*)");
397 m = totalPassPatt.matcher(line);
398 if (m.find()) {
399 totalPass = m.group(1);
400 Label totalPassL = new Label("Total Pass");
401 totalPassL.setTextFill(Color.GREEN);
402 totalPassL.setStyle("-fx-font-weight: bold");
403 Label totalPassValue = new Label(totalPass);
404 totalPassValue.setTextFill(Color.GREEN);
405 totalPassValue.setStyle("-fx-font-weight: bold");
406 finalSummaryData.add(new FinalSummaryTable(totalPassL, totalPassValue));
407 finalSummaryTable.setItems(finalSummaryData);
408 }
409 totalFailPatt = Pattern.compile("Total\\s+Fail\\s+\\:\\s+(.*)");
410 m = totalFailPatt.matcher(line);
411 if (m.find()) {
412 totalFail = m.group(1);
413 Label totalFailL = new Label("Total Fail");
414 totalFailL.setTextFill(Color.RED);
415 totalFailL.setStyle("-fx-font-weight: bold");
416 Label totalFailValue = new Label(totalFail);
417 totalFailValue.setTextFill(Color.RED);
418 totalFailValue.setStyle("-fx-font-weight: bold");
419 finalSummaryData.add(new FinalSummaryTable(totalFailL, totalFailValue));
420 finalSummaryTable.setItems(finalSummaryData);
421 }
422
423 totalreRun = Pattern.compile("Total\\s+Re\\-Run\\s+\\:\\s+(.*)");
424 m = totalreRun.matcher(line);
425 if (m.find()) {
426 Label totalReRun = new Label("Total Re-Run");
427 totalReRun.setTextFill(Color.BLUE);
428 totalReRun.setStyle("-fx-font-weight: bold");
429 Label totalReRunValue = new Label(m.group(1));
430 totalReRunValue.setTextFill(Color.BLUE);
431 totalReRunValue.setStyle("-fx-font-weight: bold");
432 finalSummaryData.add(new FinalSummaryTable(totalReRun, totalReRunValue));
433 finalSummaryTable.setItems(finalSummaryData);
434 }
435
436 noResultPatt = Pattern.compile("Total\\s+No\\s+Result\\s+\\:\\s+(.*)");
437 m = noResultPatt.matcher(line);
438 if (m.find()) {
439 noResult = m.group(1);
440 finalSummaryData.add(new FinalSummaryTable(new Label("Total No-Result"), new Label(noResult)));
441 finalSummaryTable.setItems(finalSummaryData);
442 }
443
444 totalAbortPatt = Pattern.compile("Total\\sabort\\s+\\:\\s+(.*)");
445 m = totalAbortPatt.matcher(line);
446 if (m.find()) {
447 totalAbort = m.group(1);
448 finalSummaryData.add(new FinalSummaryTable(new Label("Total Abort"), new Label(totalAbort)));
449 finalSummaryTable.setItems(finalSummaryData);
450 }
451 execPercentagePatt = Pattern.compile("Execution\\s+Result\\s+\\:\\s+(.*)");
452 m = execPercentagePatt.matcher(line);
453 if (m.find()) {
454 execPercentage = m.group(1);
455 finalSummaryData.add(new FinalSummaryTable(new Label("Execution Percentage"), new Label(execPercentage)));
456 finalSummaryTable.setItems(finalSummaryData);
457 Platform.runLater(r3);
458 }
459 successPercentagePatt = Pattern.compile("Success\\s+Percentage\\s+\\:\\s+(.*)");
460 m = successPercentagePatt.matcher(line);
461 if (m.find()) {
462 successPercentage = m.group(1);
463 finalSummaryData.add(new FinalSummaryTable(new Label("Success Percentage"), new Label(successPercentage)));
464 finalSummaryTable.setItems(finalSummaryData);
465 }
466 }
467
468 public ExecuteTest() {
469 }
470
471 public String getTestCase() {
472 return currentTestCase;
473 }
474
475 public void getTestSteps(String caseNumber) {
476 OFAFileOperations fileOperation = new OFAFileOperations();
477 int stepCount = 0;
478 String stepCounter = "";
479 String ospkFileName = label.hierarchyTestON + "/tests/" + selectedTest + "/" + selectedTest + ".ospk";
480 String pythonScriptName = label.hierarchyTestON + "/tests/" + selectedTest + "/" + selectedTest + ".py";
481 BufferedReader input = null;
482 ArrayList<String> contents = new ArrayList<String>();
483 File scriptName = new File(ospkFileName);
484 if (scriptName.exists()) {
485 try {
486 //use buffering, reading one line at a time
487 //FileReader always assumes default encoding is OK!
488 try {
489 input = new BufferedReader(new FileReader(scriptName));
490 } catch (Exception e) {
491 }
492
493 try {
494 String line = null; //not declared within while loop
495 while ((line = input.readLine()) != null) {
496 contents.add(line);
497 }
498 } finally {
499 try {
500 input.close();
501 } catch (Exception e) {
502 }
503 }
504 } catch (IOException ex) {
505 ex.printStackTrace();
506 }
507 for (int i = 0; i < contents.size(); i++) {
508 Pattern casePattern = Pattern.compile("\\s*CASE\\s*(\\d+)\\s*");
509 Matcher caseMatcher = casePattern.matcher(contents.get(i));
510 if (caseMatcher.find()) {
511 if (caseMatcher.group(1).equals(caseNumber)) {
512 i++;
513 Pattern casePatterns = Pattern.compile("\\s*CASE\\s*(\\d+)\\s*");
514 Matcher caseMatchers = casePatterns.matcher(contents.get(i));
515 while (!caseMatchers.find() && i < contents.size()) {
516 Pattern casesPatterns = Pattern.compile("\\s*CASE\\s*(\\d+)\\s*");
517 Matcher casesMatchers = casesPatterns.matcher(contents.get(i));
518 if (casesMatchers.find()) {
519 break;
520 } else {
521 Pattern stepPattern = Pattern.compile("\\s*STEP\\s+\"\\s*(.*)\\s*\"\\s*");
522 Matcher stepMatcher = stepPattern.matcher(contents.get(i));
523 try {
524 if (stepMatcher.find()) {
525 stepCount++;
526 stepCounter = caseNumber + "." + String.valueOf(stepCount);
527 stepHash.put(stepCounter, stepMatcher.group(1));
528 }
529 } catch (Exception e) {
530 break;
531 }
532 i++;
533 }
534
535 }
536 i--;
537 }
538
539 }
540 }
541 } else {
542 try {
543 //use buffering, reading one line at a time
544 //FileReader always assumes default encoding is OK!
545 try {
546 input = new BufferedReader(new FileReader(pythonScriptName));
547
548 } catch (Exception e) {
549 }
550
551 try {
552 String line = null; //not declared within while loop
553
554 while ((line = input.readLine()) != null) {
555 contents.add(line);
556 }
557 } finally {
558 try {
559 input.close();
560 } catch (Exception e) {
561 }
562
563 }
564 } catch (IOException ex) {
565 ex.printStackTrace();
566 }
567
568 for (int i = 0; i < contents.size(); i++) {
569 Pattern casePattern = Pattern.compile("\\s*def\\s+CASE(\\d+)\\s*\\(\\s*(.*)\\s*\\)\\s*:\\s*");
570 Matcher caseMatcher = casePattern.matcher(contents.get(i));
571 if (caseMatcher.find()) {
572 if (caseMatcher.group(1).equals(caseNumber)) {
573 i++;
574 Pattern casePatterns = Pattern.compile("\\s*def\\s+CASE(\\d+)\\s*\\(\\s*(.*)\\s*\\)\\s*:\\s*");
575 Matcher caseMatchers = casePatterns.matcher(contents.get(i));
576 while (!caseMatchers.find() && i < contents.size()) {
577 Pattern casesPatterns = Pattern.compile("\\s*def\\s+CASE(\\d+)\\s*\\(\\s*(.*)\\s*\\)\\s*:\\s*");
578 Matcher casesMatchers = casesPatterns.matcher(contents.get(i));
579 if (casesMatchers.find()) {
580 break;
581 } else {
582 Pattern stepPattern = Pattern.compile("\\s*main.step\\(\\s*\"\\s*(.*)\\s*\"\\s*\\)\\s*");
583 Matcher stepMatcher = stepPattern.matcher(contents.get(i));
584 try {
585 if (stepMatcher.find()) {
586 stepCount++;
587 stepCounter = caseNumber + "." + String.valueOf(stepCount);
588 stepHash.put(stepCounter, stepMatcher.group(1));
589 }
590 } catch (Exception e) {
591 break;
592 }
593 i++;
594 }
595 }
596 i--;
597 }
598 }
599 }
600 }
601 }
602
603 public void getCaseName() {
604 int stepCount = 0;
605 String stepCounter = "";
606 String paramFilePath = label.hierarchyTestON + "/tests/" + selectedTest + "/" + selectedTest + ".params";
607 FileInputStream fstream;
608 String testCases = "";
609 ArrayList<String> paramFileName = new ArrayList<String>();
610 ArrayList<String> nameBetweenTags = new ArrayList<String>();
611 try {
612 fstream = new FileInputStream(paramFilePath);
613 DataInputStream in = new DataInputStream(fstream);
614 BufferedReader br = new BufferedReader(new InputStreamReader(in));
615 String strLine;
616 try {
617 while ((strLine = br.readLine()) != null) {
618 paramFileName.add(strLine);
619 }
620 } catch (IOException ex) {
621 Logger.getLogger(ExecuteTest.class.getName()).log(Level.SEVERE, null, ex);
622 }
623 } catch (FileNotFoundException ex) {
624 Logger.getLogger(ExecuteTest.class.getName()).log(Level.SEVERE, null, ex);
625 }
626
627 for (int index = 0; index < paramFileName.size(); index++) {
628 Pattern testsPattern = Pattern.compile("<testcases>\\s*(.*)\\s*</testcases>");
629 Matcher testMatcher = testsPattern.matcher(paramFileName.get(index));
630 if (testMatcher.find()) {
631 testCases = testMatcher.group(1);
632 testCases = testCases.replaceAll(" ", "");
633 }
634
635 }
636
637 String[] testArray = null;
638 testArray = testCases.split(",");
639 String ospkFileName = label.hierarchyTestON + "/tests/" + selectedTest + "/" + selectedTest + ".ospk";
640 String pythonScriptName = label.hierarchyTestON + "/tests/" + selectedTest + "/" + selectedTest + ".py";
641 BufferedReader input = null;
642 ArrayList<String> contents = new ArrayList<String>();
643 File scriptName = new File(ospkFileName);
644 String caseId = "";
645 String caseName = "";
646 if (scriptName.exists()) {
647 try {
648 FileInputStream fstream1 = new FileInputStream(ospkFileName);
649 ArrayList<String> driverFunctionName = new ArrayList<String>();
650 DataInputStream in = new DataInputStream(fstream1);
651 BufferedReader br = new BufferedReader(new InputStreamReader(in));
652 String strLine;
653 while ((strLine = br.readLine()) != null) {
654 Pattern casePattern = Pattern.compile("^CASE\\s+(\\d+)");
655 Matcher match = casePattern.matcher(strLine);
656 while (match.find()) {
657 driverFunctionName.add(match.group());
658 caseId = match.group(1);
659 strLine = br.readLine();
660 casePattern = Pattern.compile("NAME\\s+(\\\"+(.*)\\\")");
661 match = casePattern.matcher(strLine);
662 if (match.find()) {
663 caseName = match.group(2);
664 }
665 caseNameHash.put(caseId, caseName);
666 }
667 }
668 } catch (Exception e) {
669 }
670 } else {
671 try {
672
673 FileInputStream fstream2 = new FileInputStream(pythonScriptName);
674 ArrayList<String> driverFunctionName = new ArrayList<String>();
675 DataInputStream in = new DataInputStream(fstream2);
676 BufferedReader br = new BufferedReader(new InputStreamReader(in));
677 String strLine;
678 while ((strLine = br.readLine()) != null) {
679 Pattern casePattern = Pattern.compile("\\s*def\\s+CASE(\\d+)\\s*\\(\\s*(.*)\\s*\\)\\s*:\\s*");
680 Matcher match = casePattern.matcher(strLine);
681 if (match.find()) {
682 driverFunctionName.add(match.group());
683 if (Arrays.asList(testArray).contains(match.group(1))) {
684 caseId = match.group(1);
685 } else {
686 caseId = null;
687 }
688 strLine = br.readLine();
689 }
690
691 casePattern = Pattern.compile("\\s*main.case\\(\\s*\"\\s*(.*)\\s*\"\\s*\\)\\s*");
692 match = casePattern.matcher(strLine);
693
694 if (match.find()) {
695 caseName = match.group(1);
696 if (caseId != null) {
697 caseNameHash.put(caseId, caseName);
698 }
699 }
700 }
701 } catch (Exception e) {
702 }
703 }
704 }
705}