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 const struct event_ops
*event_standard_get_ops(void);
29 const struct event_ops
*event_liboop_get_ops(void);
30 const struct event_ops
*gtk_event_get_ops(void);
32 static int write_fd
, read_fd
;
33 static struct fd_event
*fde
;
36 static struct torture_context
*test
;
38 static void fde_handler(struct event_context
*ev_ctx
, struct fd_event
*f
,
39 uint16_t flags
, void *private)
43 torture_comment(test
, "event[%d] fd[%d] events[0x%08X]%s%s\n",
44 fde_count
, *fd
, flags
,
45 (flags
& EVENT_FD_READ
)?" EVENT_FD_READ":"",
46 (flags
& EVENT_FD_WRITE
)?" EVENT_FD_WRITE":"");
49 _torture_fail_ext(test
, "got more than fde 5 events - bug!");
55 event_set_fd_flags(fde
, 0);
59 static void timed_handler(struct event_context
*ev_ctx
, struct timed_event
*te
,
60 struct timeval tval
, void *private)
62 torture_comment(test
, "timed_handler called[%d]\n", te_count
);
68 torture_comment(test
, "remove fd event!\n");
74 event_add_timed(ev_ctx
, ev_ctx
, timeval_current_ofs(0,500), timed_handler
, private);
77 static bool test_event_context(struct torture_context
*torture_ctx
,
78 const void *test_data
)
80 struct event_context
*ev_ctx
;
81 int fd
[2] = { -1, -1 };
82 BOOL try_epoll
= (BOOL
)test_data
;
83 TALLOC_CTX
*mem_ctx
= torture_ctx
;
85 ev_ctx
= event_context_init_ops(mem_ctx
,
86 event_standard_get_ops(),
103 fde
= event_add_fd(ev_ctx
, ev_ctx
, read_fd
, EVENT_FD_READ
, fde_handler
, &read_fd
);
105 event_add_timed(ev_ctx
, ev_ctx
, timeval_current_ofs(0,500), timed_handler
, fde
);
107 event_loop_wait(ev_ctx
);
116 struct torture_suite
*torture_local_event(TALLOC_CTX
*mem_ctx
)
118 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "EVENT");
120 torture_suite_add_simple_tcase(suite
, "standard with select",
124 torture_suite_add_simple_tcase(suite
, "standard try epoll (or select)",