test-vconn: Also accept EPIPE for TCP connection failures.
authorBen Pfaff <blp@nicira.com>
Tue, 31 Jul 2012 17:12:21 +0000 (10:12 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 1 Aug 2012 00:04:49 +0000 (17:04 -0700)
Ed Maste reports that write() to a socket where the other side has closed
returns EPIPE on FreeBSD and ECONNRESET on Linux.

Reported-by: Ed Maste <emaste@freebsd.org>
Signed-off-by: Ben Pfaff <blp@nicira.com>
tests/test-vconn.c

index b3a9b2f..377f9fa 100644 (file)
@@ -143,20 +143,26 @@ static void
 test_refuse_connection(int argc OVS_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);
+    int error;
 
     fpv_create(type, &fpv);
     CHECK_ERRNO(vconn_open(fpv.vconn_name, OFP10_VERSION, &vconn,
                            DSCP_DEFAULT), 0);
     fpv_close(&fpv);
     vconn_run(vconn);
-    CHECK_ERRNO(vconn_connect_block(vconn), expected_error);
+
+    error = vconn_connect_block(vconn);
+    if (!strcmp(type, "tcp")) {
+        if (error != ECONNRESET && error != EPIPE) {
+            ovs_fatal(0, "unexpected vconn_connect() return value %d (%s)",
+                      error, strerror(error));
+        }
+    } else {
+        CHECK_ERRNO(error, !strcmp(type, "unix") ? EPIPE : EPROTO);
+    }
+
     vconn_close(vconn);
     fpv_destroy(&fpv);
 }
@@ -197,6 +203,7 @@ test_read_hello(int argc OVS_UNUSED, char *argv[])
     struct fake_pvconn fpv;
     struct vconn *vconn;
     struct stream *stream;
+    int error;
 
     fpv_create(type, &fpv);
     CHECK_ERRNO(vconn_open(fpv.vconn_name, OFP10_VERSION, &vconn,
@@ -229,7 +236,11 @@ test_read_hello(int argc OVS_UNUSED, char *argv[])
        poll_block();
     }
     stream_close(stream);
-    CHECK_ERRNO(vconn_connect_block(vconn), ECONNRESET);
+    error = vconn_connect_block(vconn);
+    if (error != ECONNRESET && error != EPIPE) {
+        ovs_fatal(0, "unexpected vconn_connect() return value %d (%s)",
+                  error, strerror(error));
+    }
     vconn_close(vconn);
 }