diff --git a/config/plugins.properties b/config/plugins.properties index 62400e8..334b0ab 100644 --- a/config/plugins.properties +++ b/config/plugins.properties @@ -1,6 +1,6 @@ -#Fri Jun 26 14:47:27 CEST 2015 +#Fri Jun 26 16:02:38 CEST 2015 .\\home\\plugins\\TestMain.java=disabled -.\\home\\plugins\\TestingListDetails.java=disabled +.\\home\\plugins\\TestingListDetails.java=enabled .\\home\\plugins\\TestingList.java=enabled .\\home\\plugins\\TestingPanel.java=disabled .\\home\\plugins\\PowerSupply.java=disabled diff --git a/plugins/TestingList.java b/plugins/TestingList.java index 6af006c..3dbcd27 100644 --- a/plugins/TestingList.java +++ b/plugins/TestingList.java @@ -6,9 +6,7 @@ import ch.psi.pshell.core.Controller; import ch.psi.utils.swing.MonitoredPanel; import ch.psi.pshell.ui.Panel; import ch.psi.utils.swing.SwingUtils; -import ch.psi.wsaf.ApplicationStateException; import ch.psi.wsaf.Task; -import ch.psi.wsaf.TaskRunningException; import java.io.File; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -28,18 +26,19 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Properties; import java.util.Vector; import java.util.logging.FileHandler; import java.util.logging.SimpleFormatter; -import javax.script.ScriptException; import javax.swing.DefaultCellEditor; import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JFileChooser; -import javax.swing.JFrame; import javax.swing.table.DefaultTableCellRenderer; import org.apache.commons.io.FilenameUtils; +import org.python.core.PyList; import static org.python.bouncycastle.util.Arrays.append; /** @@ -87,20 +86,13 @@ public class TestingList extends Panel { boolean status = (boolean) eval("status"); Object deviceName = eval("DEVICE"); String sStatus = (status == true) ? TestStatus.SUCCESS.toString() : TestStatus.FAILURE.toString(); - -// if (exception!=null){ -// SwingUtils.showMessage(getComponent(), "Error", String.valueOf(exception)); -// } else { -// SwingUtils.showMessage(getComponent(), "onExecutedFile()", String.valueOf(result)); -// } - if (ret != "") { - //SwingUtils.showMessage(getComponent(), "", ret.toString() + " - " + ret.getClass().getName()); - iCurrentTestPos = testingList.showResult(deviceName.toString(), fileName, ret.toString(), sStatus); + System.out.println("received end of test for test "+fileName); +// if (ret != "") { //start next test - if (testingList.isTestRunAllowed()) { - testingList.executeTest(iCurrentTestPos + 1); + if (testingList.isTestRunAllowed() && testingList.runningTestsCount()==0) { + testingList.executeTest(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 +/* } 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"; sStatus = TestStatus.FAILURE.toString(); String[] dsDeviceName = testingList.getTestInProgress(); @@ -108,12 +100,12 @@ public class TestingList extends Panel { if (dsDeviceName[0] != "") { iCurrentTestPos = testingList.showResult(dsDeviceName[0], fileName, ret.toString(), sStatus); //start next test - if (testingList.isTestRunAllowed()) { - testingList.executeTest(iCurrentTestPos + 1); + if (testingList.isTestRunAllowed() && testingList.runningTestsCount()==0) { + testingList.executeTest(iCurrentTestPos); } } } - } catch (Exception ex) { +*/ } catch (Exception ex) { String ret = "Could not start test script"; String sStatus = TestStatus.FAILURE.toString(); String[] dsDeviceName = testingList.getTestInProgress(); @@ -490,20 +482,22 @@ public class TestingList extends Panel { }//GEN-LAST:event_jCheckBox1ActionPerformed private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked - try { - switch (evt.getClickCount()) { - case 1: - int colIndex = jTable1.getSelectedColumn(); - if (colIndex == COL.CHECK.ordinal()) { - updateStatus(); - } - break; - case 2: - openDetails(); - break; + if(this.jTable1.isEnabled()){ + try { + switch (evt.getClickCount()) { + case 1: + int colIndex = jTable1.getSelectedColumn(); + if (colIndex == COL.CHECK.ordinal()) { + updateStatus(); + } + break; + case 2: + openDetails(); + break; + } + } catch (Exception ex) { + SwingUtils.showException(this, ex); } - } catch (Exception ex) { - SwingUtils.showException(this, ex); } }//GEN-LAST:event_jTable1MouseClicked @@ -582,7 +576,7 @@ public class TestingList extends Panel { * running */ public boolean isTestRunAllowed() { - return this.jButtonRun.getToolTipText().equals("Stop tests"); + return (this.jButtonRun.getToolTipText().equals("Stop tests") && pendingTestsCount()>0); } //move selection up in table @@ -660,6 +654,14 @@ public class TestingList extends Panel { int rowD = -1; String sTestName = testName; logger.log(Level.FINE, "Looking for: deviceName: " + deviceName + "; testPath: " + testName + " in table."); + String sStatus; + if(status == "true"){ + sStatus = TestStatus.SUCCESS.toString(); + } else if (status == "false"){ + sStatus = TestStatus.FAILURE.toString(); + } else{ + sStatus = status; + } //search for device name in table for (int row = 0; row <= jTable1.getRowCount() - 1; row++) { if (deviceName.equals(jTable1.getValueAt(row, COL.DEVICENAME.ordinal())) @@ -670,14 +672,14 @@ public class TestingList extends Panel { } } ImageIcon icon = new ImageIcon(); - switch (status) { + switch (sStatus) { case "Success": icon = TestStatus.SUCCESS.Icon(); - logger.log(Level.INFO, status + " - Device: " + deviceName + "; Test: " + sTestName + "; Result: " + res); + logger.log(Level.INFO, sStatus + " - Device: " + deviceName + "; Test: " + sTestName + "; Result: " + res); break; case "Failure": icon = TestStatus.FAILURE.Icon(); - logger.log(Level.SEVERE, status + " - Device: " + deviceName + "; Test: " + sTestName + "; Result: " + res); + logger.log(Level.SEVERE, sStatus + " - Device: " + deviceName + "; Test: " + sTestName + "; Result: " + res); break; case "Running": icon = TestStatus.RUNNING.Icon(); @@ -688,12 +690,46 @@ public class TestingList extends Panel { jTable1.setValueAt(icon, rowD, COL.ICON.ordinal()); jTable1.setValueAt(getNow(), rowD, COL.TIME.ordinal()); jTable1.setValueAt(res, rowD, COL.RESULT.ordinal()); - jTable1.setValueAt(status, rowD, COL.STATUS.ordinal()); + jTable1.setValueAt(sStatus, rowD, COL.STATUS.ordinal()); } else { 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) { + setToStopped(); + } return rowD; } + + //returns the amount of tests currently in Pending state + public int pendingTestsCount(){ + return testsStatusCount(TestStatus.PENDING); + } + + //returns the amount of tests currently in Pending state + public int runningTestsCount(){ + return testsStatusCount(TestStatus.RUNNING); + } + + //returns the amount of tests currently in Pending state + public int successTestsCount(){ + return testsStatusCount(TestStatus.SUCCESS); + } + + //returns the amount of tests currently in "status" state + private int testsStatusCount(TestStatus status){ + String sStatus; + boolean bSelected; + int iPendingTestsCount = 0; + for (int row = 0; row < jTable1.getRowCount(); row++) { + bSelected = (boolean) jTable1.getValueAt(row, COL.CHECK.ordinal()); + sStatus = jTable1.getValueAt(row, COL.STATUS.ordinal()).toString(); + if(bSelected && sStatus == status.toString()){ + iPendingTestsCount++; + } + } + return iPendingTestsCount; + } /** * find the test currently in progress @@ -712,7 +748,7 @@ public class TestingList extends Panel { } } } catch (Exception ex) { - this.setButtonToStop(); + this.setToStopped(); SwingUtils.showMessage(this, "getTestInProgress()", ex.toString()); } finally { return dsTestProperties; @@ -825,8 +861,7 @@ public class TestingList extends Panel { } } if (!bSelected) { //No test to play. Stop - setButtonToStop(); - logger.log(Level.INFO, "End of tests."); + setToStopped(); } } @@ -836,7 +871,7 @@ public class TestingList extends Panel { String sStartSequence, sStatus; int[] selectedTestsRows = {}; //scan through the table starting from 'position' and execute the first selected test found - int row = position; + 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()); @@ -849,14 +884,14 @@ public class TestingList extends Panel { //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 + && 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 + && 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; } } @@ -866,16 +901,21 @@ public class TestingList extends Panel { } } } - if (!bSelected) { //No test to play. Stop - setButtonToStop(); - logger.log(Level.INFO, "End of tests."); - } + + + } + + private void setToStopped(){ + //No more tests to play. Stop + setButtonToStop(); + logger.log(Level.INFO, "End of tests."); } //start all the tests in the rowsToExecute private int executeParallelTestsGroup(int[] rowsToExecute) { int iRet = -1; - HashMap args; + 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(); @@ -901,26 +941,14 @@ public class TestingList extends Panel { logger.log(Level.INFO, "Running Test '" + sTestName + "'. No parameters found."); System.out.println("Running test '" + sTestName + "'. No parameters found."); } - args = new HashMap(); + testArgs = new HashMap(); //args.put("ret", ""); - args.put("parameters", mParameters); - args.put("device", sDeviceName); - args.put("status", false); + testArgs.put("parameters", mParameters); + testArgs.put("test", sTestName); + testArgs.put("device", sDeviceName); + testArgs.put("status", false); + args.put(sTestPath,testArgs); System.out.println("A"); - runTest = new RunTest(sTestPath, args); - System.out.println("b"); - Thread t = new Thread(runTest); - System.out.println("c"); - t.start(); - System.out.println("d"); - - -// //Object ret = eval("parallelize((run,(" + sTestPath + "," + ")))"); -// Object ret = eval("parallelize((run,('Motor Test 3 100ms',)), (run,('Motor Test 3 200ms',)))"); -// Object ret1 = ((ArrayList) ret).get(0); -// //Object ret2 = ((ArrayList) ret).get(1); -// System.out.println(String.valueOf(ret1)); - //runAsync(sTestPath, args); iRet = 0; } catch (Exception ex) { @@ -930,15 +958,30 @@ public class TestingList extends Panel { 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 implements Runnable { private String sDeviceName, sTestPath; private HashMap mParameters; private HashMap args; + private HashMap hTests; public RunTest(String sTestPath, HashMap args) { System.out.println("A1"); @@ -954,28 +997,63 @@ public class TestingList extends Panel { this.sTestPath = sTestPath; this.mParameters.put("a", 1); } - + public RunTest(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("Parameters passed: " + String.valueOf(args.get("parameters"))); - System.out.println("A4"); - for (String key:args.keySet()){ - System.out.println("key: "+ key + " val: "+ String.valueOf(args.get(key))); - // getController().getScriptManager().setVar(key,args.get(key)); - //setGlobalVar(key, (Object) args.get(key)); + 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 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::[;::] -parameters=repeatTimes:1:Repeat N times;midPoint:41.0:Middle point A;spanFromMidPoint:11.0:B steps around middle point A +parameters=repeatTimes:1:Repeat N times;midPoint:41.0:Middle point A;spanFromMidPoint:5.0:B steps around middle point A diff --git a/script/tests/tests/PS Tests/power-supply-A/power-supply-A.py b/script/tests/tests/PS Tests/power-supply-A/power-supply-A.py index fe2f730..21e4ce6 100644 --- a/script/tests/tests/PS Tests/power-supply-A/power-supply-A.py +++ b/script/tests/tests/PS Tests/power-supply-A/power-supply-A.py @@ -2,63 +2,70 @@ #ManualScan(writables, readables, start = None, end = None, steps = None, relative = False) #by default, failed +import sys, inspect, os +testPath = inspect.getfile(inspect.currentframe()) # script filename (usually with path) ret = 'Test failed' status = False DEVICE = device params = parameters +print 'parameters:' +print params +print 'device:' +print DEVICE -scan = ManualScan(['time'], ['SetVA', 'ActualVA', 'ActualIA'] , [0.0], [30.0], [20]) +scan = ManualScan(['time'], ['SetV', 'ActualV', 'ActualI'] , [0.0], [30.0], [20]) +scan.setPlotName("A") scan.start() #Creating channels: dimension 1 #Ramp rate SetRamp = Channel(DEVICE + ':Set-RampA', type = 'd') #SetRamp = Channel('pw84:ai', type = 'd') -#LinearPositioner SetVA -SetVA = Channel(DEVICE + ':Set-VA', type = 'd') -#SetVA = Channel('pw84:ai', type = 'd') +#LinearPositioner SetV +SetV = Channel(DEVICE + ':Set-VA', type = 'd') +#SetV = Channel('pw84:ai', type = 'd') #Timestamp time -#ScalarDetector ActualVA -ActualVA = Channel(DEVICE + ':Actual-VA', type = 'd') -#ActualVA = Channel('pw84:ai', type = 'd') -#ScalarDetector ActualIA -ActualIA = Channel(DEVICE + ':Actual-IA', type = 'd') -#ActualIA = Channel('pw84:ai', type = 'd') +#ScalarDetector ActualV +ActualV = Channel(DEVICE + ':Actual-VA', type = 'd') +#ActualV = Channel('pw84:ai', type = 'd') +#ScalarDetector ActualI +ActualI = Channel(DEVICE + ':Actual-IA', type = 'd') +#ActualI = Channel('pw84:ai', type = 'd') #Init SetRamp.put(10.0, timeout=None) #set voltage to 0 -print 'Ramping down power supply to 0V' -SetVA.put(0.0, timeout=None) +print 'Ramping down power supply A to 0V' +SetV.put(0.0, timeout=None) #wait up to 2 minutes for voltage to be ~0 for setpoint1 in frange(0.0, 120.0, 1.0, True): - detector2 = ActualVA.get() + detector2 = ActualV.get() if detector2 <= 1.0: break sleep(0.5) #Dimension 1 -#LinearPositioner SetVA +#LinearPositioner SetV print 'Ramping up power supply' -for setpoint1 in frange(0.0, 30.0, 5.0, True): +for setpoint1 in frange(0.0, 20.0, 5.0, True): if setpoint1 > 50.0 or setpoint1 < 0.0: break - SetVA.put(setpoint1, timeout=None) # TODO: Set appropriate timeout - readback1 = SetVA.get() + SetV.put(setpoint1, timeout=None) # TODO: Set appropriate timeout + readback1 = SetV.get() if abs(readback1 - setpoint1) > 0.9 : # TODO: Check accuracy - raise Exception('SetVA could not be set to the value ' + str(setpoint1)) - ret = 'SetVA could not be set to the value ' + str(setpoint1) + '(measured value: '+str(readback1)+')' + raise Exception('SetV could not be set to the value ' + str(setpoint1)) + ret = 'SetV could not be set to the value ' + str(setpoint1) + '(measured value: '+str(readback1)+')' status = False break #scan quickly the output during some seconds for setpoint2 in range(0, 20): #Detector time detector1 = float(java.lang.System.currentTimeMillis()) - #Detector ActualVA - detector2 = ActualVA.get() - detector3 = ActualIA.get() + #Detector ActualV + detector2 = ActualV.get() + detector3 = ActualI.get() #scan.append ([setpoint1], [readback1], [detector1, detector2]) #append(setpoints, positions, values) scan.append ([detector1], [detector1], [readback1, detector2, detector3]) @@ -69,13 +76,14 @@ for setpoint1 in frange(0.0, 30.0, 5.0, True): print 'Ramping test done' #reset output to 0V -SetVA.put(0.0, timeout=None) +SetV.put(0.0, timeout=None) #Closing channels -SetVA.close() -ActualVA.close() -ActualIA.close() - - +SetV.close() +ActualV.close() +ActualI.close() scan.end() -'Ramping A test done' \ No newline at end of file + +ret = [testPath, True, 'Ramping A test done'] + +set_return(ret) \ No newline at end of file diff --git a/script/tests/tests/PS Tests/power-supply-B/power-supply-B.py b/script/tests/tests/PS Tests/power-supply-B/power-supply-B.py index 4f4a6d6..c6bcfdf 100644 --- a/script/tests/tests/PS Tests/power-supply-B/power-supply-B.py +++ b/script/tests/tests/PS Tests/power-supply-B/power-supply-B.py @@ -2,12 +2,21 @@ #ManualScan(writables, readables, start = None, end = None, steps = None, relative = False) #by default, failed +import sys, inspect, os +testPath = inspect.getfile(inspect.currentframe()) # script filename (usually with path) ret = 'Test failed' status = False DEVICE = device params = parameters +print 'parameters:' +print params +print 'device:' +print DEVICE + +#print os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) # script directory scan = ManualScan(['time'], ['SetVB', 'ActualVB', 'ActualIB'] , [0.0], [30.0], [20]) +scan.setPlotName("B") scan.start() #Creating channels: dimension 1 @@ -29,7 +38,7 @@ ActualIA = Channel(DEVICE + ':Actual-IB', type = 'd') SetRamp.put(10.0, timeout=None) #set voltage to 0 -print 'Ramping down power supply to 0V' +print 'Ramping down power supply B to 0V' SetVA.put(0.0, timeout=None) #wait up to 2 minutes for voltage to be ~0 @@ -42,7 +51,7 @@ for setpoint1 in frange(0.0, 120.0, 1.0, True): #Dimension 1 #LinearPositioner SetVA print 'Ramping up power supply' -for setpoint1 in frange(0.0, 30.0, 5.0, True): +for setpoint1 in frange(0.0, 20.0, 5.0, True): if setpoint1 > 50.0 or setpoint1 < 0.0: break SetVA.put(setpoint1, timeout=None) # TODO: Set appropriate timeout @@ -75,7 +84,7 @@ SetVA.close() ActualVA.close() ActualIA.close() - +ret = [testPath, True, 'Ramping B test done'] scan.end() -'Ramping B test done' \ No newline at end of file +set_return(ret) \ No newline at end of file