[netfilter-cvslog] r7464 - in trunk/conntrack-tools: . qa qa/testsuite

pablo at netfilter.org pablo at netfilter.org
Sun Apr 13 03:52:48 CEST 2008


Author: pablo at netfilter.org
Date: 2008-04-13 03:52:48 +0200 (Sun, 13 Apr 2008)
New Revision: 7464

Added:
   trunk/conntrack-tools/qa/
   trunk/conntrack-tools/qa/test-conntrack.c
   trunk/conntrack-tools/qa/testsuite/
   trunk/conntrack-tools/qa/testsuite/00create
   trunk/conntrack-tools/qa/testsuite/01delete
Log:
add initial automated qa testing for the conntrack cli


Added: trunk/conntrack-tools/qa/test-conntrack.c
===================================================================
--- trunk/conntrack-tools/qa/test-conntrack.c	                        (rev 0)
+++ trunk/conntrack-tools/qa/test-conntrack.c	2008-04-13 01:52:48 UTC (rev 7464)
@@ -0,0 +1,84 @@
+/* 
+ * Very simple test-tool for the command line tool `conntrack'.
+ * This code is released under GPLv2 or any later at your option.
+ *
+ * gcc test-conntrack.c -o test
+ *
+ * Do not forget that you need *root* or CAP_NET_ADMIN capabilities ;-)
+ *
+ * (c) 2008 Pablo Neira Ayuso <pablo at netfilter.org>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <dirent.h>
+
+#define CT_PROG "/usr/sbin/conntrack"
+
+int main()
+{
+	int ret, ok = 0, bad = 0;
+	FILE *fp;
+	DIR *d;
+	char buf[1024];
+	struct dirent *dent;
+	char file[1024];
+
+	d = opendir("testsuite");
+
+	while ((dent = readdir(d)) != NULL) {
+
+		sprintf(file, "testsuite/%s", dent->d_name);
+
+		fp = fopen(file, "r");
+		if (fp == NULL) {
+			perror("cannot find testsuite file");
+			exit(EXIT_FAILURE);
+		}
+
+		while (fgets(buf, sizeof(buf), fp)) {
+			char tmp[1024] = CT_PROG, *res;
+			tmp[strlen(CT_PROG)] = ' ';
+
+			if (buf[0] == '#' || buf[0] == ' ')
+				continue;
+
+			res = strchr(buf, ';');
+			*res = '\0';
+			res+=2;
+
+			strcpy(tmp + strlen(CT_PROG) + 1, buf);
+			printf("Executing: %s\n", tmp);
+
+			ret = system(tmp);
+
+			if (WIFEXITED(ret) &&
+			    WEXITSTATUS(ret) == EXIT_SUCCESS) {
+			    	if (res[0] == 'O' &&
+				    res[1] == 'K')
+					ok++;
+				else {
+					bad++;
+					printf("^----- BAD\n");
+				}
+			} else {
+				if (res[0] == 'B' &&
+				    res[1] == 'A' &&
+				    res[2] == 'D')
+					ok++;
+				else {
+					bad++;
+					printf("^----- BAD\n");
+				}
+			}
+		}
+	}
+
+	fprintf(stdout, "OK: %d BAD: %d\n", ok, bad);
+
+	fclose(fp);
+}

Added: trunk/conntrack-tools/qa/testsuite/00create
===================================================================
--- trunk/conntrack-tools/qa/testsuite/00create	                        (rev 0)
+++ trunk/conntrack-tools/qa/testsuite/00create	2008-04-13 01:52:48 UTC (rev 7464)
@@ -0,0 +1,16 @@
+#missing destination
+-I -s 1.1.1.1 -p tcp --sport 10 --dport 20 --state LISTEN -u SEEN_REPLY -t 50 ; BAD
+#missing source
+-I -d 2.2.2.2 -p tcp --sport 10 --dport 20 --state LISTEN -u SEEN_REPLY -t 50 ; BAD
+#missing protocol
+-I -s 1.1.1.1 -d 2.2.2.2 --sport 10 --dport 20 --state LISTEN -u SEEN_REPLY -t 50 ; BAD
+#missing source port
+-I -s 1.1.1.1 -d 2.2.2.2 -p tcp --dport 20 --state LISTEN -u SEEN_REPLY -t 50 ; BAD
+#missing timeout
+-I -s 1.1.1.1 -d 2.2.2.2 -p tcp --sport 10 --dport 20 --state LISTEN -u SEEN_REPLY ; BAD
+# create a conntrack
+-I -s 1.1.1.1 -d 2.2.2.2 -p tcp --sport 10 --dport 20 --state LISTEN -u SEEN_REPLY -t 50 ; OK
+# create again
+-I -s 1.1.1.1 -d 2.2.2.2 -p tcp --sport 10 --dport 20 --state LISTEN -u SEEN_REPLY -t 50 ; BAD
+# create from reply
+-I -r 2.2.2.2 -q 1.1.1.1 -p tcp --reply-port-src 11 --reply-port-dst 21 --state LISTEN -u SEEN_REPLY -t 50 ; OK

Added: trunk/conntrack-tools/qa/testsuite/01delete
===================================================================
--- trunk/conntrack-tools/qa/testsuite/01delete	                        (rev 0)
+++ trunk/conntrack-tools/qa/testsuite/01delete	2008-04-13 01:52:48 UTC (rev 7464)
@@ -0,0 +1,2 @@
+# delete
+-D -s 1.1.1.1 -d 2.2.2.2 -p tcp --sport 10 --dport 20 ; OK




More information about the netfilter-cvslog mailing list