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 #include <common/utils/subprocess.h>
7 #include <common/utils/file_util.h>
9 #include <gtest/gtest.h>
10 #include <gtest/gtest-death-test.h>
12 #include "unit_tests/smoke_utils.h"
15 namespace common_installer {
17 class SmokeEnvironment : public testing::Environment {
19 explicit SmokeEnvironment(ci::RequestMode mode) {\
22 void SetUp() override {
23 if (request_mode_ == ci::RequestMode::USER) {
24 ASSERT_TRUE(AddTestUser(kNormalUserName));
26 kTestUserId = kGlobalUserUid;
27 kTestGroupId = kGlobalUserGid;
28 kTestUserIdStr = std::to_string(kTestUserId);
30 backups_ = SetupBackupDirectories();
31 for (auto& path : backups_)
34 void TearDown() override {
35 ASSERT_TRUE(request_mode_ == ci::RequestMode::GLOBAL ||
36 (request_mode_ == ci::RequestMode::USER &&
37 kGlobalUserUid != kTestUserId));
38 UninstallAllSmokeApps(request_mode_);
39 for (auto& path : backups_)
41 if (request_mode_ == ci::RequestMode::USER)
42 ASSERT_TRUE(DeleteTestUser(kNormalUserName));
46 ci::RequestMode request_mode_;
47 std::vector<bf::path> backups_;
50 class SmokeTest : public testing::Test {
53 class PreloadSmokeTest : public testing::Test {
54 void SetUp() override {
55 ASSERT_EQ(kGlobalUserUid, kTestUserId);
59 TEST_F(SmokeTest, RecoveryMode_ForInstallation) {
60 bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForInstallation.wgt";
61 std::string pkgid = "smokewgt09";
62 std::string appid = "smokewgt09.RecoveryModeForInstallation";
64 std::vector<std::string> args =
65 {"", "-i", path.string(), "-u", kTestUserIdStr.c_str()};
66 CrashAfterEachStep(args, [=](int step) -> bool {
68 bf::path recovery_file = FindRecoveryFile();
69 EXTENDED_ASSERT_FALSE(recovery_file.empty());
70 EXTENDED_ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
71 ci::AppInstaller::Result::OK);
72 EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid}));
78 TEST_F(SmokeTest, RecoveryMode_ForUpdate) {
79 bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForUpdate.wgt";
80 bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForUpdate_2.wgt";
81 RemoveAllRecoveryFiles();
82 ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
83 std::string pkgid = "smokewgt10";
84 std::string appid = "smokewgt10.RecoveryModeForUpdate";
85 AddDataFiles(pkgid, kTestUserId);
87 std::vector<std::string> args =
88 {"", "-i", path_new.string(), "-u", kTestUserIdStr.c_str()};
89 CrashAfterEachStep(args, [=](int step) -> bool {
91 bf::path recovery_file = FindRecoveryFile();
92 EXTENDED_ASSERT_FALSE(recovery_file.empty());
93 EXTENDED_ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
94 ci::AppInstaller::Result::OK);
95 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
97 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
98 "res/wgt/VERSION", "1\n"));
99 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
105 TEST_F(SmokeTest, RecoveryMode_ForDelta) {
106 bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForDelta.wgt";
107 bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForDelta.delta";
108 std::string pkgid = "smokewgt30";
109 std::string appid = "smokewgt30.RecoveryModeForDelta";
110 bf::path recovery_file = FindRecoveryFile();
111 RemoveAllRecoveryFiles();
112 std::vector<std::string> args =
113 {"", "-i", path_new.string(), "-u", kTestUserIdStr.c_str()};
114 CrashAfterEachStep(args, [=](int step) -> bool {
116 EXTENDED_ASSERT_FALSE(recovery_file.empty());
117 EXTENDED_ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
118 ci::AppInstaller::Result::OK);
119 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
121 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
122 "res/wgt/VERSION", "1\n"));
128 TEST_F(SmokeTest, RecoveryMode_ForMountInstall) {
129 bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForMountInstall.wgt";
130 std::string pkgid = "smokewgt31";
131 std::string appid = "smokewgt31.RecoveryModeForMountInstall";
132 RemoveAllRecoveryFiles();
133 std::vector<std::string> args =
134 {"", "-w", path.string(), "-u", kTestUserIdStr.c_str()};
135 CrashAfterEachStep(args, [=](int step) -> bool {
137 bf::path recovery_file = FindRecoveryFile();
138 EXTENDED_ASSERT_FALSE(recovery_file.empty());
139 EXTENDED_ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
140 ci::AppInstaller::Result::OK);
141 EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid}));
147 TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) {
149 kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate.wgt";
151 kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate_2.wgt";
152 std::string pkgid = "smokewgt32";
153 std::string appid = "smokewgt32.RecoveryModeForMountUpdate";
154 RemoveAllRecoveryFiles();
155 ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
156 ci::AppInstaller::Result::OK);
157 AddDataFiles(pkgid, kTestUserId);
158 std::vector<std::string> args =
159 {"", "-w", path_new.string(), "-u", kTestUserIdStr.c_str()};
160 CrashAfterEachStep(args, [=](int step) -> bool {
162 // Filesystem may be mounted after crash
163 ScopedTzipInterface poweroff_unmount_interface(pkgid);
164 poweroff_unmount_interface.Release();
166 bf::path recovery_file = FindRecoveryFile();
167 EXTENDED_ASSERT_FALSE(recovery_file.empty());
168 EXTENDED_ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
169 ci::AppInstaller::Result::OK);
171 ScopedTzipInterface interface(pkgid);
172 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
173 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(
174 pkgid, "res/wgt/VERSION", "1\n"));
175 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
182 TEST_F(SmokeTest, InstallationMode_Rollback) {
183 bf::path path = kSmokePackagesDirectory / "InstallationMode_Rollback.wgt";
184 std::string pkgid = "smokewgt06";
185 std::string appid = "smokewgt06.InstallationModeRollback";
187 const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()};
188 TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
189 EXTENDED_ASSERT_EQ(Install(path, PackageType::WGT, RequestResult::FAIL),
190 ci::AppInstaller::Result::ERROR);
191 EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid}));
196 TEST_F(SmokeTest, UpdateMode_Rollback) {
197 bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Rollback.wgt";
198 bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Rollback_2.wgt";
199 std::string pkgid = "smokewgt07";
200 std::string appid = "smokewgt07.UpdateModeRollback";
201 ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
202 AddDataFiles(pkgid, kTestUserId);
204 {"", "-i", path_new.c_str(), "-u", kTestUserIdStr.c_str()};
205 TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
206 EXTENDED_ASSERT_EQ(Install(path_new, PackageType::WGT, RequestResult::FAIL),
207 ci::AppInstaller::Result::ERROR);
208 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
210 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
211 "res/wgt/VERSION", "1\n"));
212 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
217 TEST_F(SmokeTest, DeltaMode_Rollback) {
218 bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback.wgt";
219 bf::path delta_package = kSmokePackagesDirectory / "DeltaMode_Rollback.delta";
220 std::string pkgid = "smokewgt01";
221 std::string appid = "smokewgt01.DeltaMode";
222 ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
223 AddDataFiles(pkgid, kTestUserId);
225 {"", "-i", delta_package.c_str(), "-u", kTestUserIdStr.c_str()};
226 TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
227 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
228 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
230 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
231 EXTENDED_ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
233 EXTENDED_ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
239 TEST_F(SmokeTest, InstallationMode_Rollback_Hybrid) {
240 bf::path path = kSmokePackagesDirectory /
241 "InstallationMode_Rollback_Hybrid.wgt";
242 std::string pkgid = "smokehyb07";
243 std::string appid1 = "smokehyb07.web";
244 const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()};
245 TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
246 EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid1}));
248 }, PackageType::HYBRID);
251 TEST_F(SmokeTest, UpdateMode_Rollback_Hybrid) {
252 bf::path path_old = kSmokePackagesDirectory /
253 "UpdateMode_Rollback_Hybrid.wgt";
254 bf::path path_new = kSmokePackagesDirectory /
255 "UpdateMode_Rollback_Hybrid_2.wgt";
256 std::string pkgid = "smokehyb08";
257 std::string appid1 = "smokehyb08.web";
258 ASSERT_EQ(Install(path_old, PackageType::HYBRID),
259 ci::AppInstaller::Result::OK);
260 AddDataFiles(pkgid, kTestUserId);
262 {"", "-i", path_new.c_str(), "-u", kTestUserIdStr.c_str()};
263 TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
264 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
266 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
267 "res/wgt/VERSION", "1\n"));
268 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
269 "lib/VERSION", "1\n"));
270 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
272 }, PackageType::HYBRID);
275 TEST_F(SmokeTest, DeltaMode_Rollback_Hybrid) {
276 bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback_Hybrid.wgt";
277 bf::path delta_package = kSmokePackagesDirectory /
278 "DeltaMode_Rollback_Hybrid.delta";
279 std::string pkgid = "smokehyb11";
280 std::string appid1 = "smokehyb11.web";
281 ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK);
282 AddDataFiles(pkgid, kTestUserId);
283 const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()};
284 TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
285 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
286 // Check delta modifications
287 bf::path root_path = GetPackageRoot(pkgid, kTestUserId);
288 EXTENDED_ASSERT_TRUE(bf::exists(root_path / "res" / "wgt" / "DELETED"));
289 EXTENDED_ASSERT_FALSE(bf::exists(root_path / "res" / "wgt" / "ADDED"));
290 EXTENDED_ASSERT_TRUE(bf::exists(root_path / "lib" / "DELETED"));
291 EXTENDED_ASSERT_FALSE(bf::exists(root_path / "lib" / "ADDED"));
292 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
294 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/MODIFIED",
296 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
301 TEST_F(SmokeTest, MountInstallationMode_Rollback_Hybrid) {
302 bf::path path = kSmokePackagesDirectory /
303 "MountInstallationMode_Rollback_Hybrid.wgt";
304 std::string pkgid = "smokehyb09";
305 std::string appid1 = "smokehyb09.web";
306 const char* argv[] = {"", "-w", path.c_str(), "-u", kTestUserIdStr.c_str()};
307 TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
308 ScopedTzipInterface interface(pkgid);
309 EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid1}));
311 }, PackageType::HYBRID);
314 TEST_F(SmokeTest, MountUpdateMode_Rollback_Hybrid) {
315 bf::path path_old = kSmokePackagesDirectory /
316 "MountUpdateMode_Rollback_Hybrid.wgt";
317 bf::path path_new = kSmokePackagesDirectory /
318 "MountUpdateMode_Rollback_Hybrid_2.wgt";
319 std::string pkgid = "smokehyb10";
320 std::string appid1 = "smokehyb10.web";
321 ASSERT_EQ(MountInstall(path_old, PackageType::HYBRID),
322 ci::AppInstaller::Result::OK);
323 AddDataFiles(pkgid, kTestUserId);
325 {"", "-w", path_new.c_str(), "-u", kTestUserIdStr.c_str()};
326 TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
327 ScopedTzipInterface interface(pkgid);
328 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
330 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
331 "res/wgt/VERSION", "1\n"));
332 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
333 "lib/VERSION", "1\n"));
334 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
339 TEST_F(SmokeTest, MountInstallationMode_Rollback) {
341 kSmokePackagesDirectory / "MountInstallationMode_Rollback.wgt";
342 std::string pkgid = "smokewgt33";
343 std::string appid = "smokewgt33.web";
344 const char* argv[] = {"", "-w", path.c_str(), "-u", kTestUserIdStr.c_str()};
345 TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
346 ScopedTzipInterface interface(pkgid);
347 EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid}));
352 TEST_F(SmokeTest, MountUpdateMode_Rollback) {
353 bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode_Rollback.wgt";
355 kSmokePackagesDirectory / "MountUpdateMode_Rollback_2.wgt";
356 std::string pkgid = "smokewgt34";
357 std::string appid = "smokewgt34.web";
358 ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
359 ci::AppInstaller::Result::OK);
360 AddDataFiles(pkgid, kTestUserId);
362 {"", "-w", path_new.c_str(), "-u", kTestUserIdStr.c_str()};
363 TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
364 EXTENDED_ASSERT_EQ(MountInstall(path_new, PackageType::WGT,
365 RequestResult::FAIL), ci::AppInstaller::Result::ERROR);
366 ScopedTzipInterface interface(pkgid);
367 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
369 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
370 "res/wgt/VERSION", "1\n"));
371 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
376 } // namespace common_installer
378 int main(int argc, char** argv) {
379 ci::RequestMode request_mode = ParseRequestMode(argc, argv);
380 if (getuid() != 0 || request_mode != ci::RequestMode::GLOBAL) {
381 std::cout << "Skip tests for preload request" << std::endl;
382 ::testing::GTEST_FLAG(filter) = "SmokeTest.*";
384 testing::InitGoogleTest(&argc, argv);
385 testing::Environment *env = testing::AddGlobalTestEnvironment(
386 new common_installer::SmokeEnvironment(request_mode));
387 return RUN_ALL_TESTS();