diff --git a/services/flashd/daemon/commander.cpp b/services/flashd/daemon/commander.cpp index d1be95eb3e40677a8707ccb28082f04fdd3328d7..9cd2cc9ce03bb029d85bee56d77c276b94f45984 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 c8d702ec1b2d296530235a9cfffc66ef29388123..6adf39d165bb749a950f3a6160b5506337c54494 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 d8735711b956fd912d170f0d0e18f8f77c48b4d8..c76721cc87a1f526640b156bede4f49157842325 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 d693d1db840d403d46c894d38ab70dca1477c18a..5bf3c8a653014e452380cbbdaca54935cd433fb0 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 b1111095ac3bfc3c35a8182d788d1549364b48bd..d8023bf10eda303608a5fc1956dc48fafd2302d9 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) {