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 RemoveAllRecoveryFiles();
111 ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
112 AddDataFiles(pkgid, kTestUserId);
113 std::vector<std::string> args =
114 {"", "-i", path_new.string(), "-u", kTestUserIdStr.c_str()};
115 CrashAfterEachStep(args, [=](int step) -> bool {
117 bf::path recovery_file = FindRecoveryFile();
118 EXTENDED_ASSERT_FALSE(recovery_file.empty());
119 EXTENDED_ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
120 ci::AppInstaller::Result::OK);
121 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
123 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
124 "res/wgt/VERSION", "1\n"));
125 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
131 TEST_F(SmokeTest, RecoveryMode_ForMountInstall) {
132 bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForMountInstall.wgt";
133 std::string pkgid = "smokewgt31";
134 std::string appid = "smokewgt31.RecoveryModeForMountInstall";
135 RemoveAllRecoveryFiles();
136 std::vector<std::string> args =
137 {"", "-w", path.string(), "-u", kTestUserIdStr.c_str()};
138 CrashAfterEachStep(args, [=](int step) -> bool {
140 bf::path recovery_file = FindRecoveryFile();
141 EXTENDED_ASSERT_FALSE(recovery_file.empty());
142 EXTENDED_ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
143 ci::AppInstaller::Result::OK);
144 EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid}));
150 TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) {
152 kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate.wgt";
154 kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate_2.wgt";
155 std::string pkgid = "smokewgt32";
156 std::string appid = "smokewgt32.RecoveryModeForMountUpdate";
157 RemoveAllRecoveryFiles();
158 ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
159 ci::AppInstaller::Result::OK);
160 AddDataFiles(pkgid, kTestUserId);
161 std::vector<std::string> args =
162 {"", "-w", path_new.string(), "-u", kTestUserIdStr.c_str()};
163 CrashAfterEachStep(args, [=](int step) -> bool {
165 // Filesystem may be mounted after crash
166 ScopedTzipInterface poweroff_unmount_interface(pkgid);
167 poweroff_unmount_interface.Release();
169 bf::path recovery_file = FindRecoveryFile();
170 EXTENDED_ASSERT_FALSE(recovery_file.empty());
171 EXTENDED_ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
172 ci::AppInstaller::Result::OK);
174 ScopedTzipInterface interface(pkgid);
175 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
176 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(
177 pkgid, "res/wgt/VERSION", "1\n"));
178 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
185 TEST_F(SmokeTest, InstallationMode_Rollback) {
186 bf::path path = kSmokePackagesDirectory / "InstallationMode_Rollback.wgt";
187 std::string pkgid = "smokewgt06";
188 std::string appid = "smokewgt06.InstallationModeRollback";
190 const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()};
191 TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
192 EXTENDED_ASSERT_EQ(Install(path, PackageType::WGT, RequestResult::FAIL),
193 ci::AppInstaller::Result::ERROR);
194 EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid}));
199 TEST_F(SmokeTest, UpdateMode_Rollback) {
200 bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Rollback.wgt";
201 bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Rollback_2.wgt";
202 std::string pkgid = "smokewgt07";
203 std::string appid = "smokewgt07.UpdateModeRollback";
204 ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
205 AddDataFiles(pkgid, kTestUserId);
207 {"", "-i", path_new.c_str(), "-u", kTestUserIdStr.c_str()};
208 TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
209 EXTENDED_ASSERT_EQ(Install(path_new, PackageType::WGT, RequestResult::FAIL),
210 ci::AppInstaller::Result::ERROR);
211 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
213 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
214 "res/wgt/VERSION", "1\n"));
215 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
220 TEST_F(SmokeTest, DeltaMode_Rollback) {
221 bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback.wgt";
222 bf::path delta_package = kSmokePackagesDirectory / "DeltaMode_Rollback.delta";
223 std::string pkgid = "smokewgt01";
224 std::string appid = "smokewgt01.DeltaMode";
225 ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
226 AddDataFiles(pkgid, kTestUserId);
228 {"", "-i", delta_package.c_str(), "-u", kTestUserIdStr.c_str()};
229 TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
230 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
231 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
233 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
234 EXTENDED_ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
236 EXTENDED_ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
242 TEST_F(SmokeTest, InstallationMode_Rollback_Hybrid) {
243 bf::path path = kSmokePackagesDirectory /
244 "InstallationMode_Rollback_Hybrid.wgt";
245 std::string pkgid = "smokehyb07";
246 std::string appid1 = "smokehyb07.web";
247 const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()};
248 TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
249 EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid1}));
251 }, PackageType::HYBRID);
254 TEST_F(SmokeTest, UpdateMode_Rollback_Hybrid) {
255 bf::path path_old = kSmokePackagesDirectory /
256 "UpdateMode_Rollback_Hybrid.wgt";
257 bf::path path_new = kSmokePackagesDirectory /
258 "UpdateMode_Rollback_Hybrid_2.wgt";
259 std::string pkgid = "smokehyb08";
260 std::string appid1 = "smokehyb08.web";
261 ASSERT_EQ(Install(path_old, PackageType::HYBRID),
262 ci::AppInstaller::Result::OK);
263 AddDataFiles(pkgid, kTestUserId);
265 {"", "-i", path_new.c_str(), "-u", kTestUserIdStr.c_str()};
266 TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
267 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
269 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
270 "res/wgt/VERSION", "1\n"));
271 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
272 "lib/VERSION", "1\n"));
273 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
275 }, PackageType::HYBRID);
278 TEST_F(SmokeTest, DeltaMode_Rollback_Hybrid) {
279 bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback_Hybrid.wgt";
280 bf::path delta_package = kSmokePackagesDirectory /
281 "DeltaMode_Rollback_Hybrid.delta";
282 std::string pkgid = "smokehyb11";
283 std::string appid1 = "smokehyb11.web";
284 ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK);
285 AddDataFiles(pkgid, kTestUserId);
286 const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()};
287 TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
288 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
289 // Check delta modifications
290 bf::path root_path = GetPackageRoot(pkgid, kTestUserId);
291 EXTENDED_ASSERT_TRUE(bf::exists(root_path / "res" / "wgt" / "DELETED"));
292 EXTENDED_ASSERT_FALSE(bf::exists(root_path / "res" / "wgt" / "ADDED"));
293 EXTENDED_ASSERT_TRUE(bf::exists(root_path / "lib" / "DELETED"));
294 EXTENDED_ASSERT_FALSE(bf::exists(root_path / "lib" / "ADDED"));
295 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
297 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/MODIFIED",
299 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
304 TEST_F(SmokeTest, MountInstallationMode_Rollback_Hybrid) {
305 bf::path path = kSmokePackagesDirectory /
306 "MountInstallationMode_Rollback_Hybrid.wgt";
307 std::string pkgid = "smokehyb09";
308 std::string appid1 = "smokehyb09.web";
309 const char* argv[] = {"", "-w", path.c_str(), "-u", kTestUserIdStr.c_str()};
310 TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
311 ScopedTzipInterface interface(pkgid);
312 EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid1}));
314 }, PackageType::HYBRID);
317 TEST_F(SmokeTest, MountUpdateMode_Rollback_Hybrid) {
318 bf::path path_old = kSmokePackagesDirectory /
319 "MountUpdateMode_Rollback_Hybrid.wgt";
320 bf::path path_new = kSmokePackagesDirectory /
321 "MountUpdateMode_Rollback_Hybrid_2.wgt";
322 std::string pkgid = "smokehyb10";
323 std::string appid1 = "smokehyb10.web";
324 ASSERT_EQ(MountInstall(path_old, PackageType::HYBRID),
325 ci::AppInstaller::Result::OK);
326 AddDataFiles(pkgid, kTestUserId);
328 {"", "-w", path_new.c_str(), "-u", kTestUserIdStr.c_str()};
329 TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
330 ScopedTzipInterface interface(pkgid);
331 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
333 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
334 "res/wgt/VERSION", "1\n"));
335 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
336 "lib/VERSION", "1\n"));
337 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
342 TEST_F(SmokeTest, MountInstallationMode_Rollback) {
344 kSmokePackagesDirectory / "MountInstallationMode_Rollback.wgt";
345 std::string pkgid = "smokewgt33";
346 std::string appid = "smokewgt33.web";
347 const char* argv[] = {"", "-w", path.c_str(), "-u", kTestUserIdStr.c_str()};
348 TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
349 ScopedTzipInterface interface(pkgid);
350 EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid}));
355 TEST_F(SmokeTest, MountUpdateMode_Rollback) {
356 bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode_Rollback.wgt";
358 kSmokePackagesDirectory / "MountUpdateMode_Rollback_2.wgt";
359 std::string pkgid = "smokewgt34";
360 std::string appid = "smokewgt34.web";
361 ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
362 ci::AppInstaller::Result::OK);
363 AddDataFiles(pkgid, kTestUserId);
365 {"", "-w", path_new.c_str(), "-u", kTestUserIdStr.c_str()};
366 TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
367 EXTENDED_ASSERT_EQ(MountInstall(path_new, PackageType::WGT,
368 RequestResult::FAIL), ci::AppInstaller::Result::ERROR);
369 ScopedTzipInterface interface(pkgid);
370 EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
372 EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
373 "res/wgt/VERSION", "1\n"));
374 EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
379 } // namespace common_installer
381 int main(int argc, char** argv) {
382 ci::RequestMode request_mode = ParseRequestMode(argc, argv);
383 if (getuid() != 0 || request_mode != ci::RequestMode::GLOBAL) {
384 std::cout << "Skip tests for preload request" << std::endl;
385 ::testing::GTEST_FLAG(filter) = "SmokeTest.*";
387 testing::InitGoogleTest(&argc, argv);
388 env = testing::AddGlobalTestEnvironment(
389 new common_installer::SmokeEnvironment(request_mode));
390 signal(SIGINT, signalHandler);
391 signal(SIGSEGV, signalHandler);
392 return RUN_ALL_TESTS();