aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBill Nottingham <notting@redhat.com>2009-07-29 15:57:54 -0400
committerBill Nottingham <notting@redhat.com>2009-07-29 15:57:54 -0400
commit3532aba190ca6bad047ad487d73dc453c6b192a1 (patch)
treeef87ad5f950fd43e53f9880d9145230519fb92c7 /src
parent9ead19d019eb9df05dc608cff58ba88cba2ba29f (diff)
downloadinitscripts-3532aba190ca6bad047ad487d73dc453c6b192a1.tar
initscripts-3532aba190ca6bad047ad487d73dc453c6b192a1.tar.gz
initscripts-3532aba190ca6bad047ad487d73dc453c6b192a1.tar.bz2
initscripts-3532aba190ca6bad047ad487d73dc453c6b192a1.tar.xz
initscripts-3532aba190ca6bad047ad487d73dc453c6b192a1.zip
Add some simple regression tests for ipcalc
Adapted from tests from Matej Susta <msusta@redhat.com>.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile3
-rwxr-xr-xsrc/ipcalc-tests86
2 files changed, 89 insertions, 0 deletions
diff --git a/src/Makefile b/src/Makefile
index 0577adcd..248855b2 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -12,6 +12,9 @@ mandir=/usr/share/man
all: $(PROGS)
+check: all
+ ./ipcalc-tests
+
clean:
rm -f $(PROGS) *.o
diff --git a/src/ipcalc-tests b/src/ipcalc-tests
new file mode 100755
index 00000000..0cedbc43
--- /dev/null
+++ b/src/ipcalc-tests
@@ -0,0 +1,86 @@
+#!/bin/bash
+#
+# Run some simple ipcalc tests.
+#
+# Adapted from: Matej Susta <msusta@redhat.com>
+#
+# Copyright (c) 2009 Red Hat, Inc. All rights reserved.
+#
+# This copyrighted material is made available to anyone wishing
+# to use, modify, copy, or redistribute it subject to the terms
+# and conditions of the GNU General Public License version 2.
+#
+# This program is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this program; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+exitcode=0
+
+ok() {
+ echo "ok."
+}
+
+fail() {
+ echo "FAILED!"
+ exitcode=$((exitcode+1))
+ echo -e "Output was:\n$output"
+}
+
+TestSuccess() {
+ echo -n "Checking $@... "
+ output=$(sh -c "$1" 2>&1)
+ rc=$?
+ [ $rc -eq 0 ] && ok || fail $output
+}
+
+TestFailure() {
+ echo -n "Checking $@... "
+ output=$(sh -c "$1" 2>&1)
+ rc=$?
+ [ $rc -eq 0 ] && fail $output || ok
+}
+
+TestOutput() {
+ echo -n "Checking $1... "
+ output=$(sh -c "$1" 2>&1)
+ rc=$?
+ [ "$output" = "$2" ] && ok || fail $output
+}
+
+echo -n "Checking for ipcalc binary... "
+[ -x ./ipcalc ] || { fail ; exit $exitcode ; }
+
+TestSuccess "ipcalc --help"
+
+TestSuccess "ipcalc -c 127.0.0.1"
+TestSuccess "ipcalc -c -6 ::1"
+TestSuccess "ipcalc -c ::1"
+
+TestSuccess "ipcalc -c 192.168.1.1"
+TestSuccess "ipcalc -c -6 2a01:198:200:300::2"
+TestSuccess "ipcalc -c -6 2a01:198:200:300:0000:0000:0000:2"
+TestSuccess "ipcalc -c -6 2a01:0198:0200:0300:0000:0000:0000:0002"
+
+TestFailure "ipcalc -c -6 gggg::"
+TestFailure "ipcalc -b -6 ::1/128"
+
+TestOutput "ipcalc -b 192.168.1.1/24" "BROADCAST=192.168.1.255"
+TestOutput "ipcalc -b 192.168.1.1 255.255.255.0" "BROADCAST=192.168.1.255"
+TestOutput "ipcalc -m 192.168.1.1/24" "NETMASK=255.255.255.0"
+TestOutput "ipcalc -p 192.168.1.1 255.255.255.0" "PREFIX=24"
+TestOutput "ipcalc -p 192.168.1.1 255.255.255.255" "PREFIX=32"
+TestOutput "ipcalc -p 192.168.1.1 0.0.0.0" "PREFIX=0"
+TestOutput "ipcalc -p 172.16.59.222 255.255.252.0" "PREFIX=22"
+TestOutput "ipcalc -m 172.16.59.222/22" "NETMASK=255.255.252.0"
+TestOutput "ipcalc -m 192.168.1.1" "NETMASK=255.255.255.0"
+TestOutput "ipcalc -m 10.1.2.3" "NETMASK=255.0.0.0"
+TestOutput "ipcalc -m 129.22.4.3" "NETMASK=255.255.0.0"
+
+echo "$exitcode tests failed."
+exit $exitcode