From 2d973c5353a8db4d1bb09acb55427e37f75d55a2 Mon Sep 17 00:00:00 2001 From: Adam Dunkels Date: Sun, 28 Jul 2013 20:32:17 +0200 Subject: [PATCH] Allow the exit code from a failed test script to propagate to the Java process, which makes it possible to track failing tests in makefiles and via scripts. --- tools/cooja/java/se/sics/cooja/GUI.java | 6 +++++- .../java/se/sics/cooja/plugins/LogScriptEngine.java | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/GUI.java b/tools/cooja/java/se/sics/cooja/GUI.java index 12c0d4bab..2d57a42cc 100644 --- a/tools/cooja/java/se/sics/cooja/GUI.java +++ b/tools/cooja/java/se/sics/cooja/GUI.java @@ -2673,6 +2673,10 @@ public class GUI extends Observable { * @param askForConfirmation Should we ask for confirmation before quitting? */ public void doQuit(boolean askForConfirmation) { + doQuit(askForConfirmation, 0); + } + + public void doQuit(boolean askForConfirmation, int exitCode) { if (isVisualizedInApplet()) { return; } @@ -2726,7 +2730,7 @@ public class GUI extends Observable { } saveExternalToolsUserSettings(); - System.exit(0); + System.exit(exitCode); } // // EXTERNAL TOOLS SETTINGS METHODS //// diff --git a/tools/cooja/java/se/sics/cooja/plugins/LogScriptEngine.java b/tools/cooja/java/se/sics/cooja/plugins/LogScriptEngine.java index 15719b005..3ba0eba00 100644 --- a/tools/cooja/java/se/sics/cooja/plugins/LogScriptEngine.java +++ b/tools/cooja/java/se/sics/cooja/plugins/LogScriptEngine.java @@ -101,6 +101,8 @@ public class LogScriptEngine { private long startRealTime; private long nextProgress; + private int exitCode = 0; + public LogScriptEngine(Simulation simulation) { this.simulation = simulation; } @@ -369,6 +371,7 @@ public class LogScriptEngine { if (!scriptActive) { return; } + exitCode = 2; logger.info("Timeout event @ " + t); engine.put("TIMEOUT", true); stepScript(); @@ -398,14 +401,14 @@ public class LogScriptEngine { new Thread() { public void run() { try { Thread.sleep(500); } catch (InterruptedException e) { } - simulation.getGUI().doQuit(false); + simulation.getGUI().doQuit(false, exitCode); }; }.start(); new Thread() { public void run() { try { Thread.sleep(2000); } catch (InterruptedException e) { } logger.warn("Killing Cooja"); - System.exit(1); + System.exit(exitCode); }; }.start(); } @@ -439,10 +442,12 @@ public class LogScriptEngine { } public void testOK() { + exitCode = 0; log("TEST OK\n"); deactive(); } public void testFailed() { + exitCode = 1; log("TEST FAILED\n"); deactive(); }