From 382bb652d5ce6614babd18945d697670f0055643 Mon Sep 17 00:00:00 2001 From: boccioli_m Date: Fri, 26 Jun 2015 09:24:55 +0200 Subject: [PATCH] Startup --- plugins/TestingList.java | 712 +++++++++--------- script/test/parallel.py | 24 +- .../PS Tests/power-supply-A/power-supply-A.py | 3 +- .../PS Tests/power-supply-B/power-supply-B.py | 1 + 4 files changed, 380 insertions(+), 360 deletions(-) diff --git a/plugins/TestingList.java b/plugins/TestingList.java index 13ac919..6375a99 100644 --- a/plugins/TestingList.java +++ b/plugins/TestingList.java @@ -6,7 +6,9 @@ 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; @@ -24,11 +26,13 @@ import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.util.ArrayList; import java.util.Iterator; 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; @@ -61,7 +65,7 @@ public class TestingList extends Panel { protected JPanel create() { try { testingList = new NetbeansPluginPanel(); - + } catch (IOException ex) { Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex); } @@ -70,46 +74,43 @@ public class TestingList extends Panel { /** * listen to script end of execution and get return value + * * @param fileName * @param result * @param exception */ - @Override + @Override protected void onExecutedFile(String fileName, Object result) { int iCurrentTestPos = 0; try { Object ret = eval("ret"); boolean status = (boolean) eval("status"); Object deviceName = eval("DEVICE"); - String sStatus = (status == true) ? TestStatus.SUCCESS.toString() : TestStatus.FAILURE.toString(); + 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 != "" ) { + if (ret != "") { //SwingUtils.showMessage(getComponent(), "", ret.toString() + " - " + ret.getClass().getName()); iCurrentTestPos = testingList.showResult(deviceName.toString(), fileName, ret.toString(), sStatus); //start next test - if(testingList.isTestRunAllowed()) - { - testingList.executeTest(iCurrentTestPos+1); + if (testingList.isTestRunAllowed()) { + testingList.executeTest(iCurrentTestPos + 1); } - } - 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(); //SwingUtils.showException(getComponent(), ex ); - if(dsDeviceName[0] != ""){ - iCurrentTestPos = testingList.showResult(dsDeviceName[0], fileName, ret.toString(), sStatus); - //start next test - if(testingList.isTestRunAllowed()) - { - testingList.executeTest(iCurrentTestPos+1); - } + if (dsDeviceName[0] != "") { + iCurrentTestPos = testingList.showResult(dsDeviceName[0], fileName, ret.toString(), sStatus); + //start next test + if (testingList.isTestRunAllowed()) { + testingList.executeTest(iCurrentTestPos + 1); + } } } } catch (Exception ex) { @@ -117,68 +118,69 @@ public class TestingList extends Panel { String sStatus = TestStatus.FAILURE.toString(); String[] dsDeviceName = testingList.getTestInProgress(); //SwingUtils.showException(getComponent(), ex ); - SwingUtils.showMessage(getComponent(), "onExecutedFile()", ex.toString() + " " + dsDeviceName[0]); - if(dsDeviceName[0] != ""){ - iCurrentTestPos = testingList.showResult(dsDeviceName[0], fileName, ret, sStatus); - //start next test - if(testingList.isTestRunAllowed() ) - { - testingList.executeTest(iCurrentTestPos+1); - } + SwingUtils.showMessage(getComponent(), "onExecutedFile()", ex.toString() + " " + dsDeviceName[0]); + if (dsDeviceName[0] != "") { + iCurrentTestPos = testingList.showResult(dsDeviceName[0], fileName, ret, sStatus); + //start next test + if (testingList.isTestRunAllowed()) { + testingList.executeTest(iCurrentTestPos + 1); + } } } } /** - *enumeration of table column indexes + * enumeration of table column indexes */ public enum COL { - CHECK (0), + + CHECK(0), STARTSEQUENCE(1), - TIME (2), - DEVICENAME (3), - DEVICEDESCR (4), - TESTSUITE (5), - TESTNAME (6), - TESTPATH (7), - TESTPARAMS (8), - TESTDESCR (9), - TESTHELP (10), - RESULT (11), - STATUS (12), - ICON (13); + TIME(2), + DEVICENAME(3), + DEVICEDESCR(4), + TESTSUITE(5), + TESTNAME(6), + TESTPATH(7), + TESTPARAMS(8), + TESTDESCR(9), + TESTHELP(10), + RESULT(11), + STATUS(12), + ICON(13); private int value; private COL(int value) { this.value = value; } - + /** * * @return */ - public int index(){ + public int index() { return (int) value; } - }; - + }; + /** - *enumeration of possible test statuses: text and related icon + * enumeration of possible test statuses: text and related icon */ - public enum TestStatus { + public enum TestStatus { + SUCCESS, FAILURE, PENDING, DISABLED, RUNNING; - + /** * * @return */ - public String IconFilename(){ + public String IconFilename() { String iconFileName = ""; - switch (this){ + switch (this) { case SUCCESS: iconFileName = "/icons/button_ok-16px.png"; break; @@ -197,8 +199,8 @@ public class TestingList extends Panel { } return iconFileName; } - - @Override + + @Override public final String toString() { String status = ""; switch (this) { @@ -219,27 +221,28 @@ public class TestingList extends Panel { break; } return status; - } + } + /** * * @return */ - public ImageIcon Icon(){ + public ImageIcon Icon() { String iconFileName = this.IconFilename(); ImageIcon icon = null; - if (iconFileName != "") - icon = new ImageIcon(getClass().getResource(this.IconFilename())); + if (iconFileName != "") { + icon = new ImageIcon(getClass().getResource(this.IconFilename())); + } return icon; - } - }; - - - - public enum StartSequence { + } + }; + + public enum StartSequence { + START_SEQ_AFTER, START_SEQ_TOGETHER; - - @Override + + @Override public final String toString() { String status = ""; switch (this) { @@ -252,12 +255,13 @@ public class TestingList extends Panel { } return status; } - }; - + }; + /** * */ public class NetbeansPluginPanel extends MonitoredPanel { + Logger logger = Logger.getLogger("TestsLog"); //these paths are converted to unix or win path according to host OS private final String TESTS_DEVICES_DEFAULT_DIR = new java.io.File(".").getCanonicalPath() @@ -441,70 +445,69 @@ public class TestingList extends Panel { }// //GEN-END:initComponents private void jButtonRunActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRunActionPerformed - if(this.jButtonRun.getToolTipText().equals("Run selected tests")){ + if (this.jButtonRun.getToolTipText().equals("Run selected tests")) { setButtonToStart(); updateStatus(); executeTest(0); - } - else{ + } else { setButtonToStop(); } }//GEN-LAST:event_jButtonRunActionPerformed - private void setButtonToStop(){ + private void setButtonToStop() { abort(); this.jButtonRun.setToolTipText("Run selected tests"); - jButtonRun.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/button_play-64px.png"))); + jButtonRun.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/button_play-64px.png"))); this.jTable1.setEnabled(true); - } - - private void setButtonToStart(){ + } + + private void setButtonToStart() { this.jButtonRun.setToolTipText("Stop tests"); - jButtonRun.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/button_stop-64px.png"))); + jButtonRun.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/button_stop-64px.png"))); this.jTable1.clearSelection(); this.jTable1.setEnabled(false); - } - - + } + + private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed boolean bSelected = jCheckBox1.isSelected(); int iSelRows = jTable1.getSelectedRowCount(); - - if(iSelRows>0){// if some rows are selected, check/uncheck selected rows - for (int row = 0; row <= jTable1.getRowCount()-1; row++) { - for(int selRow=0 ; selRow <= jTable1.getSelectedRowCount()-1 ; selRow++){ - if(row == jTable1.getSelectedRows()[selRow]) - jTable1.setValueAt(bSelected, row, 0); + + if (iSelRows > 0) {// if some rows are selected, check/uncheck selected rows + for (int row = 0; row <= jTable1.getRowCount() - 1; row++) { + for (int selRow = 0; selRow <= jTable1.getSelectedRowCount() - 1; selRow++) { + if (row == jTable1.getSelectedRows()[selRow]) { + jTable1.setValueAt(bSelected, row, 0); + } } } - } - else{//if none of the rows are selected, check/uncheck all - for (int row = 0; row <= jTable1.getRowCount()-1; row++) { - jTable1.setValueAt(bSelected, row, 0); - } + } else {//if none of the rows are selected, check/uncheck all + for (int row = 0; row <= jTable1.getRowCount() - 1; row++) { + jTable1.setValueAt(bSelected, row, 0); + } } updateStatus(); }//GEN-LAST:event_jCheckBox1ActionPerformed private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked - try{ - switch (evt.getClickCount()){ + try { + switch (evt.getClickCount()) { case 1: int colIndex = jTable1.getSelectedColumn(); - if (colIndex == COL.CHECK.ordinal()){ + if (colIndex == COL.CHECK.ordinal()) { updateStatus(); } break; - case 2: + case 2: openDetails(); break; } - } catch (Exception ex){ + } catch (Exception ex) { SwingUtils.showException(this, ex); - } + } }//GEN-LAST:event_jTable1MouseClicked - //oopen the log file using one of th default OS text reades + //oopen the log file using one of th default OS text reades private void jButtonOpenLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOpenLogActionPerformed String cmd; if (System.getProperty("os.name").toLowerCase().contains("windows")) { @@ -515,15 +518,17 @@ public class TestingList extends Panel { try { Runtime.getRuntime().exec(cmd); } catch (IOException ex) { - SwingUtils.showMessage(this, "jButtonOpenLogActionPerformed()", "jButtonOpenLogActionPerformed() "+ ex.toString() + - " \nPlease open the file manually. \nFile dir: "+TESTS_LOG_DEFAULT_DIR); + SwingUtils.showMessage(this, "jButtonOpenLogActionPerformed()", "jButtonOpenLogActionPerformed() " + ex.toString() + + " \nPlease open the file manually. \nFile dir: " + TESTS_LOG_DEFAULT_DIR); Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex); - } + } }//GEN-LAST:event_jButtonOpenLogActionPerformed private void jTable1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyReleased int colIndex = jTable1.getSelectedColumn(); - if (colIndex == COL.CHECK.ordinal()) updateStatus(); + if (colIndex == COL.CHECK.ordinal()) { + updateStatus(); + } }//GEN-LAST:event_jTable1KeyReleased private void jButtonMoveDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMoveDownActionPerformed @@ -535,8 +540,18 @@ public class TestingList extends Panel { }//GEN-LAST:event_jButtonMoveUpActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - // TODO add your handling code here: - this.saveSettings(); + new Thread(() -> { + try { + 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)); + System.out.println(String.valueOf(ret2)); + } catch (Exception ex) { + SwingUtils.showException(this, ex); + } + }).start(); + }//GEN-LAST:event_jButton1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed @@ -562,42 +577,51 @@ public class TestingList extends Panel { /** * - * @return status of run button. True = tests launching sequence is running + * @return status of run button. True = tests launching sequence is + * running */ - public boolean isTestRunAllowed(){ + public boolean isTestRunAllowed() { return this.jButtonRun.getToolTipText().equals("Stop tests"); } - + //move selection up in table - private void moveUp(){ - DefaultTableModel model = (DefaultTableModel)jTable1.getModel(); + private void moveUp() { + DefaultTableModel model = (DefaultTableModel) jTable1.getModel(); int[] rows = jTable1.getSelectedRows(); - model.moveRow(rows[0],rows[rows.length-1],rows[0]-1); - jTable1.setRowSelectionInterval(rows[0]-1, rows[rows.length-1]-1); + if (rows[0] - 1 >= 0) { + jTable1.setAutoCreateRowSorter(false); + model.moveRow(rows[0], rows[rows.length - 1], rows[0] - 1); + jTable1.setAutoCreateRowSorter(true); + jTable1.setRowSelectionInterval(rows[0] - 1, rows[rows.length - 1] - 1); + } } - + //move selection down in table - private void moveDown(){ - DefaultTableModel model = (DefaultTableModel)jTable1.getModel(); + private void moveDown() { + DefaultTableModel model = (DefaultTableModel) jTable1.getModel(); int[] rows = jTable1.getSelectedRows(); - model.moveRow(rows[0],rows[rows.length-1],rows[0]+1); - jTable1.setRowSelectionInterval(rows[0]+1, rows[rows.length-1]+1); + if (rows[rows.length - 1] < jTable1.getRowCount()) { + jTable1.setAutoCreateRowSorter(false); + model.moveRow(rows[0], rows[rows.length - 1], rows[0] + 1); + jTable1.setAutoCreateRowSorter(true); + jTable1.setRowSelectionInterval(rows[0] + 1, rows[rows.length - 1] + 1); + } } - + //open details of the selected test in a new panel - private void openDetails() throws Exception{ + private void openDetails() throws Exception { //pick details from the clicked row - int row = jTable1.getSelectedRow(); - String sDeviceName = jTable1.getValueAt(row, COL.DEVICENAME.ordinal()).toString(); - String sTestName = jTable1.getValueAt(row, COL.TESTNAME.ordinal()).toString(); - String sTestPath = String.valueOf(jTable1.getValueAt(row, COL.TESTPATH.ordinal())); + int row = jTable1.getSelectedRow(); + String sDeviceName = jTable1.getValueAt(row, COL.DEVICENAME.ordinal()).toString(); + String sTestName = jTable1.getValueAt(row, COL.TESTNAME.ordinal()).toString(); + String sTestPath = String.valueOf(jTable1.getValueAt(row, COL.TESTPATH.ordinal())); String sTestCaseName = jTable1.getValueAt(row, COL.TESTSUITE.ordinal()).toString(); String sTestDescription = jTable1.getValueAt(row, COL.TESTDESCR.ordinal()).toString(); String sDeviceDescription = jTable1.getValueAt(row, COL.DEVICEDESCR.ordinal()).toString(); - String sLastResult = jTable1.getValueAt(row, COL.RESULT.ordinal()).toString(); - String sResultTime = jTable1.getValueAt(row, COL.TIME.ordinal()).toString(); - String sTestHelp = String.valueOf(jTable1.getValueAt(row, COL.TESTHELP.ordinal())); - HashMap mParameters = buildParametersMap(String.valueOf(jTable1.getValueAt(row, COL.TESTPARAMS.ordinal()))); + String sLastResult = jTable1.getValueAt(row, COL.RESULT.ordinal()).toString(); + String sResultTime = jTable1.getValueAt(row, COL.TIME.ordinal()).toString(); + String sTestHelp = String.valueOf(jTable1.getValueAt(row, COL.TESTHELP.ordinal())); + HashMap mParameters = buildParametersMap(String.valueOf(jTable1.getValueAt(row, COL.TESTPARAMS.ordinal()))); //create map for passing details to Details Panel HashMap details = new HashMap(); details.put("deviceName", sDeviceName); @@ -607,23 +631,24 @@ public class TestingList extends Panel { details.put("testName", sTestName); details.put("testResult", sLastResult); details.put("time", sResultTime); - details.put("parameters", mParameters); - details.put("testHelp", sTestHelp); - details.put("testPath", sTestPath); + details.put("parameters", mParameters); + details.put("testHelp", sTestHelp); + details.put("testPath", sTestPath); //open details panel - JDialog dlg = new JDialog(getView(), "Test Details - " + sTestName , true); + JDialog dlg = new JDialog(getView(), "Test Details - " + sTestName, true); //create a class to visualise the details panel - Class testingListDetailsClass = getController().getClassByName("TestingListDetails"); - JPanel detailsPanel = (JPanel) testingListDetailsClass.getConstructor(new Class[]{HashMap.class}).newInstance(new Object[]{details}); - + Class testingListDetailsClass = getController().getClassByName("TestingListDetails"); + JPanel detailsPanel = (JPanel) testingListDetailsClass.getConstructor(new Class[]{HashMap.class}).newInstance(new Object[]{details}); + dlg.getContentPane().add(detailsPanel); //dlg.add(new TestingListDetails()); dlg.pack(); - dlg.setVisible(true); + dlg.setVisible(true); } /** - *show test result in table + * show test result in table + * * @param deviceName * @param testName * @param res @@ -633,11 +658,11 @@ public class TestingList extends Panel { public int showResult(String deviceName, String testName, String res, String status) { int rowD = -1; String sTestName = testName; - logger.log(Level.FINE, "Looking for: deviceName: " + deviceName + "; testPath: "+testName+" in table."); + logger.log(Level.FINE, "Looking for: deviceName: " + deviceName + "; testPath: " + testName + " in table."); //search for device name in table for (int row = 0; row <= jTable1.getRowCount() - 1; row++) { - if (deviceName.equals(jTable1.getValueAt(row, COL.DEVICENAME.ordinal())) && - testName.equals(jTable1.getValueAt(row, COL.TESTPATH.ordinal()))) { + if (deviceName.equals(jTable1.getValueAt(row, COL.DEVICENAME.ordinal())) + && testName.equals(jTable1.getValueAt(row, COL.TESTPATH.ordinal()))) { rowD = row; sTestName = jTable1.getValueAt(rowD, COL.TESTNAME.ordinal()).toString(); break; @@ -663,21 +688,21 @@ public class TestingList extends Panel { jTable1.setValueAt(getNow(), rowD, COL.TIME.ordinal()); jTable1.setValueAt(res, rowD, COL.RESULT.ordinal()); jTable1.setValueAt(status, rowD, COL.STATUS.ordinal()); - } - else{ + } else { logger.log(Level.SEVERE, "Cant find Test: " + testName + " in table."); } return rowD; } /** - *find the test currently in progress + * find the test currently in progress + * * @return properties of the test in progress */ public String[] getTestInProgress() { - String[] dsTestProperties = {"",""}; + String[] dsTestProperties = {"", ""}; //search for device name in table - try{ + try { for (int row = 0; row <= jTable1.getRowCount() - 1; row++) { if (jTable1.getValueAt(row, COL.STATUS.ordinal()).toString().equals(TestStatus.RUNNING.toString())) { dsTestProperties[0] = jTable1.getValueAt(row, COL.DEVICENAME.ordinal()).toString(); @@ -685,18 +710,16 @@ public class TestingList extends Panel { break; } } - } - catch (Exception ex) { + } catch (Exception ex) { this.setButtonToStop(); SwingUtils.showMessage(this, "getTestInProgress()", ex.toString()); - } - finally{ + } finally { return dsTestProperties; } } - + //returns the status of the specified test name for specified device name - public String getResult(String deviceName, String testName){ + public String getResult(String deviceName, String testName) { String sStatus = ""; int rowD = -1, colT = -1; //search for device name in table @@ -719,7 +742,7 @@ public class TestingList extends Panel { } /** - *visualise test status (columns status and icon) + * visualise test status (columns status and icon) */ public void updateStatus() { String sStatus; @@ -732,7 +755,9 @@ public class TestingList extends Panel { if (bSelected) { sStatus = TestStatus.PENDING.toString(); icon = TestStatus.PENDING.Icon(); - if(sStart == "") sStart = StartSequence.START_SEQ_AFTER.toString(); + if (sStart == "") { + sStart = StartSequence.START_SEQ_AFTER.toString(); + } } else { sStatus = TestStatus.DISABLED.toString(); icon = TestStatus.DISABLED.Icon(); @@ -743,10 +768,10 @@ public class TestingList extends Panel { jTable1.setValueAt(sStatus, row, COL.STATUS.ordinal()); jTable1.setValueAt(sStart, row, COL.STARTSEQUENCE.ordinal()); } - } - + } + //execute the selected tests in the list, starting from the position - public void executeTest_Old(int position){ + public void executeTest_Old(int position) { boolean bSelected = false; String sDeviceName; String sTestName; @@ -755,35 +780,37 @@ public class TestingList extends Panel { HashMap 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++){ + 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) { + 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(); + 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{ + 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()){ + 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); + 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("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()); + logger.log(Level.INFO, "Running test '" + sTestName + "' with the following parameters: " + mParameters.toString()); } else { logger.log(Level.INFO, "Running Test '" + sTestName + "'. No parameters found."); } @@ -794,169 +821,167 @@ public class TestingList extends Panel { showResult(sDeviceName, sTestPath, ex.toString(), TestStatus.FAILURE.toString()); setButtonToStop(); } - } - } - if(!bSelected){ //No test to play. Stop + } + } + if (!bSelected) { //No test to play. Stop setButtonToStop(); logger.log(Level.INFO, "End of tests."); } } - //execute the selected tests in the list, starting from the position - public void executeTest(int position){ + //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 = 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(); + int row = 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 + + //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... + } 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 + (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); - } - } - } - if(!bSelected){ //No test to play. Stop + if (executeParallelTestsGroup(selectedTestsRows) < 0) { //last execution did not find a test file. Continue with next execution + executeTest(position + 1); + } + } + } + if (!bSelected) { //No test to play. Stop setButtonToStop(); logger.log(Level.INFO, "End of tests."); } } - + //start all the tests in the rowsToExecute - private int executeParallelTestsGroup(int[] rowsToExecute){ + private int executeParallelTestsGroup(int[] rowsToExecute) { int iRet = -1; + HashMap args; 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."); - } + 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."); + } // runTest = new RunTest(sDeviceName, sTestPath, mParameters); // Thread t = new Thread(runTest); // t.start(); - HashMap args = new HashMap(); - Object ret = eval("ret"); - for(int i=0 ; i<1000000 ; i++){ - ret = eval("ret"); - if(String.valueOf(ret) != "") break; - } - args.put("parameters", mParameters); - args.put("device", sDeviceName); - args.put("ret", ""); - args.put("status", false); - System.out.println("Parameters passed: "+ String.valueOf(mParameters)); - try { - runAsync(sTestPath, args); - } catch (Controller.ControllerStateException ex) { - Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex); - } - 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(); - } + + args = new HashMap(); + args.put("ret", ""); + args.put("parameters", mParameters); + args.put("device", sDeviceName); + args.put("status", false); + Object ret = eval("parallelize((run,(" + sTestPath + "," + ")))"); + 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) { + SwingUtils.showMessage(this, "executeTest()", ex.toString()); + logger.log(Level.SEVERE, ex.toString()); + showResult(sDeviceName, sTestPath, ex.toString(), TestStatus.FAILURE.toString()); + setButtonToStop(); + } } return iRet; } - - - - public class RunTest implements Runnable { - private String sDeviceName, sTestPath; - private HashMap mParameters; + //delete this + public class RunTest implements Runnable { - public RunTest(String sDeviceName, String sTestPath, HashMap mParameters ){ - this.sDeviceName = sDeviceName; - this.sTestPath = sTestPath; - this.mParameters = mParameters; - } + private String sDeviceName, sTestPath; + private HashMap mParameters; - public void run() { - // code in the other thread, can reference "var" variable + public RunTest(String sDeviceName, String sTestPath, HashMap mParameters) { + this.sDeviceName = sDeviceName; + this.sTestPath = sTestPath; + this.mParameters = mParameters; + } + + public void run() { + // code in the other thread, can reference "var" variable HashMap args = new HashMap(); - try { - Thread.sleep(1000); + try { + Thread.sleep(1000); args.put("parameters", mParameters); - args.put("device", sDeviceName); - args.put("ret", ""); - args.put("status", false); - System.out.println("Parameters passed: "+ String.valueOf(mParameters)); + args.put("device", sDeviceName); + args.put("ret", ""); + args.put("status", false); + System.out.println("Parameters passed: " + String.valueOf(mParameters)); runAsync(sTestPath, args); } catch (Controller.ControllerStateException ex) { Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex); - } catch (InterruptedException ex) { - Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex); - } + } catch (InterruptedException ex) { + Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex); + } + } } - } - + //delete this - private void runTest(String sDeviceName, String sTestPath, HashMap mParameters ){ + private void runTest(String sDeviceName, String sTestPath, HashMap mParameters) { HashMap args = new HashMap(); args.put("parameters", mParameters); - args.put("device", sDeviceName); - args.put("ret", ""); - args.put("status", false); - System.out.println("Parameters passed: "+ String.valueOf(mParameters)); - try { + args.put("device", sDeviceName); + args.put("ret", ""); + args.put("status", false); + System.out.println("Parameters passed: " + String.valueOf(mParameters)); + try { runAsync(sTestPath, args); } catch (Controller.ControllerStateException ex) { Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex); } } - + /** - *table management + * table management */ private void buildTable() { String sDate = getNow(); DefaultTableModel model = (DefaultTableModel) jTable1.getModel(); jTable1.setModel(model); - + //Set up the combo box editor for the Start Sequence cells. JComboBox comboBox = new JComboBox(); comboBox.addItem(StartSequence.START_SEQ_AFTER.toString()); @@ -965,7 +990,7 @@ public class TestingList extends Panel { //Set up tool tips for the sequence cells. DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setToolTipText("Click for options"); - jTable1.getColumnModel().getColumn(COL.STARTSEQUENCE.ordinal()).setCellRenderer(renderer); + jTable1.getColumnModel().getColumn(COL.STARTSEQUENCE.ordinal()).setCellRenderer(renderer); jTable1.getColumnModel().getColumn(COL.ICON.ordinal()).setMaxWidth(27); jTable1.getColumnModel().getColumn(COL.CHECK.ordinal()).setMaxWidth(27); @@ -979,20 +1004,20 @@ public class TestingList extends Panel { jTable1.setAutoCreateRowSorter(true); updateStatus(); } - - private void hideColumn(COL column){ + + private void hideColumn(COL column) { jTable1.getColumnModel().getColumn(column.ordinal()).setMinWidth(0); jTable1.getColumnModel().getColumn(column.ordinal()).setMaxWidth(0); } //append test info to table - private void addToTable(String deviceName, - String deviceDescription, - String testSuite, - String testName, - String testParams, - String testDescription, - String testHelp) { + private void addToTable(String deviceName, + String deviceDescription, + String testSuite, + String testName, + String testParams, + String testDescription, + String testHelp) { String sDate = ""; if (testName.equals("") || deviceName.equals("")) { return; @@ -1015,7 +1040,6 @@ public class TestingList extends Panel { return dateFormat.format(date); } - /** * * @return time with sortable format @@ -1058,13 +1082,13 @@ public class TestingList extends Panel { if (configFile.exists() && !configFile.isDirectory()) { InputStream ist = new FileInputStream(configFile); propTest.load(ist); - addToTable( propDevice.getProperty("name"), - propDevice.getProperty("description"), - propDevice.getProperty("tests"), - propTest.getProperty("name"), - propTest.getProperty("parameters"), - propTest.getProperty("description"), - propTest.getProperty("help")); + addToTable(propDevice.getProperty("name"), + propDevice.getProperty("description"), + propDevice.getProperty("tests"), + propTest.getProperty("name"), + propTest.getProperty("parameters"), + propTest.getProperty("description"), + propTest.getProperty("help")); iCounter++; } } @@ -1075,34 +1099,24 @@ public class TestingList extends Panel { } logger.log(Level.INFO, iCounter + " tests loaded."); } - + /** - * Build a map with optional parameters to be passed to the testing script. - * The map is like this: - *parameters - * | - * \_ name - * | | - * | \_ value - * | \_ description - * | - * \_ name - * | | - * | \_ value - * | \_ description - * ... - * the name 'name' is the mapping key. 'value' and 'description' are constant mapping keys of a nested map. - */ - private HashMap buildParametersMap(String parametersString){ + * Build a map with optional parameters to be passed to the testing + * script. The map is like this: parameters | \_ name | | | \_ value | + * \_ description | \_ name | | | \_ value | \_ description ... the name + * 'name' is the mapping key. 'value' and 'description' are constant + * mapping keys of a nested map. + */ + private HashMap buildParametersMap(String parametersString) { HashMap mParameters = new HashMap(); // contains name and attributes HashMap mParameterAttributes = new HashMap(); //contians value and description String[] dsParameterAttributes = null; String[] dsParameters = parametersString.split(";"); - for (String sParameter : dsParameters){ + for (String sParameter : dsParameters) { dsParameterAttributes = sParameter.split(":"); - if(dsParameterAttributes.length > 2){ + if (dsParameterAttributes.length > 2) { mParameterAttributes = new HashMap(); - mParameterAttributes.put("value", (Object)dsParameterAttributes[1]); + mParameterAttributes.put("value", (Object) dsParameterAttributes[1]); mParameterAttributes.put("description", dsParameterAttributes[2]); //add parameter name and attributes (value + description) mParameters.put(dsParameterAttributes[0], mParameterAttributes); @@ -1127,8 +1141,8 @@ public class TestingList extends Panel { System.out.println("Open command cancelled by user."); } } - - private void saveSettings() { + + private void saveSettings() { final JFileChooser fc = new JFileChooser(); int returnVal = fc.showOpenDialog(NetbeansPluginPanel.this); @@ -1136,53 +1150,49 @@ public class TestingList extends Panel { if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); saveSettings(file); + } } - } - - private void saveSettings(File file) { - DefaultTableModel tableModel = (DefaultTableModel) jTable1.getModel(); - try { - ObjectOutputStream out = new ObjectOutputStream( - new FileOutputStream(file)); + + private void saveSettings(File file) { + DefaultTableModel tableModel = (DefaultTableModel) jTable1.getModel(); + try { + ObjectOutputStream out = new ObjectOutputStream( + new FileOutputStream(file)); out.writeObject(tableModel.getDataVector()); out.close(); - } - catch (Exception ex) { + } catch (Exception ex) { ex.printStackTrace(); } - } - - private void loadSettings() { + } + + private void loadSettings() { final JFileChooser fc = new JFileChooser(); int returnVal = fc.showOpenDialog(NetbeansPluginPanel.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); loadSettings(file); } - } - - private void loadSettings(File file) { - DefaultTableModel tableModel = (DefaultTableModel) jTable1.getModel(); - try { - ObjectInputStream in = new ObjectInputStream(new FileInputStream(file)); - Vector rowData = (Vector)in.readObject(); - Iterator itr = rowData.iterator(); - for (int row = 0 ; row < jTable1.getRowCount() ; row++){ - tableModel.removeRow(row); - } - while(itr.hasNext()) { - tableModel.addRow((Vector) itr.next()); - } - in.close(); } - catch (Exception ex) { - ex.printStackTrace(); - SwingUtils.showMessage(this, "loadSettings()", ex.toString()); + + private void loadSettings(File file) { + DefaultTableModel tableModel = (DefaultTableModel) jTable1.getModel(); + try { + ObjectInputStream in = new ObjectInputStream(new FileInputStream(file)); + Vector rowData = (Vector) in.readObject(); + Iterator itr = rowData.iterator(); + for (int row = 0; row < jTable1.getRowCount(); row++) { + tableModel.removeRow(row); + } + while (itr.hasNext()) { + tableModel.addRow((Vector) itr.next()); + } + in.close(); + } catch (Exception ex) { + ex.printStackTrace(); + SwingUtils.showMessage(this, "loadSettings()", ex.toString()); + } } - } - - //end of class + + //end of class } } - - diff --git a/script/test/parallel.py b/script/test/parallel.py index 8ac8a93..2d3d3de 100644 --- a/script/test/parallel.py +++ b/script/test/parallel.py @@ -1,14 +1,23 @@ +#Running scripts in parallel + +run("Motor Test 3 100ms") + +ret = parallelize((run,("Motor Test 3 100ms")), (run,("Motor Test 3 200ms"))) +print ret + + + #Simple parallization def task1(): - return out.read() + return 1 def task2(): - return inp.read() + return 2 def task3(): time.sleep(0.1) - return sin.read() + return 3 ret = parallelize(task1, task2, task3) print ret @@ -23,10 +32,10 @@ print ret #Functions with parameters def devRead(dev, msg): - print msg + " -> " + dev.getName() - return dev.read() + print msg + return "OK" -ret = parallelize((devRead,(out,"1")), (devRead,(inp,"2")), (devRead,(sin,"3"))) +ret = parallelize((devRead,(1,"1")), (devRead,(2,"2")), (devRead,(3,"3"))) print ret @@ -35,8 +44,7 @@ def taskExcept(msg): raise Exception ("Error in parallel task " + msg) -ret = parallelize((taskExcept,("1")), (taskExcept,(inp,"2")) ) +ret = parallelize((taskExcept,("1")), (taskExcept,("2")) ) print ret - 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 372e420..fe2f730 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 @@ -66,7 +66,7 @@ for setpoint1 in frange(0.0, 30.0, 5.0, True): ret = 'Test completed' status = True -print 'Raming test done' +print 'Ramping test done' #reset output to 0V SetVA.put(0.0, timeout=None) @@ -78,3 +78,4 @@ ActualIA.close() scan.end() +'Ramping A test done' \ 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 2c20f91..4f4a6d6 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 @@ -78,3 +78,4 @@ ActualIA.close() scan.end() +'Ramping B test done' \ No newline at end of file