Merging in vsys tests
authorSapan Bhatia <sapanb@cs.princeton.edu>
Fri, 14 Mar 2008 20:54:01 +0000 (20:54 +0000)
committerSapan Bhatia <sapanb@cs.princeton.edu>
Fri, 14 Mar 2008 20:54:01 +0000 (20:54 +0000)
qaapi/qa/tests/node/support/Makefile [new file with mode: 0644]
qaapi/qa/tests/node/support/vsys_conctest.c [new file with mode: 0644]
qaapi/qa/tests/node/vsys_launch.pl [new file with mode: 0644]

diff --git a/qaapi/qa/tests/node/support/Makefile b/qaapi/qa/tests/node/support/Makefile
new file mode 100644 (file)
index 0000000..a3d25d3
--- /dev/null
@@ -0,0 +1 @@
+all: vsys_conctest
diff --git a/qaapi/qa/tests/node/support/vsys_conctest.c b/qaapi/qa/tests/node/support/vsys_conctest.c
new file mode 100644 (file)
index 0000000..c155f80
--- /dev/null
@@ -0,0 +1,106 @@
+#include <stdio.h>
+#include <sys/select.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+int main()
+{
+  FILE *fp = NULL, *fp_in = NULL;
+  FILE *out_fp = NULL, *diff_fp = NULL;
+  const char* topcmd = "/vservers/pl_netflow/vsys/test.out";
+  const char* top_in_file = "/vservers/pl_netflow/vsys/test.in";
+  char buf[4096];
+  int fd_in = -1, fd_out;
+  int res;
+  int flag;
+  int count = 1;
+  struct timeval tv={.tv_sec=5,.tv_usec=0};
+
+  while (count < 100) {
+    fd_set readSet;
+    int res;
+    int nlines=0;
+
+    printf("(.)", count);
+
+    if ((fd_out = open(topcmd, O_RDONLY | O_NONBLOCK)) < 0) {
+      fprintf(stderr, "error executing top\n");
+      exit(-1);
+    }
+    if ((fd_in = open(top_in_file, O_WRONLY)) < 0) {
+      fprintf(stderr, "error opening %s\n", top_in_file);
+      exit(-1);
+    }
+
+    if ((flag = fcntl(fd_out, F_GETFL)) == -1) {
+      printf("fcntl get failed\n");
+      exit(-1);
+    }
+
+    FD_ZERO(&readSet);
+    FD_SET(fd_out, &readSet);
+
+    res = select(fd_out + 1, &readSet, NULL, NULL, &tv);
+    if (res < 1) {
+      printf("select failed\n");
+      exit(-1);
+    }
+
+    if (fcntl(fd_out, F_SETFL, flag & ~O_NONBLOCK) == -1) {
+      printf("fcntl set failed\n");
+      exit(-1);
+    }
+
+    if ((flag = fcntl(fd_out, F_GETFL)) == -1) {
+      printf("fcntl get failed\n");
+      exit(-1);
+    }
+
+    if (flag & O_NONBLOCK == 0) {
+      printf("fd_out still nonblocking\n");
+      exit(-1);
+    }
+
+    if ((fp = fdopen(fd_out, "r")) == NULL) {
+      printf("fdopen failed\n");
+      exit(-1);
+    }
+
+    if ((out_fp = fopen("/tmp/vsys_passwd_test", "w")) == NULL) {
+           printf("could not create tmp file for test\n");
+            exit(-1);
+    }
+
+    while (fgets(buf, sizeof(buf), fp) != NULL) {
+       fprintf(out_fp, "%s",buf);
+    }
+
+    fflush(out_fp);
+    fclose(out_fp);
+
+    if ((diff_fp = popen("/usr/bin/diff -u /tmp/vsys_passwd_test /etc/passwd","r")) == NULL) {
+           printf("Could not diff results\n");
+           exit(-1);
+    }
+
+    while (fgets(buf, sizeof(buf), diff_fp) != NULL) {
+           nlines++;
+    }
+
+    if (nlines) {
+           printf("Test returned different results - run again to verify\n");
+           exit(-1);
+    }
+
+    pclose (diff_fp);
+    fclose(fp);
+    close(fd_in);
+    count++;
+  }
+  printf("test successful.\n");
+  exit(0);
+
+}
diff --git a/qaapi/qa/tests/node/vsys_launch.pl b/qaapi/qa/tests/node/vsys_launch.pl
new file mode 100644 (file)
index 0000000..40317c0
--- /dev/null
@@ -0,0 +1,43 @@
+#!/usr/bin/perl
+
+# Subtest #1 Create new vsys entry
+
+print "Creating entries...\t";
+
+$vsys_entry="#!/bin/bash\n\ncat /etc/passwd";
+$vsys_entry_acl = "/vservers/pl_netflow pl_netflow";
+
+open ACL,">/vsys/test.acl" || die ("Could not create acl for test entry.");
+print ACL $vsys_entry_acl;
+close ACL;
+
+open FIL,">/vsys/test" || die ("Could not create test entry.");
+print FIL $vsys_entry;
+close $vsys_entry;
+
+chmod 0755,"/vsys/test";
+
+# Check if it has shown up
+
+(-f "/vservers/pl_netflow/test.in") || die ("in file didn't show up in the slice");
+(-f "/vservers/pl_netflow/test.out") || die ("out file didn't show up in the slice");
+
+# OK, SUBTEST #1 SUCCEEDED
+print "(success)\n";
+
+# Subtest #2 
+
+print "Multiple-connection test...\t";
+system("su -c support/vsys_conctest pl_netflow -");
+($? && die ("Multiple-connection test failed\n"));
+
+
+# OK, SUBTEST #2 SUCCEEDED
+print "(success)\n";
+
+# Subtest #3
+unlink "/vsys/test.acl";
+unlink "/vsys/test";
+
+(-f "/vservers/pl_netflow/test.in" || -f "/vservers/pl_netflow/test.out") && die ("cleanup failed");
+