mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-23 01:29:33 +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
|
||||
* 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;
|
||||
@ -77,15 +77,7 @@ public class ScriptRunner extends VisPlugin {
|
||||
private String oldTestName = null;
|
||||
private String oldInfo = null;
|
||||
|
||||
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(
|
||||
private static String exampleScript =
|
||||
"/* Script is called once for every node log output. */\n" +
|
||||
"/* Input variables: Mote mote, int id, String msg. */\n" +
|
||||
"\n" +
|
||||
@ -102,8 +94,17 @@ public class ScriptRunner extends VisPlugin {
|
||||
"/* To increase test run speed, close the simulator when done */\n" +
|
||||
"//mote.getSimulation().getGUI().doQuit(false); /* Quit simulator (to end test run)*/\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.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");
|
||||
exportButton.addActionListener(new ActionListener() {
|
||||
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();
|
||||
if (simulation == null) {
|
||||
JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
|
||||
@ -219,11 +334,14 @@ public class ScriptRunner extends VisPlugin {
|
||||
/* Strip plugins */
|
||||
Collection<Element> pluginsConfig = ScriptRunner.this.gui.getPluginsConfigXML();
|
||||
if (pluginsConfig != null) {
|
||||
JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
|
||||
"Stripping plugin configuration.\n" +
|
||||
"(Exporting non-GUI plugins not implemented.)",
|
||||
"Plugins detected", JOptionPane.WARNING_MESSAGE);
|
||||
root.addContent(pluginsConfig);
|
||||
}
|
||||
// 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 */
|
||||
root.detach();
|
||||
@ -284,6 +402,7 @@ public class ScriptRunner extends VisPlugin {
|
||||
BufferedWriter writer =
|
||||
new BufferedWriter(new OutputStreamWriter(new FileOutputStream(infoFile)));
|
||||
writer.write(info);
|
||||
writer.write("\n");
|
||||
writer.close();
|
||||
} else {
|
||||
oldInfo = null;
|
||||
@ -328,10 +447,8 @@ public class ScriptRunner extends VisPlugin {
|
||||
final JButton button = new JButton("Abort test");
|
||||
button.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (externalCoojaProcess != null) {
|
||||
externalCoojaProcess.destroy();
|
||||
}
|
||||
if (progressDialog != null && progressDialog.isDisplayable()) {
|
||||
if (progressDialog.isDisplayable()) {
|
||||
progressDialog.dispose();
|
||||
}
|
||||
}
|
||||
@ -394,8 +511,12 @@ public class ScriptRunner extends VisPlugin {
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.fatal("File not found: " + e);
|
||||
progressDialog.setTitle("Test run completed. Test failed! (no logfile)");
|
||||
button.setText("Test failed");
|
||||
} catch (IOException 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();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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() {
|
||||
if (scriptTester != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user