mirror of
https://gitee.com/openharmony/xts_dcts
synced 2024-12-04 05:54:11 +00:00
【communication】dsoftbus软总线测试用例修改
Signed-off-by: greada <kangqiao1@huawei.com>
This commit is contained in:
parent
4477f45bb1
commit
8d51058981
@ -19,6 +19,8 @@ group("communication") {
|
||||
"softbus_standard/transmission/sendfile:DctsSoftBusTransFileFunTest",
|
||||
"softbus_standard/transmission/sendmsg:DctsSoftBusTransFunTest",
|
||||
"softbus_standard/transmission/sessionmgt:DctsSoftBusTransSessionFunTest",
|
||||
"softbus_standard/transmission/reliability:DctsSoftBusTransReliabilityTest",
|
||||
"softbus_standard/dsoftbusTest:dsoftbusTest",
|
||||
]
|
||||
} else {
|
||||
deps = [ "wifi_standard:ActsWifiJSTest" ]
|
||||
|
@ -47,7 +47,6 @@ static IFileSendListener* g_fileSendListener = NULL;
|
||||
static IFileReceiveListener* g_fileRecvListener = NULL;
|
||||
|
||||
static char g_networkId[NETWORK_ID_BUF_LEN] = { 0 };
|
||||
static char g_networkIdArray[MULTI_REMOTE_DEV_COUNT][NETWORK_ID_BUF_LEN];
|
||||
static INodeStateCb g_defNodeStateCallback;
|
||||
static ConnectionAddr g_ethAddr = {
|
||||
.type = CONNECTION_ADDR_WLAN,
|
||||
@ -60,35 +59,15 @@ static unsigned int g_expectDataSize = 0;
|
||||
static char* g_expectDataContent = NULL;
|
||||
static pthread_barrier_t* g_barrier = NULL;
|
||||
|
||||
static int32_t g_threadResult4Data = SOFTBUS_ERR;
|
||||
static int32_t g_threadResult4Ctl = SOFTBUS_ERR;
|
||||
static int32_t g_recvMsgStat4Control[MAX_SESSION_NUM] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
static int32_t g_recvByteStat4Control[MAX_SESSION_NUM] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
static uint64_t g_joinNetTimeStart;
|
||||
static uint64_t g_joinNetTimeEnd;
|
||||
static uint64_t g_leaveNetTimeStart;
|
||||
static uint64_t g_leaveNetTimeEnd;
|
||||
static uint64_t g_discoverTimeStart;
|
||||
static uint64_t g_discoverTimeEnd;
|
||||
static uint64_t g_openSessionTimeStart;
|
||||
static uint64_t g_openSessionTimeEnd;
|
||||
static uint64_t g_transTimeStart;
|
||||
static uint64_t g_transTimeEnd;
|
||||
|
||||
/* discovery */
|
||||
static int g_subscribeId = 0;
|
||||
static IDiscoveryCallback g_defDiscCallback;
|
||||
static SubscribeInfo g_subInfo = {
|
||||
.medium = COAP,
|
||||
.mode = DISCOVER_MODE_ACTIVE,
|
||||
.freq = MID,
|
||||
.capability = "ddmpCapability",
|
||||
.capabilityData = (unsigned char*)"cap data",
|
||||
.dataLen = sizeof("cap data"),
|
||||
.isSameAccount = true,
|
||||
.isWakeRemote = false,
|
||||
};
|
||||
|
||||
int Wait(int timeout)
|
||||
{
|
||||
@ -111,55 +90,6 @@ int Wait(int timeout)
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int WaitNodeCount(int timeout, WaitNodeStateType state, int expectCount)
|
||||
{
|
||||
LOG("Wait4Node,timeout:%d, type:%d, exp count:%d", timeout, state, expectCount);
|
||||
int hitFlag = -1;
|
||||
int t = timeout;
|
||||
while (t > 0) {
|
||||
sleep(1);
|
||||
switch (state) {
|
||||
case STATE_ONLINE:
|
||||
if (g_nodeOnlineCount == expectCount) {
|
||||
LOG("Wait4Node[online] succ,timeout:%d", t);
|
||||
hitFlag = 1;
|
||||
}
|
||||
break;
|
||||
case STATE_OFFLINE:
|
||||
if (g_nodeOfflineCount == expectCount) {
|
||||
LOG("Wait4Node[offline] succ,timeout:%d", t);
|
||||
hitFlag = 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG("Wait4Node state error");
|
||||
hitFlag = 1;
|
||||
break;
|
||||
}
|
||||
if (hitFlag != -1) {
|
||||
break;
|
||||
}
|
||||
t--;
|
||||
}
|
||||
switch (state) {
|
||||
case STATE_ONLINE:
|
||||
if (g_nodeOnlineCount != expectCount) {
|
||||
LOG("Wait4Node[online] fail[exp:%d, real:%d]", expectCount, g_nodeOnlineCount);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
break;
|
||||
case STATE_OFFLINE:
|
||||
if (g_nodeOfflineCount != expectCount) {
|
||||
LOG("Wait4Node[offline] fail[exp:%d, real:%d]", expectCount, g_nodeOfflineCount);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int Wait4Session(int timeout, WaitSessionType type)
|
||||
{
|
||||
int hitFlag = -1;
|
||||
@ -239,12 +169,6 @@ char* GetSoftbusPid(void)
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static int IncrementSubId(void)
|
||||
{
|
||||
g_subscribeId++;
|
||||
return g_subscribeId;
|
||||
}
|
||||
|
||||
static int OnReceiveFileStarted(int sessionId, const char* files, int fileCnt)
|
||||
{
|
||||
LOG("[recv file]start,sid:%d, fileCnt:%d", sessionId, fileCnt);
|
||||
@ -353,54 +277,6 @@ static void OnDefNodeBasicInfoChanged(NodeBasicInfoType type, NodeBasicInfo* inf
|
||||
LOG("[cb]InfoChanged id: %s,name: %s", info->networkId, info->deviceName);
|
||||
}
|
||||
|
||||
static void OnJoinNetCallBack(ConnectionAddr* addr, const char* networkId, int32_t retCode)
|
||||
{
|
||||
g_joinNetTimeEnd = GetCurrentTimeOfMs();
|
||||
|
||||
if (networkId == NULL || retCode != SOFTBUS_OK) {
|
||||
LOG("[cb]JoinNet netid/ret error, ret:%d", retCode);
|
||||
g_waitFlag = WAIT_FAIL_VALUE;
|
||||
return;
|
||||
}
|
||||
|
||||
LOG("[cb]JoinNet, ret:%d, id:%s", retCode, networkId);
|
||||
switch (addr->type) {
|
||||
case CONNECTION_ADDR_WLAN:
|
||||
LOG("[cb]JoinNet type is [WLAN]");
|
||||
break;
|
||||
case CONNECTION_ADDR_BR:
|
||||
LOG("[cb]JoinNet type is [BR]");
|
||||
break;
|
||||
case CONNECTION_ADDR_ETH:
|
||||
LOG("[cb]JoinNet type is [ETH]");
|
||||
break;
|
||||
default:
|
||||
LOG("[cb]JoinNet type error");
|
||||
g_waitFlag = WAIT_FAIL_VALUE;
|
||||
return;
|
||||
}
|
||||
|
||||
int ret = strncpy_s(g_networkId, NETWORK_ID_BUF_LEN, networkId, NETWORK_ID_BUF_LEN);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("[cb]strncpy_s fail");
|
||||
return;
|
||||
}
|
||||
|
||||
g_waitFlag = WAIT_SUCCESS_VALUE;
|
||||
}
|
||||
|
||||
static void OnLeaveNetCallBack(const char* networkId, int32_t ret)
|
||||
{
|
||||
g_leaveNetTimeEnd = GetCurrentTimeOfMs();
|
||||
|
||||
LOG("[cb]LeaveLNN ret[%d]", ret);
|
||||
if (ret == SOFTBUS_OK) {
|
||||
g_waitFlag = WAIT_SUCCESS_VALUE;
|
||||
} else {
|
||||
g_waitFlag = WAIT_FAIL_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
static int DataSessionOpened(int sessionId, int result)
|
||||
{
|
||||
// wait 1s, ensure set current session id
|
||||
@ -678,115 +554,6 @@ void ResetWaitFlag4Ctl(void)
|
||||
g_waitFlag4Ctl = WAIT_DEF_VALUE;
|
||||
}
|
||||
|
||||
void ResetWaitCount4Offline(void)
|
||||
{
|
||||
g_nodeOfflineCount = 0;
|
||||
}
|
||||
|
||||
void ResetWaitCount4Online(void)
|
||||
{
|
||||
g_nodeOnlineCount = 0;
|
||||
}
|
||||
|
||||
int StartDiscoveryDevice(void)
|
||||
{
|
||||
int ret;
|
||||
int timeout = 10;
|
||||
ResetWaitFlag();
|
||||
g_subInfo.subscribeId = IncrementSubId();
|
||||
LOG("subscribeId:%d", g_subInfo.subscribeId);
|
||||
g_discoverTimeStart = GetCurrentTimeOfMs();
|
||||
ret = StartDiscovery(DEF_PKG_NAME, &g_subInfo, &g_defDiscCallback);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("call StartDiscovery fail, ret:%d", ret);
|
||||
return ret;
|
||||
}
|
||||
ret = Wait(timeout);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("discover device fail");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int JoinNetwork(void)
|
||||
{
|
||||
int ret;
|
||||
int timeout = 15;
|
||||
ResetWaitFlag();
|
||||
g_joinNetTimeStart = GetCurrentTimeOfMs();
|
||||
ret = JoinLNN(DEF_PKG_NAME, &g_ethAddr, OnJoinNetCallBack);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("call JoinLNN fail, ret:%d", ret);
|
||||
return ret;
|
||||
}
|
||||
ret = Wait(timeout);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("JoinNetwork fail");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int JoinNetworkByAddr(ConnectionAddr* addr)
|
||||
{
|
||||
int ret;
|
||||
int timeout = 15;
|
||||
ResetWaitFlag();
|
||||
LOG("JoinNetwork[input addr]ip:%s, port:%d", addr->info.ip.ip, addr->info.ip.port);
|
||||
g_joinNetTimeStart = GetCurrentTimeOfMs();
|
||||
ret = JoinLNN(DEF_PKG_NAME, addr, OnJoinNetCallBack);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("call JoinLNN fail[input addr], ret:%d", ret);
|
||||
return ret;
|
||||
}
|
||||
ret = Wait(timeout);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("JoinNetwork[input addr] fail");
|
||||
} else {
|
||||
LOG("JoinNetwork[input addr] success");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DiscoverAndJoinNetwork(void)
|
||||
{
|
||||
int ret = StartDiscoveryDevice();
|
||||
int retStop = StopDiscovery(DEF_PKG_NAME, g_subscribeId);
|
||||
if (retStop != SOFTBUS_OK) {
|
||||
LOG("call StopDiscovery fail, ret:%d", ret);
|
||||
}
|
||||
if (ret != SOFTBUS_OK) {
|
||||
return ret;
|
||||
}
|
||||
sleep(1);
|
||||
|
||||
return JoinNetwork();
|
||||
}
|
||||
|
||||
int LeaveNetWork(void)
|
||||
{
|
||||
int ret;
|
||||
int timeout = 10;
|
||||
|
||||
ret = CheckRemoteDeviceIsNull(BOOL_TRUE);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ResetWaitFlag();
|
||||
g_leaveNetTimeStart = GetCurrentTimeOfMs();
|
||||
ret = LeaveLNN(DEF_PKG_NAME, g_networkId, OnLeaveNetCallBack);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("call LeaveLNN fail, ret:%d", ret);
|
||||
return ret;
|
||||
}
|
||||
ret = Wait(timeout);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("LeaveNetwork fail");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int RegisterDeviceStateDefCallback(void)
|
||||
{
|
||||
return RegNodeDeviceStateCb(DEF_PKG_NAME, &g_defNodeStateCallback);
|
||||
@ -833,27 +600,6 @@ int CreateSsAndOpenSession4Data(void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int OpenSession4Data(void)
|
||||
{
|
||||
int ret;
|
||||
int sessionId;
|
||||
int timeout = 10;
|
||||
ResetWaitFlag4Data();
|
||||
sessionId = OpenSession(SESSION_NAME_DATA, SESSION_NAME_DATA, g_networkId, DEF_GROUP_ID, g_sessionAttr4Data);
|
||||
if (sessionId < SESSION_ID_MIN) {
|
||||
LOG("call OpenSession[data] fail, ret sid:%d,netId:%s", sessionId, g_networkId);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
SetCurrentSessionId4Data(sessionId);
|
||||
LOG("call OpenSession[data] success,sid:%d", sessionId);
|
||||
ret = Wait4Session(timeout, SESSION_4DATA);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("OpenSession[data] fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CreateSsAndOpenSession4Ctl(void)
|
||||
{
|
||||
int ret;
|
||||
@ -890,101 +636,6 @@ int CreateSsAndOpenSession4Ctl(void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int OpenSession4Ctl(void)
|
||||
{
|
||||
int ret;
|
||||
int timeout = 10;
|
||||
int sessionId;
|
||||
ResetWaitFlag4Ctl();
|
||||
sessionId = OpenSession(SESSION_NAME_CTL, SESSION_NAME_CTL, g_networkId, DEF_GROUP_ID, g_sessionAttr4Ctl);
|
||||
if (sessionId < SESSION_ID_MIN) {
|
||||
LOG("call OpenSession[ctl] fail, ret sid:%d", sessionId);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
SetCurrentSessionId4Ctl(sessionId);
|
||||
LOG("call OpenSession[ctl] success,sid:%d", sessionId);
|
||||
|
||||
ret = Wait4Session(timeout, SESSION_4CTL);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("OpenSession[ctl] fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SendCtrlMsgToRemote(CtrlCodeType code)
|
||||
{
|
||||
int ret = -1;
|
||||
switch (code) {
|
||||
case CTRL_CODE_CLOSE_WIFI_TEN_SEC:
|
||||
ret = SendMessage(g_currentSessionId4Ctl, CTRL_MSG_CLOSE_WIFI_TEN_SEC, strlen(CTRL_MSG_CLOSE_WIFI_TEN_SEC));
|
||||
break;
|
||||
case CTRL_CODE_CLOSE_WIFI_THREE_SEC:
|
||||
ret = SendMessage(
|
||||
g_currentSessionId4Ctl, CTRL_MSG_CLOSE_WIFI_THREE_SEC, strlen(CTRL_MSG_CLOSE_WIFI_THREE_SEC));
|
||||
break;
|
||||
case CTRL_CODE_CLOSE_WIFI_TEN_MIN:
|
||||
ret = SendMessage(g_currentSessionId4Ctl, CTRL_MSG_CLOSE_WIFI_TEN_MIN, strlen(CTRL_MSG_CLOSE_WIFI_TEN_MIN));
|
||||
break;
|
||||
case CTRL_CODE_CLOSE_WIFI_FIVE_MIN:
|
||||
ret =
|
||||
SendMessage(g_currentSessionId4Ctl, CTRL_MSG_CLOSE_WIFI_FIVE_MIN, strlen(CTRL_MSG_CLOSE_WIFI_FIVE_MIN));
|
||||
break;
|
||||
case CTRL_CODE_CHANGE_WIFI_TEN_SEC:
|
||||
ret =
|
||||
SendMessage(g_currentSessionId4Ctl, CTRL_MSG_CHANGE_WIFI_TEN_SEC, strlen(CTRL_MSG_CHANGE_WIFI_TEN_SEC));
|
||||
break;
|
||||
case CTRL_CODE_CHANGE_WIFI_SIXTY_SEC:
|
||||
ret = SendMessage(
|
||||
g_currentSessionId4Ctl, CTRL_MSG_CHANGE_WIFI_SIXTY_SEC, strlen(CTRL_MSG_CHANGE_WIFI_SIXTY_SEC));
|
||||
break;
|
||||
case CTRL_CODE_CHANGE_WIFI_LOOP20:
|
||||
ret = SendMessage(g_currentSessionId4Ctl, CTRL_MSG_CHANGE_WIFI_LOOP20, strlen(CTRL_MSG_CHANGE_WIFI_LOOP20));
|
||||
break;
|
||||
case CTRL_CODE_CLOSE_WIFI_LOOP20:
|
||||
ret = SendMessage(g_currentSessionId4Ctl, CTRL_MSG_CLOSE_WIFI_LOOP20, strlen(CTRL_MSG_CLOSE_WIFI_LOOP20));
|
||||
break;
|
||||
case CTRL_CODE_CHANGE_WIFI_LOOP100:
|
||||
ret =
|
||||
SendMessage(g_currentSessionId4Ctl, CTRL_MSG_CHANGE_WIFI_LOOP100, strlen(CTRL_MSG_CHANGE_WIFI_LOOP100));
|
||||
break;
|
||||
case CTRL_CODE_CLOSE_WIFI_LOOP100:
|
||||
ret = SendMessage(g_currentSessionId4Ctl, CTRL_MSG_CLOSE_WIFI_LOOP100, strlen(CTRL_MSG_CLOSE_WIFI_LOOP100));
|
||||
break;
|
||||
case CTRL_CODE_CLOSE_BR:
|
||||
ret = SendMessage(g_currentSessionId4Ctl, CTRL_MSG_CLOSE_BR, strlen(CTRL_MSG_CLOSE_BR));
|
||||
break;
|
||||
case CTRL_CODE_CLOSE_OPEN_BR:
|
||||
ret = SendMessage(g_currentSessionId4Ctl, CTRL_MSG_CLOSE_OPEN_BR, strlen(CTRL_MSG_CLOSE_OPEN_BR));
|
||||
break;
|
||||
case CTRL_CODE_OPEN_SESSION:
|
||||
ret = SendMessage(g_currentSessionId4Ctl, CTRL_MSG_OPEN_SESSION, strlen(CTRL_MSG_OPEN_SESSION));
|
||||
break;
|
||||
case CTRL_CODE_OPEN_SESSION_MSG:
|
||||
ret = SendMessage(g_currentSessionId4Ctl, CTRL_MSG_OPEN_SESSION_MSG, strlen(CTRL_MSG_OPEN_SESSION_MSG));
|
||||
break;
|
||||
case CTRL_CODE_OPEN_SESSION_FAIL:
|
||||
g_passiveOpenRetFlag = SOFTBUS_ERR;
|
||||
ret = SendMessage(g_currentSessionId4Ctl, CTRL_MSG_OPEN_SESSION_FAIL, strlen(CTRL_MSG_OPEN_SESSION_FAIL));
|
||||
break;
|
||||
case CTRL_CODE_CLOSE_SESSION:
|
||||
ret = SendMessage(g_currentSessionId4Ctl, CTRL_MSG_CLOSE_SESSION, strlen(CTRL_MSG_CLOSE_SESSION));
|
||||
break;
|
||||
case CTRL_CODE_OPEN_SESSION_NOT_EXIST:
|
||||
ret = SendMessage(
|
||||
g_currentSessionId4Ctl, CTRL_MSG_OPEN_SESSION_NOT_EXIST, strlen(CTRL_MSG_OPEN_SESSION_NOT_EXIST));
|
||||
break;
|
||||
case CTRL_CODE_SEND_BIG_DATA:
|
||||
ret = SendMessage(g_currentSessionId4Ctl, CTRL_MSG_SEND_BIG_DATA, strlen(CTRL_MSG_SEND_BIG_DATA));
|
||||
break;
|
||||
default:
|
||||
LOG("[send ctrl msg]not support this code");
|
||||
break;
|
||||
}
|
||||
LOG("[send ctrl msg]send ret:%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SendData4Data(DataType type, int size)
|
||||
{
|
||||
int ret;
|
||||
@ -1028,84 +679,6 @@ int SendData4Data(DataType type, int size)
|
||||
return ret;
|
||||
}
|
||||
|
||||
// if open session success, return session id
|
||||
int OpenSession4Perf(void)
|
||||
{
|
||||
int ret;
|
||||
int sessionId;
|
||||
int timeout = 10;
|
||||
ResetWaitFlag();
|
||||
g_openSessionTimeStart = GetCurrentTimeOfMs();
|
||||
sessionId = OpenSession(SESSION_NAME_PERF, SESSION_NAME_PERF, g_networkId, DEF_GROUP_ID, g_sessionAttr4Perf);
|
||||
if (sessionId < SESSION_ID_MIN) {
|
||||
LOG("call OpenSession[perf] fail, ret sid:%d", sessionId);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
ret = Wait(timeout);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("OpenSession[perf] fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
int OpenSession4PerfWithParam(const char* sessionName, const char* groupId, char* netId)
|
||||
{
|
||||
int ret;
|
||||
int sessionId;
|
||||
int timeout = 10;
|
||||
ResetWaitFlag();
|
||||
g_openSessionTimeStart = GetCurrentTimeOfMs();
|
||||
sessionId = OpenSession(sessionName, sessionName, netId, groupId, g_sessionAttr4Perf);
|
||||
if (sessionId < SESSION_ID_MIN) {
|
||||
LOG("call OpenSession[perf] fail, ret sid:%d", sessionId);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
ret = Wait(timeout);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("OpenSession[perf] fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
int SendData4Perf(int sessionId, char* dataMsg, char* dataByte)
|
||||
{
|
||||
int sleeptime = 500000;
|
||||
int timeout = 5;
|
||||
int isHitFail = SOFTBUS_OK;
|
||||
ResetWaitFlag();
|
||||
g_transTimeStart = GetCurrentTimeOfMs();
|
||||
int ret = SendMessage(sessionId, dataMsg, TRANS_MESSAGE_LENGTH_MAX);
|
||||
g_transTimeEnd = GetCurrentTimeOfMs();
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("call SendMessage[perf] fail, ret:%d", ret);
|
||||
isHitFail = SOFTBUS_ERR;
|
||||
} else {
|
||||
}
|
||||
usleep(sleeptime);
|
||||
|
||||
ResetWaitFlag();
|
||||
g_transTimeStart = GetCurrentTimeOfMs();
|
||||
ret = SendBytes(sessionId, dataByte, TRANS_BYTES_LENGTH_MAX);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("call SendBytes[perf] fail, ret:%d", ret);
|
||||
isHitFail = SOFTBUS_ERR;
|
||||
} else {
|
||||
ret = Wait(timeout);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("wait byte callback fail ret:%d", ret);
|
||||
isHitFail = SOFTBUS_ERR;
|
||||
}
|
||||
}
|
||||
return isHitFail;
|
||||
}
|
||||
|
||||
void SetTransStartTime(void)
|
||||
{
|
||||
g_transTimeStart = GetCurrentTimeOfMs();
|
||||
}
|
||||
|
||||
int CloseSessionAndRemoveSs4Data(void)
|
||||
{
|
||||
int ret4Close;
|
||||
@ -1227,95 +800,6 @@ int CloseSessionBatch4Ctl(int* sessionId, int count)
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
void* OpenSessionTask4Data(void* param)
|
||||
{
|
||||
LOG("OpenSessionTask[Data] start");
|
||||
int ret;
|
||||
int step1Flag;
|
||||
int step2Flag;
|
||||
int count = MAX_SESSION_NUM / 2;
|
||||
int sessionId4Data[count];
|
||||
char groupId[][GROUP_ID_LEN] = { "g1", "g2", "g3", "g4", "g5", "g6", "g7", "g8" };
|
||||
|
||||
pthread_barrier_wait(g_barrier);
|
||||
ret = OpenSessionBatch4Data(groupId, sessionId4Data, count);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("OpenSessionBatch4Data ret fail");
|
||||
} else {
|
||||
LOG("OpenSessionBatch4Data ret success");
|
||||
}
|
||||
step1Flag = ret;
|
||||
|
||||
pthread_barrier_wait(g_barrier);
|
||||
// create more, expect fail
|
||||
int moreCount = 3;
|
||||
step2Flag = SOFTBUS_OK;
|
||||
char groupIdMore[][GROUP_ID_LEN] = { "m1", "m2", "m3" };
|
||||
for (int i = 0; i < moreCount; i++) {
|
||||
int sessionId =
|
||||
OpenSession(SESSION_NAME_DATA, SESSION_NAME_DATA, g_networkId, groupIdMore[i], g_sessionAttr4Data);
|
||||
if (sessionId >= SESSION_ID_MIN) {
|
||||
LOG("OpenSessionTask[Ctrl] open more success, expect fail,i:%d, "
|
||||
"sid:%d",
|
||||
i, sessionId);
|
||||
step2Flag = SOFTBUS_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
if (step1Flag == SOFTBUS_OK && step2Flag == SOFTBUS_OK) {
|
||||
g_threadResult4Data = SOFTBUS_OK;
|
||||
} else {
|
||||
g_threadResult4Data = SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
LOG("OpenSessionTask[Data] end");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void* OpenSessionTask4Ctl(void* param)
|
||||
{
|
||||
LOG("OpenSessionTask[Ctrl] start");
|
||||
int ret;
|
||||
int step1Flag;
|
||||
int step2Flag;
|
||||
int count = MAX_SESSION_NUM / 2;
|
||||
int sessionId4Ctrl[count];
|
||||
char groupId[][GROUP_ID_LEN] = { "g1", "g2", "g3", "g4", "g5", "g6", "g7", "g8" };
|
||||
|
||||
pthread_barrier_wait(g_barrier);
|
||||
ret = OpenSessionBatch4Ctl(groupId, sessionId4Ctrl, count);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("OpenSessionBatch4Ctl ret fail");
|
||||
} else {
|
||||
LOG("OpenSessionBatch4Ctl ret success");
|
||||
}
|
||||
step1Flag = ret;
|
||||
|
||||
pthread_barrier_wait(g_barrier);
|
||||
// create more, expect fail
|
||||
int moreCount = 3;
|
||||
step2Flag = SOFTBUS_OK;
|
||||
char groupIdMore[][GROUP_ID_LEN] = { "m1", "m2", "m3" };
|
||||
for (int i = 0; i < moreCount; i++) {
|
||||
int sessionId = OpenSession(SESSION_NAME_CTL, SESSION_NAME_CTL, g_networkId, groupIdMore[i], g_sessionAttr4Ctl);
|
||||
if (sessionId >= SESSION_ID_MIN) {
|
||||
LOG("OpenSessionTask[Ctrl] open more success, expect fail,i:%d, "
|
||||
"sid:%d",
|
||||
i, sessionId);
|
||||
step2Flag = SOFTBUS_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
if (step1Flag == SOFTBUS_OK && step2Flag == SOFTBUS_OK) {
|
||||
g_threadResult4Ctl = SOFTBUS_OK;
|
||||
} else {
|
||||
g_threadResult4Ctl = SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
LOG("OpenSessionTask[Ctrl] end");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// set/get function
|
||||
void ResetClosedSessionCount4Data(void)
|
||||
{
|
||||
@ -1337,55 +821,6 @@ int GetClosedSessionCount4Ctrl(void)
|
||||
return g_sessionCloseCount4Ctrl;
|
||||
}
|
||||
|
||||
void ResetOpenSessionCount4Data(void)
|
||||
{
|
||||
g_sessionOpenCount4Data = 0;
|
||||
}
|
||||
|
||||
void ResetOpenSessionCount4Ctrl(void)
|
||||
{
|
||||
g_sessionOpenCount4Ctrl = 0;
|
||||
}
|
||||
|
||||
int GetOpenSessionCount4Data(void)
|
||||
{
|
||||
return g_sessionOpenCount4Data;
|
||||
}
|
||||
|
||||
int GetOpenSessionCount4Ctrl(void)
|
||||
{
|
||||
return g_sessionOpenCount4Ctrl;
|
||||
}
|
||||
|
||||
int* GetSid4Task2(void)
|
||||
{
|
||||
return g_sId4Task2;
|
||||
}
|
||||
|
||||
int* GetSid4Task3(void)
|
||||
{
|
||||
return g_sId4Task3;
|
||||
}
|
||||
|
||||
void ResetMsgStat4Control(void)
|
||||
{
|
||||
for (int i = 0; i < MAX_SESSION_NUM; i++) {
|
||||
g_recvMsgStat4Control[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ResetByteStat4Control(void)
|
||||
{
|
||||
for (int i = 0; i < MAX_SESSION_NUM; i++) {
|
||||
g_recvByteStat4Control[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
pthread_barrier_t* GetThreadBarrier(void)
|
||||
{
|
||||
return g_barrier;
|
||||
}
|
||||
|
||||
char* GetNetworkId(void)
|
||||
{
|
||||
return g_networkId;
|
||||
@ -1411,66 +846,6 @@ int CheckRemoteDeviceIsNull(int isSetNetId)
|
||||
}
|
||||
}
|
||||
|
||||
int GetRemoteDeviceNetId(char** netId)
|
||||
{
|
||||
int nodeNum = 0;
|
||||
NodeBasicInfo* nodeInfo = NULL;
|
||||
NodeBasicInfo* nodeInfoTmp = NULL;
|
||||
int ret = GetAllNodeDeviceInfo(DEF_PKG_NAME, &nodeInfo, &nodeNum);
|
||||
nodeInfoTmp = nodeInfo;
|
||||
LOG("[get]node number is:%d, ret:%d", nodeNum, ret);
|
||||
if (nodeInfo != NULL && nodeNum > 0) {
|
||||
for (int i = 0; i < nodeNum; i++) {
|
||||
LOG("[get] netid is:%s", nodeInfo->networkId);
|
||||
*(netId + i) = (char*)malloc(NETWORK_ID_BUF_LEN * sizeof(char));
|
||||
(void)strncpy_s(*(netId + i), NETWORK_ID_BUF_LEN, nodeInfo->networkId, NETWORK_ID_BUF_LEN);
|
||||
LOG("[get] netid is [strcpy]:%s", *(netId + i));
|
||||
nodeInfo++;
|
||||
}
|
||||
FreeNodeInfo(nodeInfoTmp);
|
||||
} else {
|
||||
LOG("[get] nodeInfo is null");
|
||||
}
|
||||
return nodeNum;
|
||||
}
|
||||
|
||||
// get remote device network id, then set to global array
|
||||
int SetRemoteDeviceNetIdToGarray(void)
|
||||
{
|
||||
int nodeNum = 0;
|
||||
NodeBasicInfo* nodeInfo = NULL;
|
||||
NodeBasicInfo* nodeInfoTmp = NULL;
|
||||
int ret = GetAllNodeDeviceInfo(DEF_PKG_NAME, &nodeInfo, &nodeNum);
|
||||
nodeInfoTmp = nodeInfo;
|
||||
LOG("[setdev netid]dev number is:%d, ret:%d", nodeNum, ret);
|
||||
if (nodeInfo != NULL && nodeNum > 0) {
|
||||
for (int i = 0; i < nodeNum; i++) {
|
||||
(void)strncpy_s(g_networkIdArray[i], NETWORK_ID_BUF_LEN, nodeInfo->networkId, NETWORK_ID_BUF_LEN);
|
||||
LOG("[setdev netid] netid:%s", g_networkIdArray[i]);
|
||||
nodeInfo++;
|
||||
}
|
||||
FreeNodeInfo(nodeInfoTmp);
|
||||
} else {
|
||||
LOG("[setdev netid] nodeInfo is null");
|
||||
}
|
||||
return nodeNum;
|
||||
}
|
||||
|
||||
int SetCurrentNetworkId(int index)
|
||||
{
|
||||
if (index < 0 || index >= MULTI_REMOTE_DEV_COUNT) {
|
||||
LOG("input index is error");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
int ret = strncpy_s(g_networkId, NETWORK_ID_BUF_LEN, g_networkIdArray[index], NETWORK_ID_BUF_LEN);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("strncpy_s fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
ISessionListener* GetSessionListenser4Data(void)
|
||||
{
|
||||
return g_sessionlistener4Data;
|
||||
@ -1481,21 +856,6 @@ ISessionListener* GetSessionListenser4Ctl(void)
|
||||
return g_sessionlistener4Ctl;
|
||||
}
|
||||
|
||||
ISessionListener* GetSessionListenser4Pass(void)
|
||||
{
|
||||
return g_sessionlistener4Pass;
|
||||
}
|
||||
|
||||
ISessionListener* GetSessionListenser4Perf(void)
|
||||
{
|
||||
return g_sessionlistener4Perf;
|
||||
}
|
||||
|
||||
ISessionListener* GetSessionListenser4Proxy(void)
|
||||
{
|
||||
return g_sessionlistener4Proxy;
|
||||
}
|
||||
|
||||
IFileSendListener* GetSendFileListener(void)
|
||||
{
|
||||
return g_fileSendListener;
|
||||
@ -1516,21 +876,6 @@ SessionAttribute* GetSessionAttr4Ctl(void)
|
||||
return g_sessionAttr4Ctl;
|
||||
}
|
||||
|
||||
SessionAttribute* GetSessionAttr4Pass(void)
|
||||
{
|
||||
return g_sessionAttr4Pass;
|
||||
}
|
||||
|
||||
SessionAttribute* GetSessionAttr4Perf(void)
|
||||
{
|
||||
return g_sessionAttr4Perf;
|
||||
}
|
||||
|
||||
SessionAttribute* GetSessionAttr4Proxy(void)
|
||||
{
|
||||
return g_sessionAttr4Proxy;
|
||||
}
|
||||
|
||||
void SetCurrentSessionId4Data(int sessionId)
|
||||
{
|
||||
g_currentSessionId4Data = sessionId;
|
||||
@ -1551,21 +896,6 @@ int GetCurrentSessionId4Ctl(void)
|
||||
return g_currentSessionId4Ctl;
|
||||
}
|
||||
|
||||
int GetThreadResult4Data(void)
|
||||
{
|
||||
return g_threadResult4Data;
|
||||
}
|
||||
|
||||
int GetThreadResult4Ctl(void)
|
||||
{
|
||||
return g_threadResult4Ctl;
|
||||
}
|
||||
|
||||
ConnectionAddr* GetConnectAddr(void)
|
||||
{
|
||||
return &g_ethAddr;
|
||||
}
|
||||
|
||||
void TestSetUp(void)
|
||||
{
|
||||
g_defNodeStateCallback.events = EVENT_NODE_STATE_MASK;
|
||||
|
@ -176,53 +176,28 @@ typedef enum {
|
||||
|
||||
int Wait(int timeout);
|
||||
int Wait4Session(int timeout, WaitSessionType type);
|
||||
int WaitNodeCount(int timeout, WaitNodeStateType state, int expectCount);
|
||||
|
||||
void TestSetUp(void);
|
||||
void TestTearDown(void);
|
||||
|
||||
int StartDiscoveryDevice(void);
|
||||
|
||||
int JoinNetwork(void);
|
||||
int LeaveNetWork(void);
|
||||
int RegisterDeviceStateDefCallback(void);
|
||||
int UnRegisterDeviceStateDefCallback(void);
|
||||
int DiscoverAndJoinNetwork(void);
|
||||
int CheckRemoteDeviceIsNull(int isSetNetId);
|
||||
int GetRemoteDeviceNetId(char** netId);
|
||||
int SetCurrentNetworkId(int index);
|
||||
int SetRemoteDeviceNetIdToGarray(void);
|
||||
|
||||
uint64_t GetCurrentTimeOfMs(void);
|
||||
|
||||
void ResetWaitFlag(void);
|
||||
void ResetWaitFlag4Data(void);
|
||||
void ResetWaitFlag4Ctl(void);
|
||||
void ResetWaitCount4Offline(void);
|
||||
void ResetWaitCount4Online(void);
|
||||
|
||||
int SendData4Data(DataType type, int size);
|
||||
int SendCtrlMsgToRemote(CtrlCodeType code);
|
||||
|
||||
int CreateSsAndOpenSession4Data(void);
|
||||
int CreateSsAndOpenSession4Ctl(void);
|
||||
int OpenSession4Ctl(void);
|
||||
int OpenSession4Data(void);
|
||||
int OpenSessionBatch4Data(char groupId[][GROUP_ID_LEN], int* sessionId, int count);
|
||||
int OpenSessionBatch4Ctl(char groupId[][GROUP_ID_LEN], int* sessionId, int count);
|
||||
int CloseSessionBatch4Data(int* sessionId, int count);
|
||||
int CloseSessionBatch4Ctl(int* sessionId, int count);
|
||||
void* OpenSessionTask4Data(void* param);
|
||||
void* OpenSessionTask4Ctl(void* param);
|
||||
|
||||
int OpenSession4Perf(void);
|
||||
int OpenSession4PerfWithParam(const char* sessionName, const char* groupId, char* netId);
|
||||
int SendData4Perf(int sessionId, char* dataMsg, char* dataByte);
|
||||
void SetTransStartTime(void);
|
||||
|
||||
void* SendDataTask1(void* param);
|
||||
void* SendDataTask2(void* param);
|
||||
void* SendDataTask3(void* param);
|
||||
|
||||
char* GetSoftbusPid(void);
|
||||
char* GetNetworkId(void);
|
||||
@ -232,34 +207,15 @@ void SetCurrentSessionId4Data(int sessionId);
|
||||
void SetCurrentSessionId4Ctl(int sessionId);
|
||||
ISessionListener* GetSessionListenser4Data(void);
|
||||
ISessionListener* GetSessionListenser4Ctl(void);
|
||||
ISessionListener* GetSessionListenser4Pass(void);
|
||||
ISessionListener* GetSessionListenser4Perf(void);
|
||||
ISessionListener* GetSessionListenser4Proxy(void);
|
||||
SessionAttribute* GetSessionAttr4Pass(void);
|
||||
SessionAttribute* GetSessionAttr4Ctl(void);
|
||||
SessionAttribute* GetSessionAttr4Data(void);
|
||||
SessionAttribute* GetSessionAttr4Perf(void);
|
||||
SessionAttribute* GetSessionAttr4Proxy(void);
|
||||
IFileReceiveListener* GetRecvFileListener(void);
|
||||
IFileSendListener* GetSendFileListener(void);
|
||||
|
||||
pthread_barrier_t* GetThreadBarrier(void);
|
||||
int GetThreadResult4Data(void);
|
||||
int GetThreadResult4Ctl(void);
|
||||
int* GetSid4Task2(void);
|
||||
int* GetSid4Task3(void);
|
||||
void ResetMsgStat4Control(void);
|
||||
void ResetByteStat4Control(void);
|
||||
ConnectionAddr* GetConnectAddr(void);
|
||||
|
||||
void ResetClosedSessionCount4Data(void);
|
||||
void ResetClosedSessionCount4Ctrl(void);
|
||||
int GetClosedSessionCount4Data(void);
|
||||
int GetClosedSessionCount4Ctrl(void);
|
||||
void ResetOpenSessionCount4Data(void);
|
||||
void ResetOpenSessionCount4Ctrl(void);
|
||||
int GetOpenSessionCount4Data(void);
|
||||
int GetOpenSessionCount4Ctrl(void);
|
||||
|
||||
int CloseSessionAndRemoveSs4Data(void);
|
||||
int CloseSessionAndRemoveSs4Ctl(void);
|
||||
|
@ -23,7 +23,6 @@ using namespace OHOS::Wifi;
|
||||
const static int WIFI_SA_ID = 1125;
|
||||
const static int TWO_SECOND = 2;
|
||||
const static int FIVE_SECOND = 5;
|
||||
static const char* def_ssid = "OpenHarmony_Private_Net_01";
|
||||
static unique_ptr<WifiDevice> wifiDevicePtr = WifiDevice::GetInstance(WIFI_SA_ID);
|
||||
|
||||
int WiFiUtils::EnableWifi()
|
||||
@ -112,44 +111,6 @@ int WiFiUtils::DisableWifi()
|
||||
}
|
||||
}
|
||||
|
||||
int WiFiUtils::DisableThenEnable(int delaySeconds)
|
||||
{
|
||||
int ret = DisableWifi();
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("[wifi]DisableWifi fail");
|
||||
return ret;
|
||||
}
|
||||
sleep(delaySeconds);
|
||||
ret = EnableWifi();
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("[wifi]EnableWifi fail");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int WiFiUtils::CheckIsConnectToDefault(void)
|
||||
{
|
||||
WifiLinkedInfo linkInfo;
|
||||
int ret = wifiDevicePtr->GetLinkedInfo(linkInfo);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("[wifi]call GetLinkedInfo fail, ret:%d", ret);
|
||||
} else {
|
||||
char rstBuff[16];
|
||||
struct in_addr inputAddr = { 0 };
|
||||
inputAddr.s_addr = htonl(linkInfo.ipAddress);
|
||||
inet_ntop(AF_INET, &inputAddr, rstBuff, sizeof(rstBuff));
|
||||
LOG("[wifi]link info,netid:%d, ssid:%s, state:%d, ip:%u,%s", linkInfo.networkId, linkInfo.ssid.c_str(),
|
||||
linkInfo.connState, linkInfo.ipAddress, rstBuff);
|
||||
if (strncmp(linkInfo.ssid.c_str(), def_ssid, strlen(def_ssid)) == 0) {
|
||||
LOG("[wifi]check success");
|
||||
return SOFTBUS_OK;
|
||||
} else {
|
||||
LOG("[wifi]check fail");
|
||||
}
|
||||
}
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
int WiFiUtils::ConnectTo(const std::string& ssid, const std::string& passwd)
|
||||
{
|
||||
WifiDeviceConfig deviceConfig;
|
||||
@ -209,48 +170,6 @@ int WiFiUtils::ConnectToNew(const std::string& ssid, const std::string& passwd)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int WiFiUtils::ConnectToOpenAP(const std::string& ssid)
|
||||
{
|
||||
WifiDeviceConfig deviceConfig;
|
||||
deviceConfig.ssid = ssid;
|
||||
deviceConfig.keyMgmt = "NONE";
|
||||
int netId;
|
||||
int ret = wifiDevicePtr->AddDeviceConfig(deviceConfig, netId);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("[wifi]call AddDeviceConfig fail, ret:%d", ret);
|
||||
} else {
|
||||
LOG("[wifi]call AddDeviceConfig success, netId:%d", netId);
|
||||
}
|
||||
|
||||
ret = wifiDevicePtr->ConnectToNetwork(netId);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("[wifi]call ConnectTo fail, ret:%d", ret);
|
||||
return SOFTBUS_ERR;
|
||||
} else {
|
||||
LOG("[wifi]call ConnectTo success, netId:%d", netId);
|
||||
}
|
||||
sleep(FIVE_SECOND);
|
||||
int state;
|
||||
ret = wifiDevicePtr->GetWifiState(state);
|
||||
LOG("[wifi]call GetWifiState ret:%d,state:%d", ret, state);
|
||||
|
||||
WifiLinkedInfo linkInfo;
|
||||
ret = wifiDevicePtr->GetLinkedInfo(linkInfo);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("[wifi]call GetLinkedInfo fail, ret:%d", ret);
|
||||
} else {
|
||||
LOG("[wifi]call GetLinkedInfo success");
|
||||
char rstBuff[16];
|
||||
struct in_addr inputAddr = { 0 };
|
||||
inputAddr.s_addr = htonl(linkInfo.ipAddress);
|
||||
inet_ntop(AF_INET, &inputAddr, rstBuff, sizeof(rstBuff));
|
||||
|
||||
LOG("[wifi]link info,netid:%d, ssid:%s, state:%d, ip:%u,%s", linkInfo.networkId, linkInfo.ssid.c_str(),
|
||||
linkInfo.connState, linkInfo.ipAddress, rstBuff);
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int WiFiUtils::EnableThenConnect(const std::string& ssid, const std::string& passwd)
|
||||
{
|
||||
int ret = EnableWifi();
|
||||
|
@ -23,13 +23,10 @@ class WiFiUtils {
|
||||
public:
|
||||
static int EnableWifi();
|
||||
static int DisableWifi();
|
||||
static int DisableThenEnable(int delaySeconds);
|
||||
static int ConnectTo(const std::string& ssid, const std::string& passwd);
|
||||
static int ConnectToNew(const std::string& ssid, const std::string& passwd);
|
||||
static int ConnectToOpenAP(const std::string& ssid);
|
||||
static int EnableThenConnect(const std::string& ssid, const std::string& passwd);
|
||||
static int DisableThenEnableAndConnect(int delaySeconds, const std::string& ssid, const std::string& passwd);
|
||||
static int CheckIsConnectToDefault(void);
|
||||
};
|
||||
|
||||
#endif
|
54
communication/softbus_standard/dsoftbusTest/BUILD.gn
Normal file
54
communication/softbus_standard/dsoftbusTest/BUILD.gn
Normal file
@ -0,0 +1,54 @@
|
||||
# Copyright (C) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//test/xts/tools/build/suite.gni")
|
||||
|
||||
module_output_path = "dcts/softbus_base/dsoftbusTest"
|
||||
|
||||
ohos_moduletest_suite("dsoftbusTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [
|
||||
"../common/net_trans_common.c",
|
||||
"../common/wifi_utils.cpp",
|
||||
"../common/SoftBus_Test_Permission.cpp",
|
||||
"./dsoftbusTest.cpp",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"../common",
|
||||
"//third_party/cJSON",
|
||||
"//utils/native/base/include",
|
||||
"//foundation/communication/dsoftbus/core/common/include",
|
||||
"//foundation/communication/dsoftbus/adapter/common/include",
|
||||
"//foundation/communication/dsoftbus/interfaces/kits/common",
|
||||
"//foundation/communication/dsoftbus/interfaces/kits/bus_center",
|
||||
"//foundation/communication/dsoftbus/interfaces/kits/discovery",
|
||||
"//foundation/communication/dsoftbus/interfaces/kits/transport",
|
||||
"//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk/main/cpp/include",
|
||||
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/wifi_standard/include",
|
||||
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/wifi_standard/interfaces",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
|
||||
"//foundation/communication/wifi/services/wifi_standard/wifi_framework/common/net_helper",
|
||||
"//foundation/communication/wifi/services/wifi_standard/wifi_framework/common/log",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//third_party/googletest:gtest_main",
|
||||
#"//foundation/communication/dsoftbus/core/frame/standard/client:softbus_client",
|
||||
"//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk:libpermissionsdk_standard",
|
||||
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/wifi_standard:wifi_sdk",
|
||||
]
|
||||
external_deps = [
|
||||
"dsoftbus_standard:softbus_client",
|
||||
]
|
||||
}
|
21
communication/softbus_standard/dsoftbusTest/Test.json
Normal file
21
communication/softbus_standard/dsoftbusTest/Test.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"description": "Config for dsoftbusTest test cases",
|
||||
"driver": {
|
||||
"module-name": "dsoftbusTest",
|
||||
"native-test-timeout": "120000",
|
||||
"native-test-device-path": "/data/local/tmp",
|
||||
"runtime-hint": "1s",
|
||||
"type": "CppTest"
|
||||
},
|
||||
"kits": [
|
||||
{
|
||||
"post-push" : [
|
||||
"chmod -R 777 /data/local/tmp/*"
|
||||
],
|
||||
"push": [
|
||||
"dsoftbusTest->/data/local/tmp/dsoftbusTest"
|
||||
],
|
||||
"type": "PushKit"
|
||||
}
|
||||
]
|
||||
}
|
517
communication/softbus_standard/dsoftbusTest/dsoftbusTest.cpp
Normal file
517
communication/softbus_standard/dsoftbusTest/dsoftbusTest.cpp
Normal file
@ -0,0 +1,517 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "SoftBus_Test_Permission.h"
|
||||
#include "net_trans_common.h"
|
||||
#include "wifi_utils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace testing::ext;
|
||||
|
||||
static INodeStateCb* g_nodeStateCallback = NULL;
|
||||
static ISessionListener* g_sessionlist4Data = NULL;
|
||||
static ISessionListener* g_sessionlist4Ctrl = NULL;
|
||||
static ISessionListener* g_sessionlist4Perf = NULL;
|
||||
static ISessionListener* g_sessionlist4Pass = NULL;
|
||||
static ISessionListener* g_sessionlist4File = NULL;
|
||||
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";
|
||||
|
||||
static void SetupCallback(void);
|
||||
static void TeardownCallback(void);
|
||||
|
||||
class dsoftbusTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void dsoftbusTest ::SetUp() {}
|
||||
|
||||
void dsoftbusTest ::TearDown() {}
|
||||
|
||||
void dsoftbusTest ::SetUpTestCase()
|
||||
{
|
||||
LOG("SetUpTestCase");
|
||||
TestSetUp();
|
||||
SetupCallback();
|
||||
SoftBus_Test_Permission::AddPermission(DEF_PKG_NAME);
|
||||
int ret = RegNodeDeviceStateCb(DEF_PKG_NAME, g_nodeStateCallback);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "call reg node state callback fail";
|
||||
}
|
||||
|
||||
void dsoftbusTest::TearDownTestCase()
|
||||
{
|
||||
LOG("TearDownTestCase");
|
||||
int ret = UnregNodeDeviceStateCb(g_nodeStateCallback);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "call unReg node state callback fail";
|
||||
SoftBus_Test_Permission ::RemovePermission(DEF_PKG_NAME);
|
||||
TeardownCallback();
|
||||
TestTearDown();
|
||||
}
|
||||
|
||||
static int OnFileSessionOpened(int sessionId, int result)
|
||||
{
|
||||
LOG("[cb][file]open session sid[%d],rst[%d]", sessionId, result);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void OnFileSessionClosed(int sessionId)
|
||||
{
|
||||
LOG("[cb][file]close session sid[%d]", sessionId);
|
||||
}
|
||||
|
||||
static void OnFileBytesReceived(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);
|
||||
}
|
||||
}
|
||||
|
||||
static void OnFileMessageReceived(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);
|
||||
}
|
||||
}
|
||||
|
||||
/* session callback for data */
|
||||
static int OnDataSessionOpened(int sessionId, int result)
|
||||
{
|
||||
LOG("[cb][data]session opened sid:%d,ret:%d", sessionId, result);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void OnDataSessionClosed(int sessionId)
|
||||
{
|
||||
LOG("[cb][data]session closed sid:%d", sessionId);
|
||||
}
|
||||
|
||||
static void OnDataBytesReceived(int sessionId, const void* data, unsigned int dataLen)
|
||||
{
|
||||
if (sessionId < 0 || sessionId > MAX_SESSION_NUM) {
|
||||
LOG("[cb][data]byte received invalid session id[%d]", sessionId);
|
||||
return;
|
||||
}
|
||||
LOG("[cb][data]byte received sid:%d, data-len:%d", sessionId, dataLen);
|
||||
int ret = SendBytes(sessionId, data, dataLen);
|
||||
LOG("[cb][data]byte received send back:%d", ret);
|
||||
}
|
||||
|
||||
static void OnDataMessageReceived(int sessionId, const void* data, unsigned int dataLen)
|
||||
{
|
||||
if (sessionId < 0 || sessionId > MAX_SESSION_NUM) {
|
||||
LOG("[cb][data]mesg received invalid session id[%d]", sessionId);
|
||||
return;
|
||||
}
|
||||
LOG("[cb][data]mesg received sid:%d, data-len:%d", sessionId, dataLen);
|
||||
int ret = SendMessage(sessionId, data, dataLen);
|
||||
LOG("[cb][data]mesg received send back:%d", ret);
|
||||
}
|
||||
|
||||
/* session callback for control */
|
||||
static int GetCodeByMsg(const string& msg)
|
||||
{
|
||||
LOG("[ctrl] recv msg content[%s]", msg.c_str());
|
||||
int ret = -1;
|
||||
if (strncmp(msg.c_str(), CTRL_MSG_CLOSE_WIFI_TEN_SEC, strlen(CTRL_MSG_CLOSE_WIFI_TEN_SEC)) == 0) {
|
||||
ret = CTRL_CODE_CLOSE_WIFI_TEN_SEC;
|
||||
} else if (strncmp(msg.c_str(), CTRL_MSG_CLOSE_WIFI_THREE_SEC, strlen(CTRL_MSG_CLOSE_WIFI_THREE_SEC)) == 0) {
|
||||
ret = CTRL_CODE_CLOSE_WIFI_THREE_SEC;
|
||||
} else if (strncmp(msg.c_str(), CTRL_MSG_CLOSE_WIFI_TEN_MIN, strlen(CTRL_MSG_CLOSE_WIFI_TEN_MIN)) == 0) {
|
||||
ret = CTRL_CODE_CLOSE_WIFI_TEN_MIN;
|
||||
} else if (strncmp(msg.c_str(), CTRL_MSG_CLOSE_WIFI_FIVE_MIN, strlen(CTRL_MSG_CLOSE_WIFI_FIVE_MIN)) == 0) {
|
||||
ret = CTRL_CODE_CLOSE_WIFI_FIVE_MIN;
|
||||
} else if (strncmp(msg.c_str(), CTRL_MSG_CHANGE_WIFI_TEN_SEC, strlen(CTRL_MSG_CHANGE_WIFI_TEN_SEC)) == 0) {
|
||||
ret = CTRL_CODE_CHANGE_WIFI_TEN_SEC;
|
||||
} else if (strncmp(msg.c_str(), CTRL_MSG_CHANGE_WIFI_SIXTY_SEC, strlen(CTRL_MSG_CHANGE_WIFI_SIXTY_SEC)) == 0) {
|
||||
ret = CTRL_CODE_CHANGE_WIFI_SIXTY_SEC;
|
||||
} else if (strncmp(msg.c_str(), CTRL_MSG_CLOSE_BR, strlen(CTRL_MSG_CLOSE_BR)) == 0) {
|
||||
ret = CTRL_CODE_CLOSE_BR;
|
||||
} else if (strncmp(msg.c_str(), CTRL_MSG_CLOSE_OPEN_BR, strlen(CTRL_MSG_CLOSE_OPEN_BR)) == 0) {
|
||||
ret = CTRL_CODE_CLOSE_OPEN_BR;
|
||||
} else if (strncmp(msg.c_str(), CTRL_MSG_OPEN_SESSION, strlen(CTRL_MSG_OPEN_SESSION)) == 0) {
|
||||
ret = CTRL_CODE_OPEN_SESSION;
|
||||
} else if (strncmp(msg.c_str(), CTRL_MSG_OPEN_SESSION_MSG, strlen(CTRL_MSG_OPEN_SESSION_MSG)) == 0) {
|
||||
ret = CTRL_CODE_OPEN_SESSION_MSG;
|
||||
} else if (strncmp(msg.c_str(), CTRL_MSG_OPEN_SESSION_NOT_EXIST, strlen(CTRL_MSG_OPEN_SESSION_NOT_EXIST)) == 0) {
|
||||
ret = CTRL_CODE_OPEN_SESSION_NOT_EXIST;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void* CtrlOperateTask(void* param)
|
||||
{
|
||||
LOG("[operate] start...");
|
||||
int code = -1;
|
||||
if (param != NULL) {
|
||||
code = *((int*)param);
|
||||
}
|
||||
LOG("[operate] code:%d", code);
|
||||
int ret;
|
||||
int sleepTime;
|
||||
switch (code) {
|
||||
case CTRL_CODE_CLOSE_WIFI_TEN_SEC:
|
||||
WiFiUtils ::DisableThenEnableAndConnect(10, def_ssid, def_passwd);
|
||||
break;
|
||||
case CTRL_CODE_CLOSE_WIFI_THREE_SEC:
|
||||
WiFiUtils ::DisableThenEnableAndConnect(3, def_ssid, def_passwd);
|
||||
break;
|
||||
case CTRL_CODE_CLOSE_WIFI_TEN_MIN:
|
||||
sleepTime = 660;
|
||||
WiFiUtils ::DisableWifi();
|
||||
while (sleepTime > 0) {
|
||||
sleep(10);
|
||||
sleepTime -= 10;
|
||||
LOG("[operate][close wifi 10mins] wait:%d", sleepTime);
|
||||
}
|
||||
WiFiUtils ::EnableThenConnect(def_ssid, def_passwd);
|
||||
break;
|
||||
case CTRL_CODE_CLOSE_WIFI_FIVE_MIN:
|
||||
sleepTime = 330;
|
||||
WiFiUtils ::DisableWifi();
|
||||
while (sleepTime > 0) {
|
||||
sleep(10);
|
||||
sleepTime -= 10;
|
||||
LOG("[operate][close wifi 5mins] wait:%d", sleepTime);
|
||||
}
|
||||
WiFiUtils ::EnableThenConnect(def_ssid, def_passwd);
|
||||
break;
|
||||
case CTRL_CODE_CHANGE_WIFI_TEN_SEC:
|
||||
sleepTime = 10;
|
||||
ret = WiFiUtils ::ConnectToNew(slave_ssid, def_passwd);
|
||||
LOG("[operate]connect to salve ret:%d", ret);
|
||||
LOG("[operate]start sleep:%d", sleepTime);
|
||||
sleep(sleepTime);
|
||||
ret = WiFiUtils ::ConnectToNew(def_ssid, def_passwd);
|
||||
LOG("[operate]connect to default ret:%d", ret);
|
||||
break;
|
||||
case CTRL_CODE_CHANGE_WIFI_SIXTY_SEC:
|
||||
sleepTime = 60;
|
||||
ret = WiFiUtils ::ConnectToNew(slave_ssid, def_passwd);
|
||||
LOG("[operate]connect to salve ret:%d", ret);
|
||||
LOG("[operate]start sleep:%d", sleepTime);
|
||||
sleep(sleepTime);
|
||||
ret = WiFiUtils ::ConnectToNew(def_ssid, def_passwd);
|
||||
LOG("[operate]connect to default ret:%d", ret);
|
||||
break;
|
||||
case CTRL_CODE_CLOSE_BR:
|
||||
// close br
|
||||
LOG("[operate]close br TODO...");
|
||||
break;
|
||||
case CTRL_CODE_CLOSE_OPEN_BR:
|
||||
// close open br
|
||||
LOG("[operate]close-open br TODO...");
|
||||
break;
|
||||
case CTRL_CODE_OPEN_SESSION:
|
||||
// open session and send byte
|
||||
LOG("[operate]open session TODO...");
|
||||
break;
|
||||
case CTRL_CODE_OPEN_SESSION_NOT_EXIST:
|
||||
// open session not exist
|
||||
LOG("[operate]open session not exist TODO...");
|
||||
break;
|
||||
case CTRL_CODE_OPEN_SESSION_MSG:
|
||||
// open session and send msg
|
||||
LOG("[operate]open session not exist TODO...");
|
||||
break;
|
||||
default:
|
||||
LOG("[operate]not support this code");
|
||||
break;
|
||||
}
|
||||
free(param);
|
||||
LOG("[operate] end");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int OnCtrlSessionOpened(int sessionId, int result)
|
||||
{
|
||||
LOG("[cb][ctrl]session opened sid:%d, ret:%d", sessionId, result);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void OnCtrlSessionClosed(int sessionId)
|
||||
{
|
||||
LOG("[cb][ctrl]session closed sid:%d", sessionId);
|
||||
}
|
||||
|
||||
static void OnCtrlBytesReceived(int sessionId, const void* data, unsigned int dataLen)
|
||||
{
|
||||
if (sessionId < 0 || sessionId > MAX_SESSION_NUM) {
|
||||
LOG("[cb][ctrl]byte received invalid session id[%d]", sessionId);
|
||||
return;
|
||||
}
|
||||
LOG("[cb][ctrl]byte received sid:%d, data-len:%d", sessionId, dataLen);
|
||||
int ret = SendBytes(sessionId, data, dataLen);
|
||||
LOG("[cb][ctrl]byte received send back:%d", ret);
|
||||
}
|
||||
|
||||
static void OnCtrlMessageReceived(int sessionId, const void* data, unsigned int dataLen)
|
||||
{
|
||||
if (sessionId < 0 || sessionId > MAX_SESSION_NUM) {
|
||||
LOG("[cb][ctrl]mesg received invalid session id[%d]", sessionId);
|
||||
return;
|
||||
}
|
||||
LOG("[cb][ctrl]mesg received sid:%d, data-len:%d", sessionId, dataLen);
|
||||
int ret = SendMessage(sessionId, data, dataLen);
|
||||
LOG("[cb][ctrl]mesg received send back:%d", ret);
|
||||
|
||||
// operate
|
||||
unsigned int maxCtrlLen = 25;
|
||||
if (dataLen < maxCtrlLen) {
|
||||
int* code = (int*)malloc(sizeof(int));
|
||||
*code = GetCodeByMsg((char*)data);
|
||||
LOG("[cb][ctrl]GetCodeByMsg is:%d", *code);
|
||||
if (*code != -1) {
|
||||
pthread_t ctrlThread;
|
||||
ret = pthread_create(&ctrlThread, nullptr, CtrlOperateTask, code);
|
||||
LOG("[cb][ctrl]create ctrl thread ret:%d", ret);
|
||||
} else {
|
||||
free(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* session callback for performance */
|
||||
static int OnPerfSessionOpened(int sessionId, int result)
|
||||
{
|
||||
LOG("[cb][perf]session opened sid:%d, ret:%d", sessionId, result);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void OnPerfSessionClosed(int sessionId)
|
||||
{
|
||||
LOG("[cb][perf]session closed sid:%d", sessionId);
|
||||
}
|
||||
|
||||
static void OnPerfBytesReceived(int sessionId, const void* data, unsigned int dataLen)
|
||||
{
|
||||
if (sessionId < 0 || sessionId > MAX_SESSION_NUM) {
|
||||
LOG("[cb][perf]byte received invalid session id[%d]", sessionId);
|
||||
return;
|
||||
}
|
||||
LOG("[cb][perf]byte received sid:%d, data-len:%d", sessionId, dataLen);
|
||||
int ret = SendBytes(sessionId, data, dataLen);
|
||||
LOG("[cb][perf]byte received send back:%d", ret);
|
||||
}
|
||||
|
||||
static void OnPerfMessageReceived(int sessionId, const void* data, unsigned int dataLen)
|
||||
{
|
||||
if (sessionId < 0 || sessionId > MAX_SESSION_NUM) {
|
||||
LOG("[cb][perf]mesg received invalid session id[%d]", sessionId);
|
||||
return;
|
||||
}
|
||||
LOG("[cb][perf]mesg received sid:%d, data-len:%d", sessionId, dataLen);
|
||||
int ret = SendMessage(sessionId, data, dataLen);
|
||||
LOG("[cb][perf]mesg received send back:%d", ret);
|
||||
}
|
||||
|
||||
/* session callback for passive*/
|
||||
static int OnPassSessionOpened(int sessionId, int result)
|
||||
{
|
||||
LOG("[cb][pass]session opened sid:%d, ret:%d", sessionId, result);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void OnPassSessionClosed(int sessionId)
|
||||
{
|
||||
LOG("[cb][pass]session closed sid:%d", sessionId);
|
||||
}
|
||||
|
||||
static void OnPassBytesReceived(int sessionId, const void* data, unsigned int dataLen)
|
||||
{
|
||||
if (sessionId < 0 || sessionId > MAX_SESSION_NUM) {
|
||||
LOG("[cb][pass]byte received invalid session id[%d]", sessionId);
|
||||
return;
|
||||
}
|
||||
LOG("[cb][pass]byte received sid:%d, data-len:%d", sessionId, dataLen);
|
||||
}
|
||||
|
||||
static void OnPassMessageReceived(int sessionId, const void* data, unsigned int dataLen)
|
||||
{
|
||||
if (sessionId < 0 || sessionId > MAX_SESSION_NUM) {
|
||||
LOG("[cb][pass]mesg received invalid session id[%d]", sessionId);
|
||||
return;
|
||||
}
|
||||
LOG("[cb][pass]mesg received sid:%d, data-len:%d", sessionId, dataLen);
|
||||
}
|
||||
|
||||
/* net state callback */
|
||||
static void OnNodeOnline(NodeBasicInfo* info)
|
||||
{
|
||||
if (info == NULL) {
|
||||
LOG("[cb]Online: info is null");
|
||||
}
|
||||
|
||||
LOG("[cb]Online id:%s, name:%s ,type id:%u", info->networkId, info->deviceName, info->deviceTypeId);
|
||||
}
|
||||
|
||||
static void OnNodeOffline(NodeBasicInfo* info)
|
||||
{
|
||||
if (info == NULL) {
|
||||
LOG("[cb]Offline: info is null");
|
||||
return;
|
||||
}
|
||||
|
||||
LOG("[cb]Offline id:%s, name:%s ,type id:%u", info->networkId, info->deviceName, info->deviceTypeId);
|
||||
}
|
||||
|
||||
static void OnNodeBasicInfoChanged(NodeBasicInfoType type, NodeBasicInfo* info)
|
||||
{
|
||||
if (info == NULL) {
|
||||
LOG("[cb]InfoChanged: info is null, type[%d]", type);
|
||||
return;
|
||||
}
|
||||
LOG("[cb]InfoChanged id: %s, name: %s", info->networkId, info->deviceName);
|
||||
}
|
||||
|
||||
static void SetupCallback(void)
|
||||
{
|
||||
if (g_sessionlist4Data == NULL) {
|
||||
g_sessionlist4Data = (ISessionListener*)calloc(1, sizeof(ISessionListener));
|
||||
g_sessionlist4Data->OnSessionOpened = OnDataSessionOpened;
|
||||
g_sessionlist4Data->OnSessionClosed = OnDataSessionClosed;
|
||||
g_sessionlist4Data->OnMessageReceived = OnDataMessageReceived;
|
||||
g_sessionlist4Data->OnBytesReceived = OnDataBytesReceived;
|
||||
}
|
||||
|
||||
if (g_sessionlist4Ctrl == NULL) {
|
||||
g_sessionlist4Ctrl = (ISessionListener*)calloc(1, sizeof(ISessionListener));
|
||||
g_sessionlist4Ctrl->OnSessionOpened = OnCtrlSessionOpened;
|
||||
g_sessionlist4Ctrl->OnSessionClosed = OnCtrlSessionClosed;
|
||||
g_sessionlist4Ctrl->OnMessageReceived = OnCtrlMessageReceived;
|
||||
g_sessionlist4Ctrl->OnBytesReceived = OnCtrlBytesReceived;
|
||||
}
|
||||
|
||||
if (g_sessionlist4Perf == NULL) {
|
||||
g_sessionlist4Perf = (ISessionListener*)calloc(1, sizeof(ISessionListener));
|
||||
g_sessionlist4Perf->OnSessionOpened = OnPerfSessionOpened;
|
||||
g_sessionlist4Perf->OnSessionClosed = OnPerfSessionClosed;
|
||||
g_sessionlist4Perf->OnMessageReceived = OnPerfMessageReceived;
|
||||
g_sessionlist4Perf->OnBytesReceived = OnPerfBytesReceived;
|
||||
}
|
||||
|
||||
if (g_sessionlist4Pass == NULL) {
|
||||
g_sessionlist4Pass = (ISessionListener*)calloc(1, sizeof(ISessionListener));
|
||||
g_sessionlist4Pass->OnSessionOpened = OnPassSessionOpened;
|
||||
g_sessionlist4Pass->OnSessionClosed = OnPassSessionClosed;
|
||||
g_sessionlist4Pass->OnMessageReceived = OnPassMessageReceived;
|
||||
g_sessionlist4Pass->OnBytesReceived = OnPassBytesReceived;
|
||||
}
|
||||
|
||||
if (g_sessionlist4File == NULL) {
|
||||
g_sessionlist4File = (ISessionListener*)calloc(1, sizeof(ISessionListener));
|
||||
g_sessionlist4File->OnSessionOpened = OnFileSessionOpened;
|
||||
g_sessionlist4File->OnSessionClosed = OnFileSessionClosed;
|
||||
g_sessionlist4File->OnMessageReceived = OnFileMessageReceived;
|
||||
g_sessionlist4File->OnBytesReceived = OnFileBytesReceived;
|
||||
}
|
||||
|
||||
if (g_nodeStateCallback == NULL) {
|
||||
g_nodeStateCallback = (INodeStateCb*)calloc(1, sizeof(INodeStateCb));
|
||||
g_nodeStateCallback->events = EVENT_NODE_STATE_MASK;
|
||||
g_nodeStateCallback->onNodeOnline = OnNodeOnline;
|
||||
g_nodeStateCallback->onNodeOffline = OnNodeOffline;
|
||||
g_nodeStateCallback->onNodeBasicInfoChanged = OnNodeBasicInfoChanged;
|
||||
}
|
||||
}
|
||||
|
||||
static void TeardownCallback(void)
|
||||
{
|
||||
if (g_sessionlist4Data != NULL) {
|
||||
free(g_sessionlist4Data);
|
||||
g_sessionlist4Data = NULL;
|
||||
}
|
||||
if (g_sessionlist4Ctrl != NULL) {
|
||||
free(g_sessionlist4Ctrl);
|
||||
g_sessionlist4Ctrl = NULL;
|
||||
}
|
||||
if (g_sessionlist4Perf != NULL) {
|
||||
free(g_sessionlist4Perf);
|
||||
g_sessionlist4Perf = NULL;
|
||||
}
|
||||
if (g_sessionlist4Pass != NULL) {
|
||||
free(g_sessionlist4Pass);
|
||||
g_sessionlist4Pass = NULL;
|
||||
}
|
||||
if (g_sessionlist4File != NULL) {
|
||||
free(g_sessionlist4File);
|
||||
g_sessionlist4File = NULL;
|
||||
}
|
||||
if (g_nodeStateCallback != NULL) {
|
||||
free(g_nodeStateCallback);
|
||||
g_nodeStateCallback = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_SelfNet_0100
|
||||
* @tc.name : 创建SS,等待opensession和消息传输
|
||||
* @tc.desc : 测试自组网下传输功能,模拟服务端
|
||||
* @tc.type : FUNC
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(dsoftbusTest, test_create_ss, TestSize.Level3)
|
||||
{
|
||||
int dataRet = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA, g_sessionlist4Data);
|
||||
LOG("CreateSs[data] ret:%d", dataRet);
|
||||
int ctrlRet = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_CTL, g_sessionlist4Ctrl);
|
||||
LOG("CreateSs[ctrl] ret:%d", ctrlRet);
|
||||
int perfRet = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_PERF, g_sessionlist4Perf);
|
||||
LOG("CreateSs[perf] ret:%d", perfRet);
|
||||
int passRet = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_PASS, g_sessionlist4Pass);
|
||||
LOG("CreateSs[pass] ret:%d", passRet);
|
||||
int fileRet = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE, g_sessionlist4File);
|
||||
LOG("CreateSs[file] ret:%d", fileRet);
|
||||
|
||||
int timeout = 10;
|
||||
if (dataRet == SOFTBUS_OK && ctrlRet == SOFTBUS_OK && perfRet == SOFTBUS_OK && passRet == SOFTBUS_OK &&
|
||||
fileRet == SOFTBUS_OK) {
|
||||
timeout = 9000;
|
||||
}
|
||||
|
||||
int ret = SetFileSendListener(DEF_PKG_NAME, SESSION_NAME_FILE, GetSendFileListener());
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("##set send listener fail:%d", ret);
|
||||
}
|
||||
ret = SetFileReceiveListener(DEF_PKG_NAME, SESSION_NAME_FILE, GetRecvFileListener(), RECV_FILE_PATH);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG("##set recv listener fail:%d", ret);
|
||||
}
|
||||
|
||||
while (timeout > 0) {
|
||||
sleep(10);
|
||||
timeout -= 10;
|
||||
LOG("###wait:%d", timeout);
|
||||
}
|
||||
|
||||
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA);
|
||||
LOG("RemoveSs[data] ret:%d", ret);
|
||||
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_CTL);
|
||||
LOG("RemoveSs[ctrl] ret:%d", ret);
|
||||
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_PERF);
|
||||
LOG("RemoveSs[perf] ret:%d", ret);
|
||||
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_PASS);
|
||||
LOG("RemoveSs[pass] ret:%d", ret);
|
||||
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE);
|
||||
LOG("RemoveSs[file] ret:%d", ret);
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
# Copyright (C) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//test/xts/tools/build/suite.gni")
|
||||
|
||||
module_output_path = "dcts/softbus_base/transmission/reliability"
|
||||
|
||||
ohos_moduletest_suite("DctsSoftBusTransReliabilityTest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [
|
||||
"../../common/SoftBus_Test_Permission.cpp",
|
||||
"../../common/net_trans_common.c",
|
||||
"../../common/wifi_utils.cpp",
|
||||
"./trans_reliability_test.cpp",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"../../common",
|
||||
"//third_party/cJSON",
|
||||
"//utils/native/base/include",
|
||||
"//foundation/communication/dsoftbus/core/common/include",
|
||||
"//foundation/communication/dsoftbus/adapter/common/include",
|
||||
"//foundation/communication/dsoftbus/interfaces/kits/common",
|
||||
"//foundation/communication/dsoftbus/interfaces/kits/bus_center",
|
||||
"//foundation/communication/dsoftbus/interfaces/kits/discovery",
|
||||
"//foundation/communication/dsoftbus/interfaces/kits/transport",
|
||||
"//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk/main/cpp/include",
|
||||
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/wifi_standard/include",
|
||||
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/wifi_standard/interfaces",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
|
||||
"//foundation/communication/wifi/services/wifi_standard/wifi_framework/common/net_helper",
|
||||
"//foundation/communication/wifi/services/wifi_standard/wifi_framework/common/log",
|
||||
]
|
||||
|
||||
deps = [
|
||||
#"//foundation/communication/dsoftbus/core/frame/standard/client:softbus_client",
|
||||
"//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk:libpermissionsdk_standard",
|
||||
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/wifi_standard:wifi_sdk",
|
||||
"//third_party/googletest:gtest_main",
|
||||
]
|
||||
external_deps = [ "dsoftbus_standard:softbus_client" ]
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
{
|
||||
"description": "Config for DctsSoftBusTransReliabilityTest test cases",
|
||||
"driver": {
|
||||
"module-name": "DctsSoftBusTransReliabilityTest",
|
||||
"native-test-timeout": "120000",
|
||||
"native-test-device-path": "/data/local/tmp",
|
||||
"runtime-hint": "1s",
|
||||
"type": "CppTest"
|
||||
},
|
||||
"kits": [
|
||||
{
|
||||
"post-push" : [
|
||||
"chmod -R 777 /data/local/tmp/*"
|
||||
],
|
||||
"push": [
|
||||
"DctsSoftBusTransReliabilityTest->/data/local/tmp/DctsSoftBusTransReliabilityTest"
|
||||
],
|
||||
"type": "PushKit"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,683 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "SoftBus_Test_Permission.h"
|
||||
#include "net_trans_common.h"
|
||||
#include "wifi_utils.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
|
||||
static const int EXPECT_INVALID_PARAM = -998;
|
||||
|
||||
class TransReliabilityTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void TransReliabilityTest::SetUp() {}
|
||||
|
||||
void TransReliabilityTest::TearDown() {}
|
||||
|
||||
void TransReliabilityTest::SetUpTestCase()
|
||||
{
|
||||
LOG("SetUp begin");
|
||||
TestSetUp();
|
||||
SoftBus_Test_Permission::AddPermission(DEF_PKG_NAME);
|
||||
|
||||
int ret = RegisterDeviceStateDefCallback();
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "call reg node state callback fail";
|
||||
|
||||
ret = CheckRemoteDeviceIsNull(BOOL_TRUE);
|
||||
ASSERT_EQ(SOFTBUS_OK, ret) << "get node fail,please check network";
|
||||
|
||||
LOG("SetUp end");
|
||||
}
|
||||
|
||||
void TransReliabilityTest::TearDownTestCase()
|
||||
{
|
||||
int ret = UnRegisterDeviceStateDefCallback();
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "call unReg node state callback fail";
|
||||
|
||||
TestTearDown();
|
||||
SoftBus_Test_Permission::RemovePermission(DEF_PKG_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_Reli_0100
|
||||
* @tc.name : SessionId doesn’t exist,Failed to send byte
|
||||
* @tc.desc : Test Transceiver data reliability
|
||||
* @tc.type : RELI
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Reli_0100, TestSize.Level3)
|
||||
{
|
||||
int ret;
|
||||
int sessionId = 0;
|
||||
string data = "invalid session id";
|
||||
ret = SendBytes(sessionId, data.c_str(), data.length());
|
||||
EXPECT_NE(SOFTBUS_OK, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_Reli_0200
|
||||
* @tc.name : SessionId closed,Failed to send byte
|
||||
* @tc.desc : Test Transceiver data reliability
|
||||
* @tc.type : RELI
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Reli_0200, TestSize.Level3)
|
||||
{
|
||||
int ret;
|
||||
ret = CreateSsAndOpenSession4Data();
|
||||
ASSERT_EQ(SOFTBUS_OK, ret) << "CreateSsAndOpenSession4Data fail";
|
||||
|
||||
int sessionId = GetCurrentSessionId4Data();
|
||||
ret = CloseSessionAndRemoveSs4Data();
|
||||
ASSERT_EQ(SOFTBUS_OK, ret);
|
||||
|
||||
string data = "session closed";
|
||||
ret = SendBytes(sessionId, data.c_str(), data.length());
|
||||
EXPECT_NE(SOFTBUS_OK, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_Reli_0300
|
||||
* @tc.name : send data during OpenSession
|
||||
* @tc.desc : Test Transceiver data reliability
|
||||
* @tc.type : FUNC
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Reli_0300, TestSize.Level3)
|
||||
{
|
||||
int ret;
|
||||
char* softbusPidStart;
|
||||
char* softbusPidEnd;
|
||||
softbusPidStart = GetSoftbusPid();
|
||||
EXPECT_TRUE(softbusPidStart != NULL);
|
||||
|
||||
const int count = 4;
|
||||
int sessionId4Data[count];
|
||||
int sessionId4Ctrl[count];
|
||||
char groupId[][GROUP_ID_LEN] = { "g1", "g2", "g3", "g4" };
|
||||
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_CTL, GetSessionListenser4Ctl());
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS-ctrl fail";
|
||||
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA, GetSessionListenser4Data());
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS-data fail";
|
||||
for (int i = 0; i < count; i++) {
|
||||
sessionId4Data[i] =
|
||||
OpenSession(SESSION_NAME_DATA, SESSION_NAME_DATA, GetNetworkId(), groupId[i], GetSessionAttr4Data());
|
||||
sessionId4Ctrl[i] =
|
||||
OpenSession(SESSION_NAME_CTL, SESSION_NAME_CTL, GetNetworkId(), groupId[i], GetSessionAttr4Ctl());
|
||||
}
|
||||
|
||||
// send data
|
||||
char* sendData = (char*)malloc(TRANS_BYTES_LENGTH_MAX);
|
||||
ASSERT_TRUE(sendData != NULL);
|
||||
(void)memset_s(sendData, TRANS_BYTES_LENGTH_MAX, 'C', TRANS_BYTES_LENGTH_MAX);
|
||||
for (int i = 0; i < count; i++) {
|
||||
ret = SendBytes(sessionId4Data[i], sendData, TRANS_BYTES_LENGTH_MAX);
|
||||
LOG("######sid:%d, send byte:%d", sessionId4Data[i], ret);
|
||||
ret = SendBytes(sessionId4Ctrl[i], sendData, TRANS_BYTES_LENGTH_MAX);
|
||||
LOG("######sid:%d, send byte:%d", sessionId4Ctrl[i], ret);
|
||||
}
|
||||
for (int i = 0; i < count; i++) {
|
||||
ret = SendMessage(sessionId4Data[i], sendData, TRANS_BYTES_LENGTH_MAX);
|
||||
LOG("######sid:%d, send msg:%d", sessionId4Data[i], ret);
|
||||
ret = SendMessage(sessionId4Ctrl[i], sendData, TRANS_BYTES_LENGTH_MAX);
|
||||
LOG("######sid:%d, send msg:%d", sessionId4Ctrl[i], ret);
|
||||
}
|
||||
|
||||
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_CTL);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSessionServer fail";
|
||||
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSessionServer fail";
|
||||
|
||||
softbusPidEnd = GetSoftbusPid();
|
||||
EXPECT_TRUE(softbusPidEnd != NULL);
|
||||
EXPECT_STREQ(softbusPidStart, softbusPidEnd);
|
||||
free(softbusPidStart);
|
||||
free(softbusPidEnd);
|
||||
free(sendData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_Reli_0400
|
||||
* @tc.name : SessionId doesn’t exist,Failed to send Message
|
||||
* @tc.desc : Test Transceiver data reliability
|
||||
* @tc.type : RELI
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Reli_0400, TestSize.Level3)
|
||||
{
|
||||
int ret;
|
||||
int sessionId = 0;
|
||||
string data = "invalid session id";
|
||||
ret = SendMessage(sessionId, data.c_str(), data.length());
|
||||
EXPECT_NE(SOFTBUS_OK, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_Session_Reli_0100
|
||||
* @tc.name : CreateSessionServer_重复创建
|
||||
* @tc.desc : 测试会话管理可靠性
|
||||
* @tc.type : RELI
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Session_Reli_0100, TestSize.Level3)
|
||||
{
|
||||
int ret;
|
||||
char sessionNames[][SESSION_NAME_SIZE_MAX] = { "com.communication.demo1.1", "com.communication.demo1.2",
|
||||
"com.communication.demo1.3", "com.communication.demo1.4", "com.communication.demo1.5",
|
||||
"com.communication.demo1.6", "com.communication.demo1.7", "com.communication.demo1.8" };
|
||||
|
||||
for (int i = 0; i < MAX_SESSION_SERVER_NUM_CLIENT; i++) {
|
||||
ret = CreateSessionServer(DEF_PKG_NAME, sessionNames[i], GetSessionListenser4Data());
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS fail,i=" << i;
|
||||
}
|
||||
|
||||
// repeat once, expect success
|
||||
for (int i = 0; i < MAX_SESSION_SERVER_NUM_CLIENT; i++) {
|
||||
ret = CreateSessionServer(DEF_PKG_NAME, sessionNames[i], GetSessionListenser4Data());
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS success[repeat],i=" << i;
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_SESSION_SERVER_NUM_CLIENT; i++) {
|
||||
ret = RemoveSessionServer(DEF_PKG_NAME, sessionNames[i]);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS fail,i=" << i;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_Session_Reli_0200
|
||||
* @tc.name : CreateSessionServer参数_异常输入
|
||||
* @tc.desc : 测试会话管理可靠性
|
||||
* @tc.type : RELI
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Session_Reli_0200, TestSize.Level3)
|
||||
{
|
||||
int ret;
|
||||
ret = CreateSessionServer(NULL, SESSION_NAME_DATA, GetSessionListenser4Data());
|
||||
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "CreateSS[pkg name null]";
|
||||
ret = CreateSessionServer(DEF_PKG_NAME, NULL, GetSessionListenser4Data());
|
||||
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "CreateSS[session name null]";
|
||||
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA, NULL);
|
||||
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "CreateSS[session listener null]";
|
||||
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]";
|
||||
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_Session_Reli_0300
|
||||
* @tc.name : RemoveSessionServer_删除未创建的Server
|
||||
* @tc.desc : 测试会话管理可靠性
|
||||
* @tc.type : RELI
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Session_Reli_0300, TestSize.Level3)
|
||||
{
|
||||
int ret;
|
||||
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "RemoveSS success[not create]";
|
||||
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_CTL);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "RemoveSS success[not create]";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_Session_Reli_0400
|
||||
* @tc.name : RemoveSessionServer_重复删除
|
||||
* @tc.desc : 测试会话管理可靠性
|
||||
* @tc.type : RELI
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Session_Reli_0400, TestSize.Level3)
|
||||
{
|
||||
int ret;
|
||||
char sessionNames[][SESSION_NAME_SIZE_MAX] = { "com.communication.demo1.1", "com.communication.demo1.2",
|
||||
"com.communication.demo1.3", "com.communication.demo1.4", "com.communication.demo1.5",
|
||||
"com.communication.demo1.6", "com.communication.demo1.7", "com.communication.demo1.8" };
|
||||
for (int i = 0; i < MAX_SESSION_SERVER_NUM_CLIENT; i++) {
|
||||
ret = CreateSessionServer(DEF_PKG_NAME, sessionNames[i], GetSessionListenser4Data());
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS fail,i=" << i;
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_SESSION_SERVER_NUM_CLIENT; i++) {
|
||||
ret = RemoveSessionServer(DEF_PKG_NAME, sessionNames[i]);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS fail,i=" << i;
|
||||
}
|
||||
// repeat once, expect fail
|
||||
for (int i = 0; i < MAX_SESSION_SERVER_NUM_CLIENT; i++) {
|
||||
ret = RemoveSessionServer(DEF_PKG_NAME, sessionNames[i]);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "RemoveSS success[repeat],i=" << i;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_Session_Reli_0500
|
||||
* @tc.name : RemoveSessionServer参数_异常输入
|
||||
* @tc.desc : 测试会话管理可靠性
|
||||
* @tc.type : RELI
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Session_Reli_0500, TestSize.Level3)
|
||||
{
|
||||
int ret;
|
||||
ret = RemoveSessionServer(NULL, SESSION_NAME_DATA);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "RemoveSS success[pkg name null]";
|
||||
ret = RemoveSessionServer(DEF_PKG_NAME, NULL);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "RemoveSS success[session name null]";
|
||||
ret = RemoveSessionServer(NULL, NULL);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "RemoveSS success[all null]";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_Session_Reli_0600
|
||||
* @tc.name : RemoveSessionServer_存在未关闭session
|
||||
* @tc.desc : 测试会话管理可靠性
|
||||
* @tc.type : RELI
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Session_Reli_0600, TestSize.Level3)
|
||||
{
|
||||
int ret;
|
||||
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA, GetSessionListenser4Data());
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS[data] fail";
|
||||
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_CTL, GetSessionListenser4Ctl());
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS[ctrl] fail";
|
||||
|
||||
int count = MAX_SESSION_NUM / 2;
|
||||
int sessionId4Data[count];
|
||||
int sessionId4Ctrl[count];
|
||||
char groupId[][GROUP_ID_LEN] = { "g1", "g2", "g3", "g4", "g5", "g6", "g7", "g8" };
|
||||
ret = OpenSessionBatch4Data(groupId, sessionId4Data, count);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "OpenSessionWithDiffGroupId4Data fail";
|
||||
ret = OpenSessionBatch4Ctl(groupId, sessionId4Ctrl, count);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "OpenSessionWithDiffGroupId4Ctl fail";
|
||||
|
||||
ResetClosedSessionCount4Ctrl();
|
||||
ResetClosedSessionCount4Data();
|
||||
// remove session server, will close opened session
|
||||
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS[data] fail";
|
||||
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_CTL);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS[ctrl] fail";
|
||||
|
||||
// check close session callback
|
||||
int timeout = 20;
|
||||
while (timeout > 0) {
|
||||
sleep(1);
|
||||
if (GetClosedSessionCount4Ctrl() == count && GetClosedSessionCount4Data() == count) {
|
||||
LOG("callback count right, timeout:%d", timeout);
|
||||
break;
|
||||
}
|
||||
timeout--;
|
||||
}
|
||||
EXPECT_EQ(count, GetClosedSessionCount4Ctrl());
|
||||
EXPECT_EQ(count, GetClosedSessionCount4Data());
|
||||
|
||||
// create new,expect success
|
||||
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA, GetSessionListenser4Data());
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS[data] fail";
|
||||
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_CTL, GetSessionListenser4Ctl());
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS[ctrl] fail";
|
||||
ret = OpenSessionBatch4Data(groupId, sessionId4Data, count);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "OpenSessionWithDiffGroupId4Data fail";
|
||||
ret = OpenSessionBatch4Ctl(groupId, sessionId4Ctrl, count);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "OpenSessionWithDiffGroupId4Ctl fail";
|
||||
|
||||
// close session,expect success
|
||||
ret = CloseSessionBatch4Data(sessionId4Data, count);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionBatch4Data fail";
|
||||
ret = CloseSessionBatch4Ctl(sessionId4Ctrl, count);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionBatch4Ctl fail";
|
||||
|
||||
// remove session server
|
||||
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS[data] fail";
|
||||
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_CTL);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS[ctrl] fail";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_Session_Reli_0700
|
||||
* @tc.name : OpenSession_未创建SessionServer
|
||||
* @tc.desc : 测试会话管理可靠性
|
||||
* @tc.type : RELI
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Session_Reli_0700, TestSize.Level3)
|
||||
{
|
||||
int ret;
|
||||
int sessionId;
|
||||
ResetWaitFlag4Data();
|
||||
sessionId = OpenSession(SESSION_NAME_DATA, SESSION_NAME_DATA, GetNetworkId(), DEF_GROUP_ID, GetSessionAttr4Data());
|
||||
EXPECT_TRUE(sessionId < SESSION_ID_MIN) << "call OpenSession success,sid:" << sessionId;
|
||||
SetCurrentSessionId4Data(sessionId);
|
||||
ret = Wait4Session(5, SESSION_4DATA);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "Wait4Session success";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_Session_Reli_0800
|
||||
* @tc.name : OpenSession_重复open同一个
|
||||
* @tc.desc : 测试会话管理可靠性
|
||||
* @tc.type : RELI
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Session_Reli_0800, TestSize.Level3)
|
||||
{
|
||||
int ret;
|
||||
int sessionId;
|
||||
ret = CreateSsAndOpenSession4Data();
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSsAndOpenSession4Data fail";
|
||||
sessionId = GetCurrentSessionId4Data();
|
||||
|
||||
// open session repeat
|
||||
int reSid;
|
||||
ResetWaitFlag4Data();
|
||||
reSid = OpenSession(SESSION_NAME_DATA, SESSION_NAME_DATA, GetNetworkId(), DEF_GROUP_ID, GetSessionAttr4Data());
|
||||
EXPECT_EQ(sessionId, reSid) << "repeat open sid not match";
|
||||
|
||||
ret = CloseSessionAndRemoveSs4Data();
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionAndRemoveSs4Data fail";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_Session_Reli_0900
|
||||
* @tc.name : OpenSession参数_异常输入
|
||||
* @tc.desc : 测试会话管理可靠性
|
||||
* @tc.type : RELI
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Session_Reli_0900, TestSize.Level3)
|
||||
{
|
||||
int ret;
|
||||
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA, GetSessionListenser4Data());
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSessionServer fail";
|
||||
|
||||
int sessionId;
|
||||
sessionId = OpenSession(NULL, SESSION_NAME_DATA, GetNetworkId(), DEF_GROUP_ID, GetSessionAttr4Data());
|
||||
EXPECT_TRUE(sessionId < SESSION_ID_MIN) << "call opensession success[my name null]";
|
||||
|
||||
sessionId = OpenSession(SESSION_NAME_DATA, NULL, GetNetworkId(), DEF_GROUP_ID, GetSessionAttr4Data());
|
||||
EXPECT_TRUE(sessionId < SESSION_ID_MIN) << "call opensession success[peer name null]";
|
||||
|
||||
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]";
|
||||
|
||||
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]";
|
||||
|
||||
sessionId = OpenSession(SESSION_NAME_DATA, SESSION_NAME_DATA, GetNetworkId(), NULL, GetSessionAttr4Data());
|
||||
EXPECT_TRUE(sessionId < SESSION_ID_MIN) << "call opensession success[group id null]";
|
||||
|
||||
sessionId = OpenSession(SESSION_NAME_DATA, SESSION_NAME_DATA, GetNetworkId(), DEF_GROUP_ID, NULL);
|
||||
EXPECT_TRUE(sessionId < SESSION_ID_MIN) << "call opensession success[arrt null]";
|
||||
|
||||
SessionAttribute sAttr;
|
||||
sAttr.dataType = 50;
|
||||
sessionId = OpenSession(SESSION_NAME_DATA, SESSION_NAME_DATA, GetNetworkId(), DEF_GROUP_ID, &sAttr);
|
||||
EXPECT_TRUE(sessionId < SESSION_ID_MIN) << "call opensession success[arrt invalid]";
|
||||
|
||||
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSessionServer fail";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_Session_Reli_1000
|
||||
* @tc.name : CloseSession_重复close
|
||||
* @tc.desc : 测试会话管理可靠性
|
||||
* @tc.type : RELI
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Session_Reli_1000, TestSize.Level3)
|
||||
{
|
||||
int ret;
|
||||
int sessionId;
|
||||
char* softbusPidStart;
|
||||
char* softbusPidEnd;
|
||||
softbusPidStart = GetSoftbusPid();
|
||||
EXPECT_TRUE(softbusPidStart != NULL);
|
||||
|
||||
ret = CreateSsAndOpenSession4Data();
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSsAndOpenSession4Data fail";
|
||||
sessionId = GetCurrentSessionId4Data();
|
||||
|
||||
ResetWaitFlag4Data();
|
||||
CloseSession(sessionId);
|
||||
ret = Wait4Session(3, SESSION_4DATA);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "CloseSession(first) hit callback, expect not";
|
||||
|
||||
// repeat,expect fail
|
||||
ResetWaitFlag4Data();
|
||||
CloseSession(sessionId);
|
||||
ret = Wait4Session(3, SESSION_4DATA);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "CloseSession(repeat) hit callback, expect not";
|
||||
|
||||
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSessionServer fail";
|
||||
|
||||
softbusPidEnd = GetSoftbusPid();
|
||||
EXPECT_TRUE(softbusPidEnd != NULL);
|
||||
EXPECT_STREQ(softbusPidStart, softbusPidEnd);
|
||||
free(softbusPidStart);
|
||||
free(softbusPidEnd);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_Session_Reli_1100
|
||||
* @tc.name : CloseSession_无效sessionId
|
||||
* @tc.desc : 测试会话管理可靠性
|
||||
* @tc.type : RELI
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Session_Reli_1100, TestSize.Level3)
|
||||
{
|
||||
int ret;
|
||||
int timeout = 3;
|
||||
int sessionId = MAX_SESSION_NUM + 1;
|
||||
ResetWaitFlag4Data();
|
||||
CloseSession(sessionId);
|
||||
ret = Wait4Session(timeout, SESSION_4DATA);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "CloseSession[sid > max] success";
|
||||
|
||||
sessionId = -1;
|
||||
ResetWaitFlag4Data();
|
||||
CloseSession(sessionId);
|
||||
ret = Wait4Session(timeout, SESSION_4DATA);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "CloseSession[sid < 0] success";
|
||||
|
||||
sessionId = 10;
|
||||
ResetWaitFlag4Data();
|
||||
CloseSession(sessionId);
|
||||
ret = Wait4Session(timeout, SESSION_4DATA);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "CloseSession[sid not open] success";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_Session_Reli_1200
|
||||
* @tc.name : GetMySessionName参数_异常输入
|
||||
* @tc.desc : 测试会话管理可靠性
|
||||
* @tc.type : RELI
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Session_Reli_1200, 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(-1, mySname, SESSION_NAME_SIZE_MAX);
|
||||
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "GetMySessionName invalid sid[-1]";
|
||||
ret = GetMySessionName(MAX_SESSION_NUM + 1, mySname, SESSION_NAME_SIZE_MAX);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "GetMySessionName invalid sid[max+1]";
|
||||
ret = GetMySessionName(sessionId + 1, mySname, SESSION_NAME_SIZE_MAX);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "GetMySessionName invalid sid[not open]";
|
||||
ret = GetMySessionName(sessionId, NULL, SESSION_NAME_SIZE_MAX);
|
||||
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "GetMySessionName invalid sname[null]";
|
||||
ret = GetMySessionName(sessionId, mySname, SESSION_NAME_SIZE_MAX + 1);
|
||||
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "GetMySessionName invalid len[max+1]";
|
||||
|
||||
char mySnameShort[5];
|
||||
ret = GetMySessionName(sessionId, mySnameShort, 5);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "GetMySessionName len short than real";
|
||||
|
||||
ret = CloseSessionAndRemoveSs4Data();
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionAndRemoveSs4Data fail";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_Session_Reli_1300
|
||||
* @tc.name : GetPeersessionName参数_异常输入
|
||||
* @tc.desc : 测试会话管理可靠性
|
||||
* @tc.type : RELI
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Session_Reli_1300, 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(-1, peerSname, SESSION_NAME_SIZE_MAX);
|
||||
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "GetPeerSessionName invalid sid[-1]";
|
||||
ret = GetPeerSessionName(MAX_SESSION_NUM + 1, peerSname, SESSION_NAME_SIZE_MAX);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "GetPeerSessionName invalid sid[max+1]";
|
||||
ret = GetPeerSessionName(sessionId + 1, peerSname, SESSION_NAME_SIZE_MAX);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "GetPeerSessionName invalid sid[not open]";
|
||||
ret = GetPeerSessionName(sessionId, NULL, SESSION_NAME_SIZE_MAX);
|
||||
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "GetPeerSessionName invalid sname[null]";
|
||||
ret = GetPeerSessionName(sessionId, peerSname, SESSION_NAME_SIZE_MAX + 1);
|
||||
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "GetPeerSessionName invalid len[max+1]";
|
||||
|
||||
char peerSnameShort[5];
|
||||
ret = GetPeerSessionName(sessionId, peerSnameShort, 5);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "GetPeerSessionName len short than real";
|
||||
|
||||
ret = CloseSessionAndRemoveSs4Data();
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionAndRemoveSs4Data fail";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_Session_Reli_1400
|
||||
* @tc.name : GetPeerDeviceId参数_异常输入
|
||||
* @tc.desc : 测试会话管理可靠性
|
||||
* @tc.type : RELI
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Session_Reli_1400, 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(-1, deviceId, SESSION_NAME_SIZE_MAX);
|
||||
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "GetPeerDeviceId invalid sid[-1]";
|
||||
ret = GetPeerDeviceId(MAX_SESSION_NUM + 1, deviceId, SESSION_NAME_SIZE_MAX);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "GetPeerDeviceId invalid sid[max+1]";
|
||||
ret = GetPeerDeviceId(sessionId + 1, deviceId, SESSION_NAME_SIZE_MAX);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "GetPeerDeviceId invalid sid[not open]";
|
||||
ret = GetPeerDeviceId(sessionId, NULL, SESSION_NAME_SIZE_MAX);
|
||||
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "GetPeerDeviceId invalid sname[null]";
|
||||
ret = GetPeerDeviceId(sessionId, deviceId, SESSION_NAME_SIZE_MAX + 1);
|
||||
EXPECT_EQ(EXPECT_INVALID_PARAM, ret) << "GetPeerDeviceId invalid len[max+1]";
|
||||
|
||||
char deviceIdShort[5];
|
||||
ret = GetPeerDeviceId(sessionId, deviceIdShort, 5);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "GetPeerDeviceId len short than real";
|
||||
|
||||
ret = CloseSessionAndRemoveSs4Data();
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionAndRemoveSs4Data fail";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_Session_Reli_1500
|
||||
* @tc.name : 主动OpenSession, 对端不存在SessionServer
|
||||
* @tc.desc : 测试会话管理可靠性
|
||||
* @tc.type : RELI
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransReliabilityTest, SUB_Softbus_Trans_Session_Reli_1500, TestSize.Level3)
|
||||
{
|
||||
int ret;
|
||||
char* softbusPidStart;
|
||||
char* softbusPidEnd;
|
||||
softbusPidStart = GetSoftbusPid();
|
||||
EXPECT_TRUE(softbusPidStart != NULL);
|
||||
|
||||
int sessionId;
|
||||
string notExistSession = "Not Exist Session Name";
|
||||
ret = CreateSessionServer(DEF_PKG_NAME, notExistSession.c_str(), GetSessionListenser4Ctl());
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "CreateSS-ctrl fail";
|
||||
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA, GetSessionListenser4Data());
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS-data fail";
|
||||
|
||||
ResetWaitFlag4Data();
|
||||
sessionId =
|
||||
OpenSession(SESSION_NAME_DATA, notExistSession.c_str(), GetNetworkId(), DEF_GROUP_ID, GetSessionAttr4Data());
|
||||
EXPECT_TRUE(sessionId < SESSION_ID_MIN) << "call open session fail, expect success";
|
||||
ret = Wait4Session(OPEN_SESSION_TIMEOUT, SESSION_4DATA);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "wait session cb success, expect fail";
|
||||
|
||||
int timeout = 5;
|
||||
ResetWaitFlag4Data();
|
||||
sessionId = OpenSession(SESSION_NAME_DATA, SESSION_NAME_DATA, GetNetworkId(), DEF_GROUP_ID, GetSessionAttr4Data());
|
||||
SetCurrentSessionId4Data(sessionId);
|
||||
EXPECT_TRUE(sessionId >= SESSION_ID_MIN) << "OpenSession normal[data] fail, expect success";
|
||||
ret = Wait4Session(timeout, SESSION_4DATA);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "wait session cb fail, expect success";
|
||||
|
||||
// clean
|
||||
CloseSession(sessionId);
|
||||
ret = RemoveSessionServer(DEF_PKG_NAME, notExistSession.c_str());
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "RemoveSS-notExist fail";
|
||||
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS-data fail";
|
||||
sleep(timeout);
|
||||
|
||||
softbusPidEnd = GetSoftbusPid();
|
||||
EXPECT_TRUE(softbusPidEnd != NULL);
|
||||
EXPECT_STREQ(softbusPidStart, softbusPidEnd);
|
||||
free(softbusPidStart);
|
||||
free(softbusPidEnd);
|
||||
}
|
@ -44,7 +44,6 @@ void TransFuncTest::SetUpTestCase()
|
||||
|
||||
int ret = RegisterDeviceStateDefCallback();
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "call reg node state callback fail";
|
||||
|
||||
ret = CheckRemoteDeviceIsNull(BOOL_TRUE);
|
||||
ASSERT_EQ(SOFTBUS_OK, ret) << "get node fail,please check network";
|
||||
|
||||
@ -81,6 +80,71 @@ HWTEST_F(TransFuncTest, SUB_Softbus_Trans_SendByte_Func_0100, TestSize.Level3)
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "close session and remove Ss fail";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_SendByte_Func_0200
|
||||
* @tc.name : SendByte Packet size 2K, send and receive successful
|
||||
* @tc.desc : Test the SendByte specification
|
||||
* @tc.type : FUNC
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransFuncTest, SUB_Softbus_Trans_SendByte_Func_0200, TestSize.Level1)
|
||||
{
|
||||
int ret;
|
||||
ret = CreateSsAndOpenSession4Data();
|
||||
ASSERT_EQ(SOFTBUS_OK, ret) << "create Ss and openS[data] fail";
|
||||
|
||||
int size = 2 * 1024 * 1024;
|
||||
ret = SendData4Data(DATA_TYPE_BYTE, size);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "SendData4Data(byte,2M) fail";
|
||||
|
||||
ret = CloseSessionAndRemoveSs4Data();
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "close session and remove Ss fail";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_SendByte_Func_0300
|
||||
* @tc.name : SendByte Packet size Max, send and receive successful
|
||||
* @tc.desc : Test the SendByte specification
|
||||
* @tc.type : FUNC
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransFuncTest, SUB_Softbus_Trans_SendByte_Func_0300, TestSize.Level2)
|
||||
{
|
||||
int ret;
|
||||
ret = CreateSsAndOpenSession4Data();
|
||||
ASSERT_EQ(SOFTBUS_OK, ret) << "create Ss and openS[data] fail";
|
||||
|
||||
int size = TRANS_BYTES_LENGTH_MAX;
|
||||
ret = SendData4Data(DATA_TYPE_BYTE, size);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "SendData4Data(byte,Max) fail";
|
||||
|
||||
ret = CloseSessionAndRemoveSs4Data();
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "close session and remove Ss fail";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_SendByte_Func_0400
|
||||
* @tc.name : SendByte Packet size 0, send and receive successful
|
||||
* @tc.desc : Test the SendByte specification
|
||||
* @tc.type : FUNC
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransFuncTest, SUB_Softbus_Trans_SendByte_Func_0400, TestSize.Level3)
|
||||
{
|
||||
int ret;
|
||||
ret = CreateSsAndOpenSession4Data();
|
||||
ASSERT_EQ(SOFTBUS_OK, ret) << "create Ss and openS[data] fail";
|
||||
|
||||
int size = 0;
|
||||
string emptyStr = "";
|
||||
int sessionId = GetCurrentSessionId4Data();
|
||||
ret = SendBytes(sessionId, emptyStr.c_str(), size);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "call sendbytes(empty) fail";
|
||||
|
||||
ret = CloseSessionAndRemoveSs4Data();
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "close session and remove Ss fail";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_SendMessage_Func_0100
|
||||
* @tc.name : SendMessage Packet size 1B, send and receive successful
|
||||
@ -101,3 +165,94 @@ HWTEST_F(TransFuncTest, SUB_Softbus_Trans_SendMessage_Func_0100, TestSize.Level3
|
||||
ret = CloseSessionAndRemoveSs4Data();
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "close session and remove Ss fail";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_SendMessage_Func_0200
|
||||
* @tc.name : SendMessage Packet size 1K, send and receive successful
|
||||
* @tc.desc : Test the SendMessage specification
|
||||
* @tc.type : FUNC
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransFuncTest, SUB_Softbus_Trans_SendMessage_Func_0200, TestSize.Level1)
|
||||
{
|
||||
int ret;
|
||||
ret = CreateSsAndOpenSession4Data();
|
||||
ASSERT_EQ(SOFTBUS_OK, ret) << "create Ss and openS[data] fail";
|
||||
|
||||
int size = 1000;
|
||||
ret = SendData4Data(DATA_TYPE_MSG, size);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "SendData4Data(msg,1K) fail";
|
||||
|
||||
ret = CloseSessionAndRemoveSs4Data();
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "close session and remove Ss fail";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_SendMessage_Func_0300
|
||||
* @tc.name : SendMessage Packet size Max, send and receive successful
|
||||
* @tc.desc : Test the SendMessage specification
|
||||
* @tc.type : FUNC
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransFuncTest, SUB_Softbus_Trans_SendMessage_Func_0300, TestSize.Level2)
|
||||
{
|
||||
int ret;
|
||||
ret = CreateSsAndOpenSession4Data();
|
||||
ASSERT_EQ(SOFTBUS_OK, ret) << "create Ss and openS[data] fail";
|
||||
|
||||
int size = TRANS_MESSAGE_LENGTH_MAX;
|
||||
ret = SendData4Data(DATA_TYPE_MSG, size);
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "SendData4Data(msg,Max) fail";
|
||||
|
||||
ret = CloseSessionAndRemoveSs4Data();
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "close session and remove Ss fail";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_SendMessage_Func_0400
|
||||
* @tc.name : SendMessage Packet size 0, send and receive successful
|
||||
* @tc.desc : Test the SendMessage specification
|
||||
* @tc.type : FUNC
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransFuncTest, SUB_Softbus_Trans_SendMessage_Func_0400, TestSize.Level3)
|
||||
{
|
||||
int ret;
|
||||
ret = CreateSsAndOpenSession4Data();
|
||||
ASSERT_EQ(SOFTBUS_OK, ret) << "create Ss and openS[data] fail";
|
||||
|
||||
int size = 0;
|
||||
string emptyStr = "";
|
||||
int sessionId = GetCurrentSessionId4Data();
|
||||
ret = SendMessage(sessionId, emptyStr.c_str(), size);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "call sendmsg(empty) fail";
|
||||
|
||||
ret = CloseSessionAndRemoveSs4Data();
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "close session and remove Ss fail";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number : SUB_Softbus_Trans_SendMessage_Func_0500
|
||||
* @tc.name : SendMessage Packet size Max+1, send and receive successful
|
||||
* @tc.desc : Test the SendMessage specification
|
||||
* @tc.type : FUNC
|
||||
* @tc.size : MediumTest
|
||||
*/
|
||||
HWTEST_F(TransFuncTest, SUB_Softbus_Trans_SendMessage_Func_0500, TestSize.Level3)
|
||||
{
|
||||
int ret;
|
||||
ret = CreateSsAndOpenSession4Data();
|
||||
ASSERT_EQ(SOFTBUS_OK, ret) << "create Ss and openS[data] fail";
|
||||
|
||||
int size = TRANS_MESSAGE_LENGTH_MAX + 1;
|
||||
char* dataMoreMax = (char*)malloc(size);
|
||||
ASSERT_TRUE(dataMoreMax != NULL) << "malloc fail";
|
||||
|
||||
int sessionId = GetCurrentSessionId4Data();
|
||||
ret = SendMessage(sessionId, &dataMoreMax, size);
|
||||
EXPECT_NE(SOFTBUS_OK, ret) << "call sendmsg(Max+1) fail";
|
||||
|
||||
ret = CloseSessionAndRemoveSs4Data();
|
||||
EXPECT_EQ(SOFTBUS_OK, ret) << "close session and remove Ss fail";
|
||||
free(dataMoreMax);
|
||||
}
|
@ -123,7 +123,7 @@ HWTEST_F(TransSessionFuncTest, SUB_Softbus_Trans_Session_Func_0200, TestSize.Lev
|
||||
// open max+1, expect fail
|
||||
int sessionId;
|
||||
sessionId = OpenSession(SESSION_NAME_DATA, SESSION_NAME_DATA, GetNetworkId(), DEF_GROUP_ID, GetSessionAttr4Data());
|
||||
EXPECT_FALSE(sessionId >= SESSION_ID_MIN) << "call OpenSession[data] fail,sid=" << sessionId;
|
||||
EXPECT_FALSE(sessionId >= SESSION_ID_MIN) << "call OpenSession[data] success,sid=" << sessionId;
|
||||
|
||||
// close session
|
||||
ret = CloseSessionBatch4Data(sessionId4Data, count);
|
||||
|
Loading…
Reference in New Issue
Block a user