From: Tomasz Swierczek Date: Tue, 22 Oct 2024 15:30:25 +0000 (+0200) Subject: Add tests of concurrent prepare_app and app_install/uninstall X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cec976e0bb9f9efe46331f55bb4820163332eb75;p=platform%2Fcore%2Ftest%2Fsecurity-tests.git Add tests of concurrent prepare_app and app_install/uninstall These tests should properly stress the two-threads implementation of the daemon that has dedicated thread just for prepare_app call. The test takes more time so its run as RUNNER_TEST (not CHILD test) as CHILD tests do have a timeout in the testing framework internals. Change-Id: Iad094acfc3d86d9b1d15c79a6b9095b733adda93 --- diff --git a/src/security-manager-tests/test_cases_prepare_app.cpp b/src/security-manager-tests/test_cases_prepare_app.cpp index edde37bc..1f69117f 100644 --- a/src/security-manager-tests/test_cases_prepare_app.cpp +++ b/src/security-manager-tests/test_cases_prepare_app.cpp @@ -645,3 +645,93 @@ RUNNER_CHILD_TEST(security_manager_300_prepare_app_recursive_threads) Api::cleanupApp(app.getAppId(), tmpUser.getUid(), pid); } } + +RUNNER_CHILD_TEST(security_manager_400_prepare_app_with_concurrent_install) +{ + std::srand(std::time(nullptr)); // use current time as seed for random generator + TemporaryTestUser tmpUser(APP_TEST_USER, GUM_USERTYPE_NORMAL, false); + tmpUser.create(); + + // few iterations of the test... + for (int i = 0; i < 5; ++i) { + AppInstallHelper app("app400", tmpUser.getUid()); + app.addPrivileges({PRIV_EXTERNALSTORAGE, PRIV_MEDIASTORAGE}); + ScopedInstaller appInstall(app); + + pid_t pid = fork(); + RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "Fork failed"); + if (pid == 0) { + RUNNER_ASSERT_ERRNO_MSG(setLauncherSecurityAttributes(tmpUser) == 0, "launcher failed"); + + // wait a bit for the other process to start running install/deinstall loop + std::this_thread::sleep_for(std::chrono::milliseconds( 10 * (std::rand() % 200) )); // max 2 seconds + + Api::prepareAppCandidate(); + Api::prepareApp(app.getAppId()); + + exit(0); + } else { + // in a loop, install & uninstall a temporary app + std::time_t begin = std::time(nullptr); + while(1) { + { + AppInstallHelper app2("app400_2", tmpUser.getUid()); + app2.addPrivileges({PRIV_EXTERNALSTORAGE, PRIV_MEDIASTORAGE}); + ScopedInstaller appInstall(app2); + } + std::time_t now = std::time(nullptr); + if (now - begin >= 3) // wait at most 3 seconds + break; + } + waitPid(pid); + Api::cleanupApp(app.getAppId(), tmpUser.getUid(), pid); + } + } +} + +RUNNER_TEST(security_manager_400_prepare_app_series_with_concurrent_install_stress) +{ + std::srand(std::time(nullptr)); // use current time as seed for random generator + TemporaryTestUser tmpUser(APP_TEST_USER, GUM_USERTYPE_NORMAL, false); + tmpUser.create(); + + pid_t pid = fork(); + RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "Fork failed"); + if (pid == 0) { + // install an app, and in a loop - fork + launch it + AppInstallHelper app("app400", tmpUser.getUid()); + ScopedInstaller appInstall(app); + + std::time_t begin = std::time(nullptr); + while(1) { + pid_t pid2 = fork(); + RUNNER_ASSERT_ERRNO_MSG(pid2 >= 0, "Fork failed"); + if (pid2 == 0) { + RUNNER_ASSERT_ERRNO_MSG(setLauncherSecurityAttributes(tmpUser) == 0, "launcher failed"); + Api::prepareAppCandidate(); + Api::prepareApp(app.getAppId()); + exit(0); + } else { + waitPid(pid2); + } + std::time_t now = std::time(nullptr); + if (now - begin >= 120) // wait 2 mins + break; + } + exit(0); + } else { + // in a loop, install & uninstall a temporary app + std::time_t begin = std::time(nullptr); + while(1) { + { + AppInstallHelper app2("app400_2", tmpUser.getUid()); + app2.addPrivileges({PRIV_EXTERNALSTORAGE, PRIV_MEDIASTORAGE}); + ScopedInstaller appInstall(app2); + } + std::time_t now = std::time(nullptr); + if (now - begin >= 120) // wait 2 mins + break; + } + waitPid(pid); + } +}