1 // Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
5 #ifndef UNIT_TESTS_SMOKE_UTILS_H_
6 #define UNIT_TESTS_SMOKE_UTILS_H_
9 #include <boost/filesystem/path.hpp>
11 #include <common/paths.h>
12 #include <common/pkgmgr_interface.h>
13 #include <common/pkgmgr_query.h>
14 #include <common/tzip_interface.h>
15 #include <gum/gum-user.h>
16 #include <gum/gum-user-service.h>
17 #include <gum/common/gum-user-types.h>
19 #include <gtest/gtest.h>
25 #include "hybrid/hybrid_installer.h"
26 #include "wgt/wgt_app_query_interface.h"
28 #define SIZEOFARRAY(ARR) \
29 sizeof(ARR) / sizeof(ARR[0]) \
31 #define EXTENDED_ASSERT_TRUE(expression) do { \
32 bool tmp = expression; \
33 EXPECT_TRUE(tmp) << #expression << " is not true"; \
38 #define EXTENDED_ASSERT_FALSE(expression) do { \
39 bool tmp = expression; \
40 EXPECT_FALSE(tmp) << #expression << " is not false"; \
45 #define EXTENDED_ASSERT_EQ(expression, value) do { \
46 auto ret = expression; \
47 EXPECT_EQ(ret, value) << #expression << " is not equal to " << #value; \
52 namespace bf = boost::filesystem;
53 namespace bs = boost::system;
54 namespace ci = common_installer;
56 extern const uid_t kGlobalUserUid;
57 extern const uid_t kGlobalUserGid;
58 extern const uid_t kDefaultUserUid;
59 extern uid_t kTestUserId;
60 extern gid_t kTestGroupId;
61 extern std::string kTestUserIdStr;
62 extern const char kNormalUserName[];
63 extern const char kSystemShareGroupName[];
64 extern const std::string& kDefaultUserIdStr;
65 extern const char kLegacyExtImageDir[];
66 extern const char kMigrateTestDBName[];
68 extern const bf::path kSmokePackagesDirectory;
78 extern const char* rwDirectories[];
81 extern const std::vector<std::string> kDBEntries;
83 extern const char kGlobalManifestDir[];
84 extern const char kSkelDir[];
85 extern const char kPreloadApps[];
86 extern const char kPreloadManifestDir[];
87 extern const char kPreloadIcons[];
89 extern testing::Environment *env;
90 void signalHandler(int signum);
92 enum class RequestResult {
97 class ScopedTzipInterface {
99 explicit ScopedTzipInterface(const std::string& pkgid)
100 : pkg_path_(bf::path(ci::GetRootAppPath(false,
101 kTestUserId)) / pkgid),
102 interface_(ci::GetMountLocation(pkg_path_)),
104 interface_.MountZip(ci::GetZipPackageLocation(pkg_path_, pkgid));
109 interface_.UnmountZip();
114 ~ScopedTzipInterface() {
120 ci::TzipInterface interface_;
124 class TestPkgmgrInstaller : public ci::PkgmgrInstallerInterface {
126 bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
127 ci::InstallationMode* mode) {
128 *installer = pkgmgr_installer_offline_new();
131 *mode = ci::InstallationMode::ONLINE;
135 bool ShouldCreateSignal() const {
140 enum class PackageType {
145 ci::RequestMode ParseRequestMode(int argc, char** argv);
147 bool TouchFile(const bf::path& path);
149 bool AddUser(const char *user_name);
151 bool DeleteUser(const char *user_name, bool rem_home_dir);
153 bool AddTestUser(const char *user_name);
155 bool DeleteTestUser(const char *user_name);
157 void RemoveAllRecoveryFiles();
159 bf::path FindRecoveryFile();
161 bf::path GetPackageRoot(const std::string& pkgid, uid_t uid);
163 bool ValidateFileContentInPackage(const std::string& pkgid,
164 const std::string& relative,
165 const std::string& expected,
166 bool is_readonly = false);
168 void AddDataFiles(const std::string& pkgid, uid_t uid);
170 bool ValidateDataFiles(const std::string& pkgid, uid_t uid);
172 bool ValidatePackageRWFS(const std::string& pkgid, uid_t uid);
174 bool ValidatePackageFS(const std::string& pkgid,
175 const std::vector<std::string>& appids,
176 uid_t uid, gid_t gid, bool is_readonly);
178 void PackageCheckCleanup(const std::string& pkgid,
179 const std::vector<std::string>&, bool is_readonly = false);
181 bool ValidatePackage(const std::string& pkgid,
182 const std::vector<std::string>& appids, bool is_readonly = false);
184 void ValidateExternalPackageFS(const std::string& pkgid,
185 const std::vector<std::string>& appids,
186 uid_t uid, gid_t gid);
188 void ValidateExternalPackage(const std::string& pkgid,
189 const std::vector<std::string>& appids);
191 bool CheckPackageNonExistance(const std::string& pkgid,
192 const std::vector<std::string>& appids);
194 void CheckPackageReadonlyNonExistance(const std::string& pkgid,
195 const std::vector<std::string>& appids);
197 std::unique_ptr<ci::AppQueryInterface> CreateQueryInterface();
199 std::unique_ptr<ci::AppInstaller> CreateInstaller(ci::PkgMgrPtr pkgmgr,
202 void TestRollbackAfterEachStep(int argc, const char*argv[],
203 std::function<bool()> validator,
204 PackageType type = PackageType::WGT);
206 void CrashAfterEachStep(std::vector<std::string> args,
207 std::function<bool(int iter)> validator,
208 PackageType type = PackageType::WGT);
210 ci::AppInstaller::Result RunInstallerWithPkgrmgr(ci::PkgMgrPtr pkgmgr,
213 ci::AppInstaller::Result CallBackend(int argc,
217 = RequestResult::NORMAL);
219 ci::AppInstaller::Result Install(const bf::path& path,
221 RequestResult mode = RequestResult::NORMAL);
223 ci::AppInstaller::Result InstallPreload(const bf::path& path, PackageType type,
224 RequestResult mode = RequestResult::NORMAL);
226 bool CheckAvailableExternalPath();
228 ci::AppInstaller::Result InstallExternal(const bf::path& path,
230 RequestResult mode = RequestResult::NORMAL);
232 ci::AppInstaller::Result MigrateLegacyExternalImage(const std::string& pkgid,
233 const bf::path& path,
234 const bf::path& legacy_path,
236 RequestResult mode = RequestResult::NORMAL);
238 ci::AppInstaller::Result MountInstall(const bf::path& path,
239 PackageType type, RequestResult mode = RequestResult::NORMAL);
241 ci::AppInstaller::Result Uninstall(const std::string& pkgid,
244 RequestResult mode = RequestResult::NORMAL);
246 ci::AppInstaller::Result RDSUpdate(const bf::path& path,
247 const std::string& pkgid,
249 RequestResult mode = RequestResult::NORMAL);
251 ci::AppInstaller::Result DeltaInstall(const bf::path& path,
252 const bf::path& delta_package, PackageType type);
254 ci::AppInstaller::Result EnablePackage(const std::string& pkgid,
256 RequestResult mode = RequestResult::NORMAL);
258 ci::AppInstaller::Result DisablePackage(const std::string& pkgid,
260 RequestResult mode = RequestResult::NORMAL);
262 ci::AppInstaller::Result Recover(const bf::path& recovery_file,
264 RequestResult mode = RequestResult::NORMAL);
266 void BackupPath(const bf::path& path);
268 void RestorePath(const bf::path& path);
270 std::vector<bf::path> SetupBackupDirectories();
272 void UninstallAllAppsInDirectory(bf::path dir, bool is_preload);
274 void UninstallAllSmokeApps(ci::RequestMode request_mode);
277 #endif // UNIT_TESTS_SMOKE_UTILS_H_