Backup:test code.
This commit is contained in:
parent
8ddb9d917d
commit
402baf38f9
|
@ -44,7 +44,7 @@ void MissionStateMachine::Init(void)
|
||||||
}
|
}
|
||||||
mStartMission = GetStartMission();
|
mStartMission = GetStartMission();
|
||||||
if (mStartMission != IpcMission::END) {
|
if (mStartMission != IpcMission::END) {
|
||||||
// RunStateMachine(mStartMission);
|
RunStateMachine(mStartMission);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LogError("ipcmission error.\n");
|
LogError("ipcmission error.\n");
|
||||||
|
@ -59,19 +59,18 @@ IpcMission MissionStateMachine::GetStartMission(void)
|
||||||
class McuAskIpcMission : public McuAsk<IpcMission>, public McuAskBase
|
class McuAskIpcMission : public McuAsk<IpcMission>, public McuAskBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
McuAskIpcMission() : McuAskBase(McuAskBlock::NOT_BLOCK, McuAskReply::NEED_REPLY)
|
McuAskIpcMission() : McuAskBase(McuAskBlock::BLOCK, McuAskReply::NEED_REPLY) { mDataReply = IpcMission::END; }
|
||||||
{
|
|
||||||
mDataReply = IpcMission::END;
|
|
||||||
}
|
|
||||||
virtual ~McuAskIpcMission() = default;
|
virtual ~McuAskIpcMission() = default;
|
||||||
};
|
};
|
||||||
std::shared_ptr<VMcuAsk> ask = std::make_shared<McuAskIpcMission>();
|
std::shared_ptr<VMcuAsk> ask = std::make_shared<McuAskIpcMission>();
|
||||||
IMcuManager::GetInstance()->GetIpcMission(ask);
|
IMcuManager::GetInstance()->GetIpcMission(ask);
|
||||||
return std::dynamic_pointer_cast<McuAskIpcMission>(ask)->mDataReply;
|
return std::dynamic_pointer_cast<McuAskIpcMission>(ask)->mDataReply;
|
||||||
}
|
}
|
||||||
// void MissionStateMachine::RunStateMachine(const IpcMission &mission)
|
void MissionStateMachine::RunStateMachine(const IpcMission &mission)
|
||||||
// {
|
{
|
||||||
// LogInfo("Make all states and start the state machine.\n");
|
LogInfo("Make all states and start the state machine.\n");
|
||||||
// mStateTree[MissionState::TOP_STATE] = MissionManagerMakePtr::GetInstance()->CreateTopState();
|
mStateTree[MissionState::TOP_STATE] = MissionManagerMakePtr::GetInstance()->CreateTopState();
|
||||||
// mStateMachine->SetTopState(mStateTree[MissionState::TOP_STATE].get());
|
mStateMachine->StatePlus(mStateTree[MissionState::TOP_STATE].get(), nullptr);
|
||||||
// }
|
mStateMachine->SetCurrentState(mStateTree[MissionState::TOP_STATE].get());
|
||||||
|
mStateMachine->StartStateMachine();
|
||||||
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IpcMission GetStartMission(void);
|
IpcMission GetStartMission(void);
|
||||||
// void RunStateMachine(const IpcMission &mission);
|
void RunStateMachine(const IpcMission &mission);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<VStateMachineHandle> mStateMachine;
|
std::shared_ptr<VStateMachineHandle> mStateMachine;
|
||||||
|
|
|
@ -13,7 +13,16 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
#include "TopState.h"
|
#include "TopState.h"
|
||||||
|
#include "ILog.h"
|
||||||
TopState::TopState() : State("TopState") {}
|
TopState::TopState() : State("TopState") {}
|
||||||
void TopState::GoInState() {}
|
void TopState::GoInState()
|
||||||
void TopState::GoOutState() {}
|
{
|
||||||
|
//
|
||||||
|
LogInfo(" ========== opState::GoInState.\n");
|
||||||
|
}
|
||||||
|
void TopState::GoOutState()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
LogInfo(" ========== opState::GoOutState.\n");
|
||||||
|
}
|
||||||
bool TopState::ExecuteStateMsg(VStateMachineData *msg) { return DataProcessing::EventHandle(msg); }
|
bool TopState::ExecuteStateMsg(VStateMachineData *msg) { return DataProcessing::EventHandle(msg); }
|
|
@ -55,7 +55,7 @@ public:
|
||||||
virtual ~VStateMachineHandle() = default;
|
virtual ~VStateMachineHandle() = default;
|
||||||
virtual bool InitialStateMachine() { return false; }
|
virtual bool InitialStateMachine() { return false; }
|
||||||
virtual void StatePlus(State *state, State *upper) {}
|
virtual void StatePlus(State *state, State *upper) {}
|
||||||
virtual void SetTopState(State *firstState) {}
|
virtual void SetCurrentState(State *firstState) {}
|
||||||
virtual void StartStateMachine() {}
|
virtual void StartStateMachine() {}
|
||||||
virtual void SendMessage(int msgName) {}
|
virtual void SendMessage(int msgName) {}
|
||||||
virtual void StopHandlerThread() {}
|
virtual void StopHandlerThread() {}
|
||||||
|
|
|
@ -95,14 +95,14 @@ void StateMachine::StateDelete(State *state)
|
||||||
pStateMachineHandler->StateDelete(state);
|
pStateMachineHandler->StateDelete(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StateMachine::SetTopState(State *firstState)
|
void StateMachine::SetCurrentState(State *firstState)
|
||||||
{
|
{
|
||||||
if (pStateMachineHandler == nullptr) {
|
if (pStateMachineHandler == nullptr) {
|
||||||
LogError("Start StateMachine failed, pStateMachineHandler is nullptr!\n");
|
LogError("Start StateMachine failed, pStateMachineHandler is nullptr!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pStateMachineHandler->SetTopState(firstState);
|
pStateMachineHandler->SetCurrentState(firstState);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StateMachine::SwitchState(State *targetState)
|
void StateMachine::SwitchState(State *targetState)
|
||||||
|
@ -382,7 +382,7 @@ void StateMachineHandler::StateDelete(State *state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StateMachineHandler::SetTopState(State *firstState)
|
void StateMachineHandler::SetCurrentState(State *firstState)
|
||||||
{
|
{
|
||||||
pFirstState = firstState;
|
pFirstState = firstState;
|
||||||
}
|
}
|
||||||
|
|
|
@ -298,7 +298,7 @@ protected:
|
||||||
*
|
*
|
||||||
* @param firstState - First state.[in]
|
* @param firstState - First state.[in]
|
||||||
*/
|
*/
|
||||||
void SetTopState(State *firstState) override;
|
void SetCurrentState(State *firstState) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description : Transition to orther state.
|
* @Description : Transition to orther state.
|
||||||
|
@ -375,7 +375,7 @@ public:
|
||||||
*
|
*
|
||||||
* @param firstState - Initialization State.[in]
|
* @param firstState - Initialization State.[in]
|
||||||
*/
|
*/
|
||||||
void SetTopState(State *firstState);
|
void SetCurrentState(State *firstState);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description : State transition function.
|
* @Description : State transition function.
|
||||||
|
|
|
@ -7,8 +7,16 @@ include_directories(
|
||||||
./src
|
./src
|
||||||
./tool/include
|
./tool/include
|
||||||
${HUNTTING_MAIN_INCLUDE_PATH}
|
${HUNTTING_MAIN_INCLUDE_PATH}
|
||||||
|
${MIDDLEWARE_SOURCE_PATH}/McuManager/include
|
||||||
|
${MIDDLEWARE_SOURCE_PATH}/McuManager/src
|
||||||
|
${UTILS_SOURCE_PATH}/McuProtocol/include
|
||||||
|
${UTILS_SOURCE_PATH}/UartDevice/include
|
||||||
${TEST_SOURCE_PATH}
|
${TEST_SOURCE_PATH}
|
||||||
|
${TEST_SOURCE_PATH}/middleware/McuManager/tool/include
|
||||||
|
${TEST_SOURCE_PATH}/utils/LinuxApiMock/include
|
||||||
${TEST_SOURCE_PATH}/utils/TestManager/include
|
${TEST_SOURCE_PATH}/utils/TestManager/include
|
||||||
|
${TEST_SOURCE_PATH}/utils/McuProtocol/tool/include
|
||||||
|
${TEST_SOURCE_PATH}/utils/UartDevice/tool/include
|
||||||
${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
|
||||||
)
|
)
|
||||||
|
@ -26,7 +34,7 @@ endif()
|
||||||
|
|
||||||
set(TARGET_NAME HunttingCameraTest)
|
set(TARGET_NAME HunttingCameraTest)
|
||||||
add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES})
|
add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES})
|
||||||
target_link_libraries(${TARGET_NAME} HunttingMainLib McuManagerTestTool TestManager gtest gmock pthread)
|
target_link_libraries(${TARGET_NAME} HunttingMainLib McuManagerTestTool McuAskBaseTestTool TestManager gtest gmock pthread)
|
||||||
if(${TEST_COVERAGE} MATCHES "true")
|
if(${TEST_COVERAGE} MATCHES "true")
|
||||||
target_link_libraries(${TARGET_NAME} gcov)
|
target_link_libraries(${TARGET_NAME} gcov)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -15,11 +15,12 @@
|
||||||
#include "GtestUsing.h"
|
#include "GtestUsing.h"
|
||||||
#include "ILog.h"
|
#include "ILog.h"
|
||||||
#include "MainThread.h"
|
#include "MainThread.h"
|
||||||
|
#include "McuManagerTestTool.h"
|
||||||
#include "TestManager.h"
|
#include "TestManager.h"
|
||||||
#include <thread>
|
#include <thread>
|
||||||
namespace HunttingCameraTest
|
namespace HunttingCameraTest
|
||||||
{
|
{
|
||||||
class HunttingCameraTest : public testing::Test, public TestManager
|
class HunttingCameraTest : public testing::Test, public TestManager, public McuManagerTestTool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HunttingCameraTest() {}
|
HunttingCameraTest() {}
|
||||||
|
@ -37,6 +38,11 @@ public:
|
||||||
// HunttingCameraTestTool::Init();
|
// HunttingCameraTestTool::Init();
|
||||||
// CreateHalCppModule();
|
// CreateHalCppModule();
|
||||||
// CreateDeviceManagerModule();
|
// CreateDeviceManagerModule();
|
||||||
|
mLinuxTest = LinuxTest::CreateLinuxTest();
|
||||||
|
std::shared_ptr<LinuxApiMock> test = mLinuxTest;
|
||||||
|
LinuxApiMock::GetInstance(&test);
|
||||||
|
LinuxApiMock::GetInstance()->Init();
|
||||||
|
McuManagerTestTool::Init(mLinuxTest);
|
||||||
TestManager::Init();
|
TestManager::Init();
|
||||||
}
|
}
|
||||||
virtual void TearDown()
|
virtual void TearDown()
|
||||||
|
@ -46,7 +52,16 @@ public:
|
||||||
// DestroyDeviceManagerModule();
|
// DestroyDeviceManagerModule();
|
||||||
// DestroyAllKeysMock();
|
// DestroyAllKeysMock();
|
||||||
TestManager::UnInit();
|
TestManager::UnInit();
|
||||||
|
LinuxApiMock::GetInstance()->UnInit();
|
||||||
|
mLinuxTest = std::make_shared<LinuxTest>();
|
||||||
|
std::shared_ptr<LinuxApiMock> test = std::make_shared<LinuxApiMock>();
|
||||||
|
LinuxApiMock::GetInstance(&test);
|
||||||
|
McuManagerTestTool::UnInit();
|
||||||
|
MainThread::GetInstance()->UnInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::shared_ptr<LinuxTest> mLinuxTest;
|
||||||
};
|
};
|
||||||
// ../output_files/test/bin/HunttingCameraTest --gtest_filter=HunttingCameraTest.INTEGRATION_DeviceManager_EXAMPLE_Demo
|
// ../output_files/test/bin/HunttingCameraTest --gtest_filter=HunttingCameraTest.INTEGRATION_DeviceManager_EXAMPLE_Demo
|
||||||
TEST_F(HunttingCameraTest, INTEGRATION_DeviceManager_EXAMPLE_Demo)
|
TEST_F(HunttingCameraTest, INTEGRATION_DeviceManager_EXAMPLE_Demo)
|
||||||
|
@ -54,6 +69,5 @@ TEST_F(HunttingCameraTest, INTEGRATION_DeviceManager_EXAMPLE_Demo)
|
||||||
MainThread::GetInstance()->Init();
|
MainThread::GetInstance()->Init();
|
||||||
TestManager::ResetTimeOut(1000 * 3);
|
TestManager::ResetTimeOut(1000 * 3);
|
||||||
MainThread::GetInstance()->Runing();
|
MainThread::GetInstance()->Runing();
|
||||||
MainThread::GetInstance()->UnInit();
|
|
||||||
}
|
}
|
||||||
} // namespace HunttingCameraTest
|
} // namespace HunttingCameraTest
|
|
@ -9,6 +9,7 @@ include_directories(
|
||||||
${UTILS_SOURCE_PATH}/Log/include
|
${UTILS_SOURCE_PATH}/Log/include
|
||||||
${UTILS_SOURCE_PATH}/McuProtocol/include
|
${UTILS_SOURCE_PATH}/McuProtocol/include
|
||||||
${MIDDLEWARE_SOURCE_PATH}/McuManager/src
|
${MIDDLEWARE_SOURCE_PATH}/McuManager/src
|
||||||
|
${TEST_SOURCE_PATH}
|
||||||
${TEST_SOURCE_PATH}/utils/LinuxApiMock/include
|
${TEST_SOURCE_PATH}/utils/LinuxApiMock/include
|
||||||
${TEST_SOURCE_PATH}/utils/McuProtocol/tool/include
|
${TEST_SOURCE_PATH}/utils/McuProtocol/tool/include
|
||||||
)
|
)
|
||||||
|
|
|
@ -14,40 +14,10 @@
|
||||||
*/
|
*/
|
||||||
#ifndef MCU_MANAGER_TEST_TOOL_H
|
#ifndef MCU_MANAGER_TEST_TOOL_H
|
||||||
#define MCU_MANAGER_TEST_TOOL_H
|
#define MCU_MANAGER_TEST_TOOL_H
|
||||||
|
#include "GtestUsing.h"
|
||||||
#include "LinuxApiMock.h"
|
#include "LinuxApiMock.h"
|
||||||
#include "McuManagerImpl.h"
|
#include "McuManagerImpl.h"
|
||||||
#include "McuProtocolTestTool.h"
|
#include "McuProtocolTestTool.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 McuManagerImplTest : public McuManagerImpl
|
class McuManagerImplTest : public McuManagerImpl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -32,6 +32,8 @@ void CancelOverrideMcuManagerMakePtrObject(void)
|
||||||
if (test) {
|
if (test) {
|
||||||
test->mMcuManagerMock.reset();
|
test->mMcuManagerMock.reset();
|
||||||
}
|
}
|
||||||
|
tmp.reset();
|
||||||
|
test.reset();
|
||||||
std::shared_ptr<McuManagerMakePtr> impl = std::make_shared<McuManagerMakePtr>();
|
std::shared_ptr<McuManagerMakePtr> impl = std::make_shared<McuManagerMakePtr>();
|
||||||
McuManagerMakePtr::GetInstance(&impl);
|
McuManagerMakePtr::GetInstance(&impl);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ void McuManagerTestTool::Init(std::shared_ptr<LinuxTest> &mock)
|
||||||
}
|
}
|
||||||
void McuManagerTestTool::UnInit(void)
|
void McuManagerTestTool::UnInit(void)
|
||||||
{
|
{
|
||||||
|
LogInfo("McuManagerTestTool::UnInit\n");
|
||||||
mMcuManagerMock.reset();
|
mMcuManagerMock.reset();
|
||||||
CancelOverrideMcuManagerMakePtrObject();
|
CancelOverrideMcuManagerMakePtrObject();
|
||||||
UartDeviceTestTool::UnregisterUartDevice(gUartDevice);
|
UartDeviceTestTool::UnregisterUartDevice(gUartDevice);
|
||||||
|
|
|
@ -122,12 +122,12 @@ void McuProtocolTestTool::UnInit(void)
|
||||||
}
|
}
|
||||||
mSerialNumberList.clear();
|
mSerialNumberList.clear();
|
||||||
if (mPipeFdMockSelectInit) {
|
if (mPipeFdMockSelectInit) {
|
||||||
|
mPipeFdMockSelectInit = false;
|
||||||
close(mPipeFdMockSelect[PIPE_READ_FD_INDEX]);
|
close(mPipeFdMockSelect[PIPE_READ_FD_INDEX]);
|
||||||
close(mPipeFdMockSelect[PIPE_WRITE_FD_INDEX]);
|
close(mPipeFdMockSelect[PIPE_WRITE_FD_INDEX]);
|
||||||
mPipeFdMockSelect[PIPE_READ_FD_INDEX] = -1;
|
mPipeFdMockSelect[PIPE_READ_FD_INDEX] = -1;
|
||||||
mPipeFdMockSelect[PIPE_WRITE_FD_INDEX] = -1;
|
mPipeFdMockSelect[PIPE_WRITE_FD_INDEX] = -1;
|
||||||
}
|
}
|
||||||
mPipeFdMockSelectInit = false;
|
|
||||||
mUartFd = INVALID_FD;
|
mUartFd = INVALID_FD;
|
||||||
std::shared_ptr<ProtocolMonitor> monitor = std::make_shared<ProtocolMonitor>();
|
std::shared_ptr<ProtocolMonitor> monitor = std::make_shared<ProtocolMonitor>();
|
||||||
ProtocolMonitor::GetInstance(&monitor);
|
ProtocolMonitor::GetInstance(&monitor);
|
||||||
|
@ -182,6 +182,10 @@ void McuProtocolTestTool::ReplySelectSucceed(std::shared_ptr<LinuxTest> &mock, c
|
||||||
selectResult = select(mPipeFdMockSelect[PIPE_READ_FD_INDEX] + 1, &fdsRead, NULL, NULL, timeout);
|
selectResult = select(mPipeFdMockSelect[PIPE_READ_FD_INDEX] + 1, &fdsRead, NULL, NULL, timeout);
|
||||||
if (selectResult) {
|
if (selectResult) {
|
||||||
// Do nothing here.
|
// Do nothing here.
|
||||||
|
if (false == mPipeFdMockSelectInit) {
|
||||||
|
LogWarning("mPipeFdMockSelectInit = false.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
ssize_t length = read(mPipeFdMockSelect[PIPE_READ_FD_INDEX], buf, READ_BUF_LENGTH);
|
ssize_t length = read(mPipeFdMockSelect[PIPE_READ_FD_INDEX], buf, READ_BUF_LENGTH);
|
||||||
if (READ_FAILD == length) {
|
if (READ_FAILD == length) {
|
||||||
LogError("mPipeFdMockSelect failed.\n");
|
LogError("mPipeFdMockSelect failed.\n");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user