Skip to content

Commit

Permalink
Merge pull request torvalds#280 from tavip/fix-tests
Browse files Browse the repository at this point in the history
Test fixes
  • Loading branch information
tavip authored Dec 18, 2016
2 parents 7d748bc + ef45471 commit e297704
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 deletions.
8 changes: 6 additions & 2 deletions tools/lkl/scripts/checkpatch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ if [ -z "$origin_master" ]; then
origin_master="origin/master"
fi

origin=$(dirname $origin_master)
master=$(basename $origin_master)

# make sure we fetch to avoid caching effects
git fetch origin
git fetch --tags $origin +refs/heads/$master:refs/remotes/$origin/$master

# find the last upstream tag to avoid checking upstream commits during
# upstream merges
tag=`git tag --sort='-*authordate' | grep ^v | head -n1`
tmp=`mktemp -d`

for c in `git log --no-merges --pretty=format:%h HEAD ^$origin_master ^$tag`; do
commits=$(git log --no-merges --pretty=format:%h HEAD ^$origin/$master ^$tag)
for c in $commits; do
git format-patch -1 -o $tmp $c
done

Expand Down
13 changes: 7 additions & 6 deletions tools/lkl/tests/net-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ static int test_icmp(char *str, int len)
struct lkl_pollfd pfd;
char buf[32];

str += snprintf(str, len, "%s ", dst);

sock = lkl_sys_socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
if (sock < 0) {
snprintf(str, len, "socket error (%s)", strerror(errno));
snprintf(str, len, "socket error (%s)", lkl_strerror(sock));
return TEST_FAILURE;
}

Expand All @@ -73,7 +75,7 @@ static int test_icmp(char *str, int len)
(struct lkl_sockaddr*)&saddr,
sizeof(saddr));
if (ret < 0) {
snprintf(str, len, "sendto error (%s)", strerror(errno));
snprintf(str, len, "sendto error (%s)", lkl_strerror(ret));
return TEST_FAILURE;
}

Expand All @@ -85,13 +87,13 @@ static int test_icmp(char *str, int len)

ret = lkl_sys_poll(&pfd, 1, 1000);
if (ret < 0) {
snprintf(str, len, "poll error (%s)", strerror(errno));
snprintf(str, len, "poll error (%s)", lkl_strerror(ret));
return TEST_FAILURE;
}

ret = lkl_sys_recv(sock, buf, sizeof(buf), MSG_DONTWAIT);
if (ret < 0) {
snprintf(str, len, "recv error (%s)", strerror(errno));
snprintf(str, len, "recv error (%s)", lkl_strerror(ret));
return TEST_FAILURE;
}

Expand All @@ -105,7 +107,6 @@ static int test_icmp(char *str, int len)
return TEST_FAILURE;
}

snprintf(str, len, "echo reply %s", dst);
return TEST_SUCCESS;
}

Expand All @@ -118,7 +119,7 @@ static int test_net_init(int argc, char **argv)
struct lkl_netdev *nd = NULL;
char boot_cmdline[256] = "\0";

if (argc < 3) {
if (argc < 4) {
printf("usage %s <iftype: tap|dpdk|raw> <ifname> <dstaddr> <v4addr>|dhcp <v4mask> [gateway]\n", argv[0]);
exit(0);
}
Expand Down
46 changes: 23 additions & 23 deletions tools/lkl/tests/net.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/bin/bash -e

IFNAME=`ip route |grep default | awk '{print $5}'`
GW=`ip route |grep default | awk '{print $3}'`
HOST_IPADDR=`ip rou |grep ${IFNAME} | grep "scope link" | awk '{print $1}' | sed "s/\(.*\)\/.*/\1/"`
PLEN=`ip rou |grep ${IFNAME} | grep "scope link" | awk '{print $1}' | sed "s/.*\/\(.*\)/\1/"`
IPADDR=`echo ${HOST_IPADDR}|awk -F. '{printf ("%d.%d.%d.%d\n",$1,$2,$3,$4+10)}'`
# currently not supported mingw
if [ "`printenv CONFIG_AUTO_LKL_POSIX_HOST`" != "y" ] ; then
exit 0
fi

IFNAME=`ip route |grep default | awk '{print $5}' | head -n1`
GW=`ip route |grep default | awk '{print $3}' | head -n1`

script_dir=$(cd $(dirname ${BASH_SOURCE:-$0}); pwd)
cd ${script_dir}
Expand Down Expand Up @@ -32,27 +34,25 @@ if [ -c /dev/net/tun ]; then
sudo ip tuntap del dev lkl_ptt1 mode tap
fi

echo "== RAW socket (LKL net) tests =="
# currently not supported mingw
if [ -n "`printenv CONFIG_AUTO_LKL_POSIX_HOST`" ] ; then
sudo ip link set dev ${IFNAME} promisc on
# this won't work if IFNAME is wifi since it rewrites the src macaddr
sudo ./net-test raw ${IFNAME} 8.8.8.8 ${IPADDR} ${PLEN} ${GW}

# DHCP test
echo " == DHCP with RAW socket test =="
sudo ./net-test raw ${IFNAME} 8.8.8.8 dhcp
sudo ip link set dev ${IFNAME} promisc off
if ping -c1 -w1 $GW &>/dev/null; then
DST=$GW
elif ping -c1 -w1 8.8.8.8 &>/dev/null; then
DST=8.8.8.8
fi

echo "== macvtap (LKL net) tests =="
# currently not supported mingw
sudo ip link add link ${IFNAME} name lkl_vtap0 type macvtap mode passthru
if ls /dev/tap* > /dev/null 2>&1 ; then
sudo ip link set dev lkl_vtap0 up
sudo chown ${USER} `ls /dev/tap*`
if ! [ -z $DST ]; then
echo "== RAW socket (LKL net) tests =="
sudo ip link set dev ${IFNAME} promisc on
sudo ./net-test raw ${IFNAME} ${DST} dhcp
sudo ip link set dev ${IFNAME} promisc off

./net-test macvtap `ls /dev/tap*` 8.8.8.8 ${IPADDR} ${PLEN} ${GW}
echo "== macvtap (LKL net) tests =="
sudo ip link add link ${IFNAME} name lkl_vtap0 type macvtap mode passthru
if ls /dev/tap* > /dev/null 2>&1 ; then
sudo ip link set dev lkl_vtap0 up
sudo chown ${USER} `ls /dev/tap*`
./net-test macvtap `ls /dev/tap*` $DST dhcp
fi
fi

# we disabled this DPDK test because it's unlikely possible to describe
Expand Down

0 comments on commit e297704

Please sign in to comment.