Skip to content

Commit

Permalink
tests-hardening: addressing shellcheck errors in our tests
Browse files Browse the repository at this point in the history
These changes shall prepare LinuxCNC's test routines to accept blanks in file names.
  • Loading branch information
smoe committed Jan 28, 2025
1 parent 8552137 commit 9928c98
Show file tree
Hide file tree
Showing 94 changed files with 286 additions and 267 deletions.
32 changes: 21 additions & 11 deletions scripts/githelper.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/false
#shellcheck disable=SC1008
#
# This is a bash shell fragment, intended to be sourced by scripts that
# want to work with git in the emc2 repo.
Expand Down Expand Up @@ -28,63 +30,71 @@ function githelper() {
case $GIT_BRANCH in
master)
GIT_TAG_GLOB="v2.10.*"
# shellcheck disable=SC2034
DEB_COMPONENT="master"
;;
# release branches have names matching "number.number", which is awkward to express as a glob
[0-9].[0-9] | [0-9].[0-9][0-9] | [0-9].[0-9][0-9][0-9] | [0-9][0-9].[0-9] | [0-9][0-9].[0-9][0-9] | [0-9][0-9].[0-9][0-9][0-9])
GIT_TAG_GLOB="v${GIT_BRANCH}.*"
# shellcheck disable=SC2034
DEB_COMPONENT=$GIT_BRANCH
;;
v2.5_branch)
GIT_TAG_GLOB="v2.5*"
# shellcheck disable=SC2034
DEB_COMPONENT="v2.5_branch"
;;
v2.4_branch)
GIT_TAG_GLOB="v2.4*"
# shellcheck disable=SC2034
DEB_COMPONENT="v2.4_branch"
;;
*)
GIT_TAG_GLOB="*"
# shellcheck disable=SC2034
DEB_COMPONENT="scratch"
;;
esac


# use the gnupg keyring from our git repo to verify signatures on the release tags
export GNUPGHOME=$(git rev-parse --show-toplevel)/gnupg
export GNUPGHOME
GNUPGHOME=$(git rev-parse --show-toplevel)/gnupg

NEWEST_SIGNED_TAG_UTIME=-1
NEWEST_UNSIGNED_TAG_UTIME=-1
for TAG in $(git tag -l "$GIT_TAG_GLOB"); do
if ! git cat-file tag $TAG > /dev/null 2> /dev/null; then
if ! git cat-file tag "$TAG" > /dev/null 2> /dev/null; then
continue
fi

TAG_UTIME=$(git cat-file tag $TAG | grep tagger | awk '{print $(NF-1)-$NF*36}')
TAG_UTIME=$(git cat-file tag "$TAG" | grep tagger | awk '{print $(NF-1)-$NF*36}')

if git tag -v "$TAG" > /dev/null 2> /dev/null; then
# it's a valid signed tag
if [ $TAG_UTIME -gt $NEWEST_SIGNED_TAG_UTIME ]; then
NEWEST_SIGNED_TAG=$TAG
NEWEST_SIGNED_TAG_UTIME=$TAG_UTIME
if [ "$TAG_UTIME" -gt "$NEWEST_SIGNED_TAG_UTIME" ]; then
NEWEST_SIGNED_TAG="$TAG"
NEWEST_SIGNED_TAG_UTIME="$TAG_UTIME"
fi
else
# unsigned tag
if [ $TAG_UTIME -gt $NEWEST_UNSIGNED_TAG_UTIME ]; then
NEWEST_UNSIGNED_TAG=$TAG
NEWEST_UNSIGNED_TAG_UTIME=$TAG_UTIME
if [ "$TAG_UTIME" -gt "$NEWEST_UNSIGNED_TAG_UTIME" ]; then
NEWEST_UNSIGNED_TAG="$TAG"
NEWEST_UNSIGNED_TAG_UTIME="$TAG_UTIME"
fi
fi

done

if [ $NEWEST_SIGNED_TAG_UTIME -gt -1 ]; then
if [ "$NEWEST_SIGNED_TAG_UTIME" -gt -1 ]; then
# shellcheck disable=SC2034
GIT_TAG="$NEWEST_SIGNED_TAG"
return
fi

if [ $NEWEST_UNSIGNED_TAG_UTIME -gt -1 ]; then
if [ "$NEWEST_UNSIGNED_TAG_UTIME" -gt -1 ]; then
echo "no signed tags found, falling back to unsigned tags" > /dev/null 1>&2
# shellcheck disable=SC2034
GIT_TAG="$NEWEST_UNSIGNED_TAG"
return
fi
Expand Down
15 changes: 11 additions & 4 deletions tests/build/header-sanity/test.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
#!/bin/sh
set -xe
CPPFLAGS=$(pkg-config --silence-errors --cflags libtirpc)
for i in $HEADERS/*.h; do

for i in "$HEADERS"/*.h
do
case $i in
*/rtapi_app.h) continue ;;
esac
# shellcheck disable=SC2086
gcc ${CPPFLAGS} -DULAPI -I$HEADERS -E -x c $i > /dev/null
done
for i in $HEADERS/*.h $HEADERS/*.hh; do
case $i in

for i in "$HEADERS"/*.h "$HEADERS"/*.hh
do
case "$i" in
*/rtapi_app.h) continue ;;
*/interp_internal.hh) continue ;;
esac
# shellcheck disable=SC2086
if g++ ${CPPFLAGS} -std=c++11 -S -o /dev/null -xcxx /dev/null > /dev/null 2>&1; then
ELEVEN=-std=c++11
else
ELEVEN=-std=c++0x
fi
g++ ${CPPFLAGS} $ELEVEN -DULAPI -I$HEADERS -E -x c++ $i > /dev/null
# shellcheck disable=SC2086
g++ ${CPPFLAGS} $ELEVEN -DULAPI -I$HEADERS -E -x c++ "$i" > /dev/null
done
2 changes: 1 addition & 1 deletion tests/ccomp/lathe-comp/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -t test.tbl -g test.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/ccomp/mill-g90g91g92/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -t test.tbl -g test.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/ccomp/mill-line-arc-entry/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -t test.tbl -g test.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/ccomp/mill-zchanges/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -t test.tbl -g test.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/classicladder/estop/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
if [ "libeatmydata.so" = "$LD_PRELOAD" ] ; then
unset LD_PRELOAD
fi
exec linuxcnc $(dirname $0)/classicladder-estop.ini
exec linuxcnc "$(dirname "$0")"/classicladder-estop.ini
12 changes: 8 additions & 4 deletions tests/halcompile/names/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@ set -x

# this one must succeed
rm -f names_match.c
halcompile names_match.comp
if [ $? -ne 0 ]; then

if ! halcompile names_match.comp
then
echo 'halcompile failed to process names_match.comp'
exit 1
fi

if [ ! -f names_match.c ]; then
echo 'halcompile failed to produce names_match.c'
exit 1
fi

# this one must fail
rm -f names_dont_match.c
halcompile names_dont_match.comp
if [ $? -eq 0 ]; then

if ! halcompile names_dont_match.comp
then
echo 'halcompile erroneously accepted names_dont_match.comp'
exit 1
fi

if [ -f names_dont_match.c ]; then
echo 'halcompile erroneously produced names_dont_match.c'
exit 1
Expand Down
4 changes: 2 additions & 2 deletions tests/hm2-idrom/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ Error[14]="hm2/hm2_test\.0: IDROM IOPorts is 0 but llio num_ioport_connectors is
result=0

TEST_PATTERN=0
while [ ! -z "${Error[$TEST_PATTERN]}" ]; do
while [ -n "${Error[$TEST_PATTERN]}" ]; do
export TEST_PATTERN
halrun -f broken-load-test.hal >halrun-stdout 2>halrun-stderr
./check-dmesg.py "${Error[$TEST_PATTERN]}" || exit $?
TEST_PATTERN=$(($TEST_PATTERN+1))
TEST_PATTERN=$((TEST_PATTERN+1))
done

exit $result
2 changes: 1 addition & 1 deletion tests/interp/cam-nisley/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -t test.tbl -g cam.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/crazy-paths/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g test.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/do-while-break/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g test.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/exists/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g test.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/flowsnake/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g flowsnake.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/fractional-linenumbers/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g test.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/g10/g10-l1-l10/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g test.ngc -t test.tbl | awk '{$1=""; print}' | sed 's/-0\.0000/0.0000/g'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/g10/g10-l11/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g test.ngc -t test.tbl | awk '{$1=""; print}' | sed 's/-0\.0000/0.0000/g'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/g10/g10-l2-while-active/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g test.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/g10/g10-l20-while-active/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g test.ngc | awk '{$1=""; print}' | sed 's/-0\.0000/0.0000/g'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/g10/g10-with-g92/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g test.ngc -t test.tbl | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/g33.1/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g g33.1.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/g6164/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g test.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
10 changes: 5 additions & 5 deletions tests/interp/g71-endless-loop/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ pid=$!

# Give it 10 seconds to complete
count=10
while [ 0 -lt $count ] && kill -0 $pid > /dev/null 2>&1 ; do
while [ 0 -lt "$count" ] && kill -0 "$pid" > /dev/null 2>&1 ; do
sleep 1
count=$(($count - 1))
count=$((count - 1))
done

if kill -0 $pid > /dev/null 2>&1; then
kill -9 $pid
echo "error: g71-endless-loop.ngc program seem to be stuck, killing"
if kill -0 "$pid" > /dev/null 2>&1; then
kill -9 "$pid"
echo "E: g71-endless-loop.ngc program seem to be stuck, killing"
exit 1
fi

Expand Down
8 changes: 4 additions & 4 deletions tests/interp/g71-with-g70/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ pid=$!

# Give it 5 seconds to complete
count=5
while [ 0 -lt $count ] && kill -0 $pid > /dev/null 2>&1 ; do
while [ 0 -lt "$count" ] && kill -0 "$pid" > /dev/null 2>&1 ; do
sleep 1
count=$(($count - 1))
count=$((count - 1))
done

if kill -0 $pid > /dev/null 2>&1; then
kill -9 $pid
if kill -0 "$pid" > /dev/null 2>&1; then
kill -9 "$pid"
echo "error: g71_and_g70.ngc program seem to be stuck, killing"
exit 1
fi
Expand Down
10 changes: 5 additions & 5 deletions tests/interp/g72-facing/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ pid=$!

# Give it 10 seconds to complete
count=10
while [ 0 -lt $count ] && kill -0 $pid > /dev/null 2>&1 ; do
while [ 0 -lt "$count" ] && kill -0 "$pid" > /dev/null 2>&1 ; do
sleep 1
count=$(($count - 1))
count=$((count - 1))
done

if kill -0 $pid > /dev/null 2>&1; then
kill -9 $pid
echo "error: g71-iterations-present.ngc program seem to be stuck, killing"
if kill -0 "$pid" > /dev/null 2>&1; then
kill -9 "$pid"
echo "E: g71-iterations-present.ngc program seem to be stuck, killing"
exit 1
fi

Expand Down
8 changes: 4 additions & 4 deletions tests/interp/g72-missing-iteration/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ pid=$!

# Give it 10 seconds to complete
count=10
while [ 0 -lt $count ] && kill -0 $pid > /dev/null 2>&1 ; do
while [ 0 -lt "$count" ] && kill -0 "$pid" > /dev/null 2>&1 ; do
sleep 1
count=$((count - 1))
done

if kill -0 $pid > /dev/null 2>&1; then
kill -9 $pid
echo "error: g71-iterations-missing.ngc program seem to be stuck, killing"
if kill -0 "$pid" > /dev/null 2>&1; then
kill -9 "$pid"
echo "E: g71-iterations-missing.ngc program seem to be stuck, killing"
exit 1
fi

Expand Down
2 changes: 1 addition & 1 deletion tests/interp/g76/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -t test.tbl -g g76only.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/g81/g17/g98/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g g17-g98-g81.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/g81/g17/g99/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g g17-g99-g81.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/g81/g18/g98/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g g18-g98-g81.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/g81/g18/g99/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g g18-g99-g81.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/g81/g19/g98/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g g19-g98-g81.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/g81/g19/g99/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g g19-g99-g81.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/g84/g17/g98/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g g17-g98-g84.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/g84/g17/g99/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g g17-g99-g84.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/g84/g18/g98/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g g18-g98-g84.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/g84/g18/g99/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g g18-g99-g84.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
2 changes: 1 addition & 1 deletion tests/interp/g84/g19/g98/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
rs274 -g g19-g98-g84.ngc | awk '{$1=""; print}'
exit ${PIPESTATUS[0]}
exit "${PIPESTATUS[0]}"
Loading

0 comments on commit 9928c98

Please sign in to comment.