Run installer with subprocess in smoke test
[platform/core/appfw/wgt-backend.git] / test / smoke_tests / extensive_smoke_test.cc
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.
4
5 #include <common/utils/subprocess.h>
6
7 #include <common/utils/file_util.h>
8 #include <smoke_tests/common/smoke_utils.h>
9
10 #include <gtest/gtest.h>
11 #include <gtest/gtest-death-test.h>
12
13 #include "smoke_tests/wgt_smoke_utils.h"
14
15 namespace ci = common_installer;
16
17 namespace smoke_test {
18
19 class SmokeEnvironment : public testing::Environment {
20  public:
21   explicit SmokeEnvironment(ci::RequestMode mode) {\
22     request_mode_ = mode;
23   }
24   void SetUp() override {
25     if (request_mode_ == ci::RequestMode::USER)
26       ASSERT_TRUE(AddTestUser(&test_user));
27     backups_ = SetupBackupDirectories(test_user.uid);
28     for (auto& path : backups_)
29       ASSERT_TRUE(BackupPath(path));
30     CreateDatabase();
31   }
32   void TearDown() override {
33     ASSERT_TRUE(request_mode_ == ci::RequestMode::GLOBAL ||
34                 (request_mode_ == ci::RequestMode::USER &&
35                 kGlobalUserUid != test_user.uid));
36     WgtBackendInterface backend(std::to_string(test_user.uid));
37     UninstallAllSmokeApps(request_mode_, test_user.uid, &backend);
38     for (auto& path : backups_)
39       ASSERT_TRUE(RestorePath(path));
40     if (request_mode_ == ci::RequestMode::USER)
41       ASSERT_TRUE(DeleteTestUser());
42   }
43   User test_user;
44
45  private:
46   ci::RequestMode request_mode_;
47   std::vector<bf::path> backups_;
48 };
49
50 }  // namespace smoke_test
51
52 namespace {
53
54 smoke_test::SmokeEnvironment *env = nullptr;
55 void signalHandler(int signum) {
56   env->TearDown();
57   exit(signum);
58 }
59
60 }  // namespace
61
62 namespace smoke_test {
63
64 class SmokeTest : public testing::Test {
65  public:
66   SmokeTest() : backend(std::to_string(env->test_user.uid)),
67       params{PackageType::WGT, false} {
68     params.test_user.uid = env->test_user.uid;
69     params.test_user.gid = env->test_user.gid;
70   }
71  protected:
72   WgtBackendInterface backend;
73   TestParameters params;
74 };
75
76 class PreloadSmokeTest : public testing::Test {
77  public:
78   PreloadSmokeTest() : backend(std::to_string(env->test_user.uid)),
79       params{PackageType::WGT, true}  {
80     params.test_user.uid = env->test_user.uid;
81     params.test_user.gid = env->test_user.gid;
82   }
83  protected:
84   WgtBackendInterface backend;
85   TestParameters params;
86 };
87
88 class HybridSmokeTest : public testing::Test {
89  public:
90   HybridSmokeTest() : backend(std::to_string(env->test_user.uid)),
91       params{PackageType::HYBRID, false} {
92     params.test_user.uid = env->test_user.uid;
93     params.test_user.gid = env->test_user.gid;
94   }
95  protected:
96   HybridBackendInterface backend;
97   TestParameters params;
98 };
99
100 TEST_F(SmokeTest, RecoveryMode_ForInstallation) {
101   bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForInstallation.wgt";
102   std::string pkgid = "smokewgt09";
103   std::string appid = "smokewgt09.RecoveryModeForInstallation";
104
105   std::string test_user_str = std::to_string(params.test_user.uid);
106   std::vector<std::string> args =
107       {"", "-i", path.string(), "-u", test_user_str.c_str()};
108   backend.CrashAfterEachStep(&args, [&](int step) -> bool {
109     if (step >= 2) {
110       bf::path recovery_file = FindRecoveryFile("/wgt-recovery",
111                                                 params.test_user.uid);
112       EXTENDED_ASSERT_FALSE(recovery_file.empty());
113       std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
114           GetRecoverFileInfo(recovery_file);
115       EXTENDED_ASSERT_EQ(backend.RecoverWithSubprocess(recovery_file),
116           BackendInterface::SubProcessResult::SUCCESS);
117       if (recovery_info->cleanup()) {
118         EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
119         EXTENDED_ASSERT_EQ(backend.UninstallWithSubprocess(pkgid),
120             BackendInterface::SubProcessResult::SUCCESS);
121       } else {
122         EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
123       }
124     }
125     return true;
126   }, params.pkg_type);
127 }
128
129 TEST_F(SmokeTest, RecoveryMode_ForUpdate) {
130   bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForUpdate.wgt";
131   bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForUpdate_2.wgt";
132   RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
133   ASSERT_EQ(backend.InstallWithSubprocess(path_old),
134       BackendInterface::SubProcessResult::SUCCESS);
135   std::string pkgid = "smokewgt10";
136   std::string appid = "smokewgt10.RecoveryModeForUpdate";
137   AddDataFiles(pkgid, params.test_user.uid);
138
139   std::string test_user_str = std::to_string(params.test_user.uid);
140   std::vector<std::string> args =
141       {"", "-i", path_new.string(), "-u", test_user_str.c_str()};
142   backend.CrashAfterEachStep(&args, [&](int step) -> bool {
143     if (step >= 2) {
144       bf::path recovery_file = FindRecoveryFile("/wgt-recovery",
145                                                 params.test_user.uid);
146       EXTENDED_ASSERT_FALSE(recovery_file.empty());
147       std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
148           GetRecoverFileInfo(recovery_file);
149       EXTENDED_ASSERT_EQ(backend.RecoverWithSubprocess(recovery_file),
150           BackendInterface::SubProcessResult::SUCCESS);
151       EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
152
153       std::string version = recovery_info->cleanup() ? "2\n" :"1\n";
154       EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
155           "res/wgt/VERSION", version, params));
156       EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
157
158       if (recovery_info->cleanup()) {
159         EXTENDED_ASSERT_EQ(backend.UninstallWithSubprocess(pkgid),
160             BackendInterface::SubProcessResult::SUCCESS);
161         EXTENDED_ASSERT_EQ(backend.InstallWithSubprocess(path_old),
162             BackendInterface::SubProcessResult::SUCCESS);
163         AddDataFiles(pkgid, params.test_user.uid);
164       }
165     }
166     return true;
167   }, params.pkg_type);
168 }
169
170 TEST_F(SmokeTest, RecoveryMode_ForDelta) {
171   bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForDelta.wgt";
172   bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForDelta.delta";
173   std::string pkgid = "smokewgt30";
174   std::string appid = "smokewgt30.RecoveryModeForDelta";
175   RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
176   ASSERT_EQ(BackendInterface::SubProcessResult::SUCCESS,
177       backend.InstallWithSubprocess(path_old));
178   AddDataFiles(pkgid, params.test_user.uid);
179   std::string test_user_str = std::to_string(params.test_user.uid);
180   std::vector<std::string> args =
181       {"", "-i", path_new.string(), "-u", test_user_str.c_str()};
182   backend.CrashAfterEachStep(&args, [&](int step) -> bool {
183     if (step >= 2) {
184       bf::path recovery_file = FindRecoveryFile("/wgt-recovery",
185                                                 params.test_user.uid);
186       EXTENDED_ASSERT_FALSE(recovery_file.empty());
187       std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
188           GetRecoverFileInfo(recovery_file);
189       EXTENDED_ASSERT_EQ(backend.RecoverWithSubprocess(recovery_file),
190           BackendInterface::SubProcessResult::SUCCESS);
191       EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
192       std::string contents = recovery_info->cleanup() ? "2\n" : "1\n";
193
194       EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
195           "res/wgt/VERSION", contents, params));
196       EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
197
198       if (recovery_info->cleanup()) {
199         EXTENDED_ASSERT_EQ(backend.UninstallWithSubprocess(pkgid),
200             BackendInterface::SubProcessResult::SUCCESS);
201         EXTENDED_ASSERT_EQ(backend.InstallWithSubprocess(path_old),
202             BackendInterface::SubProcessResult::SUCCESS);
203         AddDataFiles(pkgid, params.test_user.uid);
204       }
205     }
206     return true;
207   }, params.pkg_type);
208 }
209
210 TEST_F(SmokeTest, RecoveryMode_ForMountInstall) {
211   bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForMountInstall.wgt";
212   std::string pkgid = "smokewgt31";
213   std::string appid = "smokewgt31.RecoveryModeForMountInstall";
214   RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
215   std::string test_user_str = std::to_string(params.test_user.uid);
216   std::vector<std::string> args =
217       {"", "-w", path.string(), "-u", test_user_str.c_str()};
218   backend.CrashAfterEachStep(&args, [&](int step) -> bool {
219     if (step >= 2) {
220       bf::path recovery_file = FindRecoveryFile("/wgt-recovery",
221                                                 params.test_user.uid);
222       EXTENDED_ASSERT_FALSE(recovery_file.empty());
223       std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
224           GetRecoverFileInfo(recovery_file);
225       EXTENDED_ASSERT_EQ(backend.RecoverWithSubprocess(recovery_file),
226           BackendInterface::SubProcessResult::SUCCESS);
227       ScopedTzipInterface interface(pkgid, params.test_user.uid);
228       if (recovery_info->cleanup()) {
229         EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
230         EXTENDED_ASSERT_EQ(backend.UninstallWithSubprocess(pkgid),
231             BackendInterface::SubProcessResult::SUCCESS);
232       } else {
233         EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
234       }
235     }
236     return true;
237   }, params.pkg_type);
238 }
239
240 TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) {
241   bf::path path_old =
242       kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate.wgt";
243   bf::path path_new =
244       kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate_2.wgt";
245   std::string pkgid = "smokewgt32";
246   std::string appid = "smokewgt32.RecoveryModeForMountUpdate";
247   RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
248   ASSERT_EQ(backend.MountInstallWithSubprocess(path_old),
249       BackendInterface::SubProcessResult::SUCCESS);
250   AddDataFiles(pkgid, params.test_user.uid);
251   std::string test_user_str = std::to_string(params.test_user.uid);
252   std::vector<std::string> args =
253       {"", "-w", path_new.string(), "-u", test_user_str.c_str()};
254   backend.CrashAfterEachStep(&args, [&](int step) -> bool {
255     if (step >= 2) {
256       // Filesystem may be mounted after crash
257       ScopedTzipInterface poweroff_unmount_interface(pkgid,
258                                                      params.test_user.uid);
259       poweroff_unmount_interface.Release();
260
261       bf::path recovery_file = FindRecoveryFile("/wgt-recovery",
262                                                 params.test_user.uid);
263       EXTENDED_ASSERT_FALSE(recovery_file.empty());
264       std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
265           GetRecoverFileInfo(recovery_file);
266       EXTENDED_ASSERT_EQ(backend.RecoverWithSubprocess(recovery_file),
267           BackendInterface::SubProcessResult::SUCCESS);
268
269       ScopedTzipInterface interface(pkgid, params.test_user.uid);
270       EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
271       std::string version = recovery_info->cleanup() ? "2\n" : "1\n";
272       EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(
273           pkgid, "res/wgt/VERSION", version, params));
274       EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
275       if (recovery_info->cleanup()) {
276         interface.Release();
277         EXTENDED_ASSERT_EQ(backend.UninstallWithSubprocess(pkgid),
278             BackendInterface::SubProcessResult::SUCCESS);
279         EXTENDED_ASSERT_EQ(backend.MountInstallWithSubprocess(path_old),
280             BackendInterface::SubProcessResult::SUCCESS);
281         AddDataFiles(pkgid, params.test_user.uid);
282       }
283     }
284     return true;
285   }, params.pkg_type);
286 }
287
288
289 TEST_F(SmokeTest, InstallationMode_Rollback) {
290   bf::path path = kSmokePackagesDirectory / "InstallationMode_Rollback.wgt";
291   std::string pkgid = "smokewgt06";
292   std::string appid = "smokewgt06.InstallationModeRollback";
293
294   std::string test_user_str = std::to_string(params.test_user.uid);
295   const char* argv[] = {"", "-i", path.c_str(), "-u", test_user_str.c_str()};
296   backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
297     EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
298     return true;
299   });
300 }
301
302 TEST_F(SmokeTest, UpdateMode_Rollback) {
303   bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Rollback.wgt";
304   bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Rollback_2.wgt";
305   std::string pkgid = "smokewgt07";
306   std::string appid = "smokewgt07.UpdateModeRollback";
307   ASSERT_EQ(backend.InstallWithSubprocess(path_old),
308       BackendInterface::SubProcessResult::SUCCESS);
309   AddDataFiles(pkgid, params.test_user.uid);
310   std::string test_user_str = std::to_string(params.test_user.uid);
311   const char* argv[] =
312       {"", "-i", path_new.c_str(), "-u", test_user_str.c_str()};
313   backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
314     EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
315
316     EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
317         "res/wgt/VERSION", "1\n", params));
318     EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
319     return true;
320   });
321 }
322
323 TEST_F(SmokeTest, DeltaMode_Rollback) {
324   bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback.wgt";
325   bf::path delta_package = kSmokePackagesDirectory / "DeltaMode_Rollback.delta";
326   std::string pkgid = "smokewgt01";
327   std::string appid = "smokewgt01.DeltaMode";
328   ASSERT_EQ(backend.InstallWithSubprocess(path),
329       BackendInterface::SubProcessResult::SUCCESS);
330   AddDataFiles(pkgid, params.test_user.uid);
331   std::string test_user_str = std::to_string(params.test_user.uid);
332   const char* argv[] =
333       {"", "-i", delta_package.c_str(), "-u", test_user_str.c_str()};
334   backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
335     EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
336     EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
337                                              "version 1\n", params));
338     EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
339     EXTENDED_ASSERT_TRUE(bf::exists(GetPackageRoot(
340         pkgid, params.test_user.uid) / "res/wgt/DELETED"));
341     EXTENDED_ASSERT_FALSE(bf::exists(GetPackageRoot(
342         pkgid, params.test_user.uid) / "res/wgt/ADDED"));
343     return true;
344   });
345 }
346
347 TEST_F(HybridSmokeTest, InstallationMode_Rollback) {
348   bf::path path = kSmokePackagesDirectory /
349       "InstallationMode_Rollback_Hybrid.wgt";
350   std::string pkgid = "smokehyb07";
351   std::string appid1 = "smokehyb07.web";
352   std::string test_user_str = std::to_string(params.test_user.uid);
353   const char* argv[] = {"", "-i", path.c_str(), "-u", test_user_str.c_str()};
354   backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
355      EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
356      return true;
357   });
358 }
359
360 TEST_F(HybridSmokeTest, UpdateMode_Rollback) {
361   bf::path path_old = kSmokePackagesDirectory /
362       "UpdateMode_Rollback_Hybrid.wgt";
363   bf::path path_new = kSmokePackagesDirectory /
364       "UpdateMode_Rollback_Hybrid_2.wgt";
365   std::string pkgid = "smokehyb08";
366   std::string appid1 = "smokehyb08.web";
367   ASSERT_EQ(backend.InstallWithSubprocess(path_old),
368       BackendInterface::SubProcessResult::SUCCESS);
369   AddDataFiles(pkgid, params.test_user.uid);
370   std::string test_user_str = std::to_string(params.test_user.uid);
371   const char* argv[] =
372       {"", "-i", path_new.c_str(), "-u", test_user_str.c_str()};
373   backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
374     EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid1}, params));
375
376     EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
377         "res/wgt/VERSION", "1\n", params));
378     EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
379         "lib/VERSION", "1\n", params));
380     EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
381     return true;
382   });
383 }
384
385 TEST_F(HybridSmokeTest, DeltaMode_Rollback_Hybrid) {
386   bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback_Hybrid.wgt";
387   bf::path delta_package = kSmokePackagesDirectory /
388       "DeltaMode_Rollback_Hybrid.delta";
389   std::string pkgid = "smokehyb11";
390   std::string appid1 = "smokehyb11.web";
391   ASSERT_EQ(backend.InstallWithSubprocess(path),
392       BackendInterface::SubProcessResult::SUCCESS);
393   AddDataFiles(pkgid, params.test_user.uid);
394   std::string test_user_str = std::to_string(params.test_user.uid);
395   const char* argv[] = {"", "-i", path.c_str(), "-u", test_user_str.c_str()};
396   backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
397     EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid1}, params));
398     // Check delta modifications
399     bf::path root_path = GetPackageRoot(pkgid, params.test_user.uid);
400     EXTENDED_ASSERT_TRUE(bf::exists(root_path / "res" / "wgt" / "DELETED"));
401     EXTENDED_ASSERT_FALSE(bf::exists(root_path / "res" / "wgt" / "ADDED"));
402     EXTENDED_ASSERT_TRUE(bf::exists(root_path / "lib" / "DELETED"));
403     EXTENDED_ASSERT_FALSE(bf::exists(root_path / "lib" / "ADDED"));
404     EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
405                                              "version 1\n", params));
406     EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/MODIFIED",
407                                              "version 1\n", params));
408     EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
409     return true;
410   });
411 }
412
413 TEST_F(HybridSmokeTest, MountInstallationMode_Rollback) {
414   bf::path path = kSmokePackagesDirectory /
415       "MountInstallationMode_Rollback_Hybrid.wgt";
416   std::string pkgid = "smokehyb09";
417   std::string appid1 = "smokehyb09.web";
418   std::string test_user_str = std::to_string(params.test_user.uid);
419   const char* argv[] = {"", "-w", path.c_str(), "-u", test_user_str.c_str()};
420   backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
421     ScopedTzipInterface interface(pkgid, params.test_user.uid);
422     EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
423     return true;
424   });
425 }
426
427 TEST_F(HybridSmokeTest, MountUpdateMode_Rollback) {
428   bf::path path_old = kSmokePackagesDirectory /
429       "MountUpdateMode_Rollback_Hybrid.wgt";
430   bf::path path_new = kSmokePackagesDirectory /
431       "MountUpdateMode_Rollback_Hybrid_2.wgt";
432   std::string pkgid = "smokehyb10";
433   std::string appid1 = "smokehyb10.web";
434   ASSERT_EQ(backend.MountInstallWithSubprocess(path_old),
435       BackendInterface::SubProcessResult::SUCCESS);
436   AddDataFiles(pkgid, params.test_user.uid);
437   std::string test_user_str = std::to_string(params.test_user.uid);
438   const char* argv[] =
439       {"", "-w", path_new.c_str(), "-u", test_user_str.c_str()};
440   backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
441     ScopedTzipInterface interface(pkgid, params.test_user.uid);
442     EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid1}, params));
443
444     EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
445         "res/wgt/VERSION", "1\n", params));
446     EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
447         "lib/VERSION", "1\n", params));
448     EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
449     return true;
450   });
451 }
452
453 TEST_F(SmokeTest, MountInstallationMode_Rollback) {
454   bf::path path =
455       kSmokePackagesDirectory / "MountInstallationMode_Rollback.wgt";
456   std::string pkgid = "smokewgt33";
457   std::string appid = "smokewgt33.web";
458   std::string test_user_str = std::to_string(params.test_user.uid);
459   const char* argv[] = {"", "-w", path.c_str(), "-u", test_user_str.c_str()};
460   backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
461     ScopedTzipInterface interface(pkgid, params.test_user.uid);
462     EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
463     return true;
464   });
465 }
466
467 TEST_F(SmokeTest, MountUpdateMode_Rollback) {
468   bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode_Rollback.wgt";
469   bf::path path_new =
470       kSmokePackagesDirectory / "MountUpdateMode_Rollback_2.wgt";
471   std::string pkgid = "smokewgt34";
472   std::string appid = "smokewgt34.web";
473   ASSERT_EQ(backend.MountInstallWithSubprocess(path_old),
474             BackendInterface::SubProcessResult::SUCCESS);
475   AddDataFiles(pkgid, params.test_user.uid);
476   std::string test_user_str = std::to_string(params.test_user.uid);
477   const char* argv[] =
478       {"", "-w", path_new.c_str(), "-u", test_user_str.c_str()};
479   backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
480     ScopedTzipInterface interface(pkgid, params.test_user.uid);
481     EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
482
483     EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
484         "res/wgt/VERSION", "1\n", params));
485     EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
486     return true;
487   });
488 }
489
490 TEST_F(PreloadSmokeTest, RecoveryMode_ForReadonlyUpdateInstall) {
491   ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
492   bf::path path_old = kSmokePackagesDirectory /
493       "RecoveryMode_ForReadonlyUpdateInstall.wgt";
494   bf::path path_new = kSmokePackagesDirectory /
495       "RecoveryMode_ForReadonlyUpdateInstall_2.wgt";
496   RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
497   ASSERT_EQ(backend.InstallPreloadWithSubprocess(path_old),
498       BackendInterface::SubProcessResult::SUCCESS);
499   std::string pkgid = "smokewgt51";
500   std::string appid = "smokewgt51.RecoveryModeForReadonlyUpdateInstall";
501   AddDataFiles(pkgid, params.test_user.uid);
502   std::string test_uid_str = std::to_string(params.test_user.uid);
503   std::vector<std::string> args =
504       {"", "-i", path_new.string(), "-u", test_uid_str.c_str()};
505   backend.CrashAfterEachStep(&args, [&](int step) -> bool {
506     if (step >= 2) {
507       bf::path recovery_file = FindRecoveryFile("/wgt-recovery",
508                                                 params.test_user.uid);
509       EXTENDED_ASSERT_FALSE(recovery_file.empty());
510       std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
511           GetRecoverFileInfo(recovery_file);
512       EXTENDED_ASSERT_EQ(backend.RecoverWithSubprocess(recovery_file),
513           BackendInterface::SubProcessResult::SUCCESS);
514       if (recovery_info->cleanup())
515         params.is_readonly = false;
516       EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
517
518       std::string version = recovery_info->cleanup() ? "2\n" :"1\n";
519       EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
520           "res/wgt/VERSION", version, params));
521       EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
522
523       if (recovery_info->cleanup()) {
524         EXTENDED_ASSERT_EQ(backend.UninstallWithSubprocess(pkgid),
525             BackendInterface::SubProcessResult::SUCCESS);
526         AddDataFiles(pkgid, params.test_user.uid);
527       }
528     }
529     return true;
530   }, params.pkg_type);
531 }
532
533 }  // namespace smoke_test
534
535 int main(int argc,  char** argv) {
536   try {
537     ci::RequestMode request_mode = smoke_test::ParseRequestMode(argc, argv);
538     if (getuid() != 0 || request_mode != ci::RequestMode::GLOBAL) {
539       std::cout << "Skip tests for preload request" << std::endl;
540       ::testing::GTEST_FLAG(filter) = "SmokeTest.*";
541     }
542     testing::InitGoogleTest(&argc, argv);
543     ::env = static_cast<smoke_test::SmokeEnvironment*>(
544         testing::AddGlobalTestEnvironment(
545             new smoke_test::SmokeEnvironment(request_mode)));
546     signal(SIGINT, ::signalHandler);
547     signal(SIGSEGV, ::signalHandler);
548     return RUN_ALL_TESTS();
549   } catch (...) {
550     std::cout << "Exception occurred during testing";
551     return 1;
552   }
553 }