summaryrefslogtreecommitdiffstats
path: root/qa/test-conntrack.c
diff options
context:
space:
mode:
author/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org>2008-04-13 01:52:48 +0000
committer/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org>2008-04-13 01:52:48 +0000
commitc2f6ad83b0087a246447726a121d1694d95fc627 (patch)
treeed7510155d595afa74a7128c58fac0bd8091b315 /qa/test-conntrack.c
parentde56472737c5aa007f775bc475570f49c0e55fb3 (diff)
add initial automated qa testing for the conntrack cli
Diffstat (limited to 'qa/test-conntrack.c')
-rw-r--r--qa/test-conntrack.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/qa/test-conntrack.c b/qa/test-conntrack.c
new file mode 100644
index 0000000..c58aa8d
--- /dev/null
+++ b/qa/test-conntrack.c
@@ -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@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);
+}