diff --git a/tools/cooja/java/se/sics/cooja/plugins/LogScriptEngine.java b/tools/cooja/java/se/sics/cooja/plugins/LogScriptEngine.java index 91e1e2af6..3b148bc28 100644 --- a/tools/cooja/java/se/sics/cooja/plugins/LogScriptEngine.java +++ b/tools/cooja/java/se/sics/cooja/plugins/LogScriptEngine.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: LogScriptEngine.java,v 1.15 2009/06/15 15:41:32 fros4943 Exp $ + * $Id: LogScriptEngine.java,v 1.16 2009/06/15 16:53:32 fros4943 Exp $ */ package se.sics.cooja.plugins; @@ -371,9 +371,7 @@ public class LogScriptEngine { simulation.scheduleEvent(quitEvent, simulation.getSimulationTime()); } - if (timeoutEvent != null) { - timeoutEvent.remove(); - } + timeoutEvent.remove(); semaphoreSim.release(100); throw new RuntimeException("test script killed"); diff --git a/tools/cooja/java/se/sics/cooja/plugins/ScriptParser.java b/tools/cooja/java/se/sics/cooja/plugins/ScriptParser.java index 6d4b73db8..62eba9832 100644 --- a/tools/cooja/java/se/sics/cooja/plugins/ScriptParser.java +++ b/tools/cooja/java/se/sics/cooja/plugins/ScriptParser.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ScriptParser.java,v 1.6 2009/06/12 15:12:46 fros4943 Exp $ + * $Id: ScriptParser.java,v 1.7 2009/06/15 16:53:32 fros4943 Exp $ */ package se.sics.cooja.plugins; @@ -218,14 +218,33 @@ public class ScriptParser { } public String getJSCode() { + return getJSCode(code, timeoutCode); + } + + public static String getJSCode(String code, String timeoutCode) { return + "function run() { " + + "SEMAPHORE_SIM.acquire(); " + + "SEMAPHORE_SCRIPT.acquire(); " + /* STARTUP BLOCKS HERE! */ + "if (SHUTDOWN) { SCRIPT_KILL(); } " + + "if (TIMEOUT) { SCRIPT_TIMEOUT(); } " + + "msg = new java.lang.String(msg); " + + "node.setMoteMsg(mote, msg); " + + code + + "\n" + + "\n" + + "while (true) { SCRIPT_SWITCH(); } " /* SCRIPT ENDED */+ + "};" + + "\n" + "function GENERATE_MSG(time, msg) { " + " log.generateMessage(time, msg); " + "};\n" + + "\n" + "function SCRIPT_KILL() { " + " SEMAPHORE_SIM.release(100); " + " throw('test script killed'); " + "};\n" + + "\n" + "function SCRIPT_TIMEOUT() { " + timeoutCode + "; " + " log.log('TEST TIMEOUT\\n'); " + @@ -236,6 +255,7 @@ public class ScriptParser { " } " + " SCRIPT_KILL(); " + "};\n" + + "\n" + "function SCRIPT_SWITCH() { " + " SEMAPHORE_SIM.release(); " + " SEMAPHORE_SCRIPT.acquire(); " /* SWITCH BLOCKS HERE! */ + @@ -244,19 +264,10 @@ public class ScriptParser { " msg = new java.lang.String(msg); " + " node.setMoteMsg(mote, msg); " + "};\n" + + "\n" + "function write(mote,msg) { " + " mote.getInterfaces().getLog().writeString(msg); " + - "};\n" + - "function run() { " + - "SEMAPHORE_SIM.acquire(); " + - "SEMAPHORE_SCRIPT.acquire(); " + /* STARTUP BLOCKS HERE! */ - "if (SHUTDOWN) { SCRIPT_KILL(); } " + - "if (TIMEOUT) { SCRIPT_TIMEOUT(); } " + - "msg = new java.lang.String(msg); " + - "node.setMoteMsg(mote, msg); " + - code + "\n" + - "while (true) { SCRIPT_SWITCH(); } " /* SCRIPT ENDED */+ - "};"; + "};\n"; } public long getTimeoutTime() { diff --git a/tools/cooja/java/se/sics/cooja/plugins/ScriptRunner.java b/tools/cooja/java/se/sics/cooja/plugins/ScriptRunner.java index 8e86f97ac..4e5c25f41 100644 --- a/tools/cooja/java/se/sics/cooja/plugins/ScriptRunner.java +++ b/tools/cooja/java/se/sics/cooja/plugins/ScriptRunner.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ScriptRunner.java,v 1.20 2009/06/15 15:41:32 fros4943 Exp $ + * $Id: ScriptRunner.java,v 1.21 2009/06/15 16:53:32 fros4943 Exp $ */ package se.sics.cooja.plugins; @@ -75,9 +75,6 @@ public class ScriptRunner extends VisPlugin { private LogScriptEngine engine = null; - private File coojaBuild; - private File coojaJAR; - private final File logFile; private static BufferedWriter logWriter = null; /* For non-GUI tests */ private JTextArea scriptTextArea = null; @@ -92,26 +89,11 @@ public class ScriptRunner extends VisPlugin { super("Contiki Test Editor", gui, false); this.simulation = simulation; - try { - coojaBuild = new File(GUI.getExternalToolsSetting("PATH_CONTIKI"), "tools/cooja/build"); - coojaJAR = new File(GUI.getExternalToolsSetting("PATH_CONTIKI"), "tools/cooja/dist/cooja.jar"); - coojaBuild = coojaBuild.getCanonicalFile(); - coojaJAR = coojaJAR.getCanonicalFile(); - } catch (IOException e) { - coojaBuild = new File(GUI.getExternalToolsSetting("PATH_CONTIKI"), "tools/cooja/build"); - coojaJAR = new File(GUI.getExternalToolsSetting("PATH_CONTIKI"), "tools/cooja/dist/cooja.jar"); - } - logFile = new File(coojaBuild, "COOJA.testlog"); - final JTextArea lineTextArea = new JTextArea(); lineTextArea.setEnabled(false); lineTextArea.setMargin(new Insets(5,0,5,0)); - try { - scriptFirstLinesNumber = new ScriptParser("").getJSCode().split("\n").length + 2; - } catch (ScriptSyntaxErrorException e1) { - scriptFirstLinesNumber = 1; - } + scriptFirstLinesNumber = 1; /* Examples popup menu */ final JPopupMenu popupMenu = new JPopupMenu(); @@ -178,6 +160,17 @@ public class ScriptRunner extends VisPlugin { txt += i + "\n"; } lineTextArea.setText(txt); + + ScriptParser parser; + try { + parser = new ScriptParser(scriptTextArea.getText()); + String tooltip = parser.getJSCode(); + tooltip = tooltip.replaceAll("\n", "
"); + tooltip = "Generated code:

" + tooltip + ""; + lineTextArea.setToolTipText(tooltip); + } catch (ScriptSyntaxErrorException e) { + lineTextArea.setToolTipText("Unable to generate code: " + e.getMessage()); + } } public void changedUpdate(DocumentEvent e) { @@ -278,6 +271,7 @@ public class ScriptRunner extends VisPlugin { /* Continously write test output to file */ if (logWriter == null) { /* Warning: static variable, used by all active test editor plugins */ + File logFile = new File("COOJA.testlog"); if (logFile.exists()) { logFile.delete(); } @@ -371,6 +365,18 @@ public class ScriptRunner extends VisPlugin { final JDialog progressDialog = new JDialog((Window)GUI.getTopParentContainer(), (String) null); progressDialog.setTitle("Running test..."); + File coojaBuild; + File coojaJAR; + try { + coojaBuild = new File(GUI.getExternalToolsSetting("PATH_CONTIKI"), "tools/cooja/build"); + coojaJAR = new File(GUI.getExternalToolsSetting("PATH_CONTIKI"), "tools/cooja/dist/cooja.jar"); + coojaBuild = coojaBuild.getCanonicalFile(); + coojaJAR = coojaJAR.getCanonicalFile(); + } catch (IOException e) { + coojaBuild = new File(GUI.getExternalToolsSetting("PATH_CONTIKI"), "tools/cooja/build"); + coojaJAR = new File(GUI.getExternalToolsSetting("PATH_CONTIKI"), "tools/cooja/dist/cooja.jar"); + } + if (!coojaJAR.exists()) { JOptionPane.showMessageDialog(GUI.getTopParentContainer(), "Can't start COOJA, cooja.jar not found:" + @@ -380,6 +386,8 @@ public class ScriptRunner extends VisPlugin { return; } + final File logFile = new File(coojaBuild, "COOJA.testlog"); + String command[] = { "java", "-jar",