[SmokeTest] Add SIGINT and SIGSEGV handling
[platform/core/appfw/wgt-backend.git] / src / unit_tests / smoke_test.cc
1 // Copyright (c) 2015 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 #include <common/utils/file_util.h>
7
8 #include <gtest/gtest-death-test.h>
9
10 #include "unit_tests/smoke_utils.h"
11
12
13 namespace common_installer {
14
15 class SmokeEnvironment : public testing::Environment {
16  public:
17   explicit SmokeEnvironment(ci::RequestMode mode) {\
18     request_mode_ = mode;
19   }
20   void SetUp() override {
21     if (request_mode_ == ci::RequestMode::USER) {
22       ASSERT_TRUE(AddTestUser(kNormalUserName));
23     } else {
24       kTestUserId = kGlobalUserUid;
25       kTestGroupId = kGlobalUserGid;
26       kTestUserIdStr = std::to_string(kTestUserId);
27     }
28     backups_ = SetupBackupDirectories();
29     for (auto& path : backups_)
30       BackupPath(path);
31   }
32   void TearDown() override {
33     ASSERT_TRUE(request_mode_ == ci::RequestMode::GLOBAL ||
34                 (request_mode_ == ci::RequestMode::USER &&
35                 kGlobalUserUid != kTestUserId));
36     UninstallAllSmokeApps(request_mode_);
37     for (auto& path : backups_)
38       RestorePath(path);
39     if (request_mode_ == ci::RequestMode::USER)
40       ASSERT_TRUE(DeleteTestUser(kNormalUserName));
41   }
42
43  private:
44   ci::RequestMode request_mode_;
45   std::vector<bf::path> backups_;
46 };
47
48 class SmokeTest : public testing::Test {
49 };
50
51 class PreloadSmokeTest : public testing::Test {
52   void SetUp() override {
53     ASSERT_EQ(kGlobalUserUid, kTestUserId);
54   }
55 };
56
57 TEST_F(SmokeTest, InstallationMode) {
58   bf::path path = kSmokePackagesDirectory / "InstallationMode.wgt";
59   std::string pkgid = "smokewgt03";
60   std::string appid = "smokewgt03.InstallationMode";
61   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
62   ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
63 }
64
65 TEST_F(SmokeTest, UpdateMode) {
66   bf::path path_old = kSmokePackagesDirectory / "UpdateMode.wgt";
67   bf::path path_new = kSmokePackagesDirectory / "UpdateMode_2.wgt";
68   std::string pkgid = "smokewgt04";
69   std::string appid = "smokewgt04.UpdateMode";
70   ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
71   AddDataFiles(pkgid, kTestUserId);
72   ASSERT_EQ(Install(path_new, PackageType::WGT), ci::AppInstaller::Result::OK);
73   ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
74
75   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
76   ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
77 }
78
79 TEST_F(SmokeTest, DeinstallationMode) {
80   bf::path path = kSmokePackagesDirectory / "DeinstallationMode.wgt";
81   std::string pkgid = "smokewgt05";
82   std::string appid = "smokewgt05.DeinstallationMode";
83   ASSERT_EQ(Install(path, PackageType::WGT),
84             ci::AppInstaller::Result::OK);
85   ASSERT_EQ(Uninstall(pkgid, PackageType::WGT, false),
86             ci::AppInstaller::Result::OK);
87   ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid}));
88 }
89
90 TEST_F(SmokeTest, RDSMode) {
91   bf::path path = kSmokePackagesDirectory / "RDSMode.wgt";
92   std::string pkgid = "smokewgt11";
93   std::string appid = "smokewgt11.RDSMode";
94   bf::path delta_directory = kSmokePackagesDirectory / "delta_dir/";
95   bf::path sdk_expected_directory =
96       bf::path(ci::GetRootAppPath(false, kTestUserId)) / "tmp" / pkgid;
97   bs::error_code error;
98   bf::create_directories(sdk_expected_directory.parent_path(), error);
99   ASSERT_FALSE(error);
100   ASSERT_TRUE(CopyDir(delta_directory, sdk_expected_directory));
101   ASSERT_EQ(RDSUpdate(path, pkgid, PackageType::WGT),
102             ci::AppInstaller::Result::OK);
103   ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
104
105   // Check delta modifications
106   ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
107       "res" / "wgt" / "DELETED"));
108   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
109       "res" / "wgt" / "ADDED"));
110   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "2\n"));
111 }
112
113 TEST_F(SmokeTest, EnablePkg) {
114   bf::path path = kSmokePackagesDirectory / "EnablePkg.wgt";
115   std::string pkgid = "smokewgt22";
116   ASSERT_EQ(Install(path, PackageType::WGT),
117             ci::AppInstaller::Result::OK);
118   ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
119             ci::AppInstaller::Result::OK);
120   ASSERT_EQ(EnablePackage(pkgid, PackageType::WGT),
121             ci::AppInstaller::Result::OK);
122
123   ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid,
124       ci::GetRequestMode(kTestUserId),
125       kTestUserId));
126 }
127
128 TEST_F(SmokeTest, DisablePkg) {
129   bf::path path = kSmokePackagesDirectory / "DisablePkg.wgt";
130   std::string pkgid = "smokewgt21";
131   std::string appid = "smokewgt21.DisablePkg";
132   ASSERT_EQ(Install(path, PackageType::WGT),
133             ci::AppInstaller::Result::OK);
134   ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
135             ci::AppInstaller::Result::OK);
136   ASSERT_TRUE(ci::QueryIsDisabledPackage(pkgid, kTestUserId));
137   ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
138 }
139
140 TEST_F(SmokeTest, DeltaMode) {
141   bf::path path = kSmokePackagesDirectory / "DeltaMode.wgt";
142   bf::path delta_package = kSmokePackagesDirectory / "DeltaMode.delta";
143   std::string pkgid = "smokewgt17";
144   std::string appid = "smokewgt17.DeltaMode";
145   ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::WGT),
146             ci::AppInstaller::Result::OK);
147   ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
148
149   // Check delta modifications
150   ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
151       "res" / "wgt" / "DELETED"));
152   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
153       "res" / "wgt" / "ADDED"));
154   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
155       "res" / "wgt" / "css" / "style.css"));
156   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
157       "res" / "wgt" / "images" / "tizen_32.png"));
158   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
159       "res" / "wgt" / "js" / "main.js"));
160   ASSERT_TRUE(ValidateFileContentInPackage(
161       pkgid, "res/wgt/MODIFIED", "version 2\n"));
162 }
163
164 TEST_F(SmokeTest, RecoveryMode_ForInstallation) {
165   bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForInstallation.wgt";
166   Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
167   backend_crash.Run("-i", path.string(), "-u", kTestUserIdStr.c_str());
168   ASSERT_NE(backend_crash.Wait(), 0);
169
170   std::string pkgid = "smokewgt09";
171   std::string appid = "smokewgt09.RecoveryModeForInstallation";
172   bf::path recovery_file = FindRecoveryFile();
173   ASSERT_FALSE(recovery_file.empty());
174   ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
175       ci::AppInstaller::Result::OK);
176   ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid}));
177 }
178
179 TEST_F(SmokeTest, RecoveryMode_ForUpdate) {
180   bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForUpdate.wgt";
181   bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForUpdate_2.wgt";
182   RemoveAllRecoveryFiles();
183   ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
184   std::string pkgid = "smokewgt10";
185   std::string appid = "smokewgt10.RecoveryModeForUpdate";
186   AddDataFiles(pkgid, kTestUserId);
187   Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
188   backend_crash.Run("-i", path_new.string(), "-u", kTestUserIdStr.c_str());
189   ASSERT_NE(backend_crash.Wait(), 0);
190
191   bf::path recovery_file = FindRecoveryFile();
192   ASSERT_FALSE(recovery_file.empty());
193   ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
194             ci::AppInstaller::Result::OK);
195   ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
196
197   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
198   ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
199 }
200
201 TEST_F(SmokeTest, RecoveryMode_ForDelta) {
202   bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForDelta.wgt";
203   bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForDelta.delta";
204   RemoveAllRecoveryFiles();
205   ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
206   Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
207   backend_crash.Run("-i", path_new.string(), "-u", kTestUserIdStr.c_str());
208   ASSERT_NE(backend_crash.Wait(), 0);
209
210   std::string pkgid = "smokewgt30";
211   std::string appid = "smokewgt30.RecoveryModeForDelta";
212   bf::path recovery_file = FindRecoveryFile();
213   ASSERT_FALSE(recovery_file.empty());
214   ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
215             ci::AppInstaller::Result::OK);
216   ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
217
218   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
219 }
220
221 TEST_F(SmokeTest, RecoveryMode_ForMountInstall) {
222   bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForMountInstall.wgt";
223   RemoveAllRecoveryFiles();
224   Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
225   backend_crash.Run("-w", path.string(), "-u", kTestUserIdStr.c_str());
226   ASSERT_NE(backend_crash.Wait(), 0);
227
228   std::string pkgid = "smokewgt31";
229   std::string appid = "smokewgt31.RecoveryModeForMountInstall";
230   bf::path recovery_file = FindRecoveryFile();
231   ASSERT_FALSE(recovery_file.empty());
232   ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
233             ci::AppInstaller::Result::OK);
234   ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid}));
235 }
236
237 TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) {
238   bf::path path_old =
239       kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate.wgt";
240   bf::path path_new =
241       kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate_2.wgt";
242   std::string pkgid = "smokewgt32";
243   std::string appid = "smokewgt32.RecoveryModeForMountUpdate";
244   RemoveAllRecoveryFiles();
245   ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
246             ci::AppInstaller::Result::OK);
247   AddDataFiles(pkgid, kTestUserId);
248   Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
249   backend_crash.Run("-w", path_new.string(), "-u", kTestUserIdStr.c_str());
250   ASSERT_NE(backend_crash.Wait(), 0);
251
252   // Filesystem may be mounted after crash
253   ScopedTzipInterface poweroff_unmount_interface(pkgid);
254   poweroff_unmount_interface.Release();
255
256   bf::path recovery_file = FindRecoveryFile();
257   ASSERT_FALSE(recovery_file.empty());
258   ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
259             ci::AppInstaller::Result::OK);
260
261   ScopedTzipInterface interface(pkgid);
262   ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
263   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
264   ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
265 }
266
267 TEST_F(SmokeTest, InstallationMode_GoodSignature) {
268   // pkgid: smokewgt08
269   bf::path path = kSmokePackagesDirectory / "InstallationMode_GoodSignature.wgt";  // NOLINT
270   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
271 }
272
273 TEST_F(SmokeTest, InstallationMode_WrongSignature) {
274   // pkgid: smokewgt12
275   bf::path path = kSmokePackagesDirectory / "InstallationMode_WrongSignature.wgt";  // NOLINT
276   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::ERROR);
277 }
278
279 TEST_F(SmokeTest, InstallationMode_Rollback) {
280   bf::path path = kSmokePackagesDirectory / "InstallationMode_Rollback.wgt";
281   std::string pkgid = "smokewgt06";
282   std::string appid = "smokewgt06.InstallationModeRollback";
283   ASSERT_EQ(Install(path, PackageType::WGT, RequestResult::FAIL),
284             ci::AppInstaller::Result::ERROR);
285   ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid}));
286 }
287
288 TEST_F(SmokeTest, UpdateMode_Rollback) {
289   bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Rollback.wgt";
290   bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Rollback_2.wgt";
291   std::string pkgid = "smokewgt07";
292   std::string appid = "smokewgt07.UpdateModeRollback";
293   ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
294   AddDataFiles(pkgid, kTestUserId);
295   ASSERT_EQ(Install(path_new, PackageType::WGT, RequestResult::FAIL),
296                     ci::AppInstaller::Result::ERROR);
297   ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
298
299   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
300   ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
301 }
302
303 TEST_F(SmokeTest, DeltaMode_Rollback) {
304   bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback.wgt";
305   bf::path delta_package = kSmokePackagesDirectory / "DeltaMode_Rollback.delta";
306   std::string pkgid = "smokewgt01";
307   std::string appid = "smokewgt01.DeltaMode";
308   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
309   AddDataFiles(pkgid, kTestUserId);
310   ASSERT_EQ(Install(delta_package, PackageType::WGT, RequestResult::FAIL),
311             ci::AppInstaller::Result::ERROR);
312
313   ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
314   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
315                                            "version 1\n"));
316   ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
317   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
318                          "res/wgt/DELETED"));
319   ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
320                           "res/wgt/ADDED"));
321 }
322
323 TEST_F(SmokeTest, InstallationMode_Hybrid) {
324   bf::path path = kSmokePackagesDirectory / "InstallationMode_Hybrid.wgt";
325   std::string pkgid = "smokehyb01";
326   // Excutable for native app doesn't create symlink
327   std::string appid1 = "smokehyb01.Web";
328   ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK);
329   ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
330 }
331
332 TEST_F(SmokeTest, UpdateMode_Hybrid) {
333   bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Hybrid.wgt";
334   bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Hybrid_2.wgt";
335   std::string pkgid = "smokehyb02";
336   std::string appid1 = "smokehyb02.Web";
337   ASSERT_EQ(Install(path_old, PackageType::HYBRID),
338             ci::AppInstaller::Result::OK);
339 //  AddDataFiles(pkgid, kTestUserId);
340   ASSERT_EQ(Install(path_new, PackageType::HYBRID),
341             ci::AppInstaller::Result::OK);
342   ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
343
344   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
345   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "VERSION", "2\n"));
346 //  ValidateDataFiles(pkgid, kTestUserId);
347 }
348
349 TEST_F(SmokeTest, DeinstallationMode_Hybrid) {
350   bf::path path = kSmokePackagesDirectory / "DeinstallationMode_Hybrid.wgt";
351   std::string pkgid = "smokehyb03";
352   std::string appid1 = "smokehyb03.Web";
353   ASSERT_EQ(Install(path, PackageType::HYBRID),
354             ci::AppInstaller::Result::OK);
355   ASSERT_EQ(Uninstall(pkgid, PackageType::HYBRID, false),
356             ci::AppInstaller::Result::OK);
357   ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid1}));
358 }
359
360 TEST_F(SmokeTest, DeltaMode_Hybrid) {
361   bf::path path = kSmokePackagesDirectory / "DeltaMode_Hybrid.wgt";
362   bf::path delta_package = kSmokePackagesDirectory / "DeltaMode_Hybrid.delta";
363   std::string pkgid = "smokehyb04";
364   std::string appid1 = "smokehyb04.Web";
365   ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::HYBRID),
366             ci::AppInstaller::Result::OK);
367   ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
368
369   // Check delta modifications
370   bf::path root_path = ci::GetRootAppPath(false,
371       kTestUserId);
372   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
373   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
374   ASSERT_FALSE(bf::exists(root_path / pkgid / "lib" / "DELETED"));
375   ASSERT_TRUE(bf::exists(root_path / pkgid / "lib" / "ADDED"));
376   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "css" / "style.css"));  // NOLINT
377   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "images" / "tizen_32.png"));  // NOLINT
378   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "js" / "main.js"));
379   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "version 2\n"));  // NOLINT
380   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/MODIFIED", "version 2\n"));  // NOLINT
381 }
382
383 TEST_F(SmokeTest, MountInstallationMode_Hybrid) {
384   bf::path path = kSmokePackagesDirectory / "MountInstallationMode_Hybrid.wgt";
385   std::string pkgid = "smokehyb05";
386   std::string appid1 = "smokehyb05.web";
387   ASSERT_EQ(MountInstall(path, PackageType::HYBRID),
388             ci::AppInstaller::Result::OK);
389   ScopedTzipInterface interface(pkgid);
390   ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
391 }
392
393 TEST_F(SmokeTest, MountUpdateMode_Hybrid) {
394   bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode_Hybrid.wgt";
395   bf::path path_new = kSmokePackagesDirectory / "MountUpdateMode_Hybrid_2.wgt";
396   std::string pkgid = "smokehyb06";
397   std::string appid1 = "smokehyb06.web";
398   ASSERT_EQ(MountInstall(path_old, PackageType::HYBRID),
399             ci::AppInstaller::Result::OK);
400   AddDataFiles(pkgid, kTestUserId);
401   ASSERT_EQ(MountInstall(path_new, PackageType::HYBRID),
402             ci::AppInstaller::Result::OK);
403   ScopedTzipInterface interface(pkgid);
404   ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
405
406   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
407   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/VERSION", "2\n"));
408   ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
409 }
410
411 TEST_F(SmokeTest, InstallationMode_Rollback_Hybrid) {
412   bf::path path = kSmokePackagesDirectory /
413       "InstallationMode_Rollback_Hybrid.wgt";
414   std::string pkgid = "smokehyb07";
415   std::string appid1 = "smokehyb07.web";
416   ASSERT_EQ(Install(path, PackageType::HYBRID, RequestResult::FAIL),
417             ci::AppInstaller::Result::ERROR);
418   ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid1}));
419 }
420
421 TEST_F(SmokeTest, UpdateMode_Rollback_Hybrid) {
422   bf::path path_old = kSmokePackagesDirectory /
423       "UpdateMode_Rollback_Hybrid.wgt";
424   bf::path path_new = kSmokePackagesDirectory /
425       "UpdateMode_Rollback_Hybrid_2.wgt";
426   std::string pkgid = "smokehyb08";
427   std::string appid1 = "smokehyb08.web";
428   ASSERT_EQ(Install(path_old, PackageType::HYBRID),
429             ci::AppInstaller::Result::OK);
430   AddDataFiles(pkgid, kTestUserId);
431   ASSERT_EQ(Install(path_new, PackageType::HYBRID,
432       RequestResult::FAIL), ci::AppInstaller::Result::ERROR);
433   ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
434
435   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
436   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/VERSION", "1\n"));
437   ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
438 }
439
440 TEST_F(SmokeTest, DeltaMode_Rollback_Hybrid) {
441   bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback_Hybrid.wgt";
442   bf::path delta_package = kSmokePackagesDirectory /
443       "DeltaMode_Rollback_Hybrid.delta";
444   std::string pkgid = "smokehyb11";
445   std::string appid1 = "smokehyb11.web";
446   ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK);
447   AddDataFiles(pkgid, kTestUserId);
448   ASSERT_EQ(Install(delta_package, PackageType::HYBRID, RequestResult::FAIL),
449             ci::AppInstaller::Result::ERROR);
450
451   ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
452   // Check delta modifications
453   bf::path root_path = GetPackageRoot(pkgid, kTestUserId);
454   ASSERT_TRUE(bf::exists(root_path / "res" / "wgt" / "DELETED"));
455   ASSERT_FALSE(bf::exists(root_path / "res" / "wgt" / "ADDED"));
456   ASSERT_TRUE(bf::exists(root_path / "lib" / "DELETED"));
457   ASSERT_FALSE(bf::exists(root_path / "lib" / "ADDED"));
458   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
459                                            "version 1\n"));
460   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/MODIFIED",
461                                            "version 1\n"));
462   ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
463 }
464
465 TEST_F(SmokeTest, MountInstallationMode_Rollback_Hybrid) {
466   bf::path path = kSmokePackagesDirectory /
467       "MountInstallationMode_Rollback_Hybrid.wgt";
468   std::string pkgid = "smokehyb09";
469   std::string appid1 = "smokehyb09.web";
470   ASSERT_EQ(MountInstall(path, PackageType::HYBRID, RequestResult::FAIL),
471       ci::AppInstaller::Result::ERROR);
472   ScopedTzipInterface interface(pkgid);
473   ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid1}));
474 }
475
476 TEST_F(SmokeTest, MountUpdateMode_Rollback_Hybrid) {
477   bf::path path_old = kSmokePackagesDirectory /
478       "MountUpdateMode_Rollback_Hybrid.wgt";
479   bf::path path_new = kSmokePackagesDirectory /
480       "MountUpdateMode_Rollback_Hybrid_2.wgt";
481   std::string pkgid = "smokehyb10";
482   std::string appid1 = "smokehyb10.web";
483   ASSERT_EQ(MountInstall(path_old, PackageType::HYBRID),
484             ci::AppInstaller::Result::OK);
485   AddDataFiles(pkgid, kTestUserId);
486   ASSERT_EQ(MountInstall(path_new, PackageType::HYBRID,
487       RequestResult::FAIL), ci::AppInstaller::Result::ERROR);
488   ScopedTzipInterface interface(pkgid);
489   ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
490
491   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
492   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/VERSION", "1\n"));
493   ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
494 }
495
496 TEST_F(SmokeTest, MountInstallationMode) {
497   bf::path path = kSmokePackagesDirectory / "MountInstallationMode.wgt";
498   std::string pkgid = "smokewgt28";
499   std::string appid = "smokewgt28.InstallationMode";
500   ASSERT_EQ(MountInstall(path, PackageType::WGT), ci::AppInstaller::Result::OK);
501   ScopedTzipInterface interface(pkgid);
502   ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
503 }
504
505 TEST_F(SmokeTest, MountUpdateMode) {
506   bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode.wgt";
507   bf::path path_new = kSmokePackagesDirectory / "MountUpdateMode_2.wgt";
508   std::string pkgid = "smokewgt29";
509   std::string appid = "smokewgt29.UpdateMode";
510   ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
511             ci::AppInstaller::Result::OK);
512   AddDataFiles(pkgid, kTestUserId);
513   ASSERT_EQ(MountInstall(path_new, PackageType::WGT),
514             ci::AppInstaller::Result::OK);
515   ScopedTzipInterface interface(pkgid);
516   ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
517
518   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
519   ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
520 }
521
522 TEST_F(SmokeTest, MountInstallationMode_Rollback) {
523   bf::path path =
524       kSmokePackagesDirectory / "MountInstallationMode_Rollback.wgt";
525   std::string pkgid = "smokewgt33";
526   std::string appid = "smokewgt33.web";
527   ASSERT_EQ(MountInstall(path, PackageType::WGT, RequestResult::FAIL),
528             ci::AppInstaller::Result::ERROR);
529   ScopedTzipInterface interface(pkgid);
530   ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid}));
531 }
532
533 TEST_F(SmokeTest, MountUpdateMode_Rollback) {
534   bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode_Rollback.wgt";
535   bf::path path_new =
536       kSmokePackagesDirectory / "MountUpdateMode_Rollback_2.wgt";
537   std::string pkgid = "smokewgt34";
538   std::string appid = "smokewgt34.web";
539   ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
540             ci::AppInstaller::Result::OK);
541   AddDataFiles(pkgid, kTestUserId);
542   ASSERT_EQ(MountInstall(path_new, PackageType::WGT,
543       RequestResult::FAIL), ci::AppInstaller::Result::ERROR);
544   ScopedTzipInterface interface(pkgid);
545   ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
546
547   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
548   ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
549 }
550
551 TEST_F(SmokeTest, UserDefinedPlugins) {
552   bf::path path = kSmokePackagesDirectory / "SimpleEchoPrivilege.wgt";
553   std::string pkgid = "smokewgt02";
554   std::string appid = "smokewgt02.SimpleEcho";
555   std::string call_privilege = "http://tizen.org/privilege/call";
556   std::string location_privilege = "http://tizen.org/privilege/location";
557   std::string power_privilege = "http://tizen.org/privilege/power";
558
559   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
560   ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
561   std::vector<std::string> res;
562   ASSERT_TRUE(ci::QueryPrivilegesForPkgId(pkgid, kTestUserId, &res));
563   ASSERT_TRUE(std::find(res.begin(), res.end(), call_privilege) != res.end());
564   ASSERT_TRUE(std::find(res.begin(), res.end(), location_privilege)
565           != res.end());
566   ASSERT_TRUE(std::find(res.begin(), res.end(), power_privilege) != res.end());
567 }
568
569 TEST_F(SmokeTest, InstallExternalMode) {
570   ASSERT_TRUE(CheckAvailableExternalPath());
571   bf::path path = kSmokePackagesDirectory / "InstallExternalMode.wgt";
572   std::string pkgid = "smokewgt35";
573   std::string appid = "smokewgt35.web";
574   ASSERT_EQ(InstallExternal(path, PackageType::WGT),
575       ci::AppInstaller::Result::OK);
576   ValidateExternalPackage(pkgid, {appid});
577 }
578
579 TEST_F(SmokeTest, MigrateLegacyExternalImageMode) {
580   ASSERT_TRUE(CheckAvailableExternalPath());
581   bf::path path =
582       kSmokePackagesDirectory / "MigrateLegacyExternalImageMode.wgt";
583   std::string pkgid = "smokewgt36";
584   std::string appid = "smokewgt36.web";
585   bf::path legacy_path = kSmokePackagesDirectory / kLegacyExtImageDir;
586   ASSERT_EQ(MigrateLegacyExternalImage(pkgid, path, legacy_path,
587       PackageType::WGT), ci::AppInstaller::Result::OK);
588   ValidateExternalPackage(pkgid, {appid});
589 }
590
591 TEST_F(PreloadSmokeTest, InstallationMode_Preload) {
592   ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
593   bf::path path = kSmokePackagesDirectory / "InstallationMode_Preload.wgt";
594   std::string pkgid = "smokewgt37";
595   std::string appid = "smokewgt37.InstallationModePreload";
596   ASSERT_EQ(InstallPreload(path, PackageType::WGT),
597             ci::AppInstaller::Result::OK);
598   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, true));
599 }
600
601 TEST_F(PreloadSmokeTest, UpdateMode_Preload) {
602   ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
603   bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Preload.wgt";
604   bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Preload2.wgt";
605   std::string pkgid = "smokewgt38";
606   std::string appid = "smokewgt38.UpdateModePreload";
607   ASSERT_EQ(InstallPreload(path_old, PackageType::WGT),
608             ci::AppInstaller::Result::OK);
609   AddDataFiles(pkgid, kTestUserId);
610   ASSERT_EQ(InstallPreload(path_new, PackageType::WGT),
611             ci::AppInstaller::Result::OK);
612   ASSERT_TRUE(ValidatePackage(pkgid, {appid}, true));
613
614   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2",
615                                            true));
616   ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
617 }
618
619 TEST_F(PreloadSmokeTest, DeinstallationMode_Preload) {
620   ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
621   bf::path path = kSmokePackagesDirectory / "DeinstallationMode_Preload.wgt";
622   std::string pkgid = "smokewgt39";
623   std::string appid = "smokewgt39.DeinstallationModePreload";
624   ASSERT_EQ(InstallPreload(path, PackageType::WGT),
625             ci::AppInstaller::Result::OK);
626   ASSERT_EQ(Uninstall(pkgid, PackageType::WGT, true),
627             ci::AppInstaller::Result::OK);
628   CheckPackageReadonlyNonExistance(pkgid, {appid});
629 }
630
631 TEST_F(SmokeTest, SharedRes24) {
632   bf::path path = kSmokePackagesDirectory / "SharedRes24.wgt";
633   std::string pkgid = "smokeSh2xx";
634   std::string appid = "smokeSh2xx.SharedRes24";
635   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
636   ValidatePackage(pkgid, {appid});
637   bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
638   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "NOT-SHARED-WGT"));  // NOLINT
639   ASSERT_FALSE(bf::exists(root_path / pkgid / "shared" / "res" / "NOT-SHARED-WGT"));  // NOLINT
640 }
641
642 TEST_F(SmokeTest, SharedRes30) {
643   bf::path path = kSmokePackagesDirectory / "SharedRes30.wgt";
644   std::string pkgid = "smokeSh3xx";
645   std::string appid = "smokeSh3xx.SharedRes30";
646   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
647   ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
648   bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
649   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT"));  // NOLINT
650   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "shared" / "res" / "SHARED-WGT"));  // NOLINT
651 }
652
653 TEST_F(SmokeTest, SharedRes30Delta) {
654   bf::path path = kSmokePackagesDirectory / "SharedRes30Delta.wgt";
655   bf::path delta_package = kSmokePackagesDirectory / "SharedRes30Delta.delta";
656   std::string pkgid = "smokeSh3De";
657   std::string appid = "smokeSh3De.SharedRes30Delta";
658   ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::WGT),
659             ci::AppInstaller::Result::OK);
660   ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
661   // Check delta modifications
662   bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
663   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-2"));  // NOLINT
664   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "shared" / "res" / "SHARED-WGT-2"));  // NOLINT
665   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-1"));  // NOLINT
666   ASSERT_FALSE(bf::exists(root_path / pkgid / "shared" / "res" / "SHARED-WGT-1"));  // NOLINT
667 }
668
669 TEST_F(SmokeTest, SharedRes30Hybrid) {
670   bf::path path = kSmokePackagesDirectory / "SharedRes30Hybrid.wgt";
671   std::string pkgid = "smokeSh3Hy";
672   std::string appid1 = "smokeSh3Hy.SharedRes30Hybrid";
673   std::string appid2 = "sharedres30hybridserivce";
674   ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK);
675   ASSERT_TRUE(ValidatePackage(pkgid, {appid1, appid2}));
676   bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
677   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT"));  // NOLINT
678   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "shared" / "res" / "SHARED-WGT"));  // NOLINT
679   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "shared" / "res" / "SHARED-TPK"));  // NOLINT
680   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-TPK"));  // NOLINT
681 }
682
683 TEST_F(SmokeTest, SharedRes30HybridDelta) {
684   bf::path path = kSmokePackagesDirectory / "SharedRes30HybridDelta.wgt";
685   bf::path delta_package = kSmokePackagesDirectory /
686       "SharedRes30HybridDelta.delta";
687   std::string pkgid = "smokeSh3HD";
688   std::string appid1 = "smokeSh3HD.SharedRes30HybridDelta";
689   std::string appid2 = "sharedres30hybriddeltaserivce";
690   ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::HYBRID),
691             ci::AppInstaller::Result::OK);
692   ASSERT_TRUE(ValidatePackage(pkgid, {appid1, appid2}));
693   // Check delta modifications
694   bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
695   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-2"));  // NOLINT
696   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "shared" / "res" / "SHARED-WGT-2"));  // NOLINT
697   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "shared" / "res" / "SHARED-TPK-2"));  // NOLINT
698   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-TPK-2"));  // NOLINT
699   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-1"));  // NOLINT
700   ASSERT_FALSE(bf::exists(root_path / pkgid / "shared" / "res" / "SHARED-WGT-1"));  // NOLINT
701 }
702
703 }  // namespace common_installer
704
705 int main(int argc,  char** argv) {
706   ci::RequestMode request_mode = ParseRequestMode(argc, argv);
707   if (getuid() != 0 || request_mode != ci::RequestMode::GLOBAL) {
708     std::cout << "Skip tests for preload request" << std::endl;
709     ::testing::GTEST_FLAG(filter) = "SmokeTest.*";
710   }
711   testing::InitGoogleTest(&argc, argv);
712   env = testing::AddGlobalTestEnvironment(
713       new common_installer::SmokeEnvironment(request_mode));
714   signal(SIGINT, signalHandler);
715   signal(SIGSEGV, signalHandler);
716   return RUN_ALL_TESTS();
717 }