This commit is contained in:
boccioli_m
2015-06-30 15:30:40 +02:00
parent df5b42a266
commit 86d98e0c2f
2 changed files with 570 additions and 8 deletions

View File

@@ -86,11 +86,11 @@ public class TestingList extends Panel {
boolean status = (boolean) eval("status");
Object deviceName = eval("DEVICE");
String sStatus = (status == true) ? TestStatus.SUCCESS.toString() : TestStatus.FAILURE.toString();
System.out.println("received end of test for test "+fileName);
System.out.println("onExecutedFile: received end of test for test "+fileName);
// if (ret != "") {
//start next test
if (testingList.isTestRunAllowed() && testingList.runningTestsCount()==0) {
testingList.executeTest(iCurrentTestPos);
// testingList.executeTests(iCurrentTestPos);
}
/* } else { // ret empty means that either the test script does not have variable ret, or that the script could not be started at all
ret = "Could not start test script or script doea not contain default variables";
@@ -115,7 +115,7 @@ public class TestingList extends Panel {
iCurrentTestPos = testingList.showResult(dsDeviceName[0], fileName, ret, sStatus);
//start next test
if (testingList.isTestRunAllowed()) {
testingList.executeTest(iCurrentTestPos + 1);
// testingList.executeTests(iCurrentTestPos + 1);
}
}
}
@@ -440,7 +440,7 @@ public class TestingList extends Panel {
if (this.jButtonRun.getToolTipText().equals("Run selected tests")) {
setButtonToStart();
updateStatus();
executeTest(0);
executeTests();
} else {
setButtonToStop();
}
@@ -812,7 +812,16 @@ public class TestingList extends Panel {
jTable1.setValueAt(sStart, row, COL.STARTSEQUENCE.ordinal());
}
}
public void executeTests(){
RunTest runTest = new RunTest();
System.out.println("C");
Thread t = new Thread(runTest);
System.out.println("D");
t.start();
System.out.println("E");
}
/*
//execute the selected tests in the list, starting from the position
public void executeTest_Old(int position) {
boolean bSelected = false;
@@ -973,7 +982,7 @@ public class TestingList extends Panel {
return iRet;
}
*/
//delete this
/*
public class RunTest_old implements Runnable {
@@ -1083,12 +1092,112 @@ public class TestingList extends Panel {
this.mParameters.put("a", 1);
}
public RunTest(HashMap<String,HashMap> args) {
System.out.println("A0");
System.out.println("A0");
this.hTests = (HashMap) args;
}
public RunTest() {
System.out.println("A0");
}
public void run() {
// code in the other thread, can reference "var" variable
executeTest(0);
}
//execute the selected tests in the list, starting from the position
private void executeTest(int position) {
boolean bSelected = false;
String sStartSequence, sStatus;
int[] selectedTestsRows = {};
//scan through the table starting from 'position' and execute the first selected test found
int row = 0;// position;
if (row >= 0 && row < jTable1.getRowCount()) {
for (row = position; row < jTable1.getRowCount(); row++) {
bSelected = (boolean) jTable1.getValueAt(row, COL.CHECK.ordinal());
sStartSequence = jTable1.getValueAt(row, COL.STARTSEQUENCE.ordinal()).toString();
sStatus = jTable1.getValueAt(row, COL.STATUS.ordinal()).toString();
//collect tests to be launched in parallel
//the test must be: selected, set as start with previous, pending.
//alternatively, the test must be: selected, first of the list.
//System.out.println(String.valueOf(row) + "\t" + String.valueOf(bSelected) + "\t" + String.valueOf(selectedTestsRows.length) + "\t" + sStartSequence + "\t" + sStatus);
if (bSelected
&& sStatus.equals(TestStatus.PENDING.toString())
&& (selectedTestsRows.length == 0 || //the test must be: selected, pending, first of the list.
sStartSequence.equals(StartSequence.START_SEQ_TOGETHER.toString()))) { //or the test must be: selected, pending, set as start with previous
selectedTestsRows = append(selectedTestsRows, row);
} else if (bSelected
&& sStatus.equals(TestStatus.PENDING.toString()) &&//if this test must be executed...
selectedTestsRows.length > 0 && //but there are already tests to be executed in parallel....
(sStartSequence.equals(StartSequence.START_SEQ_AFTER.toString()))) { //...and this test must be executed in series, then stop searching
break;
}
}
if (selectedTestsRows.length > 0) { //at least one test is selected: launch it (or them)
if (executeParallelTestsGroup(selectedTestsRows) < 0) { //last execution did not find a test file. Continue with next execution
executeTest(position + 1);
}
}
}
}
//start all the tests in the rowsToExecute
private int executeParallelTestsGroup(int[] rowsToExecute) {
int iRet = -1;
HashMap args = new HashMap(); //this is the global map that will contain one map per test.
HashMap testArgs; //this is the map for a test.
RunTest runTest;
for (int row : rowsToExecute) {
String sDeviceName = jTable1.getValueAt(row, COL.DEVICENAME.ordinal()).toString();
String sTestName = jTable1.getValueAt(row, COL.TESTNAME.ordinal()).toString();
String sTestCaseName = jTable1.getValueAt(row, COL.TESTSUITE.ordinal()).toString();
String sTestPath = jTable1.getValueAt(row, COL.TESTPATH.ordinal()).toString();
HashMap mParameters = buildParametersMap(String.valueOf(jTable1.getValueAt(row, COL.TESTPARAMS.ordinal())));
System.out.println(String.valueOf(row) + "\t" + sDeviceName + "\t" + sTestName + "\t" + sTestCaseName + "\t" + String.valueOf(rowsToExecute.length));
try {
File f = new File(sTestPath);
if (!f.exists() || f.isDirectory()) {
logger.log(Level.SEVERE, "Cannot find test script: " + sTestPath);
showResult(sDeviceName, sTestPath, "Cannot find test script: " + sTestPath, TestStatus.FAILURE.toString());
iRet = -1;
continue;
}
showResult(sDeviceName, sTestPath, "Test running", TestStatus.RUNNING.toString());
//launch the test
if (!mParameters.isEmpty()) {
logger.log(Level.INFO, "Running test '" + sTestName + "' with the following parameters: " + mParameters.toString());
System.out.println("Running test '" + sTestName + "' with the following parameters: " + mParameters.toString());
} else {
logger.log(Level.INFO, "Running Test '" + sTestName + "'. No parameters found.");
System.out.println("Running test '" + sTestName + "'. No parameters found.");
}
testArgs = new HashMap();
//args.put("ret", "");
testArgs.put("parameters", mParameters);
testArgs.put("test", sTestName);
testArgs.put("device", sDeviceName);
testArgs.put("status", false);
args.put(sTestPath,testArgs);
System.out.println("A");
hTests = args;
iRet = 0;
} catch (Exception ex) {
SwingUtils.showMessage(TestingList.this.getComponent(), "executeTest()", ex.toString());
logger.log(Level.SEVERE, ex.toString());
showResult(sDeviceName, sTestPath, ex.toString(), TestStatus.FAILURE.toString());
setButtonToStop();
}
}
try{
// runTest = new RunTest(args);
// System.out.println("C");
// Thread t = new Thread(runTest);
// System.out.println("D");
// t.start();
// System.out.println("E");
int iLastExecutedTestIndex = -1;
final String sParallelizeBegin = "(run,(str('";
final String sParallelizeEnd = "'),))";
@@ -1131,8 +1240,20 @@ public class TestingList extends Panel {
Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex);
SwingUtils.showMessage(TestingList.this.getComponent(), "runTest()", ex.toString());
System.out.println(String.valueOf(ex));
}
setButtonToStop();
}
} catch (Exception ex) {
SwingUtils.showMessage(TestingList.this.getComponent(), "executeTest(), run thread", ex.toString());
logger.log(Level.SEVERE, ex.toString());
setButtonToStop();
}
return iRet;
}
}