From ce6872223f053d58561f00c68fee76e887deb339 Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Wed, 18 Oct 2017 16:58:38 +0200 Subject: [PATCH] Fix multiple definitions of runInChild 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 | 23 +++++++++++++++++++++++ src/common/tests_common.h | 6 +++++- src/cynara-tests/test_cases_helpers.cpp | 12 ------------ src/security-manager-tests/common/sm_commons.cpp | 22 ---------------------- src/security-manager-tests/common/sm_commons.h | 3 --- 5 files changed, 28 insertions(+), 38 deletions(-) diff --git a/src/common/tests_common.cpp b/src/common/tests_common.cpp index d08893c..b5dff60 100644 --- a/src/common/tests_common.cpp +++ b/src/common/tests_common.cpp @@ -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("< &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 &process) { + pid_t pid = fork(); + RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "fork failed"); + if (pid == 0) { + process(); + exit(EXIT_SUCCESS); + } else { + waitPid(pid); + } +} + diff --git a/src/common/tests_common.h b/src/common/tests_common.h index 251e111..3f109b9 100644 --- a/src/common/tests_common.h +++ b/src/common/tests_common.h @@ -29,7 +29,8 @@ #include #include #include -#include + +#include #include #include #include @@ -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 &process); +void runInChildParentWait(const std::function &process); + #define RUNNER_TEST_SMACK(Proc, ...) \ void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple); \ static int Static##Proc##Init() \ diff --git a/src/cynara-tests/test_cases_helpers.cpp b/src/cynara-tests/test_cases_helpers.cpp index 06aa14d..33481a6 100644 --- a/src/cynara-tests/test_cases_helpers.cpp +++ b/src/cynara-tests/test_cases_helpers.cpp @@ -66,18 +66,6 @@ private: std::string m_label = "cynara_helpers"; }; -pid_t runInChild(const std::function &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); diff --git a/src/security-manager-tests/common/sm_commons.cpp b/src/security-manager-tests/common/sm_commons.cpp index d6b0ee8..acaf64d 100644 --- a/src/security-manager-tests/common/sm_commons.cpp +++ b/src/security-manager-tests/common/sm_commons.cpp @@ -330,28 +330,6 @@ CapsSetsUniquePtr setCaps(const char *cap_string) return caps; } -pid_t runInChild(const std::function &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 &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); } diff --git a/src/security-manager-tests/common/sm_commons.h b/src/security-manager-tests/common/sm_commons.h index 02e9a13..902d70c 100644 --- a/src/security-manager-tests/common/sm_commons.h +++ b/src/security-manager-tests/common/sm_commons.h @@ -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 &process); - -void runInChildParentWait(const std::function &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); -- 2.7.4