[SSSD] [Patch] Cmocka unit test for negcache.c module

Jakub Hrozek jhrozek at redhat.com
Tue Feb 25 15:40:18 UTC 2014


On Mon, Feb 17, 2014 at 04:47:09PM +0100, Lukas Slebodnik wrote:
> The test(s) don't pass because they cannot pass.
> You used function create_dom_test_ctx and param with filter_groups and
> filter_users and result of this is configuration:
> 
> [domain/nss_test]
> filter_users = testuser1
> filter_groups = testgroup1
> 
> But negative cache reads configuration options from [nss] section.

No, it reads from both actually and domain takes precedence.

> 
> [nss]
> filter_users = testuser1
> filter_groups = testgroup1

There was two different bugs in the test. Because the domain structure
was created with talloc, the ->next pointer was random data and a for
loop that walked through the list of domains crashed.

The second bug was that the test used different domain name for the
domain structure (NAME) and a different name when generating the
configuration (TEST_DOM_NAME) so the config was never read actually.

Attached is a snippet that I used to fix the test. Pallavi, if you
agree, please resubmit your patch with the snippet squashed in.

btw I didn't know what was test_sss_ncache_reset_permanent() about, so I
removed it during my testing..feel free to retain it in the final patch,
but please don't leave if-ed code in the resulting test.
-------------- next part --------------
>From 52702a54761cb9018b2accd5c05f36f9575f166d Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Tue, 25 Feb 2014 16:36:15 +0100
Subject: [PATCH] fix the negcache test

---
 src/tests/cmocka/test_negcache.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/src/tests/cmocka/test_negcache.c b/src/tests/cmocka/test_negcache.c
index 85903a3be7900e39a3bebac438d6e7d977f177d3..0ae275db770cf6625f9c8ec503e7451eabb5a827 100644
--- a/src/tests/cmocka/test_negcache.c
+++ b/src/tests/cmocka/test_negcache.c
@@ -557,18 +557,6 @@ static void test_sss_ncache_service_port(void **state)
     assert_int_equal(ret, EEXIST);
 }
 
-#if 0
-static void test_sss_ncache_reset_permanent(void **state)
-{
-    int ret;
-    struct test_state *ts;
-
-    ts = talloc_get_type_abort(*state, struct test_state);
-    ret = sss_ncache_reset_permanent(ts->ctx);
-    assert_int_equal(ret, EOK);
-}
-#endif
-
 static void test_sss_ncache_prepopulate(void **state)
 {
     int ret;
@@ -589,7 +577,7 @@ static void test_sss_ncache_prepopulate(void **state)
     ev = tevent_context_init(ts);
     assert_non_null(ev);
 
-    dom = talloc(ts, struct sss_domain_info);
+    dom = talloc_zero(ts, struct sss_domain_info);
     assert_non_null(dom);
     dom->name = discard_const(NAME);
 
@@ -597,7 +585,7 @@ static void test_sss_ncache_prepopulate(void **state)
     assert_non_null(ts->nctx);
 
     tc = create_dom_test_ctx(ts, TESTS_PATH, TEST_CONF_DB,
-                             TEST_SYSDB_FILE, TEST_DOM_NAME,
+                             TEST_SYSDB_FILE, NAME,
                              TEST_ID_PROVIDER, params);
     assert_non_null(tc);
 
-- 
1.8.5.3



More information about the sssd-devel mailing list