Merge branch 'master-develop' of gitee.com:shenzhen-jiuyilian/ipc into master-develop

This commit is contained in:
Fancy code 2024-03-12 14:47:43 +08:00
commit b68ef7834a
15 changed files with 131 additions and 40 deletions

View File

@ -43,12 +43,11 @@ void MissionStateMachine::Init(void)
return; return;
} }
mStartMission = GetStartMission(); mStartMission = GetStartMission();
if (mStartMission != IpcMission::END) { if (mStartMission == IpcMission::END) {
RunStateMachine(mStartMission); LogError("ipcmission error, will start test mode.\n");
} mStartMission = IpcMission::TEST;
else {
LogError("ipcmission error.\n");
} }
RunStateMachine(mStartMission);
} }
void MissionStateMachine::UnInit(void) void MissionStateMachine::UnInit(void)
{ {

View File

@ -76,7 +76,7 @@ const StatusCode McuDevice::UnInit(void)
size_t McuDevice::WriteData(const void *buff, const size_t buffLength, std::shared_ptr<VProtocolContext> &context, size_t McuDevice::WriteData(const void *buff, const size_t buffLength, std::shared_ptr<VProtocolContext> &context,
const unsigned int &serialNumber) const unsigned int &serialNumber)
{ {
constexpr int WRITE_ERROR = -1; constexpr size_t WRITE_ERROR = -1;
size_t length = WRITE_ERROR; size_t length = WRITE_ERROR;
if (context.get() == nullptr) { if (context.get() == nullptr) {
/** /**
@ -99,9 +99,16 @@ size_t McuDevice::WriteData(const void *buff, const size_t buffLength, std::shar
AddMcuAsk(ask); AddMcuAsk(ask);
length = IUartSend(mUartDevice, buff, buffLength); length = IUartSend(mUartDevice, buff, buffLength);
mMutex.unlock(); mMutex.unlock();
if (WRITE_ERROR == length) {
LogError("Uart send failed, something wrong happened.\n");
ask->ReplyFinished(false);
DeleteMcuAsk(ask);
goto END;
}
if (ask->NeedReply() == true) { if (ask->NeedReply() == true) {
ask->Blocking(); ask->Blocking();
} }
END:
return length; return length;
} }
void McuDevice::GetIpcMissionReply(const unsigned int &serialNumber, const unsigned char &mission) void McuDevice::GetIpcMissionReply(const unsigned int &serialNumber, const unsigned char &mission)

View File

@ -46,4 +46,6 @@ using ::testing::Unused;
using ::testing::WithArgs; using ::testing::WithArgs;
using ::testing::internal::BuiltInDefaultValue; using ::testing::internal::BuiltInDefaultValue;
using ::testing::SetArgReferee; using ::testing::SetArgReferee;
// using ::testing::Mock::VerifyAndClearExpectations;
using ::testing::Mock;
#endif #endif

View File

@ -170,4 +170,15 @@ TEST_F(HunttingCameraTest, INTEGRATION_HunttingCamera_AUTO_MockUploadFiles)
MockUploadFiles(); MockUploadFiles();
MainThread::GetInstance()->Runing(); MainThread::GetInstance()->Runing();
} }
// ../output_files/test/bin/HunttingCameraTest
// --gtest_filter=HunttingCameraTest.INTEGRATION_HunttingCamera_AUTO_McuOpenFailed
TEST_F(HunttingCameraTest, INTEGRATION_HunttingCamera_AUTO_McuOpenFailed)
{
McuManagerTestTool::MockMcuDeviceOpenFailed(mLinuxTest);
MainThread::GetInstance()->Init();
TestManager::ResetTimeOut(1000 * 3);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
// MockUploadFiles();
MainThread::GetInstance()->Runing();
}
} // namespace HunttingCameraTest } // namespace HunttingCameraTest

View File

@ -13,6 +13,7 @@ include_directories(
# ${UTILS_SOURCE_PATH}/ModBusCRC16/include # ${UTILS_SOURCE_PATH}/ModBusCRC16/include
# ${TEST_SOURCE_PATH}/utils/LinuxApiMock/include # ${TEST_SOURCE_PATH}/utils/LinuxApiMock/include
# ${TEST_SOURCE_PATH}/utils/UartDevice/tool/include # ${TEST_SOURCE_PATH}/utils/UartDevice/tool/include
${TEST_SOURCE_PATH}
${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include
${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/include ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/include
) )

View File

@ -14,38 +14,8 @@
*/ */
#ifndef MCU_ASK_BASE_TEST_TOOL_H #ifndef MCU_ASK_BASE_TEST_TOOL_H
#define MCU_ASK_BASE_TEST_TOOL_H #define MCU_ASK_BASE_TEST_TOOL_H
#include "GtestUsing.h"
#include "McuAskBase.h" #include "McuAskBase.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
using ::testing::_;
using ::testing::Action;
using ::testing::ActionInterface;
using ::testing::AnyNumber;
using ::testing::Assign;
using ::testing::AtLeast;
using ::testing::ByMove;
using ::testing::ByRef;
using ::testing::DefaultValue;
using ::testing::DoAll;
using ::testing::DoDefault;
using ::testing::IgnoreResult;
using ::testing::Invoke;
using ::testing::InvokeWithoutArgs;
using ::testing::MakePolymorphicAction;
using ::testing::PolymorphicAction;
using ::testing::Return;
using ::testing::ReturnNew;
using ::testing::ReturnNull;
using ::testing::ReturnPointee;
using ::testing::ReturnRef;
using ::testing::ReturnRefOfCopy;
using ::testing::ReturnRoundRobin;
using ::testing::SaveArg;
using ::testing::SetArgPointee;
using ::testing::SetArgumentPointee;
using ::testing::Unused;
using ::testing::WithArgs;
using ::testing::internal::BuiltInDefaultValue;
class McuAskBaseTest : public McuAskBase class McuAskBaseTest : public McuAskBase
{ {
public: public:
@ -84,5 +54,7 @@ public:
public: public:
void McuAskDefaultFeatures(std::shared_ptr<McuAskBaseTestTool> &mock); void McuAskDefaultFeatures(std::shared_ptr<McuAskBaseTestTool> &mock);
void McuAskDoNothing(std::shared_ptr<McuAskBaseTestTool> &mock);
void NoNeedToBlocking(std::shared_ptr<McuAskBaseTestTool> &mock);
}; };
#endif #endif

View File

@ -13,6 +13,9 @@
* limitations under the License. * limitations under the License.
*/ */
#include "McuAskBaseTestTool.h" #include "McuAskBaseTestTool.h"
#include "ILog.h"
constexpr int CALL_ONLY_ONCE = 1;
constexpr int SHOULD_NOT_CALL = 0;
ASK_RESULT McuAskBaseTest::Blocking(void) ASK_RESULT McuAskBaseTest::Blocking(void)
{ {
BlockingTrace(); BlockingTrace();
@ -35,8 +38,6 @@ bool McuAskBaseTest::IfTimeout(const unsigned int &integrationTimeMs)
} }
void McuAskBaseTestTool::McuAskDefaultFeatures(std::shared_ptr<McuAskBaseTestTool> &mock) void McuAskBaseTestTool::McuAskDefaultFeatures(std::shared_ptr<McuAskBaseTestTool> &mock)
{ {
constexpr int CALL_ONLY_ONCE = 1;
constexpr int SHOULD_NOT_CALL = 0;
if (McuAskBlock::BLOCK == mIsBlock && McuAskReply::NEED_REPLY == mNeedReply) { if (McuAskBlock::BLOCK == mIsBlock && McuAskReply::NEED_REPLY == mNeedReply) {
EXPECT_CALL(*mock.get(), BlockingTrace()).Times(CALL_ONLY_ONCE); EXPECT_CALL(*mock.get(), BlockingTrace()).Times(CALL_ONLY_ONCE);
EXPECT_CALL(*mock.get(), NeedReplyTrace()).Times(AtLeast(1)); EXPECT_CALL(*mock.get(), NeedReplyTrace()).Times(AtLeast(1));
@ -55,4 +56,16 @@ void McuAskBaseTestTool::McuAskDefaultFeatures(std::shared_ptr<McuAskBaseTestToo
EXPECT_CALL(*mock.get(), ReplyFinishedTrace(_)).Times(SHOULD_NOT_CALL); EXPECT_CALL(*mock.get(), ReplyFinishedTrace(_)).Times(SHOULD_NOT_CALL);
EXPECT_CALL(*mock.get(), IfTimeoutTrace(_)).Times(SHOULD_NOT_CALL); EXPECT_CALL(*mock.get(), IfTimeoutTrace(_)).Times(SHOULD_NOT_CALL);
} }
}
void McuAskBaseTestTool::McuAskDoNothing(std::shared_ptr<McuAskBaseTestTool> &mock)
{
EXPECT_CALL(*mock.get(), BlockingTrace()).Times(AnyNumber());
EXPECT_CALL(*mock.get(), NeedReplyTrace()).Times(AnyNumber());
EXPECT_CALL(*mock.get(), ReplyFinishedTrace(_)).Times(AnyNumber());
EXPECT_CALL(*mock.get(), IfTimeoutTrace(_)).Times(AnyNumber());
}
void McuAskBaseTestTool::NoNeedToBlocking(std::shared_ptr<McuAskBaseTestTool> &mock)
{
// Mock::AllowLeak(mock.get());
EXPECT_CALL(*mock.get(), BlockingTrace()).Times(SHOULD_NOT_CALL);
} }

View File

@ -756,4 +756,36 @@ TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_SetPirSensitivity2)
EXPECT_EQ(CheckAskExist(ask), false); // Ensure that the request has been processed and deleted. EXPECT_EQ(CheckAskExist(ask), false); // Ensure that the request has been processed and deleted.
IMcuManager::GetInstance()->UnInit(); IMcuManager::GetInstance()->UnInit();
} }
// ../output_files/test/bin/McuManagerTest
// --gtest_filter=McuManagerMockTest.INTEGRATION_McuManager_AUTO_GetIpcMissionFailed
TEST_F(McuManagerMockTest, INTEGRATION_McuManager_AUTO_GetIpcMissionFailed)
{
class McuAskTest : public McuAsk<IpcMission>, public McuAskBaseTestTool
{
public:
McuAskTest() : McuAskBaseTestTool(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY) {}
virtual ~McuAskTest() = default;
void ReplyFinished(const bool result) override
{
McuAskBaseTestTool::ReplyFinished(result);
if (result) {
LogInfo("Ask data succeed, mDataReply = %d.\n", static_cast<int>(mDataReply));
// Do something here.
}
else {
LogError("Ask data falied.\n");
}
}
};
McuManagerTestTool::MockMcuDeviceOpenFailed(mLinuxTest);
IMcuManager::GetInstance()->Init();
std::shared_ptr<VMcuAsk> ask = std::make_shared<McuAskTest>();
std::shared_ptr<McuAskBaseTestTool> testTool = std::dynamic_pointer_cast<McuAskBaseTestTool>(ask);
testTool->McuAskDoNothing(testTool);
testTool->NoNeedToBlocking(testTool);
IMcuManager::GetInstance()->GetIpcMission(ask);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
EXPECT_EQ(CheckAskExist(ask), false); // Ensure that the request has been processed and deleted.
IMcuManager::GetInstance()->UnInit();
}
} // namespace McuManagerMockTest } // namespace McuManagerMockTest

View File

@ -35,6 +35,7 @@ public:
void UnInit(void); void UnInit(void);
bool CheckAskExist(const std::shared_ptr<VMcuAsk> &ask); bool CheckAskExist(const std::shared_ptr<VMcuAsk> &ask);
void OtherSideAskIpcMission(std::shared_ptr<LinuxTest> &mock, const unsigned int &serialNumber); void OtherSideAskIpcMission(std::shared_ptr<LinuxTest> &mock, const unsigned int &serialNumber);
void MockMcuDeviceOpenFailed(std::shared_ptr<LinuxTest> &mock);
private: private:
std::shared_ptr<McuManagerImplTest> mMcuManagerMock; std::shared_ptr<McuManagerImplTest> mMcuManagerMock;

View File

@ -47,4 +47,8 @@ bool McuManagerTestTool::CheckAskExist(const std::shared_ptr<VMcuAsk> &ask)
void McuManagerTestTool::OtherSideAskIpcMission(std::shared_ptr<LinuxTest> &mock, const unsigned int &serialNumber) void McuManagerTestTool::OtherSideAskIpcMission(std::shared_ptr<LinuxTest> &mock, const unsigned int &serialNumber)
{ {
McuProtocolTestTool::OtherSideAskIpcMission(mock, serialNumber); McuProtocolTestTool::OtherSideAskIpcMission(mock, serialNumber);
}
void McuManagerTestTool::MockMcuDeviceOpenFailed(std::shared_ptr<LinuxTest> &mock)
{
UartDeviceTestTool::SetUartDeviceOpenFailed(mock, gUartDevice);
} }

View File

@ -178,4 +178,18 @@ TEST_F(UartDeviceMockTest, UNIT_UartDevice_AUTO_MultiThreadTest)
test2.detach(); test2.detach();
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
} }
// ../output_files/test/bin/UartDeviceTest --gtest_filter=UartDeviceMockTest.UNIT_UartDevice_AUTO_OpenFailed
TEST_F(UartDeviceMockTest, UNIT_UartDevice_AUTO_OpenFailed)
{
SetUartDeviceOpenFailed(mLinuxTest, gUartDevice);
const char *SEND_BUF = "TEST";
constexpr ssize_t SEND_LENGTH = 1; // less than static_cast<ssize_t>(strlen(SEND_BUF))
SetSendApiOnce(mLinuxTest, gUartDevice, SEND_LENGTH);
void *object = CreateUartDevice(gUartDevice);
IUartOpen(object);
ssize_t sendResult = IUartSend(object, SEND_BUF, strlen(SEND_BUF));
EXPECT_EQ(sendResult, static_cast<ssize_t>(strlen(SEND_BUF)));
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
IUartDeviceFree(object);
}
} // namespace UartDeviceMockTest } // namespace UartDeviceMockTest

View File

@ -61,6 +61,13 @@ public:
* @param length The length of data that will be received. * @param length The length of data that will be received.
*/ */
void SetRecvApiOnce(std::shared_ptr<LinuxTest> &mock, const UartInfo &uart, void *recvBuff, const ssize_t &length); void SetRecvApiOnce(std::shared_ptr<LinuxTest> &mock, const UartInfo &uart, void *recvBuff, const ssize_t &length);
/**
* @brief Set the Uart Device Open Failed object
*
* @param mock
* @param uart
*/
void SetUartDeviceOpenFailed(std::shared_ptr<LinuxTest> &mock, const UartInfo &uart);
private: private:
std::map<const char *, int> mDeviceMap; std::map<const char *, int> mDeviceMap;

View File

@ -103,4 +103,9 @@ void UartDeviceTestTool::SetRecvApiOnce(std::shared_ptr<LinuxTest> &mock, const
EXPECT_CALL(*mock.get(), fx_read(uartFd, _, _)) EXPECT_CALL(*mock.get(), fx_read(uartFd, _, _))
.WillOnce(DoAll(WithArgs<0, 1, 2>(Invoke(readBuf)), Return(length))) .WillOnce(DoAll(WithArgs<0, 1, 2>(Invoke(readBuf)), Return(length)))
.WillRepeatedly(DoAll(Return(UART_DEVICE_READ_NOTHING))); .WillRepeatedly(DoAll(Return(UART_DEVICE_READ_NOTHING)));
}
void UartDeviceTestTool::SetUartDeviceOpenFailed(std::shared_ptr<LinuxTest> &mock, const UartInfo &uart)
{
LogInfo("SetUartDeviceOpenFailed[%s], will return -1\n", uart.mDevice);
EXPECT_CALL(*mock.get(), fx_open(uart.mDevice, _)).WillRepeatedly(DoAll((Return(-1))));
} }

23
tools/shell/find_and_kill.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
# 指定要查找并杀死的进程名称列表
target_processes=("rkipc" "rkwifi_server" "wpa_supplicant" "udhcpc")
# 遍历进程名称列表
for target_process in "${target_processes[@]}"; do
# 使用pgrep命令查找目标进程的PID
pids=$(pgrep -f "$target_process")
# 检查是否找到目标进程
if [ -z "$pids" ]; then
echo "未找到目标进程: $target_process"
else
echo "找到以下目标进程并准备杀死它们:"
for pid in $pids; do
echo "进程: $target_process,PID: $pid"
# 使用kill命令杀死目标进程
kill -9 "$pid"
done
echo "所有$target_process进程已被杀死"
fi
done

View File

@ -30,12 +30,12 @@ const char *GetUartDeviceModuleName(void) { return UART_DEVICE_NAME; }
UartDeviceImpl::UartDeviceImpl(const UartInfo &uatrInfo) : mUatrInfo(uatrInfo) { mFd = -1; } UartDeviceImpl::UartDeviceImpl(const UartInfo &uatrInfo) : mUatrInfo(uatrInfo) { mFd = -1; }
const StatusCode UartDeviceImpl::UartOpen(void) const StatusCode UartDeviceImpl::UartOpen(void)
{ {
LogInfo("open uart device = %s\n", mUatrInfo.mDevice);
mFd = fx_open(mUatrInfo.mDevice, O_RDWR | O_NOCTTY | O_NONBLOCK); mFd = fx_open(mUatrInfo.mDevice, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (INVALID_FD == mFd) { if (INVALID_FD == mFd) {
perror("Can't Open Serial Port"); perror("Can't Open Serial Port");
return CreateStatusCode(STATUS_CODE_NOT_OK); return CreateStatusCode(STATUS_CODE_NOT_OK);
} }
LogInfo("open uart device = %s, fd = %d\n", mUatrInfo.mDevice, mFd);
return SetConfig(); return SetConfig();
} }