added debugging output + generated javascript code tooltip
This commit is contained in:
parent
67bca87c1d
commit
32ac82fc22
@ -26,7 +26,7 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* 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;
|
package se.sics.cooja.plugins;
|
||||||
@ -371,9 +371,7 @@ public class LogScriptEngine {
|
|||||||
simulation.scheduleEvent(quitEvent, simulation.getSimulationTime());
|
simulation.scheduleEvent(quitEvent, simulation.getSimulationTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeoutEvent != null) {
|
|
||||||
timeoutEvent.remove();
|
timeoutEvent.remove();
|
||||||
}
|
|
||||||
|
|
||||||
semaphoreSim.release(100);
|
semaphoreSim.release(100);
|
||||||
throw new RuntimeException("test script killed");
|
throw new RuntimeException("test script killed");
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* 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;
|
package se.sics.cooja.plugins;
|
||||||
@ -218,14 +218,33 @@ public class ScriptParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getJSCode() {
|
public String getJSCode() {
|
||||||
|
return getJSCode(code, timeoutCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getJSCode(String code, String timeoutCode) {
|
||||||
return
|
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) { " +
|
"function GENERATE_MSG(time, msg) { " +
|
||||||
" log.generateMessage(time, msg); " +
|
" log.generateMessage(time, msg); " +
|
||||||
"};\n" +
|
"};\n" +
|
||||||
|
"\n" +
|
||||||
"function SCRIPT_KILL() { " +
|
"function SCRIPT_KILL() { " +
|
||||||
" SEMAPHORE_SIM.release(100); " +
|
" SEMAPHORE_SIM.release(100); " +
|
||||||
" throw('test script killed'); " +
|
" throw('test script killed'); " +
|
||||||
"};\n" +
|
"};\n" +
|
||||||
|
"\n" +
|
||||||
"function SCRIPT_TIMEOUT() { " +
|
"function SCRIPT_TIMEOUT() { " +
|
||||||
timeoutCode + "; " +
|
timeoutCode + "; " +
|
||||||
" log.log('TEST TIMEOUT\\n'); " +
|
" log.log('TEST TIMEOUT\\n'); " +
|
||||||
@ -236,6 +255,7 @@ public class ScriptParser {
|
|||||||
" } " +
|
" } " +
|
||||||
" SCRIPT_KILL(); " +
|
" SCRIPT_KILL(); " +
|
||||||
"};\n" +
|
"};\n" +
|
||||||
|
"\n" +
|
||||||
"function SCRIPT_SWITCH() { " +
|
"function SCRIPT_SWITCH() { " +
|
||||||
" SEMAPHORE_SIM.release(); " +
|
" SEMAPHORE_SIM.release(); " +
|
||||||
" SEMAPHORE_SCRIPT.acquire(); " /* SWITCH BLOCKS HERE! */ +
|
" SEMAPHORE_SCRIPT.acquire(); " /* SWITCH BLOCKS HERE! */ +
|
||||||
@ -244,19 +264,10 @@ public class ScriptParser {
|
|||||||
" msg = new java.lang.String(msg); " +
|
" msg = new java.lang.String(msg); " +
|
||||||
" node.setMoteMsg(mote, msg); " +
|
" node.setMoteMsg(mote, msg); " +
|
||||||
"};\n" +
|
"};\n" +
|
||||||
|
"\n" +
|
||||||
"function write(mote,msg) { " +
|
"function write(mote,msg) { " +
|
||||||
" mote.getInterfaces().getLog().writeString(msg); " +
|
" mote.getInterfaces().getLog().writeString(msg); " +
|
||||||
"};\n" +
|
"};\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 */+
|
|
||||||
"};";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getTimeoutTime() {
|
public long getTimeoutTime() {
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* 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;
|
package se.sics.cooja.plugins;
|
||||||
@ -75,9 +75,6 @@ public class ScriptRunner extends VisPlugin {
|
|||||||
|
|
||||||
private LogScriptEngine engine = null;
|
private LogScriptEngine engine = null;
|
||||||
|
|
||||||
private File coojaBuild;
|
|
||||||
private File coojaJAR;
|
|
||||||
private final File logFile;
|
|
||||||
private static BufferedWriter logWriter = null; /* For non-GUI tests */
|
private static BufferedWriter logWriter = null; /* For non-GUI tests */
|
||||||
|
|
||||||
private JTextArea scriptTextArea = null;
|
private JTextArea scriptTextArea = null;
|
||||||
@ -92,26 +89,11 @@ public class ScriptRunner extends VisPlugin {
|
|||||||
super("Contiki Test Editor", gui, false);
|
super("Contiki Test Editor", gui, false);
|
||||||
this.simulation = simulation;
|
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();
|
final JTextArea lineTextArea = new JTextArea();
|
||||||
lineTextArea.setEnabled(false);
|
lineTextArea.setEnabled(false);
|
||||||
lineTextArea.setMargin(new Insets(5,0,5,0));
|
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 */
|
/* Examples popup menu */
|
||||||
final JPopupMenu popupMenu = new JPopupMenu();
|
final JPopupMenu popupMenu = new JPopupMenu();
|
||||||
@ -178,6 +160,17 @@ public class ScriptRunner extends VisPlugin {
|
|||||||
txt += i + "\n";
|
txt += i + "\n";
|
||||||
}
|
}
|
||||||
lineTextArea.setText(txt);
|
lineTextArea.setText(txt);
|
||||||
|
|
||||||
|
ScriptParser parser;
|
||||||
|
try {
|
||||||
|
parser = new ScriptParser(scriptTextArea.getText());
|
||||||
|
String tooltip = parser.getJSCode();
|
||||||
|
tooltip = tooltip.replaceAll("\n", "<br>");
|
||||||
|
tooltip = "<html><b>Generated code:</b><p>" + tooltip + "</html>";
|
||||||
|
lineTextArea.setToolTipText(tooltip);
|
||||||
|
} catch (ScriptSyntaxErrorException e) {
|
||||||
|
lineTextArea.setToolTipText("Unable to generate code: " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changedUpdate(DocumentEvent e) {
|
public void changedUpdate(DocumentEvent e) {
|
||||||
@ -278,6 +271,7 @@ public class ScriptRunner extends VisPlugin {
|
|||||||
/* Continously write test output to file */
|
/* Continously write test output to file */
|
||||||
if (logWriter == null) {
|
if (logWriter == null) {
|
||||||
/* Warning: static variable, used by all active test editor plugins */
|
/* Warning: static variable, used by all active test editor plugins */
|
||||||
|
File logFile = new File("COOJA.testlog");
|
||||||
if (logFile.exists()) {
|
if (logFile.exists()) {
|
||||||
logFile.delete();
|
logFile.delete();
|
||||||
}
|
}
|
||||||
@ -371,6 +365,18 @@ public class ScriptRunner extends VisPlugin {
|
|||||||
final JDialog progressDialog = new JDialog((Window)GUI.getTopParentContainer(), (String) null);
|
final JDialog progressDialog = new JDialog((Window)GUI.getTopParentContainer(), (String) null);
|
||||||
progressDialog.setTitle("Running test...");
|
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()) {
|
if (!coojaJAR.exists()) {
|
||||||
JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
|
JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
|
||||||
"Can't start COOJA, cooja.jar not found:" +
|
"Can't start COOJA, cooja.jar not found:" +
|
||||||
@ -380,6 +386,8 @@ public class ScriptRunner extends VisPlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final File logFile = new File(coojaBuild, "COOJA.testlog");
|
||||||
|
|
||||||
String command[] = {
|
String command[] = {
|
||||||
"java",
|
"java",
|
||||||
"-jar",
|
"-jar",
|
||||||
|
Loading…
Reference in New Issue
Block a user