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 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): 15f714a188SAmr Mokhtar print "ERROR: Test app timed out" 16f714a188SAmr Mokhtar process.kill() 17f714a188SAmr Mokhtar 18f714a188SAmr Mokhtarif "RTE_SDK" in os.environ: 19f714a188SAmr Mokhtar dpdk_path = os.environ["RTE_SDK"] 20f714a188SAmr Mokhtarelse: 21f714a188SAmr Mokhtar dpdk_path = "../.." 22f714a188SAmr Mokhtar 23f714a188SAmr Mokhtarif "RTE_TARGET" in os.environ: 24f714a188SAmr Mokhtar dpdk_target = os.environ["RTE_TARGET"] 25f714a188SAmr Mokhtarelse: 26*218c4e68SBruce Richardson dpdk_target = "x86_64-native-linux-gcc" 27f714a188SAmr Mokhtar 28f714a188SAmr Mokhtarparser = argparse.ArgumentParser( 29f714a188SAmr Mokhtar description='BBdev Unit Test Application', 30f714a188SAmr Mokhtar formatter_class=argparse.ArgumentDefaultsHelpFormatter) 31f714a188SAmr Mokhtarparser.add_argument("-p", "--testapp-path", 32f714a188SAmr Mokhtar help="specifies path to the bbdev test app", 33f714a188SAmr Mokhtar default=dpdk_path + "/" + dpdk_target + "/app/testbbdev") 34f714a188SAmr Mokhtarparser.add_argument("-e", "--eal-params", 35f714a188SAmr Mokhtar help="EAL arguments which are passed to the test app", 367ce00bf3SKamil Chalupnik default="--vdev=baseband_null0") 37f714a188SAmr Mokhtarparser.add_argument("-t", "--timeout", 38f714a188SAmr Mokhtar type=int, 39f714a188SAmr Mokhtar help="Timeout in seconds", 40f714a188SAmr Mokhtar default=300) 41f714a188SAmr Mokhtarparser.add_argument("-c", "--test-cases", 42f714a188SAmr Mokhtar nargs="+", 43f714a188SAmr Mokhtar help="Defines test cases to run. Run all if not specified") 44f714a188SAmr Mokhtarparser.add_argument("-v", "--test-vector", 45f714a188SAmr Mokhtar nargs="+", 46f714a188SAmr Mokhtar help="Specifies paths to the test vector files.", 47f714a188SAmr Mokhtar default=[dpdk_path + 48ae828b8cSKamil Chalupnik "/app/test-bbdev/test_vectors/bbdev_null.data"]) 49f714a188SAmr Mokhtarparser.add_argument("-n", "--num-ops", 50f714a188SAmr Mokhtar type=int, 51f714a188SAmr Mokhtar help="Number of operations to process on device.", 52f714a188SAmr Mokhtar default=32) 53f714a188SAmr Mokhtarparser.add_argument("-b", "--burst-size", 54f714a188SAmr Mokhtar nargs="+", 55f714a188SAmr Mokhtar type=int, 56f714a188SAmr Mokhtar help="Operations enqueue/dequeue burst size.", 57f714a188SAmr Mokhtar default=[32]) 58f714a188SAmr Mokhtarparser.add_argument("-l", "--num-lcores", 59f714a188SAmr Mokhtar type=int, 60f714a188SAmr Mokhtar help="Number of lcores to run.", 61f714a188SAmr Mokhtar default=16) 62f714a188SAmr Mokhtar 63f714a188SAmr Mokhtarargs = parser.parse_args() 64f714a188SAmr Mokhtar 65f714a188SAmr Mokhtarif not os.path.exists(args.testapp_path): 66f714a188SAmr Mokhtar print "No such file: " + args.testapp_path 67f714a188SAmr Mokhtar sys.exit(1) 68f714a188SAmr Mokhtar 69f714a188SAmr Mokhtarparams = [args.testapp_path] 70f714a188SAmr Mokhtarif args.eal_params: 71f714a188SAmr Mokhtar params.extend(shlex.split(args.eal_params)) 72f714a188SAmr Mokhtar 73f714a188SAmr Mokhtarparams.extend(["--"]) 74f714a188SAmr Mokhtar 75f714a188SAmr Mokhtarif args.num_ops: 76f714a188SAmr Mokhtar params.extend(["-n", str(args.num_ops)]) 77f714a188SAmr Mokhtar 78f714a188SAmr Mokhtarif args.num_lcores: 79f714a188SAmr Mokhtar params.extend(["-l", str(args.num_lcores)]) 80f714a188SAmr Mokhtar 81f714a188SAmr Mokhtarif args.test_cases: 82f714a188SAmr Mokhtar params.extend(["-c"]) 83f714a188SAmr Mokhtar params.extend([",".join(args.test_cases)]) 84f714a188SAmr Mokhtar 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