⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 voip_auto_test.c

📁 telcobridges voip develop
💻 C
📖 第 1 页 / 共 2 页
字号:
			FRED,
			"VoipStartTestConnect01: %s\n", TBX_ERROR_DESCRIPTION);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{
	}

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipStartStressTest01			:	This test will send a notification to the test controller that the test succeed
 |
 |	in_hMsg							:	Message received
 |  in_pszTestParameter				:	Parameters of the test
 |									
 |  Note							:	~
 |									
 |  Return							:	TBX_RESULT_OK if the function succeeded
 |										Other error code if the function could not complete properly.
 |								
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipStartStressTest01
(
	IN		TBX_MSG_HANDLE				in_hMsg,
	IN		PTBX_CHAR					in_pszTestParameter
)
{
	VOIP_EVT_OP_START_STRESS_TEST	StressTestEvent;
	TBX_ADAPTER_HANDLE				hAdapter = 0;
	TBX_CHAR						szAdapterName [128];
	PVOIP_ADAPTER_CONTEXT			pAdapterContext;
	PVOIP_ADAPTER_CONTEXT_NODE		pAdapterContextNode;
	
	TBX_RESULT						Result = TBX_RESULT_OK;

	TBX_UINT						un32Ip0,un32Ip1,un32Ip2,un32Ip3;
	TBX_UINT						un32TestDurationSec;
	TBX_UINT						un32FirstType;
	TBX_UINT						un32NbConnPerSec;
	TBX_UINT						un32MinDur;
	TBX_UINT						un32MaxDur;
	TBX_UINT						un32fAbortOnFailure;
	TBX_UINT						un32fDisconnectUponStartup;
	TBX_UINT						un32fDoBertTests;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* initialize local variable */
		pAdapterContext = NULL;
		pAdapterContextNode = NULL;
		un32Ip0 = 127;
		un32Ip1 = 0;
		un32Ip2 = 0;
		un32Ip3 = 1;
		un32TestDurationSec = (TBX_UINT32)-1;
		un32FirstType = 0;
		un32NbConnPerSec = 250;
		un32MinDur = 0;
		un32MaxDur = 4;
		un32fAbortOnFailure = TBX_TRUE;
		un32fDisconnectUponStartup = TBX_TRUE;
		un32fDoBertTests = TBX_TRUE;

		/* Parse the stress-test parameter line */
		sscanf (in_pszTestParameter, VOIP_TEST_STRESS_TEST_START_ARGUMENTS,
			&un32Ip0, &un32Ip1, &un32Ip2, &un32Ip3,
			&un32TestDurationSec,
			&un32FirstType, &un32NbConnPerSec, &un32MinDur, &un32MaxDur,
			&un32fAbortOnFailure, &un32fDisconnectUponStartup, &un32fDoBertTests,
			szAdapterName);

		TbxCliToolsLogPrint(
			g_pContext->CliContext.hCliTools,
			TRACE_LEVEL_ALWAYS,
			FGREEN,
			"VoipStartStressTest01 started with parameter: %s\n", in_pszTestParameter );
		
		/* start stress test */
		sprintf (StressTestEvent.szStreamSocketIP, "%d.%d.%d.%d", un32Ip0, un32Ip1, un32Ip2, un32Ip3);
		StressTestEvent.FirstResType						= un32FirstType;
		StressTestEvent.un32ConnectionsPerSecond			= un32NbConnPerSec;
		StressTestEvent.un32MinConnectionDuration			= un32MinDur;
		StressTestEvent.un32MaxConnectionDuration			= un32MaxDur;
		StressTestEvent.fAutoAbort							= un32fAbortOnFailure;
		StressTestEvent.fClearOpenedConnectionUponStartup	= un32fDisconnectUponStartup;
		StressTestEvent.fDoBertTests						= un32fDoBertTests;
		StressTestEvent.un32TestDurationInSec				= un32TestDurationSec;

		/* Adapter ready. Check if it is one of the adapters we are using...  */
		pAdapterContextNode = TBXPoolOfBuffersFind
		(
			g_pContext->hPoolOfAdapters,
			(TBX_HASH_KEY)szAdapterName
		);
		if ((pAdapterContextNode == NULL) || (pAdapterContextNode->pAdapterContext == NULL))
		{
			TbxCliToolsLogPrint(
				g_pContext->CliContext.hCliTools,
				TRACE_LEVEL_ERROR,
				FRED,
				"Adapter %s not found/valid\n", szAdapterName);
			TBX_EXIT_ERROR (TBX_RESULT_NOT_FOUND, 0, "Adapter not found/valid");
		}
		pAdapterContext = pAdapterContextNode->pAdapterContext;

		VoipStressTestStart( pAdapterContext, &StressTestEvent );

		TBX_EXIT_SUCCESS (TBX_RESULT_OK);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		TbxCliToolsLogPrint(
			g_pContext->CliContext.hCliTools,
			TRACE_LEVEL_ERROR,
			FRED,
			"VoipStartStressTest01: %s\n", TBX_ERROR_DESCRIPTION);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{
		/* send confirmation */
		Result = TBTestLibSendConfirmStartTestMessage
		(
			g_pContext->hTbxLib,
			TBX_MSG_ADAPTER_HANDLE_GET( in_hMsg ),
			0,
			g_pContext->TestModeContext.un32TestId,
			(TBX_RESULT_FAILURE(TBX_ERROR_RESULT)?TBX_RESULT_AUTOTEST_FAIL:TBX_RESULT_AUTOTEST_OK)
		);
		if( TBX_RESULT_FAILURE( Result ) )
		{
			TbxCliToolsLogPrint(
				g_pContext->CliContext.hCliTools,
				TRACE_LEVEL_ERROR,
				FRED,
				"Start test confirmation message failed: 0x%X\n", Result);
		}
	}

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipStopStressTest01			:	This test will send a notification to the test controller that the test succeed
 |
 |	in_hMsg							:	Message received
 |  in_pszTestParameter				:	Parameters of the test
 |									
 |  Note							:	~
 |									
 |  Return							:	TBX_RESULT_OK if the function succeeded
 |										Other error code if the function could not complete properly.
 |								
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipStopStressTest01
(
	IN		TBX_MSG_HANDLE				in_hMsg,
	IN		PTBX_CHAR					in_pszTestParameter
)
{
	TBX_RESULT						Result = TBX_RESULT_OK;
	TBX_RESULT						TestResult = TBX_RESULT_OK;
	TBX_CHAR						szAdapterName [128];
	PVOIP_ADAPTER_CONTEXT			pAdapterContext;
	PVOIP_ADAPTER_CONTEXT_NODE		pAdapterContextNode;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* initialize local variable */
		pAdapterContext = NULL;
		pAdapterContextNode = NULL;

		/* Parse the stress-test parameter line */
		sscanf (in_pszTestParameter, VOIP_TEST_STRESS_TEST_STOP_ARGUMENTS,
			szAdapterName);

		/* Adapter ready. Check if it is one of the adapters we are using...  */
		pAdapterContextNode = TBXPoolOfBuffersFind
		(
			g_pContext->hPoolOfAdapters,
			(TBX_HASH_KEY)szAdapterName
		);
		if ((pAdapterContextNode == NULL) || (pAdapterContextNode->pAdapterContext == NULL))
		{
			TbxCliToolsLogPrint(
				g_pContext->CliContext.hCliTools,
				TRACE_LEVEL_ERROR,
				FRED,
				"Adapter %s not found/valid\n", szAdapterName);
			TBX_EXIT_ERROR (TBX_RESULT_NOT_FOUND, 0, "Adapter not found/valid");
		}
		pAdapterContext = pAdapterContextNode->pAdapterContext;

		TbxCliToolsLogPrint(
			g_pContext->CliContext.hCliTools,
			TRACE_LEVEL_ALWAYS,
			FGREEN,
			"VoipStopStressTest01 is stopping\n" );

		VoipStressTestStop( pAdapterContext );

		/* Check if the test failed */
		if ((pAdapterContext->StressTest.Stats.un64MaxBertErrorFound > VOIP_STRESS_TEST_MAX_BER_ERROR_ACCEPTED) ||
			(pAdapterContext->StressTest.Stats.un64NbConnectionsFailed > 0) ||
			(pAdapterContext->StressTest.Stats.un64NbConnectionsAttempt == 0))
		{
			TestResult = TBX_RESULT_FAIL;

			TbxCliToolsLogPrint(
				g_pContext->CliContext.hCliTools,
				TRACE_LEVEL_ERROR,
				FRED,
				"VoipStopStressTest01: Test FAILED (MaxBertErrorFound=%u, NbConnFailed=%u, NbConnAttempt=%u)\n", 
				pAdapterContext->StressTest.Stats.un64MaxBertErrorFound,
				pAdapterContext->StressTest.Stats.un64NbConnectionsFailed,
				pAdapterContext->StressTest.Stats.un64NbConnectionsAttempt);

		}	

		TBX_EXIT_SUCCESS (TBX_RESULT_OK);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		TbxCliToolsLogPrint(
			g_pContext->CliContext.hCliTools,
			TRACE_LEVEL_ERROR,
			FRED,
			"VoipStopStressTest01: %s\n", TBX_ERROR_DESCRIPTION);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{
		/* send confirmation */
		Result = TBTestLibSendConfirmStopTestMessage
		(
			g_pContext->hTbxLib,
			TBX_MSG_ADAPTER_HANDLE_GET( in_hMsg ),
			0,
			g_pContext->TestModeContext.un32TestId,
			(TBX_RESULT_FAILURE(TBX_ERROR_RESULT)?TBX_RESULT_AUTOTEST_FAIL:TestResult)
		);
		if( TBX_RESULT_FAILURE( Result ) )
		{
			TbxCliToolsLogPrint(
				g_pContext->CliContext.hCliTools,
				TRACE_LEVEL_ERROR,
				FRED,
				"Stop test confirmation message failed: 0x%X\n", Result);
		}
	}

	RETURN;
}



/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipStopStressTest01ByItself    :	This test will send a notification to the test controller that the test succeed
 |
 |  in_pszAdapterName				:	Adapter name on which the test was stopped
 |	in_result						:	Result of the test stop
 |									
 |  Note							:	~
 |									
 |  Return							:	TBX_RESULT_OK if the function succeeded
 |										Other error code if the function could not complete properly.
 |								
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipStopStressTest01ByItself
(
	IN		PTBX_CHAR					in_pszAdapterName,
	IN		TBX_RESULT					in_result
)
{
	TBX_RESULT						Result = TBX_RESULT_OK;
	TBX_RESULT						TestResult = TBX_RESULT_OK;
	PVOIP_ADAPTER_CONTEXT			pAdapterContext;
	PVOIP_ADAPTER_CONTEXT_NODE		pAdapterContextNode;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* initialize local variable */
		pAdapterContext = NULL;
		pAdapterContextNode = NULL;

		/* Adapter ready. Check if it is one of the adapters we are using...  */
		pAdapterContextNode = TBXPoolOfBuffersFind
		(
			g_pContext->hPoolOfAdapters,
			(TBX_HASH_KEY)in_pszAdapterName
		);
		if ((pAdapterContextNode == NULL) || (pAdapterContextNode->pAdapterContext == NULL))
		{
			TbxCliToolsLogPrint(
				g_pContext->CliContext.hCliTools,
				TRACE_LEVEL_ERROR,
				FRED,
				"Adapter %s not found/valid\n", in_pszAdapterName);
			TBX_EXIT_ERROR (TBX_RESULT_NOT_FOUND, 0, "Adapter not found/valid");
		}
		pAdapterContext = pAdapterContextNode->pAdapterContext;

		TbxCliToolsLogPrint(
			g_pContext->CliContext.hCliTools,
			TRACE_LEVEL_ALWAYS,
			FGREEN,
			"VoipStopStressTest01 is stopping\n" );

		VoipStressTestStop( pAdapterContext );

		/* Check if the test failed */
		if ((pAdapterContext->StressTest.Stats.un64MaxBertErrorFound > VOIP_STRESS_TEST_MAX_BER_ERROR_ACCEPTED) ||
			(pAdapterContext->StressTest.Stats.un64NbConnectionsFailed > 0) ||
			(pAdapterContext->StressTest.Stats.un64NbConnectionsAttempt == 0) ||
			TBX_RESULT_FAILURE(in_result))
		{
			TestResult = TBX_RESULT_FAIL;

			TbxCliToolsLogPrint(
				g_pContext->CliContext.hCliTools,
				TRACE_LEVEL_ERROR,
				FRED,
				"VoipStopStressTest01ByItself: Test FAILED (MaxBertErrorFound=%u, NbConnFailed=%u, NbConnAttempt=%u,result=0x%08X)\n", 
				(TBX_UINT32)pAdapterContext->StressTest.Stats.un64MaxBertErrorFound,
				(TBX_UINT32)pAdapterContext->StressTest.Stats.un64NbConnectionsFailed,
				(TBX_UINT32)pAdapterContext->StressTest.Stats.un64NbConnectionsAttempt,
				in_result);
		}	

		TBX_EXIT_SUCCESS (TBX_RESULT_OK);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		TbxCliToolsLogPrint(
			g_pContext->CliContext.hCliTools,
			TRACE_LEVEL_ERROR,
			FRED,
			"VoipStopStressTest01ByItself: %s\n", TBX_ERROR_DESCRIPTION);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{
		/* send confirmation */
		Result = TBTestLibSendConfirmTestTerminateMessage
		(
			g_pContext->hTbxLib,
			g_pContext->TestModeContext.hHostHandle,
			0,
			g_pContext->TestModeContext.un32TestId,
			(TBX_RESULT_FAILURE(TBX_ERROR_RESULT)?TBX_RESULT_AUTOTEST_FAIL:TestResult)
		);
		if( TBX_RESULT_FAILURE( Result ) )
		{
			TbxCliToolsLogPrint(
				g_pContext->CliContext.hCliTools,
				TRACE_LEVEL_ERROR,
				FRED,
				"Stop test confirmation message failed: 0x%X\n", Result);
		}
	}

	RETURN;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -