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