···14141515* The kernel must have network namespace support16161717-* The kernel must have veth support available, as a veth pair is created1717+* The kernel must have veth support available, as a veth pair is created1818 prior to running the tests.19192020-* All tc-related features must be built in or available as modules.2121- To check what is required in current setup run:2020+* All tc-related features being tested must be built in or available as2121+ modules. To check what is required in current setup run:2222 ./tdc.py -c23232424 Note:···4444RUNNING TDC4545-----------46464747-To use tdc, root privileges are required. tdc will not run otherwise.4747+To use tdc, root privileges are required. This is because the4848+commands being tested must be run as root. The code that enforces4949+execution by root uid has been moved into a plugin (see PLUGIN5050+ARCHITECTURE, below).48514949-All tests are executed inside a network namespace to prevent conflicts5050-within the host.5252+If nsPlugin is linked, all tests are executed inside a network5353+namespace to prevent conflicts within the host.51545255Running tdc without any arguments will run all tests. Refer to the section5356on command line arguments for more information, or run:···6057TAP (Test Anything Protocol) format when they are done. If tests fail,6158output captured from the failing test will be printed immediately following6259the failed test in the TAP output.6060+6161+6262+OVERVIEW OF TDC EXECUTION6363+-------------------------6464+6565+One run of tests is considered a "test suite" (this will be refined in the6666+future). A test suite has one or more test cases in it.6767+6868+A test case has four stages:6969+7070+ - setup7171+ - execute7272+ - verify7373+ - teardown7474+7575+The setup and teardown stages can run zero or more commands. The setup7676+stage does some setup if the test needs it. The teardown stage undoes7777+the setup and returns the system to a "neutral" state so any other test7878+can be run next. These two stages require any commands run to return7979+success, but do not otherwise verify the results.8080+8181+The execute and verify stages each run one command. The execute stage8282+tests the return code against one or more acceptable values. The8383+verify stage checks the return code for success, and also compares8484+the stdout with a regular expression.8585+8686+Each of the commands in any stage will run in a shell instance.638764886589USER-DEFINED CONSTANTS···10070Example:10171 $TC qdisc add dev $DEV1 ingress102727373+The NAMES values are used to substitute into the commands in the test cases.7474+1037510476COMMAND LINE ARGUMENTS10577----------------------1067810779Run tdc.py -h to see the full list of available arguments.10880109109--p PATH Specify the tc executable located at PATH to be used on this110110- test run111111--c Show the available test case categories in this test file112112--c CATEGORY Run only tests that belong to CATEGORY113113--f FILE Read test cases from the JSON file named FILE114114--l [CATEGORY] List all test cases in the JSON file. If CATEGORY is115115- specified, list test cases matching that category.116116--s ID Show the test case matching ID117117--e ID Execute the test case identified by ID118118--i Generate unique ID numbers for test cases with no existing119119- ID number8181+usage: tdc.py [-h] [-p PATH] [-D DIR [DIR ...]] [-f FILE [FILE ...]]8282+ [-c [CATG [CATG ...]]] [-e ID [ID ...]] [-l] [-s] [-i] [-v]8383+ [-d DEVICE] [-n NS] [-V]8484+8585+Linux TC unit tests8686+8787+optional arguments:8888+ -h, --help show this help message and exit8989+ -p PATH, --path PATH The full path to the tc executable to use9090+ -v, --verbose Show the commands that are being run9191+ -d DEVICE, --device DEVICE9292+ Execute the test case in flower category9393+9494+selection:9595+ select which test cases: files plus directories; filtered by categories9696+ plus testids9797+9898+ -D DIR [DIR ...], --directory DIR [DIR ...]9999+ Collect tests from the specified directory(ies)100100+ (default [tc-tests])101101+ -f FILE [FILE ...], --file FILE [FILE ...]102102+ Run tests from the specified file(s)103103+ -c [CATG [CATG ...]], --category [CATG [CATG ...]]104104+ Run tests only from the specified category/ies, or if105105+ no category/ies is/are specified, list known106106+ categories.107107+ -e ID [ID ...], --execute ID [ID ...]108108+ Execute the specified test cases with specified IDs109109+110110+action:111111+ select action to perform on selected test cases112112+113113+ -l, --list List all test cases, or those only within the114114+ specified category115115+ -s, --show Display the selected test cases116116+ -i, --id Generate ID numbers for new test cases117117+118118+netns:119119+ options for nsPlugin(run commands in net namespace)120120+121121+ -n NS, --namespace NS122122+ Run commands in namespace NS123123+124124+valgrind:125125+ options for valgrindPlugin (run command under test under Valgrind)126126+127127+ -V, --valgrind Run commands under valgrind128128+129129+130130+PLUGIN ARCHITECTURE131131+-------------------132132+133133+There is now a plugin architecture, and some of the functionality that134134+was in the tdc.py script has been moved into the plugins.135135+136136+The plugins are in the directory plugin-lib. The are executed from137137+directory plugins. Put symbolic links from plugins to plugin-lib,138138+and name them according to the order you want them to run.139139+140140+Example:141141+142142+bjb@bee:~/work/tc-testing$ ls -l plugins143143+total 4144144+lrwxrwxrwx 1 bjb bjb 27 Oct 4 16:12 10-rootPlugin.py -> ../plugin-lib/rootPlugin.py145145+lrwxrwxrwx 1 bjb bjb 25 Oct 12 17:55 20-nsPlugin.py -> ../plugin-lib/nsPlugin.py146146+-rwxr-xr-x 1 bjb bjb 0 Sep 29 15:56 __init__.py147147+148148+The plugins are a subclass of TdcPlugin, defined in TdcPlugin.py and149149+must be called "SubPlugin" so tdc can find them. They are150150+distinguished from each other in the python program by their module151151+name.152152+153153+This base class supplies "hooks" to run extra functions. These hooks are as follows:154154+155155+pre- and post-suite156156+pre- and post-case157157+pre- and post-execute stage158158+adjust-command (runs in all stages and receives the stage name)159159+160160+The pre-suite hook receives the number of tests and an array of test ids.161161+This allows you to dump out the list of skipped tests in the event of a162162+failure during setup or teardown stage.163163+164164+The pre-case hook receives the ordinal number and test id of the current test.165165+166166+The adjust-command hook receives the stage id (see list below) and the167167+full command to be executed. This allows for last-minute adjustment168168+of the command.169169+170170+The stages are identified by the following strings:171171+172172+ - pre (pre-suite)173173+ - setup174174+ - command175175+ - verify176176+ - teardown177177+ - post (post-suite)178178+179179+180180+To write a plugin, you need to inherit from TdcPlugin in181181+TdcPlugin.py. To use the plugin, you have to put the182182+implementation file in plugin-lib, and add a symbolic link to it from183183+plugins. It will be detected at run time and invoked at the184184+appropriate times. There are a few examples in the plugin-lib185185+directory:186186+187187+ - rootPlugin.py:188188+ implements the enforcement of running as root189189+ - nsPlugin.py:190190+ sets up a network namespace and runs all commands in that namespace191191+ - valgrindPlugin.py192192+ runs each command in the execute stage under valgrind,193193+ and checks for leaks.194194+ This plugin will output an extra test for each test in the test file,195195+ one is the existing output as to whether the test passed or failed,196196+ and the other is a test whether the command leaked memory or not.197197+ (This one is a preliminary version, it may not work quite right yet,198198+ but the overall template is there and it should only need tweaks.)120199121200122201ACKNOWLEDGEMENTS
+23-2
tools/testing/selftests/tc-testing/TODO.txt
···5566- Add support for multiple versions of tc to run successively7788-- Improve error messages when tdc aborts its run88+- Improve error messages when tdc aborts its run. Partially done - still99+ need to better handle problems in pre- and post-suite.9101010-- Allow tdc to write its results to file1111+- Use python logger module for debug/verbose output1212+1313+- Allow tdc to write its results to file.1414+ Maybe use python logger module for this too.1515+1616+- A better implementation of the "hooks". Currently, every plugin1717+ will attempt to run a function at every hook point. Could be1818+ changed so that plugin __init__ methods will register functions to1919+ be run in the various predefined times. Then if a plugin does not2020+ require action at a specific point, no penalty will be paid for2121+ trying to run a function that will do nothing.2222+2323+- Proper exception handling - make an exception class and use it2424+2525+- a TestCase class, for easier testcase handling, searching, comparison2626+2727+- a TestSuite class2828+ and a way to configure a test suite,2929+ to automate running multiple "test suites" with different requirements3030+3131+- super simple test case example using ls, touch, etc