#include <dpl/test/test_runner.h>
#include <app_install_helper.h>
+#include <scoped_installer.h>
#include <sm_api.h>
#include <sm_commons.h>
#include <memory.h>
+#include <tests_common.h>
using namespace SecurityManagerTest;
} \
} while (0)
-void threadFn(int i)
+void threadFn(int i, const std::string &expectedLabel)
{
if (i % 2 == 0) {
// block all signals
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);
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;
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);
}