OSSP CVS Repository

ossp - Difference in ossp-pkg/sio/sio_test.c versions 1.13 and 1.14
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/sio/sio_test.c 1.13 -> 1.14

--- sio_test.c   2003/02/03 17:19:11     1.13
+++ sio_test.c   2003/02/04 15:07:21     1.14
@@ -69,14 +69,15 @@
 extern sio_module_t sio_module_sillymux;
 
 
-#define EVAL(name,rc,rc0,block) \
+#define EVAL(name,rc,rc0,block,errf) \
     ts_test_check(TS_CTX, name); \
     block \
     if (rc != rc0) \
         ts_test_fail(TS_CTX, "%s -> %d[%s] (expected %d[%s])\n", \
-            name, rc, sio_error(rc), rc0, sio_error(rc0))
+            name, rc, errf(rc), rc0, errf(rc0))
 
-#define EVAL0(name,block) EVAL(name,rc,SIO_OK,block)
+#define EVAL0(name,block) EVAL(name,rc,SIO_OK,block,sio_error)
+#define EVALS(name,block) EVAL(name,rc,SA_OK,block,sa_error)
 
 static sio_rc_t sreadloop(sio_t *, char *, size_t, size_t *);
 static int test_sio_pipe_read(ts_test_t *, int, int);
@@ -572,6 +573,9 @@
 
     if (child == 0) {
         int result;
+
+        sleep(1);
+
         close(pd[1]);
         result = test_sio_pipe_write(NULL, pd[0], wcount);
         close(pd[0]);
@@ -1032,6 +1036,9 @@
 
     if (child == 0) {
         int result;
+
+        sleep(1);
+
         close(pd[1]);
         result = test_sio_hello_client(NULL, pd[0]);
         close(pd[0]);
@@ -1226,9 +1233,321 @@
 #endif
 
 #if ENABLE_SA
+static
+int test_sio_sa_read(ts_test_t *_t, sa_t *sa, int wcount)
+{
+    int error = 0, result = -1;
+    sio_rc_t rc;
+    sio_t *sio;
+    sio_stage_t *sios_buffer, *sios_sa;
+    size_t bufsize =  987;     /* output buffer size */
+    size_t buflen  =   64;     /* sa input buffer size */
+    int i;
+    char S[] = "Hello world\n";
+    char buf[sizeof(S)];
+    size_t actual, len = strlen(S);
+
+    EVAL0("sio_create", {
+        rc = sio_create(&sio);
+    });
+    if (rc != SIO_OK) return -1;
+    EVAL0("sio_create_stage(&sios_sa)", {
+        rc = sio_create_stage(sio, &sio_module_sa, &sios_sa);
+    });
+    if (rc != SIO_OK) return -1;
+    EVAL0("sio_create_stage(&sios_buffer)", {
+        rc = sio_create_stage(sio, &sio_module_buffer, &sios_buffer);
+    });
+    if (rc != SIO_OK) return -1;
+
+    EVAL0("sio_configure_stage(sios_sa, buflen)", {
+        rc = sio_configure_stage(sio, sios_sa, "buflen", &buflen);
+    });
+    if (rc != SIO_OK) return -1;
+    EVAL0("sio_configure_stage(sios_buffer)", {
+        rc = sio_configure_stage(sio, sios_buffer, "outputsize", &buflen);
+    });
+    if (rc != SIO_OK) return -1;
+    EVAL0("sio_configure_stage(sios_buffer, inputsize)", {
+        rc = sio_configure_stage(sio, sios_buffer, "inputsize", &bufsize);
+    });
+    if (rc != SIO_OK) return -1;
+
+    EVAL0("sio_configure_stage(sios_sa, sa)", {
+        rc = sio_configure_stage(sio, sios_sa, "sa", sa);
+    });
+    if (rc != SIO_OK) goto badread;
+
+    EVAL0("sio_attach(sios_sa)", {
+        rc = sio_attach(sio, sios_sa, SIO_MODE_READWRITE);
+    });
+    if (rc != SIO_OK) goto badread;
+    EVAL0("sio_attach(sios_buffer)", {
+        rc = sio_attach(sio, sios_buffer, SIO_MODE_READWRITE);
+    });
+    if (rc != SIO_OK) goto badread2;
+
+    for (i=0; i<wcount; ++i) {
+        EVAL0("sio_read", {
+            rc = sreadloop(sio, buf, len, &actual);
+        });
+        if (rc != SIO_OK) error = 1;
+        if (rc != SIO_OK) break;
+        if (actual != len) {
+            ts_test_fail(TS_CTX, "sio_read result %d (expected %d)\n",
+                (int)actual, (int)len);
+            break;
+        }
+        buf[actual] = '\0';
+        if (strcmp(buf, S)) {
+            ts_test_fail(TS_CTX, "sio_read data mismatch at loop %d\n",
+                i);
+            break;
+        }
+    }
+
+    EVAL0("sio_detach(sios_buffer)", {
+        rc = sio_detach(sio, sios_buffer);
+    });
+    if (rc != SIO_OK) error = 1;
+
+    result = error;
+
+    badread2:
+
+    EVAL0("sio_detach(sios_sa)", {
+        rc = sio_detach(sio, sios_sa);
+    });
+    if (rc != SIO_OK) result = -1;
+
+    badread:
+
+    EVAL0("sio_destroy_stage", {
+        rc = sio_destroy_stage(sio, sios_buffer);
+    });
+    if (rc != SIO_OK) result = -1;
+    EVAL0("sio_destroy_stage(sios_sa)", {
+        rc = sio_destroy_stage(sio, sios_sa);
+    });
+    if (rc != SIO_OK) result = -1;
+    EVAL0("sio_destroy", {
+        rc = sio_destroy(sio);
+    });
+    if (rc != SIO_OK) result = -1;
+
+    return result;
+}
+
+static
+int test_sio_sa_write(ts_test_t *_t, sa_t *sa, int wcount)
+{
+    int error = 0, result = -1;
+    sio_rc_t rc;
+    sio_t *sio;
+    sio_stage_t *sios_buffer, *sios_sa;
+    size_t bufsize = 1003;     /* output buffer size */
+    size_t buflen  =   47;     /* sa input buffer size */
+    int i;
+    char S[] = "Hello world\n";
+    size_t actual, len = strlen(S);
+
+    EVAL0("sio_create", {
+        rc = sio_create(&sio);
+    });
+    if (rc != SIO_OK) return -1;
+    EVAL0("sio_create_stage(&sios_sa)", {
+        rc = sio_create_stage(sio, &sio_module_sa, &sios_sa);
+    });
+    if (rc != SIO_OK) return -1;
+    EVAL0("sio_create_stage(&sios_buffer)", {
+        rc = sio_create_stage(sio, &sio_module_buffer, &sios_buffer);
+    });
+    if (rc != SIO_OK) return -1;
+
+    EVAL0("sio_configure_stage(sios_sa, buflen)", {
+        rc = sio_configure_stage(sio, sios_sa, "buflen", &buflen);
+    });
+    if (rc != SIO_OK) return -1;
+    EVAL0("sio_configure_stage(sios_buffer)", {
+        rc = sio_configure_stage(sio, sios_buffer, "outputsize", &buflen);
+    });
+    if (rc != SIO_OK) return -1;
+    EVAL0("sio_configure_stage(sios_buffer, inputsize)", {
+        rc = sio_configure_stage(sio, sios_buffer, "inputsize", &bufsize);
+    });
+    if (rc != SIO_OK) return -1;
+
+    /*
+     * WRITE phase
+     */
+
+    EVAL0("sio_configure_stage(sios_sa, sa)", {
+        rc = sio_configure_stage(sio, sios_sa, "sa", sa);
+    });
+    if (rc != SIO_OK) goto badwrite;
+    EVAL0("sio_attach(sios_sa)", {
+        rc = sio_attach(sio, sios_sa, SIO_MODE_READWRITE);
+    });
+    if (rc != SIO_OK) goto badwrite;
+    EVAL0("sio_attach(sios_buffer)", {
+        rc = sio_attach(sio, sios_buffer, SIO_MODE_READWRITE);
+    });
+    if (rc != SIO_OK) goto badwrite2;
+
+    for (i=0; i<wcount; ++i) {
+        EVAL0("sio_write", {
+            rc = sio_write(sio, S, len, &actual);
+        });
+        if (rc != SIO_OK) error = 1;
+        if (rc != SIO_OK) break;
+        if (actual != len) {
+            ts_test_fail(TS_CTX, "sio_write result %d (expected %d)\n",
+                (int)actual, (int)len);
+            break;
+        }
+    }
+
+    EVAL0("sio_push", {
+        rc = sio_push(sio);
+    });
+    if (rc != SIO_OK) error = 1;
+
+    EVAL0("sio_detach(sios_buffer)", {
+        rc = sio_detach(sio, sios_buffer);
+    });
+    if (rc != SIO_OK) error = 1;
+
+    result = error;
+
+    badwrite2:
+    EVAL0("sio_detach(sios_sa)", {
+        rc = sio_detach(sio, sios_sa);
+    });
+    if (rc != SIO_OK) result = -1;
+
+    badwrite:
+
+    /*
+     * common cleanup
+     */
+
+    EVAL0("sio_destroy_stage", {
+        rc = sio_destroy_stage(sio, sios_buffer);
+    });
+    if (rc != SIO_OK) result = -1;
+    EVAL0("sio_destroy_stage(sios_sa)", {
+        rc = sio_destroy_stage(sio, sios_sa);
+    });
+    if (rc != SIO_OK) result = -1;
+    EVAL0("sio_destroy", {
+        rc = sio_destroy(sio);
+    });
+    if (rc != SIO_OK) result = -1;
+
+    return result;
+}
+
 TS_TEST(test_sio_sa)
 {
+    pid_t child;
+    sa_rc_t rc;
+    sa_addr_t *saa_b, *saa_p;
+    sa_t *sa_client, *sa_server;
+    int wcount = 147;
+    int status;
+
+    fflush(stdout);
+    fflush(stderr);
+
+    EVALS("sa_create(sa_server)", {
+        rc = sa_create(&sa_server);
+    });
+    if (rc != SA_OK) goto sa_bail;
+    EVALS("sa_timeout(sa_server, SA_TIMEOUT_ALL, 5, 0)", {
+        rc = sa_timeout(sa_server, SA_TIMEOUT_ALL, 5, 0);
+    });
+    if (rc != SA_OK) goto sa_bail1;
+    EVALS("sa_option(sa_server, SA_OPTION_REUSEADDR, 1)", {
+        rc = sa_option(sa_server, SA_OPTION_REUSEADDR, 1);
+    });
+    if (rc != SA_OK) goto sa_bail1;
+    EVALS("sa_addr_create(&saa_b)", {
+        rc = sa_addr_create(&saa_b);
+    });
+    if (rc != SA_OK) goto sa_bail1;
+    EVALS("sa_addr_u2a(saa_b, uri)", {
+        rc = sa_addr_u2a(saa_b, "inet://127.0.0.1:0");
+    });
+    if (rc != SA_OK) goto sa_bail1;
+    EVALS("sa_bind(sa_server, saa_b)", {
+        rc = sa_bind(sa_server, saa_b);
+    });
+    if (rc != SA_OK) goto sa_bail2;
+    EVALS("sa_listen(sa_server, 128)", {
+        rc = sa_listen(sa_server, 128);
+    });
+    if (rc != SA_OK) goto sa_bail2;
+    EVALS("sa_getlocal(sa_server, &saa_p)", {
+        rc = sa_getlocal(sa_server, &saa_p);
+    });
+    if (rc != SA_OK) goto sa_bail2;
+    EVALS("sa_create(sa_client)", {
+        rc = sa_create(&sa_client);
+    });
+    if (rc != SA_OK) goto sa_bail3;
+    EVALS("sa_timeout(sa_client, SA_TIMEOUT_ALL, 5, 0)", {
+        rc = sa_timeout(sa_client, SA_TIMEOUT_ALL, 5, 0);
+    });
+    if (rc != SA_OK) goto sa_bail4;
+
+    child = fork();
+    if (child == -1) {
+        ts_test_fail(TS_CTX, "cannot fork (%s)\n",
+            strerror(errno));
+    }
+
+    if (child == 0) {
+        int result;
+        sa_t *sa_conn;
+        sa_addr_t *saa_c;
+
+        sleep(1);
+
+        rc = sa_accept(sa_server, &saa_c, &sa_conn);
+        if (rc != SA_OK) exit(2);
+        rc = sa_addr_destroy(saa_c);
+
+        rc = sa_shutdown(sa_server, "rw");
+        rc = sa_shutdown(sa_conn, "r");
+        result = test_sio_sa_write(NULL, sa_conn, wcount);
+        rc = sa_shutdown(sa_conn, "w");
+        exit(result ? 1 : 0);
+    } else {
+        EVALS("sa_connect(sa_client, saa_p)", {
+            rc = sa_connect(sa_client, saa_p);
+        });
+        rc = sa_shutdown(sa_server, "w");
+        test_sio_sa_read(_t, sa_client, wcount);
+        rc = sa_shutdown(sa_server, "r");
+        waitpid(child, &status, 0);
+        if (status != 0) {
+            ts_test_fail(TS_CTX, "child returned status %08lx\n",
+                status);
+        }
+    }
+
+sa_bail4:
+    sa_destroy(sa_client);
+sa_bail3:
+    sa_addr_destroy(saa_p);
+sa_bail2:
+    sa_addr_destroy(saa_b);
+sa_bail1:
+    sa_destroy(sa_server);
+sa_bail:
+    return;
 }
+
 #endif
 
 #if ENABLE_BIO

CVSTrac 2.0.1