vconn: Convert vconn code to modern OVS structure.
[sliver-openvswitch.git] / tests / test-vconn.c
index cefe899..87e35c4 100644 (file)
@@ -1,17 +1,17 @@
 /*
  * Copyright (c) 2009 Nicira Networks.
  *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
  *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 
 #include <config.h>
@@ -78,7 +78,7 @@ fpv_create(const char *type, struct fake_pvconn *fpv)
 
         /* Retrieve socket's port number. */
         sin_len = sizeof sin;
-        if (getsockname(fd, &sin, &sin_len) < 0) {
+        if (getsockname(fd, (struct sockaddr *)&sin, &sin_len) < 0) {
             ovs_fatal(errno, "failed to read TCP socket name");
         }
         if (sin_len != sizeof sin || sin.sin_family != AF_INET) {
@@ -143,6 +143,7 @@ test_refuse_connection(const char *type, int expected_error)
     fpv_create(type, &fpv);
     assert(!vconn_open(fpv.vconn_name, OFP_VERSION, &vconn));
     fpv_close(&fpv);
+    vconn_run(vconn);
     assert(vconn_connect(vconn) == expected_error);
     vconn_close(vconn);
     fpv_destroy(&fpv);
@@ -159,6 +160,7 @@ test_accept_then_close(const char *type, int expected_error)
 
     fpv_create(type, &fpv);
     assert(!vconn_open(fpv.vconn_name, OFP_VERSION, &vconn));
+    vconn_run(vconn);
     close(fpv_accept(&fpv));
     fpv_close(&fpv);
     assert(vconn_connect(vconn) == expected_error);
@@ -178,6 +180,7 @@ test_read_hello(const char *type, int expected_error)
 
     fpv_create(type, &fpv);
     assert(!vconn_open(fpv.vconn_name, OFP_VERSION, &vconn));
+    vconn_run(vconn);
     fd = fpv_accept(&fpv);
     fpv_destroy(&fpv);
     assert(!set_nonblocking(fd));
@@ -195,7 +198,9 @@ test_read_hello(const char *type, int expected_error)
            assert(errno == EAGAIN);
        }
 
+       vconn_run(vconn);
        assert(vconn_connect(vconn) == EAGAIN);
+       vconn_run_wait(vconn);
        vconn_connect_wait(vconn);
        poll_fd_wait(fd, POLLIN);
        poll_block();
@@ -221,10 +226,11 @@ test_send_hello(const char *type, const void *out, size_t out_size,
 
     fpv_create(type, &fpv);
     assert(!vconn_open(fpv.vconn_name, OFP_VERSION, &vconn));
+    vconn_run(vconn);
     fd = fpv_accept(&fpv);
     fpv_destroy(&fpv);
 
-    write(fd, out, out_size);
+    assert(write(fd, out, out_size) == out_size);
 
     assert(!set_nonblocking(fd));
 
@@ -243,6 +249,7 @@ test_send_hello(const char *type, const void *out, size_t out_size,
            }
        }
 
+       vconn_run(vconn);
        if (!connected) {
            int error = vconn_connect(vconn);
            if (error == expect_connect_error) {
@@ -262,6 +269,7 @@ test_send_hello(const char *type, const void *out, size_t out_size,
            break;
        }
 
+       vconn_run_wait(vconn);
        if (!connected) {
            vconn_connect_wait(vconn);
        }