diff mbox

[2/2] example/l3fwd: add test script

Message ID 1468395048-5024-1-git-send-email-forrest.shi@linaro.org
State New
Headers show

Commit Message

Forrest Shi July 13, 2016, 7:30 a.m. UTC
From: Xuelin Shi <forrest.shi@linaro.org>


Signed-off-by: Xuelin Shi <forrest.shi@linaro.org>

---
 example/l3fwd/odp_l3fwd_run.sh | 97 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)
 create mode 100644 example/l3fwd/odp_l3fwd_run.sh

-- 
2.1.0.27.g96db324
diff mbox

Patch

diff --git a/example/l3fwd/odp_l3fwd_run.sh b/example/l3fwd/odp_l3fwd_run.sh
new file mode 100644
index 0000000..db9a838
--- /dev/null
+++ b/example/l3fwd/odp_l3fwd_run.sh
@@ -0,0 +1,97 @@ 
+#!/bin/sh
+#
+# Copyright (c) 2016, Linaro Limited
+# All rights reserved.
+#
+# SPDX-License-Identifier:	BSD-3-Clause
+#
+
+# The script assumes that the user is in the directory where odp_l3fwd exists.
+# If that's not true, then the user has to specify the path to it and run:
+#TEST_DIR=$builddir $ODP/example/l3fwd/
+
+# directory where test binaries have been built
+TEST_DIR="${TEST_DIR:-$PWD}"
+# directory where test sources are, including scripts
+TEST_SRC_DIR=$(dirname $0)
+
+PATH=$TEST_DIR:$TEST_DIR/../../example/generator:$PATH
+
+# exit codes expected by automake for skipped tests
+TEST_SKIPPED=77
+
+# Use installed pktio env or for make check take it from platform directory
+if [ -f "./pktio_env" ]; then
+	. ./pktio_env
+elif  [ "$ODP_PLATFORM" = "" ]; then
+	echo "$0: error: ODP_PLATFORM must be defined"
+	# not skipped as this should never happen via "make check"
+	exit 1
+elif [ -f ${TEST_SRC_DIR}/../../platform/$ODP_PLATFORM/test/pktio/pktio_env ]; then
+	. ${TEST_SRC_DIR}/../../platform/$ODP_PLATFORM/test/pktio/pktio_env
+else
+	echo "BUG: unable to find pktio_env!"
+	echo "pktio_env has to be in current directory or in platform/\$ODP_PLATFORM/test."
+	echo "ODP_PLATFORM=\"$ODP_PLATFORM\""
+	exit 1
+fi
+
+run_l3fwd()
+{
+	setup_pktio_env clean # install trap to call cleanup_pktio_env
+
+	if [ $? -ne 0 ]; then
+		echo "setup_pktio_env error $?"
+		exit $TEST_SKIPPED
+	fi
+
+	type odp_generator > /dev/null
+	if [ $? -ne 0 ]; then
+		echo "odp_generator not installed. Aborting."
+		cleanup_pktio_env
+		exit 1
+	fi
+
+	#@todo: limit odp_generator to cores
+	#https://bugs.linaro.org/show_bug.cgi?id=1398
+	(odp_generator${EXEEXT} -I $IF0 \
+			--srcip 1.1.1.1 --dstip 2.1.1.1 -m u 2>&1 > /dev/null) \
+			2>&1 > /dev/null &
+	GEN_PID=$!
+
+	# this just turns off output buffering so that you still get periodic
+	# output while piping to tee, as long as stdbuf is available.
+	if [ "$(which stdbuf)" != "" ]; then
+		STDBUF="stdbuf -o 0"
+	else
+		STDBUF=
+	fi
+	LOG=odp_l3fwd_tmp.log
+	$STDBUF odp_l3fwd${EXEEXT} -i $IF1,$IF2 -r "1.1.1.0/24:$IF1" -r "2.1.1.0/24:$IF2" -d 50 | tee $LOG
+	ret=$?
+
+	kill ${GEN_PID}
+
+	if [ ! -f $LOG ]; then
+		echo "FAIL: $LOG not found"
+		ret=1
+	elif [ $ret -eq 0 ]; then
+		PASS_PPS=1000
+		MAX_PPS=$(awk '/TEST RESULT/ {print $3}' $LOG)
+		if [ "$MAX_PPS" -lt "$PASS_PPS" ]; then
+			echo "FAIL: pps below threshold $MAX_PPS < $PASS_PPS"
+			ret=1
+		fi
+	fi
+
+	rm -f $LOG
+	cleanup_pktio_env
+
+	exit $ret
+}
+
+case "$1" in
+	setup)   setup_pktio_env   ;;
+	cleanup) cleanup_pktio_env ;;
+	*)       run_l3fwd ;;
+esac