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