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>
8 #include <smoke_tests/common/smoke_utils.h>
10 #include <gtest/gtest.h>
11 #include <gtest/gtest-death-test.h>
13 #include "smoke_tests/wgt_smoke_utils.h"
15 namespace ci = common_installer;
17 namespace smoke_test {
19 class SmokeEnvironment : public testing::Environment {
21 explicit SmokeEnvironment(ci::RequestMode mode) {\
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));
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());
46 ci::RequestMode request_mode_;
47 std::vector<bf::path> backups_;
50 } // namespace smoke_test
54 smoke_test::SmokeEnvironment *env = nullptr;
55 void signalHandler(int signum) {
62 namespace smoke_test {
64 class SmokeTest : public testing::Test {
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;
72 WgtBackendInterface backend;
73 TestParameters params;
76 class PreloadSmokeTest : public testing::Test {
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;
84 WgtBackendInterface backend;
85 TestParameters params;
88 class HybridSmokeTest : public testing::Test {
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;
96 HybridBackendInterface backend;
97 TestParameters params;
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";
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 {
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);
122 EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
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 std::string pkgid = "smokewgt10";
133 std::string appid = "smokewgt10.RecoveryModeForUpdate";
134 RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
135 ASSERT_EQ(backend.InstallWithSubprocess(path_old),
136 BackendInterface::SubProcessResult::SUCCESS);
137 std::vector<bf::path> added_files;
138 AddDataFiles(pkgid, params.test_user.uid, &added_files);
139 FileInfoCollector expected_file_status_old(pkgid, params);
140 ASSERT_TRUE(expected_file_status_old.Init());
141 ASSERT_EQ(backend.InstallWithSubprocess(path_new),
142 BackendInterface::SubProcessResult::SUCCESS);
143 FileInfoCollector expected_file_status_new(pkgid, params);
144 ASSERT_TRUE(expected_file_status_new.Init());
145 ASSERT_EQ(backend.UninstallWithSubprocess(pkgid),
146 BackendInterface::SubProcessResult::SUCCESS);
147 ASSERT_EQ(backend.InstallWithSubprocess(path_old),
148 BackendInterface::SubProcessResult::SUCCESS);
149 AddDataFiles(pkgid, params.test_user.uid);
151 std::string test_user_str = std::to_string(params.test_user.uid);
152 std::vector<std::string> args =
153 {"", "-i", path_new.string(), "-u", test_user_str.c_str()};
154 backend.CrashAfterEachStep(&args, [&](int step) -> bool {
156 bf::path recovery_file = FindRecoveryFile("/wgt-recovery",
157 params.test_user.uid);
158 EXTENDED_ASSERT_FALSE(recovery_file.empty());
159 std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
160 GetRecoverFileInfo(recovery_file);
161 EXTENDED_ASSERT_EQ(backend.RecoverWithSubprocess(recovery_file),
162 BackendInterface::SubProcessResult::SUCCESS);
163 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
165 std::string version = recovery_info->cleanup() ? "2\n" :"1\n";
166 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
167 "res/wgt/VERSION", version, params));
168 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
169 FileInfoCollector new_file_status(pkgid, params);
170 EXTENDED_ASSERT_TRUE(new_file_status.Init());
172 if (recovery_info->cleanup()) {
173 EXTENDED_ASSERT_TRUE(
174 expected_file_status_new.IsEqual(new_file_status, &added_files));
175 EXTENDED_ASSERT_EQ(backend.UninstallWithSubprocess(pkgid),
176 BackendInterface::SubProcessResult::SUCCESS);
177 EXTENDED_ASSERT_EQ(backend.InstallWithSubprocess(path_old),
178 BackendInterface::SubProcessResult::SUCCESS);
179 AddDataFiles(pkgid, params.test_user.uid);
181 EXTENDED_ASSERT_TRUE(
182 expected_file_status_old.IsEqual(new_file_status, &added_files));
189 TEST_F(SmokeTest, RecoveryMode_ForDelta) {
190 bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForDelta.wgt";
191 bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForDelta.delta";
192 std::string pkgid = "smokewgt30";
193 std::string appid = "smokewgt30.RecoveryModeForDelta";
194 RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
195 ASSERT_EQ(BackendInterface::SubProcessResult::SUCCESS,
196 backend.InstallWithSubprocess(path_old));
197 std::vector<bf::path> added_files;
198 AddDataFiles(pkgid, params.test_user.uid, &added_files);
199 FileInfoCollector expected_file_status_old(pkgid, params);
200 ASSERT_TRUE(expected_file_status_old.Init());
201 ASSERT_EQ(backend.InstallWithSubprocess(path_new),
202 BackendInterface::SubProcessResult::SUCCESS);
203 FileInfoCollector expected_file_status_new(pkgid, params);
204 ASSERT_TRUE(expected_file_status_new.Init());
205 ASSERT_EQ(backend.UninstallWithSubprocess(pkgid),
206 BackendInterface::SubProcessResult::SUCCESS);
207 ASSERT_EQ(backend.InstallWithSubprocess(path_old),
208 BackendInterface::SubProcessResult::SUCCESS);
209 AddDataFiles(pkgid, params.test_user.uid);
210 std::string test_user_str = std::to_string(params.test_user.uid);
211 std::vector<std::string> args =
212 {"", "-i", path_new.string(), "-u", test_user_str.c_str()};
213 backend.CrashAfterEachStep(&args, [&](int step) -> bool {
215 bf::path recovery_file = FindRecoveryFile("/wgt-recovery",
216 params.test_user.uid);
217 EXTENDED_ASSERT_FALSE(recovery_file.empty());
218 std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
219 GetRecoverFileInfo(recovery_file);
220 EXTENDED_ASSERT_EQ(backend.RecoverWithSubprocess(recovery_file),
221 BackendInterface::SubProcessResult::SUCCESS);
222 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
223 std::string contents = recovery_info->cleanup() ? "2\n" : "1\n";
225 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
226 "res/wgt/VERSION", contents, params));
227 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
228 FileInfoCollector new_file_status(pkgid, params);
229 EXTENDED_ASSERT_TRUE(new_file_status.Init());
231 if (recovery_info->cleanup()) {
232 EXTENDED_ASSERT_TRUE(
233 expected_file_status_new.IsEqual(new_file_status, &added_files));
234 EXTENDED_ASSERT_EQ(backend.UninstallWithSubprocess(pkgid),
235 BackendInterface::SubProcessResult::SUCCESS);
236 EXTENDED_ASSERT_EQ(backend.InstallWithSubprocess(path_old),
237 BackendInterface::SubProcessResult::SUCCESS);
238 AddDataFiles(pkgid, params.test_user.uid);
240 EXTENDED_ASSERT_TRUE(
241 expected_file_status_old.IsEqual(new_file_status, &added_files));
248 TEST_F(SmokeTest, RecoveryMode_ForMountInstall) {
249 bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForMountInstall.wgt";
250 std::string pkgid = "smokewgt31";
251 std::string appid = "smokewgt31.RecoveryModeForMountInstall";
252 RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
253 std::string test_user_str = std::to_string(params.test_user.uid);
254 std::vector<std::string> args =
255 {"", "-w", path.string(), "-u", test_user_str.c_str()};
256 backend.CrashAfterEachStep(&args, [&](int step) -> bool {
258 bf::path recovery_file = FindRecoveryFile("/wgt-recovery",
259 params.test_user.uid);
260 EXTENDED_ASSERT_FALSE(recovery_file.empty());
261 std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
262 GetRecoverFileInfo(recovery_file);
263 EXTENDED_ASSERT_EQ(backend.RecoverWithSubprocess(recovery_file),
264 BackendInterface::SubProcessResult::SUCCESS);
265 ScopedTzipInterface interface(pkgid, params.test_user.uid);
266 if (recovery_info->cleanup()) {
267 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
268 EXTENDED_ASSERT_EQ(backend.UninstallWithSubprocess(pkgid),
269 BackendInterface::SubProcessResult::SUCCESS);
271 EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
278 TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) {
280 kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate.wgt";
282 kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate_2.wgt";
283 std::string pkgid = "smokewgt32";
284 std::string appid = "smokewgt32.RecoveryModeForMountUpdate";
285 RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
286 ASSERT_EQ(backend.MountInstallWithSubprocess(path_old),
287 BackendInterface::SubProcessResult::SUCCESS);
288 std::vector<bf::path> added_files;
289 AddDataFiles(pkgid, params.test_user.uid, &added_files);
290 FileInfoCollector expected_file_status_old(pkgid, params);
291 ASSERT_TRUE(expected_file_status_old.Init());
292 ASSERT_EQ(backend.MountInstallWithSubprocess(path_new),
293 BackendInterface::SubProcessResult::SUCCESS);
294 FileInfoCollector expected_file_status_new(pkgid, params);
295 ASSERT_TRUE(expected_file_status_new.Init());
296 ASSERT_EQ(backend.UninstallWithSubprocess(pkgid),
297 BackendInterface::SubProcessResult::SUCCESS);
298 ASSERT_EQ(backend.MountInstallWithSubprocess(path_old),
299 BackendInterface::SubProcessResult::SUCCESS);
300 AddDataFiles(pkgid, params.test_user.uid);
301 std::string test_user_str = std::to_string(params.test_user.uid);
302 std::vector<std::string> args =
303 {"", "-w", path_new.string(), "-u", test_user_str.c_str()};
304 backend.CrashAfterEachStep(&args, [&](int step) -> bool {
306 // Filesystem may be mounted after crash
307 ScopedTzipInterface poweroff_unmount_interface(pkgid,
308 params.test_user.uid);
309 poweroff_unmount_interface.Release();
311 bf::path recovery_file = FindRecoveryFile("/wgt-recovery",
312 params.test_user.uid);
313 EXTENDED_ASSERT_FALSE(recovery_file.empty());
314 std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
315 GetRecoverFileInfo(recovery_file);
316 EXTENDED_ASSERT_EQ(backend.RecoverWithSubprocess(recovery_file),
317 BackendInterface::SubProcessResult::SUCCESS);
319 ScopedTzipInterface interface(pkgid, params.test_user.uid);
320 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
321 std::string version = recovery_info->cleanup() ? "2\n" : "1\n";
322 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(
323 pkgid, "res/wgt/VERSION", version, params));
324 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
326 FileInfoCollector new_file_status(pkgid, params);
327 EXTENDED_ASSERT_TRUE(new_file_status.Init());
328 if (recovery_info->cleanup()) {
329 EXTENDED_ASSERT_TRUE(
330 expected_file_status_new.IsEqual(new_file_status, &added_files));
331 EXTENDED_ASSERT_EQ(backend.UninstallWithSubprocess(pkgid),
332 BackendInterface::SubProcessResult::SUCCESS);
333 EXTENDED_ASSERT_EQ(backend.MountInstallWithSubprocess(path_old),
334 BackendInterface::SubProcessResult::SUCCESS);
335 AddDataFiles(pkgid, params.test_user.uid);
337 EXTENDED_ASSERT_TRUE(
338 expected_file_status_old.IsEqual(new_file_status, &added_files));
346 TEST_F(SmokeTest, InstallationMode_Rollback) {
347 bf::path path = kSmokePackagesDirectory / "InstallationMode_Rollback.wgt";
348 std::string pkgid = "smokewgt06";
349 std::string appid = "smokewgt06.InstallationModeRollback";
351 std::string test_user_str = std::to_string(params.test_user.uid);
352 const char* argv[] = {"", "-i", path.c_str(), "-u", test_user_str.c_str()};
353 backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
354 EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
359 TEST_F(SmokeTest, UpdateMode_Rollback) {
360 bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Rollback.wgt";
361 bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Rollback_2.wgt";
362 std::string pkgid = "smokewgt07";
363 std::string appid = "smokewgt07.UpdateModeRollback";
364 ASSERT_EQ(backend.InstallWithSubprocess(path_old),
365 BackendInterface::SubProcessResult::SUCCESS);
366 std::vector<bf::path> added_files;
367 AddDataFiles(pkgid, params.test_user.uid, &added_files);
368 FileInfoCollector expected_file_status(pkgid, params);
369 ASSERT_TRUE(expected_file_status.Init());
370 std::string test_user_str = std::to_string(params.test_user.uid);
372 {"", "-i", path_new.c_str(), "-u", test_user_str.c_str()};
373 backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
374 FileInfoCollector new_file_status(pkgid, params);
375 EXTENDED_ASSERT_TRUE(new_file_status.Init());
376 EXTENDED_ASSERT_TRUE(
377 expected_file_status.IsEqual(new_file_status, &added_files));
378 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
380 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
381 "res/wgt/VERSION", "1\n", params));
382 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
387 TEST_F(SmokeTest, DeltaMode_Rollback) {
388 bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback.wgt";
389 bf::path delta_package = kSmokePackagesDirectory / "DeltaMode_Rollback.delta";
390 std::string pkgid = "smokewgt01";
391 std::string appid = "smokewgt01.DeltaMode";
392 ASSERT_EQ(backend.InstallWithSubprocess(path),
393 BackendInterface::SubProcessResult::SUCCESS);
394 std::vector<bf::path> added_files;
395 AddDataFiles(pkgid, params.test_user.uid, &added_files);
396 FileInfoCollector expected_file_status(pkgid, params);
397 ASSERT_TRUE(expected_file_status.Init());
398 std::string test_user_str = std::to_string(params.test_user.uid);
400 {"", "-i", delta_package.c_str(), "-u", test_user_str.c_str()};
401 backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
402 FileInfoCollector new_file_status(pkgid, params);
403 EXTENDED_ASSERT_TRUE(new_file_status.Init());
404 EXTENDED_ASSERT_TRUE(
405 expected_file_status.IsEqual(new_file_status, &added_files));
406 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
407 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
408 "version 1\n", params));
409 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
410 EXTENDED_ASSERT_TRUE(bf::exists(GetPackageRoot(
411 pkgid, params.test_user.uid) / "res/wgt/DELETED"));
412 EXTENDED_ASSERT_FALSE(bf::exists(GetPackageRoot(
413 pkgid, params.test_user.uid) / "res/wgt/ADDED"));
418 TEST_F(HybridSmokeTest, InstallationMode_Rollback) {
419 bf::path path = kSmokePackagesDirectory /
420 "InstallationMode_Rollback_Hybrid.wgt";
421 std::string pkgid = "smokehyb07";
422 std::string appid1 = "smokehyb07.web";
423 std::string test_user_str = std::to_string(params.test_user.uid);
424 const char* argv[] = {"", "-i", path.c_str(), "-u", test_user_str.c_str()};
425 backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
426 EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
431 TEST_F(HybridSmokeTest, UpdateMode_Rollback) {
432 bf::path path_old = kSmokePackagesDirectory /
433 "UpdateMode_Rollback_Hybrid.wgt";
434 bf::path path_new = kSmokePackagesDirectory /
435 "UpdateMode_Rollback_Hybrid_2.wgt";
436 std::string pkgid = "smokehyb08";
437 std::string appid1 = "smokehyb08.web";
438 ASSERT_EQ(backend.InstallWithSubprocess(path_old),
439 BackendInterface::SubProcessResult::SUCCESS);
440 std::vector<bf::path> added_files;
441 AddDataFiles(pkgid, params.test_user.uid, &added_files);
442 FileInfoCollector expected_file_status(pkgid, params);
443 ASSERT_TRUE(expected_file_status.Init());
444 std::string test_user_str = std::to_string(params.test_user.uid);
446 {"", "-i", path_new.c_str(), "-u", test_user_str.c_str()};
447 backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
448 FileInfoCollector new_file_status(pkgid, params);
449 EXTENDED_ASSERT_TRUE(new_file_status.Init());
450 EXTENDED_ASSERT_TRUE(
451 expected_file_status.IsEqual(new_file_status, &added_files));
452 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid1}, params));
454 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
455 "res/wgt/VERSION", "1\n", params));
456 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
457 "lib/VERSION", "1\n", params));
458 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
463 TEST_F(HybridSmokeTest, DeltaMode_Rollback_Hybrid) {
464 bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback_Hybrid.wgt";
465 bf::path delta_package = kSmokePackagesDirectory /
466 "DeltaMode_Rollback_Hybrid.delta";
467 std::string pkgid = "smokehyb11";
468 std::string appid1 = "smokehyb11.web";
469 ASSERT_EQ(backend.InstallWithSubprocess(path),
470 BackendInterface::SubProcessResult::SUCCESS);
471 std::vector<bf::path> added_files;
472 AddDataFiles(pkgid, params.test_user.uid, &added_files);
473 FileInfoCollector expected_file_status(pkgid, params);
474 ASSERT_TRUE(expected_file_status.Init());
475 std::string test_user_str = std::to_string(params.test_user.uid);
476 const char* argv[] = {"", "-i", path.c_str(), "-u", test_user_str.c_str()};
477 backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
478 FileInfoCollector new_file_status(pkgid, params);
479 EXTENDED_ASSERT_TRUE(new_file_status.Init());
480 EXTENDED_ASSERT_TRUE(
481 expected_file_status.IsEqual(new_file_status, &added_files));
482 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid1}, params));
483 // Check delta modifications
484 bf::path root_path = GetPackageRoot(pkgid, params.test_user.uid);
485 EXTENDED_ASSERT_TRUE(bf::exists(root_path / "res" / "wgt" / "DELETED"));
486 EXTENDED_ASSERT_FALSE(bf::exists(root_path / "res" / "wgt" / "ADDED"));
487 EXTENDED_ASSERT_TRUE(bf::exists(root_path / "lib" / "DELETED"));
488 EXTENDED_ASSERT_FALSE(bf::exists(root_path / "lib" / "ADDED"));
489 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
490 "version 1\n", params));
491 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/MODIFIED",
492 "version 1\n", params));
493 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
498 TEST_F(HybridSmokeTest, MountInstallationMode_Rollback) {
499 bf::path path = kSmokePackagesDirectory /
500 "MountInstallationMode_Rollback_Hybrid.wgt";
501 std::string pkgid = "smokehyb09";
502 std::string appid1 = "smokehyb09.web";
503 std::string test_user_str = std::to_string(params.test_user.uid);
504 const char* argv[] = {"", "-w", path.c_str(), "-u", test_user_str.c_str()};
505 backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
506 ScopedTzipInterface interface(pkgid, params.test_user.uid);
507 EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
512 TEST_F(HybridSmokeTest, MountUpdateMode_Rollback) {
513 bf::path path_old = kSmokePackagesDirectory /
514 "MountUpdateMode_Rollback_Hybrid.wgt";
515 bf::path path_new = kSmokePackagesDirectory /
516 "MountUpdateMode_Rollback_Hybrid_2.wgt";
517 std::string pkgid = "smokehyb10";
518 std::string appid1 = "smokehyb10.web";
519 ASSERT_EQ(backend.MountInstallWithSubprocess(path_old),
520 BackendInterface::SubProcessResult::SUCCESS);
521 std::vector<bf::path> added_files;
522 AddDataFiles(pkgid, params.test_user.uid, &added_files);
523 FileInfoCollector expected_file_status(pkgid, params);
524 ASSERT_TRUE(expected_file_status.Init());
525 std::string test_user_str = std::to_string(params.test_user.uid);
527 {"", "-w", path_new.c_str(), "-u", test_user_str.c_str()};
528 backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
529 FileInfoCollector new_file_status(pkgid, params);
530 EXTENDED_ASSERT_TRUE(new_file_status.Init());
531 EXTENDED_ASSERT_TRUE(
532 expected_file_status.IsEqual(new_file_status, &added_files));
533 ScopedTzipInterface interface(pkgid, params.test_user.uid);
534 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid1}, params));
536 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
537 "res/wgt/VERSION", "1\n", params));
538 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
539 "lib/VERSION", "1\n", params));
540 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
545 TEST_F(SmokeTest, MountInstallationMode_Rollback) {
547 kSmokePackagesDirectory / "MountInstallationMode_Rollback.wgt";
548 std::string pkgid = "smokewgt33";
549 std::string appid = "smokewgt33.web";
550 std::string test_user_str = std::to_string(params.test_user.uid);
551 const char* argv[] = {"", "-w", path.c_str(), "-u", test_user_str.c_str()};
552 backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
553 ScopedTzipInterface interface(pkgid, params.test_user.uid);
554 EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
559 TEST_F(SmokeTest, MountUpdateMode_Rollback) {
560 bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode_Rollback.wgt";
562 kSmokePackagesDirectory / "MountUpdateMode_Rollback_2.wgt";
563 std::string pkgid = "smokewgt34";
564 std::string appid = "smokewgt34.web";
565 ASSERT_EQ(backend.MountInstallWithSubprocess(path_old),
566 BackendInterface::SubProcessResult::SUCCESS);
567 std::vector<bf::path> added_files;
568 AddDataFiles(pkgid, params.test_user.uid, &added_files);
569 FileInfoCollector expected_file_status(pkgid, params);
570 ASSERT_TRUE(expected_file_status.Init());
571 std::string test_user_str = std::to_string(params.test_user.uid);
573 {"", "-w", path_new.c_str(), "-u", test_user_str.c_str()};
574 backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
575 FileInfoCollector new_file_status(pkgid, params);
576 EXTENDED_ASSERT_TRUE(new_file_status.Init());
577 EXTENDED_ASSERT_TRUE(
578 expected_file_status.IsEqual(new_file_status, &added_files));
579 ScopedTzipInterface interface(pkgid, params.test_user.uid);
580 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
582 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
583 "res/wgt/VERSION", "1\n", params));
584 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
589 TEST_F(PreloadSmokeTest, RecoveryMode_ForReadonlyUpdateInstall) {
590 ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
591 bf::path path_old = kSmokePackagesDirectory /
592 "RecoveryMode_ForReadonlyUpdateInstall.wgt";
593 bf::path path_new = kSmokePackagesDirectory /
594 "RecoveryMode_ForReadonlyUpdateInstall_2.wgt";
595 std::string pkgid = "smokewgt51";
596 std::string appid = "smokewgt51.RecoveryModeForReadonlyUpdateInstall";
597 RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
598 ASSERT_EQ(backend.InstallPreloadWithSubprocess(path_old),
599 BackendInterface::SubProcessResult::SUCCESS);
600 std::vector<bf::path> added_files;
601 AddDataFiles(pkgid, params.test_user.uid, &added_files);
602 FileInfoCollector expected_file_status_old(pkgid, params);
603 ASSERT_TRUE(expected_file_status_old.Init());
604 ASSERT_EQ(backend.InstallWithSubprocess(path_new),
605 BackendInterface::SubProcessResult::SUCCESS);
606 params.is_readonly = false;
607 FileInfoCollector expected_file_status_new(pkgid, params);
608 ASSERT_TRUE(expected_file_status_new.Init());
609 params.is_readonly = true;
610 ASSERT_EQ(backend.UninstallWithSubprocess(pkgid),
611 BackendInterface::SubProcessResult::SUCCESS);
612 AddDataFiles(pkgid, params.test_user.uid);
613 std::string test_uid_str = std::to_string(params.test_user.uid);
614 std::vector<std::string> args =
615 {"", "-i", path_new.string(), "-u", test_uid_str.c_str()};
616 backend.CrashAfterEachStep(&args, [&](int step) -> bool {
618 bf::path recovery_file = FindRecoveryFile("/wgt-recovery",
619 params.test_user.uid);
620 EXTENDED_ASSERT_FALSE(recovery_file.empty());
621 std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
622 GetRecoverFileInfo(recovery_file);
623 EXTENDED_ASSERT_EQ(backend.RecoverWithSubprocess(recovery_file),
624 BackendInterface::SubProcessResult::SUCCESS);
625 if (recovery_info->cleanup())
626 params.is_readonly = false;
627 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
629 std::string version = recovery_info->cleanup() ? "2\n" :"1\n";
630 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
631 "res/wgt/VERSION", version, params));
632 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
633 FileInfoCollector new_file_status(pkgid, params);
634 EXTENDED_ASSERT_TRUE(new_file_status.Init());
636 if (recovery_info->cleanup()) {
637 EXTENDED_ASSERT_TRUE(
638 expected_file_status_new.IsEqual(new_file_status, &added_files));
639 EXTENDED_ASSERT_EQ(backend.UninstallWithSubprocess(pkgid),
640 BackendInterface::SubProcessResult::SUCCESS);
641 AddDataFiles(pkgid, params.test_user.uid);
643 EXTENDED_ASSERT_TRUE(
644 expected_file_status_old.IsEqual(new_file_status, &added_files));
651 } // namespace smoke_test
653 int main(int argc, char** argv) {
655 ci::RequestMode request_mode = smoke_test::ParseRequestMode(argc, argv);
656 if (getuid() != 0 || request_mode != ci::RequestMode::GLOBAL) {
657 std::cout << "Skip tests for preload request" << std::endl;
658 ::testing::GTEST_FLAG(filter) = "SmokeTest.*";
660 testing::InitGoogleTest(&argc, argv);
661 ::env = static_cast<smoke_test::SmokeEnvironment*>(
662 testing::AddGlobalTestEnvironment(
663 new smoke_test::SmokeEnvironment(request_mode)));
664 signal(SIGINT, ::signalHandler);
665 signal(SIGSEGV, ::signalHandler);
666 return RUN_ALL_TESTS();
668 std::cout << "Exception occurred during testing";