This commit is contained in:
boccioli_m
2015-07-01 09:19:02 +02:00
parent 86d98e0c2f
commit edcc5cb443
4 changed files with 222 additions and 447 deletions

View File

@@ -442,7 +442,7 @@ public class TestingList extends Panel {
updateStatus();
executeTests();
} else {
setButtonToStop();
setToStopped();
}
}//GEN-LAST:event_jButtonRunActionPerformed
@@ -695,7 +695,7 @@ public class TestingList extends Panel {
logger.log(Level.SEVERE, "Cant find Test: " + testName + " in table.");
}
//check if there are still pending tests. If not, set the status of the tool to Stopped.
if (rowD >= jTable1.getRowCount()-1 || pendingTestsCount()==0) {
if (pendingTestsCount()==0 && runningTestsCount()==0) {
setToStopped();
}
return rowD;
@@ -815,261 +815,10 @@ public class TestingList extends Panel {
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;
String sDeviceName;
String sTestName;
String sTestCaseName;
String sTestPath;
HashMap<String,Object> args = new HashMap<>();
HashMap mParameters = new HashMap();
//scan through the table starting from 'position' and execute the first selected test found
int row = position;
if (row >= 0 && row <= jTable1.getRowCount() - 1) {
for (row = position; row <= jTable1.getRowCount() - 1; row++) {
bSelected = (boolean) jTable1.getValueAt(row, COL.CHECK.ordinal());
if (bSelected) {
break;
}
}
if (bSelected) {
//build the .py test file path
sDeviceName = jTable1.getValueAt(row, COL.DEVICENAME.ordinal()).toString();
sTestName = jTable1.getValueAt(row, COL.TESTNAME.ordinal()).toString();
sTestCaseName = jTable1.getValueAt(row, COL.TESTSUITE.ordinal()).toString();
sTestPath = jTable1.getValueAt(row, COL.TESTPATH.ordinal()).toString();
mParameters = buildParametersMap(String.valueOf(jTable1.getValueAt(row, COL.TESTPARAMS.ordinal())));
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());
executeTest(position + 1);
return;
}
showResult(sDeviceName, sTestPath, "Test running", TestStatus.RUNNING.toString());
//launch the test
args.put("DEVICE", sDeviceName);
args.put("ret", "");
args.put("status", false);
if (!mParameters.isEmpty()) {
args.put("parameters", mParameters);
logger.log(Level.INFO, "Running test '" + sTestName + "' with the following parameters: " + mParameters.toString());
} else {
logger.log(Level.INFO, "Running Test '" + sTestName + "'. No parameters found.");
}
runAsync(sTestPath, args);
} catch (Exception ex) {
SwingUtils.showMessage(this, "executeTest()", ex.toString());
logger.log(Level.SEVERE, ex.toString());
showResult(sDeviceName, sTestPath, ex.toString(), TestStatus.FAILURE.toString());
setButtonToStop();
}
}
}
if (!bSelected) { //No test to play. Stop
setToStopped();
}
t.start();
}
//execute the selected tests in the list, starting from the position
public 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");
iRet = 0;
} catch (Exception ex) {
SwingUtils.showMessage(this, "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");
} catch (Exception ex) {
SwingUtils.showMessage(this, "executeTest(), run thread", ex.toString());
logger.log(Level.SEVERE, ex.toString());
setButtonToStop();
}
return iRet;
}
*/
//delete this
/*
public class RunTest_old implements Runnable {
private String sDeviceName, sTestPath;
private HashMap mParameters;
private HashMap<String,Object> args;
private HashMap<String,HashMap> hTests;
public RunTest(String sTestPath, HashMap<String,Object> args) {
System.out.println("A1");
this.sDeviceName = args.get("device").toString();
System.out.println("A2");
this.sTestPath = sTestPath;
System.out.println("A3");
this.mParameters = (HashMap) args.get("parameters");
this.args = args;
}
public RunTest(String sTestPath) {
this.sDeviceName = sTestPath;
this.sTestPath = sTestPath;
this.mParameters.put("a", 1);
}
public RunTest(HashMap<String,HashMap> args) {
System.out.println("A0");
this.hTests = (HashMap) args;
}
public void run() {
// code in the other thread, can reference "var" variable
int iLastExecutedTestIndex = -1;
final String sParallelizeBegin = "(run,(str('";
final String sParallelizeEnd = "'),))";
try {
System.out.println("A0.1");
//runAsync(sTestPath, args);parallelize((run,('Motor Test 3 100ms'), (run,('Motor Test 3 200ms')))
// Object ret = eval("parallelize((run,('Motor Test 3 100ms',)), (run,('Motor Test 3 200ms',)))");
String sParallelizeCommand = "parallelize(";
int i = 0;
int iTotalEntries = hTests.entrySet().size();
for(Map.Entry<String, HashMap> hTest : hTests.entrySet()){
setGlobalsVars(hTest.getValue());
sTestPath = hTest.getKey().toString();
sTestPath = sTestPath.replace("\\","\\\\");
sParallelizeCommand = sParallelizeCommand + "(run,(str('" + sTestPath;
i++;
System.out.println("Parameters passed: " + String.valueOf(hTest.getValue().get("parameters")));
System.out.println("A"+i);
if (i<iTotalEntries){
sParallelizeCommand = sParallelizeCommand + "'),,locals='pio')),"; //between each "run" command
}else{
sParallelizeCommand = sParallelizeCommand + "'),)))"; //very last part of command "parallelize"
}
}
System.out.println(sParallelizeCommand);
Object ret = eval(sParallelizeCommand);
// Object ret = eval("parallelize((run,(str('"+sTestPath+"'),)), (run,('Motor Test 3 200ms',)))");
System.out.println("Ret = " + String.valueOf(ret));
//Object ret1 = ((ArrayList) ret).get(0);
//Object ret11 = ((List<PyList>) ret1).get(0);
//Object ret2 = ((ArrayList) ret).get(1);
//System.out.println(String.valueOf(ret1));
//System.out.println(String.valueOf(ret11));
String sTestResult, sTestStatus, sTestName;
//read the return mapping and put the result in the right table row
for(Object oTestRet : (ArrayList) ret){
sTestPath = String.valueOf(((List<PyList>) oTestRet).get(0));
sTestStatus = String.valueOf(((List<PyList>) oTestRet).get(1));
sTestResult = String.valueOf(((List<PyList>) oTestRet).get(2));
HashMap<String, HashMap> hTest = hTests.get(sTestPath);
sDeviceName = String.valueOf(hTest.get("device"));
sTestName = String.valueOf(hTest.get("test"));
System.out.println(sDeviceName + "|" + sTestPath + "|" + sTestResult + "|" + sTestStatus);
iLastExecutedTestIndex = showResult(sDeviceName, sTestPath, sTestResult, sTestStatus) ;
}
} catch (Exception ex) {
Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex);
SwingUtils.showMessage(TestingList.this.getComponent(), "runTest()", ex.toString());
System.out.println(String.valueOf(ex));
}
}
}
*/
public class RunTest implements Runnable {
private String sDeviceName, sTestPath;
@@ -1096,7 +845,7 @@ public class TestingList extends Panel {
this.hTests = (HashMap) args;
}
public RunTest() {
System.out.println("A0");
//System.out.println("A0");
}
public void run() {
@@ -1135,9 +884,9 @@ public class TestingList extends Panel {
}
}
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
executeParallelTestsGroup(selectedTestsRows) ; //last execution did not find a test file. Continue with next execution
executeTest(position + 1);
}
}
}
}
@@ -1161,7 +910,6 @@ public class TestingList extends Panel {
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());
@@ -1180,29 +928,22 @@ public class TestingList extends Panel {
testArgs.put("device", sDeviceName);
testArgs.put("status", false);
args.put(sTestPath,testArgs);
System.out.println("A");
//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();
setToStopped();
}
}
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 = "'),))";
try {
System.out.println("A0.1");
//System.out.println("A0.1");
String sParallelizeCommand = "parallelize(";
int i = 0;
int iTotalEntries = hTests.entrySet().size();
@@ -1213,9 +954,9 @@ public class TestingList extends Panel {
sParallelizeCommand = sParallelizeCommand + "(run,(str('" + sTestPath;
i++;
System.out.println("Parameters passed: " + String.valueOf(hTest.getValue().get("parameters")));
System.out.println("A"+i);
//System.out.println("A"+i);
if (i<iTotalEntries){
sParallelizeCommand = sParallelizeCommand + "'),,locals='pio')),"; //between each "run" command
sParallelizeCommand = sParallelizeCommand + "'),)),"; //between each "run" command
}else{
sParallelizeCommand = sParallelizeCommand + "'),)))"; //very last part of command "parallelize"
}
@@ -1223,46 +964,56 @@ public class TestingList extends Panel {
System.out.println(sParallelizeCommand);
Object ret = eval(sParallelizeCommand);
// Object ret = eval("parallelize((run,(str('"+sTestPath+"'),)), (run,('Motor Test 3 200ms',)))");
System.out.println("Ret = " + String.valueOf(ret));
//System.out.println("Ret = " + String.valueOf(ret));
String sTestResult, sTestStatus, sTestName;
//read the return mapping and put the result in the right table row
for(Object oTestRet : (ArrayList) ret){
sTestPath = String.valueOf(((List<PyList>) oTestRet).get(0));
sTestStatus = String.valueOf(((List<PyList>) oTestRet).get(1));
sTestResult = String.valueOf(((List<PyList>) oTestRet).get(2));
HashMap<String, HashMap> hTest = hTests.get(sTestPath);
sDeviceName = String.valueOf(hTest.get("device"));
sTestName = String.valueOf(hTest.get("test"));
System.out.println("ret type "+ret.getClass().toString() );
for(Object oTestRet : (ArrayList) ret){
if(oTestRet.getClass().toString() == "org.python.core.PyList" && ((List<PyList>) oTestRet).size()>=3){
sTestPath = String.valueOf(((List<PyList>) oTestRet).get(0));
sTestStatus = String.valueOf(((List<PyList>) oTestRet).get(1));
sTestResult = String.valueOf(((List<PyList>) oTestRet).get(2));
HashMap<String, HashMap> hTest = hTests.get(sTestPath);
sDeviceName = String.valueOf(hTest.get("device"));
sTestName = String.valueOf(hTest.get("test"));
} else{ //problem, the test script does not return all the expected return values
String sErrorText = "Test "+ sTestPath+" did not return all requird return values";
Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, sErrorText);
SwingUtils.showMessage(TestingList.this.getComponent(), "executeParallelTestsGroup()", sErrorText);
System.out.println(String.valueOf(sErrorText));
sTestPath = String.valueOf(((List<PyList>) oTestRet).get(0));
sTestStatus = sErrorText;
sTestResult = "false";
HashMap<String, HashMap> hTest = hTests.get(sTestPath);
sDeviceName = String.valueOf(hTest.get("device"));
sTestName = String.valueOf(hTest.get("test"));
}
System.out.println(sDeviceName + "|" + sTestPath + "|" + sTestResult + "|" + sTestStatus);
iLastExecutedTestIndex = showResult(sDeviceName, sTestPath, sTestResult, sTestStatus) ;
iLastExecutedTestIndex = showResult(sDeviceName, sTestPath, sTestResult, sTestStatus) ;
}
} catch (ClassCastException ccex) {
Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ccex);
SwingUtils.showMessage(TestingList.this.getComponent(), "executeParallelTestsGroup()", ccex.toString());
//System.out.println(String.valueOf(ccex));
if(!sDeviceName.isEmpty())
showResult(sDeviceName, sTestPath, ccex.toString(), TestStatus.FAILURE.toString());
} catch (Exception ex) {
Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex);
SwingUtils.showMessage(TestingList.this.getComponent(), "runTest()", ex.toString());
SwingUtils.showMessage(TestingList.this.getComponent(), "executeParallelTestsGroup()", ex.toString());
System.out.println(String.valueOf(ex));
setButtonToStop();
showResult(sDeviceName, sTestPath, ex.toString(), TestStatus.FAILURE.toString());
}
} catch (Exception ex) {
SwingUtils.showMessage(TestingList.this.getComponent(), "executeTest(), run thread", ex.toString());
SwingUtils.showMessage(TestingList.this.getComponent(), "executeParallelTestsGroup(), run thread", ex.toString());
logger.log(Level.SEVERE, ex.toString());
setButtonToStop();
}
setToStopped();
}
return iRet;
}
}
}
}
//delete this
private void runTest(String sDeviceName, String sTestPath, HashMap mParameters) {