Closedown

This commit is contained in:
boccioli_m
2015-07-02 13:51:01 +02:00
parent e5355b7000
commit a3bc44ae37
6 changed files with 74 additions and 71 deletions

View File

@@ -1,7 +1,7 @@
/*
* Copyright (c) 2015 Paul Scherrer Institute. All rights reserved.
*/
//<editor-fold defaultstate="collapsed" desc="import">
import ch.psi.pshell.core.Controller;
import ch.psi.utils.swing.MonitoredPanel;
import ch.psi.pshell.ui.Panel;
@@ -40,7 +40,7 @@ import javax.swing.table.DefaultTableCellRenderer;
import org.apache.commons.io.FilenameUtils;
import org.python.core.PyList;
import static org.python.bouncycastle.util.Arrays.append;
//</editor-fold>
/**
*
* @author boccioli_m
@@ -532,6 +532,7 @@ public class TestingList extends Panel {
new Thread(() -> {
try {
Object ret = eval("parallelize((run,('testLocalVar1',globals(),{'a':21, 'b':34})), (run,('testLocalVar2',globals(),{'a':231, 'b':234})))");
//Object ret = eval("parallelize((run,('testLocalVar1',locals= {'a':21, 'b':34})), (run,('testLocalVar2', locals={'a':231, 'b':234})))");
Object ret1 = ((ArrayList) ret).get(0);
Object ret2 = ((ArrayList) ret).get(1);
System.out.println(String.valueOf(ret1));
@@ -815,32 +816,9 @@ public class TestingList extends Panel {
public class RunTest implements Runnable {
private String sDeviceName, sTestPath;
private HashMap mParameters;
private HashMap<String,Object> args;
private HashMap<String,HashMap> hTests;
//delete this
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;
}
//delete this
public RunTest(String sTestPath) {
this.sDeviceName = sTestPath;
this.sTestPath = sTestPath;
this.mParameters.put("a", 1);
}
//delete this
public RunTest(HashMap<String,HashMap> args) {
System.out.println("A0");
this.hTests = (HashMap) args;
}
public RunTest() {
//System.out.println("A0");
@@ -882,6 +860,7 @@ public class TestingList extends Panel {
}
}
if (selectedTestsRows.length > 0) { //at least one test is selected: launch it (or them)
System.out.println("\n===================================================\n");
executeParallelTestsGroup(selectedTestsRows) ; //last execution did not find a test file. Continue with next execution
executeTest(position + 1);
@@ -889,6 +868,22 @@ public class TestingList extends Panel {
}
}
private HashMap buildMapFromTableRow(int row){
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())));
HashMap testArgs = new HashMap();
//args.put("ret", "");
testArgs.put("parameters", mParameters);
testArgs.put("test", sTestName);
testArgs.put("device", sDeviceName);
testArgs.put("testPath", sTestPath);
testArgs.put("status", false);
return testArgs;
}
//start all the tests in the rowsToExecute
private int executeParallelTestsGroup(int[] rowsToExecute) {
@@ -896,14 +891,15 @@ public class TestingList extends Panel {
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;
String sTestName="", sDeviceName="", sTestPath="";
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 {
testArgs = buildMapFromTableRow(row);
sTestName = (String) testArgs.get("test") ;
sTestPath = (String) testArgs.get("testPath") ;
sDeviceName = (String) testArgs.get("device") ;
mParameters = (HashMap) testArgs.get("parameters") ;
File f = new File(sTestPath);
if (!f.exists() || f.isDirectory()) {
logger.log(Level.SEVERE, "Cannot find test script: " + sTestPath);
@@ -919,14 +915,9 @@ public class TestingList extends Panel {
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) {
@@ -950,27 +941,29 @@ public class TestingList extends Panel {
setGlobalsVars(hTest.getValue());
sTestPath = hTest.getKey().toString();
sTestPath = sTestPath.replace("\\","\\\\");
System.out.println(hTest.getValue().get("test"));
//System.out.println(hTest.getValue().get("test"));
sParallelizeCommand = sParallelizeCommand + "(run,(str('" + sTestPath;
i++;
System.out.println("Parameters passed: " + String.valueOf(hTest.getValue().get("parameters")));
//System.out.println("Parameters passed: " + String.valueOf(hTest.getValue().get("parameters")));
//System.out.println("A"+i);
sParallelizeArguments = "globals(),{parameters:'"+hTest.getValue().get("parameters")+
"',test:'"+hTest.getValue().get("test")+
"',device:'"+hTest.getValue().get("device")+
"',status:'"+hTest.getValue().get("status")+"'}";
//sParallelizeArguments = "locals()";
sParallelizeCommand = sParallelizeCommand +
"'),"+sParallelizeArguments;
i++;
if (i<iTotalEntries){
sParallelizeCommand = sParallelizeCommand +
"'),"+sParallelizeArguments+")),"; //between each "run" command
sParallelizeCommand = sParallelizeCommand +")),"; //between each "run" command
}else{
sParallelizeCommand = sParallelizeCommand + "'),"+sParallelizeArguments+")))"; //very last part of command "parallelize"
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));
String sTestResult, sTestStatus, sTestName;
String sTestResult, sTestStatus;
//read the return mapping and put the result in the right table row
//System.out.println("ret type "+ret.getClass().toString() );
//scan through all return mappings of all run tests
@@ -998,7 +991,7 @@ public class TestingList extends Panel {
sDeviceName = String.valueOf(hTest.get("device"));
sTestName = String.valueOf(hTest.get("test"));
}
System.out.println(sDeviceName + "|" + sTestPath + "|" + sTestResult + "|" + sTestStatus);
System.out.println("Result: " + sDeviceName + "|" + sTestPath + "|" + sTestResult + "|" + sTestStatus);
iLastExecutedTestIndex = showResult(sDeviceName, sTestPath, sTestResult, sTestStatus) ;
}
} catch (ClassCastException ccex) {