From: Rafal Krypa Date: Mon, 2 Jan 2017 13:03:37 +0000 (+0100) Subject: Fix thread credential synchronization tests X-Git-Tag: security-manager_5.5_testing~20^2~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=db64322307dcc53f79a8aade5ca3286bf128fd92;p=platform%2Fcore%2Ftest%2Fsecurity-tests.git Fix thread credential synchronization tests Tests in SECURITY_MANAGER_PREPARE_APP group consisted of 3 dependant test cases: prepare, actual test and cleanup. Now they are merged into single test case that doesn't depend on any preparations done by other test cases. Change-Id: I734a7c992b4edb32e7db2f7581c501daed3c4929 Signed-off-by: Rafal Krypa --- diff --git a/src/security-manager-tests/test_cases_prepare_app.cpp b/src/security-manager-tests/test_cases_prepare_app.cpp index 7acfa827..bebb90ac 100644 --- a/src/security-manager-tests/test_cases_prepare_app.cpp +++ b/src/security-manager-tests/test_cases_prepare_app.cpp @@ -26,9 +26,11 @@ #include #include +#include #include #include #include +#include using namespace SecurityManagerTest; @@ -56,7 +58,7 @@ std::mutex error_mutex; } \ } while (0) -void threadFn(int i) +void threadFn(int i, const std::string &expectedLabel) { if (i % 2 == 0) { // block all signals @@ -68,9 +70,6 @@ void threadFn(int i) while (!finish) usleep(1000); - AppInstallHelper helper(SYNC_TEST_APP.c_str()); - std::string expectedLabel = helper.generateAppLabel(); - char* label; THREAD_ASSERT_MSG(smack_new_label_from_self(&label) > 0, "smack_new_label_from_self failed"); CStringPtr labelPtr(label); @@ -100,10 +99,10 @@ struct ThreadWrapper thread.join(); } - void run(int i) + void run(int i, const std::string &expectedLabel) { THREAD_ASSERT_MSG(!thread.joinable(), "Thread already started"); - thread = std::thread(threadFn, i); + thread = std::thread(threadFn, i, expectedLabel); } std::thread thread; @@ -113,36 +112,26 @@ struct ThreadWrapper RUNNER_TEST_GROUP_INIT(SECURITY_MANAGER_PREPARE_APP) -// TODO merge it into one test -RUNNER_TEST(security_manager_100_synchronize_credentials_1_prepare) -{ - AppInstallHelper helper(SYNC_TEST_APP.c_str()); - - InstallRequest install; - install.setAppId(helper.getAppId()); - install.setPkgId(helper.getPkgId()); - Api::install(install); -} - -RUNNER_CHILD_TEST(security_manager_100_synchronize_credentials_2_test) +RUNNER_CHILD_TEST(security_manager_100_synchronize_credentials_test) { - AppInstallHelper helper(SYNC_TEST_APP.c_str()); - { - ThreadWrapper threads[THREADS]; - - for (size_t i = 0; i < THREADS; i++) - threads[i].run(i); - - Api::prepareApp(helper.getAppId().c_str()); + AppInstallHelper app(SYNC_TEST_APP.c_str()); + ScopedInstaller appInstall(app); + const std::string expectedLabel = app.generateAppLabel(); + + pid_t pid = fork(); + RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "Fork failed"); + if (pid == 0) { + { + ThreadWrapper threads[THREADS]; + + for (size_t i = 0; i < THREADS; i++) + threads[i].run(i, expectedLabel); + + Api::prepareApp(app.getAppId().c_str()); + } + RUNNER_ASSERT_MSG(thread_errors.empty(), std::endl << thread_errors); + exit(0); + } else { + waitPid(pid); } - RUNNER_ASSERT_MSG(thread_errors.empty(), std::endl << thread_errors); -} - -RUNNER_TEST(security_manager_100_synchronize_credentials_3_cleanup) -{ - AppInstallHelper helper(SYNC_TEST_APP.c_str()); - - InstallRequest uninstall; - uninstall.setAppId(helper.getAppId()); - Api::uninstall(uninstall); }