From fee97d39829f1b54176d9db75d84fc2bd8d023df Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sun, 25 May 2014 21:44:41 +0200 Subject: [PATCH] Remove old tests for tinc 1.1 and add a basic test for MeshLink. --- test/Makefile.am | 23 ++--- test/basic.test | 20 +---- test/commandline.test | 49 ---------- test/executables.test | 8 -- test/import-export.test | 64 ------------- test/invite-join.test | 49 ---------- test/ns-ping.test | 70 --------------- test/ping.test | 58 ------------ test/pong.c | 194 ---------------------------------------- test/sptps-basic.test | 28 ------ test/testlib.sh | 49 ---------- test/variables.test | 88 ------------------ 12 files changed, 7 insertions(+), 693 deletions(-) delete mode 100755 test/commandline.test delete mode 100755 test/executables.test delete mode 100755 test/import-export.test delete mode 100755 test/invite-join.test delete mode 100755 test/ns-ping.test delete mode 100755 test/ping.test delete mode 100644 test/pong.c delete mode 100755 test/sptps-basic.test delete mode 100644 test/testlib.sh delete mode 100755 test/variables.test diff --git a/test/Makefile.am b/test/Makefile.am index 5457b2fc..2b72a0a4 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,24 +1,11 @@ TESTS = \ - basic.test \ - commandline.test \ - executables.test \ - import-export.test \ - invite-join.test \ - ns-ping.test \ - ping.test \ - sptps-basic.test \ - variables.test + basic.test dist_check_SCRIPTS = $(TESTS) -EXTRA_DIST = testlib.sh +AM_CPPFLAGS = -I../src -check_PROGRAMS = pong +check_PROGRAMS = basic -pong_SOURCES = pong.c - -clean-local: - -for pid in *.test.?/pid; do ../src/tinc --pidfile="$$pid" stop; done - -killall ../src/sptps_test - -killall pong - -rm -rf *.test.? +basic_SOURCES = basic.c +basic_LDADD = ../src/libmeshlink.la diff --git a/test/basic.test b/test/basic.test index b181e754..e67c92a4 100755 --- a/test/basic.test +++ b/test/basic.test @@ -1,20 +1,4 @@ #!/bin/sh -. ./testlib.sh - -# Initialize and test one node - -$tinc $c1 init foo -$tinc $c1 set DeviceType dummy -$tinc $c1 set Port 0 - -# Test running in the foreground - -(sleep 1; $tinc $c1 stop) & -$tinc $c1 start $r1 -D - -# Test running tinc in the background - -$tinc $c1 start $r1 -sleep 1 -$tinc $c1 stop +rm -Rf basic_conf +./basic diff --git a/test/commandline.test b/test/commandline.test deleted file mode 100755 index e95c9535..00000000 --- a/test/commandline.test +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh - -. ./testlib.sh - -# Initialize one node - -$tinc $c1 <$d1/tinc-up <$d1/tinc-up <$d2/tinc-up <$d1/tinc-up < - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - 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. -*/ - -#include "../src/system.h" - -uint8_t mymac[6] = {6, 5, 5, 6, 5, 5}; - -static ssize_t do_arp(uint8_t *buf, ssize_t len, struct sockaddr_in *in) { - struct ether_arp arp; - memcpy(&arp, buf + 14, sizeof arp); - - // Is it a valid ARP request? - if(ntohs(arp.arp_hrd) != ARPHRD_ETHER || ntohs(arp.arp_pro) != ETH_P_IP || arp.arp_hln != ETH_ALEN || arp.arp_pln != sizeof in->sin_addr.s_addr || ntohs(arp.arp_op) != ARPOP_REQUEST) - return 0; - - // Does it match our address? - if(memcmp(&in->sin_addr.s_addr, arp.arp_tpa, 4)) - return 0; - - // Swap addresses - memcpy(buf, buf + 6, 6); - memcpy(buf + 6, mymac, 6); - - arp.arp_op = htons(ARPOP_REPLY); - memcpy(arp.arp_tpa, arp.arp_spa, sizeof arp.arp_tpa); - memcpy(arp.arp_tha, arp.arp_sha, sizeof arp.arp_tha); - memcpy(arp.arp_spa, &in->sin_addr.s_addr, sizeof in->sin_addr.s_addr); - memcpy(arp.arp_sha, mymac, 6); - - memcpy(buf + 14, &arp, sizeof arp); - - return len; -} - -static ssize_t do_ipv4(uint8_t *buf, ssize_t len, struct sockaddr_in *in) { - struct ip ip; - struct icmp icmp; - - // Does it match our address? - if(memcmp(buf, mymac, 6)) - return 0; - - memcpy(&ip, buf + 14, sizeof ip); - if(memcmp(&ip.ip_dst, &in->sin_addr.s_addr, 4)) - return 0; - - // Is it an ICMP echo request? - if(ip.ip_p != IPPROTO_ICMP) - return 0; - - memcpy(&icmp, buf + 14 + sizeof ip, sizeof icmp); - if(icmp.icmp_type != ICMP_ECHO) - return 0; - - // Return an echo reply - memcpy(buf, buf + 6, 6); - memcpy(buf + 6, mymac, 6); - - ip.ip_dst = ip.ip_src; - memcpy(&ip.ip_src, &in->sin_addr.s_addr, 4); - - icmp.icmp_type = ICMP_ECHOREPLY; - - memcpy(buf + 14, &ip, sizeof ip); - memcpy(buf + 14 + sizeof ip, &icmp, sizeof icmp); - - return len; -} - -static ssize_t do_ipv6(uint8_t *buf, ssize_t len, struct sockaddr_in6 *in) { - return 0; -} - -int main(int argc, char *argv[]) { - if(argc != 4) { - fprintf(stderr, "Usage: %s \n", argv[0]); - return 1; - } - - struct addrinfo hints = {}, *ai = NULL; - hints.ai_socktype = SOCK_DGRAM; - hints.ai_flags = AI_ADDRCONFIG; - - errno = ENOENT; - if(getaddrinfo(argv[1], argv[2], &hints, &ai) || !ai) { - fprintf(stderr, "Could not resolve %s port %s: %s\n", argv[1], argv[2], strerror(errno)); - return 1; - } - - int fd; - fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); - if(!fd) { - fprintf(stderr, "Could not create socket: %s\n", strerror(errno)); - return 1; - } - - static const int one = 1; - setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof one); - - if(bind(fd, ai->ai_addr, ai->ai_addrlen)) { - fprintf(stderr, "Could not bind socket: %s\n", strerror(errno)); - return 1; - } - - switch(ai->ai_family) { - case AF_INET: { - struct ip_mreq mreq; - struct sockaddr_in in; - memcpy(&in, ai->ai_addr, sizeof in); - mreq.imr_multiaddr.s_addr = in.sin_addr.s_addr; - mreq.imr_interface.s_addr = htonl(INADDR_ANY); - if(setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof mreq)) { - fprintf(stderr, "Cannot join multicast group: %s\n", strerror(errno)); - return 1; - } -#ifdef IP_MULTICAST_LOOP - setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, (const void *)&one, sizeof one); -#endif - } break; - -#ifdef IPV6_JOIN_GROUP - case AF_INET6: { - struct ipv6_mreq mreq; - struct sockaddr_in6 in6; - memcpy(&in6, ai->ai_addr, sizeof in6); - memcpy(&mreq.ipv6mr_multiaddr, &in6.sin6_addr, sizeof mreq.ipv6mr_multiaddr); - mreq.ipv6mr_interface = in6.sin6_scope_id; - if(setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, (void *)&mreq, sizeof mreq)) { - fprintf(stderr, "Cannot join multicast group: %s\n", strerror(errno)); - return 1; - } -#ifdef IPV6_MULTICAST_LOOP - setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, (const void *)&one, sizeof one); -#endif - } break; -#endif - - default: - fprintf(stderr, "Multicast for address family %hx unsupported\n", ai->ai_family); - return 1; - } - - errno = ENOENT; - struct addrinfo *ai2 = NULL; - if(getaddrinfo(argv[3], NULL, &hints, &ai2) || !ai2) { - fprintf(stderr, "Could not resolve %s: %s\n", argv[3], strerror(errno)); - return 1; - } - - while(true) { - uint8_t buf[10000]; - struct sockaddr src; - socklen_t srclen; - ssize_t len = recvfrom(fd, buf, sizeof buf, 0, &src, &srclen); - if(len <= 0) - break; - - // Ignore short packets. - if(len < 14) - continue; - - uint16_t type = buf[12] << 8 | buf[13]; - - if(ai2->ai_family == AF_INET && type == ETH_P_IP) - len = do_ipv4(buf, len, (struct sockaddr_in *)ai2->ai_addr); - else if(ai2->ai_family == AF_INET && type == ETH_P_ARP) - len = do_arp(buf, len, (struct sockaddr_in *)ai2->ai_addr); - else if(ai2->ai_family == AF_INET6 && type == ETH_P_IPV6) - len = do_ipv6(buf, len, (struct sockaddr_in6 *)ai2->ai_addr); - else - continue; - - if(len > 0) - sendto(fd, buf, len, 0, ai->ai_addr, ai->ai_addrlen); - } - - return 0; -} diff --git a/test/sptps-basic.test b/test/sptps-basic.test deleted file mode 100755 index 644a31e0..00000000 --- a/test/sptps-basic.test +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -. ./testlib.sh - -# Generate keys - -mkdir -p $d1 - -$sptps_keypair $d1/server.priv $d1/server.pub -$sptps_keypair $d1/client.priv $d1/client.pub - -# Test transfer of a simple file. - -(sleep 1; $sptps_test -q $d1/client.priv $d1/server.pub localhost 32750 <../README) & -$sptps_test $d1/server.priv $d1/client.pub 32750 >$d1/out1 -cmp $d1/out1 ../README - -$sptps_test -q $d1/server.priv $d1/client.pub 32750 <../NEWS & -sleep 1 -$sptps_test $d1/client.priv $d1/server.pub localhost 32750 > $d1/out2 -cmp $d1/out2 ../NEWS - -# Datagram mode - -$sptps_test -dq $d1/server.priv $d1/client.pub 32750 <../COPYING & -sleep 1 -sleep 1 | $sptps_test -dq $d1/client.priv $d1/server.pub localhost 32750 >$d1/out3 -cmp $d1/out3 ../COPYING diff --git a/test/testlib.sh b/test/testlib.sh deleted file mode 100644 index 31033352..00000000 --- a/test/testlib.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh - -# Paths to executables - -tincd=../src/tincd -tinc=../src/tinc -sptps_test=../src/sptps_test -sptps_keypair=../src/sptps_keypair - -# Test directories - -case "$_" in - /*) - d1=$_.1 - d2=$_.2 - d3=$_.3 - ;; - *) - d1=$PWD/$_.1 - d2=$PWD/$_.2 - d3=$PWD/$_.3 - ;; -esac - -# Default arguments for both tinc and tincd - -c1="--config=$d1 --pidfile=$d1/pid" -c2="--config=$d2 --pidfile=$d2/pid" -c3="--config=$d3 --pidfile=$d3/pid" - -# Arguments when running tincd - -r1="--logfile=$d1/log -d5" -r2="--logfile=$d2/log -d5" -r3="--logfile=$d3/log -d5" - -# Check for leftover tinc daemons - -[ -f $d1/pid ] && $tinc $c1 stop -[ -f $d2/pid ] && $tinc $c2 stop -[ -f $d3/pid ] && $tinc $c3 stop - -# Remove test directories - -rm -rf $d1 $d2 $d3 - -# Exit on errors, log all commands being executed - -set -ex diff --git a/test/variables.test b/test/variables.test deleted file mode 100755 index 4cf9d5e5..00000000 --- a/test/variables.test +++ /dev/null @@ -1,88 +0,0 @@ -#!/bin/sh - -. ./testlib.sh - -# Initialize one node - -$tinc $c1 init foo -test "`$tinc $c1 get Name`" = "foo" - -# Test case sensitivity - -$tinc $c1 set Mode switch -test "`$tinc $c1 get Mode`" = "switch" -test "`$tinc $c1 get mode`" = "switch" -$tinc $c1 set mode router -test "`$tinc $c1 get Mode`" = "router" -test "`$tinc $c1 get mode`" = "router" -$tinc $c1 set Mode Switch -test "`$tinc $c1 get Mode`" = "Switch" - -# Test deletion - -$tinc $c1 del Mode hub && exit 1 || true -$tinc $c1 del Mode switch -test -z "`$tinc $c1 get Mode`" - -# There can only be one Mode variable - -$tinc $c1 add Mode switch -$tinc $c1 add Mode hub -test "`$tinc $c1 get Mode`" = "hub" - -# Test addition/deletion of multivalued variables - -$tinc $c1 add Subnet 1 -$tinc $c1 add Subnet 2 -$tinc $c1 add Subnet 2 -$tinc $c1 add Subnet 3 -test "`$tinc $c1 get Subnet`" = "1 -2 -2 -3" -$tinc $c1 del Subnet 2 -test "`$tinc $c1 get Subnet`" = "1 -3" -$tinc $c1 del Subnet -test -z "`$tinc $c1 get Subnet`" - -# We should not be able to get/set server variables using node.variable syntax - -test -z "`$tinc $c1 get foo.Name`" -$tinc $c1 set foo.Name bar && exit 1 || true - -# Test getting/setting host variables for other nodes - -touch $d1/hosts/bar - -$tinc $c1 add bar.PMTU 1 -$tinc $c1 add bar.PMTU 2 -test "`$tinc $c1 get bar.PMTU`" = "2" - -$tinc $c1 add bar.Subnet 1 -$tinc $c1 add bar.Subnet 2 -$tinc $c1 add bar.Subnet 2 -$tinc $c1 add bar.Subnet 3 -test "`$tinc $c1 get bar.Subnet`" = "1 -2 -2 -3" -$tinc $c1 del bar.Subnet 2 -test "`$tinc $c1 get bar.Subnet`" = "1 -3" -$tinc $c1 del bar.Subnet -test -z "`$tinc $c1 get bar.Subnet`" - -# We should not be able to get/set for nodes with invalid names - -touch $d1/hosts/qu-ux - -$tinc $c1 set qu-ux.Subnet 1 && exit 1 || true - -# We should not be able to set obsolete variables unless forced - -$tinc $c1 set PrivateKey 12345 && exit 1 || true -$tinc $c1 --force set PrivateKey 12345 -test "`$tinc $c1 get PrivateKey`" = "12345" -$tinc $c1 del PrivateKey -test -z "`$tinc $c1 get PrivateKey`" -- 2.39.2