sq test_event_fd1
authorStefan Metzmacher <metze@samba.org>
Wed, 27 Feb 2013 15:37:09 +0000 (16:37 +0100)
committerStefan Metzmacher <metze@samba.org>
Wed, 27 Feb 2013 15:37:09 +0000 (16:37 +0100)
lib/tevent/testsuite.c

index a07772d558cd0fba2d8fa92034e1bba0056e8bf6..dd972414b3f47460d044694961639de21a0fd117 100644 (file)
@@ -192,7 +192,8 @@ struct test_event_fd1_state {
        struct tevent_context *ev;
        int sock[2];
        struct tevent_timer *te;
-       struct tevent_fd *fde;
+       struct tevent_fd *fde0;
+       struct tevent_fd *fde1;
        bool got_write;
        bool got_read;
        unsigned loop_count;
@@ -273,7 +274,7 @@ static void test_event_fd1_finished(struct tevent_context *ev_ctx,
        state->got_write = false;
        state->got_read = false;
 
-       tevent_fd_set_flags(state->fde, TEVENT_FD_WRITE);
+       tevent_fd_set_flags(state->fde0, TEVENT_FD_WRITE);
 
        state->te = tevent_add_timer(state->ev, state->ev,
                                    timeval_current_ofs(0,1000),
@@ -301,6 +302,20 @@ static bool test_event_fd1(struct torture_context *tctx,
        torture_comment(tctx, "backend '%s' - %s\n",
                        state.backend, __FUNCTION__);
 
+       /*
+        * This tests the following:
+        *
+        * It monitors the state of state.sock[0]
+        * with tevent_fd, but we never read/write on state.sock[0]
+        * while state.sock[1] * is only used to write a few bytes.
+        *
+        * We have a loop:
+        *   - we wait only for TEVENT_FD_WRITE on state.sock[0]
+        *   - we write 1 byte to state.sock[1]
+        *   - we wait only for TEVENT_FD_READ on state.sock[0]
+        *   - we disable events on state.sock[0]
+        *   - the timer event restarts the loop
+        */
        state.sock[0] = -1;
        state.sock[1] = -1;
        socketpair(AF_UNIX, SOCK_STREAM, 0, state.sock);
@@ -308,11 +323,16 @@ static bool test_event_fd1(struct torture_context *tctx,
        state.te = tevent_add_timer(state.ev, state.ev,
                                    timeval_current_ofs(0,1000),
                                    test_event_fd1_finished, &state);
-       state.fde = tevent_add_fd(state.ev, state.ev,
-                                 state.sock[0], TEVENT_FD_WRITE,
-                                 test_event_fd1_fde_handler, &state);
+       state.fde0 = tevent_add_fd(state.ev, state.ev,
+                                  state.sock[0], TEVENT_FD_WRITE,
+                                  test_event_fd1_fde_handler, &state);
+       /* state.fde1 is only used to auto close */
+       state.fde1 = tevent_add_fd(state.ev, state.ev,
+                                  state.sock[1], 0,
+                                  test_event_fd1_fde_handler, &state);
 
-       tevent_fd_set_auto_close(state.fde);
+       tevent_fd_set_auto_close(state.fde0);
+       tevent_fd_set_auto_close(state.fde1);
 
        while (!state.finished) {
                errno = 0;
@@ -326,6 +346,9 @@ static bool test_event_fd1(struct torture_context *tctx,
 
        talloc_free(state.ev);
 
+       torture_assert(tctx, state.error == NULL, talloc_asprintf(tctx,
+                      "%s", state.error));
+
        return true;
 }