test_be_ptask.c revision f818dba78f3e2f3d53ba072e42ac662d2f49edad
65d8ae9c4a66f5ca85289c02dc06d63261c84619Scott Moser Pavel Březina <pbrezina@redhat.com>
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn Copyright (C) 2014 Red Hat
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn This program is free software; you can redistribute it and/or modify
acbb59f50d5196facde837ea377f70e98ce1e6f8Serge Hallyn it under the terms of the GNU General Public License as published by
acbb59f50d5196facde837ea377f70e98ce1e6f8Serge Hallyn the Free Software Foundation; either version 3 of the License, or
acbb59f50d5196facde837ea377f70e98ce1e6f8Serge Hallyn (at your option) any later version.
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn This program is distributed in the hope that it will be useful,
acbb59f50d5196facde837ea377f70e98ce1e6f8Serge Hallyn but WITHOUT ANY WARRANTY; without even the implied warranty of
acbb59f50d5196facde837ea377f70e98ce1e6f8Serge Hallyn MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
acbb59f50d5196facde837ea377f70e98ce1e6f8Serge Hallyn GNU General Public License for more details.
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn You should have received a copy of the GNU General Public License
acbb59f50d5196facde837ea377f70e98ce1e6f8Serge Hallyn along with this program. If not, see <http://www.gnu.org/licenses/>.
1aad9e44d65e7c20dabc4c99f57bcf532db66c68Serge Hallyn cmocka_unit_test_setup_teardown(test_ ## test, test_setup, test_teardown)
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn test_ctx->be_ctx->offstat.went_offline = get_current_time(); \
4759162d078d86628956cae4846c6efccf548e67Serge Hallyn/* Since both test_ctx->done and ptask->req is marked as finished already
4759162d078d86628956cae4846c6efccf548e67Serge Hallyn * in the sync _send function before a new execution is scheduled we need to
4759162d078d86628956cae4846c6efccf548e67Serge Hallyn * rely on the fact that ptask->req is set to zero when a new timer is
daaf41b36790bdaae855048e56ed090b17a77c97Stéphane Graber * created. This way we guarantee that the condition is true only when
4759162d078d86628956cae4846c6efccf548e67Serge Hallyn * the ptask is executed and a new one is scheduled. */
4759162d078d86628956cae4846c6efccf548e67Serge Hallyn#define is_sync_ptask_finished(test_ctx, ptask) \
f2a95ee1bf54c949614a68bf152ea9a8e1d3a172Stéphane Graber/* Mock few backend functions so we don't have to bring the whole
f2a95ee1bf54c949614a68bf152ea9a8e1d3a172Stéphane Graber * data provider into this test. */
bf7d76cf3ae180820c0a29e0bfbaa97c20ce6a3dSerge Hallyn test_ctx = sss_mock_ptr_type(struct test_ctx *);
0a3673e80732ab83d807d406fb2fd3c3b7f54ad3Stéphane Graber test_ctx = sss_mock_ptr_type(struct test_ctx *);
5ff337745e4a705293b056ab58f6ea7a92cabbc8Stéphane Graberstruct tevent_req * test_be_ptask_send(TALLOC_CTX *mem_ctx,
4759162d078d86628956cae4846c6efccf548e67Serge Hallyn test_ctx = talloc_get_type(pvt, struct test_ctx);
ad3f14ab58ec91ff11d0dcf2cbd5f47f02935344Scott Moser req = tevent_req_create(mem_ctx, &state, struct test_be_ptask_state);
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallynstruct tevent_req * test_be_ptask_null_send(TALLOC_CTX *mem_ctx,
65d8ae9c4a66f5ca85289c02dc06d63261c84619Scott Moser test_ctx = talloc_get_type(pvt, struct test_ctx);
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallynstruct tevent_req * test_be_ptask_timeout_send(TALLOC_CTX *mem_ctx,
8a3c76b24d73ab8a830035e7a66400e2cc2e8334Stéphane Graber test_ctx = talloc_get_type(pvt, struct test_ctx);
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn req = tevent_req_create(mem_ctx, &state, struct test_be_ptask_state);
4759162d078d86628956cae4846c6efccf548e67Serge Hallyn /* we won't finish the request */
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallynerrno_t test_be_ptask_recv(struct tevent_req *req)
4759162d078d86628956cae4846c6efccf548e67Serge Hallyn state = tevent_req_data(req, struct test_be_ptask_state);
65d8ae9c4a66f5ca85289c02dc06d63261c84619Scott Mosererrno_t test_be_ptask_error_recv(struct tevent_req *req)
57d116ab501594c2e50ab45f1cf2fae48c5eab09Serge Hallyn state = tevent_req_data(req, struct test_be_ptask_state);
d46417540f61ffb93344f3d338340588bf118ab4Stéphane Graber test_ctx = talloc_get_type(pvt, struct test_ctx);
4b954f12173c382f7104a0e9464fa66dd3cade35Dimitri John Ledkoverrno_t test_be_ptask_sync_error(TALLOC_CTX *mem_ctx,
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn test_ctx = talloc_get_type(pvt, struct test_ctx);
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn test_ctx = talloc_zero(global_talloc_context, struct test_ctx);
9cde0368fbbfa61add2e73f8ccd5b00c1b0f2e08Stéphane Graber test_ctx->tctx = create_ev_test_ctx(test_ctx);
9cde0368fbbfa61add2e73f8ccd5b00c1b0f2e08Stéphane Graber test_ctx->be_ctx = mock_be_ctx(test_ctx, test_ctx->tctx);
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn test_ctx->be_ctx->ev = tevent_context_init(test_ctx->be_ctx);
4759162d078d86628956cae4846c6efccf548e67Serge Hallynvoid test_be_ptask_create_einval_be(void **state)
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn struct test_ctx *test_ctx = (struct test_ctx *)(*state);
f1ccde27c038e7fb7e538913505248b36ddd9e65Serge Hallyn ret = be_ptask_create(test_ctx, NULL, PERIOD, 0, 0, 0, 0,
1aad9e44d65e7c20dabc4c99f57bcf532db66c68Serge Hallyn test_be_ptask_recv, NULL, "Test ptask", &ptask);
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallynvoid test_be_ptask_create_einval_period(void **state)
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn struct test_ctx *test_ctx = (struct test_ctx *)(*state);
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn ret = be_ptask_create(test_ctx, test_ctx->be_ctx, 0, 0, 0, 0, 0,
f1ccde27c038e7fb7e538913505248b36ddd9e65Serge Hallyn test_be_ptask_recv, NULL, "Test ptask", &ptask);
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallynvoid test_be_ptask_create_einval_send(void **state)
57d116ab501594c2e50ab45f1cf2fae48c5eab09Serge Hallyn struct test_ctx *test_ctx = (struct test_ctx *)(*state);
27c278a76931bfc4660caa85d1942ca91c86e0bfStéphane Graber ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
1aad9e44d65e7c20dabc4c99f57bcf532db66c68Serge Hallyn test_be_ptask_recv, NULL, "Test ptask", &ptask);
65d8ae9c4a66f5ca85289c02dc06d63261c84619Scott Moservoid test_be_ptask_create_einval_recv(void **state)
17abf2784de1047fb2904ff130ee5efe4ea7b598Elan Ruusamäe struct test_ctx *test_ctx = (struct test_ctx *)(*state);
d1458ac8d13880f83fa2d1e08623b97c50d311d7Serge Hallyn ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
c01c25fcdd1e0cacad8075bcfcef4c8e8d4b8cb6Stéphane Grabervoid test_be_ptask_create_einval_name(void **state)
57d116ab501594c2e50ab45f1cf2fae48c5eab09Serge Hallyn struct test_ctx *test_ctx = (struct test_ctx *)(*state);
2133f58c66ab7627a4159fafbb75106c556b014dSerge Hallyn ret = be_ptask_create(test_ctx, test_ctx->be_ctx, PERIOD, 0, 0, 0, 0,
&ptask);
&ptask);
&ptask);
int opt;
switch(opt) {