2 Unix SMB/CIFS implementation.
4 testing of the events subsystem
6 Copyright (C) Stefan Metzmacher
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "lib/events/events.h"
25 #include "system/filesys.h"
26 #include "torture/torture.h"
28 static int write_fd, read_fd;
29 static struct fd_event *fde;
32 static struct torture_context *test;
34 static void fde_handler(struct event_context *ev_ctx, struct fd_event *f,
35 uint16_t flags, void *private)
39 torture_comment(test, "event[%d] fd[%d] events[0x%08X]%s%s\n",
40 fde_count, *fd, flags,
41 (flags & EVENT_FD_READ)?" EVENT_FD_READ":"",
42 (flags & EVENT_FD_WRITE)?" EVENT_FD_WRITE":"");
45 torture_result(test, TORTURE_FAIL,
46 __location__": got more than fde 5 events - bug!");
52 event_set_fd_flags(fde, 0);
56 static void timed_handler(struct event_context *ev_ctx, struct timed_event *te,
57 struct timeval tval, void *private)
59 torture_comment(test, "timed_handler called[%d]\n", te_count);
65 torture_comment(test, "remove fd event!\n");
71 event_add_timed(ev_ctx, ev_ctx, timeval_current_ofs(0,500), timed_handler, private);
74 static bool test_event_context(struct torture_context *torture_ctx,
75 const void *test_data)
77 struct event_context *ev_ctx;
78 int fd[2] = { -1, -1 };
79 const char *backend = (const char *)test_data;
80 TALLOC_CTX *mem_ctx = torture_ctx;
84 ev_ctx = event_context_init_byname(mem_ctx, backend);
86 torture_comment(test, "event backend '%s' not supported\n", backend);
90 torture_comment(test, "Testing event backend '%s'\n", backend);
104 fde = event_add_fd(ev_ctx, ev_ctx, read_fd, EVENT_FD_READ,
105 fde_handler, &read_fd);
107 event_add_timed(ev_ctx, ev_ctx, timeval_current_ofs(0,500),
111 event_loop_once(ev_ctx);
121 struct torture_suite *torture_local_event(TALLOC_CTX *mem_ctx)
123 struct torture_suite *suite = torture_suite_create(mem_ctx, "EVENT");
124 const char **list = event_backend_list(suite);
127 for (i=0;list && list[i];i++) {
128 torture_suite_add_simple_tcase(suite, list[i],
130 (const void *)list[i]);