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>
18 #include <manifest_parser/utils/version_number.h>
20 #include <gtest/gtest.h>
26 #include "hybrid/hybrid_installer.h"
27 #include "wgt/wgt_app_query_interface.h"
29 #define SIZEOFARRAY(ARR) \
30 sizeof(ARR) / sizeof(ARR[0]) \
32 #define EXTENDED_ASSERT_TRUE(expression) do { \
33 bool tmp = expression; \
34 EXPECT_TRUE(tmp) << #expression << " is not true"; \
39 #define EXTENDED_ASSERT_FALSE(expression) do { \
40 bool tmp = expression; \
41 EXPECT_FALSE(tmp) << #expression << " is not false"; \
46 #define EXTENDED_ASSERT_EQ(expression, value) do { \
47 auto ret = expression; \
48 EXPECT_EQ(ret, value) << #expression << " is not equal to " << #value; \
53 namespace bf = boost::filesystem;
54 namespace bs = boost::system;
55 namespace ci = common_installer;
57 extern const uid_t kGlobalUserUid;
58 extern const uid_t kGlobalUserGid;
59 extern const uid_t kDefaultUserUid;
60 extern uid_t kTestUserId;
61 extern gid_t kTestGroupId;
62 extern std::string kTestUserIdStr;
63 extern const char kNormalUserName[];
64 extern const char kSystemShareGroupName[];
65 extern const std::string& kDefaultUserIdStr;
66 extern const char kLegacyExtImageDir[];
67 extern const char kMigrateTestDBName[];
69 extern const bf::path kSmokePackagesDirectory;
79 extern const char* rwDirectories[];
82 extern const std::vector<std::string> kDBEntries;
84 extern const char kGlobalManifestDir[];
85 extern const char kSkelDir[];
86 extern const char kPreloadApps[];
87 extern const char kPreloadManifestDir[];
88 extern const char kPreloadIcons[];
90 extern testing::Environment *env;
91 void signalHandler(int signum);
93 enum class RequestResult {
98 class ScopedTzipInterface {
100 explicit ScopedTzipInterface(const std::string& pkgid)
101 : pkg_path_(bf::path(ci::GetRootAppPath(false,
102 kTestUserId)) / pkgid),
103 interface_(ci::GetMountLocation(pkg_path_)),
105 interface_.MountZip(ci::GetZipPackageLocation(pkg_path_, pkgid));
110 interface_.UnmountZip();
115 ~ScopedTzipInterface() {
121 ci::TzipInterface interface_;
125 class TestPkgmgrInstaller : public ci::PkgmgrInstallerInterface {
127 bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
128 ci::InstallationMode* mode) {
129 *installer = pkgmgr_installer_offline_new();
132 *mode = ci::InstallationMode::ONLINE;
136 bool ShouldCreateSignal() const {
141 enum class PackageType {
146 ci::RequestMode ParseRequestMode(int argc, char** argv);
148 bool TouchFile(const bf::path& path);
150 bool AddUser(const char *user_name);
152 bool DeleteUser(const char *user_name, bool rem_home_dir);
154 bool AddTestUser(const char *user_name);
156 bool DeleteTestUser(const char *user_name);
158 void RemoveAllRecoveryFiles();
160 bf::path FindRecoveryFile();
162 bf::path GetPackageRoot(const std::string& pkgid, uid_t uid);
164 bool ValidateFileContentInPackage(const std::string& pkgid,
165 const std::string& relative,
166 const std::string& expected,
167 bool is_readonly = false);
169 void AddDataFiles(const std::string& pkgid, uid_t uid);
171 bool ValidateDataFiles(const std::string& pkgid, uid_t uid);
173 bool ValidatePackageRWFS(const std::string& pkgid, uid_t uid);
175 bool ValidatePackageFS(const std::string& pkgid,
176 const std::vector<std::string>& appids,
177 uid_t uid, gid_t gid, bool is_readonly);
179 void PackageCheckCleanup(const std::string& pkgid,
180 const std::vector<std::string>&, bool is_readonly = false);
182 bool ValidatePackage(const std::string& pkgid,
183 const std::vector<std::string>& appids, bool is_readonly = false);
185 void ValidateExternalPackageFS(const std::string& pkgid,
186 const std::vector<std::string>& appids,
187 uid_t uid, gid_t gid);
189 void ValidateExternalPackage(const std::string& pkgid,
190 const std::vector<std::string>& appids);
192 bool CheckPackageNonExistance(const std::string& pkgid,
193 const std::vector<std::string>& appids);
195 void CheckPackageReadonlyNonExistance(const std::string& pkgid,
196 const std::vector<std::string>& appids);
198 std::unique_ptr<ci::AppQueryInterface> CreateQueryInterface();
200 std::unique_ptr<ci::AppInstaller> CreateInstaller(ci::PkgMgrPtr pkgmgr,
203 void TestRollbackAfterEachStep(int argc, const char*argv[],
204 std::function<bool()> validator,
205 PackageType type = PackageType::WGT);
207 void CrashAfterEachStep(std::vector<std::string> args,
208 std::function<bool(int iter)> validator,
209 PackageType type = PackageType::WGT);
211 ci::AppInstaller::Result RunInstallerWithPkgrmgr(ci::PkgMgrPtr pkgmgr,
214 ci::AppInstaller::Result CallBackend(int argc,
218 = RequestResult::NORMAL);
220 ci::AppInstaller::Result Install(const bf::path& path,
222 RequestResult mode = RequestResult::NORMAL);
224 ci::AppInstaller::Result InstallPreload(const bf::path& path, PackageType type,
225 RequestResult mode = RequestResult::NORMAL);
227 bool CheckAvailableExternalPath();
229 ci::AppInstaller::Result InstallExternal(const bf::path& path,
231 RequestResult mode = RequestResult::NORMAL);
233 ci::AppInstaller::Result MigrateLegacyExternalImage(const std::string& pkgid,
234 const bf::path& path,
235 const bf::path& legacy_path,
237 RequestResult mode = RequestResult::NORMAL);
239 ci::AppInstaller::Result MountInstall(const bf::path& path,
240 PackageType type, RequestResult mode = RequestResult::NORMAL);
242 ci::AppInstaller::Result Uninstall(const std::string& pkgid,
245 RequestResult mode = RequestResult::NORMAL);
247 ci::AppInstaller::Result RDSUpdate(const bf::path& path,
248 const std::string& pkgid,
250 RequestResult mode = RequestResult::NORMAL);
252 ci::AppInstaller::Result DeltaInstall(const bf::path& path,
253 const bf::path& delta_package, PackageType type);
255 ci::AppInstaller::Result EnablePackage(const std::string& pkgid,
257 RequestResult mode = RequestResult::NORMAL);
259 ci::AppInstaller::Result DisablePackage(const std::string& pkgid,
261 RequestResult mode = RequestResult::NORMAL);
263 ci::AppInstaller::Result Recover(const bf::path& recovery_file,
265 RequestResult mode = RequestResult::NORMAL);
267 ci::AppInstaller::Result ManifestDirectInstall(const std::string& pkgid,
268 PackageType type, RequestResult mode = RequestResult::NORMAL);
270 bool BackupPath(const bf::path& path);
272 bool RestorePath(const bf::path& path);
274 std::vector<bf::path> SetupBackupDirectories();
276 void UninstallAllAppsInDirectory(bf::path dir, bool is_preload);
278 void UninstallAllSmokeApps(ci::RequestMode request_mode);
280 int GetAppInstalledTime(const char *appid, uid_t uid);
282 #endif // UNIT_TESTS_SMOKE_UTILS_H_