1#!/usr/bin/env bash 2# 3# Project : ipv6calc 4# File : test_ipv6logconv.sh 5# Version : $Id: 714a225a3a138ff655b772d43861e58dcedb64fa $ 6# Copyright : 2002-2021 by Peter Bieringer <pb (at) bieringer.de> 7# 8# Test program for "ipv6logconv" 9 10if [ ! -x ./ipv6logconv ]; then 11 echo "Binary './ipv6logconv' missing or not executable" 12 exit 1 13fi 14 15# Test proper option definitions 16echo "Test proper option definition" 17./ipv6logconv -h >/dev/null 18if [ $? -ne 1 ]; then 19 echo "ERROR : something wrong in option definition" 20 exit 1 21fi 22 23echo "Run 'ipv6logconv' version help test for feature tokens..." 24./ipv6logconv -v -h 25retval=$? 26if [ $retval -ne 0 ]; then 27 echo "Error executing 'ipv6logconv -v -h'!" 28 exit 1 29fi 30echo 31 32source ../ipv6calc/test_scenarios.sh 33 34testscenarios() { 35# Address 36cat <<END | grep -v "^#" 37195.226.187.50 - - "IPv4 address" 383ffe:ffff::1 - - "IPv6 address/6bone test" 393FFE:1a05:510:200:0:5EFE:8CAD:8108 - - 40ff02::1:ff00:1234 - - 41ff01::1:ff00:1234 - - 423ffe::1:ff00:1234 - - 43::1 - - 44::2.2.3.4 - - 45::ffff:2.2.3.4 - - 462002:0102:0204::1 - - 47fe80::210:a4ff:fe01:2345 - - 48fe80::210:a489:ab01:2345 - - 493ffe:ffff::210:a4ff:fe01:2345 - - 503ffe:ffff::210:a489:ab01:2345 - - 513ffe:ffff::000:a4ff:fe01:2345 - - 523ffe:ffff::000:a489:ab01:2345 - - 533ffe:ffff::000:0250:c2ff:fe00:3011 - - "Microsoft" 54fe80::fefc:acff:fe10:fe01 - - 552.2.3.4 - - 562002:50b5:7940:0000:0000:0000:50b5:7940 - - "Microsoft 6to4 address" 57fd00:1234:5678:9abc::1 - - "Unique Local IPv6 Unicast Address" 58fd00:1234:5678:9abc:210:a489:ab01:2345 - - "Unique Local IPv6 Unicast Address" 593ffe:831f:ce49:7601:8000:efff:af4a:86BF - - Teredo 602001:db8:0123:4567:837:3b0d:a304:9141 - - Privacy IID 61END 62} 63 64testscenarios_cache() { 65# Address 66cat <<END_CACHE | grep -v "^#" 67195.226.187.50 - - "IPv4 address" 68195.226.187.50 - - "IPv4 address" 693ffe:ffff::1 - - "IPv6 address/6bone test" 703ffe:ffff::1 - - "IPv6 address/6bone test" 713ffe:ffff::1 - - "IPv6 address/6bone test" 72195.226.187.50 - - "IPv4 address" 733FFE:1a05:510:200:0:5EFE:8CAD:8108 - - 743FFE:1a05:510:200:0:5EFE:8CAD:8108 - - 753FFE:1a05:510:200:0:5EFE:8CAD:8108 - - 76195.226.187.50 - - "IPv4 address" 773ffe:ffff::1 - - "IPv6 address/6bone test" 783FFE:1a05:510:200:0:5EFE:8CAD:8108 - - 792.2.3.4 - - 802.2.3.4 - - 81195.226.187.50 - - "IPv4 address" 82::ffff:2.2.3.4 - - 832002:0102:0204::1 - - 84fe80::210:a4ff:fe01:2345 - - 85fe80::210:a489:ab01:2345 - - 863ffe:ffff::210:a4ff:fe01:2345 - - 872.2.3.4 - - 883.2.3.4 - - 894.2.3.4 - - 905.2.3.4 - - 91195.226.187.50 - - "IPv4 address" 92END_CACHE 93} 94 95#set -x 96## main ## 97echo "Run 'ipv6logconv' function tests..." >&2 98 99if ./ipv6logconv -v | grep -w "CONV_REG" | grep -w "CONV_IEEE"; then 100 true 101else 102 echo "NOTICE : ipv6logconv tests skipped, at least one required database feature is missing" 103 exit 0 104fi 105 106if [ "$1" != "bulk" ]; then 107 testscenarios | grep -v "^#" | while read line; do 108 echo 109 echo "INPUT: $line" 110 echo "$line" | ./ipv6logconv --out any -q $* 111 retval=$? 112 if [ $retval -ne 0 ]; then 113 echo "Error executing 'ipv6logconv'!" >&2 114 exit 1 115 fi 116 done || exit 1 117 echo 118else 119 shift 120 echo "Test with cache" 121 testscenarios_cache | grep -v "^#" | ./ipv6logconv --out any -q $* 122 retval=$? 123 if [ $retval -ne 0 ]; then 124 echo "Error executing 'ipv6logconv'!" >&2 125 exit 1 126 fi 127 echo "Test without cache" 128 testscenarios_cache | grep -v "^#" | ./ipv6logconv --out any -q -n $* 129 retval=$? 130 if [ $retval -ne 0 ]; then 131 echo "Error executing 'ipv6logconv'!" >&2 132 exit 1 133 fi 134 echo 135fi 136 137echo "INFO : test scenario with huge amount of addresses..." 138testscenario_hugelist ipv4 | awk '{ print $1 " token2 token3" }' | ./ipv6logconv -q --out any -q >/dev/null 139if [ $? -ne 0 ]; then 140 echo "ERROR : exit code <> 0" 141 exit 1 142fi 143 144echo "INFO : test scenario with huge amount of addresses: OK" 145 146if [ $? -eq 0 ]; then 147 echo "All tests were successfully done!" >&2 148fi 149