From a3bc44ae3708756bf4bf609b0f9e9dd7349e54a7 Mon Sep 17 00:00:00 2001 From: boccioli_m Date: Thu, 2 Jul 2015 13:51:01 +0200 Subject: [PATCH] Closedown --- plugins/TestingList.java | 83 +++++++++---------- plugins/TestingListDetails.form | 9 +- plugins/TestingListDetails.java | 8 +- .../Motor Test 2/Motor Test 2.py | 30 ++++--- .../PS Tests/power-supply-A/power-supply-A.py | 13 +-- .../PS Tests/power-supply-B/power-supply-B.py | 2 +- 6 files changed, 74 insertions(+), 71 deletions(-) diff --git a/plugins/TestingList.java b/plugins/TestingList.java index fcc4e98..667cca4 100644 --- a/plugins/TestingList.java +++ b/plugins/TestingList.java @@ -1,7 +1,7 @@ /* * Copyright (c) 2015 Paul Scherrer Institute. All rights reserved. */ - +// 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; - +// /** * * @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 args; private HashMap hTests; - - //delete this - public RunTest(String sTestPath, HashMap 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 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 - - + + + + + - + diff --git a/plugins/TestingListDetails.java b/plugins/TestingListDetails.java index 270bdf2..9e1c00c 100644 --- a/plugins/TestingListDetails.java +++ b/plugins/TestingListDetails.java @@ -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) diff --git a/script/tests/tests/Collimator Tests/Motor Test 2/Motor Test 2.py b/script/tests/tests/Collimator Tests/Motor Test 2/Motor Test 2.py index f8481ec..7d477a2 100644 --- a/script/tests/tests/Collimator Tests/Motor Test 2/Motor Test 2.py +++ b/script/tests/tests/Collimator Tests/Motor Test 2/Motor Test 2.py @@ -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 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 f6408d7..d8ca3bb 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 @@ -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) 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 2ea72de..7bbc701 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 @@ -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