diff options
author | Tudor Florea <tudor.florea@enea.com> | 2015-10-08 22:50:30 +0200 |
---|---|---|
committer | Tudor Florea <tudor.florea@enea.com> | 2015-10-08 22:50:30 +0200 |
commit | 56fadd5827f95396b1237dfe628e2b8a3d28dd00 (patch) | |
tree | a1bcdf8f990f18fb0222d215522a99176719c4eb /recipes-test/ddt-runner/files/scripts/p2041rdb/ethernet | |
download | meta-enea-56fadd5827f95396b1237dfe628e2b8a3d28dd00.tar.gz |
initial commit for Enea Linux 5.0 arm
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'recipes-test/ddt-runner/files/scripts/p2041rdb/ethernet')
-rwxr-xr-x | recipes-test/ddt-runner/files/scripts/p2041rdb/ethernet | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/recipes-test/ddt-runner/files/scripts/p2041rdb/ethernet b/recipes-test/ddt-runner/files/scripts/p2041rdb/ethernet new file mode 100755 index 0000000..0f2b4cf --- /dev/null +++ b/recipes-test/ddt-runner/files/scripts/p2041rdb/ethernet | |||
@@ -0,0 +1,111 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | |||
4 | exit1() { | ||
5 | echo $@ >&2 | ||
6 | exit 1 | ||
7 | } | ||
8 | |||
9 | |||
10 | err() { | ||
11 | echo $@ >&2 | ||
12 | exit_status=1 | ||
13 | } | ||
14 | |||
15 | |||
16 | get_default_gw() { | ||
17 | echo $(route | grep default | awk '{ print $2 }') | ||
18 | } | ||
19 | |||
20 | |||
21 | test_eth_device() { | ||
22 | local readonly dev=$1 | ||
23 | local readonly ethernet_ping_ipaddr=$2 | ||
24 | local readonly MINDATASIZE=56 | ||
25 | local readonly MAXDATASIZE=650 | ||
26 | local readonly STEPSIZE=100 | ||
27 | local readonly ITERATION=2 | ||
28 | local datasize | ||
29 | local i | ||
30 | local ping_err | ||
31 | for i in `seq 1 $ITERATION`; do | ||
32 | datasize=$MINDATASIZE | ||
33 | while [ $datasize -le $MAXDATASIZE ]; do | ||
34 | ping -I $dev -c 1 -s $datasize $ethernet_ping_ipaddr > $STATISTICS | ||
35 | ping_err=$? | ||
36 | packets_received=`cat $STATISTICS | grep "received" | | ||
37 | awk '{print$4}'` | ||
38 | |||
39 | # Evaluate possible errors on the ping operation | ||
40 | if [ $ping_err -ne 0 ] || [ -z "$packets_received" ] || | ||
41 | [ $packets_received -eq 0 ]; then | ||
42 | err "FAIL: ping $ethernet_ping_ipaddr through $dev" | ||
43 | cat $STATISTICS >> $LOGFILE | ||
44 | echo "Size: $datasize Iteration: $i" >> $LOGFILE | ||
45 | fi | ||
46 | datasize=$((datasize+STEPSIZE)) | ||
47 | done | ||
48 | done | ||
49 | } | ||
50 | |||
51 | |||
52 | clean_tasks() { | ||
53 | echo "Executing clean up tasks" | ||
54 | rm -f $LOGFILE $STATISTICS | ||
55 | } | ||
56 | |||
57 | |||
58 | cleanup() { | ||
59 | echo "Aborting script execution" | ||
60 | clean_tasks | ||
61 | exit 1 | ||
62 | } | ||
63 | |||
64 | |||
65 | |||
66 | readonly LOGFILE=`/bin/mktemp` | ||
67 | readonly STATISTICS=`/bin/mktemp` | ||
68 | exit_status=0 | ||
69 | |||
70 | trap cleanup SIGHUP SIGINT SIGTERM | ||
71 | |||
72 | |||
73 | |||
74 | readonly DEF_GW=$(get_default_gw) | ||
75 | |||
76 | [ -n "$DEF_GW" ] && echo "Found default gw $DEF_GW" || | ||
77 | exit1 "FAIL: no default gw" | ||
78 | |||
79 | readonly S=: | ||
80 | readonly DEVS="$(route -n | tail -n +3 | sort -k8 -u | awk '{print $8"'$S'"$2}')" | ||
81 | |||
82 | if [ -n "$DEVS" ]; then | ||
83 | echo "Will test: $DEVS" | ||
84 | else | ||
85 | exit1 "FAIL: no ethernet devices to test" | ||
86 | fi | ||
87 | |||
88 | for iface_gw in $DEVS; do | ||
89 | iface=$(echo "$iface_gw" | sed -n 's/\(.*\)'$S'.*/\1/p') | ||
90 | gw=$(echo "$iface_gw" | sed -n 's/.*'$S'\(.*\)/\1/p') | ||
91 | if [ -z "$gw" ]; then | ||
92 | err "FAIL: no ethernet gateway for $iface" | ||
93 | else | ||
94 | [ "$gw" = 0.0.0.0 ] && gw="$DEF_GW" | ||
95 | echo "Testing $iface:$gw" | ||
96 | test_eth_device $iface $gw | ||
97 | fi | ||
98 | done | ||
99 | |||
100 | # Report failures | ||
101 | if [ $exit_status -ne 0 ]; then | ||
102 | echo "=================== error report ===================" | ||
103 | cat $LOGFILE | ||
104 | echo "====================================================" | ||
105 | echo "FAIL: ping test" | ||
106 | else | ||
107 | echo "PASS: ping test success" | ||
108 | fi | ||
109 | |||
110 | clean_tasks | ||
111 | exit $exit_status | ||