X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fcommon%2Ftests_common.cpp;h=b5dff60ff34ebff1f7e241bd1e61d645455a6232;hb=9f7bf61c1ad3b4260381cc3fa695cb1904a729f4;hp=2332abb80d4b33ae0d00fe7a1fb1035e9307753b;hpb=172747c7c388d09105f6788e0604b37f1e6df896;p=platform%2Fcore%2Ftest%2Fsecurity-tests.git diff --git a/src/common/tests_common.cpp b/src/common/tests_common.cpp index 2332abb..b5dff60 100644 --- a/src/common/tests_common.cpp +++ b/src/common/tests_common.cpp @@ -26,16 +26,13 @@ #include #include #include +#include #include #include #include #include #include -int DB::Transaction::db_result = PC_OPERATION_SUCCESS; - -const char *WGT_APP_ID = "QwCqJ0ttyS"; - bool smack_check(void) { #ifndef WRT_SMACK_ENABLED @@ -234,3 +231,41 @@ void removeDir(const std::string &path) RUNNER_ASSERT_ERRNO_MSG(0 == rmdir(path.c_str()), "rmdir for <" << path << "> failed"); } + +void waitPid(pid_t pid) +{ + int status; + pid_t ret = waitpid(pid, &status, 0); + RUNNER_ASSERT_MSG((ret != -1) && WIFEXITED(status) && WEXITSTATUS(status) == 0, + "Child process exited abnormally" << + ": ret=" << ret << ", errno=" << errno << ", status=" << status); +} +// changes process label +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); + } +} +