Fix OSX bugs in test framework

Use GNU grep, sed and awk instead of BSD variants.  Developers will have
to install these using a package manager like homebrew.  Updated the
INSTALL.md and doc/Development.md tech docs with instructions.
This commit is contained in:
Andrew Bettison 2016-01-26 23:56:27 +10:30
parent dbf49d8a81
commit 0361b99ca7
5 changed files with 83 additions and 23 deletions

View File

@ -9,9 +9,11 @@ These instructions will build [Serval DNA][] successfully for the following plat
* Debian Linux, ix86 and x86\_64, kernels 2.6.x and 3.x, using [gcc 4.4][] to
[gcc 4.8][]
* Mac OS X 10.7 “Lion”, x86\_64, using [gcc 4.2][] available in [Xcode 4][]
3.2.6
* Oracle SunOs 5.10 (Solaris), Sparc, using [gcc 4.4][]
* Mac OS X x86\_64, releases 10.7 “Lion” to 10.11 “El Capitan”, using [gcc
4.2][] available in [Xcode][] versions 3.2 to 7.2, and GNU tools available
from [homebrew][]
* Oracle SunOs 5.10 (Solaris), Sparc, using [gcc 4.4][] and GNU tools
installed
[Serval DNA][] also runs on the following platforms, to which these build
instructions do not apply:
@ -59,9 +61,14 @@ Optional:
Test dependencies:
* bash 3.2.48 or later
* GNU grep, sed and awk (on OSX and Solaris, as ggrep, gsed and gawk)
* jq 1.3 or later
* curl
The GNU grep, sed and awk programs can be installed on OSX using the
[homebrew][] package manager. The [Notes for Developers](./doc/Development.md)
give more details.
Build
-----
@ -211,7 +218,7 @@ This document is available under the [Creative Commons Attribution 4.0 Internati
[Android 2.2 “Froyo”]: http://developer.android.com/about/versions/android-2.2-highlights.html
[Android NDK]: http://developer.android.com/tools/sdk/ndk/index.html
[gcc 4.2]: http://gcc.gnu.org/gcc-4.2/
[Xcode 4]: https://developer.apple.com/xcode/
[Xcode]: https://developer.apple.com/xcode/
[gcc 4.4]: http://gcc.gnu.org/gcc-4.4/
[gcc 4.7]: http://gcc.gnu.org/gcc-4.7/
[OpenWRT]: ./doc/OpenWRT.md
@ -226,4 +233,5 @@ This document is available under the [Creative Commons Attribution 4.0 Internati
[Git]: http://git-scm.com/
[Subversion]: http://subversion.apache.org/
[Bourne shell]: http://en.wikipedia.org/wiki/Bourne_shell
[homebrew]: http://brew.sh/
[CC BY 4.0]: ./LICENSE-DOCUMENTATION.md

View File

@ -59,6 +59,53 @@ suppress most of these messages from the output of [aclocal][] and
aclocal: warning: autoconf input should be named 'configure.ac', not 'configure.in'
$
Apple OSX
---------
The [OSX grep(1)][] , [OSX sed(1)][] and [OSX awk(1)][] tools provided by Apple
OSX are the BSD variants. The test scripts require the GNU variants with the
names *ggrep*, *gsed* and *gawk*, which can be installed on OSX using the
[homebrew][] package manager:
$ brew install grep
==> Installing grep from homebrew/dupes
==> Installing dependencies for homebrew/dupes/grep: pcre
==> Installing homebrew/dupes/grep dependency: pcre
==> Downloading https://homebrew.bintray.com/bottles/pcre-8.38.el_capitan.bottle.tar.gz
==> Pouring pcre-8.38.el_capitan.bottle.tar.gz
/usr/local/Cellar/pcre/8.38: 146 files, 5.4M
==> Installing homebrew/dupes/grep
==> Downloading https://homebrew.bintray.com/bottles-dupes/grep-2.22.el_capitan.bottle.tar.gz
==> Pouring grep-2.22.el_capitan.bottle.tar.gz
==> Caveats
The command has been installed with the prefix "g".
If you do not want the prefix, install using the "with-default-names" option.
==> Summary
/usr/local/Cellar/grep/2.22: 14 files, 756.5K
$ brew install gnu-sed
==> Downloading https://homebrew.bintray.com/bottles/gnu-sed-4.2.2.el_capitan.bottle.2.tar.gz
==> Pouring gnu-sed-4.2.2.el_capitan.bottle.2.tar.gz
tar: Failed to set default locale
==> Caveats
The command has been installed with the prefix "g".
If you do not want the prefix, install using the "with-default-names" option.
If you need to use these commands with their normal names, you
can add a "gnubin" directory to your PATH from your bashrc like:
PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"
Additionally, you can access their man pages with normal names if you add
the "gnuman" directory to your MANPATH from your bashrc as well:
MANPATH="/usr/local/opt/gnu-sed/libexec/gnuman:$MANPATH"
==> Summary
/usr/local/Cellar/gnu-sed/4.2.2: 9 files, 452K
$ brew install gawk
==> Downloading https://homebrew.bintray.com/bottles/gawk-4.1.3.el_capitan.bottle.tar.gz
==> Pouring gawk-4.1.3.el_capitan.bottle.tar.gz
/usr/local/Cellar/gawk/4.1.3: 63 files, 3.2M
$
About the examples
------------------
@ -89,4 +136,8 @@ Available under the [Creative Commons Attribution 4.0 International licence][CC
[build]: ../INSTALL.md
[aclocal]: https://www.gnu.org/software/automake/manual/html_node/aclocal-Invocation.html
[autoreconf]: https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf.html#autoreconf-Invocation
[OSX grep(1)]: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/grep.1.html
[OSX sed(1)]: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/sed.1.html
[OSX awk(1)]: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/awk.1.html
[homebrew]: http://brew.sh/
[Bourne shell]: http://en.wikipedia.org/wiki/Bourne_shell

View File

@ -117,7 +117,7 @@ unpack_stdout_list() {
for hdr in "${header[@]}"; do
hdr="${hdr//[^A-Za-z0-9_]/_}"
# hdr="${hdr^^*}" would do in Bash-4.0 and later
hdr="$(echo "$hdr" | sed -e 's/.*/\U&/')"
hdr="$(echo "$hdr" | tr a-z A-Z)"
colvars+=("$hdr")
done
local -a row

View File

@ -59,17 +59,18 @@ SED=sed
GREP=grep
TSFMT='+%Y-%m-%d %H:%M:%S'
SYSTYPE=`uname -s`
if [ $SYSTYPE = "SunOS" ]; then
SYSTYPE="$(uname -s)"
case "$SYSTYPE" in
SunOS | Darwin)
AWK=gawk
SED=gsed
GREP=ggrep
fi
if [ $SYSTYPE = "Linux" ]; then
;;
Linux)
# Get nanosecond resolution
TSFMT='+%Y-%m-%d %H:%M:%S.%N'
fi
;;
esac
usage() {
echo -n "\

View File

@ -44,7 +44,7 @@ link_matches() {
done
sid="$1"
tfw_log "Looking for link ${sid}, ${link_type}, ${interface_ex}, ${via}"
if ! grep "^${sid}:${link_type}:${interface_ex}:${via}\$" $_tfw_tmp/stdout; then
if ! $GREP "^${sid}:${link_type}:${interface_ex}:${via}\$" $_tfw_tmp/stdout; then
tfw_log "Link not found"
return 1
fi
@ -276,9 +276,9 @@ start_fakeradio() {
$servald_build_root/fakeradio 4 1 > "$SERVALD_VAR/radioout" 2> "$SERVALD_VAR/radioerr" &
FAKERADIO_PID=$!
wait_until $GREP "^right:" "$SERVALD_VAR/radioout"
local _line=`head "$SERVALD_VAR/radioout" -n 1`
local _line=`head -n 1 "$SERVALD_VAR/radioout"`
END1="${_line#*:}"
_line=`tail "$SERVALD_VAR/radioout" -n 1`
_line=`tail -n 1 "$SERVALD_VAR/radioout"`
END2="${_line#*:}"
tfw_log "Started fakeradio pid=$FAKERADIO_PID, end1=$END1, end2=$END2"
}
@ -446,7 +446,7 @@ test_scan_one() {
}
scan_completed() {
grep "Scan completed" $instance_servald_log || return 1
$GREP "Scan completed" $instance_servald_log || return 1
return 0
}
@ -771,8 +771,8 @@ test_ping_unreliable_1hop() {
set_instance +A
executeOk_servald mdp ping --interval=0.100 --timeout=3 --wait-for-duplicates $SIDB 100
tfw_cat --stdout --stderr
received=$(sed -n -e 's/.*\<\([0-9]\+\) packets received.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
duplicates=$(sed -n -e 's/.*\<\([0-9]\+\) duplicates.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
received=$($SED -n -e 's/.*\<\([0-9][0-9]*\) packets received.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
duplicates=$($SED -n -e 's/.*\<\([0-9][0-9]*\) duplicates.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
assert [ "$received" -ge 98 ]
assert [ "$duplicates" -le 2 ]
}
@ -801,8 +801,8 @@ test_ping_unreliable_2hop() {
set_instance +A
executeOk_servald mdp ping --interval=0.100 --timeout=3 --wait-for-duplicates $SIDC 100
tfw_cat --stdout --stderr
received=$(sed -n -e 's/.*\<\([0-9]\+\) packets received.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
duplicates=$(sed -n -e 's/.*\<\([0-9]\+\) duplicates.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
received=$($SED -n -e 's/.*\<\([0-9]\+\) packets received.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
duplicates=$($SED -n -e 's/.*\<\([0-9]\+\) duplicates.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
assert [ "$received" -ge 98 ]
assert [ "$duplicates" -le 5 ]
}
@ -884,8 +884,8 @@ test_unreliable_links() {
set_instance +A
executeOk_servald mdp ping --interval=0.100 --timeout=3 --wait-for-duplicates $SIDC 50
tfw_cat --stdout --stderr
received=$(sed -n -e 's/.*\<\([0-9]\+\) packets received.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
duplicates=$(sed -n -e 's/.*\<\([0-9]\+\) duplicates.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
received=$($SED -n -e 's/.*\<\([0-9]\+\) packets received.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
duplicates=$($SED -n -e 's/.*\<\([0-9]\+\) duplicates.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
assert [ "$received" -ge 20 ]
assert [ "$duplicates" -le 10 ]
# make sure the path is still there.
@ -930,8 +930,8 @@ test_unreliable_links2() {
set_instance +A
executeOk_servald mdp ping --interval=0.100 --timeout=3 --wait-for-duplicates $SIDD 50
tfw_cat --stdout --stderr
received=$(sed -n -e 's/.*\<\([0-9]\+\) packets received.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
duplicates=$(sed -n -e 's/.*\<\([0-9]\+\) duplicates.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
received=$($SED -n -e 's/.*\<\([0-9]\+\) packets received.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
duplicates=$($SED -n -e 's/.*\<\([0-9]\+\) duplicates.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
assert [ "$received" -ge 20 ]
assert [ "$duplicates" -le 10 ]
wait_until --timeout=20 path_exists +A +B +C +D