Skip to content

Commit 31c2611

Browse files
mishuang2017davem330
authored andcommitted
selftests: Introduce a new test case to tc testsuite
In this patchset, we fixed a tc bug. This patch adds the test case that reproduces the bug. To run this test case, user should specify an existing NIC device: # sudo ./tdc.py -d enp4s0f0 This test case belongs to category "flower". If user doesn't specify a NIC device, the test cases belong to "flower" will not be run. In this test case, we create 1M filters and all filters share the same action. When destroying all filters, kernel should not panic. It takes about 18s to run it. Acked-by: Jamal Hadi Salim <[email protected]> Acked-by: Lucas Bates <[email protected]> Signed-off-by: Chris Mi <[email protected]> Signed-off-by: Cong Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7f07199 commit 31c2611

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

tools/testing/selftests/tc-testing/tc-tests/filters/tests.json

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,26 @@
1717
"teardown": [
1818
"$TC qdisc del dev $DEV1 ingress"
1919
]
20+
},
21+
{
22+
"id": "d052",
23+
"name": "Add 1M filters with the same action",
24+
"category": [
25+
"filter",
26+
"flower"
27+
],
28+
"setup": [
29+
"$TC qdisc add dev $DEV2 ingress",
30+
"./tdc_batch.py $DEV2 $BATCH_FILE --share_action -n 1000000"
31+
],
32+
"cmdUnderTest": "$TC -b $BATCH_FILE",
33+
"expExitCode": "0",
34+
"verifyCmd": "$TC actions list action gact",
35+
"matchPattern": "action order 0: gact action drop.*index 1 ref 1000000 bind 1000000",
36+
"matchCount": "1",
37+
"teardown": [
38+
"$TC qdisc del dev $DEV2 ingress",
39+
"/bin/rm $BATCH_FILE"
40+
]
2041
}
21-
]
42+
]

tools/testing/selftests/tc-testing/tdc.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def prepare_env(cmdlist):
8888
exit(1)
8989

9090

91-
def test_runner(filtered_tests):
91+
def test_runner(filtered_tests, args):
9292
"""
9393
Driver function for the unit tests.
9494
@@ -105,6 +105,8 @@ def test_runner(filtered_tests):
105105
for tidx in testlist:
106106
result = True
107107
tresult = ""
108+
if "flower" in tidx["category"] and args.device == None:
109+
continue
108110
print("Test " + tidx["id"] + ": " + tidx["name"])
109111
prepare_env(tidx["setup"])
110112
(p, procout) = exec_cmd(tidx["cmdUnderTest"])
@@ -152,6 +154,10 @@ def ns_create():
152154
exec_cmd(cmd, False)
153155
cmd = 'ip -s $NS link set $DEV1 up'
154156
exec_cmd(cmd, False)
157+
cmd = 'ip link set $DEV2 netns $NS'
158+
exec_cmd(cmd, False)
159+
cmd = 'ip -s $NS link set $DEV2 up'
160+
exec_cmd(cmd, False)
155161

156162

157163
def ns_destroy():
@@ -211,7 +217,8 @@ def set_args(parser):
211217
help='Execute the single test case with specified ID')
212218
parser.add_argument('-i', '--id', action='store_true', dest='gen_id',
213219
help='Generate ID numbers for new test cases')
214-
return parser
220+
parser.add_argument('-d', '--device',
221+
help='Execute the test case in flower category')
215222
return parser
216223

217224

@@ -225,6 +232,8 @@ def check_default_settings(args):
225232

226233
if args.path != None:
227234
NAMES['TC'] = args.path
235+
if args.device != None:
236+
NAMES['DEV2'] = args.device
228237
if not os.path.isfile(NAMES['TC']):
229238
print("The specified tc path " + NAMES['TC'] + " does not exist.")
230239
exit(1)
@@ -381,14 +390,17 @@ def set_operation_mode(args):
381390
if (len(alltests) == 0):
382391
print("Cannot find a test case with ID matching " + target_id)
383392
exit(1)
384-
catresults = test_runner(alltests)
393+
catresults = test_runner(alltests, args)
385394
print("All test results: " + "\n\n" + catresults)
386395
elif (len(target_category) > 0):
396+
if (target_category == "flower") and args.device == None:
397+
print("Please specify a NIC device (-d) to run category flower")
398+
exit(1)
387399
if (target_category not in ucat):
388400
print("Specified category is not present in this file.")
389401
exit(1)
390402
else:
391-
catresults = test_runner(testcases[target_category])
403+
catresults = test_runner(testcases[target_category], args)
392404
print("Category " + target_category + "\n\n" + catresults)
393405

394406
ns_destroy()

tools/testing/selftests/tc-testing/tdc_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# Name of veth devices to be created for the namespace
1313
'DEV0': 'v0p0',
1414
'DEV1': 'v0p1',
15+
'DEV2': '',
16+
'BATCH_FILE': './batch.txt',
1517
# Name of the namespace to use
1618
'NS': 'tcut'
1719
}

0 commit comments

Comments
 (0)