Fix multiple definitions of runInChild 21/156521/1
authorZofia Abramowska <z.abramowska@samsung.com>
Wed, 18 Oct 2017 14:58:38 +0000 (16:58 +0200)
committerZofia Abramowska <z.abramowska@samsung.com>
Wed, 18 Oct 2017 15:01:05 +0000 (17:01 +0200)
security-manager tests and cynara-tests both have
runInChild defined. This should be moved to tests
commons, so there would be no conflict in future.

Change-Id: I28b2ebf1b2d02ccb8a483f741b0a701bf46303b1

src/common/tests_common.cpp
src/common/tests_common.h
src/cynara-tests/test_cases_helpers.cpp
src/security-manager-tests/common/sm_commons.cpp
src/security-manager-tests/common/sm_commons.h

index d08893c..b5dff60 100644 (file)
@@ -246,3 +246,26 @@ void change_label(const char* label)
     int ret = smack_set_label_for_self(label);
     RUNNER_ASSERT_MSG(0 == ret, "Error in smack_set_label_for_self("<<label<<"). Error: " << ret);
 }
+
+pid_t runInChild(const std::function<void(void)> &process) {
+    pid_t pid = fork();
+    RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "fork failed");
+
+    if (pid == 0) {
+        process();
+        exit(EXIT_SUCCESS);
+    }
+    return pid;
+}
+
+void runInChildParentWait(const std::function<void(void)> &process) {
+    pid_t pid = fork();
+    RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "fork failed");
+    if (pid == 0) {
+        process();
+        exit(EXIT_SUCCESS);
+    } else {
+        waitPid(pid);
+    }
+}
+
index 251e111..3f109b9 100644 (file)
@@ -29,7 +29,8 @@
 #include <dpl/test/test_runner.h>
 #include <dpl/test/test_runner_child.h>
 #include <dpl/test/test_runner_multiprocess.h>
-#include <sys/smack.h>
+
+#include <algorithm>
 #include <sys/types.h>
 #include <string>
 #include <tuple>
@@ -59,6 +60,9 @@ void removeDir(const std::string &path);
 void waitPid(pid_t pid);
 void change_label(const char* label);
 
+pid_t runInChild(const std::function<void(void)> &process);
+void runInChildParentWait(const std::function<void(void)> &process);
+
 #define RUNNER_TEST_SMACK(Proc, ...)                                                        \
     void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple);                                  \
     static int Static##Proc##Init()                                                         \
index 06aa14d..33481a6 100644 (file)
@@ -66,18 +66,6 @@ private:
     std::string m_label = "cynara_helpers";
 };
 
-pid_t runInChild(const std::function<void(void)> &process) {
-    pid_t pid = fork();
-    RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "fork failed");
-
-    if (pid == 0) {
-        process();
-        exit(EXIT_SUCCESS);
-    }
-
-    return pid;
-}
-
 cynara_client_creds getClientDefaultMethod() {
     cynara_client_creds def;
     int ret = cynara_creds_get_default_client_method(&def);
index d6b0ee8..acaf64d 100644 (file)
@@ -330,28 +330,6 @@ CapsSetsUniquePtr setCaps(const char *cap_string)
     return caps;
 }
 
-pid_t runInChild(const std::function<void(void)> &process) {
-    pid_t pid = fork();
-    RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "fork failed");
-
-    if (pid == 0) {
-        process();
-        exit(EXIT_SUCCESS);
-    }
-    return pid;
-}
-
-void runInChildParentWait(const std::function<void(void)> &process) {
-    pid_t pid = fork();
-    RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "fork failed");
-    if (pid == 0) {
-        process();
-        exit(EXIT_SUCCESS);
-    } else {
-        waitPid(pid);
-    }
-}
-
 static int getOppositeAccessType(int accessType) {
     return accessType ^ (R_OK | W_OK | X_OK);
 }
index 02e9a13..902d70c 100644 (file)
@@ -63,9 +63,6 @@ void check_exact_smack_accesses(const std::string &subject,
 
 CapsSetsUniquePtr setCaps(const char *cap_string);
 
-pid_t runInChild(const std::function<void(void)> &process);
-
-void runInChildParentWait(const std::function<void(void)> &process);
 void runAccessTest(const std::string &label, uid_t uid, gid_t gid,
                    const std::string &testPath, int accessType);
 void runAccessTest(const AppInstallHelper &app, const std::string &testPath, int accessType);