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