mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
Improve:SD card hal test.
This commit is contained in:
parent
7abf2d7a76
commit
f0062b96c2
|
@ -60,7 +60,7 @@ void SdCardHal::DevDetectingThread(void)
|
|||
// const char *SD_CARD_DEVICE = "/SD_CARD_DEVICE/mmcblk1p1";
|
||||
mThreadRuning = true;
|
||||
while (mThreadRuning) {
|
||||
if (access(SD_CARD_DEVICE, F_OK) != DEVICE_EXIST) {
|
||||
if (fx_access(SD_CARD_DEVICE, F_OK) != DEVICE_EXIST) {
|
||||
if (SdCardHalStatus::PULL_OUT_DEVICE_NOT_EXIST != mStatus) {
|
||||
mStatus = SdCardHalStatus::PULL_OUT_DEVICE_NOT_EXIST;
|
||||
ReportDetecedChangedResult(mStatus);
|
||||
|
@ -104,7 +104,8 @@ void SdCardHal::DevDetectingThread(void)
|
|||
}
|
||||
else {
|
||||
// LogInfo("sdCardHal: %s is inserted.\n", SD_CARD_DEVICE);
|
||||
if (SdCardHalStatus::INSERTED != mStatus) {
|
||||
if (SdCardHalStatus::INSERTED != mStatus && SdCardHalStatus::MOUNTED != mStatus &&
|
||||
SdCardHalStatus::UNMOUNTED != mStatus) {
|
||||
mStatus = SdCardHalStatus::INSERTED;
|
||||
ReportDetecedChangedResult(mStatus);
|
||||
}
|
||||
|
@ -128,6 +129,7 @@ void SdCardHal::ReportDetecedChangedResult(const SdCardHalStatus &status)
|
|||
snprintf(cmd, BUF_LENGTH, "mount %s %s", SD_CARD_DEV, SD_CARD_MOUNT_PATH);
|
||||
fx_system(cmd);
|
||||
mountedStatus = SdCardHalStatus::MOUNTED;
|
||||
mStatus = SdCardHalStatus::MOUNTED;
|
||||
}
|
||||
auto monitor = mMonitor.lock();
|
||||
if (mMonitor.expired()) {
|
||||
|
|
|
@ -26,6 +26,7 @@ if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX})
|
|||
set(TEST_LINUX_MOCK "${TEST_LINUX_MOCK},--wrap=fx_select" CACHE STRING INTERNAL FORCE)
|
||||
set(TEST_LINUX_MOCK "${TEST_LINUX_MOCK},--wrap=fx_write" CACHE STRING INTERNAL FORCE)
|
||||
set(TEST_LINUX_MOCK "${TEST_LINUX_MOCK},--wrap=fx_read" CACHE STRING INTERNAL FORCE)
|
||||
set(TEST_LINUX_MOCK "${TEST_LINUX_MOCK},--wrap=fx_access" CACHE STRING INTERNAL FORCE)
|
||||
endif()
|
||||
# Mock Linux api.
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TEST_LINUX_MOCK}")
|
||||
|
|
|
@ -33,9 +33,10 @@ TEST_F(HunttingCameraTest, INTEGRATION_HunttingCamera_EXAMPLE_MediaReprot)
|
|||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
// McuManagerTestTool::MockMcuDeviceOpenFailed(mLinuxTest);
|
||||
MainThread::GetInstance()->Init();
|
||||
TestManager::ResetTimeOut(1000 * 3);
|
||||
TestManager::ResetTimeOut(1000 * 6);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
// MockAppPlayback();
|
||||
MainThread::GetInstance()->Runing();
|
||||
MainThread::GetInstance()->UnInit();
|
||||
}
|
||||
} // namespace MediaManager_Mock_Test
|
|
@ -184,6 +184,8 @@ void HalTestTool::HalMockInit(std::shared_ptr<IHalCpp> &vMock)
|
|||
EXPECT_CALL(*mock.get(), GetAllKeysTrace(_))
|
||||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
std::shared_ptr<VWifiHal> wifiHal = std::make_shared<WifiHalMock>();
|
||||
std::shared_ptr<WifiHalMock> wifiHalMock = std::dynamic_pointer_cast<WifiHalMock>(wifiHal);
|
||||
EXPECT_CALL(*wifiHalMock.get(), OpenApMode()).WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_OK))));
|
||||
EXPECT_CALL(*mock.get(), GetWifiHalTrace(_))
|
||||
.WillRepeatedly(DoAll(SetArgReferee<0>(wifiHal), Return(CreateStatusCode(STATUS_CODE_OK))));
|
||||
EXPECT_CALL(*mock.get(), GetCameraHalTrace(_))
|
||||
|
|
|
@ -22,8 +22,10 @@ SdCardHalMock::SdCardHalMock()
|
|||
void SdCardHalMock::SetLinuxTest(std::shared_ptr<LinuxTest> &mock)
|
||||
{
|
||||
constexpr int FSTAT_SUCCESS = 0;
|
||||
constexpr int FILE_EXIST = 0;
|
||||
mLinuxTest = mock;
|
||||
mDevFd = mLinuxTest->GetHandleForMock();
|
||||
EXPECT_CALL(*mock.get(), fx_access(SD_CARD_DEVICE, F_OK)).WillRepeatedly(DoAll(Return(FILE_EXIST)));
|
||||
EXPECT_CALL(*mock.get(), fx_open(SD_CARD_DEVICE, _)).WillRepeatedly(DoAll((Return(mDevFd))));
|
||||
auto fstatFunc = [=, &mock](int fd, struct stat *statbuf) {
|
||||
statbuf->st_mode = S_IFBLK | 0600;
|
||||
|
|
|
@ -27,5 +27,6 @@ class WifiHalMock : public WifiHalTest
|
|||
public:
|
||||
WifiHalMock() = default;
|
||||
virtual ~WifiHalMock() = default;
|
||||
MOCK_METHOD0(OpenApMode, StatusCode(void));
|
||||
};
|
||||
#endif
|
|
@ -33,6 +33,7 @@ public:
|
|||
virtual ssize_t fx_read(int fd, void *buf, size_t count);
|
||||
virtual int fx_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
|
||||
virtual int fx_fstat(int fd, struct stat *statbuf);
|
||||
virtual int fx_access(const char *pathname, int mode);
|
||||
};
|
||||
/**
|
||||
* A simulation interface class used for automated testing in Ubuntu systems, implementing the function of piling on
|
||||
|
@ -50,6 +51,7 @@ public:
|
|||
MOCK_METHOD3(fx_read, ssize_t(int, void *, size_t));
|
||||
MOCK_METHOD5(fx_select, int(int, fd_set *, fd_set *, fd_set *, struct timeval *));
|
||||
MOCK_METHOD2(fx_fstat, int(int, struct stat *));
|
||||
MOCK_METHOD2(fx_access, int(const char *, int));
|
||||
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -64,6 +64,10 @@ int LinuxApiMock::fx_fstat(int fd, struct stat *statbuf)
|
|||
{
|
||||
return __real_fx_fstat(fd, statbuf);
|
||||
}
|
||||
int LinuxApiMock::fx_access(const char *pathname, int mode)
|
||||
{
|
||||
return __real_fx_access(pathname, mode);
|
||||
}
|
||||
std::shared_ptr<LinuxTest> LinuxTest::CreateLinuxTest(void)
|
||||
{
|
||||
std::shared_ptr<LinuxTest> test = std::make_shared<LinuxTestImpl>();
|
||||
|
|
|
@ -103,6 +103,17 @@ void LinuxTestImpl::ApiInit(std::shared_ptr<LinuxTest> &mock)
|
|||
WithArgs<0, 1>(Invoke(api_fstat)),
|
||||
Invoke((std::dynamic_pointer_cast<LinuxTestImpl>(mock)).get(), &LinuxTestImpl::ApiUnlockThread),
|
||||
ReturnPointee(&fstatResult)));
|
||||
static int accessResult = -1;
|
||||
auto api_access = [=](const char *pathname, int mode) {
|
||||
accessResult = __real_fx_access(pathname, mode);
|
||||
LogInfo("accessResult = %d\n", accessResult);
|
||||
};
|
||||
EXPECT_CALL(*mock.get(), fx_access(_, _))
|
||||
.WillRepeatedly(
|
||||
DoAll(Invoke((std::dynamic_pointer_cast<LinuxTestImpl>(mock)).get(), &LinuxTestImpl::ApiLock),
|
||||
WithArgs<0, 1>(Invoke(api_access)),
|
||||
Invoke((std::dynamic_pointer_cast<LinuxTestImpl>(mock)).get(), &LinuxTestImpl::ApiUnlockThread),
|
||||
ReturnPointee(&accessResult)));
|
||||
}
|
||||
void LinuxTestImpl::Init()
|
||||
{
|
||||
|
|
|
@ -46,6 +46,10 @@ int __wrap_fx_fstat(int fd, struct stat *statbuf)
|
|||
// TODO: 在此处加锁,优化打桩时,接口需要调用真实接口并返回真实接口的返回值返回全局变量的多线程安全问题。
|
||||
return LinuxApiMock::GetInstance()->fx_fstat(fd, statbuf);
|
||||
}
|
||||
int __wrap_fx_access(const char *pathname, int mode)
|
||||
{
|
||||
return LinuxApiMock::GetInstance()->fx_access(pathname, mode);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -29,6 +29,7 @@ ssize_t __real_fx_write(int fd, const void *buf, size_t count);
|
|||
ssize_t __real_fx_read(int fd, void *buf, size_t count);
|
||||
int __real_fx_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
|
||||
int __real_fx_fstat(int fd, struct stat *statbuf);
|
||||
int __real_fx_access(const char *pathname, int mode);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -32,6 +32,7 @@ ssize_t fx_write(int fd, const void *buf, size_t count);
|
|||
ssize_t fx_read(int fd, void *buf, size_t count);
|
||||
int fx_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
|
||||
int fx_fstat(int fd, struct stat *statbuf);
|
||||
int fx_access(const char *pathname, int mode);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -53,4 +53,8 @@ int fx_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, st
|
|||
int fx_fstat(int fd, struct stat *statbuf)
|
||||
{
|
||||
return fstat(fd, statbuf);
|
||||
}
|
||||
int fx_access(const char *pathname, int mode)
|
||||
{
|
||||
return access(pathname, mode);
|
||||
}
|
Loading…
Reference in New Issue
Block a user