User 'app_fw' for smoke tests 67/84567/5
authorTomasz Iwanek <t.iwanek@samsung.com>
Fri, 19 Aug 2016 08:49:17 +0000 (10:49 +0200)
committerTomasz Iwanek <t.iwanek@samsung.com>
Mon, 22 Aug 2016 11:32:49 +0000 (04:32 -0700)
To verify, run:
 app_fw@localhost:~$ /usr/bin/wgt-backend-ut/smoke-test

Fail expected: 'SmokeTest.RecoveryMode_Update' (on second run)
This will be fixed separately.

Tests:
 - SmokeTest.MountInstallationMode
 - SmokeTest.MountUpdateMode
are expected to fail as well.

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

Change-Id: Id08ad6bc3f294522e6c01d652194ebd248b7510b

packaging/wgt-backend-tests.manifest
packaging/wgt-backend.spec
src/unit_tests/smoke_test.cc
src/unit_tests/test_samples/smoke/DisablePkg.wgt

index 9e728be..0d58b09 100644 (file)
@@ -3,7 +3,7 @@
                 <domain name="_" />
         </request>
         <assign>
-                <filesystem path="/usr/bin/wgt-backend-ut/smoke_test" exec_label="User" />
-                <filesystem path="/usr/bin/wgt-backend-ut/smoke-test-helper" exec_label="User" />
+                <filesystem path="/usr/bin/wgt-backend-ut/smoke_test" exec_label="none" />
+                <filesystem path="/usr/bin/wgt-backend-ut/smoke-test-helper" exec_label="none" />
         </assign>
 </manifest>
index 9d9f89a..9741293 100644 (file)
@@ -53,7 +53,8 @@ mkdir -p %{buildroot}/etc/package-manager/backend
 ln -s %{_bindir}/wgt-backend %{buildroot}%{_sysconfdir}/package-manager/backend/wgt
 
 %post tests
-/usr/sbin/setcap cap_dac_override=eip %{_bindir}/wgt-backend-ut/smoke-test
+/usr/sbin/setcap cap_chown,cap_dac_override,cap_fowner=eip %{_bindir}/wgt-backend-ut/smoke-test
+/usr/sbin/setcap cap_chown,cap_dac_override,cap_fowner=eip %{_bindir}/wgt-backend-ut/smoke-test-helper
 
 %files
 %manifest wgt-backend.manifest
index 3e80354..c56ebbd 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/wgt-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));
   }
@@ -101,7 +105,7 @@ bool TouchFile(const bf::path& path) {
 
 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(
@@ -117,7 +121,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)) {
@@ -133,7 +137,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";
@@ -156,7 +160,7 @@ bool ValidateFileContentInPackage(const std::string& pkgid,
 void ValidatePackageFS(const std::string& pkgid,
                        const std::vector<std::string>& appids) {
   bf::path root_path = ci::GetRootAppPath(false,
-      tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+      kTestUserId);
   bf::path package_path = root_path / pkgid;
   bf::path data_path = package_path / "data";
   bf::path shared_path = package_path / "shared";
@@ -169,7 +173,7 @@ void ValidatePackageFS(const std::string& pkgid,
 
   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));
 
   for (auto& appid : appids) {
@@ -195,13 +199,13 @@ void ValidatePackageFS(const std::string& pkgid,
 void PackageCheckCleanup(const std::string& pkgid,
                          const std::vector<std::string>&) {
   bf::path root_path = ci::GetRootAppPath(
-      false, tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+      false, 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
@@ -214,16 +218,16 @@ void PackageCheckCleanup(const std::string& pkgid,
 void ValidatePackage(const std::string& pkgid,
                      const std::vector<std::string>& appids) {
   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, appids);
 }
 
 void CheckPackageNonExistance(const std::string& pkgid,
                               const std::vector<std::string>& appids) {
   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, appids);
 }
 
@@ -281,7 +285,7 @@ ci::AppInstaller::Result CallBackend(int argc,
 ci::AppInstaller::Result Install(const bf::path& path,
                                  PackageType type,
                                  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, type, mode);
 }
 
@@ -298,7 +302,7 @@ ci::AppInstaller::Result Update(const bf::path& path_old,
 
 ci::AppInstaller::Result MountInstall(const bf::path& path,
     PackageType type, 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, type, mode);
 }
 
@@ -315,7 +319,7 @@ ci::AppInstaller::Result MountUpdate(const bf::path& path_old,
 ci::AppInstaller::Result Uninstall(const std::string& pkgid,
                                    PackageType type,
                                    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, type, mode);
 }
 
@@ -327,7 +331,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, type, mode);
 }
 
@@ -343,28 +348,29 @@ ci::AppInstaller::Result DeltaInstall(const bf::path& path,
 ci::AppInstaller::Result Clear(const std::string& pkgid,
                                    PackageType type,
                                    RequestResult mode = RequestResult::NORMAL) {
-  const char* argv[] = {"", "-c", pkgid.c_str()};
+  const char* argv[] = {"", "-c", pkgid.c_str(), "-u", kTestUserIdStr.c_str()};
   return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
 }
 
 ci::AppInstaller::Result EnablePackage(const std::string& pkgid,
                                   PackageType type,
                                   RequestResult mode = RequestResult::NORMAL) {
-  const char* argv[] = {"", "-A", pkgid.c_str()};
+  const char* argv[] = {"", "-A", pkgid.c_str(), "-u", kTestUserIdStr.c_str()};
   return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
 }
 
 ci::AppInstaller::Result DisablePackage(const std::string& pkgid,
                                   PackageType type,
                                   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, type, mode);
 }
 
 ci::AppInstaller::Result Recover(const bf::path& recovery_file,
                                  PackageType type,
                                  RequestResult mode = RequestResult::NORMAL) {
-  const char* argv[] = {"", "-b", recovery_file.c_str()};
+  const char* argv[] = {"", "-b", recovery_file.c_str(), "-u",
+                        kTestUserIdStr.c_str()};
   TestPkgmgrInstaller pkgmgr_installer;
   std::unique_ptr<ci::AppQueryInterface> query_interface =
       CreateQueryInterface();
@@ -387,7 +393,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;
@@ -420,7 +426,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;
@@ -483,7 +489,7 @@ TEST_F(SmokeTest, RDSMode) {
 
   // Check delta modifications
   bf::path root_path = ci::GetRootAppPath(false,
-      tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+      kTestUserId);
   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
   ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "2\n");
@@ -500,8 +506,8 @@ TEST_F(SmokeTest, EnablePkg) {
             ci::AppInstaller::Result::OK);
 
   ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid,
-      ci::GetRequestMode(tzplatform_getuid(TZ_SYS_DEFAULT_USER)),
-      tzplatform_getuid(TZ_SYS_DEFAULT_USER)));
+      ci::GetRequestMode(kTestUserId),
+      kTestUserId));
 }
 
 TEST_F(SmokeTest, DisablePkg) {
@@ -513,8 +519,8 @@ TEST_F(SmokeTest, DisablePkg) {
   ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
             ci::AppInstaller::Result::OK);
   ASSERT_FALSE(ci::QueryIsPackageInstalled(pkgid,
-      ci::GetRequestMode(tzplatform_getuid(TZ_SYS_DEFAULT_USER)),
-      tzplatform_getuid(TZ_SYS_DEFAULT_USER)));
+      ci::GetRequestMode(kTestUserId),
+      kTestUserId));
   ValidatePackageFS(pkgid, {appid});
 }
 
@@ -525,7 +531,7 @@ TEST_F(SmokeTest, ClearMode) {
   ASSERT_EQ(Install(path, PackageType::WGT),
             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);
@@ -548,7 +554,7 @@ TEST_F(SmokeTest, DeltaMode) {
 
   // Check delta modifications
   bf::path root_path = ci::GetRootAppPath(false,
-      tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+      kTestUserId);
   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "css" / "style.css"));  // NOLINT
@@ -560,7 +566,7 @@ TEST_F(SmokeTest, DeltaMode) {
 TEST_F(SmokeTest, RecoveryMode_ForInstallation) {
   bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForInstallation.wgt";
   Subprocess backend_crash("/usr/bin/wgt-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 = "smokeapp09";
@@ -576,11 +582,9 @@ TEST_F(SmokeTest, RecoveryMode_ForUpdate) {
   bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForUpdate.wgt";
   bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForUpdate_2.wgt";
   RemoveAllRecoveryFiles();
-  Subprocess backend_test("/usr/bin/wgt-backend");
-  backend_test.Run("-i", path_old.string());
-  ASSERT_EQ(backend_test.Wait(), 0);
+  ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
   Subprocess backend_crash("/usr/bin/wgt-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 = "smokeapp10";
@@ -671,7 +675,7 @@ TEST_F(SmokeTest, DeltaMode_Hybrid) {
 
   // Check delta modifications
   bf::path root_path = ci::GetRootAppPath(false,
-      tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+      kTestUserId);
   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
   ASSERT_FALSE(bf::exists(root_path / pkgid / "lib" / "DELETED"));
@@ -709,11 +713,8 @@ TEST_F(SmokeTest, MountUpdateMode) {
 
 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();
index 3245443..905c527 100644 (file)
Binary files a/src/unit_tests/test_samples/smoke/DisablePkg.wgt and b/src/unit_tests/test_samples/smoke/DisablePkg.wgt differ