Skip to content

Commit bef867a

Browse files
committed
test: Fix test-static-code for busybox grep
That does not know about `--text`, so only use that option if it is available.
1 parent dafed61 commit bef867a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

tests/test-static-code

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@ set -e
33

44
ROOTDIR=$(dirname $(readlink -f $0))/..
55

6+
# busybox grep does not know about --text
7+
if grep --help 2>/dev/null | grep -q -- --text; then
8+
GREP="grep --text"
9+
else
10+
GREP=grep
11+
fi
12+
613
# split preload code into internal logic and libc wrappers
714
CODE_INT=`grep -B 100000 'Overridden libc' $ROOTDIR/src/libumockdev-preload.c`
815
CODE_WRAPPERS=`grep -A 100000 'Overridden libc' $ROOTDIR/src/libumockdev-preload.c`
916

10-
LIBC_OVERRIDES=`echo "$CODE_WRAPPERS" | grep --text '^[a-z_]\+(' | grep -v '^WRAP_' | cut -f1 -d'('`
17+
LIBC_OVERRIDES=`echo "$CODE_WRAPPERS" | $GREP '^[a-z_]\+(' | grep -v '^WRAP_' | cut -f1 -d'('`
1118

1219
RET=0
1320

@@ -23,11 +30,11 @@ check_empty() {
2330
}
2431

2532
# internal code must not have any exported (non-static) functions
26-
R=$(echo "$CODE_INT" | grep --text -B1 '^[a-z_]\+(' | awk 'BEGIN { RS="--\n" } !/static/ { print $0 }')
33+
R=$(echo "$CODE_INT" | $GREP -B1 '^[a-z_]\+(' | awk 'BEGIN { RS="--\n" } !/static/ { print $0 }')
2734
check_empty "$R" "preload internal code part has exported function(s)"
2835

2936
# wrappers must be exported
30-
R=$(echo "$CODE_WRAPPERS" | grep --text -B1 '^[a-z_]\+(' | awk 'BEGIN { RS="--\n" } /static/ { print $0 }')
37+
R=$(echo "$CODE_WRAPPERS" | $GREP -B1 '^[a-z_]\+(' | awk 'BEGIN { RS="--\n" } /static/ { print $0 }')
3138
check_empty "$R" "preload libc wrapped code part has non-exported function(s)"
3239

3340
# wrappers must not have a '_' in the name, libc doesn't use that style
@@ -36,7 +43,7 @@ check_empty "$R" "preload libc wrapped code part exports function with '_'"
3643

3744
# must not use wrapped functions in internal logic
3845
for fn in $LIBC_OVERRIDES; do
39-
R=$(echo "$CODE_INT" | grep --text -w $fn | grep --text -Ev "(/\*|\"|libc_func|#include|^ \* ).*$fn" || true)
46+
R=$(echo "$CODE_INT" | $GREP -w $fn | $GREP -Ev "(/\*|\"|libc_func|#include|^ \* ).*$fn" || true)
4047
check_empty "$R" "preload internal code part must not use overridden libc function $fn"
4148
done
4249

0 commit comments

Comments
 (0)