Skip to content

Commit ba9fd89

Browse files
committed
Script Portability
1. The openssl interop test script should check that it should run before doing anything else. 2. The process to create a random port number was using a non-portable option to the head command. Changed to use the od tool reading from /dev/random. 3. Ran into a sed that doesn't use the -i option, so changed it to cp its own bak file and sed from that.
1 parent c4fee4c commit ba9fd89

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

fips-check.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,9 @@ if [ "x$CAVP_SELFTEST_ONLY" == "xno" ];
346346
then
347347
NEWHASH=$(./wolfcrypt/test/testwolfcrypt | sed -n 's/hash = \(.*\)/\1/p')
348348
if [ -n "$NEWHASH" ]; then
349-
sed -i.bak "s/^\".*\";/\"${NEWHASH}\";/" $CRYPT_SRC_PATH/fips_test.c
350-
$MAKE clean
349+
cp $CRYPT_SRC_PATH/fips_test.c $CRYPT_SRC_PATH/fips_test.c.bak
350+
sed "s/^\".*\";/\"${NEWHASH}\";/" $CRYPT_SRC_PATH/fips_test.c.bak >$CRYPT_SRC_PATH/fips_test.c
351+
make clean
351352
fi
352353
fi
353354

fips-hash.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ fi
1515
NEWHASH=$(./wolfcrypt/test/testwolfcrypt | sed -n 's/hash = \(.*\)/\1/p')
1616
if test -n "$NEWHASH"
1717
then
18-
sed -i.bak "s/^\".*\";/\"${NEWHASH}\";/" wolfcrypt/src/fips_test.c
18+
cp wolfcrypt/src/fips_test.c wolfcrypt/src/fips_test.c.bak
19+
sed "s/^\".*\";/\"${NEWHASH}\";/" wolfcrypt/src/fips_test.c.bak >wolfcrypt/src/fips_test.c
1920
fi
2021

scripts/openssl.test

+8-11
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
#openssl.test
44

5+
if test -n "$WOLFSSL_OPENSSL_TEST"; then
6+
echo "WOLFSSL_OPENSSL_TEST set, running test..."
7+
else
8+
echo "WOLFSSL_OPENSSL_TEST NOT set, won't run"
9+
exit 0
10+
fi
11+
512
# need a unique port since may run the same time as testsuite
613
generate_port() {
7-
port=`LC_CTYPE=C tr -cd 0-9 </dev/urandom | head -c 7`
8-
port=$((`LC_CTYPE=C tr -cd 1-9 </dev/urandom | head -c 1`$port))
9-
port=$(($port % (65535-49512)))
10-
port=$(($port + 49512))
14+
port=$(($(od -An -N2 /dev/random) % (65535-49512) + 49512))
1115
}
1216

1317

@@ -68,13 +72,6 @@ do_trap() {
6872

6973
trap do_trap INT TERM
7074

71-
if test -n "$WOLFSSL_OPENSSL_TEST"; then
72-
echo "WOLFSSL_OPENSSL_TEST set, running test..."
73-
else
74-
echo "WOLFSSL_OPENSSL_TEST NOT set, won't run"
75-
exit 0
76-
fi
77-
7875
echo -e "\nTesting existence of openssl command...\n"
7976
command -v $OPENSSL >/dev/null 2>&1 || { echo >&2 "Requires openssl command, but it's not installed. Ending."; exit 0; }
8077

0 commit comments

Comments
 (0)