Sophie

Sophie

distrib > Mageia > 6 > armv7hl > media > core-updates-src > by-pkgid > 655a3b499c6651e9ecbb8a6afc4f0743 > files > 8

sssd-1.13.4-9.1.mga6.src.rpm

From 78040843f5a2cb34f9729a45e806a5ce2d9f6024 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek@redhat.com>
Date: Fri, 15 Jan 2016 11:24:11 +0100
Subject: [PATCH 04/24] tests: Extend test_child_common.c to include tests for
 the only_extra_args functionality
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Reviewed-by: Sumit Bose <sbose@redhat.com>
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
(cherry picked from commit b5797517abb117cff7330acc894b71deda74be3d)
(cherry picked from commit 166c06a0cd867ca516dcaece6ba0e9af486452f1)
---
 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.7.4