Selaa lähdekoodia

Z991239-385 #comment 添加压力测试实体mod_highVoltage

gifur 5 vuotta sitten
vanhempi
sitoutus
6b180e2857

+ 4 - 3
addin/cfg/shell.ini.in

@@ -14,7 +14,7 @@ TestPassiveEntity=0,@LIB_PREFIX@mod_testPassiveEntity@LIB_SUFFIX@,0x108
 TestPassiveSecondEntity=0,@LIB_PREFIX@mod_testPassiveEntity@LIB_SUFFIX@,0x109
 TestPassiveThirdEntity=0,@LIB_PREFIX@mod_testPassiveEntity@LIB_SUFFIX@,0x10A
 TestLogSender=0,@LIB_PREFIX@mod_testSendLog@LIB_SUFFIX@,0x10B
-
+HighVoltage=0,@LIB_PREFIX@mod_highVoltage@LIB_SUFFIX@,0x10C
 [Startup]
 Number=2
 1=HelloService
@@ -23,15 +23,16 @@ Number=2
 [SysEvent]
 SampleState=SampleEntity;TestDeamon;HelloClient HelloService,"0"
 PrivilegeState=TestPrivilegeEntity	TestNormalEntity,"the max length of this system value cannot exceed to 260 include end char"
-
+AlwaysUpdate=HighVoltage,"0"
 [Test]
-Number=6
+Number=7
 1=TestDeamon TestMode=ON Level=3 Entity=BlackSheep -D
 2=TestSubscribe
 3=SampleEntity
 4=TestLogSender
 5=TestNormalEntity
 6=TestPrivilegeEntity
+7=HighVoltage
 
 [Debug]
 TestDeamon=1

+ 1 - 0
module/CMakeLists.txt

@@ -40,6 +40,7 @@ macro(add_module_libraries _module_prefix _module_name _module_version)
         set(${_module_prefix}_SRCS ${${_module_prefix}_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
     endif(WIN32)
     add_library(${_module_name} SHARED ${${_module_prefix}_SRCS})
+    target_include_directories(${_module_name} PRIVATE ${MODULE_BASE_DIR}/include)
     # ÉèÖù¤³ÌÊä³ö·¾¶
     if(SIMULATE_DEV_AND_TEST_TEMP)
         set_target_properties(${_module_name} 

+ 233 - 0
module/include/mod_highVoltageBase.hpp

@@ -0,0 +1,233 @@
+#ifndef _MOD_HIGH_VOLTAGE_BASE_H__
+#define _MOD_HIGH_VOLTAGE_BASE_H__
+
+#include "stdafx.h"
+#include "SpBase.h"
+#include "SpTest.h"
+
+/*one of test module: use to high voltage test*/
+
+namespace HighVoltage
+{
+#define eMsg_MessageBroadcase1 0
+#define eMsg_MessageBroadcase2 0
+
+#define eMsgSig_MessageBroadcase1 4367746706
+#define eMsgSig_MessageBroadcase2 4367746606
+
+	struct MessageBroadcase1
+	{
+		CSimpleStringA context;
+
+		void Serialize(SpBuffer& Buf)
+		{
+			auto& buf = Buf & context;
+		}
+	};
+
+	struct MessageBroadcase2
+	{
+		CSimpleStringA context;
+
+		void Serialize(SpBuffer& Buf)
+		{
+			auto& buf = Buf & context;
+		}
+	};
+}
+
+#include "HelloService_client_g.h"
+#include "SampleEntity_client_g.h"
+
+
+class SubSampleClient : public SampleEntity::SampleService_ClientBase
+{
+public:
+
+	SubSampleClient(CEntityBase* pEntity) :SampleService_ClientBase(pEntity) {}
+
+	void OnMessage(ErrorCodeEnum Error, SampleEntity::SampleService_SubscribeOverlap_Message_Info& Msg, CSmartPointer<IReleasable> pData)
+	{
+		LOG_FUNCTION();
+	}
+};
+
+class CHighVoltageBase : public CEntityBase
+{
+public:
+	CHighVoltageBase() {}
+	virtual ~CHighVoltageBase() {}
+
+	virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
+	{
+		LOG_FUNCTION();
+		pTransactionContext->SendAnswer(Error_Succeed);
+	}
+
+	virtual void OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer<ITransactionContext> pTransactionContext)
+	{
+		LOG_FUNCTION();
+		pTransactionContext->SendAnswer(Error_Succeed);
+	}
+
+	void CHighVoltageBase::OnStarted()
+	{
+
+	}
+
+	void OnExam(CSmartPointer<ITransactionContext> pTransactionContext)
+	{
+		pTransactionContext->SendAnswer(Error_Succeed);
+		TestCaseInvoke();
+	}
+
+	virtual void TestCaseInvoke();
+
+	void UpdateSysVal()
+	{
+		LOG_FUNCTION();
+
+		UINT64 uTimes = 0;
+
+		const char* lpcszSysValStr[] = {
+			"fsfjlkmfdklfasjff;iewjfofdnfksdfdsnfdsklfjsdlffdf332231u09-9=-89=-90764sdffsfdsf3erwerwo",
+			"wpkopmnoinvoivncoihsdjfo3h32898y12u3hujeop[pokl;k.ghsadhdjkw3oeqoiqjhiokqrjh3hoqh2j1k2jefjklajl"
+		};
+
+		do {
+
+			CSimpleStringA strValue;
+			IFFAILBREAK(GetFunction()->GetSysVar("AlwaysUpdate", strValue));
+			if (strValue.Compare(lpcszSysValStr[0]) == 0)
+				strValue = lpcszSysValStr[1];
+			else
+				strValue = lpcszSysValStr[0];
+			IFFAILBREAK(GetFunction()->SetSysVar("AlwaysUpdate", strValue, true));
+
+			LogEvent(Severity_Low, 0, CSimpleStringA::Format("%s operates %lld times.", __FUNCTION__, ++uTimes));
+
+
+		} while (true);
+	}
+
+	void SendBroadCast()
+	{
+		LOG_FUNCTION();
+
+		UINT64 uTimes = 0;
+
+		do {
+
+			HighVoltage::MessageBroadcase1 broad1;
+			broad1.context = "broad1::v.cmljgoeirjoaiwenaksldfnmjdsofidjvoivvksldgfmliejwofjaweofiasdkfljsdfjsd;foijoeifje";
+			IFFAILBREAK(SpSendBroadcast(GetFunction(), SP_MSG_OF(MessageBroadcase1), SP_MSG_SIG_OF(MessageBroadcase1), broad1));
+
+			HighVoltage::MessageBroadcase2 broad2;
+			broad2.context = "broad2::v.cmljgoeirjoaiwenaksldfnmjdsofidjvoivvksldgfmliejwofjaweofiasdkfljsdfjsd;foijoeifje";
+			IFFAILBREAK(SpSendBroadcast(GetFunction(), SP_MSG_OF(MessageBroadcase2), SP_MSG_SIG_OF(MessageBroadcase2), broad2));
+
+
+			LogEvent(Severity_Low, 0, CSimpleStringA::Format("%s operates %lld times.", __FUNCTION__, ++uTimes));
+
+		} while (true);
+	}
+
+	void CommunicateWithRemoteEntity()
+	{
+		LOG_FUNCTION();
+
+		UINT64 uTimes = 0;
+		do {
+
+			SubSampleClient* sampleClient = new SubSampleClient(this);
+			IFFAILBREAK(sampleClient->Connect());
+
+			{
+				SampleEntity::SampleService_OnewayFuncOverlap_Info info;
+				info.req_context = "SampleService_OnewayFuncOverlap_Info::xvmx.cvmsifjwoejklfjlkdfsdjfoiwjeiofjlsfsdgjlfdg";
+				IFFAILBREAK(sampleClient->OnewayFuncOverlap(info));
+			}
+
+			{
+				SampleEntity::SampleService_OnewayFuncNormal_Info info;
+				info.tstring = "SampleService_OnewayFuncNormal_Info::tstring::xvmx.cvmsifjwoejklfjlkdfsdjfoiwjeiofjlsfsdgjlfdg";
+				info.twstring = L"SampleService_OnewayFuncNormal_Info::twstring::xvmx.cvmsifjwoejklfjlkdfsdjfoiwjeiofjlsfsdgjlfdg";
+				IFFAILBREAK(sampleClient->OnewayFuncNormal(info));
+			}
+
+			{
+				SampleEntity::SampleService_TwoWayFuncNormal_Req Req;
+				SampleEntity::SampleService_TwoWayFuncNormal_Ans Ans;
+
+				Req.tbool = true;
+				Req.tchar = 'I';
+				Req.tint = 123;
+				Req.tuint = 123;
+				Req.tshort = 123;
+				Req.tushort = 123;
+				Req.tuchar = 'I';
+				Req.tstring = "SampleService_TwoWayFuncNormal_Req::tstring::xclvmsdiofjweoij3r283908u238925j4ioijn;klgnfakjsfsfhffjeoiwjhoi";
+				Req.twstring = "SampleService_TwoWayFuncNormal_Req::twstring::xclvmsdiofjweoij3r283908u238925j4ioijn;klgnfakjsfsfhffjeoiwjhoi";
+				Req.tfloat = 123.456;
+				Req.tdouble = 123.456;
+				Req.tblob.Clear();
+				Req.tint64 = 123;
+				Req.tuint64 = 123;
+
+				IFFAILBREAK(sampleClient->TwoWayFuncNormal(Req, Ans, 10000));
+
+			}
+		
+			sampleClient->GetFunction()->CloseSession();
+
+			LogEvent(Severity_Low, 0, CSimpleStringA::Format("%s operates %lld times.", __FUNCTION__, ++uTimes));
+
+		} while (true);
+	}
+};
+
+struct UpdateSysValTask : public ITaskSp
+{
+	UpdateSysValTask(CHighVoltageBase* pEntity) :m_pEntity(pEntity) {}
+	CHighVoltageBase* m_pEntity;
+	void Process()
+	{
+		m_pEntity->UpdateSysVal();
+	}
+};
+
+struct SendBroadCastTask : public ITaskSp
+{
+	SendBroadCastTask(CHighVoltageBase* pEntity) :m_pEntity(pEntity) {}
+	CHighVoltageBase* m_pEntity;
+	void Process()
+	{
+		m_pEntity->SendBroadCast();
+	}
+};
+
+struct CommunicateWithRemoteEntityTask : public ITaskSp
+{
+	CommunicateWithRemoteEntityTask(CHighVoltageBase* pEntity) :m_pEntity(pEntity) {}
+	CHighVoltageBase* m_pEntity;
+	void Process()
+	{
+		m_pEntity->CommunicateWithRemoteEntity();
+	}
+};
+
+void CHighVoltageBase::TestCaseInvoke()
+{
+	{
+		char szProcessID[12];
+		sprintf(szProcessID, "%u", GetCurrentProcessId());
+		MessageBoxA(NULL, szProcessID, "", MB_OK);
+	}
+
+	LOG_FUNCTION();
+	IFFAILBREAK(GetFunction()->PostThreadPoolTask(new UpdateSysValTask(this)));
+	IFFAILBREAK(GetFunction()->PostThreadPoolTask(new SendBroadCastTask(this)));
+	IFFAILBREAK(GetFunction()->PostThreadPoolTask(new CommunicateWithRemoteEntityTask(this)));
+}
+
+#endif //_MOD_HIGH_VOLTAGE_BASE_H__

+ 81 - 0
module/mod_sample/mod_SampleEntity.h

@@ -12,6 +12,81 @@
 
 using namespace SampleEntity;
 
+class SampleService_Session : public SampleService_ServerSessionBase
+{
+	virtual void Handle_OnewayFuncOverlap(SpOnewayCallContext<SampleService_OnewayFuncOverlap_Info>::Pointer ctx)
+	{
+		LOG_FUNCTION();
+		/// override by user
+	}
+
+	virtual void Handle_OnewayFuncNoOverlap(SpOnewayCallContext<SampleService_OnewayFuncNoOverlap_Info>::Pointer ctx)
+	{
+		LOG_FUNCTION();
+
+		/// override by user
+	}
+
+	virtual void Handle_OnewayFuncNormal(SpOnewayCallContext<SampleService_OnewayFuncNormal_Info>::Pointer ctx)
+	{
+		LOG_FUNCTION();
+
+		/// override by user
+	}
+
+	virtual void Handle_TwoWayFuncOverlap(SpReqAnsContext<SampleService_TwoWayFuncOverlap_Req, SampleService_TwoWayFuncOverlap_Ans>::Pointer ctx)
+	{
+		LOG_FUNCTION();
+
+		/// override by user
+
+		ctx->Answer();
+	}
+
+	virtual void Handle_TwoWayFuncNotOverlap(SpReqAnsContext<SampleService_TwoWayFuncNotOverlap_Req, SampleService_TwoWayFuncNotOverlap_Ans>::Pointer ctx)
+	{
+		LOG_FUNCTION();
+
+		/// override by user
+
+		ctx->Answer();
+	}
+
+	virtual void Handle_TwoWayFuncWithID(SpReqAnsContext<SampleService_TwoWayFuncWithID_Req, SampleService_TwoWayFuncWithID_Ans>::Pointer ctx)
+	{
+		LOG_FUNCTION();
+
+		/// override by user
+
+		ctx->Answer();
+	}
+
+	virtual void Handle_TwoWayFuncNormal(SpReqAnsContext<SampleService_TwoWayFuncNormal_Req, SampleService_TwoWayFuncNormal_Ans>::Pointer ctx)
+	{
+		LOG_FUNCTION();
+
+		/// override by user
+
+		ctx->Answer();
+	}
+
+	virtual void Handle_SubscribeOverlap(SpSubscribeContext<SampleService_SubscribeOverlap_Sub, SampleService_SubscribeOverlap_Message_Info>::Pointer ctx)
+	{
+		LOG_FUNCTION();
+
+		/// override by user
+
+	}
+
+	virtual void Handle_SubscribeOverlap_Cancel(SpOnewayCallContext<SampleService_SubscribeOverlap_Cancel_Info>::Pointer ctx)
+	{
+		LOG_FUNCTION();
+
+		/// override by user
+
+	}
+};
+
 class CSampleEntity : public CEntityBase, public ITestCaseSuite<CSampleEntity>
 {
 public:
@@ -22,6 +97,12 @@ public:
 
 	virtual bool IsMultiThread() const { return true; }
 
+	virtual CServerSessionBase* OnNewSession(const char* pszRemoteEntityName, const char* pszClass)
+	{
+		LOG_FUNCTION();
+		return new SampleService_Session();
+	}
+
 	virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
 	{
 		ErrorCodeEnum ec = Error_Succeed;

+ 19 - 0
module/mod_testHighVoltage/CMakeLists.txt

@@ -0,0 +1,19 @@
+# 定义实体名称
+define_moudle("highVoltage")
+
+set(${MODULE_PREFIX}_SRCS
+	mod_highVoltage.cpp)
+
+set(MOD_VERSION_STRING "1.0.0-dev1")
+
+add_module_libraries(${MODULE_PREFIX} ${MODULE_NAME} ${MOD_VERSION_STRING})
+target_include_directories(${MODULE_NAME}
+	PRIVATE ${MODULE_BASE_DIR}/mod_sample
+	PRIVATE ${MODULE_BASE_DIR}/mod_helloservice
+)
+
+# 添加实体需要依赖的其他共享库(包括系统库)
+set(${MODULE_PREFIX}_LIBS spbase winpr)
+target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
+
+deploy_module(${MODULE_PREFIX} ${MODULE_NAME})

+ 15 - 0
module/mod_testHighVoltage/mod_highVoltage.cpp

@@ -0,0 +1,15 @@
+#include "mod_highVoltageBase.hpp"
+
+/*one of test module: use to high voltage test*/
+
+class CHighVoltage : public CHighVoltageBase
+{
+public:
+	CHighVoltage() {}
+	virtual ~CHighVoltage() {}
+	virtual const char *GetEntityName() const { return "HighVoltage"; }
+};
+
+SP_BEGIN_ENTITY_MAP()
+	SP_ENTITY(CHighVoltage)
+SP_END_ENTITY_MAP()

+ 4 - 2
module/mod_validityVertifier/mod_validityVertifier.cpp

@@ -239,12 +239,14 @@ public:
 			if (IS_FAILURED(ec)) {
 				THROW_ERROR("Test for %s failed return %s!", result->strEntityName.GetData(), SpStrError(ec));
 			}
-			Dbg("Test %s succ.", result->strEntityName.GetData());
+			else {
+				LogEvent(Severity_High, 0, CSimpleStringA::Format("Test %s succ.", result->strEntityName.GetData()));
+			}
 		}
 	}
 
-
 private:
+
 	void RequireTerminalExit()
 	{
 		if (_testInfo.isTestMode) {

+ 2 - 1
spshell/spshell.cpp

@@ -746,6 +746,7 @@ void DisplayUsage()
 		"  --debug                                    -- 以Debug的模式运行程序\n"
 		"  --kill                                          -- 直接杀死程序相关进程\n"
 		"  --ipc <pipe,tcp>                      -- pipe: 实体间以管道的方式通信;tcp: 实体间以socket的方式通信\n"
+		"  --version                                  -- 查看相关模块的版本号和生成时间\n"
 	);
 
 	//sp_dbg_info(szHelp);
@@ -868,6 +869,7 @@ sp_cfg_start_args_t* DealWithArgs(int argc, char** argv)
 			printf("%s\n", GetFullVersionString());
 #endif //_WIN32
 			exit(0);
+			break;
 		}
 		break;
 		case 'H':
@@ -884,7 +886,6 @@ sp_cfg_start_args_t* DealWithArgs(int argc, char** argv)
 		while (optind < argc) {
 			//sp_dbg_warn("\t%s", argv[optind++]);
 		}
-			
 	}
 
 	if (args && args->start_entities != 0) {