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