xref: /dpdk/app/test-bbdev/test-bbdev.py (revision d2fb7164)
1#!/usr/bin/env python
2
3# SPDX-License-Identifier: BSD-3-Clause
4# Copyright(c) 2017 Intel Corporation
5
6from __future__ import print_function
7import sys
8import os
9import argparse
10import subprocess
11import shlex
12
13from threading import Timer
14
15def kill(process):
16    print("ERROR: Test app timed out")
17    process.kill()
18
19if 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
23dpdk_path = "../.."
24dpdk_target = "build"
25
26parser = argparse.ArgumentParser(
27                    description='BBdev Unit Test Application',
28                    formatter_class=argparse.ArgumentDefaultsHelpFormatter)
29parser.add_argument("-p", "--testapp-path",
30                    help="specifies path to the bbdev test app",
31                    default=dpdk_path + "/" + dpdk_target + "/app/dpdk-test-bbdev")
32parser.add_argument("-e", "--eal-params",
33                    help="EAL arguments which are passed to the test app",
34                    default="--vdev=baseband_null0")
35parser.add_argument("-t", "--timeout",
36                    type=int,
37                    help="Timeout in seconds",
38                    default=300)
39parser.add_argument("-c", "--test-cases",
40                    nargs="+",
41                    help="Defines test cases to run. Run all if not specified")
42parser.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"])
47parser.add_argument("-n", "--num-ops",
48                    type=int,
49                    help="Number of operations to process on device.",
50                    default=32)
51parser.add_argument("-b", "--burst-size",
52                    nargs="+",
53                    type=int,
54                    help="Operations enqueue/dequeue burst size.",
55                    default=[32])
56parser.add_argument("-l", "--num-lcores",
57                    type=int,
58                    help="Number of lcores to run.",
59                    default=16)
60parser.add_argument("-i", "--init-device",
61                    action='store_true',
62                    help="Initialise PF device with default values.")
63
64args = parser.parse_args()
65
66if not os.path.exists(args.testapp_path):
67    print("No such file: " + args.testapp_path)
68    sys.exit(1)
69
70params = [args.testapp_path]
71if args.eal_params:
72    params.extend(shlex.split(args.eal_params))
73
74params.extend(["--"])
75
76if args.num_ops:
77    params.extend(["-n", str(args.num_ops)])
78
79if args.num_lcores:
80    params.extend(["-l", str(args.num_lcores)])
81
82if args.test_cases:
83    params.extend(["-c"])
84    params.extend([",".join(args.test_cases)])
85
86if args.init_device:
87    params.extend(["-i"])
88
89
90exit_status = 0
91for 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
116sys.exit(exit_status)
117