|
|
| 4 |
Testing framework |
4 |
Testing framework |
| 5 |
----------------- |
5 |
----------------- |
| 6 |
|
6 |
|
| 7 |
ns-3 consists of a simulation core engine, a set of models, example programs, |
7 |
|ns3| consists of a simulation core engine, a set of models, example programs, |
| 8 |
and tests. Over time, new contributors contribute models, tests, and |
8 |
and tests. Over time, new contributors contribute models, tests, and |
| 9 |
examples. A Python test program ``test.py`` serves as the test |
9 |
examples. A Python test program ``test.py`` serves as the test |
| 10 |
execution manager; ``test.py`` can run test code and examples to |
10 |
execution manager; ``test.py`` can run test code and examples to |
|
|
| 17 |
BuildBots |
17 |
BuildBots |
| 18 |
********* |
18 |
********* |
| 19 |
|
19 |
|
| 20 |
At the highest level of ns-3 testing are the buildbots (build robots). |
20 |
At the highest level of |ns3| testing are the buildbots (build robots). |
| 21 |
If you are unfamiliar with |
21 |
If you are unfamiliar with |
| 22 |
this system look at `<http://djmitche.github.com/buildbot/docs/0.7.11/>`_. |
22 |
this system look at `<http://djmitche.github.com/buildbot/docs/0.7.11/>`_. |
| 23 |
This is an open-source automated system that allows |ns3| to be rebuilt |
23 |
This is an open-source automated system that allows |ns3| to be rebuilt |
|
|
| 120 |
-e EXAMPLE, --example=EXAMPLE |
120 |
-e EXAMPLE, --example=EXAMPLE |
| 121 |
specify a single example to run (no relative path is |
121 |
specify a single example to run (no relative path is |
| 122 |
needed) |
122 |
needed) |
|
|
123 |
-d, --duration print the duration of each test suite and example |
| 124 |
-e EXAMPLE, --example=EXAMPLE |
| 125 |
specify a single example to run (no relative path is |
| 126 |
needed) |
| 127 |
-u, --update-data If examples use reference data files, get them to re- |
| 128 |
generate them |
| 129 |
-f FULLNESS, --fullness=FULLNESS |
| 130 |
choose the duration of tests to run: QUICK, EXTENSIVE, |
| 131 |
or TAKES_FOREVER, where EXTENSIVE includes QUICK and |
| 132 |
TAKES_FOREVER includes QUICK and EXTENSIVE (only QUICK |
| 133 |
tests are run by default) |
| 123 |
-g, --grind run the test suites and examples using valgrind |
134 |
-g, --grind run the test suites and examples using valgrind |
| 124 |
-k, --kinds print the kinds of tests available |
135 |
-k, --kinds print the kinds of tests available |
| 125 |
-l, --list print the list of known tests |
136 |
-l, --list print the list of known tests |
|
|
| 307 |
|
318 |
|
| 308 |
PASS: Example examples/udp/udp-echo |
319 |
PASS: Example examples/udp/udp-echo |
| 309 |
|
320 |
|
| 310 |
You can specify the directory where ns-3 was built using the |
321 |
You can specify the directory where |ns3| was built using the |
| 311 |
``--buildpath`` option as follows. |
322 |
``--buildpath`` option as follows. |
| 312 |
|
323 |
|
| 313 |
:: |
324 |
:: |
|
|
| 329 |
PASS: Example examples/tutorial/first.py |
340 |
PASS: Example examples/tutorial/first.py |
| 330 |
|
341 |
|
| 331 |
Because Python examples are not built, you do not need to specify the |
342 |
Because Python examples are not built, you do not need to specify the |
| 332 |
directory where ns-3 was built to run them. |
343 |
directory where |ns3| was built to run them. |
| 333 |
|
344 |
|
| 334 |
Normally when example programs are executed, they write a large amount of trace |
345 |
Normally when example programs are executed, they write a large amount of trace |
| 335 |
file data. This is normally saved to the base directory of the distribution |
346 |
file data. This is normally saved to the base directory of the distribution |
|
|
| 399 |
$ ./test.py --verbose |
410 |
$ ./test.py --verbose |
| 400 |
|
411 |
|
| 401 |
All of these options can be mixed and matched. For example, to run all of the |
412 |
All of these options can be mixed and matched. For example, to run all of the |
| 402 |
ns-3 core test suites under valgrind, in verbose mode, while generating an HTML |
413 |
|ns3| core test suites under valgrind, in verbose mode, while generating an HTML |
| 403 |
output file, one would do:: |
414 |
output file, one would do:: |
| 404 |
|
415 |
|
| 405 |
$ ./test.py --verbose --grind --constrain=core --html=results.html |
416 |
$ ./test.py --verbose --grind --constrain=core --html=results.html |
|
|
| 417 |
* Examples |
428 |
* Examples |
| 418 |
* Performance Tests |
429 |
* Performance Tests |
| 419 |
|
430 |
|
|
|
431 |
Moreover, each test is further classified according to the expected time needed to |
| 432 |
run it. Tests are classified as: |
| 433 |
|
| 434 |
* QUICK |
| 435 |
* EXTENSIVE |
| 436 |
* TAKES_FOREVER |
| 437 |
|
| 438 |
Note that specifying EXTENSIVE fullness will also run tests in QUICK category. |
| 439 |
Specifying TAKES_FOREVER will run tests in EXTENSIVE and QUICK categories. |
| 440 |
By default, only QUICK tests are ran. |
| 441 |
|
| 442 |
As a rule of thumb, tests that must be run to ensure |ns3| coherence should be |
| 443 |
QUICK (i.e., take a few seconds). Tests that could be skipped, but are nice to do |
| 444 |
can be EXTENSIVE; these are tests that typically need minutes. TAKES_FOREVER is |
| 445 |
left for tests that take a really long time, in the order of several minutes. |
| 446 |
The main classification goal is to be able to run the buildbots in a reasonable |
| 447 |
time, and still be able to perform more extensive tests when needed. |
| 448 |
|
| 420 |
BuildVerificationTests |
449 |
BuildVerificationTests |
| 421 |
++++++++++++++++++++++ |
450 |
++++++++++++++++++++++ |
| 422 |
|
451 |
|
| 423 |
These are relatively simple tests that are built along with the distribution |
452 |
These are relatively simple tests that are built along with the distribution |
| 424 |
and are used to make sure that the build is pretty much working. Our |
453 |
and are used to make sure that the build is pretty much working. Our |
| 425 |
current unit tests live in the source files of the code they test and are |
454 |
current unit tests live in the source files of the code they test and are |
| 426 |
built into the ns-3 modules; and so fit the description of BVTs. BVTs live |
455 |
built into the |ns3| modules; and so fit the description of BVTs. BVTs live |
| 427 |
in the same source code that is built into the ns-3 code. Our current tests |
456 |
in the same source code that is built into the |ns3| code. Our current tests |
| 428 |
are examples of this kind of test. |
457 |
are examples of this kind of test. |
| 429 |
|
458 |
|
| 430 |
Unit Tests |
459 |
Unit Tests |
|
|
| 432 |
|
461 |
|
| 433 |
Unit tests are more involved tests that go into detail to make sure that a |
462 |
Unit tests are more involved tests that go into detail to make sure that a |
| 434 |
piece of code works as advertised in isolation. There is really no reason |
463 |
piece of code works as advertised in isolation. There is really no reason |
| 435 |
for this kind of test to be built into an ns-3 module. It turns out, for |
464 |
for this kind of test to be built into an |ns3| module. It turns out, for |
| 436 |
example, that the unit tests for the object name service are about the same |
465 |
example, that the unit tests for the object name service are about the same |
| 437 |
size as the object name service code itself. Unit tests are tests that |
466 |
size as the object name service code itself. Unit tests are tests that |
| 438 |
check a single bit of functionality that are not built into the ns-3 code, |
467 |
check a single bit of functionality that are not built into the |ns3| code, |
| 439 |
but live in the same directory as the code it tests. It is possible that |
468 |
but live in the same directory as the code it tests. It is possible that |
| 440 |
these tests check integration of multiple implementation files in a module |
469 |
these tests check integration of multiple implementation files in a module |
| 441 |
as well. The file src/core/test/names-test-suite.cc is an example of this kind |
470 |
as well. The file src/core/test/names-test-suite.cc is an example of this kind |
|
|
| 451 |
but they are typically overloaded examples. We provide a new place |
480 |
but they are typically overloaded examples. We provide a new place |
| 452 |
for this kind of test in the directory ``src/test``. The file |
481 |
for this kind of test in the directory ``src/test``. The file |
| 453 |
src/test/ns3tcp/ns3-interop-test-suite.cc is an example of this kind of |
482 |
src/test/ns3tcp/ns3-interop-test-suite.cc is an example of this kind of |
| 454 |
test. It uses NSC TCP to test the ns-3 TCP implementation. Often there |
483 |
test. It uses NSC TCP to test the |ns3| TCP implementation. Often there |
| 455 |
will be test vectors required for this kind of test, and they are stored in |
484 |
will be test vectors required for this kind of test, and they are stored in |
| 456 |
the directory where the test lives. For example, |
485 |
the directory where the test lives. For example, |
| 457 |
ns3tcp-interop-response-vectors.pcap is a file consisting of a number of TCP |
486 |
ns3tcp-interop-response-vectors.pcap is a file consisting of a number of TCP |
| 458 |
headers that are used as the expected responses of the ns-3 TCP under test |
487 |
headers that are used as the expected responses of the |ns3| TCP under test |
| 459 |
to a stimulus generated by the NSC TCP which is used as a ''known good'' |
488 |
to a stimulus generated by the NSC TCP which is used as a ''known good'' |
| 460 |
implementation. |
489 |
implementation. |
| 461 |
|
490 |
|
|
|
| 492 |
|
521 |
|
| 493 |
$ ./waf --configure --enable-examples --enable-tests |
522 |
$ ./waf --configure --enable-examples --enable-tests |
| 494 |
|
523 |
|
| 495 |
Then, build ns-3, and after it is built, just run ``test.py``. ``test.py -h`` |
524 |
Then, build |ns3|, and after it is built, just run ``test.py``. ``test.py -h`` |
| 496 |
will show a number of configuration options that modify the behavior |
525 |
will show a number of configuration options that modify the behavior |
| 497 |
of test.py. |
526 |
of test.py. |
| 498 |
|
527 |
|
|
|
| 503 |
Debugging Tests |
532 |
Debugging Tests |
| 504 |
*************** |
533 |
*************** |
| 505 |
|
534 |
|
| 506 |
The debugging of the test programs is best performed running the low-level test-runner program. The test-runner is the bridge from generic Python code to |ns3| code. It is written in C++ and uses the automatic test discovery process in the |
535 |
The debugging of the test programs is best performed running the low-level |
| 507 |
|ns3| code to find and allow execution of all of the various tests. |
536 |
test-runner program. The test-runner is the bridge from generic Python |
|
|
537 |
code to |ns3| code. It is written in C++ and uses the automatic test |
| 538 |
discovery process in the |ns3| code to find and allow execution of all |
| 539 |
of the various tests. |
| 508 |
|
540 |
|
| 509 |
The main reason why ``test.py`` is not suitable for debugging is that it is not allowed for logging to be turned on using the ``NS_LOG`` environmental variable when test.py runs. This limitation does not apply to the test-runner executable. Hence, if you want to see logging output from your tests, you have to run them using the test-runner directly. |
541 |
The main reason why ``test.py`` is not suitable for debugging is that it is |
|
|
542 |
not allowed for logging to be turned on using the ``NS_LOG`` environmental |
| 543 |
variable when test.py runs. This limitation does not apply to the test-runner |
| 544 |
executable. Hence, if you want to see logging output from your tests, you |
| 545 |
have to run them using the test-runner directly. |
| 510 |
|
546 |
|
| 511 |
In order to execute the test-runner, you run it like any other ns-3 executable |
547 |
In order to execute the test-runner, you run it like any other |ns3| executable |
| 512 |
-- using ``waf``. To get a list of available options, you can type:: |
548 |
-- using ``waf``. To get a list of available options, you can type:: |
| 513 |
|
549 |
|
| 514 |
$ ./waf --run "test-runner --help" |
550 |
$ ./waf --run "test-runner --help" |
|
|
| 761 |
MyTestSuite::MyTestSuite () |
797 |
MyTestSuite::MyTestSuite () |
| 762 |
: TestSuite ("my-test-suite-name", UNIT) |
798 |
: TestSuite ("my-test-suite-name", UNIT) |
| 763 |
{ |
799 |
{ |
| 764 |
AddTestCase (new MyTestCase); |
800 |
AddTestCase (new MyTestCase, TestCase::QUICK); |
| 765 |
} |
801 |
} |
| 766 |
|
802 |
|
| 767 |
MyTestSuite myTestSuite; |
803 |
MyTestSuite myTestSuite; |