View | Details | Raw Unified | Return to bug 2105
Collapse All | Expand All

(-)a/doc/manual/source/test-framework.rst (-17 / +52 lines)
 Lines 4-10    Link Here 
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
 Lines 17-23    Link Here 
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
 Lines 120-125    Link Here 
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
 Lines 307-313    Link Here 
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
::
 Lines 329-335    Link Here 
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 
 Lines 399-405    Link Here 
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 
 Lines 417-430    Link Here 
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
where EXTENSIVE includes QUICK and TAKES_FOREVER includes QUICK and EXTENSIVE
439
(only QUICK tests are run by default).
440
441
As a rule of thumb, tests that must be run to ensure |ns3| coherence should be
442
QUICK (i.e., take a few seconds). Tests that could be skipped, but are nice to do
443
can be EXTENSIVE: these are tests that typically needs minutes. TAKES_FOREVER is
444
left for test that takes really slow: in the order of several minutes.
445
The main classification goal is to be able to run the buildbots in a reasonable
446
time, and still be able to perform more extensive tests when needed.
447
420
BuildVerificationTests
448
BuildVerificationTests
421
++++++++++++++++++++++
449
++++++++++++++++++++++
422
450
423
These are relatively simple tests that are built along with the distribution
451
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
452
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
453
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
454
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
455
in the same source code that is built into the |ns3| code.  Our current tests
428
are examples of this kind of test.
456
are examples of this kind of test.
429
457
430
Unit Tests
458
Unit Tests
 Lines 432-441    Link Here 
432
460
433
Unit tests are more involved tests that go into detail to make sure that a
461
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
462
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
463
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
464
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
465
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,
466
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
467
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
468
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
469
as well.  The file src/core/test/names-test-suite.cc is an example of this kind
 Lines 451-461    Link Here 
451
but they are typically overloaded examples.  We provide a new place 
479
but they are typically overloaded examples.  We provide a new place 
452
for this kind of test in the directory ``src/test``.  The file
480
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
481
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
482
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
483
will be test vectors required for this kind of test, and they are stored in
456
the directory where the test lives.  For example,
484
the directory where the test lives.  For example,
457
ns3tcp-interop-response-vectors.pcap is a file consisting of a number of TCP
485
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
486
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''
487
to a stimulus generated by the NSC TCP which is used as a ''known good''
460
implementation.
488
implementation.
461
489
 Lines 492-498    Link Here 
492
520
493
   $ ./waf --configure --enable-examples --enable-tests
521
   $ ./waf --configure --enable-examples --enable-tests
494
522
495
Then, build ns-3, and after it is built, just run ``test.py``.  ``test.py -h``
523
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
524
will show a number of configuration options that modify the behavior
497
of test.py.
525
of test.py.
498
526
 Lines 503-514    Link Here 
503
Debugging Tests
531
Debugging Tests
504
***************
532
***************
505
533
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 
534
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.
535
test-runner program. The test-runner is the bridge from generic Python 
536
code to |ns3| code. It is written in C++ and uses the automatic test 
537
discovery process in the |ns3| code to find and allow execution of all 
538
of the various tests.
508
539
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.
540
The main reason why ``test.py`` is not suitable for debugging is that it is 
541
not allowed for logging to be turned on using the ``NS_LOG`` environmental 
542
variable when test.py runs.  This limitation does not apply to the test-runner 
543
executable. Hence, if you want to see logging output from your tests, you 
544
have to run them using the test-runner directly.
510
545
511
In order to execute the test-runner, you run it like any other ns-3 executable
546
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::
547
-- using ``waf``.  To get a list of available options, you can type::
513
548
514
  $ ./waf --run "test-runner --help"
549
  $ ./waf --run "test-runner --help"
 Lines 761-767    Link Here 
761
  MyTestSuite::MyTestSuite ()
796
  MyTestSuite::MyTestSuite ()
762
    : TestSuite ("my-test-suite-name", UNIT)
797
    : TestSuite ("my-test-suite-name", UNIT)
763
  {
798
  {
764
    AddTestCase (new MyTestCase);
799
    AddTestCase (new MyTestCase, TestCase::QUICK);
765
  }
800
  }
766
  
801
  
767
  MyTestSuite myTestSuite;
802
  MyTestSuite myTestSuite;

Return to bug 2105