add python2 deprecation notice
[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 sys.version_info.major < 3:
20     print("WARNING: Python 2 is deprecated for use in DPDK, and will not work in future releases.", file=sys.stderr)
21     print("Please use Python 3 instead", file=sys.stderr)
22
23 if "RTE_SDK" in os.environ:
24     dpdk_path = os.environ["RTE_SDK"]
25 else:
26     dpdk_path = "../.."
27
28 if "RTE_TARGET" in os.environ:
29     dpdk_target = os.environ["RTE_TARGET"]
30 else:
31     dpdk_target = "x86_64-native-linux-gcc"
32
33 parser = argparse.ArgumentParser(
34                     description='BBdev Unit Test Application',
35                     formatter_class=argparse.ArgumentDefaultsHelpFormatter)
36 parser.add_argument("-p", "--testapp-path",
37                     help="specifies path to the bbdev test app",
38                     default=dpdk_path + "/" + dpdk_target + "/app/testbbdev")
39 parser.add_argument("-e", "--eal-params",
40                     help="EAL arguments which are passed to the test app",
41                     default="--vdev=baseband_null0")
42 parser.add_argument("-t", "--timeout",
43                     type=int,
44                     help="Timeout in seconds",
45                     default=300)
46 parser.add_argument("-c", "--test-cases",
47                     nargs="+",
48                     help="Defines test cases to run. Run all if not specified")
49 parser.add_argument("-v", "--test-vector",
50                     nargs="+",
51                     help="Specifies paths to the test vector files.",
52                     default=[dpdk_path +
53                     "/app/test-bbdev/test_vectors/bbdev_null.data"])
54 parser.add_argument("-n", "--num-ops",
55                     type=int,
56                     help="Number of operations to process on device.",
57                     default=32)
58 parser.add_argument("-b", "--burst-size",
59                     nargs="+",
60                     type=int,
61                     help="Operations enqueue/dequeue burst size.",
62                     default=[32])
63 parser.add_argument("-l", "--num-lcores",
64                     type=int,
65                     help="Number of lcores to run.",
66                     default=16)
67 parser.add_argument("-i", "--init-device",
68                     action='store_true',
69                     help="Initialise PF device with default values.")
70
71 args = parser.parse_args()
72
73 if not os.path.exists(args.testapp_path):
74     print("No such file: " + args.testapp_path)
75     sys.exit(1)
76
77 params = [args.testapp_path]
78 if args.eal_params:
79     params.extend(shlex.split(args.eal_params))
80
81 params.extend(["--"])
82
83 if args.num_ops:
84     params.extend(["-n", str(args.num_ops)])
85
86 if args.num_lcores:
87     params.extend(["-l", str(args.num_lcores)])
88
89 if args.test_cases:
90     params.extend(["-c"])
91     params.extend([",".join(args.test_cases)])
92
93 if args.init_device:
94     params.extend(["-i"])
95
96
97 exit_status = 0
98 for vector in args.test_vector:
99     for burst_size in args.burst_size:
100         call_params = params[:]
101         call_params.extend(["-v", vector])
102         call_params.extend(["-b", str(burst_size)])
103         params_string = " ".join(call_params)
104
105         print("Executing: {}".format(params_string))
106         app_proc = subprocess.Popen(call_params)
107         if args.timeout > 0:
108             timer = Timer(args.timeout, kill, [app_proc])
109             timer.start()
110
111         try:
112             app_proc.communicate()
113         except:
114             print("Error: failed to execute: {}".format(params_string))
115         finally:
116             timer.cancel()
117
118         if app_proc.returncode != 0:
119             exit_status = 1
120             print("ERROR TestCase failed. Failed test for vector {}. Return code: {}".format(
121                 vector, app_proc.returncode))
122
123 sys.exit(exit_status)