1*76b903eeSLucas Batestdc - Linux Traffic Control (tc) unit testing suite 2*76b903eeSLucas Bates 3*76b903eeSLucas BatesAuthor: Lucas Bates - [email protected] 4*76b903eeSLucas Bates 5*76b903eeSLucas Batestdc is a Python script to load tc unit tests from a separate JSON file and 6*76b903eeSLucas Batesexecute them inside a network namespace dedicated to the task. 7*76b903eeSLucas Bates 8*76b903eeSLucas Bates 9*76b903eeSLucas BatesREQUIREMENTS 10*76b903eeSLucas Bates------------ 11*76b903eeSLucas Bates 12*76b903eeSLucas Bates* Minimum Python version of 3.4. Earlier 3.X versions may work but are not 13*76b903eeSLucas Bates guaranteed. 14*76b903eeSLucas Bates 15*76b903eeSLucas Bates* The kernel must have network namespace support 16*76b903eeSLucas Bates 17*76b903eeSLucas Bates* The kernel must have veth support available, as a veth pair is created 18*76b903eeSLucas Bates prior to running the tests. 19*76b903eeSLucas Bates 20*76b903eeSLucas Bates* All tc-related features must be built in or available as modules. 21*76b903eeSLucas Bates To check what is required in current setup run: 22*76b903eeSLucas Bates ./tdc.py -c 23*76b903eeSLucas Bates 24*76b903eeSLucas Bates Note: 25*76b903eeSLucas Bates In the current release, tdc run will abort due to a failure in setup or 26*76b903eeSLucas Bates teardown commands - which includes not being able to run a test simply 27*76b903eeSLucas Bates because the kernel did not support a specific feature. (This will be 28*76b903eeSLucas Bates handled in a future version - the current workaround is to run the tests 29*76b903eeSLucas Bates on specific test categories that your kernel supports) 30*76b903eeSLucas Bates 31*76b903eeSLucas Bates 32*76b903eeSLucas BatesBEFORE YOU RUN 33*76b903eeSLucas Bates-------------- 34*76b903eeSLucas Bates 35*76b903eeSLucas BatesThe path to the tc executable that will be most commonly tested can be defined 36*76b903eeSLucas Batesin the tdc_config.py file. Find the 'TC' entry in the NAMES dictionary and 37*76b903eeSLucas Batesdefine the path. 38*76b903eeSLucas Bates 39*76b903eeSLucas BatesIf you need to test a different tc executable on the fly, you can do so by 40*76b903eeSLucas Batesusing the -p option when running tdc: 41*76b903eeSLucas Bates ./tdc.py -p /path/to/tc 42*76b903eeSLucas Bates 43*76b903eeSLucas Bates 44*76b903eeSLucas BatesRUNNING TDC 45*76b903eeSLucas Bates----------- 46*76b903eeSLucas Bates 47*76b903eeSLucas BatesTo use tdc, root privileges are required. tdc will not run otherwise. 48*76b903eeSLucas Bates 49*76b903eeSLucas BatesAll tests are executed inside a network namespace to prevent conflicts 50*76b903eeSLucas Bateswithin the host. 51*76b903eeSLucas Bates 52*76b903eeSLucas BatesRunning tdc without any arguments will run all tests. Refer to the section 53*76b903eeSLucas Bateson command line arguments for more information, or run: 54*76b903eeSLucas Bates ./tdc.py -h 55*76b903eeSLucas Bates 56*76b903eeSLucas Batestdc will list the test names as they are being run, and print a summary in 57*76b903eeSLucas BatesTAP (Test Anything Protocol) format when they are done. If tests fail, 58*76b903eeSLucas Batesoutput captured from the failing test will be printed immediately following 59*76b903eeSLucas Batesthe failed test in the TAP output. 60*76b903eeSLucas Bates 61*76b903eeSLucas Bates 62*76b903eeSLucas BatesUSER-DEFINED CONSTANTS 63*76b903eeSLucas Bates---------------------- 64*76b903eeSLucas Bates 65*76b903eeSLucas BatesThe tdc_config.py file contains multiple values that can be altered to suit 66*76b903eeSLucas Batesyour needs. Any value in the NAMES dictionary can be altered without affecting 67*76b903eeSLucas Batesthe tests to be run. These values are used in the tc commands that will be 68*76b903eeSLucas Batesexecuted as part of the test. More will be added as test cases require. 69*76b903eeSLucas Bates 70*76b903eeSLucas BatesExample: 71*76b903eeSLucas Bates $TC qdisc add dev $DEV1 ingress 72*76b903eeSLucas Bates 73*76b903eeSLucas Bates 74*76b903eeSLucas BatesCOMMAND LINE ARGUMENTS 75*76b903eeSLucas Bates---------------------- 76*76b903eeSLucas Bates 77*76b903eeSLucas BatesRun tdc.py -h to see the full list of available arguments. 78*76b903eeSLucas Bates 79*76b903eeSLucas Bates-p PATH Specify the tc executable located at PATH to be used on this 80*76b903eeSLucas Bates test run 81*76b903eeSLucas Bates-c Show the available test case categories in this test file 82*76b903eeSLucas Bates-c CATEGORY Run only tests that belong to CATEGORY 83*76b903eeSLucas Bates-f FILE Read test cases from the JSON file named FILE 84*76b903eeSLucas Bates-l [CATEGORY] List all test cases in the JSON file. If CATEGORY is 85*76b903eeSLucas Bates specified, list test cases matching that category. 86*76b903eeSLucas Bates-s ID Show the test case matching ID 87*76b903eeSLucas Bates-e ID Execute the test case identified by ID 88*76b903eeSLucas Bates-i Generate unique ID numbers for test cases with no existing 89*76b903eeSLucas Bates ID number 90*76b903eeSLucas Bates 91*76b903eeSLucas Bates 92*76b903eeSLucas BatesACKNOWLEDGEMENTS 93*76b903eeSLucas Bates---------------- 94*76b903eeSLucas Bates 95*76b903eeSLucas BatesThanks to: 96*76b903eeSLucas Bates 97*76b903eeSLucas BatesJamal Hadi Salim, for providing valuable test cases 98*76b903eeSLucas BatesKeara Leibovitz, who wrote the CLI test driver that I used as a base for the 99*76b903eeSLucas Bates first version of the tc testing suite. This work was presented at 100*76b903eeSLucas Bates Netdev 1.2 Tokyo in October 2016. 101*76b903eeSLucas BatesSamir Hussain, for providing help while I dove into Python for the first time 102*76b903eeSLucas Bates and being a second eye for this code. 103