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