@@ -5,6 +5,8 @@ AM_CFLAGS += -I$(srcdir)/include
AM_CFLAGS += -I$(top_srcdir)/include
AM_CFLAGS += -I$(top_srcdir)/helper/include
+SUBDIRS = test
+
include_HEADERS = \
$(top_srcdir)/include/odp.h
@@ -15,3 +15,5 @@ AC_LINK_IFELSE(
echo "GCC-style __atomic builtins not supported by the compiler."
echo "Use newer version. For gcc > 4.7.0"
exit -1)
+
+AC_CONFIG_FILES([platform/linux-generic/test/Makefile])
new file mode 100644
@@ -0,0 +1 @@
+dist_bin_SCRIPTS = $(srcdir)/pktio_env
new file mode 100644
@@ -0,0 +1,120 @@
+#!/bin/sh
+#
+# Copyright (c) 2015, Linaro Limited
+# All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+# Test script wrapper for running ODP pktio apps on linux-generic.
+#
+# For linux-generic the default behavior is to create two pairs of
+# virtual Ethernet interfaces and provide the names of these via
+# environment variables to pktio apps, the interfaces will be removed
+# before the script exits.
+#
+# Note that the creation of virtual Ethernet devices depends on having
+# CONFIG_VETH enabled in the kernel, if not enabled the env setup will be skipped.
+#
+# Network set up
+# IF0 <---> IF1
+# IF2 <---> IF3
+IF0=pktio-p0-p1
+IF1=pktio-p1-p0
+IF2=pktio-p2-p3
+IF3=pktio-p3-p2
+
+if [ "$0" = "$BASH_SOURCE" ]; then
+ echo "Error: Platform specific env file has to be sourced."
+fi
+
+check_for_root()
+{
+ if [ "$(id -u)" != "0" ]; then
+ echo "check_for_root(): need to be root to setup VETH"
+ return 1
+ fi
+ return 0
+}
+
+# wait for a network interface's operational state to be "up"
+wait_for_iface_up()
+{
+ iface=$1
+ cnt=0
+
+ while [ $cnt -lt 50 ]; do
+ read operstate < /sys/class/net/$iface/operstate
+
+ if [ $? -ne 0 ]; then
+ break
+ elif [ "$operstate" = "up" ]; then
+ return 0
+ fi
+
+ sleep 0.1
+ cnt=`expr $cnt + 1`
+ done
+
+ return 1
+}
+
+setup_pktio_env()
+{
+ echo "pktio: setting up test interfaces $IF0, $IF1, $IF2, $IF3."
+
+ check_for_root
+ if [ $? -ne 0 ]; then
+ return 1
+ fi
+
+ for iface in $IF0 $IF1 $IF2 $IF3; do
+ ip link show $iface 2> /dev/null
+ if [ $? -eq 0 ]; then
+ echo "pktio: interface $iface already exist $?"
+ return 2
+ fi
+ done
+
+ if [ "$1" = "clean" ]; then
+ trap cleanup_pktio_env EXIT
+ fi
+
+ ip link add $IF0 type veth peer name $IF1
+ if [ $? -ne 0 ]; then
+ echo "pktio: error: unable to create veth pair"
+ return 3
+ fi
+ ip link add $IF2 type veth peer name $IF3
+ if [ $? -ne 0 ]; then
+ echo "pktio: error: unable to create veth pair"
+ return 4
+ fi
+
+ for iface in $IF0 $IF1 $IF2 $IF3; do
+ ip link set $iface mtu 9216 up
+ ifconfig $iface -arp
+ done
+
+ # check that the interface has come up before starting the test
+ for iface in $IF0 $IF1 $IF2 $IF3; do
+ wait_for_iface_up $iface
+ if [ $? -ne 0 ]; then
+ echo "pktio: interface $iface failed to come up"
+ return 5
+ fi
+ done
+}
+
+cleanup_pktio_env()
+{
+ echo "pktio: removing test interfaces $IF0, $IF1, $IF2, $IF3"
+ check_for_root
+ if [ $? -ne 0 ]; then
+ return 1
+ fi
+
+ for iface in $IF0 $IF1 $IF2 $IF3; do
+ ip link del $iface 2> /dev/null
+ done
+ return 0
+}
@@ -13,4 +13,9 @@ To run valgrind on the executables do:
$ ./bootstrap
$ ./configure --enable-test-vald --enable-valgrind
$ cd test/validation
-$ make check-valgrind
+
+Some tests scripts, like pktio require ODP_PLATFORM variable to be exported to load
+platform specific env files. 'make check' defines that variable automatically,
+and package will put all required files at the same place as tests binaries. But if
+you run tests manually from odp source code then you need it to be defined, like:
+export ODP_PLATFROM=linux-generic.
@@ -1,104 +1,51 @@
#!/bin/sh
#
-# Test script wrapper for running ODP pktio tests on linux-generic.
+# Copyright (c) 2015, Linaro Limited
+# All rights reserved.
#
-# For platforms other than linux-generic this script does nothing other
-# than running the odp_pktio binary, odp_pktio will then attempt to
-# open and use the special device named "loop" for testing.
+# SPDX-License-Identifier: BSD-3-Clause
#
-# For linux-generic the default behaviour is to create a pair of
-# virtual Ethernet interfaces and provide the names of these via
-# environment variables to odp_pktio, the interfaces will be removed
-# before the script exits. Note that the creation of virtual Ethernet
-# devices depends on having CONFIG_VETH enabled in the kernel, if not
-# enabled the test will be skipped.
+
+# TEST_DIR is set by Makefile to point to the directory where binaries have been
+# built (Makefile variable builddir)
+# If TEST_DIR is not set it means we are not running with make, and in this case
+# there are two situations:
+# 1. user build ODP in the same dir as the source (most likely)
+# here the user can simply call odp_pktio_run
+# 2. user may have built ODP in a separate build dir (like bitbake usually does)
+# here the user has to do something like $ODP/test/validation/odp_pktio_run
#
-# The evironment variable ODP_PLATFORM is used to determine the
-# platform under test, when this script is invoked via 'make check'
-# this variable is set automatically.
-#
-# It's also possible to split up the steps, which makes it easier when
-# debugging, for example;
-#
-# export ODP_PLATFORM=linux-generic
-# odp_pktio_run setup
-# wireshark -i pktio-p0 -k &
-# odp_pktio_run
-# (repeat running test multiple times..)
-# odp_pktio_run cleanup
-#
-TEST_DIR="${TEST_DIR:-$(dirname $0)}"
-IF0=pktio-p0
-IF1=pktio-p1
+# In both situations the script assumes that the user is in the directory where
+# odp_pktio exists. If that's not true, then the user has to specify the path
+# to it and run:
+# TEST_DIR=$builddir $ODP/test/validation/odp_pktio_run
+
+# 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:$PATH
# exit codes expected by automake for skipped tests
TEST_SKIPPED=77
-# wait for a network interface's operational state to be "up"
-wait_for_iface_up()
-{
- iface=$1
- cnt=0
-
- while [ $cnt -lt 50 ]; do
- read operstate < /sys/class/net/$iface/operstate
-
- if [ $? != 0 ]; then
- break
- elif [ "$operstate" = "up" ]; then
- return 0
- fi
-
- sleep 0.1
- cnt=`expr $cnt + 1`
- done
-
- return 1
-}
-
-setup_env1()
-{
- ip link show $IF0 2> /dev/null
- if [ $? = 0 ]; then
- ip link show $IF1 2> /dev/null
- if [ $? = 0 ]; then
- echo "pktio: interfaces $IF0 and $IF1 already exist"
- return
- fi
+# Use installed pktio env or for make check take it from platform directory
+if [ -f "./pktio_env" ]; then
+ . ./pktio_env
+ if [ "$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_env ]; then
+ . ${TEST_SRC_DIR}/../../platform/$ODP_PLATFORM/test/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
-
- echo "pktio: setting up test interfaces $IF0 and $IF1"
-
- if [ "$1" = "clean" ]; then
- trap cleanup_env1 EXIT
- fi
-
- ip link add $IF0 type veth peer name $IF1
- if [ $? != 0 ]; then
- echo "pktio: error: unable to create veth pair"
- exit $TEST_SKIPPED
- fi
- ip link set $IF0 mtu 9216 up
- ip link set $IF1 mtu 9216 up
- ifconfig $IF0 -arp
- ifconfig $IF1 -arp
-
- # check that the interface has come up before starting the test
- for iface in $IF0 $IF1; do
- wait_for_iface_up $iface
- if [ $? != 0 ]; then
- echo "pktio: interface $iface failed to come up"
- exit 1
- fi
- done
-}
-
-cleanup_env1()
-{
- echo "pktio: removing test interfaces $IF0 and $IF1"
- ip link del $IF0 2> /dev/null
- ip link del $IF1 2> /dev/null
-}
+fi
run_test()
{
@@ -115,13 +62,13 @@ run_test()
if [ "$disabletype" != "SKIP" ]; then
export ODP_PKTIO_DISABLE_SOCKET_${distype}=y
fi
- $TEST_DIR/odp_pktio
- if [ $? != 0 ]; then
+ odp_pktio
+ if [ $? -ne 0 ]; then
ret=1
fi
done
- if [ $ret != 0 ]; then
+ if [ $ret -ne 0 ]; then
echo "!!! FAILED !!!"
fi
@@ -132,13 +79,13 @@ run()
{
if [ "$ODP_PLATFORM" != "linux-generic" -o "$(id -u)" != "0" ]; then
echo "pktio: using 'loop' device"
- $TEST_DIR/odp_pktio
+ odp_pktio
exit $?
fi
if [ "$ODP_PKTIO_IF0" = "" ]; then
# no interfaces specified on linux-generic, use defaults
- setup_env1 clean
+ setup_pktio_env clean
export ODP_PKTIO_IF0=$IF0
export ODP_PKTIO_IF1=$IF1
fi
@@ -146,14 +93,8 @@ run()
run_test
}
-if [ "$ODP_PLATFORM" = "" ]; then
- echo "pktio: error: ODP_PLATFORM must be defined"
- # not skipped as this should never happen via "make check"
- exit 1
-fi
-
case "$1" in
- setup) setup_env1 ;;
- cleanup) cleanup_env1 ;;
- *) run ;;
+ setup) setup_pktio_env ;;
+ cleanup) cleanup_pktio_env ;;
+ *) run ;;
esac