[SSSD] SSSD Test Suite Coverage

Abhishek Singh abhishekkumarsingh.cse at gmail.com
Fri Mar 22 18:33:41 UTC 2013


New tests added to success tests.
Please review it.

Thanks,



On Fri, Mar 22, 2013 at 4:48 PM, Stephen Gallagher <sgallagh at redhat.com>wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Fri 22 Mar 2013 04:32:52 AM EDT, Abhishek Singh wrote:
> >
> > Hi,
> >
> > I have attached a patch that contains cmocka unittest for io.c .
> > Kindly review it.
> >
>
>
> This is a good start, but I'd like to see some more comprehensive
> tests. In the success tests, could you please use fcntl(F_GETFD) to
> confirm that the file descriptor actually has the correct flags? You
> can take a look at the sss_open_cloexec() function implementation for
> inspiration here.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.13 (GNU/Linux)
> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>
> iEYEARECAAYFAlFMPg0ACgkQeiVVYja6o6MHsACfTSehzUmCKYeRVmFeBnOKFUco
> dJIAnj6CGoKH3psZ97dchvTil5jwEIvE
> =hEyx
> -----END PGP SIGNATURE-----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.fedorahosted.org/pipermail/sssd-devel/attachments/20130323/fedb5006/attachment.html>
-------------- next part --------------
From ec6e487e9f741e6a76cae7cccac6e248f2cd24e2 Mon Sep 17 00:00:00 2001
From: Abhishek Singh <abhishekkumarsingh.cse at gmail.com>
Date: Fri, 22 Mar 2013 23:57:12 +0530
Subject: [PATCH] cmocka unittest for io added

---
 Makefile.am                |  13 +++-
 src/tests/cmocka/test_io.c | 148 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 160 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..3e5727a1cf2af5c562c33147a8daaadc68279602
--- /dev/null
+++ b/src/tests/cmocka/test_io.c
@@ -0,0 +1,148 @@
+/*
+    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 ret_flag;
+    int expec_flag;
+    int flags = O_RDWR;
+
+    fd = sss_open_cloexec(FILE_PATH, flags, &ret);
+
+    ret_flag = fcntl(fd, F_GETFD, 0);
+    expec_flag = FD_CLOEXEC;
+
+    assert_true(fd != -1);
+    assert_int_equal(ret_flag, expec_flag);
+
+    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 ret_flag;
+    int expec_flag;
+    int dir_fd;
+    int flags = O_RDWR;
+
+    dir_fd = get_dirfd();
+    fd = sss_openat_cloexec(dir_fd, "test.in", flags, &ret);
+
+    ret_flag = fcntl(fd, F_GETFD, 0);
+    expec_flag = FD_CLOEXEC;
+
+    assert_true(fd != -1);
+    assert_int_equal(ret_flag, expec_flag);
+
+    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