Using Cooja test scripts to automate simulations

From ContikiWiki

Jump to: navigation, search

Also see TestScripts

(The following tutorial is based on an email from Fredrik Ă–sterlind to the developer mailing list, 2009-05-18)

The easiest way to automate simulations in Cooja so that you can run multiple test is by using COOJAs "Contiki test scripts". Contiki tests can be run both with and without GUI, and could, combined with a shell script, automate several test runs (for example changing parameters in the .csc simulation file).

Example: running a simple Hello world test repeatedly with different random seeds.


Contents

[edit] 1. Create new simulation

When in the "Create new simulation" dialog, be sure to configure for automatically generated random seeds (the checkbox right of the "Main random seed"). Every time this simulation is loaded, a new random seed will be used.


[edit] 2. Configure simulation

Create a mote type (use hello world or your favorite Contiki app), and add a few nodes. At this step you may typically also want to configure the radio medium, node positions...


[edit] 3. Create a test script

Start the "Contiki Test Editor" plugin. There are several test scripts available (Javascripts, ends with .js), for now use this very simple script:

TIMEOUT(10000);
log.log("first simulation message at time : " + time + "\n");
while (true) {
  YIELD(); /* wait for another mote output */
}

Copy and paste this script into the upper part of the test editor - this is where the javascript code goes. The lower part shows the currently active test output.

The above script is very simple: it declares a test timeout of 10 seconds. It also prints the first printf() output from any of the simulation nodes. Depending on what you want to do, perhaps such a simple script is sufficient if you only want to repeat tests with a given duration (10 seconds in this case).


[edit] 4. Activate the test

Click "Activate" in the plugin, and then start the simulation. The simulation stops after ten seconds. In the lower part of the test editor plugin, you should messages indicating that the test timed out (failed).


[edit] 5. Run test (repeatedly) without GUI

To run this test without GUI, you should first export it: "Export as Contiki test". Follow the instructions. The test files will be saved to /tools/cooja/contiki_tests. Open a terminal and enter this directory.

To run the test once:

> bash RUN_TEST mytest

mytest.log contains the test output (the lower part of the plugin when in graphical mode).

To run the test 10 times:

> bash RUN_REPEATED 10 mytest

mytest6.log contains the test output of test run number 6/10.

Personal tools