tests: Improve vconn tests.
authorBen Pfaff <blp@nicira.com>
Fri, 8 Jan 2010 17:41:29 +0000 (09:41 -0800)
committerBen Pfaff <blp@nicira.com>
Fri, 8 Jan 2010 17:41:29 +0000 (09:41 -0800)
m4/openvswitch.m4
tests/atlocal.in
tests/automake.mk
tests/library.at
tests/test-vconn.c
tests/testsuite.at
tests/vconn.at [new file with mode: 0644]

index f9b7e57..6f30792 100644 (file)
@@ -1,6 +1,6 @@
 # -*- autoconf -*-
 
-# Copyright (c) 2008, 2009 Nicira Networks.
+# Copyright (c) 2008, 2009, 2010 Nicira Networks.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -93,6 +93,7 @@ AC_DEFUN([OVS_CHECK_OPENSSL],
    OpenFlow connections over SSL will not be supported.])])
 
    fi
+   AC_SUBST([HAVE_OPENSSL])
    AM_CONDITIONAL([HAVE_OPENSSL], [test "$HAVE_OPENSSL" = yes])
    if test "$HAVE_OPENSSL" = yes; then
       AC_DEFINE([HAVE_OPENSSL], [1], [Define to 1 if OpenSSL is installed.])
index d0ca704..d0149c1 100644 (file)
@@ -1,3 +1,4 @@
 # -*- shell-script -*-
 PERL='@PERL@'
 LCOV='@LCOV@'
+HAVE_OPENSSL='@HAVE_OPENSSL@'
index 9d6623b..ee738d1 100644 (file)
@@ -8,6 +8,7 @@ TESTSUITE_AT = \
        tests/testsuite.at \
        tests/lcov-pre.at \
        tests/library.at \
+       tests/vconn.at \
        tests/dir_name.at \
        tests/aes128.at \
        tests/uuid.at \
index eab1424..bbc5170 100644 (file)
@@ -34,8 +34,3 @@ AT_CLEANUP
 AT_SETUP([test type properties])
 OVS_CHECK_LCOV([test-type-props], [0], [ignore])
 AT_CLEANUP
-
-AT_SETUP([test vconn library])
-AT_CHECK([cp $abs_top_srcdir/tests/testpki*.pem .])
-OVS_CHECK_LCOV([test-vconn], [0], [], [ignore])
-AT_CLEANUP
index 948f30a..c118af9 100644 (file)
@@ -21,6 +21,7 @@
 #include <signal.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include "command-line.h"
 #include "poll-loop.h"
 #include "socket-util.h"
 #include "stream.h"
@@ -64,6 +65,12 @@ check_errno(int a, int b, const char *as, const char *file, int line)
 static void
 fpv_create(const char *type, struct fake_pvconn *fpv)
 {
+    if (!strcmp(type, "ssl")) {
+        stream_ssl_set_private_key_file("testpki-privkey.pem");
+        stream_ssl_set_certificate_file("testpki-cert.pem");
+        stream_ssl_set_ca_cert_file("testpki-cacert.pem", false);
+    }
+
     fpv->type = type;
     if (!strcmp(type, "unix")) {
         static int unix_count = 0;
@@ -125,11 +132,15 @@ fpv_destroy(struct fake_pvconn *fpv)
 /* Connects to a fake_pvconn with vconn_open(), then closes the listener and
  * verifies that vconn_connect() reports 'expected_error'. */
 static void
-test_refuse_connection(const char *type, int expected_error)
+test_refuse_connection(int argc UNUSED, char *argv[])
 {
+    const char *type = argv[1];
+    int expected_error;
     struct fake_pvconn fpv;
     struct vconn *vconn;
 
+    expected_error = !strcmp(type, "unix") ? EPIPE : ECONNRESET;
+
     fpv_create(type, &fpv);
     CHECK_ERRNO(vconn_open(fpv.vconn_name, OFP_VERSION, &vconn), 0);
     fpv_close(&fpv);
@@ -143,11 +154,17 @@ test_refuse_connection(const char *type, int expected_error)
  * closes it immediately, and verifies that vconn_connect() reports
  * 'expected_error'. */
 static void
-test_accept_then_close(const char *type, int expected_error)
+test_accept_then_close(int argc UNUSED, char *argv[])
 {
+    const char *type = argv[1];
+    int expected_error;
     struct fake_pvconn fpv;
     struct vconn *vconn;
 
+    expected_error = (!strcmp(type, "unix") ? EPIPE
+                      : !strcmp(type, "tcp") ? ECONNRESET
+                      : EPROTO);
+
     fpv_create(type, &fpv);
     CHECK_ERRNO(vconn_open(fpv.vconn_name, OFP_VERSION, &vconn), 0);
     vconn_run(vconn);
@@ -162,8 +179,9 @@ test_accept_then_close(const char *type, int expected_error)
  * reads the hello message from it, then closes the connection and verifies
  * that vconn_connect() reports 'expected_error'. */
 static void
-test_read_hello(const char *type, int expected_error)
+test_read_hello(int argc UNUSED, char *argv[])
 {
+    const char *type = argv[1];
     struct fake_pvconn fpv;
     struct vconn *vconn;
     struct stream *stream;
@@ -195,7 +213,7 @@ test_read_hello(const char *type, int expected_error)
        poll_block();
     }
     stream_close(stream);
-    CHECK_ERRNO(vconn_connect(vconn), expected_error);
+    CHECK_ERRNO(vconn_connect(vconn), ECONNRESET);
     vconn_close(vconn);
 }
 
@@ -290,8 +308,9 @@ test_send_hello(const char *type, const void *out, size_t out_size,
 
 /* Try connecting and sending a normal hello, which should succeed. */
 static void
-test_send_plain_hello(const char *type)
+test_send_plain_hello(int argc UNUSED, char *argv[])
 {
+    const char *type = argv[1];
     struct ofp_header hello;
 
     hello.version = OFP_VERSION;
@@ -305,8 +324,9 @@ test_send_plain_hello(const char *type)
  * the specification says that implementations must accept and ignore extra
  * data). */
 static void
-test_send_long_hello(const char *type)
+test_send_long_hello(int argc UNUSED, char *argv[])
 {
+    const char *type = argv[1];
     struct ofp_header hello;
     char buffer[sizeof hello * 2];
 
@@ -322,8 +342,9 @@ test_send_long_hello(const char *type)
 /* Try connecting and sending an echo request instead of a hello, which should
  * fail with EPROTO. */
 static void
-test_send_echo_hello(const char *type)
+test_send_echo_hello(int argc UNUSED, char *argv[])
 {
+    const char *type = argv[1];
     struct ofp_header echo;
 
     echo.version = OFP_VERSION;
@@ -336,8 +357,9 @@ test_send_echo_hello(const char *type)
 /* Try connecting and sending a hello packet that has its length field as 0,
  * which should fail with EPROTO. */
 static void
-test_send_short_hello(const char *type)
+test_send_short_hello(int argc UNUSED, char *argv[])
 {
+    const char *type = argv[1];
     struct ofp_header hello;
 
     memset(&hello, 0, sizeof hello);
@@ -347,8 +369,9 @@ test_send_short_hello(const char *type)
 /* Try connecting and sending a hello packet that has a bad version, which
  * should fail with EPROTO. */
 static void
-test_send_invalid_version_hello(const char *type)
+test_send_invalid_version_hello(int argc UNUSED, char *argv[])
 {
+    const char *type = argv[1];
     struct ofp_header hello;
 
     hello.version = OFP_VERSION - 1;
@@ -358,48 +381,31 @@ test_send_invalid_version_hello(const char *type)
     test_send_hello(type, &hello, sizeof hello, EPROTO);
 }
 
+static const struct command commands[] = {
+    {"refuse-connection", 1, 1, test_refuse_connection},
+    {"accept-then-close", 1, 1, test_accept_then_close},
+    {"read-hello", 1, 1, test_read_hello},
+    {"send-plain-hello", 1, 1, test_send_plain_hello},
+    {"send-long-hello", 1, 1, test_send_long_hello},
+    {"send-echo-hello", 1, 1, test_send_echo_hello},
+    {"send-short-hello", 1, 1, test_send_short_hello},
+    {"send-invalid-version-hello", 1, 1, test_send_invalid_version_hello},
+    {NULL, 0, 0, NULL},
+};
+
 int
-main(int argc UNUSED, char *argv[])
+main(int argc, char *argv[])
 {
     set_program_name(argv[0]);
     time_init();
     vlog_init();
+    vlog_set_levels(VLM_ANY_MODULE, VLF_ANY_FACILITY, VLL_EMER);
+    vlog_set_levels(VLM_ANY_MODULE, VLF_CONSOLE, VLL_DBG);
     signal(SIGPIPE, SIG_IGN);
 
     time_alarm(10);
 
-    test_refuse_connection("unix", EPIPE);
-    test_accept_then_close("unix", EPIPE);
-    test_read_hello("unix", ECONNRESET);
-    test_send_plain_hello("unix");
-    test_send_long_hello("unix");
-    test_send_echo_hello("unix");
-    test_send_short_hello("unix");
-    test_send_invalid_version_hello("unix");
-
-    test_accept_then_close("tcp", ECONNRESET);
-    test_refuse_connection("tcp", ECONNRESET);
-    test_read_hello("tcp", ECONNRESET);
-    test_send_plain_hello("tcp");
-    test_send_long_hello("tcp");
-    test_send_echo_hello("tcp");
-    test_send_short_hello("tcp");
-    test_send_invalid_version_hello("tcp");
-
-#ifdef HAVE_OPENSSL
-    stream_ssl_set_private_key_file("testpki-privkey.pem");
-    stream_ssl_set_certificate_file("testpki-cert.pem");
-    stream_ssl_set_ca_cert_file("testpki-cacert.pem", false);
-
-    test_accept_then_close("ssl", EPROTO);
-    test_refuse_connection("ssl", ECONNRESET);
-    test_read_hello("ssl", ECONNRESET);
-    test_send_plain_hello("ssl");
-    test_send_long_hello("ssl");
-    test_send_echo_hello("ssl");
-    test_send_short_hello("ssl");
-    test_send_invalid_version_hello("ssl");
-#endif  /* HAVE_OPENSSL */
+    run_command(argc - 1, argv + 1, commands);
 
     return 0;
 }
index ceded7e..f99b438 100644 (file)
@@ -1,6 +1,6 @@
 AT_INIT
 
-AT_COPYRIGHT([Copyright (c) 2009 Nicira Networks.
+AT_COPYRIGHT([Copyright (c) 2009, 2010 Nicira Networks.
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@ m4_define([OVS_WAIT_UNTIL],
 
 m4_include([tests/lcov-pre.at])
 m4_include([tests/library.at])
+m4_include([tests/vconn.at])
 m4_include([tests/dir_name.at])
 m4_include([tests/aes128.at])
 m4_include([tests/uuid.at])
diff --git a/tests/vconn.at b/tests/vconn.at
new file mode 100644 (file)
index 0000000..7d2afa3
--- /dev/null
@@ -0,0 +1,22 @@
+m4_define([TEST_VCONN_CLASS],
+  [AT_BANNER([vconn library -- $1 class])
+   m4_foreach(
+     [testname], 
+     [[refuse-connection], 
+      [accept-then-close],
+      [read-hello],
+      [send-plain-hello],
+      [send-long-hello],
+      [send-echo-hello],
+      [send-short-hello],
+      [send-invalid-version-hello]],
+     [AT_SETUP([$1 vconn - m4_bpatsubst(testname, [-], [ ])])
+      m4_if([$1], [ssl], [
+        AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
+        AT_CHECK([cp $abs_top_srcdir/tests/testpki*.pem .])])
+      OVS_CHECK_LCOV([test-vconn testname $1], [0], [], [ignore])
+      AT_CLEANUP])])
+
+TEST_VCONN_CLASS([unix])
+TEST_VCONN_CLASS([tcp])
+TEST_VCONN_CLASS([ssl])