User 'app_fw' for smoke tests 64/84564/3
authorTomasz Iwanek <t.iwanek@samsung.com>
Wed, 17 Aug 2016 13:31:04 +0000 (15:31 +0200)
committerTomasz Iwanek <t.iwanek@samsung.com>
Fri, 19 Aug 2016 10:42:56 +0000 (12:42 +0200)
To verify, run:
 app_fw@localhost:~$ /usr/bin/tpk-backend-ut/smoke-test

One fail expected: 'SmokeTest.RecoveryMode_Tpk_Update' (on second run)
This will be fixed separately.

Requires: https://review.tizen.org/gerrit/#/c/84457/

Change-Id: I346825789d0f00279f3157bb8098beaae8818d41

packaging/tpk-backend-tests.manifest
packaging/tpk-backend.spec
src/unit_tests/smoke_test.cc

index 1f06ac4..bd6568f 100644 (file)
@@ -3,7 +3,7 @@
                 <domain name="_" />
         </request>
         <assign>
-                <filesystem path="/usr/bin/tpk-backend-ut/smoke-test" exec_label="User" />
-                <filesystem path="/usr/bin/tpk-backend-ut/smoke-test-helper" exec_label="User" />
+                <filesystem path="/usr/bin/tpk-backend-ut/smoke-test" exec_label="none" />
+                <filesystem path="/usr/bin/tpk-backend-ut/smoke-test-helper" exec_label="none" />
         </assign>
 </manifest>
index 0025c94..256a32e 100644 (file)
@@ -55,7 +55,8 @@ ln -s %{_bindir}/tpk-backend %{buildroot}%{_sysconfdir}/package-manager/backend/
 ln -s %{_bindir}/tpk-backend %{buildroot}%{_sysconfdir}/package-manager/backend/rpm
 
 %post tests
-/usr/sbin/setcap cap_dac_override=eip %{_bindir}/tpk-backend-ut/smoke-test
+/usr/sbin/setcap cap_chown,cap_dac_override,cap_fowner=eip %{_bindir}/tpk-backend-ut/smoke-test
+/usr/sbin/setcap cap_chown,cap_dac_override,cap_fowner=eip %{_bindir}/tpk-backend-ut/smoke-test-helper
 
 %files
 %{_sysconfdir}/package-manager/backend/tpk
index f63aaf0..de42c5e 100644 (file)
@@ -38,6 +38,10 @@ namespace ci = common_installer;
 
 namespace {
 
+const uid_t kTestUserId = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
+const std::string kTestUserIdStr =
+    std::to_string(kTestUserId);
+
 const bf::path kSmokePackagesDirectory =
     "/usr/share/tpk-backend-ut/test_samples/smoke/";
 
@@ -56,7 +60,7 @@ class ScopedTzipInterface {
  public:
   explicit ScopedTzipInterface(const std::string& pkgid)
       : pkg_path_(bf::path(ci::GetRootAppPath(false,
-            tzplatform_getuid(TZ_SYS_DEFAULT_USER))) / pkgid),
+            kTestUserId)) / pkgid),
         interface_(ci::GetMountLocation(pkg_path_)) {
     interface_.MountZip(ci::GetZipPackageLocation(pkg_path_, pkgid));
   }
@@ -96,7 +100,7 @@ class TestPkgmgrInstaller : public ci::PkgmgrInstallerInterface {
 
 void RemoveAllRecoveryFiles() {
   bf::path root_path = ci::GetRootAppPath(false,
-      tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+      kTestUserId);
   if (!bf::exists(root_path))
     return;
   for (auto& dir_entry : boost::make_iterator_range(
@@ -112,7 +116,7 @@ void RemoveAllRecoveryFiles() {
 
 bf::path FindRecoveryFile() {
   bf::path root_path = ci::GetRootAppPath(false,
-      tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+      kTestUserId);
   for (auto& dir_entry : boost::make_iterator_range(
          bf::directory_iterator(root_path), bf::directory_iterator())) {
     if (bf::is_regular_file(dir_entry)) {
@@ -128,7 +132,7 @@ bool ValidateFileContentInPackage(const std::string& pkgid,
                                   const std::string& relative,
                                   const std::string& expected) {
   bf::path root_path = ci::GetRootAppPath(false,
-      tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+      kTestUserId);
   bf::path file_path = root_path / pkgid / relative;
   if (!bf::exists(file_path)) {
     LOG(ERROR) << file_path << " doesn't exist";
@@ -150,7 +154,7 @@ bool ValidateFileContentInPackage(const std::string& pkgid,
 
 void ValidatePackageFS(const std::string& pkgid, const std::string& appid) {
   bf::path root_path = ci::GetRootAppPath(false,
-      tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+      kTestUserId);
   bf::path package_path = root_path / pkgid;
   bf::path binary_path = package_path / "bin" / appid;
   bf::path data_path = package_path / "data";
@@ -165,7 +169,7 @@ void ValidatePackageFS(const std::string& pkgid, const std::string& appid) {
 
   bf::path manifest_path =
       bf::path(getUserManifestPath(
-          tzplatform_getuid(TZ_SYS_DEFAULT_USER), false)) / (pkgid + ".xml");
+          kTestUserId, false)) / (pkgid + ".xml");
   ASSERT_TRUE(bf::exists(manifest_path));
 
   // backups should not exist
@@ -177,13 +181,13 @@ void ValidatePackageFS(const std::string& pkgid, const std::string& appid) {
 
 void PackageCheckCleanup(const std::string& pkgid, const std::string&) {
   bf::path root_path = ci::GetRootAppPath(false,
-      tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+      kTestUserId);
   bf::path package_path = root_path / pkgid;
   ASSERT_FALSE(bf::exists(package_path));
 
   bf::path manifest_path =
       bf::path(getUserManifestPath(
-          tzplatform_getuid(TZ_SYS_DEFAULT_USER), false)) / (pkgid + ".xml");
+          kTestUserId, false)) / (pkgid + ".xml");
   ASSERT_FALSE(bf::exists(manifest_path));
 
   // backups should not exist
@@ -195,16 +199,16 @@ void PackageCheckCleanup(const std::string& pkgid, const std::string&) {
 
 void ValidatePackage(const std::string& pkgid, const std::string& appid) {
   ASSERT_TRUE(ci::QueryIsPackageInstalled(
-      pkgid, ci::GetRequestMode(tzplatform_getuid(TZ_SYS_DEFAULT_USER)),
-      tzplatform_getuid(TZ_SYS_DEFAULT_USER)));
+      pkgid, ci::GetRequestMode(kTestUserId),
+      kTestUserId));
   ValidatePackageFS(pkgid, appid);
 }
 
 void CheckPackageNonExistance(const std::string& pkgid,
                               const std::string& appid) {
   ASSERT_FALSE(ci::QueryIsPackageInstalled(
-      pkgid, ci::GetRequestMode(tzplatform_getuid(TZ_SYS_DEFAULT_USER)),
-      tzplatform_getuid(TZ_SYS_DEFAULT_USER)));
+      pkgid, ci::GetRequestMode(kTestUserId),
+      kTestUserId));
   PackageCheckCleanup(pkgid, appid);
 }
 
@@ -249,7 +253,7 @@ ci::AppInstaller::Result CallBackend(int argc,
 }
 ci::AppInstaller::Result Install(const bf::path& path,
                                  RequestResult mode = RequestResult::NORMAL) {
-  const char* argv[] = {"", "-i", path.c_str()};
+  const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()};
   return CallBackend(SIZEOFARRAY(argv), argv, mode);
 }
 
@@ -265,7 +269,7 @@ ci::AppInstaller::Result Update(const bf::path& path_old,
 
 ci::AppInstaller::Result MountInstall(const bf::path& path,
                                  RequestResult mode = RequestResult::NORMAL) {
-  const char* argv[] = {"", "-w", path.c_str()};
+  const char* argv[] = {"", "-w", path.c_str(), "-u", kTestUserIdStr.c_str()};
   return CallBackend(SIZEOFARRAY(argv), argv, mode);
 }
 
@@ -281,25 +285,25 @@ ci::AppInstaller::Result MountUpdate(const bf::path& path_old,
 
 ci::AppInstaller::Result Uninstall(const std::string& pkgid,
                                    RequestResult mode = RequestResult::NORMAL) {
-  const char* argv[] = {"", "-d", pkgid.c_str()};
+  const char* argv[] = {"", "-d", pkgid.c_str(), "-u", kTestUserIdStr.c_str()};
   return CallBackend(SIZEOFARRAY(argv), argv, mode);
 }
 
 ci::AppInstaller::Result Clear(const bf::path& path,
                                  RequestResult mode = RequestResult::NORMAL) {
-  const char* argv[] = {"", "-c", path.c_str()};
+  const char* argv[] = {"", "-c", path.c_str(), "-u", kTestUserIdStr.c_str()};
   return CallBackend(SIZEOFARRAY(argv), argv, mode);
 }
 
 ci::AppInstaller::Result EnablePackage(const std::string& path,
                                  RequestResult mode = RequestResult::NORMAL) {
-  const char* argv[] = {"", "-A", path.c_str()};
+  const char* argv[] = {"", "-A", path.c_str(), "-u", kTestUserIdStr.c_str()};
   return CallBackend(SIZEOFARRAY(argv), argv, mode);
 }
 
 ci::AppInstaller::Result DisablePackage(const std::string& path,
                                  RequestResult mode = RequestResult::NORMAL) {
-  const char* argv[] = {"", "-D", path.c_str()};
+  const char* argv[] = {"", "-D", path.c_str(), "-u", kTestUserIdStr.c_str()};
   return CallBackend(SIZEOFARRAY(argv), argv, mode);
 }
 
@@ -310,7 +314,8 @@ ci::AppInstaller::Result Reinstall(const bf::path& path,
     LOG(ERROR) << "Failed to install application. Cannot perform RDS";
     return ci::AppInstaller::Result::UNKNOWN;
   }
-  const char* argv[] = {"", "-r", delta_dir.c_str()};
+  const char* argv[] = {"", "-r", delta_dir.c_str(), "-u",
+                        kTestUserIdStr.c_str()};
   return CallBackend(SIZEOFARRAY(argv), argv, mode);
 }
 
@@ -325,7 +330,8 @@ ci::AppInstaller::Result DeltaInstall(const bf::path& path,
 
 ci::AppInstaller::Result Recover(const bf::path& recovery_file,
                                  RequestResult mode = RequestResult::NORMAL) {
-  const char* argv[] = {"", "-b", recovery_file.c_str()};
+  const char* argv[] = {"", "-b", recovery_file.c_str(), "-u",
+                        kTestUserIdStr.c_str()};
   return CallBackend(SIZEOFARRAY(argv), argv, mode);
 }
 
@@ -338,7 +344,7 @@ class SmokeEnvironment : public testing::Environment {
   explicit SmokeEnvironment(const bf::path& home) : home_(home) {
   }
   void SetUp() override {
-    bf::path UserDBDir = bf::path(kUserDataBaseDir) / std::to_string(getuid());
+    bf::path UserDBDir = bf::path(kUserDataBaseDir) / kTestUserIdStr;
     bf::path UserDBDirBackup = UserDBDir.string() + std::string(".bck");
 
     bs::error_code error;
@@ -371,7 +377,7 @@ class SmokeEnvironment : public testing::Environment {
     }
   }
   void TearDown() override {
-    bf::path UserDBDir = bf::path(kUserDataBaseDir) / std::to_string(getuid());
+    bf::path UserDBDir = bf::path(kUserDataBaseDir) / kTestUserIdStr;
     bf::path UserDBDirBackup = UserDBDir.string() + std::string(".bck");
 
     bs::error_code error;
@@ -404,7 +410,7 @@ TEST_F(SmokeTest, DeltaMode_Tpk) {
 
   // Check delta modifications
   bf::path root_path = ci::GetRootAppPath(false,
-      tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+      kTestUserId);
   ASSERT_FALSE(bf::exists(root_path / pkgid / "DELETED"));
   ASSERT_TRUE(bf::exists(root_path / pkgid / "ADDED"));
   ASSERT_TRUE(bf::exists(root_path / pkgid / "bin" / "native"));
@@ -422,7 +428,7 @@ TEST_F(SmokeTest, ReinstallMode_Tpk) {
 
   // Check rds modifications
   bf::path root_path = ci::GetRootAppPath(false,
-      tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+      kTestUserId);
   ASSERT_FALSE(bf::exists(root_path / pkgid / "DELETED"));
   ASSERT_TRUE(bf::exists(root_path / pkgid / "ADDED"));
   ASSERT_TRUE(bf::exists(root_path / pkgid / "bin" / "native"));
@@ -465,8 +471,8 @@ TEST_F(SmokeTest, EnablePkg) {
   ASSERT_EQ(DisablePackage(pkgid), ci::AppInstaller::Result::OK);
   ASSERT_EQ(EnablePackage(pkgid), ci::AppInstaller::Result::OK);
   ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode(
-      tzplatform_getuid(TZ_SYS_DEFAULT_USER)),
-      tzplatform_getuid(TZ_SYS_DEFAULT_USER)));
+      kTestUserId),
+      kTestUserId));
 }
 
 TEST_F(SmokeTest, DisablePkg) {
@@ -476,8 +482,8 @@ TEST_F(SmokeTest, DisablePkg) {
   ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK);
   ASSERT_EQ(DisablePackage(pkgid), ci::AppInstaller::Result::OK);
   ASSERT_FALSE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode(
-      tzplatform_getuid(TZ_SYS_DEFAULT_USER)),
-      tzplatform_getuid(TZ_SYS_DEFAULT_USER)));
+      kTestUserId),
+      kTestUserId));
   ValidatePackageFS(pkgid, {appid});
 }
 
@@ -487,7 +493,7 @@ TEST_F(SmokeTest, ClearMode_Tpk) {
   std::string appid = "smokeapp21.ClearModeTpk";
   ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK);
   bf::path root_path = ci::GetRootAppPath(false,
-      tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+      kTestUserId);
   bs::error_code error;
   bf::create_directory(root_path / pkgid / "data" / "dir", error);
   ASSERT_FALSE(error);
@@ -503,7 +509,7 @@ TEST_F(SmokeTest, RecoveryMode_Tpk_Installation) {
   bf::path path = kSmokePackagesDirectory / "RecoveryMode_Tpk_Installation.tpk";
   RemoveAllRecoveryFiles();
   ci::Subprocess backend_crash("/usr/bin/tpk-backend-ut/smoke-test-helper");
-  backend_crash.Run("-i", path.string());
+  backend_crash.Run("-i", path.string(), "-u", kTestUserIdStr.c_str());
   ASSERT_NE(backend_crash.Wait(), 0);
 
   std::string pkgid = "smokeapp15";
@@ -518,11 +524,9 @@ TEST_F(SmokeTest, RecoveryMode_Tpk_Update) {
   bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_Tpk_Update.tpk";
   bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_Tpk_Update_2.tpk";
   RemoveAllRecoveryFiles();
-  ci::Subprocess backend("/usr/bin/tpk-backend");
-  backend.Run("-i", path_old.string());
-  ASSERT_EQ(backend.Wait(), 0);
+  ASSERT_EQ(Install(path_old), ci::AppInstaller::Result::OK);
   ci::Subprocess backend_crash("/usr/bin/tpk-backend-ut/smoke-test-helper");
-  backend_crash.Run("-i", path_new.string());
+  backend_crash.Run("-i", path_new.string(), "-u", kTestUserIdStr.c_str());
   ASSERT_NE(backend_crash.Wait(), 0);
 
   std::string pkgid = "smokeapp16";
@@ -560,11 +564,8 @@ TEST_F(SmokeTest, MountUpdateMode_Tpk) {
 
 int main(int argc,  char** argv) {
   testing::InitGoogleTest(&argc, argv);
-  const char* directory = getenv("HOME");
-  if (!directory) {
-    LOG(ERROR) << "Cannot get $HOME value";
-    return 1;
-  }
+  bf::path directory =
+      bf::path("/home") / tzplatform_getenv(TZ_SYS_DEFAULT_USER);
   testing::AddGlobalTestEnvironment(
       new common_installer::SmokeEnvironment(directory));
   return RUN_ALL_TESTS();