Add test for allocations during app preparation 74/315974/2
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 6 Dec 2024 19:38:11 +0000 (20:38 +0100)
committerTomasz Swierczek <t.swierczek@samsung.com>
Mon, 9 Dec 2024 08:22:34 +0000 (08:22 +0000)
Change-Id: I7540450868479a15d5be0448c8b7155b09746b7a

src/security-manager-tests/test_cases_prepare_app.cpp

index ff0062739c9f879f51226c206e3d3f581be632f8..3cb2b2e59b7096ff4dd27ed750d325a99167efd0 100644 (file)
@@ -26,6 +26,7 @@
 #include <memory>
 #include <mutex>
 #include <fstream>
+#include <atomic>
 
 #include <dpl/test/test_runner_child.h>
 #include <dpl/test/test_runner.h>
@@ -479,6 +480,50 @@ template <class T, size_t N>
 constexpr size_t arraySize(T (&)[N]) { return N; }
 } // namespace
 
+RUNNER_TEST(security_manager_190_prepare_app_threads_malloc)
+{
+    TemporaryTestUser tmpUser(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
+    tmpUser.create();
+
+    const auto uid = tmpUser.getUid();
+
+       AppInstallHelper app("app190", uid);
+
+       ScopedInstaller installer(app);
+
+       const auto pid = fork();
+       RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "Fork failed");
+
+       if (pid == 0) {
+               RUNNER_ASSERT_ERRNO_MSG(setLauncherSecurityAttributes(tmpUser) == 0, "launcher failed");
+
+               const auto appId = app.getAppId();
+
+               Api::prepareAppCandidate();
+
+               std::atomic<bool> quit = false;
+               static constexpr size_t MAX = 60;
+               std::vector<std::thread> threads;threads.reserve(MAX);
+               for (size_t i = 0; i < MAX; i++ ) {
+                       threads.emplace_back(std::thread([&](){
+                               while(!quit) {
+                                       auto tmp = malloc(1000);
+                                       usleep(100);
+                                       free(tmp);
+                               }
+                       }));
+               }
+
+               Api::prepareApp(appId);
+               quit = true;
+               for (size_t i = 0; i < MAX; i++ )
+                       threads[i].join();
+               exit(0);
+       }
+       waitPid(pid);
+       Api::cleanupApp(app.getAppId(), uid, pid);
+}
+
 RUNNER_TEST(security_manager_200_prepare_app_perf)
 {
     constexpr int8_t nThreads = 32;