Improve:sd card foramt when abnormal.
This commit is contained in:
parent
732caa9440
commit
cb5c52bae8
|
@ -126,7 +126,7 @@ bool SdCardHandleState::ResetKeyMediaTaskHandle(VStateMachineData *msg)
|
|||
*/
|
||||
bool SdCardHandleState::FormatKeyFormattingSDCardHandle(VStateMachineData *msg)
|
||||
{
|
||||
if (StorageEvent::SD_CARD_INSERT == mSdCardStatus) {
|
||||
if (StorageEvent::SD_CARD_INSERT == mSdCardStatus || StorageEvent::SD_ABNORMAL == mSdCardStatus) {
|
||||
LogInfo("FormatKeyFormattingSDCardHandle.\n");
|
||||
MissionStateMachine::GetInstance()->DelayMessage(msg);
|
||||
MissionStateMachine::GetInstance()->SwitchState(SystemState::FORMATTING_STATE);
|
||||
|
|
|
@ -166,10 +166,10 @@ void SdCardHal::ReportDetecedChangedResult(const SdCardHalStatus &status)
|
|||
LogInfo("SdCardHalStatus changed: %s.\n", PrintfStatusString(status));
|
||||
SdCardHalStatus mountedStatus = SdCardHalStatus::END;
|
||||
if (SdCardHalStatus::INSERTED == status) {
|
||||
LogInfo("mount sd to %s.\n", SD_CARD_MOUNT_PATH);
|
||||
constexpr int BUF_LENGTH = 128;
|
||||
char cmd[BUF_LENGTH] = {0};
|
||||
snprintf(cmd, BUF_LENGTH, "mount %s %s", SD_CARD_DEV, SD_CARD_MOUNT_PATH);
|
||||
LogInfo("system cmd: %s.\n", cmd);
|
||||
int ret = fx_system(cmd);
|
||||
constexpr int SYSTEM_SUCCESS = 0;
|
||||
if (SYSTEM_SUCCESS == ret) {
|
||||
|
|
|
@ -23,7 +23,7 @@ enum class StorageEvent
|
|||
{
|
||||
SD_CARD_INSERT = 0,
|
||||
SD_CARD_REMOVE,
|
||||
SD_ABNORMAL,
|
||||
SD_ABNORMAL, ///< Abnormal status includes: The card cannot be mounted.
|
||||
EMMC_NORMAL,
|
||||
END
|
||||
};
|
||||
|
|
|
@ -65,6 +65,22 @@ TEST_F(HuntingCameraTest, HS_INTEGRATION_HunttingCamera_EXAMPLE_KeyControlClick)
|
|||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MainThread::GetInstance()->Runing();
|
||||
}
|
||||
/**
|
||||
* @brief Construct a new test f object
|
||||
* ../output_files/test/bin/HuntingCameraTest
|
||||
* --gtest_filter=HuntingCameraTest.HS_INTEGRATION_HunttingCamera_EXAMPLE_SD_Abnormal
|
||||
*/
|
||||
TEST_F(HuntingCameraTest, HS_INTEGRATION_HunttingCamera_EXAMPLE_SD_Abnormal)
|
||||
{
|
||||
SetAllCamerasResult(mAllCamerasMock);
|
||||
MockOtherSideIpcMissionReply(IpcMission::TEST);
|
||||
MockSdCardAbnormal(mLinuxTest);
|
||||
MainThread::GetInstance()->Init();
|
||||
TestManager::ResetTimeOut(1000 * 25);
|
||||
HalTestTool::MockKeyClick("format", 1000 * 18); // Simulate pressing a button.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MainThread::GetInstance()->Runing();
|
||||
}
|
||||
/**
|
||||
* @brief Construct a new test f object
|
||||
* ../output_files/test/bin/HuntingCameraTest
|
||||
|
|
|
@ -73,7 +73,8 @@ private: // About camera hal
|
|||
protected: // About sd card hal
|
||||
void MockSdCardRemove(std::shared_ptr<LinuxTest> &mock);
|
||||
void MockSdCardInsert(std::shared_ptr<LinuxTest> &mock);
|
||||
void MockSdCardFormatReturn(std::shared_ptr<LinuxTest> &mock, const int &systemResult);
|
||||
void MockSdCardFormatReturn(std::shared_ptr<LinuxTest> &mock, const int &systemResult); // TODO: delete
|
||||
void MockSdCardAbnormal(std::shared_ptr<LinuxTest> &mock);
|
||||
|
||||
public:
|
||||
static std::shared_ptr<VKeyHal> MakeKeyHalTest(const std::string &keyName);
|
||||
|
|
|
@ -374,6 +374,15 @@ void HalTestTool::MockSdCardFormatReturn(std::shared_ptr<LinuxTest> &mock, const
|
|||
}
|
||||
sdCardHal->MockSdCardFormatResult(mock, systemResult);
|
||||
}
|
||||
void HalTestTool::MockSdCardAbnormal(std::shared_ptr<LinuxTest> &mock)
|
||||
{
|
||||
std::shared_ptr<SdCardHalMock> sdCardHal = std::dynamic_pointer_cast<SdCardHalMock>(mSdCardHal);
|
||||
if (nullptr == sdCardHal) {
|
||||
LogError("SdCardHalMock is null.\n");
|
||||
return;
|
||||
}
|
||||
sdCardHal->MockSdCardAbnormal(mock);
|
||||
}
|
||||
std::shared_ptr<VKeyHal> HalTestTool::MakeKeyHalTest(const std::string &keyName)
|
||||
{
|
||||
std::shared_ptr<VKeyHal> key = std::make_shared<KeyControlMock>(keyName);
|
||||
|
|
|
@ -50,7 +50,10 @@ void SdCardHalMock::MockSdCardInsert(std::shared_ptr<LinuxTest> &mock)
|
|||
}
|
||||
void SdCardHalMock::MockSdCardFormatResult(std::shared_ptr<LinuxTest> &mock, const int &result)
|
||||
{
|
||||
// TODO: improve
|
||||
LinuxTest::SetSystemCommandResult(mock, "mkfs.vfat", result);
|
||||
LinuxTest::SetSystemCommandResult(mock, "umount", result);
|
||||
}
|
||||
void SdCardHalMock::MockSdCardAbnormal(std::shared_ptr<LinuxTest> &mock)
|
||||
{
|
||||
LinuxTest::SetSystemCommandResult(mock, "mount", MOCK_SYSTEM_RESULT_FAILED);
|
||||
}
|
|
@ -17,6 +17,8 @@
|
|||
#include "IHalCpp.h"
|
||||
#include "LinuxApiMock.h"
|
||||
#include "SdCardHal.h"
|
||||
constexpr int MOCK_SYSTEM_RESULT_SUCCEED = 0;
|
||||
constexpr int MOCK_SYSTEM_RESULT_FAILED = -1;
|
||||
class SdCardHalMock : public SdCardHal
|
||||
{
|
||||
public:
|
||||
|
@ -26,6 +28,7 @@ public:
|
|||
void MockSdCardRemove(std::shared_ptr<LinuxTest> &mock);
|
||||
void MockSdCardInsert(std::shared_ptr<LinuxTest> &mock);
|
||||
void MockSdCardFormatResult(std::shared_ptr<LinuxTest> &mock, const int &result);
|
||||
void MockSdCardAbnormal(std::shared_ptr<LinuxTest> &mock);
|
||||
|
||||
private:
|
||||
std::shared_ptr<LinuxTest> mLinuxTest;
|
||||
|
|
Loading…
Reference in New Issue
Block a user