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