Hi,

the attached patch was already acked by Sumit as part of the adcli
thread, so I'd like to push it now.
>From 52003e9d03a38e863b46bb25fffd803ecf1716e5 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhro...@redhat.com>
Date: Fri, 15 Jan 2016 11:24:11 +0100
Subject: [PATCH] tests: Extend test_child_common.c to include tests for the
 only_extra_args functionality

---
 src/tests/cmocka/dummy_child.c       | 19 +++++++++
 src/tests/cmocka/test_child_common.c | 79 ++++++++++++++++++++++++++++++++----
 2 files changed, 91 insertions(+), 7 deletions(-)

diff --git a/src/tests/cmocka/dummy_child.c b/src/tests/cmocka/dummy_child.c
index 
3f79ca837b92b8e8ea60ae45eec4c9148f162719..bcaa9455037a0604422750bf7cc719a25cef4a99
 100644
--- a/src/tests/cmocka/dummy_child.c
+++ b/src/tests/cmocka/dummy_child.c
@@ -84,6 +84,25 @@ int main(int argc, const char *argv[])
                 DEBUG(SSSDBG_CRIT_FAILURE, "This band sounds weird\n");
                 _exit(1);
             }
+        } else if (strcasecmp(action, "check_only_extra_args") == 0) {
+            if (debug_timestamps == 1) {
+                DEBUG(SSSDBG_CRIT_FAILURE,
+                      "debug_timestamp was passed when only extra args "
+                      "should have been\n");
+                _exit(1);
+            }
+
+            if (!(strcmp(guitar, "george") == 0 \
+                        && strcmp(drums, "ringo") == 0)) {
+                DEBUG(SSSDBG_CRIT_FAILURE, "This band sounds weird\n");
+                _exit(1);
+            }
+        } else if (strcasecmp(action, "check_only_extra_args_neg") == 0) {
+            if (debug_timestamps != 1) {
+                DEBUG(SSSDBG_CRIT_FAILURE,
+                      "debug_timestamp was not passed as expected\n");
+                _exit(1);
+            }
         } else if (strcasecmp(action, "echo") == 0) {
             errno = 0;
             len = sss_atomic_read_s(STDIN_FILENO, buf, IN_BUF_SIZE);
diff --git a/src/tests/cmocka/test_child_common.c 
b/src/tests/cmocka/test_child_common.c
index 
9ed9c1ae42dd93cef833b738c29259a18e791339..423132bdf7c1e429ce895821c8c7ed5e013ecb55
 100644
--- a/src/tests/cmocka/test_child_common.c
+++ b/src/tests/cmocka/test_child_common.c
@@ -38,6 +38,8 @@ struct child_test_ctx {
     int pipefd_from_child[2];
 
     struct sss_test_ctx *test_ctx;
+
+    int save_debug_timestamps;
 };
 
 static int child_test_setup(void **state)
@@ -119,27 +121,58 @@ void test_exec_child(void **state)
     }
 }
 
-/* Make sure extra arguments are passed correctly */
-void test_exec_child_extra_args(void **state)
+static int only_extra_args_setup(void **state)
 {
+    struct child_test_ctx *child_tctx;
     errno_t ret;
-    pid_t child_pid;
-    int status;
+
+    ret = child_test_setup((void **) &child_tctx);
+    if (ret != 0) {
+        return ret;
+    }
+
+    child_tctx->save_debug_timestamps = debug_timestamps;
+    *state = child_tctx;
+
+    return 0;
+}
+
+static int only_extra_args_teardown(void **state)
+{
     struct child_test_ctx *child_tctx = talloc_get_type(*state,
                                                         struct child_test_ctx);
+    errno_t ret;
+
+    debug_timestamps = child_tctx->save_debug_timestamps;
+    ret = child_test_teardown((void **) &child_tctx);
+    if (ret != 0) {
+        return ret;
+    }
+
+    return 0;
+}
+
+static void extra_args_test(struct child_test_ctx *child_tctx,
+                            bool extra_args_only)
+{
+    pid_t child_pid;
+    errno_t ret;
+    int status;
+
     const char *extra_args[] = { "--guitar=george",
                                  "--drums=ringo",
                                  NULL };
 
-    setenv("TEST_CHILD_ACTION", "check_extra_args", 1);
-
     child_pid = fork();
     assert_int_not_equal(child_pid, -1);
     if (child_pid == 0) {
+        debug_timestamps = 1;
+
         ret = exec_child_ex(child_tctx,
                             child_tctx->pipefd_to_child,
                             child_tctx->pipefd_from_child,
-                            CHILD_DIR"/"TEST_BIN, 2, extra_args, false,
+                            CHILD_DIR"/"TEST_BIN, 2, extra_args,
+                            extra_args_only,
                             STDIN_FILENO, STDOUT_FILENO);
         assert_int_equal(ret, EOK);
     } else {
@@ -162,6 +195,32 @@ void test_exec_child_extra_args(void **state)
     }
 }
 
+/* Make sure extra arguments are passed correctly */
+void test_exec_child_extra_args(void **state)
+{
+    struct child_test_ctx *child_tctx = talloc_get_type(*state,
+                                                        struct child_test_ctx);
+    setenv("TEST_CHILD_ACTION", "check_extra_args", 1);
+    extra_args_test(child_tctx, false);
+}
+
+/* Make sure extra arguments are passed correctly */
+void test_exec_child_only_extra_args(void **state)
+{
+    struct child_test_ctx *child_tctx = talloc_get_type(*state,
+                                                        struct child_test_ctx);
+    setenv("TEST_CHILD_ACTION", "check_only_extra_args", 1);
+    extra_args_test(child_tctx, true);
+}
+
+void test_exec_child_only_extra_args_neg(void **state)
+{
+    struct child_test_ctx *child_tctx = talloc_get_type(*state,
+                                                        struct child_test_ctx);
+    setenv("TEST_CHILD_ACTION", "check_only_extra_args_neg", 1);
+    extra_args_test(child_tctx, false);
+}
+
 struct tevent_req *echo_child_write_send(TALLOC_CTX *mem_ctx,
                                          struct child_test_ctx *child_tctx,
                                          struct child_io_fds *io_fds,
@@ -478,6 +537,12 @@ int main(int argc, const char *argv[])
         cmocka_unit_test_setup_teardown(test_sss_child,
                                         child_test_setup,
                                         child_test_teardown),
+        cmocka_unit_test_setup_teardown(test_exec_child_only_extra_args,
+                                        only_extra_args_setup,
+                                        only_extra_args_teardown),
+        cmocka_unit_test_setup_teardown(test_exec_child_only_extra_args_neg,
+                                        only_extra_args_setup,
+                                        only_extra_args_teardown),
     };
 
     /* Set debug level to invalid value so we can deside if -d 0 was used. */
-- 
2.4.3

_______________________________________________
sssd-devel mailing list
sssd-devel@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/sssd-devel@lists.fedorahosted.org

Reply via email to