]> git.ozlabs.org Git - ccan/commitdiff
ccan/io: go linear for debugging.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 14 Oct 2013 10:58:36 +0000 (21:28 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 14 Oct 2013 10:58:36 +0000 (21:28 +1030)
Debugging an async library is a pain: it's nice to force it into a
linear call chain to try to track problems.

Ugly code, though.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
26 files changed:
ccan/io/backend.h
ccan/io/io.c
ccan/io/io.h
ccan/io/poll.c
ccan/io/test/run-01-start-finish-DEBUG.c [new file with mode: 0644]
ccan/io/test/run-01-start-finish.c
ccan/io/test/run-02-read-DEBUG.c [new file with mode: 0644]
ccan/io/test/run-02-read.c
ccan/io/test/run-03-readpartial-DEBUG.c [new file with mode: 0644]
ccan/io/test/run-03-readpartial.c
ccan/io/test/run-04-writepartial-DEBUG.c [new file with mode: 0644]
ccan/io/test/run-04-writepartial.c
ccan/io/test/run-05-write-DEBUG.c [new file with mode: 0644]
ccan/io/test/run-05-write.c
ccan/io/test/run-06-idle-DEBUG.c [new file with mode: 0644]
ccan/io/test/run-06-idle.c
ccan/io/test/run-07-break-DEBUG.c [new file with mode: 0644]
ccan/io/test/run-07-break.c
ccan/io/test/run-08-hangup-on-idle-DEBUG.c [new file with mode: 0644]
ccan/io/test/run-08-read-after-hangup-DEBUG.c [new file with mode: 0644]
ccan/io/test/run-10-many-DEBUG.c [new file with mode: 0644]
ccan/io/test/run-12-bidir-DEBUG.c [new file with mode: 0644]
ccan/io/test/run-12-bidir.c
ccan/io/test/run-13-all-idle-DEBUG.c [new file with mode: 0644]
ccan/io/test/run-15-timeout-DEBUG.c [new file with mode: 0644]
ccan/io/test/run-15-timeout.c

index 48e160dad3991a58b0bd566d9e39fb758854e159..fa4cf8ee9f638ec5a32f9d671b7a9ffe0d649d10 100644 (file)
@@ -47,6 +47,26 @@ static inline bool timeout_active(const struct io_conn *conn)
 
 extern void *io_loop_return;
 
 
 extern void *io_loop_return;
 
+#ifdef DEBUG
+extern struct io_conn *current;
+static inline void set_current(struct io_conn *conn)
+{
+       current = conn;
+}
+static inline bool doing_debug(void)
+{
+       return io_debug != NULL;
+}
+#else
+static inline void set_current(struct io_conn *conn)
+{
+}
+static inline bool doing_debug(void)
+{
+       return false;
+}
+#endif
+
 bool add_listener(struct io_listener *l);
 bool add_conn(struct io_conn *c);
 bool add_duplex(struct io_conn *c);
 bool add_listener(struct io_listener *l);
 bool add_conn(struct io_conn *c);
 bool add_duplex(struct io_conn *c);
index 8d43922351d51ba131e4c087b600bbdc013993c0..5ecd82418dd62f67dea51b34156efdfedf3674bf 100644 (file)
 
 void *io_loop_return;
 
 
 void *io_loop_return;
 
+#ifdef DEBUG
+bool io_plan_for_other;
+struct io_conn *current;
+bool (*io_debug)(struct io_conn *conn);
+bool io_debug_wakeup;
+
+static void debug_io_plan(struct io_plan *plan)
+{
+       if (io_plan_for_other) {
+               io_plan_for_other = false;
+               return;
+       }
+
+       if (!io_debug || !current)
+               return;
+
+       if (!io_debug(current) && !io_debug_wakeup)
+               return;
+
+       io_debug_wakeup = false;
+       current->plan = *plan;
+       backend_plan_changed(current);
+
+       /* Call back into the loop immediately. */
+       io_loop_return = io_loop();
+}
+
+static void debug_io_wake(struct io_conn *conn)
+{
+       /* We want linear if we wake a debugged connection, too. */
+       if (io_debug && io_debug(conn))
+               io_debug_wakeup = true;
+}
+#else
+static void debug_io_plan(struct io_plan *plan)
+{
+}
+static void debug_io_wake(struct io_conn *conn)
+{
+}
+#endif
+
 struct io_listener *io_new_listener_(int fd,
                                     void (*init)(int fd, void *arg),
                                     void *arg)
 struct io_listener *io_new_listener_(int fd,
                                     void (*init)(int fd, void *arg),
                                     void *arg)
@@ -138,6 +180,8 @@ struct io_plan io_write_(const void *data, size_t len,
        plan.next = cb;
        plan.next_arg = arg;
        plan.pollflag = POLLOUT;
        plan.next = cb;
        plan.next_arg = arg;
        plan.pollflag = POLLOUT;
+
+       debug_io_plan(&plan);
        return plan;
 }
 
        return plan;
 }
 
@@ -169,6 +213,8 @@ struct io_plan io_read_(void *data, size_t len,
        plan.next = cb;
        plan.next_arg = arg;
        plan.pollflag = POLLIN;
        plan.next = cb;
        plan.next_arg = arg;
        plan.pollflag = POLLIN;
+
+       debug_io_plan(&plan);
        return plan;
 }
 
        return plan;
 }
 
@@ -200,6 +246,7 @@ struct io_plan io_read_partial_(void *data, size_t *len,
        plan.next_arg = arg;
        plan.pollflag = POLLIN;
 
        plan.next_arg = arg;
        plan.pollflag = POLLIN;
 
+       debug_io_plan(&plan);
        return plan;
 }
 
        return plan;
 }
 
@@ -231,6 +278,7 @@ struct io_plan io_write_partial_(const void *data, size_t *len,
        plan.next_arg = arg;
        plan.pollflag = POLLOUT;
 
        plan.next_arg = arg;
        plan.pollflag = POLLOUT;
 
+       debug_io_plan(&plan);
        return plan;
 }
 
        return plan;
 }
 
@@ -243,10 +291,11 @@ struct io_plan io_idle(void)
        /* Never called (overridded by io_wake), but NULL means closing */
        plan.next = io_close;
 
        /* Never called (overridded by io_wake), but NULL means closing */
        plan.next = io_close;
 
+       debug_io_plan(&plan);
        return plan;
 }
 
        return plan;
 }
 
-void io_wake(struct io_conn *conn, struct io_plan plan)
+void io_wake_(struct io_conn *conn, struct io_plan plan)
 
 {
        /* It might be closing, but we haven't called its finish() yet. */
 
 {
        /* It might be closing, but we haven't called its finish() yet. */
@@ -256,15 +305,19 @@ void io_wake(struct io_conn *conn, struct io_plan plan)
        assert(!conn->plan.io);
        conn->plan = plan;
        backend_plan_changed(conn);
        assert(!conn->plan.io);
        conn->plan = plan;
        backend_plan_changed(conn);
+
+       debug_io_wake(conn);
 }
 
 void io_ready(struct io_conn *conn)
 {
        if (conn->plan.io(conn->fd.fd, &conn->plan)) {
 }
 
 void io_ready(struct io_conn *conn)
 {
        if (conn->plan.io(conn->fd.fd, &conn->plan)) {
+               set_current(conn);
                if (timeout_active(conn))
                        backend_del_timeout(conn);
                conn->plan = conn->plan.next(conn, conn->plan.next_arg);
                backend_plan_changed(conn);
                if (timeout_active(conn))
                        backend_del_timeout(conn);
                conn->plan = conn->plan.next(conn, conn->plan.next_arg);
                backend_plan_changed(conn);
+               set_current(NULL);
        }
 }
 
        }
 }
 
@@ -278,11 +331,12 @@ struct io_plan io_close(struct io_conn *conn, void *arg)
        /* This means we're closing. */
        plan.next = NULL;
 
        /* This means we're closing. */
        plan.next = NULL;
 
+       debug_io_plan(&plan);
        return plan;
 }
 
 /* Exit the loop, returning this (non-NULL) arg. */
        return plan;
 }
 
 /* Exit the loop, returning this (non-NULL) arg. */
-struct io_plan io_break(void *ret, struct io_plan plan)
+struct io_plan io_break_(void *ret, struct io_plan plan)
 {
        assert(ret);
        io_loop_return = ret;
 {
        assert(ret);
        io_loop_return = ret;
index b7249e3a6b916a4ac966b77d81d00e244fd64319..b8bf643dd6abe76a73a59ee56e1a4b25bb98bed1 100644 (file)
@@ -8,6 +8,14 @@
 
 struct io_conn;
 
 
 struct io_conn;
 
+#ifdef DEBUG
+extern bool io_plan_for_other;
+extern bool (*io_debug)(struct io_conn *conn);
+#define io_plan_other() ((io_plan_for_other = true))
+#else
+#define io_plan_other() (void)0
+#endif
+
 struct io_state_read {
        char *buf;
        size_t len;
 struct io_state_read {
        char *buf;
        size_t len;
@@ -63,10 +71,11 @@ struct io_plan {
  * Returns NULL on error (and sets errno).
  */
 #define io_new_conn(fd, plan, finish, arg)                             \
  * Returns NULL on error (and sets errno).
  */
 #define io_new_conn(fd, plan, finish, arg)                             \
-       io_new_conn_((fd), (plan),                                      \
-                    typesafe_cb_preargs(void, void *, (finish), (arg), \
-                                        struct io_conn *),             \
-                    (arg))
+       (io_plan_other(), io_new_conn_((fd), (plan),                    \
+                                      typesafe_cb_preargs(void, void *, \
+                                                          (finish), (arg), \
+                                                          struct io_conn *), \
+                                      (arg)))
 struct io_conn *io_new_conn_(int fd,
                             struct io_plan plan,
                             void (*finish)(struct io_conn *, void *),
 struct io_conn *io_new_conn_(int fd,
                             struct io_plan plan,
                             void (*finish)(struct io_conn *, void *),
@@ -237,10 +246,11 @@ bool io_timeout_(struct io_conn *conn, struct timespec ts,
  * You must io_close() both of them to close the fd.
  */
 #define io_duplex(conn, plan, finish, arg)                             \
  * You must io_close() both of them to close the fd.
  */
 #define io_duplex(conn, plan, finish, arg)                             \
-       io_duplex_((conn), (plan),                                      \
-                  typesafe_cb_preargs(void, void *, (finish), (arg),   \
-                                      struct io_conn *),               \
-                  (arg))
+       (io_plan_other(), io_duplex_((conn), (plan),                    \
+                                    typesafe_cb_preargs(void, void *,  \
+                                                        (finish), (arg), \
+                                                        struct io_conn *), \
+                                    (arg)))
 
 struct io_conn *io_duplex_(struct io_conn *conn,
                           struct io_plan plan,
 
 struct io_conn *io_duplex_(struct io_conn *conn,
                           struct io_plan plan,
@@ -254,7 +264,8 @@ struct io_conn *io_duplex_(struct io_conn *conn,
  *
  * This makes @conn do I/O the next time around the io_loop().
  */
  *
  * This makes @conn do I/O the next time around the io_loop().
  */
-void io_wake(struct io_conn *conn, struct io_plan plan);
+#define io_wake(conn, plan) (io_plan_other(), io_wake_((conn), (plan)))
+void io_wake_(struct io_conn *conn, struct io_plan plan);
 
 /**
  * io_break - return from io_loop()
 
 /**
  * io_break - return from io_loop()
@@ -267,7 +278,8 @@ void io_wake(struct io_conn *conn, struct io_plan plan);
  *
  * If io_loop() is called again, then @plan will be carried out.
  */
  *
  * If io_loop() is called again, then @plan will be carried out.
  */
-struct io_plan io_break(void *ret, struct io_plan plan);
+#define io_break(ret, plan) (io_plan_other(), io_break_((ret), (plan)))
+struct io_plan io_break_(void *ret, struct io_plan plan);
 
 /* FIXME: io_recvfrom/io_sendto */
 
 
 /* FIXME: io_recvfrom/io_sendto */
 
index 7f3df7ed301728965cbc2fc203f0bcc46262ec11..85407f62a8e32bafef27bb735b31992b3c1d2c66 100644 (file)
@@ -12,6 +12,49 @@ static size_t num_fds = 0, max_fds = 0, num_closing = 0, num_waiting = 0;
 static struct pollfd *pollfds = NULL;
 static struct fd **fds = NULL;
 static struct timers timeouts;
 static struct pollfd *pollfds = NULL;
 static struct fd **fds = NULL;
 static struct timers timeouts;
+#ifdef DEBUG
+static unsigned int io_loop_level;
+static struct io_conn *free_later;
+static void io_loop_enter(void)
+{
+       io_loop_level++;
+}
+static void io_loop_exit(void)
+{
+       io_loop_level--;
+       if (io_loop_level == 0) {
+               /* Delayed free. */
+               while (free_later) {
+                       struct io_conn *c = free_later;
+                       free_later = c->finish_arg;
+                       free(c);
+               }
+       }
+}
+static void free_conn(struct io_conn *conn)
+{
+       /* Only free on final exit: chain via finish. */
+       if (io_loop_level > 1) {
+               struct io_conn *c;
+               for (c = free_later; c; c = c->finish_arg)
+                       assert(c != conn);
+               conn->finish_arg = free_later;
+               free_later = conn;
+       } else
+               free(conn);
+}
+#else
+static void io_loop_enter(void)
+{
+}
+static void io_loop_exit(void)
+{
+}
+static void free_conn(struct io_conn *conn)
+{
+       free(conn);
+}
+#endif
 
 static bool add_fd(struct fd *fd, short events)
 {
 
 static bool add_fd(struct fd *fd, short events)
 {
@@ -83,7 +126,13 @@ bool add_listener(struct io_listener *l)
 
 void backend_plan_changed(struct io_conn *conn)
 {
 
 void backend_plan_changed(struct io_conn *conn)
 {
-       struct pollfd *pfd = &pollfds[conn->fd.backend_info];
+       struct pollfd *pfd;
+
+       /* This can happen with debugging and delayed free... */
+       if (conn->fd.backend_info == -1)
+               return;
+
+       pfd = &pollfds[conn->fd.backend_info];
 
        if (pfd->events)
                num_waiting--;
 
        if (pfd->events)
                num_waiting--;
@@ -133,6 +182,7 @@ static void del_conn(struct io_conn *conn)
                /* In case fds[] pointed to the other one. */
                fds[conn->fd.backend_info] = &conn->duplex->fd;
                conn->duplex->duplex = NULL;
                /* In case fds[] pointed to the other one. */
                fds[conn->fd.backend_info] = &conn->duplex->fd;
                conn->duplex->duplex = NULL;
+               conn->fd.backend_info = -1;
        } else
                del_fd(&conn->fd);
        num_closing--;
        } else
                del_fd(&conn->fd);
        num_closing--;
@@ -176,7 +226,7 @@ static void finish_conns(void)
                for (duplex = c->duplex; c; c = duplex, duplex = NULL) {
                        if (!c->plan.next) {
                                del_conn(c);
                for (duplex = c->duplex; c; c = duplex, duplex = NULL) {
                        if (!c->plan.next) {
                                del_conn(c);
-                               free(c);
+                               free_conn(c);
                                i--;
                        }
                }
                                i--;
                        }
                }
@@ -204,9 +254,12 @@ void *io_loop(void)
 {
        void *ret;
 
 {
        void *ret;
 
+       io_loop_enter();
+
        while (!io_loop_return) {
                int i, r, timeout = INT_MAX;
                struct timespec now;
        while (!io_loop_return) {
                int i, r, timeout = INT_MAX;
                struct timespec now;
+               bool some_timeouts = false;
 
                if (timeouts.base) {
                        struct timespec first;
 
                if (timeouts.base) {
                        struct timespec first;
@@ -221,7 +274,9 @@ void *io_loop(void)
                                struct io_conn *conn = t->conn;
                                /* Clear, in case timer re-adds */
                                t->conn = NULL;
                                struct io_conn *conn = t->conn;
                                /* Clear, in case timer re-adds */
                                t->conn = NULL;
+                               set_current(conn);
                                set_plan(conn, t->next(conn, t->next_arg));
                                set_plan(conn, t->next(conn, t->next_arg));
+                               some_timeouts = true;
                        }
 
                        /* Now figure out how long to wait for the next one. */
                        }
 
                        /* Now figure out how long to wait for the next one. */
@@ -238,6 +293,10 @@ void *io_loop(void)
                        continue;
                }
 
                        continue;
                }
 
+               /* debug can recurse on io_loop; anything can change. */
+               if (doing_debug() && some_timeouts)
+                       continue;
+
                if (num_fds == 0)
                        break;
 
                if (num_fds == 0)
                        break;
 
@@ -267,17 +326,27 @@ void *io_loop(void)
                                        if (events & mask) {
                                                io_ready(c->duplex);
                                                events &= ~mask;
                                        if (events & mask) {
                                                io_ready(c->duplex);
                                                events &= ~mask;
+                                               /* debug can recurse;
+                                                * anything can change. */
+                                               if (doing_debug())
+                                                       break;
                                                if (!(events&(POLLIN|POLLOUT)))
                                                        continue;
                                        }
                                }
                                io_ready(c);
                                                if (!(events&(POLLIN|POLLOUT)))
                                                        continue;
                                        }
                                }
                                io_ready(c);
+                               /* debug can recurse; anything can change. */
+                               if (doing_debug())
+                                       break;
                        } else if (events & POLLHUP) {
                                r--;
                        } else if (events & POLLHUP) {
                                r--;
+                               set_current(c);
                                set_plan(c, io_close(c, NULL));
                                set_plan(c, io_close(c, NULL));
-                               if (c->duplex)
+                               if (c->duplex) {
+                                       set_current(c->duplex);
                                        set_plan(c->duplex,
                                                 io_close(c->duplex, NULL));
                                        set_plan(c->duplex,
                                                 io_close(c->duplex, NULL));
+                               }
                        }
                }
        }
                        }
                }
        }
@@ -287,5 +356,7 @@ void *io_loop(void)
 
        ret = io_loop_return;
        io_loop_return = NULL;
 
        ret = io_loop_return;
        io_loop_return = NULL;
+
+       io_loop_exit();
        return ret;
 }
        return ret;
 }
diff --git a/ccan/io/test/run-01-start-finish-DEBUG.c b/ccan/io/test/run-01-start-finish-DEBUG.c
new file mode 100644 (file)
index 0000000..48f0f3e
--- /dev/null
@@ -0,0 +1,8 @@
+#define DEBUG
+#define PORT "64001"
+#define main real_main
+int real_main(void);
+#include "run-01-start-finish.c"
+#undef main
+static bool always_debug(struct io_conn *conn) { return true; }
+int main(void) { io_debug = always_debug; return real_main(); }
index b5114abeafcceabe3b26d88581336e63b89ee582..074769693f3266843deb2d3d26d98f4e33dca95d 100644 (file)
@@ -6,6 +6,10 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
 #include <sys/wait.h>
 #include <stdio.h>
 
+#ifndef PORT
+#define PORT "65001"
+#endif
+
 static void finish_ok(struct io_conn *conn, int *state)
 {
        ok1(*state == 1);
 static void finish_ok(struct io_conn *conn, int *state)
 {
        ok1(*state == 1);
@@ -62,7 +66,7 @@ int main(void)
 
        /* This is how many tests you plan to run */
        plan_tests(9);
 
        /* This is how many tests you plan to run */
        plan_tests(9);
-       fd = make_listen_fd("65001", &addrinfo);
+       fd = make_listen_fd(PORT, &addrinfo);
        ok1(fd >= 0);
        l = io_new_listener(fd, init_conn, &state);
        ok1(l);
        ok1(fd >= 0);
        l = io_new_listener(fd, init_conn, &state);
        ok1(l);
diff --git a/ccan/io/test/run-02-read-DEBUG.c b/ccan/io/test/run-02-read-DEBUG.c
new file mode 100644 (file)
index 0000000..d48260c
--- /dev/null
@@ -0,0 +1,8 @@
+#define DEBUG
+#define PORT "64002"
+#define main real_main
+int real_main(void);
+#include "run-02-read.c"
+#undef main
+static bool always_debug(struct io_conn *conn) { return true; }
+int main(void) { io_debug = always_debug; return real_main(); }
index 9abcd9647b6fb7295e998ec9437f6ef4543ff29c..b8c93c36209dd1a81a40a5049d4b13725cb39e7e 100644 (file)
@@ -6,6 +6,10 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
 #include <sys/wait.h>
 #include <stdio.h>
 
+#ifndef PORT
+#define PORT "65002"
+#endif
+
 struct data {
        int state;
        char buf[4];
 struct data {
        int state;
        char buf[4];
@@ -70,7 +74,7 @@ int main(void)
        /* This is how many tests you plan to run */
        plan_tests(10);
        d->state = 0;
        /* This is how many tests you plan to run */
        plan_tests(10);
        d->state = 0;
-       fd = make_listen_fd("65002", &addrinfo);
+       fd = make_listen_fd(PORT, &addrinfo);
        ok1(fd >= 0);
        l = io_new_listener(fd, init_conn, d);
        ok1(l);
        ok1(fd >= 0);
        l = io_new_listener(fd, init_conn, d);
        ok1(l);
diff --git a/ccan/io/test/run-03-readpartial-DEBUG.c b/ccan/io/test/run-03-readpartial-DEBUG.c
new file mode 100644 (file)
index 0000000..f23cc31
--- /dev/null
@@ -0,0 +1,8 @@
+#define DEBUG
+#define PORT "64003"
+#define main real_main
+int real_main(void);
+#include "run-03-readpartial.c"
+#undef main
+static bool always_debug(struct io_conn *conn) { return true; }
+int main(void) { io_debug = always_debug; return real_main(); }
index a24be7e025847b3e36bf4cf865cc11113e3a47f8..5e08b1a2709347af6131af10c54692f5edeaf2d9 100644 (file)
@@ -6,6 +6,10 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
 #include <sys/wait.h>
 #include <stdio.h>
 
+#ifndef PORT
+#define PORT "65003"
+#endif
+
 struct data {
        int state;
        size_t bytes;
 struct data {
        int state;
        size_t bytes;
@@ -90,7 +94,7 @@ int main(void)
        /* This is how many tests you plan to run */
        plan_tests(22);
        d->state = 0;
        /* This is how many tests you plan to run */
        plan_tests(22);
        d->state = 0;
-       fd = make_listen_fd("65003", &addrinfo);
+       fd = make_listen_fd(PORT, &addrinfo);
        ok1(fd >= 0);
        l = io_new_listener(fd, init_conn, d);
        ok1(l);
        ok1(fd >= 0);
        l = io_new_listener(fd, init_conn, d);
        ok1(l);
diff --git a/ccan/io/test/run-04-writepartial-DEBUG.c b/ccan/io/test/run-04-writepartial-DEBUG.c
new file mode 100644 (file)
index 0000000..515bd46
--- /dev/null
@@ -0,0 +1,8 @@
+#define DEBUG
+#define PORT "64004"
+#define main real_main
+int real_main(void);
+#include "run-04-writepartial.c"
+#undef main
+static bool always_debug(struct io_conn *conn) { return true; }
+int main(void) { io_debug = always_debug; return real_main(); }
index 12a21ddcd712e08fc793150380f8a8e0fefc17a4..681d9d4de9cb1676b55588a6ea0954b3f42dd932 100644 (file)
@@ -6,6 +6,10 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
 #include <sys/wait.h>
 #include <stdio.h>
 
+#ifndef PORT
+#define PORT "65004"
+#endif
+
 struct data {
        int state;
        size_t bytes;
 struct data {
        int state;
        size_t bytes;
@@ -91,7 +95,7 @@ int main(void)
        d->bytes = 1024*1024;
        d->buf = malloc(d->bytes);
        memset(d->buf, 'a', d->bytes);
        d->bytes = 1024*1024;
        d->buf = malloc(d->bytes);
        memset(d->buf, 'a', d->bytes);
-       fd = make_listen_fd("65004", &addrinfo);
+       fd = make_listen_fd(PORT, &addrinfo);
        ok1(fd >= 0);
        l = io_new_listener(fd, init_conn, d);
        ok1(l);
        ok1(fd >= 0);
        l = io_new_listener(fd, init_conn, d);
        ok1(l);
diff --git a/ccan/io/test/run-05-write-DEBUG.c b/ccan/io/test/run-05-write-DEBUG.c
new file mode 100644 (file)
index 0000000..ae5eb10
--- /dev/null
@@ -0,0 +1,8 @@
+#define DEBUG
+#define PORT "64005"
+#define main real_main
+int real_main(void);
+#include "run-05-write.c"
+#undef main
+static bool always_debug(struct io_conn *conn) { return true; }
+int main(void) { io_debug = always_debug; return real_main(); }
index e878c33054776e00406488e00a04e17aeecf8e3a..f8f30ee59194716fb7466a705b02fa40a865c877 100644 (file)
@@ -6,6 +6,10 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
 #include <sys/wait.h>
 #include <stdio.h>
 
+#ifndef PORT
+#define PORT "65005"
+#endif
+
 struct data {
        int state;
        size_t bytes;
 struct data {
        int state;
        size_t bytes;
@@ -94,7 +98,7 @@ int main(void)
        d->bytes = 1024*1024;
        d->buf = malloc(d->bytes);
        memset(d->buf, 'a', d->bytes);
        d->bytes = 1024*1024;
        d->buf = malloc(d->bytes);
        memset(d->buf, 'a', d->bytes);
-       fd = make_listen_fd("65005", &addrinfo);
+       fd = make_listen_fd(PORT, &addrinfo);
        ok1(fd >= 0);
        l = io_new_listener(fd, init_conn, d);
        ok1(l);
        ok1(fd >= 0);
        l = io_new_listener(fd, init_conn, d);
        ok1(l);
diff --git a/ccan/io/test/run-06-idle-DEBUG.c b/ccan/io/test/run-06-idle-DEBUG.c
new file mode 100644 (file)
index 0000000..f2ed1d4
--- /dev/null
@@ -0,0 +1,8 @@
+#define DEBUG
+#define PORT "64006"
+#define main real_main
+int real_main(void);
+#include "run-06-idle.c"
+#undef main
+static bool always_debug(struct io_conn *conn) { return true; }
+int main(void) { io_debug = always_debug; return real_main(); }
index d75a216db6a48d5cbc68aa6a093e4ba7c0496c77..388805a882b4bb31bccfc44790d694a8f1f5a641 100644 (file)
@@ -9,6 +9,10 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
 #include <sys/stat.h>
 #include <fcntl.h>
 
+#ifndef PORT
+#define PORT "65006"
+#endif
+
 static struct io_conn *idler;
 
 struct data {
 static struct io_conn *idler;
 
 struct data {
@@ -98,7 +102,7 @@ int main(void)
        /* This is how many tests you plan to run */
        plan_tests(14);
        d->state = 0;
        /* This is how many tests you plan to run */
        plan_tests(14);
        d->state = 0;
-       fd = make_listen_fd("65006", &addrinfo);
+       fd = make_listen_fd(PORT, &addrinfo);
        ok1(fd >= 0);
        l = io_new_listener(fd, init_conn, d);
        ok1(l);
        ok1(fd >= 0);
        l = io_new_listener(fd, init_conn, d);
        ok1(l);
diff --git a/ccan/io/test/run-07-break-DEBUG.c b/ccan/io/test/run-07-break-DEBUG.c
new file mode 100644 (file)
index 0000000..7309594
--- /dev/null
@@ -0,0 +1,8 @@
+#define DEBUG
+#define PORT "64007"
+#define main real_main
+int real_main(void);
+#include "run-07-break.c"
+#undef main
+static bool always_debug(struct io_conn *conn) { return true; }
+int main(void) { io_debug = always_debug; return real_main(); }
index 5a6e9701b52ca3d2c9567c096ebe02bd3c83458c..3ea20bf528cf26da7157a5e9eb91ca786804b41e 100644 (file)
@@ -6,6 +6,10 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
 #include <sys/wait.h>
 #include <stdio.h>
 
+#ifndef PORT
+#define PORT "65007"
+#endif
+
 struct data {
        int state;
        char buf[4];
 struct data {
        int state;
        char buf[4];
@@ -78,7 +82,7 @@ int main(void)
        /* This is how many tests you plan to run */
        plan_tests(13);
        d->state = 0;
        /* This is how many tests you plan to run */
        plan_tests(13);
        d->state = 0;
-       fd = make_listen_fd("65007", &addrinfo);
+       fd = make_listen_fd(PORT, &addrinfo);
        ok1(fd >= 0);
        l = io_new_listener(fd, init_conn, d);
        ok1(l);
        ok1(fd >= 0);
        l = io_new_listener(fd, init_conn, d);
        ok1(l);
diff --git a/ccan/io/test/run-08-hangup-on-idle-DEBUG.c b/ccan/io/test/run-08-hangup-on-idle-DEBUG.c
new file mode 100644 (file)
index 0000000..589dc26
--- /dev/null
@@ -0,0 +1,7 @@
+#define DEBUG
+#define main real_main
+int real_main(void);
+#include "run-08-hangup-on-idle.c"
+#undef main
+static bool always_debug(struct io_conn *conn) { return true; }
+int main(void) { io_debug = always_debug; return real_main(); }
diff --git a/ccan/io/test/run-08-read-after-hangup-DEBUG.c b/ccan/io/test/run-08-read-after-hangup-DEBUG.c
new file mode 100644 (file)
index 0000000..189a3ea
--- /dev/null
@@ -0,0 +1,7 @@
+#define DEBUG
+#define main real_main
+int real_main(void);
+#include "run-08-read-after-hangup.c"
+#undef main
+static bool always_debug(struct io_conn *conn) { return true; }
+int main(void) { io_debug = always_debug; return real_main(); }
diff --git a/ccan/io/test/run-10-many-DEBUG.c b/ccan/io/test/run-10-many-DEBUG.c
new file mode 100644 (file)
index 0000000..3b18596
--- /dev/null
@@ -0,0 +1,12 @@
+#define DEBUG
+#define PORT "64010"
+#define main real_main
+int real_main(void);
+#include "run-10-many.c"
+#undef main
+/* We stack overflow if we debug all of them! */
+static bool debug_one(struct io_conn *conn)
+{
+       return conn == buf[1].reader;
+}
+int main(void) { io_debug = debug_one; return real_main(); }
diff --git a/ccan/io/test/run-12-bidir-DEBUG.c b/ccan/io/test/run-12-bidir-DEBUG.c
new file mode 100644 (file)
index 0000000..d2c886d
--- /dev/null
@@ -0,0 +1,8 @@
+#define DEBUG
+#define PORT "64012"
+#define main real_main
+int real_main(void);
+#include "run-12-bidir.c"
+#undef main
+static bool always_debug(struct io_conn *conn) { return true; }
+int main(void) { io_debug = always_debug; return real_main(); }
index 6dc94c8a4a57a1baee29d281b7e04355a7cd7752..812c863c85059be1c0fd8dfce286b063034b63f1 100644 (file)
@@ -6,6 +6,10 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
 #include <sys/wait.h>
 #include <stdio.h>
 
+#ifndef PORT
+#define PORT "65012"
+#endif
+
 struct data {
        struct io_listener *l;
        int state;
 struct data {
        struct io_listener *l;
        int state;
@@ -82,7 +86,7 @@ int main(void)
        /* This is how many tests you plan to run */
        plan_tests(10);
        d->state = 0;
        /* This is how many tests you plan to run */
        plan_tests(10);
        d->state = 0;
-       fd = make_listen_fd("65012", &addrinfo);
+       fd = make_listen_fd(PORT, &addrinfo);
        ok1(fd >= 0);
        d->l = io_new_listener(fd, init_conn, d);
        ok1(d->l);
        ok1(fd >= 0);
        d->l = io_new_listener(fd, init_conn, d);
        ok1(d->l);
diff --git a/ccan/io/test/run-13-all-idle-DEBUG.c b/ccan/io/test/run-13-all-idle-DEBUG.c
new file mode 100644 (file)
index 0000000..1ef1db6
--- /dev/null
@@ -0,0 +1,8 @@
+#define DEBUG
+#define PORT "64013"
+#define main real_main
+int real_main(void);
+#include "run-13-all-idle.c"
+#undef main
+static bool always_debug(struct io_conn *conn) { return true; }
+int main(void) { io_debug = always_debug; return real_main(); }
diff --git a/ccan/io/test/run-15-timeout-DEBUG.c b/ccan/io/test/run-15-timeout-DEBUG.c
new file mode 100644 (file)
index 0000000..8ada4c0
--- /dev/null
@@ -0,0 +1,8 @@
+#define DEBUG
+#define PORT "64015"
+#define main real_main
+int real_main(void);
+#include "run-15-timeout.c"
+#undef main
+static bool always_debug(struct io_conn *conn) { return true; }
+int main(void) { io_debug = always_debug; return real_main(); }
index f8ddc6a57ed6e21ae492a497476a1cd65c2a6bfa..f8ea6f4c22891c602c339a60401b89830730b5b7 100644 (file)
@@ -7,6 +7,10 @@
 #include <stdio.h>
 #include <unistd.h>
 
 #include <stdio.h>
 #include <unistd.h>
 
+#ifndef PORT
+#define PORT "65015"
+#endif
+
 struct data {
        int state;
        int timeout_usec;
 struct data {
        int state;
        int timeout_usec;
@@ -93,7 +97,7 @@ int main(void)
        d->state = 0;
        d->timed_out = false;
        d->timeout_usec = 100000;
        d->state = 0;
        d->timed_out = false;
        d->timeout_usec = 100000;
-       fd = make_listen_fd("65002", &addrinfo);
+       fd = make_listen_fd(PORT, &addrinfo);
        ok1(fd >= 0);
        l = io_new_listener(fd, init_conn, d);
        ok1(l);
        ok1(fd >= 0);
        l = io_new_listener(fd, init_conn, d);
        ok1(l);