$ ./waf configure --enable-examples --enable-tests
$ ./waf build
$ ./test.py
Waf: Entering directory '/home/craigdo/repos/ns-3-allinone-test/ns-3-dev/build' Waf: Leaving directory '/home/craigdo/repos/ns-3-allinone-test/ns-3-dev/build' 'build' finished successfully (0.939s) FAIL: TestSuite propagation-loss-model PASS: TestSuite object-name-service PASS: TestSuite pcap-file-object PASS: TestSuite ns3-tcp-cwnd ... PASS: TestSuite ns3-tcp-interoperability PASS: Example csma-broadcast PASS: Example csma-multicast
Usage: test.py [options] Options: -h, --help show this help message and exit -b BUILDPATH, --buildpath=BUILDPATH specify the path where ns-3 was built (defaults to the build directory for the current variant) -c KIND, --constrain=KIND constrain the test-runner by kind of test -e EXAMPLE, --example=EXAMPLE specify a single example to run (no relative path is needed) -d, --duration print the duration of each test suite and example -e EXAMPLE, --example=EXAMPLE specify a single example to run (no relative path is needed) -u, --update-data If examples use reference data files, get them to re- generate them -f FULLNESS, --fullness=FULLNESS choose the duration of tests to run: QUICK, EXTENSIVE, or TAKES_FOREVER, where EXTENSIVE includes QUICK and TAKES_FOREVER includes QUICK and EXTENSIVE (only QUICK tests are run by default) -g, --grind run the test suites and examples using valgrind -k, --kinds print the kinds of tests available -l, --list print the list of known tests -m, --multiple report multiple failures from test suites and test cases -n, --nowaf do not run waf before starting testing -p PYEXAMPLE, --pyexample=PYEXAMPLE specify a single python example to run (with relative path) -r, --retain retain all temporary files (which are normally deleted) -s TEST-SUITE, --suite=TEST-SUITE specify a single test suite to run -t TEXT-FILE, --text=TEXT-FILE write detailed test results into TEXT-FILE.txt -v, --verbose print progress and informational messages -w HTML-FILE, --web=HTML-FILE, --html=HTML-FILE write detailed test results into HTML-FILE.html -x XML-FILE, --xml=XML-FILE write detailed test results into XML-FILE.xml
若是指定可選的輸出方式,能夠生成詳細的測試和狀態描述。可選的樣式有 text 和 HTML 。buildbots 選擇 HTML 方式生成 HTML 測試報告用於 nightly builds :html
$ ./test.py --html=nightly.html
$ ./test.py --text=results.txt
$ ./test.py --suite=propagation-loss-model
或者等價於python
$ ./test.py -s propagation-loss-model
結果是單個 test suite 正在運行。linux
FAIL: TestSuite propagation-loss-model
$ ./test.py --suite=propagation-loss-model --text=results.txt
FAIL: Test Suite ''propagation-loss-model'' (real 0.02 user 0.01 system 0.00) PASS: Test Case "Check ... Friis ... model ..." (real 0.01 user 0.00 system 0.00) FAIL: Test Case "Check ... Log Distance ... model" (real 0.01 user 0.01 system 0.00) Details: Message: Got unexpected SNR value Condition: [long description of what actually failed] Actual: 176.395 Limit: 176.407 +- 0.0005 File: ../src/test/ns3wifi/propagation-loss-models-test-suite.cc Line: 360
$ ./test.py --constrain=unit
類似地,下列命令會致使只有 example smoke tests 運行:web
$ ./test.py --constrain=unit
爲了快速看到合法的約束列表,你能夠要求它們列舉出來。下使用列代碼:redis
$ ./test.py --kinds
Waf: Entering directory '/home/craigdo/repos/ns-3-allinone-test/ns-3-dev/build' Waf: Leaving directory '/home/craigdo/repos/ns-3-allinone-test/ns-3-dev/build' 'build' finished successfully (0.939s)Waf: Entering directory '/home/craigdo/repos/ns-3-allinone-test/ns-3-dev/build' bvt: Build Verification Tests (to see if build completed successfully) core: Run all TestSuite-based tests (exclude examples) example: Examples (to see if example programs run successfully) performance: Performance Tests (check to see if the system is as fast as expected) system: System Tests (spans modules to check integration of modules) unit: Unit Tests (within modules to check basic functionality)
$ ./test.py --list
Waf: Entering directory `/home/craigdo/repos/ns-3-allinone-test/ns-3-dev/build' Waf: Leaving directory `/home/craigdo/repos/ns-3-allinone-test/ns-3-dev/build' 'build' finished successfully (0.939s) Test Type Test Name --------- --------- performance many-uniform-random-variables-one-get-value-call performance one-uniform-random-variable-many-get-value-calls performance type-id-perf system buildings-pathloss-test system buildings-shadowing-test system devices-mesh-dot11s-regression system devices-mesh-flame-regression system epc-gtpu ... unit wimax-phy-layer unit wimax-service-flow unit wimax-ss-mac-layer unit wimax-tlv example adhoc-aloha-ideal-phy example adhoc-aloha-ideal-phy-matrix-propagation-loss-model example adhoc-aloha-ideal-phy-with-microwave-oven example aodv ...
$ ./test.py --example=udp-echo
PASS: Example examples/udp/udp-echo
$ ./test.py --buildpath=/home/craigdo/repos/ns-3-allinone-test/ns-3-dev/build/debug --example=wifi-simple-adhoc
$ ./test.py --pyexample=examples/tutorial/first.py
會致使單個 example 運行,shell
PASS: Example examples/tutorial/first.py
$ ./test.py --list --nowaf
將會致使顯示當前已經編譯的 test suites ,相似於:app
propagation-loss-model ns3-tcp-cwnd ns3-tcp-interoperability pcap-file object-name-service random-variable-stream-generators
$ ./test.py --grind
$ ./test.py --retain
$ ./test.py --verbose
$ ./test.py --verbose --grind --constrain=core --html=results.html
(3d)Examples框架
$ ./waf --configure --enable-examples --enable-tests
$ ./waf --run "test-runner --help"
你會看到相似下面的輸出:dom
Usage: /home/craigdo/repos/ns-3-allinone-test/ns-3-dev/build/utils/ns3-dev-test-runner-debug [OPTIONS] Options: --help : print these options --print-test-name-list : print the list of names of tests available --list : an alias for --print-test-name-list --print-test-types : print the type of tests along with their names --print-test-type-list : print the list of types of tests available --print-temp-dir : print name of temporary directory before running the tests --test-type=TYPE : process only tests of type TYPE --test-name=NAME : process only test whose name matches NAME --suite=NAME : an alias (here for compatibility reasons only) for --test-name=NAME --assert-on-failure : when a test fails, crash immediately (useful when running under a debugger --stop-on-failure : when a test fails, stop immediately --fullness=FULLNESS : choose the duration of tests to run: QUICK, EXTENSIVE, or TAKES_FOREVER, where EXTENSIVE includes QUICK and TAKES_FOREVER includes QUICK and EXTENSIVE (only QUICK tests are run by default) --verbose : print details of test execution --xml : format test run output as xml --tempdir=DIR : set temp dir for tests to store output files --datadir=DIR : set data dir for tests to read reference files --out=FILE : send test result to FILE instead of standard output --append=FILE : append test result to FILE instead of standard output
$ ./waf shell $ cd build/utils $ gdb ns3-dev-test-runner-debug $ run --suite=global-value --assert-on-failure
$ ./waf --run "test-runner --suite=pcap-file"
$ NS_LOG="Packet" ./waf -- run "test-runner -- suite=pcap-file"
例如,對 「lte-test-rr-ff-mac-scheduler.cc」 添加日誌功能,能夠獲取相關的吞吐量信息,使用相似上述的命令:tcp
$ NS_LOG="LenaTestRrFfMacScheduler" ./waf --run "test-runner --suite=lte-rr-ff-mac-scheduler" >& log5.out
能夠在 log5.out 中查看有用的日誌信息,部分截圖以下:
(5a)Test output(測試輸出)
/tmp/ns-3.10.25.37.61537845
$ ./test.py -r
(5b)Reporting of test failures(上報測試失敗)
$ ./waf --run "test-runner --suite=pcap-file --out=myfile.txt"
(5c)Debugging test suite failures
CRASH: TestSuite ns3-wifi-interference
$ ./waf --command-template="gdb %s" --run "test-runner" Waf: Entering directory `/home/tomh/hg/sep09/ns-3-allinone/ns-3-dev-678/build'Waf: Leaving directory `/home/tomh/hg/sep09/ns-3-allinone/ns-3-dev-678/build''build' finished successfully (0.380s) GNU gdb 6.8-debian Copyright (C) 2008 Free Software Foundation, Inc. L cense GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu"... (gdb) r --suite= Starting program: <..>/build/utils/ns3-dev-test-runner-debug --suite=ns3-wifi-interference [Thread debugging using libthread_db enabled] assert failed. file=../src/core/model/type-id.cc, line=138, cond="uid <= m_information.size () && uid != 0" ...
這裏還有另一個例子教你如何使用 valgrind 調試內存問題,例如:
VALGR: TestSuite devices-mesh-dot11s-regression $ ./waf --command-template="valgrind %s --suite=devices-mesh-dot11s-regression" --run test-runner
class MySuite : public TestSuite { public: MyTestSuite (); }; MyTestSuite::MyTestSuite () : TestSuite ("my-test-suite-name", UNIT) { AddTestCase (new MyTestCase, TestCase::QUICK); }
static MyTestSuite myTestSuite;
class MyTestCase : public TestCase{ MyTestCase (); virtual void DoSetup (void); virtual void DoRun (void);}; MyTestCase::MyTestCase () : TestCase ("Check some bit of functionality"){} voidMyTestCase::DoRun (void){ NS_TEST_ASSERT_MSG_EQ (true, true, "Some failure message");}