2009-04-23 12:53:32 +02:00
|
|
|
TIMEOUT(30000);
|
2008-12-16 10:51:36 +01:00
|
|
|
|
2009-01-08 17:41:48 +01:00
|
|
|
/* conf */
|
|
|
|
nrReplies = 0;
|
2008-12-16 10:51:36 +01:00
|
|
|
ipAddress = "172.16.1.0";
|
|
|
|
osName = java.lang.System.getProperty("os.name").toLowerCase();
|
|
|
|
if (osName.startsWith("win")) {
|
2009-05-18 10:03:40 +02:00
|
|
|
pingOnceCmd = "ping -n 1 " + ipAddress;
|
2008-12-16 10:51:36 +01:00
|
|
|
pingCmd = "ping -n 10 " + ipAddress;
|
|
|
|
} else {
|
2009-05-18 10:03:40 +02:00
|
|
|
pingOnceCmd = "ping -c 1 " + ipAddress;
|
2008-12-16 10:51:36 +01:00
|
|
|
pingCmd = "ping -c 10 " + ipAddress;
|
|
|
|
}
|
|
|
|
replyMsg = "from " + ipAddress;
|
|
|
|
|
2009-05-18 10:03:40 +02:00
|
|
|
/* wait for mote startup */
|
2009-01-08 17:41:48 +01:00
|
|
|
WAIT_UNTIL(msg.contains('Sky telnet process'));
|
2008-12-16 10:51:36 +01:00
|
|
|
|
2009-05-18 10:03:40 +02:00
|
|
|
/* make gateway */
|
|
|
|
pingOnceProcess = new java.lang.Runtime.getRuntime().exec(pingOnceCmd);
|
|
|
|
GENERATE_MSG(5000, "continue");
|
|
|
|
WAIT_UNTIL(msg.equals("continue"));
|
|
|
|
log.log("cont\n");
|
|
|
|
|
|
|
|
/* override simulation delay, test will time out is too fast otherwise */
|
2009-04-23 12:53:32 +02:00
|
|
|
mote.getSimulation().setDelayTime(1);
|
|
|
|
|
2009-01-08 17:41:48 +01:00
|
|
|
/* start ping process */
|
2008-12-16 10:51:36 +01:00
|
|
|
var runnableObj = new Object();
|
|
|
|
runnableObj.run = function() {
|
|
|
|
pingProcess = new java.lang.Runtime.getRuntime().exec(pingCmd);
|
|
|
|
log.log("cmd> " + pingCmd + "\n");
|
|
|
|
|
|
|
|
stdIn = new java.io.BufferedReader(new java.io.InputStreamReader(pingProcess.getInputStream()));
|
|
|
|
while ((line = stdIn.readLine()) != null) {
|
|
|
|
log.log("> " + line + "\n");
|
|
|
|
if (line.contains(replyMsg)) {
|
2009-01-08 17:41:48 +01:00
|
|
|
nrReplies++;
|
|
|
|
//log.log("reply #" + nrReplies + "\n");
|
2008-12-16 10:51:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pingProcess.destroy();
|
|
|
|
|
2009-01-08 17:41:48 +01:00
|
|
|
if (nrReplies > 5) {
|
2008-12-16 10:51:36 +01:00
|
|
|
log.testOK(); /* Report test success and quit */
|
|
|
|
} else {
|
2009-01-08 17:41:48 +01:00
|
|
|
log.log("Only " + nrReplies + "/10 ping replies was received\n");
|
2008-12-16 10:51:36 +01:00
|
|
|
log.testFailed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var thread = new java.lang.Thread(new java.lang.Runnable(runnableObj));
|
|
|
|
thread.start();
|