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) {

View File

@@ -91,10 +91,13 @@
</Group>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane1" min="-2" pref="188" max="-2" attributes="0"/>
<Component id="jLabel7" min="-2" max="-2" attributes="0"/>
<Group type="102" attributes="0">
<Component id="jLabel7" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="229" max="32767" attributes="0"/>
</Group>
<Component id="jScrollPane1" pref="0" max="32767" attributes="0"/>
</Group>
<EmptySpace pref="65" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="cmCancel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="cmOk" alignment="3" min="-2" max="-2" attributes="0"/>

View File

@@ -247,9 +247,11 @@ public class TestingListDetails extends javax.swing.JPanel {
.addComponent(jLabel6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 65, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel7)
.addGap(0, 229, Short.MAX_VALUE))
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmCancel)
.addComponent(cmOk)

View File

@@ -14,8 +14,7 @@ def startTest(testName, DEVICE, params):
#get parameters from the calling interface
try:
print "Running test Motor Test 2 for device " + DEVICE + " with the following parameters:"
print params
print_log(testName, DEVICE, "Running test Motor Test 2 for device " + DEVICE + " with the following parameters:\n" + str(params))
middle = float(params["midPoint"]["value"])
loopTimes = int(params["repeatTimes"]["value"])
span = float(params["spanFromMidPoint"]["value"])
@@ -85,7 +84,7 @@ def startTest(testName, DEVICE, params):
endDefault = middle + span
end = endDefault+1
#find position: it will be the middle point of the test
print 'Moving to middle point ' + str(middle)
print_log(testName, DEVICE, 'Moving to middle point ' + str(middle) )
idInkr.put(middle, timeout=None) # TODO: Set appropriate timeout
readback2 = idInkr.get()
if abs(readback2 - middle) > 1 : # TODO: Check accuracy
@@ -96,7 +95,7 @@ def startTest(testName, DEVICE, params):
start = readback2+direction
countSteps = 0
count = 0
print 'Moving arond middle point (+-' + str(span) + ')'
print_log(testName, DEVICE, 'Moving around middle point (+-' + str(span) + ')' )
for setpoint1 in range(0, loopTimes*2):
count = count + 1
sleep( 2 ) # Settling time
@@ -147,14 +146,14 @@ def startTest(testName, DEVICE, params):
end = startDefault-1
start = setpoint2 - direction
direction = -1.0
print 'End of span (' + str(setpoint2) + '), changing direction to ' + str(direction)
print_log(testName, DEVICE, 'End of span (' + str(setpoint2) + '), changing direction to ' + str(direction) )
break
if endL>0.0 or ( direction < 0.0 and setpoint2 <= end +1):
#invert direction and swap start with end of translation
end = endDefault+1
start = setpoint2 - direction
direction = 1.0
print 'End of span (' + str(setpoint2) + '), changing direction to ' + str(direction)
print_log(testName, DEVICE, 'End of span (' + str(setpoint2) + '), changing direction to ' + str(direction) )
break
#set limits back
@@ -183,15 +182,20 @@ def startTest(testName, DEVICE, params):
#prepare and send feedback to calling tool
def sendFeedback(testPath, testName, DEVICE, returnString, testPassed):
print 'End of test. Result:'
print 'Test path: ' + testPath
print 'Test name: ' + testName
print 'Device: ' + DEVICE
print 'Test passed: ' + str(testPassed)
print 'Return string: ' + returnString
print_log(testName, DEVICE, 'End of test. Result:')
print_log(testName, DEVICE, 'Test path: ' + testPath)
print_log(testName, DEVICE, 'Test name: ' + testName )
print_log(testName, DEVICE, 'Device: ' + DEVICE)
print_log(testName, DEVICE, 'Test passed: ' + str(testPassed))
print_log(testName, DEVICE, 'Return string: ' + returnString)
ret = [testPath, DEVICE, returnString, testPassed]
set_return(ret)
def print_log(testName, DEVICE, text):
time.ctime()
now = time.strftime('%Y.%m.%d %H:%M:%S')
print now + ' ' + DEVICE + ' - ' + testName + ': ' + text
import sys, inspect, os, traceback
#get test arguments
DEVICE = device

View File

@@ -33,7 +33,7 @@ def startTest(testName, DEVICE, params):
ActualI = Channel(DEVICE + ':Actual-IA', type = 'd')
#ActualI = Channel('pw84:ai', type = 'd')
except:
sendFeedback(testPath, DEVICE, 'Unable to create channel - ' + traceback.format_exc(), False)
sendFeedback(testPath, testName, DEVICE, 'Unable to create channel - ' + traceback.format_exc(), False)
#raise Exception('Unable to create channel - ' + traceback.format_exc())
return
@@ -93,11 +93,12 @@ def startTest(testName, DEVICE, params):
#prepare and send feedback to calling tool
def sendFeedback(testPath, testName, DEVICE, returnString, testPassed):
print 'Test path: ' + testPath
print 'Test name: ' + testName
print 'Device: ' + DEVICE
print 'Test passed: ' + str(testPassed)
print 'Return string: ' + returnString
print_log(testName, DEVICE, 'End of test. Result:')
print_log(testName, DEVICE, 'Test path: ' + testPath)
print_log(testName, DEVICE, 'Test name: ' + testName )
print_log(testName, DEVICE, 'Device: ' + DEVICE)
print_log(testName, DEVICE, 'Test passed: ' + str(testPassed))
print_log(testName, DEVICE, 'Return string: ' + returnString)
ret = [testPath, DEVICE, returnString, testPassed]
set_return(ret)

View File

@@ -33,7 +33,7 @@ def startTest(testName, DEVICE, params):
ActualIA = Channel(DEVICE + ':Actual-IB', type = 'd')
#ActualIA = Channel('pw84:ai', type = 'd')
except:
sendFeedback(testPath, DEVICE, 'Unable to create channel - ' + traceback.format_exc(), False)
sendFeedback(testPath, testName, DEVICE, 'Unable to create channel - ' + traceback.format_exc(), False)
#raise Exception('Unable to create channel - ' + traceback.format_exc())
return
#Init