!152 软总线新增用例

Merge pull request !152 from 张攀/master
This commit is contained in:
openharmony_ci 2022-10-11 02:25:55 +00:00 committed by Gitee
commit e9d765bf6d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 1087 additions and 96 deletions

View File

@ -25,6 +25,7 @@ static int32_t g_waitFlag = WAIT_DEF_VALUE;
static int32_t g_waitFlag4Data = WAIT_DEF_VALUE;
static int32_t g_waitFlag4Ctl = WAIT_DEF_VALUE;
static int32_t g_waitFlag4Proxy = WAIT_DEF_VALUE;
static int32_t g_waitFlag4Stream = WAIT_DEF_VALUE;
static int32_t g_passiveOpenRetFlag = SOFTBUS_OK;
static int32_t g_nodeOnlineCount = 0;
static int32_t g_nodeOfflineCount = 0;
@ -47,6 +48,7 @@ static ISessionListener* g_sessionlistener4Ctl = NULL;
static ISessionListener* g_sessionlistener4Pass = NULL;
static ISessionListener* g_sessionlistener4Perf = NULL;
static ISessionListener* g_sessionlistener4Proxy = NULL;
static ISessionListener* g_sessionlistener4Stream = NULL;
static IFileSendListener* g_fileSendListener = NULL;
static IFileReceiveListener* g_fileRecvListener = NULL;
@ -128,6 +130,12 @@ int Wait4Session(int timeout, WaitSessionType type)
hitFlag = 1;
}
break;
case SESSION_4STREAM:
if (g_waitFlag4Stream != WAIT_DEF_VALUE) {
LOG("Wait4Session[proxy] succ,flag:%d", g_waitFlag4Stream);
hitFlag = 1;
}
break;
default:
LOG("Wait4Session type error");
hitFlag = 1;
@ -157,6 +165,12 @@ int Wait4Session(int timeout, WaitSessionType type)
return SOFTBUS_ERR;
}
break;
case SESSION_4STREAM:
if (g_waitFlag4Stream != WAIT_SUCCESS_VALUE) {
LOG("Wait4Session[proxy] fail[exp:%d, real:%d]", WAIT_SUCCESS_VALUE, g_waitFlag4Stream);
return SOFTBUS_ERR;
}
break;
default:
return SOFTBUS_ERR;
}
@ -564,6 +578,31 @@ static void ProxyMessageReceived(int sessionId, const void* data, unsigned int d
}
}
static int StreamSessionOpened(int sessionId, int result)
{
LOG("[cb][stream]open session sessionId[%d],rst[%d]", sessionId, result);
if (result == SOFTBUS_OK) {
g_waitFlag4Stream = WAIT_SUCCESS_VALUE;
} else {
g_waitFlag4Stream = WAIT_FAIL_VALUE;
}
return SOFTBUS_OK;
}
static void StreamSessionClosed(int sessionId)
{
LOG("[cb][stream]close session sessionId[%d]", sessionId);
}
static void StreamReceived(int sessionId, const StreamData *data, const StreamData *ext, const StreamFrameInfo *frame)
{
if (data != NULL) {
LOG("[cb][stream]ByteRec sessionId:%d, data= %.*s.\n", sessionId, data->bufLen, data->buf);
g_waitFlag4Stream = WAIT_SUCCESS_VALUE;
}
}
void ResetWaitFlag(void)
{
g_waitFlag = WAIT_DEF_VALUE;
@ -1032,6 +1071,16 @@ ISessionListener* GetSessionListenser4Ctl(void)
return g_sessionlistener4Ctl;
}
ISessionListener* GetSessionListenser4Proxy(void)
{
return g_sessionlistener4Proxy;
}
ISessionListener* GetSessionListenser4Stream(void)
{
return g_sessionlistener4Stream;
}
IFileSendListener* GetSendFileListener(void)
{
return g_fileSendListener;
@ -1140,6 +1189,12 @@ void TestSetUp(void)
g_sessionlistener4Proxy->OnMessageReceived = ProxyMessageReceived;
g_sessionlistener4Proxy->OnBytesReceived = ProxyBytesReceived;
}
if (g_sessionlistener4Stream == NULL) {
g_sessionlistener4Stream = (ISessionListener*)calloc(1, sizeof(ISessionListener));
g_sessionlistener4Stream->OnSessionOpened = StreamSessionOpened;
g_sessionlistener4Stream->OnSessionClosed = StreamSessionClosed;
g_sessionlistener4Stream->OnStreamReceived = StreamReceived;
}
if (g_fileSendListener == NULL) {
g_fileSendListener = (IFileSendListener*)calloc(1, sizeof(IFileSendListener));
@ -1210,6 +1265,10 @@ void TestTearDown(void)
free(g_sessionlistener4Proxy);
g_sessionlistener4Proxy = NULL;
}
if (g_sessionlistener4Stream != NULL) {
free(g_sessionlistener4Stream);
g_sessionlistener4Stream = NULL;
}
if (g_fileRecvListener != NULL) {
free(g_fileRecvListener);

View File

@ -223,8 +223,12 @@ void SetCurrentSessionId4Ctl(int sessionId);
void SetCurrentSessionId4Proxy(int sessionId);
ISessionListener* GetSessionListenser4Data(void);
ISessionListener* GetSessionListenser4Ctl(void);
ISessionListener* GetSessionListenser4Proxy(void);
ISessionListener* GetSessionListenser4Stream(void);
SessionAttribute* GetSessionAttr4Ctl(void);
SessionAttribute* GetSessionAttr4Data(void);
SessionAttribute* GetSessionAttr4Proxy(void);
IFileReceiveListener* GetRecvFileListener(void);
IFileSendListener* GetSendFileListener(void);

View File

@ -30,6 +30,8 @@ static ISessionListener* g_sessionlist4File = NULL;
static ISessionListener* g_sessionlist4Proxy = NULL;
static ISessionListener *g_sessionlist4Stream = NULL;
static uint64_t g_transTimeEnd;
static const char* def_passwd = "OH2022@xa";
static const char* def_ssid = "OpenHarmony_Private_Net_01";
static const char* slave_ssid = "OpenHarmony_Private_Net_02";
@ -113,11 +115,37 @@ static void OnStreamSessionClosed(int sessionId)
LOG("[cb][stream]close session sid[%d]", sessionId);
}
static inline int GetNumberInStreamData(const char *streamData)
{
if (streamData[0] == '1') {
return (streamData[1] - '0');
} else if (streamData[0] == '2') {
return (streamData[1] - '0') * 10 + (streamData[2] - '0');
} else if (streamData[0] == '3') {
return (streamData[1] - '0') * 100 + (streamData[2] - '0') * 10 + (streamData[3] - '0');
} else if (streamData[0] == '4') {
return (streamData[1] - '0') * 1000 + (streamData[2] - '0') * 100 + (streamData[3] - '0' * 10 + (streamData[4] - '0'));
}
return -1;
}
static void StreamReceived(int sessionId, const StreamData *data, const StreamData *ext, const StreamFrameInfo *frame)
{
if (data != NULL) {
LOG("[cb][stream]ByteRec sid:%d, data= %.*s.\n", sessionId, data->bufLen, data->buf);
g_transTimeEnd = GetCurrentTimeOfMs();
int i = GetNumberInStreamData((const char *)data->buf);
if (i < 0) {
return;
}
if (i % 60 == 0)
{
LOG("### RECV IFREAMTime = %llu and counts = %d ", g_transTimeEnd, i );
} else
{
LOG("### RECV PFREAMTime = %llu and counts = %d ", g_transTimeEnd, i );
}
if (data != NULL) {
LOG("[cb][stream]Rec sid:%d, data= %.*s.\n", sessionId, data->bufLen, data->buf);
}
}
/* session callback for data */

View File

@ -208,7 +208,7 @@ HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_0500, Tes
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_0600
* @tc.name : CreateSessionServer input wrong value
* @tc.name : CreateSessionServer input pkg name null
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
@ -216,12 +216,86 @@ HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_0500, Tes
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_0600, TestSize.Level3)
{
int ret;
ISessionListener* listener = (ISessionListener*)malloc(sizeof(ISessionListener));
ret = CreateSessionServer(NULL, SESSION_NAME_DATA, GetSessionListenser4Data());
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "CreateSS[pkg name null]";
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA);
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS fail[session listener only malloc]";
listener->OnBytesReceived = NULL;
listener->OnMessageReceived = NULL;
listener->OnSessionClosed = NULL;
listener->OnSessionOpened = NULL;
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA, listener);
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "CreateSS success[session listener member=null]";
free(listener);
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_0700
* @tc.name : CreateSessionServer input session name null
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_0700, TestSize.Level3)
{
int ret;
ISessionListener* listener = (ISessionListener*)malloc(sizeof(ISessionListener));
ret = CreateSessionServer(DEF_PKG_NAME, NULL, GetSessionListenser4Data());
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "CreateSS[session name null]";
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA);
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS fail[session listener only malloc]";
listener->OnBytesReceived = NULL;
listener->OnMessageReceived = NULL;
listener->OnSessionClosed = NULL;
listener->OnSessionOpened = NULL;
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA, listener);
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "CreateSS success[session listener member=null]";
free(listener);
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_0800
* @tc.name : CreateSessionServer input session listener null
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_0800, TestSize.Level3)
{
int ret;
ISessionListener* listener = (ISessionListener*)malloc(sizeof(ISessionListener));
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA, NULL);
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "CreateSS[session listener null]";
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA);
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS fail[session listener only malloc]";
listener->OnBytesReceived = NULL;
listener->OnMessageReceived = NULL;
listener->OnSessionClosed = NULL;
listener->OnSessionOpened = NULL;
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA, listener);
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "CreateSS success[session listener member=null]";
free(listener);
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_0900
* @tc.name : CreateSessionServer input session listener only malloc
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_0900, TestSize.Level3)
{
int ret;
ISessionListener* listener = (ISessionListener*)malloc(sizeof(ISessionListener));
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA, listener);
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS fail[session listener only malloc]";
@ -239,31 +313,57 @@ HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_0600, Tes
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_0700
* @tc.name : RemoveSessionServer input wrong value
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_1000
* @tc.name : RemoveSessionServer input pkg name null
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_0700, TestSize.Level3)
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1000, TestSize.Level3)
{
int ret;
ret = RemoveSessionServer(NULL, SESSION_NAME_DATA);
EXPECT_NE(SOFTBUS_OK, ret) << "RemoveSS success[pkg name null]";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_1100
* @tc.name : RemoveSessionServer input session name null
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1100, TestSize.Level3)
{
int ret;
ret = RemoveSessionServer(DEF_PKG_NAME, NULL);
EXPECT_NE(SOFTBUS_OK, ret) << "RemoveSS success[session name null]";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_1200
* @tc.name : RemoveSessionServer input all null
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1200, TestSize.Level3)
{
int ret;
ret = RemoveSessionServer(NULL, NULL);
EXPECT_NE(SOFTBUS_OK, ret) << "RemoveSS success[all null]";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_0800
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_1300
* @tc.name : RemoveSessionServer There are unclosed Session
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_0800, TestSize.Level3)
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1300, TestSize.Level3)
{
int ret;
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA, GetSessionListenser4Data());
@ -309,13 +409,13 @@ HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_0800, Tes
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_0900
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_1400
* @tc.name : OpenSession, SessionServer do not exist
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_0900, TestSize.Level3)
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1400, TestSize.Level3)
{
int ret;
int sessionId;
@ -328,13 +428,13 @@ HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_0900, Tes
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_1000
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_1500
* @tc.name : OpenSession Open the same one repeatedly
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1000, TestSize.Level3)
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1500, TestSize.Level3)
{
int ret;
int sessionId;
@ -353,13 +453,13 @@ HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1000, Tes
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_1100
* @tc.name : OpenSession input wrong value
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_1600
* @tc.name : OpenSession input my name null
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1100, TestSize.Level3)
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1600, TestSize.Level3)
{
int ret;
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA, GetSessionListenser4Data());
@ -369,23 +469,131 @@ HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1100, Tes
sessionId = OpenSession(NULL, SESSION_NAME_DATA, GetNetworkId(), DEF_GROUP_ID, GetSessionAttr4Data());
EXPECT_TRUE(sessionId < SESSION_ID_MIN) << "call opensession success[my name null]";
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA);
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSessionServer fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_1700
* @tc.name : OpenSession input peer name null
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1700, TestSize.Level3)
{
int ret;
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA, GetSessionListenser4Data());
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSessionServer fail";
int sessionId;
sessionId = OpenSession(SESSION_NAME_DATA, NULL, GetNetworkId(), DEF_GROUP_ID, GetSessionAttr4Data());
EXPECT_TRUE(sessionId < SESSION_ID_MIN) << "call opensession success[peer name null]";
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA);
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSessionServer fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_1800
* @tc.name : OpenSession input net id null
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1800, TestSize.Level3)
{
int ret;
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA, GetSessionListenser4Data());
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSessionServer fail";
int sessionId;
sessionId = OpenSession(SESSION_NAME_DATA, SESSION_NAME_DATA, NULL, DEF_GROUP_ID, GetSessionAttr4Data());
EXPECT_TRUE(sessionId < SESSION_ID_MIN) << "call opensession success[net id null]";
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA);
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSessionServer fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_1900
* @tc.name : OpenSession input net id invalid
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1900, TestSize.Level3)
{
int ret;
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA, GetSessionListenser4Data());
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSessionServer fail";
int sessionId;
string invalidNetId = "123456789012345678901234567890123456789012345678901234567890abcd";
sessionId =
OpenSession(SESSION_NAME_DATA, SESSION_NAME_DATA, invalidNetId.c_str(), DEF_GROUP_ID, GetSessionAttr4Data());
EXPECT_TRUE(sessionId < SESSION_ID_MIN) << "call opensession success[net id invalid]";
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA);
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSessionServer fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_2000
* @tc.name : OpenSession input group id null
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_2000, TestSize.Level3)
{
int ret;
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA, GetSessionListenser4Data());
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSessionServer fail";
int sessionId;
sessionId = OpenSession(SESSION_NAME_DATA, SESSION_NAME_DATA, GetNetworkId(), NULL, GetSessionAttr4Data());
EXPECT_TRUE(sessionId < SESSION_ID_MIN) << "call opensession success[group id null]";
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA);
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSessionServer fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_2100
* @tc.name : OpenSession input arrt null
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_2100, TestSize.Level3)
{
int ret;
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA, GetSessionListenser4Data());
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSessionServer fail";
int sessionId;
sessionId = OpenSession(SESSION_NAME_DATA, SESSION_NAME_DATA, GetNetworkId(), DEF_GROUP_ID, NULL);
EXPECT_TRUE(sessionId < SESSION_ID_MIN) << "call opensession success[arrt null]";
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA);
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSessionServer fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_2200
* @tc.name : OpenSession input arrt invalid
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_2200, TestSize.Level3)
{
int ret;
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA, GetSessionListenser4Data());
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSessionServer fail";
int sessionId;
SessionAttribute sAttr;
sAttr.dataType = 50;
sessionId = OpenSession(SESSION_NAME_DATA, SESSION_NAME_DATA, GetNetworkId(), DEF_GROUP_ID, &sAttr);
@ -396,13 +604,13 @@ HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1100, Tes
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_1200
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_2300
* @tc.name : CloseSession repeatedly
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1200, TestSize.Level3)
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_2300, TestSize.Level3)
{
int ret;
int sessionId;
@ -437,13 +645,13 @@ HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1200, Tes
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_1300
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_2400
* @tc.name : CloseSession not exist sessionId
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1300, TestSize.Level3)
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_2400, TestSize.Level3)
{
int ret;
int timeout = 3;
@ -467,13 +675,13 @@ HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1300, Tes
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_1400
* @tc.name : GetMySessionName input wrong value
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_2500
* @tc.name : GetMySessionName input invalid sid -1
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1400, TestSize.Level3)
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_2500, TestSize.Level3)
{
int ret;
int sessionId;
@ -484,15 +692,116 @@ HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1400, Tes
char mySname[SESSION_NAME_SIZE_MAX] = { 0 };
ret = GetMySessionName(-1, mySname, SESSION_NAME_SIZE_MAX);
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "GetMySessionName invalid sid[-1]";
ret = CloseSessionAndRemoveSs4Data();
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionAndRemoveSs4Data fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_2600
* @tc.name : GetMySessionName input invalid sid max+1
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_2600, TestSize.Level3)
{
int ret;
int sessionId;
ret = CreateSsAndOpenSession4Data();
ASSERT_EQ(SOFTBUS_OK, ret) << "CreateSsAndOpenSession4Data fail";
sessionId = GetCurrentSessionId4Data();
char mySname[SESSION_NAME_SIZE_MAX] = { 0 };
ret = GetMySessionName(MAX_SESSION_NUM + 1, mySname, SESSION_NAME_SIZE_MAX);
EXPECT_NE(SOFTBUS_OK, ret) << "GetMySessionName invalid sid[max+1]";
ret = CloseSessionAndRemoveSs4Data();
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionAndRemoveSs4Data fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_2700
* @tc.name : GetMySessionName input invalid sid not open
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_2700, TestSize.Level3)
{
int ret;
int sessionId;
ret = CreateSsAndOpenSession4Data();
ASSERT_EQ(SOFTBUS_OK, ret) << "CreateSsAndOpenSession4Data fail";
sessionId = GetCurrentSessionId4Data();
char mySname[SESSION_NAME_SIZE_MAX] = { 0 };
ret = GetMySessionName(sessionId + 1, mySname, SESSION_NAME_SIZE_MAX);
EXPECT_NE(SOFTBUS_OK, ret) << "GetMySessionName invalid sid[not open]";
ret = CloseSessionAndRemoveSs4Data();
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionAndRemoveSs4Data fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_2800
* @tc.name : GetMySessionName input MySessionName invalid sname null
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_2800, TestSize.Level3)
{
int ret;
int sessionId;
ret = CreateSsAndOpenSession4Data();
ASSERT_EQ(SOFTBUS_OK, ret) << "CreateSsAndOpenSession4Data fail";
sessionId = GetCurrentSessionId4Data();
ret = GetMySessionName(sessionId, NULL, SESSION_NAME_SIZE_MAX);
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "GetMySessionName invalid sname[null]";
ret = CloseSessionAndRemoveSs4Data();
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionAndRemoveSs4Data fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_2900
* @tc.name : GetMySessionName input MySessionName invalid len[max+1]
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_2900, TestSize.Level3)
{
int ret;
int sessionId;
ret = CreateSsAndOpenSession4Data();
ASSERT_EQ(SOFTBUS_OK, ret) << "CreateSsAndOpenSession4Data fail";
sessionId = GetCurrentSessionId4Data();
char mySname[SESSION_NAME_SIZE_MAX] = { 0 };
ret = GetMySessionName(sessionId, mySname, SESSION_NAME_SIZE_MAX + 1);
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "GetMySessionName invalid len[max+1]";
ret = CloseSessionAndRemoveSs4Data();
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionAndRemoveSs4Data fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_3000
* @tc.name : GetMySessionName input MySessionName len short than real
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_3000, TestSize.Level3)
{
int ret;
int sessionId;
ret = CreateSsAndOpenSession4Data();
ASSERT_EQ(SOFTBUS_OK, ret) << "CreateSsAndOpenSession4Data fail";
sessionId = GetCurrentSessionId4Data();
char mySnameShort[5];
ret = GetMySessionName(sessionId, mySnameShort, 5);
EXPECT_NE(SOFTBUS_OK, ret) << "GetMySessionName len short than real";
@ -502,13 +811,13 @@ HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1400, Tes
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_1500
* @tc.name : GetPeersessionName input wrong value
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_3100
* @tc.name : GetPeersessionName input invalid sid -1
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1500, TestSize.Level3)
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_3100, TestSize.Level3)
{
int ret;
int sessionId;
@ -519,15 +828,117 @@ HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1500, Tes
char peerSname[SESSION_NAME_SIZE_MAX] = { 0 };
ret = GetPeerSessionName(-1, peerSname, SESSION_NAME_SIZE_MAX);
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "GetPeerSessionName invalid sid[-1]";
ret = CloseSessionAndRemoveSs4Data();
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionAndRemoveSs4Data fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_3200
* @tc.name : GetPeersessionName input invalid sid max+1
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_3200, TestSize.Level3)
{
int ret;
int sessionId;
ret = CreateSsAndOpenSession4Data();
ASSERT_EQ(SOFTBUS_OK, ret) << "CreateSsAndOpenSession4Data fail";
sessionId = GetCurrentSessionId4Data();
char peerSname[SESSION_NAME_SIZE_MAX] = { 0 };
ret = GetPeerSessionName(MAX_SESSION_NUM + 1, peerSname, SESSION_NAME_SIZE_MAX);
EXPECT_NE(SOFTBUS_OK, ret) << "GetPeerSessionName invalid sid[max+1]";
ret = CloseSessionAndRemoveSs4Data();
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionAndRemoveSs4Data fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_3300
* @tc.name : GetPeersessionName input invalid sid not open
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_3300, TestSize.Level3)
{
int ret;
int sessionId;
ret = CreateSsAndOpenSession4Data();
ASSERT_EQ(SOFTBUS_OK, ret) << "CreateSsAndOpenSession4Data fail";
sessionId = GetCurrentSessionId4Data();
char peerSname[SESSION_NAME_SIZE_MAX] = { 0 };
ret = GetPeerSessionName(sessionId + 1, peerSname, SESSION_NAME_SIZE_MAX);
EXPECT_NE(SOFTBUS_OK, ret) << "GetPeerSessionName invalid sid[not open]";
ret = CloseSessionAndRemoveSs4Data();
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionAndRemoveSs4Data fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_3400
* @tc.name : GetPeersessionName input SessionName invalid sname[null]
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_3400, TestSize.Level3)
{
int ret;
int sessionId;
ret = CreateSsAndOpenSession4Data();
ASSERT_EQ(SOFTBUS_OK, ret) << "CreateSsAndOpenSession4Data fail";
sessionId = GetCurrentSessionId4Data();
ret = GetPeerSessionName(sessionId, NULL, SESSION_NAME_SIZE_MAX);
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "GetPeerSessionName invalid sname[null]";
ret = CloseSessionAndRemoveSs4Data();
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionAndRemoveSs4Data fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_3500
* @tc.name : GetPeersessionName input PeerSessionName invalid len[max+1]
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_3500, TestSize.Level3)
{
int ret;
int sessionId;
ret = CreateSsAndOpenSession4Data();
ASSERT_EQ(SOFTBUS_OK, ret) << "CreateSsAndOpenSession4Data fail";
sessionId = GetCurrentSessionId4Data();
char peerSname[SESSION_NAME_SIZE_MAX] = { 0 };
ret = GetPeerSessionName(sessionId, peerSname, SESSION_NAME_SIZE_MAX + 1);
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "GetPeerSessionName invalid len[max+1]";
ret = CloseSessionAndRemoveSs4Data();
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionAndRemoveSs4Data fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_3600
* @tc.name : GetPeersessionName input PeerSessionName len short than real
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_3600, TestSize.Level3)
{
int ret;
int sessionId;
ret = CreateSsAndOpenSession4Data();
ASSERT_EQ(SOFTBUS_OK, ret) << "CreateSsAndOpenSession4Data fail";
sessionId = GetCurrentSessionId4Data();
char peerSnameShort[5];
ret = GetPeerSessionName(sessionId, peerSnameShort, 5);
EXPECT_NE(SOFTBUS_OK, ret) << "GetPeerSessionName len short than real";
@ -537,13 +948,13 @@ HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1500, Tes
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_1600
* @tc.name : GetPeerDeviceId input wrong value
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_3700
* @tc.name : GetPeerDeviceId input DeviceId invalid sid -1
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1600, TestSize.Level3)
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_3700, TestSize.Level3)
{
int ret;
int sessionId;
@ -554,15 +965,114 @@ HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1600, Tes
char deviceId[SESSION_NAME_SIZE_MAX] = { 0 };
ret = GetPeerDeviceId(-1, deviceId, SESSION_NAME_SIZE_MAX);
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "GetPeerDeviceId invalid sid[-1]";
ret = CloseSessionAndRemoveSs4Data();
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionAndRemoveSs4Data fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_3800
* @tc.name : GetPeerDeviceId input DeviceId invalid sid[max+1]
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_3800, TestSize.Level3)
{
int ret;
int sessionId;
ret = CreateSsAndOpenSession4Data();
ASSERT_EQ(SOFTBUS_OK, ret) << "CreateSsAndOpenSession4Data fail";
sessionId = GetCurrentSessionId4Data();
char deviceId[SESSION_NAME_SIZE_MAX] = { 0 };
ret = GetPeerDeviceId(MAX_SESSION_NUM + 1, deviceId, SESSION_NAME_SIZE_MAX);
EXPECT_NE(SOFTBUS_OK, ret) << "GetPeerDeviceId invalid sid[max+1]";
ret = CloseSessionAndRemoveSs4Data();
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionAndRemoveSs4Data fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_3900
* @tc.name : GetPeerDeviceId input DeviceId invalid sid not open
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_3900, TestSize.Level3)
{
int ret;
int sessionId;
ret = CreateSsAndOpenSession4Data();
ASSERT_EQ(SOFTBUS_OK, ret) << "CreateSsAndOpenSession4Data fail";
char deviceId[SESSION_NAME_SIZE_MAX] = { 0 };
sessionId = GetCurrentSessionId4Data();
ret = GetPeerDeviceId(sessionId + 1, deviceId, SESSION_NAME_SIZE_MAX);
EXPECT_NE(SOFTBUS_OK, ret) << "GetPeerDeviceId invalid sid[not open]";
ret = CloseSessionAndRemoveSs4Data();
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionAndRemoveSs4Data fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_4000
* @tc.name : GetPeerDeviceId input DeviceId invalid sname[null]
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_4000, TestSize.Level3)
{
int ret;
int sessionId;
ret = CreateSsAndOpenSession4Data();
ASSERT_EQ(SOFTBUS_OK, ret) << "CreateSsAndOpenSession4Data fail";
sessionId = GetCurrentSessionId4Data();
ret = GetPeerDeviceId(sessionId, NULL, SESSION_NAME_SIZE_MAX);
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "GetPeerDeviceId invalid sname[null]";
ret = CloseSessionAndRemoveSs4Data();
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionAndRemoveSs4Data fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_4100
* @tc.name : GetPeerDeviceId input DeviceId invalid len[max+1]
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_4100, TestSize.Level3)
{
int ret;
int sessionId;
ret = CreateSsAndOpenSession4Data();
ASSERT_EQ(SOFTBUS_OK, ret) << "CreateSsAndOpenSession4Data fail";
sessionId = GetCurrentSessionId4Data();
char deviceId[SESSION_NAME_SIZE_MAX] = { 0 };
ret = GetPeerDeviceId(sessionId, deviceId, SESSION_NAME_SIZE_MAX + 1);
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "GetPeerDeviceId invalid len[max+1]";
ret = CloseSessionAndRemoveSs4Data();
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionAndRemoveSs4Data fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_4200
* @tc.name : GetPeerDeviceId input DeviceId len short than real
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_4200, TestSize.Level3)
{
int ret;
int sessionId;
ret = CreateSsAndOpenSession4Data();
ASSERT_EQ(SOFTBUS_OK, ret) << "CreateSsAndOpenSession4Data fail";
sessionId = GetCurrentSessionId4Data();
char deviceIdShort[5];
ret = GetPeerDeviceId(sessionId, deviceIdShort, 5);
EXPECT_NE(SOFTBUS_OK, ret) << "GetPeerDeviceId len short than real";
@ -572,13 +1082,13 @@ HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1600, Tes
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_1700
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Reli_4300
* @tc.name : OpenSession, no Session Server exists on the peer
* @tc.desc : Test session management reliability
* @tc.type : RELI
* @tc.size : MediumTest
*/
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_1700, TestSize.Level3)
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Comp_OpenSession_Reli_4300, TestSize.Level3)
{
int ret;
char* softbusPidStart;

View File

@ -17,41 +17,10 @@
#include "net_trans_common.h"
#include "wifi_utils.h"
static int g_waitFlag = WAIT_DEF_VALUE;
static int ONE_SECOND = 1;
static int StreamSessionOpened(int sessionId, int result)
{
LOG("[cb][stream]open session sessionId[%d],rst[%d]", sessionId, result);
if (result == SOFTBUS_OK) {
g_waitFlag = WAIT_SUCCESS_VALUE;
} else {
g_waitFlag = WAIT_FAIL_VALUE;
}
return SOFTBUS_OK;
}
static void StreamSessionClosed(int sessionId)
{
LOG("[cb][stream]close session sessionId[%d]", sessionId);
}
static void StreamReceived(int sessionId, const StreamData *data, const StreamData *ext, const StreamFrameInfo *frame)
{
if (data != NULL) {
LOG("[cb][stream]ByteRec sessionId:%d, data= %.*s.\n", sessionId, data->bufLen, data->buf);
g_waitFlag = WAIT_SUCCESS_VALUE;
}
}
static ISessionListener g_streamSessionListener = {
.OnSessionOpened = StreamSessionOpened,
.OnSessionClosed = StreamSessionClosed,
.OnStreamReceived = StreamReceived
};
#define I_FRAME_SIZE (150 * 1024)
#define P_FRAME_SIZE (30 * 1024)
static uint64_t g_transTimStart;
using namespace testing::ext;
@ -90,26 +59,21 @@ void TransStreamTest::TearDownTestCase()
TestTearDown();
}
static int WaitStream(int timeout)
static inline void SetNumberInStreamData(char *streamData, int i)
{
LOG("start waitStream,timeout:%d", timeout);
int count = 0;
int t = timeout;
while (t > 0) {
sleep(ONE_SECOND);
if (g_waitFlag != WAIT_DEF_VALUE) {
LOG("waitStream success[flag:%d][time:%d]", g_waitFlag, count);
break;
}
t--;
count++;
if (i < 10) {
streamData[0] = '1';
streamData[1] = '0' + i;
} else if (i < 100){
streamData[0] = '2';
streamData[1] = '0' + (i / 10);
streamData[2] = '0' + (i % 10);
} else {
streamData[0] = '3';
streamData[1] = '0' + (i / 100);
streamData[2] = '0' + ((i / 10) % 10);
streamData[3] = '0' + (i % 100);
}
if (g_waitFlag != WAIT_SUCCESS_VALUE) {
LOG("waitStream fail[exp:%d, real:%d][used time:%d]", WAIT_SUCCESS_VALUE,
g_waitFlag, count);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
/**
@ -134,11 +98,9 @@ HWTEST_F(TransStreamTest, SUB_Softbus_Trans_Comp_SendStream_0100, TestSize.Level
};
StreamFrameInfo frame = {0};
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_STREAM, &g_streamSessionListener);
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_STREAM, GetSessionListenser4Stream());
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS[Stream] fail";
g_waitFlag = WAIT_DEF_VALUE;
SessionAttribute attr;
(void)memset_s(&attr, sizeof(attr), 0, sizeof(attr));
attr.dataType = TYPE_STREAM;
@ -146,7 +108,7 @@ HWTEST_F(TransStreamTest, SUB_Softbus_Trans_Comp_SendStream_0100, TestSize.Level
DEF_GROUP_ID, &attr);
EXPECT_TRUE(sessionId >= SESSION_ID_MIN) << "call OpenSession[Stream] fail, sessionId=" << sessionId;
if (sessionId >= SESSION_ID_MIN) {
ret = WaitStream(5);
ret = Wait4Session(5, SESSION_4STREAM);
EXPECT_EQ(SOFTBUS_OK, ret) << "wait opensession fail[Stream]";
LOG("call OpenSession[Stream] success");
}
@ -158,3 +120,86 @@ HWTEST_F(TransStreamTest, SUB_Softbus_Trans_Comp_SendStream_0100, TestSize.Level
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_STREAM);
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS[proxy] fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_SendStream_0200
* @tc.name : test Common Stream
* @tc.desc : Test send stream function
* @tc.type : FUNC
* @tc.size : MediumTest
*/
HWTEST_F(TransStreamTest, SUB_Softbus_Trans_Comp_SendStream_0200, TestSize.Level2) {
int ret;
char *sendIFrame = (char *)malloc(I_FRAME_SIZE);
EXPECT_NE(sendIFrame, nullptr);
char *sendPFrame = (char *)malloc(P_FRAME_SIZE);
EXPECT_NE(sendPFrame, nullptr);
StreamData extStreamData {0};
StreamData streamIData {
.buf = sendIFrame,
.bufLen = I_FRAME_SIZE + 1,
};
StreamFrameInfo iFrame = {0};
StreamData streamPData {
.buf = sendPFrame,
.bufLen = I_FRAME_SIZE + 1,
};
StreamFrameInfo pFrame = {0};
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_STREAM, GetSessionListenser4Stream());
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS[Stream] fail";
SessionAttribute attr;
(void)memset_s(&attr, sizeof(attr), 0, sizeof(attr));
attr.dataType = TYPE_STREAM;
int sessionId = OpenSession(SESSION_NAME_STREAM, SESSION_NAME_STREAM, GetNetworkId(),
DEF_GROUP_ID, &attr);
EXPECT_TRUE(sessionId >= SESSION_ID_MIN) << "call OpenSession[Stream] fail, sessionId=" << sessionId;
if (sessionId >= SESSION_ID_MIN) {
ret = Wait4Session(5, SESSION_4STREAM);
EXPECT_EQ(SOFTBUS_OK, ret) << "wait opensession fail[Stream]";
LOG("call OpenSession[Stream] success");
}
for (int i = 0; i < 6000; i++)
{
if (i % 60 == 0)
{
//I_Fream
SetNumberInStreamData(sendIFrame, i);
g_transTimStart = GetCurrentTimeOfMs();
ret = SendStream(sessionId, &streamIData, &extStreamData, &iFrame);
EXPECT_EQ(SOFTBUS_OK, ret) << "call SendStream fail";
if (ret == SOFTBUS_OK)
{
LOG("###SendStream IFREAM Start Time = %llu and counts = %d ", g_transTimStart, i);
}
} else
{
//P Fream
SetNumberInStreamData(sendPFrame, i);
g_transTimStart = GetCurrentTimeOfMs();
ret = SendStream(sessionId, &streamPData, &extStreamData, &pFrame);
EXPECT_EQ(SOFTBUS_OK, ret) << "call SendStream fail";
if (ret == SOFTBUS_OK)
{
LOG("###SendStream PFREAM Start Time = %llu and counts = %d ", g_transTimStart, i );
}
}
usleep(16666); //sleep 100ms
}
free(sendIFrame);
sendIFrame = nullptr;
free(sendPFrame);
sendPFrame = nullptr;
CloseSession(sessionId);
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_STREAM);
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS[proxy] fail";
}

View File

@ -18,6 +18,56 @@
#include "net_trans_common.h"
#include "wifi_utils.h"
static int g_waitFlag = WAIT_DEF_VALUE;
static int FileSessionOpened(int sessionId, int result)
{
LOG("[cb][file]open session sid[%d],rst[%d]", sessionId, result);
if (result == SOFTBUS_OK) {
g_waitFlag = WAIT_SUCCESS_VALUE;
} else {
g_waitFlag = WAIT_FAIL_VALUE;
}
return SOFTBUS_OK;
}
static void FileSessionClosed(int sessionId)
{
LOG("[cb][file]close session sid[%d]", sessionId);
}
static void FileBytesReceived(int sessionId, const void* data, unsigned int dataLen)
{
LOG("[cb][file]ByteRec sid:%d, data len:%d", sessionId, dataLen);
if (data == NULL) {
LOG("[cb][file]ByteRec invalid data=null sid[%d]", sessionId);
g_waitFlag = WAIT_FAIL_VALUE;
} else {
g_waitFlag = WAIT_SUCCESS_VALUE;
}
}
static void FileMessageReceived(int sessionId, const void* data, unsigned int dataLen)
{
LOG("[cb][file]MessageRec sid:%d, data len:%d", sessionId, dataLen);
if (data == NULL) {
LOG("[cb][file]MessageRec invalid data=null sid[%d]", sessionId);
g_waitFlag = WAIT_FAIL_VALUE;
} else {
g_waitFlag = WAIT_SUCCESS_VALUE;
}
}
static SessionAttribute g_fileSessionAttr = {
.dataType = TYPE_FILE,
};
static ISessionListener g_fileSessionListener = {
.OnSessionOpened = FileSessionOpened,
.OnSessionClosed = FileSessionClosed,
.OnBytesReceived = FileBytesReceived,
.OnMessageReceived = FileMessageReceived,
};
using namespace testing::ext;
class TransSessionFuncTest : public testing::Test {
@ -50,6 +100,8 @@ void TransSessionFuncTest::SetUpTestCase()
ret = CheckRemoteDeviceIsNull(BOOL_TRUE);
ASSERT_EQ(SOFTBUS_OK, ret) << "get node fail,please check network";
system(" truncate -s 8M /data/8M.tar");
LOG("SetUp end");
}
@ -63,8 +115,7 @@ void TransSessionFuncTest::TearDownTestCase()
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Func_0100
* @tc.name : one Client creates SessionServer + 1, Max succeeds, 1
* fails
* @tc.name : one Client creates SessionServer + 1, Max succeeds, 1 fails
* @tc.desc : Test session management
* @tc.type : FUNC
* @tc.size : MediumTest
@ -95,10 +146,10 @@ HWTEST_F(TransSessionFuncTest, SUB_Softbus_Trans_Comp_OpenSession_Func_0100, Tes
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Func_0200
* @tc.name : OpenSession + 1, Max succeeds, 1 fails
* @tc.desc : Test session management
* @tc.type : FUNC
* @tc.size : MediumTest
* @tc.name : OpenSession + 1, Max succeeds, 1 fails
* @tc.desc : Test session management
* @tc.type : FUNC
* @tc.size : MediumTest
*/
HWTEST_F(TransSessionFuncTest, SUB_Softbus_Trans_Comp_OpenSession_Func_0200, TestSize.Level3)
{
@ -165,10 +216,10 @@ HWTEST_F(TransSessionFuncTest, SUB_Softbus_Trans_Comp_OpenSession_Func_0300, Tes
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Func_0400
* @tc.name : Obtain DevicedId based on Sessionid
* @tc.desc : Test session management
* @tc.type : FUNC
* @tc.size : MediumTest
* @tc.name : Obtain DevicedId based on Sessionid
* @tc.desc : Test session management
* @tc.type : FUNC
* @tc.size : MediumTest
*/
HWTEST_F(TransSessionFuncTest, SUB_Softbus_Trans_Comp_OpenSession_Func_0400, TestSize.Level3)
{
@ -184,3 +235,297 @@ HWTEST_F(TransSessionFuncTest, SUB_Softbus_Trans_Comp_OpenSession_Func_0400, Tes
ret = CloseSessionAndRemoveSs4Ctl();
EXPECT_EQ(SOFTBUS_OK, ret) << "close session and remove Ss fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Func_0500
* @tc.name : OpenSession Type is TYPE_BYTES sendfile fail
* @tc.desc : Test session management
* @tc.type : FUNC
* @tc.size : MediumTest
*/
HWTEST_F(TransSessionFuncTest, SUB_Softbus_Trans_Comp_OpenSession_Func_0500, TestSize.Level3)
{
int ret;
int sessionId;
int timeout = 10;
static const char* g_file[] = {
"/data/8M.tar",
};
static const char *recv_file[] = {
"/data/datatype_8M.tar",
};
ret = SetFileSendListener(DEF_PKG_NAME, SESSION_NAME_FILE, GetSendFileListener());
EXPECT_EQ(SOFTBUS_OK, ret) << "call SetFileSendListener fail";
ret = SetFileReceiveListener(DEF_PKG_NAME, SESSION_NAME_FILE, GetRecvFileListener(), RECV_FILE_PATH);
EXPECT_EQ(SOFTBUS_OK, ret) << "call SetFileSendListener fail";
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE, &g_fileSessionListener);
EXPECT_EQ(SOFTBUS_OK, ret) << "call CreateSS[file] fail";
sessionId = OpenSession(SESSION_NAME_FILE, SESSION_NAME_FILE, GetNetworkId(), DEF_GROUP_ID, GetSessionAttr4Data());
if (sessionId < SESSION_ID_MIN)
{
LOG("call opensession[file] fail, ret sid:%d, netid:%s", sessionId, GetNetworkId());
}
ret = Wait4Session(timeout, SESSION_4DATA);
if (ret != SOFTBUS_OK)
{
LOG("call opensession[file] fail");
}
ret = SendFile(sessionId, g_file, recv_file, 1);
EXPECT_NE(SOFTBUS_OK, ret) << "sendfile succees";
CloseSession(sessionId);
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE);
EXPECT_EQ(SOFTBUS_OK, ret) << "remove Ss fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Func_0600
* @tc.name : OpenSession Type is TYPE_MESSAGE sendfile fail
* @tc.desc : Test session management
* @tc.type : FUNC
* @tc.size : MediumTest
*/
HWTEST_F(TransSessionFuncTest, SUB_Softbus_Trans_Comp_OpenSession_Func_0600, TestSize.Level3)
{
int ret;
int sessionId;
int timeout = 10;
static const char* g_file[] = {
"/data/8M.tar",
};
static const char *recv_file[] = {
"/data/messagetype_8M.tar",
};
ret = SetFileSendListener(DEF_PKG_NAME, SESSION_NAME_PROXY, GetSendFileListener());
EXPECT_EQ(SOFTBUS_OK, ret) << "call SetFileSendListener fail";
ret = SetFileReceiveListener(DEF_PKG_NAME, SESSION_NAME_PROXY, GetRecvFileListener(), RECV_FILE_PATH);
EXPECT_EQ(SOFTBUS_OK, ret) << "call SetFileSendListener fail";
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_PROXY, GetSessionListenser4Proxy());
EXPECT_EQ(SOFTBUS_OK, ret) << "call CreateSS[file] fail";
sessionId = OpenSession(SESSION_NAME_PROXY, SESSION_NAME_PROXY, GetNetworkId(), DEF_GROUP_ID, GetSessionAttr4Proxy());
if (sessionId < SESSION_ID_MIN)
{
LOG("call opensession[message] fail, ret sid:%d, netid:%s", sessionId, GetNetworkId());
}
ret = Wait4Session(timeout, SESSION_4PROXY);
if (ret != SOFTBUS_OK)
{
LOG("call opensession[message] fail");
}
ret = SendFile(sessionId, g_file, recv_file, 1);
EXPECT_NE(SOFTBUS_OK, ret) << "sendfile succees";
CloseSession(sessionId);
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_PROXY);
EXPECT_EQ(SOFTBUS_OK, ret) << "remove Ss fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Func_0700
* @tc.name : OpenSession Type is TYPE_STREAM sendfile fail
* @tc.desc : Test session management
* @tc.type : FUNC
* @tc.size : MediumTest
*/
HWTEST_F(TransSessionFuncTest, SUB_Softbus_Trans_Comp_OpenSession_Func_0700, TestSize.Level3)
{
int ret;
int sessionId;
int timeout = 10;
static const char* g_file[] = {
"/data/8M.tar",
};
static const char *recv_file[] = {
"/data/streamtype_8M.tar",
};
ret = SetFileSendListener(DEF_PKG_NAME, SESSION_NAME_STREAM, GetSendFileListener());
EXPECT_EQ(SOFTBUS_OK, ret) << "call SetFileSendListener fail";
ret = SetFileReceiveListener(DEF_PKG_NAME, SESSION_NAME_STREAM, GetRecvFileListener(), RECV_FILE_PATH);
EXPECT_EQ(SOFTBUS_OK, ret) << "call SetFileSendListener fail";
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_STREAM, GetSessionListenser4Stream());
EXPECT_EQ(SOFTBUS_OK, ret) << "call CreateSS[file] fail";
SessionAttribute attr;
(void)memset_s(&attr, sizeof(attr), 0, sizeof(attr));
attr.dataType = TYPE_STREAM;
sessionId = OpenSession(SESSION_NAME_STREAM, SESSION_NAME_STREAM, GetNetworkId(), DEF_GROUP_ID, &attr);
if (sessionId < SESSION_ID_MIN)
{
LOG("call opensession[stream] fail, ret sid:%d, netid:%s", sessionId, GetNetworkId());
}
ret = Wait4Session(timeout, SESSION_4STREAM);
if (ret != SOFTBUS_OK)
{
LOG("call opensession[stream] fail");
}
ret = SendFile(sessionId, g_file, recv_file, 1);
EXPECT_NE(SOFTBUS_OK, ret) << "sendfile succees";
CloseSession(sessionId);
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_STREAM);
EXPECT_EQ(SOFTBUS_OK, ret) << "remove Ss fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Func_0800
* @tc.name : OpenSession Type is TYPE_BYTES sendstream fail
* @tc.desc : Test session management
* @tc.type : FUNC
* @tc.size : MediumTest
*/
HWTEST_F(TransSessionFuncTest, SUB_Softbus_Trans_Comp_OpenSession_Func_0800, TestSize.Level3)
{
int ret;
int sessionId;
int timeout = 10;
string data = "send stream transmission test!!!!";
char *sendData = (char *)malloc(data.length() + 1);
EXPECT_NE(sendData, nullptr);
ret = strcpy_s(sendData, data.length() + 1, data.c_str());
EXPECT_EQ(ret, SOFTBUS_OK);
StreamData extStreamData {0};
StreamData streamData {
.buf = sendData,
.bufLen = data.length() + 1,
};
StreamFrameInfo frame = {0};
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_STREAM, &g_fileSessionListener);
EXPECT_EQ(SOFTBUS_OK, ret) << "call CreateSS[file] fail";
sessionId = OpenSession(SESSION_NAME_STREAM, SESSION_NAME_STREAM, GetNetworkId(), DEF_GROUP_ID, GetSessionAttr4Data());
if (sessionId < SESSION_ID_MIN)
{
LOG("call opensession[file] fail, ret sid:%d, netid:%s", sessionId, GetNetworkId());
}
ret = Wait4Session(timeout, SESSION_4DATA);
if (ret != SOFTBUS_OK)
{
LOG("call opensession[file] fail");
}
ret = SendStream(sessionId, &streamData, &extStreamData, &frame);
EXPECT_NE(SOFTBUS_OK, ret) << "sendstream succees";
CloseSession(sessionId);
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE);
EXPECT_EQ(SOFTBUS_OK, ret) << "remove Ss fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Func_0900
* @tc.name : OpenSession Type is TYPE_MESSAGE sendstream fail
* @tc.desc : Test session management
* @tc.type : FUNC
* @tc.size : MediumTest
*/
HWTEST_F(TransSessionFuncTest, SUB_Softbus_Trans_Comp_OpenSession_Func_0900, TestSize.Level3)
{
int ret;
int sessionId;
int timeout = 10;
string data = "send stream transmission test!!!!";
char *sendData = (char *)malloc(data.length() + 1);
EXPECT_NE(sendData, nullptr);
ret = strcpy_s(sendData, data.length() + 1, data.c_str());
EXPECT_EQ(ret, SOFTBUS_OK);
StreamData extStreamData {0};
StreamData streamData {
.buf = sendData,
.bufLen = data.length() + 1,
};
StreamFrameInfo frame = {0};
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_PROXY, GetSessionListenser4Proxy());
EXPECT_EQ(SOFTBUS_OK, ret) << "call CreateSS[file] fail";
sessionId = OpenSession(SESSION_NAME_PROXY, SESSION_NAME_PROXY, GetNetworkId(), DEF_GROUP_ID, GetSessionAttr4Proxy());
if (sessionId < SESSION_ID_MIN)
{
LOG("call opensession[message] fail, ret sid:%d, netid:%s", sessionId, GetNetworkId());
}
ret = Wait4Session(timeout, SESSION_4PROXY);
if (ret != SOFTBUS_OK)
{
LOG("call opensession[message] fail");
}
ret = SendStream(sessionId, &streamData, &extStreamData, &frame);
EXPECT_NE(SOFTBUS_OK, ret) << "sendstream succees";
CloseSession(sessionId);
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_PROXY);
EXPECT_EQ(SOFTBUS_OK, ret) << "remove Ss fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Comp_OpenSession_Func_1000
* @tc.name : OpenSession Type is TYPE_FILE sendstream fail
* @tc.desc : Test session management
* @tc.type : FUNC
* @tc.size : MediumTest
*/
HWTEST_F(TransSessionFuncTest, SUB_Softbus_Trans_Comp_OpenSession_Func_1000, TestSize.Level3)
{
int ret;
int sessionId;
int timeout = 10;
string data = "send stream transmission test!!!!";
char *sendData = (char *)malloc(data.length() + 1);
EXPECT_NE(sendData, nullptr);
ret = strcpy_s(sendData, data.length() + 1, data.c_str());
EXPECT_EQ(ret, SOFTBUS_OK);
StreamData extStreamData {0};
StreamData streamData {
.buf = sendData,
.bufLen = data.length() + 1,
};
StreamFrameInfo frame = {0};
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE, &g_fileSessionListener);
EXPECT_EQ(SOFTBUS_OK, ret) << "call CreateSS[file] fail";
sessionId = OpenSession(SESSION_NAME_FILE, SESSION_NAME_FILE, GetNetworkId(), DEF_GROUP_ID, &g_fileSessionAttr);
if (sessionId < SESSION_ID_MIN)
{
LOG("call opensession[stream] fail, ret sid:%d, netid:%s", sessionId, GetNetworkId());
}
ret = Wait4Session(timeout, SESSION_4STREAM);
if (ret != SOFTBUS_OK)
{
LOG("call opensession[stream] fail");
}
ret = SendStream(sessionId, &streamData, &extStreamData, &frame);
EXPECT_NE(SOFTBUS_OK, ret) << "sendstream succees";
CloseSession(sessionId);
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_STREAM);
EXPECT_EQ(SOFTBUS_OK, ret) << "remove Ss fail";
}