hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
....@@ -4,6 +4,7 @@
44 # IPv4 and IPv6 onlink tests
55
66 PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no}
7
+VERBOSE=0
78
89 # Network interfaces
910 # - odd in current namespace; even in peer ns
....@@ -91,10 +92,10 @@
9192
9293 if [ ${rc} -eq ${expected} ]; then
9394 nsuccess=$((nsuccess+1))
94
- printf "\n TEST: %-50s [ OK ]\n" "${msg}"
95
+ printf " TEST: %-50s [ OK ]\n" "${msg}"
9596 else
9697 nfail=$((nfail+1))
97
- printf "\n TEST: %-50s [FAIL]\n" "${msg}"
98
+ printf " TEST: %-50s [FAIL]\n" "${msg}"
9899 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
99100 echo
100101 echo "hit enter to continue, 'q' to quit"
....@@ -121,9 +122,23 @@
121122
122123 run_cmd()
123124 {
124
- echo
125
- echo "COMMAND: $*"
126
- eval $*
125
+ local cmd="$*"
126
+ local out
127
+ local rc
128
+
129
+ if [ "$VERBOSE" = "1" ]; then
130
+ printf " COMMAND: $cmd\n"
131
+ fi
132
+
133
+ out=$(eval $cmd 2>&1)
134
+ rc=$?
135
+ if [ "$VERBOSE" = "1" -a -n "$out" ]; then
136
+ echo " $out"
137
+ fi
138
+
139
+ [ "$VERBOSE" = "1" ] && echo
140
+
141
+ return $rc
127142 }
128143
129144 get_linklocal()
....@@ -451,11 +466,34 @@
451466 }
452467
453468 ################################################################################
469
+# usage
470
+
471
+usage()
472
+{
473
+ cat <<EOF
474
+usage: ${0##*/} OPTS
475
+
476
+ -p Pause on fail
477
+ -v verbose mode (show commands and output)
478
+EOF
479
+}
480
+
481
+################################################################################
454482 # main
455483
456484 nsuccess=0
457485 nfail=0
458486
487
+while getopts :t:pPhv o
488
+do
489
+ case $o in
490
+ p) PAUSE_ON_FAIL=yes;;
491
+ v) VERBOSE=$(($VERBOSE + 1));;
492
+ h) usage; exit 0;;
493
+ *) usage; exit 1;;
494
+ esac
495
+done
496
+
459497 cleanup
460498 setup
461499 run_onlink_tests