Index: ossp-pkg/sio/sio_test.c RCS File: /v/ossp/cvs/ossp-pkg/sio/sio_test.c,v rcsdiff -q -kk '-r1.8' '-r1.9' -u '/v/ossp/cvs/ossp-pkg/sio/sio_test.c,v' 2>/dev/null --- sio_test.c 2003/01/20 19:13:39 1.8 +++ sio_test.c 2003/01/30 13:44:20 1.9 @@ -33,11 +33,15 @@ #endif #include +#include #include #include #include #include +#include +#include + #include "ts.h" #include "al.h" #include "sio.h" @@ -69,13 +73,17 @@ block \ if (rc != rc0) \ ts_test_fail(TS_CTX, "%s -> %d[%s] (expected %d[%s])\n", \ - rc, sio_error(rc), rc0, sio_error(rc0)) + name, rc, sio_error(rc), rc0, sio_error(rc0)) #define EVAL0(name,block) EVAL(name,rc,SIO_OK,block) +sio_rc_t readloop(sio_t *, char *, size_t, size_t *); +int test_sio_pipe_read(ts_test_t *, int, int); +int test_sio_pipe_write(ts_test_t *, int, int); + sio_rc_t readloop(sio_t *sio, char *buf, size_t len, size_t *actualp) { - sio_rc_t rc; + sio_rc_t rc = SIO_OK; size_t actual, total = 0; while (len > 0) { @@ -322,21 +330,530 @@ }); } +int test_sio_pipe_read(ts_test_t *_t, int fd, int wcount) +{ + int error = 0, result = -1; + sio_rc_t rc; + sio_t *sio; + sio_stage_t *sios_buffer, *sios_fd; + size_t bufsize = 987; /* output buffer size */ + size_t buflen = 64; /* fd 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_fd)", { + rc = sio_create_stage(sio, &sio_module_fd, &sios_fd); + }); + 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_fd, buflen)", { + rc = sio_configure_stage(sio, sios_fd, "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_fd, fd)", { + rc = sio_configure_stage(sio, sios_fd, "fd", &fd); + }); + if (rc != SIO_OK) goto badread; + + EVAL0("sio_attach(sios_fd)", { + rc = sio_attach(sio, sios_fd, 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 0) { + int n = lenodd - codd; + if (n > actual) n = actual; + if (memcmp(p, SO + codd, n) != 0) { + ts_test_fail(TS_CTX, "data mismatch on odd stream\n"); + break; + } + actual -= n; + p += n; + codd += n; + if (codd >= lenodd) { + codd = 0; + ++nodd; + } + } + if (actual > 0) + break; + + EVAL0("sio_read(C_sio)", { + rc = readloop(C_sio, buf, sizeof(buf), &actual); + if (rc == SIO_ERR_EOF) { + --nstreams; + rc = SIO_OK; + } + }); + if (rc != SIO_OK) + break; + p = buf; + while (actual > 0) { + int n = leneven - ceven; + if (n > actual) n = actual; + if (memcmp(p, SE + ceven, n) != 0) { + ts_test_fail(TS_CTX, "data mismatch on even stream\n"); + break; + } + actual -= n; + p += n; + ceven += n; + if (ceven >= leneven) { + ceven = 0; + ++neven; + } + } + if (actual > 0) + break; + + if (nstreams == 0) { + if (neven != wcount || + ceven != 0 || + nodd != wcount || + codd != 0) { + ts_test_fail(TS_CTX, "data missing from streams\n"); + } + break; + } + } + + /* + * destroy EVEN stream + */ + EVAL0("sio_detach(C_sios_sio)", { + rc = sio_detach(C_sio, C_sios_sio); + }); + EVAL0("sio_destroy_stage(C_sios_sio)", { + rc = sio_destroy_stage(C_sio, C_sios_sio); + }); + EVAL0("sio_destroy(C_sio)", { + rc = sio_destroy(C_sio); + }); + + /* + * destroy ODD stream + */ + EVAL0("sio_detach(B_sios_sio)", { + rc = sio_detach(B_sio, B_sios_sio); + }); + EVAL0("sio_destroy_stage(B_sios_sio)", { + rc = sio_destroy_stage(B_sio, B_sios_sio); + }); + EVAL0("sio_destroy(B_sio)", { + rc = sio_destroy(B_sio); + }); + + /* + * destroy MUX stream + */ + EVAL0("sio_detach(A_sios_sillymux)", { + rc = sio_detach(A_sio, A_sios_sillymux); + }); + EVAL0("sio_detach(A_sios_fd)", { + rc = sio_detach(A_sio, A_sios_fd); + }); + EVAL0("sio_destroy_stage(A_sios_sillymux)", { + rc = sio_destroy_stage(A_sio, A_sios_sillymux); + }); + EVAL0("sio_destroy_stage(A_sios_fd)", { + rc = sio_destroy_stage(A_sio, A_sios_fd); + }); + EVAL0("sio_destroy(A_sio)", { + rc = sio_destroy(A_sio); + }); + +close_and_cleanup: + close(fd); + if (unlink(tempfile) < 0) { + ts_test_fail(TS_CTX, "cannot unlink temporary file \"%s\" (%s)\n", + tempfile, strerror(errno)); + } } TS_TEST(test_sio_hello) { } +#if ENABLE_ZLIB TS_TEST(test_sio_zlib) { } +#endif #if ENABLE_SA TS_TEST(test_sio_sa)