2 Unix SMB/CIFS implementation.
4 testing of the events subsystem
6 Copyright (C) Stefan Metzmacher 2006-2009
8 ** NOTE! The following LGPL license applies to the tevent
9 ** library. This does NOT imply that all of Samba is released
12 This library is free software; you can redistribute it and/or
13 modify it under the terms of the GNU Lesser General Public
14 License as published by the Free Software Foundation; either
15 version 3 of the License, or (at your option) any later version.
17 This library is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Lesser General Public License for more details.
22 You should have received a copy of the GNU Lesser General Public
23 License along with this library; if not, see <http://www.gnu.org/licenses/>.
27 #include "lib/tevent/tevent.h"
28 #include "system/filesys.h"
29 #include "torture/torture.h"
33 static void fde_handler(struct tevent_context
*ev_ctx
, struct tevent_fd
*f
,
34 uint16_t flags
, void *private_data
)
36 int *fd
= (int *)private_data
;
39 kill(getpid(), SIGUSR1
);
41 kill(getpid(), SIGALRM
);
47 static void finished_handler(struct tevent_context
*ev_ctx
, struct tevent_timer
*te
,
48 struct timeval tval
, void *private_data
)
50 int *finished
= (int *)private_data
;
54 static void count_handler(struct tevent_context
*ev_ctx
, struct tevent_signal
*te
,
55 int signum
, int count
, void *info
, void *private_data
)
57 int *countp
= (int *)private_data
;
61 static bool test_event_context(struct torture_context
*test
,
62 const void *test_data
)
64 struct tevent_context
*ev_ctx
;
65 int fd
[2] = { -1, -1 };
66 const char *backend
= (const char *)test_data
;
67 int alarm_count
=0, info_count
=0;
68 struct tevent_fd
*fde
;
70 struct tevent_signal
*se1
= NULL
;
72 struct tevent_signal
*se2
= NULL
;
74 struct tevent_signal
*se3
= NULL
;
80 ev_ctx
= tevent_context_init_byname(test
, backend
);
82 torture_comment(test
, "event backend '%s' not supported\n", backend
);
86 torture_comment(test
, "Testing event backend '%s'\n", backend
);
94 fde
= tevent_add_fd(ev_ctx
, ev_ctx
, fd
[0], TEVENT_FD_READ
,
96 tevent_fd_set_auto_close(fde
);
98 tevent_add_timer(ev_ctx
, ev_ctx
, timeval_current_ofs(2,0),
99 finished_handler
, &finished
);
102 se1
= tevent_add_signal(ev_ctx
, ev_ctx
, SIGALRM
, SA_RESTART
, count_handler
, &alarm_count
);
105 se2
= tevent_add_signal(ev_ctx
, ev_ctx
, SIGALRM
, SA_RESETHAND
, count_handler
, &alarm_count
);
108 se3
= tevent_add_signal(ev_ctx
, ev_ctx
, SIGUSR1
, SA_SIGINFO
, count_handler
, &info_count
);
113 t
= timeval_current();
116 if (tevent_loop_once(ev_ctx
) == -1) {
118 torture_fail(test
, talloc_asprintf(test
, "Failed event loop %s\n", strerror(errno
)));
125 while (alarm_count
< fde_count
+1) {
126 if (tevent_loop_once(ev_ctx
) == -1) {
131 torture_comment(test
, "Got %.2f pipe events/sec\n", fde_count
/timeval_elapsed(&t
));
137 torture_assert_int_equal(test
, alarm_count
, 1+fde_count
, "alarm count mismatch");
141 torture_assert_int_equal(test
, info_count
, fde_count
, "info count mismatch");
149 struct torture_suite
*torture_local_event(TALLOC_CTX
*mem_ctx
)
151 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "event");
152 const char **list
= tevent_backend_list(suite
);
155 for (i
=0;list
&& list
[i
];i
++) {
156 torture_suite_add_simple_tcase_const(suite
, list
[i
],
158 (const void *)list
[i
]);