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 3 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, see <http://www.gnu.org/licenses/>.
23 #include "lib/events/events.h"
24 #include "system/filesys.h"
25 #include "torture/torture.h"
29 static void fde_handler(struct tevent_context
*ev_ctx
, struct tevent_fd
*f
,
30 uint16_t flags
, void *private)
32 int *fd
= (int *)private;
35 kill(getpid(), SIGUSR1
);
37 kill(getpid(), SIGALRM
);
43 static void finished_handler(struct tevent_context
*ev_ctx
, struct tevent_timer
*te
,
44 struct timeval tval
, void *private)
46 int *finished
= (int *)private;
50 static void count_handler(struct tevent_context
*ev_ctx
, struct signal_event
*te
,
51 int signum
, int count
, void *info
, void *private)
53 int *countp
= (int *)private;
57 static bool test_event_context(struct torture_context
*test
,
58 const void *test_data
)
60 struct tevent_context
*ev_ctx
;
61 int fd
[2] = { -1, -1 };
62 const char *backend
= (const char *)test_data
;
63 int alarm_count
=0, info_count
=0;
64 struct tevent_fd
*fde
;
65 struct signal_event
*se1
, *se2
, *se3
;
70 ev_ctx
= event_context_init_byname(test
, backend
);
72 torture_comment(test
, "event backend '%s' not supported\n", backend
);
76 torture_comment(test
, "Testing event backend '%s'\n", backend
);
84 fde
= event_add_fd(ev_ctx
, ev_ctx
, fd
[0], EVENT_FD_READ
,
86 tevent_fd_set_auto_close(fde
);
88 event_add_timed(ev_ctx
, ev_ctx
, timeval_current_ofs(2,0),
89 finished_handler
, &finished
);
91 se1
= event_add_signal(ev_ctx
, ev_ctx
, SIGALRM
, SA_RESTART
, count_handler
, &alarm_count
);
92 se2
= event_add_signal(ev_ctx
, ev_ctx
, SIGALRM
, SA_RESETHAND
, count_handler
, &alarm_count
);
94 se3
= event_add_signal(ev_ctx
, ev_ctx
, SIGUSR1
, SA_SIGINFO
, count_handler
, &info_count
);
99 t
= timeval_current();
102 if (event_loop_once(ev_ctx
) == -1) {
104 torture_fail(test
, talloc_asprintf(test
, "Failed event loop %s\n", strerror(errno
)));
111 while (alarm_count
< fde_count
+1) {
112 if (event_loop_once(ev_ctx
) == -1) {
117 torture_comment(test
, "Got %.2f pipe events/sec\n", fde_count
/timeval_elapsed(&t
));
121 torture_assert_int_equal(test
, alarm_count
, 1+fde_count
, "alarm count mismatch");
125 torture_assert_int_equal(test
, info_count
, fde_count
, "info count mismatch");
133 struct torture_suite
*torture_local_event(TALLOC_CTX
*mem_ctx
)
135 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "EVENT");
136 const char **list
= event_backend_list(suite
);
139 for (i
=0;list
&& list
[i
];i
++) {
140 torture_suite_add_simple_tcase_const(suite
, list
[i
],
142 (const void *)list
[i
]);