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