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