From e4c30576ca528430b844bb75c6f7c587e31b3c55 Mon Sep 17 00:00:00 2001 From: liaoxianyi Date: Tue, 14 Jan 2025 11:57:21 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ut=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxianyi --- services/flashd/daemon/commander.cpp | 2 + services/flashd/daemon/system_depend.cpp | 2 + services/flashd/daemon/update_commander.cpp | 5 ++- services/flashd/partition.h | 6 ++- test/unittest/flashd_test/flashd_unittest.cpp | 39 +++++++++++++++++++ 5 files changed, 52 insertions(+), 2 deletions(-) diff --git a/services/flashd/daemon/commander.cpp b/services/flashd/daemon/commander.cpp index d1be95eb..9cd2cc9c 100644 --- a/services/flashd/daemon/commander.cpp +++ b/services/flashd/daemon/commander.cpp @@ -37,6 +37,7 @@ void Commander::NotifyFail(CmdType type, const std::string &msg) const void Commander::UpdateProgress(CmdType type) const { +#ifndef UPDATER_UT if (!IsCallbackVaild()) { return; } @@ -56,6 +57,7 @@ void Commander::UpdateProgress(CmdType type) const } preProcess = currentProcess; callback_(type, UpdaterState::DOING, std::to_string(currentProcess)); +#endif } bool Commander::IsCallbackVaild() const diff --git a/services/flashd/daemon/system_depend.cpp b/services/flashd/daemon/system_depend.cpp index c8d702ec..6adf39d1 100644 --- a/services/flashd/daemon/system_depend.cpp +++ b/services/flashd/daemon/system_depend.cpp @@ -32,6 +32,7 @@ envirments namespace Hdc { namespace SystemDepend { +#ifndef UPDATER_UT bool SetDevItem(const char *key, const char *value) { bool ret = true; @@ -57,5 +58,6 @@ namespace SystemDepend { Updater::Utils::UpdaterDoReboot("", "Updater flashd reboot command"); return true; } +#endif } } // namespace Hdc diff --git a/services/flashd/daemon/update_commander.cpp b/services/flashd/daemon/update_commander.cpp index d8735711..c76721cc 100644 --- a/services/flashd/daemon/update_commander.cpp +++ b/services/flashd/daemon/update_commander.cpp @@ -88,7 +88,7 @@ bool UpdateCommander::DoUpdate(const uint8_t *payload, int payloadSize) FLASHD_LOGE("file fd is invaild"); return false; } - +#ifndef UPDATER_UT auto writeSize = std::min(static_cast(payloadSize), fileSize_ - currentSize_); if (writeSize <= 0) { FLASHD_LOGW("all the data has been written"); @@ -109,6 +109,7 @@ bool UpdateCommander::DoUpdate(const uint8_t *payload, int payloadSize) NotifySuccess(CmdType::UPDATE); return true; } +#endif UpdateProgress(CmdType::UPDATE); return true; } @@ -118,9 +119,11 @@ bool UpdateCommander::ExecUpdate() const const std::string miscFile = "/dev/block/by-name/misc"; std::vector filePath; filePath.push_back(filePath_); +#ifndef UPDATER_UT if (RebootAndInstallUpgradePackage(miscFile, filePath) == 0) { return true; } +#endif return false; } diff --git a/services/flashd/partition.h b/services/flashd/partition.h index d693d1db..5bf3c8a6 100644 --- a/services/flashd/partition.h +++ b/services/flashd/partition.h @@ -38,9 +38,13 @@ public: int DoEraseExt(const Ptable::PtnInfo &ptnInfo) const; #endif +#ifdef UPDATER_UT + uint64_t GetBlockDeviceSize(int fd) const; +#else private: uint64_t GetBlockDeviceSize(int fd) const; - +#endif +private: std::string devName_ = ""; std::unique_ptr writer_ = nullptr; }; diff --git a/test/unittest/flashd_test/flashd_unittest.cpp b/test/unittest/flashd_test/flashd_unittest.cpp index b1111095..d8023bf1 100644 --- a/test/unittest/flashd_test/flashd_unittest.cpp +++ b/test/unittest/flashd_test/flashd_unittest.cpp @@ -235,6 +235,45 @@ HWTEST_F(FLashServiceUnitTest, FlashdWriterRawWriter, TestSize.Level1) EXPECT_EQ(-1, ret); } +HWTEST_F(FLashServiceUnitTest, RegisterUserWriter, TestSize.Level0) +{ + std::string partName = ""; + std::string temp = ""; + uint8_t *buffer = reinterpret_cast(temp.data()); + int bufferSize = partName.size(); + std::unique_ptr writer = FlashdImageWriter::GetInstance().GetWriter(partName, buffer, bufferSize); + if (writer == nullptr) { + std::cout << "writer is nullptr"; + } + EXPECT_NE(nullptr, writer); + LOG(INFO) << "RegisterUserWriter finish"; +} + +HWTEST_F(FLashServiceUnitTest, UpdateCommanderPostCommand, TestSize.Level0) +{ + LoadFstab(); + std::unique_ptr commander = nullptr; + Flashd::UpdaterState ret = UpdaterState::DOING; + auto callbackFail = [&ret](Flashd::CmdType type, Flashd::UpdaterState state, const std::string &msg) { + ret = state; + }; + commander = Flashd::CommanderFactory::GetInstance().CreateCommander(Hdc::CMDSTR_UPDATE_SYSTEM, callbackFail); + EXPECT_NE(nullptr, commander); + commander->PostCommand(); + EXPECT_NE(nullptr, commander); + LOG(INFO) << "UpdateCommanderPostCommand finish"; +} + +HWTEST_F(FLashServiceUnitTest, PartitionGetBlockDeviceSize, TestSize.Level1) +{ + std::string partitionName = "test"; + Partition partTest(partitionName); + int fd = 1; + int ret = partTest.GetBlockDeviceSize(fd); + LOG(INFO) << "PartitionGetBlockDeviceSize ret: " << ret; + EXPECT_EQ(0, ret); +} + bool IsTestImg(const std::string &partition, const uint8_t *data, size_t len) { if (data == nullptr) { -- Gitee