Skip to content

Commit

Permalink
Fix the scripts test3{3,4,5,6}.sh
Browse files Browse the repository at this point in the history
So they work correctly on “recent” distributions.
  • Loading branch information
tleguern committed Jan 29, 2020
1 parent deafefa commit 35f3675
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 71 deletions.
28 changes: 10 additions & 18 deletions regress/test33.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,25 @@

# test33: Create a tap0 persistent device and destroy it

TEST="`pwd`/helper33"
SYSTEM=`uname`

TEST="$(pwd)/helper33"
TARGET='tap0'
TYPE='tap'

if [ "$SYSTEM" = "Linux" ]; then
IFDEL="ip tuntap del $TARGET mode $TYPE"
if [ "$(uname)" = Linux ]; then
ifdel() { ip tuntap del "$1" mode "$2"; }
ifcheck() { ip link show "$1"; }
else
IFDEL="ifconfig $TARGET destroy"
ifdel() { ifconfig "$1" destroy; }
ifcheck() { ifconfig "$1"; }
fi

OK=0
$TEST && OK=1

# If the $TEST was a success, check if the interface still exist
if [ $OK -eq 1 ]; then
ifconfig $TARGET > /dev/null && OK=2
else
if ! $TEST; then
exit 1
fi

# The $TARGET still exists, clean it and return failure
if [ $OK -eq 2 ]; then
$IFDEL
# The interface should NOT exists
if ifcheck "$TARGET"; then
ifdel "$TARGET" "$TYPE"
exit 1
fi

# Everything went fine
exit 0
26 changes: 10 additions & 16 deletions regress/test34.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,25 @@

# test34: Create a tun0 persistent device and destroy it

TEST="`pwd`/helper34"
SYSTEM=`uname`
TEST="$(pwd)/helper34"
TARGET='tun0'
TYPE='tun'

if [ "$SYSTEM" = "Linux" ]; then
IFDEL="ip tuntap del $TARGET mode $TYPE"
if [ "$(uname)" = Linux ]; then
ifdel() { ip tuntap del "$1" mode "$2"; }
ifcheck() { ip link show "$1"; }
else
IFDEL="ifconfig $TARGET destroy"
ifdel() { ifconfig "$1" destroy; }
ifcheck() { ifconfig "$1"; }
fi

OK=0
$TEST && OK=1

# The $TEST is successful
if [ $OK -eq 1 ]; then
ifconfig $TARGET && OK=2
else
if ! $TEST; then
exit 1
fi

# The $TARGET still exists
if [ $OK -eq 2 ]; then
$IFDEL
# The interface should NOT exists
if ifcheck "$TARGET"; then
ifdel "$TARGET" "$TYPE"
exit 1
fi

exit 0
30 changes: 11 additions & 19 deletions regress/test35.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,25 @@

# test35: Create a tap0 persistent device and release it

TEST="`pwd`/helper35"
SYSTEM=`uname`

TEST="$(pwd)/helper35"
TARGET='tap0'
TYPE='tap'

if [ "$SYSTEM" = "Linux" ]; then
IFDEL="ip tuntap del $TARGET mode $TYPE"
if [ "$(uname)" = Linux ]; then
ifdel() { ip tuntap del "$1" mode "$2"; }
ifcheck() { ip link show "$1"; }
else
IFDEL="ifconfig $TARGET destroy"
ifdel() { ifconfig "$1" destroy; }
ifcheck() { ifconfig "$1"; }
fi

OK=0
$TEST && OK=1

# The $TEST is successful
if [ $OK -eq 1 ]; then
ifconfig $TARGET && OK=2
else
if ! $TEST; then
exit 1
fi

# The $TARGET still exists
if [ $OK -eq 2 ]; then
$IFDEL
exit 0
else
# The interface SHOULD exists
if ! ifcheck "$TARGET"; then
exit 1
fi

ifdel "$TARGET" "$TYPE"
exit 0
30 changes: 12 additions & 18 deletions regress/test36.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,25 @@

# test36: Create a tun1 persistent device and release it

TEST="`pwd`/helper36"
SYSTEM=`uname`
TEST="$(pwd)/helper36"
TARGET='tun1'
TYPE='tun'

if [ "$SYSTEM" = "Linux" ]; then
IFDEL="ip tuntap del $TARGET mode $TYPE"
if [ "$(uname)" = Linux ]; then
ifdel() { ip tuntap del "$1" mode "$2"; }
ifcheck() { ip link show "$1"; }
else
IFDEL="ifconfig $TARGET destroy"
ifdel() { ifconfig "$1" destroy; }
ifcheck() { ifconfig "$1"; }
fi

OK=0
$TEST && OK=1

# If the $TEST was a success, check if the interface still exist
if [ $OK -eq 1 ]; then
ifconfig $TARGET && OK=2
else
if ! $TEST; then
exit 1
fi

# The $TARGET still exists, clean it and exit success
if [ $OK -eq 2 ]; then
$IFDEL
exit 0
# The interface SHOULD exists
if ! ifcheck "$TARGET"; then
exit 1
fi

exit 1
ifdel "$TARGET" "$TYPE"
exit 0

0 comments on commit 35f3675

Please sign in to comment.