Line data Source code
1 : /*
2 : Authors:
3 : Jakub Hrozek <jhrozek@redhat.com>
4 :
5 : Copyright (C) 2013 Red Hat
6 :
7 : SSSD tests: Common utilities for tests that exercise domains
8 :
9 : This program is free software; you can redistribute it and/or modify
10 : it under the terms of the GNU General Public License as published by
11 : the Free Software Foundation; either version 3 of the License, or
12 : (at your option) any later version.
13 :
14 : This program is distributed in the hope that it will be useful,
15 : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : GNU General Public License for more details.
18 :
19 : You should have received a copy of the GNU General Public License
20 : along with this program. If not, see <http://www.gnu.org/licenses/>.
21 : */
22 :
23 : #include <tevent.h>
24 : #include <talloc.h>
25 : #include <errno.h>
26 :
27 : #include "tests/common.h"
28 :
29 : struct sss_test_ctx *
30 201 : create_ev_test_ctx(TALLOC_CTX *mem_ctx)
31 : {
32 : struct sss_test_ctx *test_ctx;
33 :
34 201 : test_ctx = talloc_zero(mem_ctx, struct sss_test_ctx);
35 201 : if (test_ctx == NULL) {
36 0 : DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero failed\n");
37 0 : goto fail;
38 : }
39 :
40 : /* Create an event context */
41 201 : test_ctx->ev = tevent_context_init(test_ctx);
42 201 : if (test_ctx->ev == NULL) {
43 0 : DEBUG(SSSDBG_CRIT_FAILURE, "tevent_context_init failed\n");
44 0 : goto fail;
45 : }
46 :
47 201 : return test_ctx;
48 :
49 : fail:
50 0 : talloc_free(test_ctx);
51 0 : return NULL;
52 : }
53 :
54 : struct tevent_req *
55 164 : test_request_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, errno_t err)
56 : {
57 : struct tevent_req *req;
58 : int *state;
59 :
60 164 : req = tevent_req_create(mem_ctx, &state, int);
61 164 : if (!req) return NULL;
62 :
63 164 : if (err == EOK) {
64 164 : tevent_req_done(req);
65 : } else {
66 0 : tevent_req_error(req, err);
67 : }
68 164 : tevent_req_post(req, ev);
69 164 : return req;
70 : }
71 :
72 129 : errno_t test_request_recv(struct tevent_req *req)
73 : {
74 129 : TEVENT_REQ_RETURN_ON_ERROR(req);
75 :
76 129 : return EOK;
77 : }
78 :
79 169 : int test_ev_loop(struct sss_test_ctx *tctx)
80 : {
81 2689 : while (!tctx->done)
82 2351 : tevent_loop_once(tctx->ev);
83 :
84 169 : return tctx->error;
85 : }
86 :
87 14 : void test_ev_done(struct sss_test_ctx *tctx, errno_t ret)
88 : {
89 14 : tctx->error = ret;
90 14 : tctx->done = true;
91 14 : }
|