mirror of
https://github.com/oliverschmidt/contiki.git
synced 2025-01-11 03:29:51 +00:00
added import test functionality
This commit is contained in:
parent
1483a80a28
commit
ed18334c66
@ -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.3 2008/09/17 16:30:57 fros4943 Exp $
|
* $Id: ScriptRunner.java,v 1.4 2008/09/29 13:03:29 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.plugins;
|
package se.sics.cooja.plugins;
|
||||||
@ -77,15 +77,7 @@ public class ScriptRunner extends VisPlugin {
|
|||||||
private String oldTestName = null;
|
private String oldTestName = null;
|
||||||
private String oldInfo = null;
|
private String oldInfo = null;
|
||||||
|
|
||||||
public ScriptRunner(GUI gui) {
|
private static String exampleScript =
|
||||||
super("(GUI) Test Script Editor", gui);
|
|
||||||
this.gui = gui;
|
|
||||||
|
|
||||||
scriptTextArea = new JTextArea(8,50);
|
|
||||||
scriptTextArea.setMargin(new Insets(5,5,5,5));
|
|
||||||
scriptTextArea.setEditable(true);
|
|
||||||
scriptTextArea.setCursor(null);
|
|
||||||
scriptTextArea.setText(
|
|
||||||
"/* Script is called once for every node log output. */\n" +
|
"/* Script is called once for every node log output. */\n" +
|
||||||
"/* Input variables: Mote mote, int id, String msg. */\n" +
|
"/* Input variables: Mote mote, int id, String msg. */\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
@ -102,8 +94,17 @@ public class ScriptRunner extends VisPlugin {
|
|||||||
"/* To increase test run speed, close the simulator when done */\n" +
|
"/* To increase test run speed, close the simulator when done */\n" +
|
||||||
"//mote.getSimulation().getGUI().doQuit(false); /* Quit simulator (to end test run)*/\n" +
|
"//mote.getSimulation().getGUI().doQuit(false); /* Quit simulator (to end test run)*/\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"//mote.getSimulation().getGUI().reloadCurrentSimulation(true); /* Reload simulation */\n"
|
"//mote.getSimulation().getGUI().reloadCurrentSimulation(true); /* Reload simulation */\n";
|
||||||
);
|
|
||||||
|
public ScriptRunner(GUI gui) {
|
||||||
|
super("(GUI) Test Script Editor", gui);
|
||||||
|
this.gui = gui;
|
||||||
|
|
||||||
|
scriptTextArea = new JTextArea(8,50);
|
||||||
|
scriptTextArea.setMargin(new Insets(5,5,5,5));
|
||||||
|
scriptTextArea.setEditable(true);
|
||||||
|
scriptTextArea.setCursor(null);
|
||||||
|
scriptTextArea.setText(exampleScript);
|
||||||
|
|
||||||
logTextArea = new JTextArea(8,50);
|
logTextArea = new JTextArea(8,50);
|
||||||
logTextArea.setMargin(new Insets(5,5,5,5));
|
logTextArea.setMargin(new Insets(5,5,5,5));
|
||||||
@ -136,9 +137,123 @@ public class ScriptRunner extends VisPlugin {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
JButton importButton = new JButton("Import Contiki test");
|
||||||
|
importButton.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent ev) {
|
||||||
|
Runnable doImport = new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
importContikiTest();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
new Thread(doImport).start();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
JButton exportButton = new JButton("Export as Contiki test");
|
JButton exportButton = new JButton("Export as Contiki test");
|
||||||
exportButton.addActionListener(new ActionListener() {
|
exportButton.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent ev) {
|
public void actionPerformed(ActionEvent ev) {
|
||||||
|
exportAsContikiTest();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
JSplitPane centerPanel = new JSplitPane(
|
||||||
|
JSplitPane.VERTICAL_SPLIT,
|
||||||
|
new JScrollPane(scriptTextArea),
|
||||||
|
new JScrollPane(logTextArea)
|
||||||
|
);
|
||||||
|
|
||||||
|
JPanel buttonPanel = new JPanel(new BorderLayout());
|
||||||
|
buttonPanel.add(BorderLayout.WEST, importButton);
|
||||||
|
buttonPanel.add(BorderLayout.CENTER, toggleButton);
|
||||||
|
buttonPanel.add(BorderLayout.EAST, exportButton);
|
||||||
|
|
||||||
|
JPanel southPanel = new JPanel(new BorderLayout());
|
||||||
|
southPanel.add(BorderLayout.EAST, buttonPanel);
|
||||||
|
|
||||||
|
getContentPane().add(BorderLayout.CENTER, centerPanel);
|
||||||
|
getContentPane().add(BorderLayout.SOUTH, southPanel);
|
||||||
|
|
||||||
|
pack();
|
||||||
|
|
||||||
|
try {
|
||||||
|
setSelected(true);
|
||||||
|
} catch (java.beans.PropertyVetoException e) {
|
||||||
|
// Could not select
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void importContikiTest() {
|
||||||
|
Simulation simulation = ScriptRunner.this.gui.getSimulation();
|
||||||
|
|
||||||
|
/* Load config from test directory */
|
||||||
|
final File proposedDir = new File(GUI.getExternalToolsSetting("PATH_CONTIKI") + "/tools/cooja/contiki_tests");
|
||||||
|
if (!proposedDir.exists()) {
|
||||||
|
logger.fatal("Test directory does not exist: " + proposedDir.getPath());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
gui.doLoadConfig(false, true, proposedDir);
|
||||||
|
Vector<File> history = gui.getFileHistory();
|
||||||
|
|
||||||
|
File cscFile = history.firstElement();
|
||||||
|
String testName = cscFile.getName().substring(0, cscFile.getName().length()-4);
|
||||||
|
File testDir = cscFile.getParentFile();
|
||||||
|
File jsFile = new File(testDir, testName + ".js");
|
||||||
|
File infoFile = new File(testDir, testName + ".info");
|
||||||
|
|
||||||
|
oldTestName = testName;
|
||||||
|
|
||||||
|
if (!cscFile.exists()) {
|
||||||
|
logger.fatal("Can't locate config file: " + cscFile.getAbsolutePath());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!jsFile.exists()) {
|
||||||
|
logger.fatal("Can't locate .js file: " + jsFile.getAbsolutePath());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Import .js */
|
||||||
|
try {
|
||||||
|
scriptTextArea.setText("");
|
||||||
|
BufferedReader reader =
|
||||||
|
new BufferedReader(new InputStreamReader(new FileInputStream(jsFile)));
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
scriptTextArea.append(line + "\n");
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Import .info */
|
||||||
|
if (infoFile.exists()) {
|
||||||
|
try {
|
||||||
|
oldInfo = "";
|
||||||
|
BufferedReader reader =
|
||||||
|
new BufferedReader(new InputStreamReader(new FileInputStream(infoFile)));
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
oldInfo += line + "\n";
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void exportAsContikiTest() {
|
||||||
|
|
||||||
Simulation simulation = ScriptRunner.this.gui.getSimulation();
|
Simulation simulation = ScriptRunner.this.gui.getSimulation();
|
||||||
if (simulation == null) {
|
if (simulation == null) {
|
||||||
JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
|
JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
|
||||||
@ -219,11 +334,14 @@ public class ScriptRunner extends VisPlugin {
|
|||||||
/* Strip plugins */
|
/* Strip plugins */
|
||||||
Collection<Element> pluginsConfig = ScriptRunner.this.gui.getPluginsConfigXML();
|
Collection<Element> pluginsConfig = ScriptRunner.this.gui.getPluginsConfigXML();
|
||||||
if (pluginsConfig != null) {
|
if (pluginsConfig != null) {
|
||||||
JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
|
root.addContent(pluginsConfig);
|
||||||
"Stripping plugin configuration.\n" +
|
|
||||||
"(Exporting non-GUI plugins not implemented.)",
|
|
||||||
"Plugins detected", JOptionPane.WARNING_MESSAGE);
|
|
||||||
}
|
}
|
||||||
|
// if (pluginsConfig != null) {
|
||||||
|
// JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
|
||||||
|
// "Stripping plugin configuration.\n" +
|
||||||
|
// "(Exporting non-GUI plugins not implemented.)",
|
||||||
|
// "Plugins detected", JOptionPane.WARNING_MESSAGE);
|
||||||
|
// }
|
||||||
|
|
||||||
/* Fix simulation delay */
|
/* Fix simulation delay */
|
||||||
root.detach();
|
root.detach();
|
||||||
@ -284,6 +402,7 @@ public class ScriptRunner extends VisPlugin {
|
|||||||
BufferedWriter writer =
|
BufferedWriter writer =
|
||||||
new BufferedWriter(new OutputStreamWriter(new FileOutputStream(infoFile)));
|
new BufferedWriter(new OutputStreamWriter(new FileOutputStream(infoFile)));
|
||||||
writer.write(info);
|
writer.write(info);
|
||||||
|
writer.write("\n");
|
||||||
writer.close();
|
writer.close();
|
||||||
} else {
|
} else {
|
||||||
oldInfo = null;
|
oldInfo = null;
|
||||||
@ -328,10 +447,8 @@ public class ScriptRunner extends VisPlugin {
|
|||||||
final JButton button = new JButton("Abort test");
|
final JButton button = new JButton("Abort test");
|
||||||
button.addActionListener(new ActionListener() {
|
button.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (externalCoojaProcess != null) {
|
|
||||||
externalCoojaProcess.destroy();
|
externalCoojaProcess.destroy();
|
||||||
}
|
if (progressDialog.isDisplayable()) {
|
||||||
if (progressDialog != null && progressDialog.isDisplayable()) {
|
|
||||||
progressDialog.dispose();
|
progressDialog.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -394,8 +511,12 @@ public class ScriptRunner extends VisPlugin {
|
|||||||
}
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
logger.fatal("File not found: " + e);
|
logger.fatal("File not found: " + e);
|
||||||
|
progressDialog.setTitle("Test run completed. Test failed! (no logfile)");
|
||||||
|
button.setText("Test failed");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.fatal("IO error: " + e);
|
logger.fatal("IO error: " + e);
|
||||||
|
progressDialog.setTitle("Test run completed. Test failed! (IO exception)");
|
||||||
|
button.setText("Test failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -423,30 +544,6 @@ public class ScriptRunner extends VisPlugin {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
JPanel centerPanel = new JPanel(new BorderLayout());
|
|
||||||
centerPanel.add(BorderLayout.CENTER, new JScrollPane(scriptTextArea));
|
|
||||||
centerPanel.add(BorderLayout.SOUTH, new JScrollPane(logTextArea));
|
|
||||||
|
|
||||||
JPanel buttonPanel = new JPanel(new BorderLayout());
|
|
||||||
buttonPanel.add(BorderLayout.WEST, toggleButton);
|
|
||||||
buttonPanel.add(BorderLayout.EAST, exportButton);
|
|
||||||
|
|
||||||
JPanel southPanel = new JPanel(new BorderLayout());
|
|
||||||
southPanel.add(BorderLayout.EAST, buttonPanel);
|
|
||||||
|
|
||||||
getContentPane().add(BorderLayout.CENTER, centerPanel);
|
|
||||||
getContentPane().add(BorderLayout.SOUTH, southPanel);
|
|
||||||
|
|
||||||
pack();
|
|
||||||
|
|
||||||
try {
|
|
||||||
setSelected(true);
|
|
||||||
} catch (java.beans.PropertyVetoException e) {
|
|
||||||
// Could not select
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void closePlugin() {
|
public void closePlugin() {
|
||||||
if (scriptTester != null) {
|
if (scriptTester != null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user