e127fb2eb3fe5813c09765d4ebc9b143862d2333
[dpdk.git] / app / test-bbdev / test-bbdev.py
1 #!/usr/bin/env python
2
3 # SPDX-License-Identifier: BSD-3-Clause
4 # Copyright(c) 2017 Intel Corporation
5
6 from __future__ import print_function
7 import sys
8 import os
9 import argparse
10 import subprocess
11 import shlex
12
13 from threading import Timer
14
15 def kill(process):
16     print("ERROR: Test app timed out")
17     process.kill()
18
19 if "RTE_SDK" in os.environ:
20     dpdk_path = os.environ["RTE_SDK"]
21 else:
22     dpdk_path = "../.."
23
24 if "RTE_TARGET" in os.environ:
25     dpdk_target = os.environ["RTE_TARGET"]
26 else:
27     dpdk_target = "x86_64-native-linux-gcc"
28
29 parser = argparse.ArgumentParser(
30                     description='BBdev Unit Test Application',
31                     formatter_class=argparse.ArgumentDefaultsHelpFormatter)
32 parser.add_argument("-p", "--testapp-path",
33                     help="specifies path to the bbdev test app",
34                     default=dpdk_path + "/" + dpdk_target + "/app/testbbdev")
35 parser.add_argument("-e", "--eal-params",
36                     help="EAL arguments which are passed to the test app",
37                     default="--vdev=baseband_null0")
38 parser.add_argument("-t", "--timeout",
39                     type=int,
40                     help="Timeout in seconds",
41                     default=300)
42 parser.add_argument("-c", "--test-cases",
43                     nargs="+",
44                     help="Defines test cases to run. Run all if not specified")
45 parser.add_argument("-v", "--test-vector",
46                     nargs="+",
47                     help="Specifies paths to the test vector files.",
48                     default=[dpdk_path +
49                     "/app/test-bbdev/test_vectors/bbdev_null.data"])
50 parser.add_argument("-n", "--num-ops",
51                     type=int,
52                     help="Number of operations to process on device.",
53                     default=32)
54 parser.add_argument("-b", "--burst-size",
55                     nargs="+",
56                     type=int,
57                     help="Operations enqueue/dequeue burst size.",
58                     default=[32])
59 parser.add_argument("-l", "--num-lcores",
60                     type=int,
61                     help="Number of lcores to run.",
62                     default=16)
63 parser.add_argument("-i", "--init-device",
64                     action='store_true',
65                     help="Initialise PF device with default values.")
66
67 args = parser.parse_args()
68
69 if not os.path.exists(args.testapp_path):
70     print("No such file: " + args.testapp_path)
71     sys.exit(1)
72
73 params = [args.testapp_path]
74 if args.eal_params:
75     params.extend(shlex.split(args.eal_params))
76
77 params.extend(["--"])
78
79 if args.num_ops:
80     params.extend(["-n", str(args.num_ops)])
81
82 if args.num_lcores:
83     params.extend(["-l", str(args.num_lcores)])
84
85 if args.test_cases:
86     params.extend(["-c"])
87     params.extend([",".join(args.test_cases)])
88
89 if args.init_device:
90     params.extend(["-i"])
91
92
93 exit_status = 0
94 for vector in args.test_vector:
95     for burst_size in args.burst_size:
96         call_params = params[:]
97         call_params.extend(["-v", vector])
98         call_params.extend(["-b", str(burst_size)])
99         params_string = " ".join(call_params)
100
101         print("Executing: {}".format(params_string))
102         app_proc = subprocess.Popen(call_params)
103         if args.timeout > 0:
104             timer = Timer(args.timeout, kill, [app_proc])
105             timer.start()
106
107         try:
108             app_proc.communicate()
109         except:
110             print("Error: failed to execute: {}".format(params_string))
111         finally:
112             timer.cancel()
113
114         if app_proc.returncode != 0:
115             exit_status = 1
116             print("ERROR TestCase failed. Failed test for vector {}. Return code: {}".format(
117                 vector, app_proc.returncode))
118
119 sys.exit(exit_status)