[SSSD] SSSD Test Suite Coverage

Abhishek Singh abhishekkumarsingh.cse at gmail.com
Fri Mar 22 08:32:52 UTC 2013


Hi,

I have attached a patch that contains cmocka unittest for io.c . Kindly
review it.

thanks


On Tue, Mar 19, 2013 at 12:52 AM, Jakub Hrozek <jhrozek at redhat.com> wrote:

> On Tue, Mar 19, 2013 at 12:31:09AM +0530, Abhishek Singh wrote:
> > Changes done.
> >
> > My public repo of sssd : https://github.com/AbhishekKumarSingh/sssd
> >
>
> Hi Abhishek,
>
> this is much better, thank you!
>
> I only have two minor style nitpicks now:
> 1) void test_check_if_uid_is_active_success(void ** state)
> We usually don't put a space after the asterisk that denotes a pointer
> and the variable name. In other words, we would have used:
> "void **state"
>
> 2) In main(), I think it would be more readable to put a tab (in my
> .vimrc a tab expands to 4 spaces) before names of the tests. So this
> block:
>  96 int main(void)
>  97 {
>  98     const UnitTest tests[] = {
>  99     unit_test(test_check_if_uid_is_active_success),
> 100     unit_test(test_check_if_uid_is_active_fail),
> 101     unit_test(test_get_uid_table)
> 102     };
>
> Would become this:
>  96 int main(void)
>  97 {
>  98     const UnitTest tests[] = {
>  99         unit_test(test_check_if_uid_is_active_success),
> 100         unit_test(test_check_if_uid_is_active_fail),
> 101         unit_test(test_get_uid_table)
> 102     };
>
> Otherwise the test looks very good to me. Compiles and runs just fine.
> There's no need to send the patches to the list if you fix these, just
> push the changes to your local repo and I'll check them out.
>
> For the record, on IRC we agreed that Abhishek's next step might be to
> take a look at one of the modules in the src/utils subdirectory that are
> lacking tests. The advantage is that those modules are just utility
> functions that are fully synchronous so he wouldn't have to worry about
> tevent (yet :-)). Two candidates that come to mind are
> src/util/backup_file.c and src/util/io.c
>
> Great work so far Abhishek!
> _______________________________________________
> sssd-devel mailing list
> sssd-devel at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/sssd-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.fedorahosted.org/pipermail/sssd-devel/attachments/20130322/36371fcc/attachment.html>
-------------- next part --------------
From 6d13f84b8e74de1d8fcce7e505c78b8474f402b0 Mon Sep 17 00:00:00 2001
From: Abhishek Singh <abhishekkumarsingh.cse at gmail.com>
Date: Fri, 22 Mar 2013 14:00:48 +0530
Subject: [PATCH] cmocka unittest for io added

---
 Makefile.am                |  13 ++++-
 src/tests/cmocka/test_io.c | 138 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 150 insertions(+), 1 deletion(-)
 create mode 100644 src/tests/cmocka/test_io.c

diff --git a/Makefile.am b/Makefile.am
index a52629748c6633a7c6ded5a110704292ceb70e90..02dd90ce46f7143c3f8ac7cfa79471ab95eaffe5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -141,7 +141,8 @@ endif
 if HAVE_CMOCKA
     non_interactive_cmocka_based_tests = \
         nss-srv-tests \
-        test-find-uid
+        test-find-uid \
+        test-io
 endif
 
 check_PROGRAMS = \
@@ -1218,6 +1219,16 @@ test_find_uid_LDADD = \
     $(DHASH_LIBS) \
     $(CMOCKA_LIBS) \
     libsss_util.la
+
+test_io_DEPENDENCIES = \
+    $(ldblib_LTLIBRARIES)
+test_io_SOURCES = \
+    src/tests/cmocka/test_io.c \
+    src/util/io.c
+test_io_CFLAGS = \
+    $(AM_CFLAGS)
+test_io_LDADD = \
+    $(CMOCKA_LIBS)
 endif
 
 noinst_PROGRAMS = pam_test_client
diff --git a/src/tests/cmocka/test_io.c b/src/tests/cmocka/test_io.c
new file mode 100644
index 0000000000000000000000000000000000000000..b70c091d6193a0cb5525c109ad1937d53b52e2d4
--- /dev/null
+++ b/src/tests/cmocka/test_io.c
@@ -0,0 +1,138 @@
+/*
+    SSSD
+
+    find_uid - Utilities tests
+
+    Authors:
+        Abhishek Singh <abhishekkumarsingh.cse at gmail.com>
+
+    Copyright (C) 2013 Red Hat
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <dirent.h>
+#include <unistd.h>
+
+#include "util/io.h"
+
+#define FILE_PATH "/tmp/test.in"
+#define NON_EX_PATH "non-existent-path"
+
+static void setup_all(void)
+{
+    FILE *fp;
+    fp = fopen(FILE_PATH, "w");
+    if (fp != NULL)
+        fclose(fp);
+    else
+        printf("Error! file test.in can't be created");
+}
+
+static void teardown_all(void)
+{
+    remove(FILE_PATH);
+}
+
+static int get_dirfd(void)
+{
+    int dir_fd;
+    DIR *tmp = opendir("/tmp");
+        if (tmp != NULL)
+            dir_fd = dirfd(tmp);
+
+    return dir_fd;
+}
+
+void test_sss_open_cloexec_success(void **state)
+{
+    int fd;
+    int ret;
+    int flags = O_RDWR;
+
+    fd = sss_open_cloexec(FILE_PATH, flags, &ret);
+
+    assert_true(fd != -1);
+    assert_int_equal(ret, 0);
+
+    close(fd);
+}
+
+void test_sss_open_cloexec_fail(void **state)
+{
+    int fd;
+    int ret;
+    int flags = O_RDWR;
+
+    fd = sss_open_cloexec(NON_EX_PATH, flags, &ret);
+
+    assert_true(fd == -1);
+    assert_int_not_equal(ret, 0);
+
+    close(fd);
+}
+
+void test_sss_openat_cloexec_success(void **state)
+{
+    int fd;
+    int ret;
+    int dir_fd;
+    int flags = O_RDWR;
+
+    dir_fd = get_dirfd();
+    fd = sss_openat_cloexec(dir_fd, "test.in", flags, &ret);
+
+    assert_true(fd != -1);
+    assert_int_equal(ret, 0);
+
+    close(fd);
+}
+
+void test_sss_openat_cloexec_fail(void **state)
+{
+    int fd;
+    int ret;
+    int dir_fd;
+    int flags = O_RDWR;
+
+    dir_fd = get_dirfd();
+    fd = sss_openat_cloexec(dir_fd, NON_EX_PATH, flags, &ret);
+
+    assert_true(fd == -1);
+    assert_int_not_equal(ret, 0);
+
+    close(fd);
+}
+
+int main(void)
+{
+    const UnitTest tests[] = {
+        unit_test_setup_teardown(test_sss_open_cloexec_success, setup_all,
+                                 teardown_all),
+        unit_test_setup_teardown(test_sss_open_cloexec_fail, setup_all,
+                                 teardown_all),
+        unit_test_setup_teardown(test_sss_openat_cloexec_success, setup_all,
+                                 teardown_all),
+        unit_test_setup_teardown(test_sss_openat_cloexec_fail, setup_all,
+                                 teardown_all)
+    };
+
+    return run_tests(tests);
+}
-- 
1.8.1.4


More information about the sssd-devel mailing list