diff options
author | Lukas Slebodnik <lslebodn@redhat.com> | 2014-08-20 19:09:59 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2014-08-22 10:51:28 +0200 |
commit | 12e7e87ccbae0d5c2f338cd019ca51556cbcd3ae (patch) | |
tree | 9f0a4e5139396590f08f2aa52e189d235644253d /src | |
parent | bf65fbdd8c3fecd38a66363c3517e7a2679b8186 (diff) | |
download | sssd-12e7e87ccbae0d5c2f338cd019ca51556cbcd3ae.tar.gz sssd-12e7e87ccbae0d5c2f338cd019ca51556cbcd3ae.tar.xz sssd-12e7e87ccbae0d5c2f338cd019ca51556cbcd3ae.zip |
test_dyndns: Use different talloc context in wrapped functions.
Real functions use own allocation strategy. We use talloc in wrapped functions.
But wrapped functions should not use global_talloc_context,
leak_check_teardown will report false positive memory leaks.
leak_check_teardown()
./src/tests/cmocka/test_dyndns.c:378: error: Failure!
[ FAILED ] dyndns_test_ok_dyndns_test_teardown
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/tests/cmocka/test_dyndns.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/tests/cmocka/test_dyndns.c b/src/tests/cmocka/test_dyndns.c index b7e45a19d..1349fff9d 100644 --- a/src/tests/cmocka/test_dyndns.c +++ b/src/tests/cmocka/test_dyndns.c @@ -47,6 +47,8 @@ enum mock_nsupdate_states { MOCK_NSUPDATE_TIMEOUT, }; +static TALLOC_CTX *global_mock_context = NULL; + struct dyndns_test_ctx { struct sss_test_ctx *tctx; @@ -104,7 +106,7 @@ int __wrap_getifaddrs(struct ifaddrs **_ifap) goto fail; } - ifap = talloc_zero(global_talloc_context, struct ifaddrs); + ifap = talloc_zero(global_mock_context, struct ifaddrs); if (ifap == NULL) { errno = ENOMEM; /* getifaddrs sets errno, too */ goto fail; @@ -198,6 +200,7 @@ void dyndns_test_get_ifaddr(void **state) assert_string_equal(straddr, "192.168.0.1"); talloc_free(addrlist); + assert_true(check_leaks_pop(dyndns_test_ctx) == true); } @@ -356,6 +359,9 @@ void dyndns_test_setup(void **state) }; assert_true(leak_check_setup()); + global_mock_context = talloc_new(global_talloc_context); + assert_non_null(global_mock_context); + dyndns_test_ctx = talloc_zero(global_talloc_context, struct dyndns_test_ctx); assert_non_null(dyndns_test_ctx); @@ -372,9 +378,20 @@ void dyndns_test_setup(void **state) dyndns_test_ctx->be_ctx->conf_path = dyndns_test_ctx->tctx->conf_dom_path; } +void dyndns_test_simple_setup(void **state) +{ + assert_true(leak_check_setup()); + global_mock_context = talloc_new(global_talloc_context); + assert_non_null(global_mock_context); + + dyndns_test_ctx = talloc_zero(global_talloc_context, struct dyndns_test_ctx); + assert_non_null(dyndns_test_ctx); +} + void dyndns_test_teardown(void **state) { talloc_free(dyndns_test_ctx); + talloc_free(global_mock_context); assert_true(leak_check_teardown()); } @@ -394,7 +411,9 @@ int main(int argc, const char *argv[]) const UnitTest tests[] = { /* Utility functions unit test */ - unit_test(dyndns_test_get_ifaddr), + unit_test_setup_teardown(dyndns_test_get_ifaddr, + dyndns_test_simple_setup, + dyndns_test_teardown), /* Dynamic DNS update unit tests*/ unit_test_setup_teardown(dyndns_test_ok, |