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: 26218c4e68SBruce 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) 62*d819c083SNicolas Chautruparser.add_argument("-i", "--init-device", 63*d819c083SNicolas Chautru action='store_true', 64*d819c083SNicolas Chautru help="Initialise PF device with default values.") 65f714a188SAmr Mokhtar 66f714a188SAmr Mokhtarargs = parser.parse_args() 67f714a188SAmr Mokhtar 68f714a188SAmr Mokhtarif not os.path.exists(args.testapp_path): 69f714a188SAmr Mokhtar print "No such file: " + args.testapp_path 70f714a188SAmr Mokhtar sys.exit(1) 71f714a188SAmr Mokhtar 72f714a188SAmr Mokhtarparams = [args.testapp_path] 73f714a188SAmr Mokhtarif args.eal_params: 74f714a188SAmr Mokhtar params.extend(shlex.split(args.eal_params)) 75f714a188SAmr Mokhtar 76f714a188SAmr Mokhtarparams.extend(["--"]) 77f714a188SAmr Mokhtar 78f714a188SAmr Mokhtarif args.num_ops: 79f714a188SAmr Mokhtar params.extend(["-n", str(args.num_ops)]) 80f714a188SAmr Mokhtar 81f714a188SAmr Mokhtarif args.num_lcores: 82f714a188SAmr Mokhtar params.extend(["-l", str(args.num_lcores)]) 83f714a188SAmr Mokhtar 84f714a188SAmr Mokhtarif args.test_cases: 85f714a188SAmr Mokhtar params.extend(["-c"]) 86f714a188SAmr Mokhtar params.extend([",".join(args.test_cases)]) 87f714a188SAmr Mokhtar 88*d819c083SNicolas Chautruif args.init_device: 89*d819c083SNicolas Chautru params.extend(["-i"]) 90*d819c083SNicolas Chautru 91*d819c083SNicolas Chautru 92f714a188SAmr Mokhtarexit_status = 0 93f714a188SAmr Mokhtarfor vector in args.test_vector: 94f714a188SAmr Mokhtar for burst_size in args.burst_size: 95f714a188SAmr Mokhtar call_params = params[:] 96f714a188SAmr Mokhtar call_params.extend(["-v", vector]) 97f714a188SAmr Mokhtar call_params.extend(["-b", str(burst_size)]) 98f714a188SAmr Mokhtar params_string = " ".join(call_params) 99f714a188SAmr Mokhtar 100f714a188SAmr Mokhtar print("Executing: {}".format(params_string)) 101f714a188SAmr Mokhtar app_proc = subprocess.Popen(call_params) 102f714a188SAmr Mokhtar if args.timeout > 0: 103f714a188SAmr Mokhtar timer = Timer(args.timeout, kill, [app_proc]) 104f714a188SAmr Mokhtar timer.start() 105f714a188SAmr Mokhtar 106f714a188SAmr Mokhtar try: 107f714a188SAmr Mokhtar app_proc.communicate() 108f714a188SAmr Mokhtar except: 109f714a188SAmr Mokhtar print("Error: failed to execute: {}".format(params_string)) 110f714a188SAmr Mokhtar finally: 111f714a188SAmr Mokhtar timer.cancel() 112f714a188SAmr Mokhtar 113f714a188SAmr Mokhtar if app_proc.returncode != 0: 114f714a188SAmr Mokhtar exit_status = 1 115f714a188SAmr Mokhtar print("ERROR TestCase failed. Failed test for vector {}. Return code: {}".format( 116f714a188SAmr Mokhtar vector, app_proc.returncode)) 117f714a188SAmr Mokhtar 118f714a188SAmr Mokhtarsys.exit(exit_status) 119