提交 ca7d3637 编写于 作者: M mlinlmcc 提交者: Gitee

setup期间检查AP、STA、config,如果状态是enable,则disable,避免状态混乱影响测试用例执行

上级 9f76ebf1
......@@ -32,12 +32,9 @@
#define LEVEL_FOUR 4
#define DEF_TASK_STACK 2000
#define DEF_TASK_PRIORITY 20
#define DEPE_AP_SSID "xts_execute"
#define DEF_NET_IF "wlan0"
static int g_apEnableSuccess = 0;
static int g_staScanSuccess = 0;
struct netif *g_wsNetInterface = NULL;
WifiEvent g_wifiEventHandler = {0};
/**
......@@ -216,14 +213,61 @@ LITE_TEST_SUIT(communication, wifiservice, WifiServiceFuncTestSuite);
*/
static BOOL WifiServiceFuncTestSuiteSetUp(void)
{
WifiErrorCode error;
// check wifi stat
int ret = IsWifiActive();
if (ret == WIFI_STATE_AVALIABLE) {
printf("[Setup]wifi is active, disbale now...\n");
error = DisableWifi();
if (error == WIFI_SUCCESS) {
printf("[Setup]disbale wifi success\n");
} else {
TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS);
printf("[Setup]disbale wifi fail, please disable wifi, then run test cases!\n");
return FALSE;
}
}
// check AP stat
ret = IsHotspotActive();
if (ret == WIFI_HOTSPOT_ACTIVE) {
printf("[Setup]AP is active, disbale now...\n");
error = DisableHotspot();
if (error == WIFI_SUCCESS) {
printf("[Setup]disbale AP success\n");
} else {
TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS);
printf("[Setup]disbale AP fail, please disable ap, then run test cases!\n");
return FALSE;
}
}
// check device config
WifiDeviceConfig config[WIFI_MAX_CONFIG_SIZE] = {0};
unsigned int size = WIFI_MAX_CONFIG_SIZE;
error = GetDeviceConfigs(config, &size);
if (error != ERROR_WIFI_NOT_AVAILABLE) {
printf("[Setup]there is device config, clear now...\n");
int count = 0;
for (int i = 0; i < WIFI_MAX_CONFIG_SIZE; i++) {
if (&config[i] != NULL) {
RemoveDevice(config[i].netId);
count++;
}
}
printf("[Setup]clear count [%d]\n", count);
}
// register wifi event
g_wifiEventHandler.OnWifiScanStateChanged = OnWifiScanStateChangedHandler;
g_wifiEventHandler.OnWifiConnectionChanged = OnWifiConnectionChangedHandler;
g_wifiEventHandler.OnHotspotStaJoin = OnHotspotStaJoinHandler;
g_wifiEventHandler.OnHotspotStaLeave = OnHotspotStaLeaveHandler;
g_wifiEventHandler.OnHotspotStateChanged = OnHotspotStateChangedHandler;
WifiErrorCode error = RegisterWifiEvent(&g_wifiEventHandler);
TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS);
error = RegisterWifiEvent(&g_wifiEventHandler);
TEST_ASSERT_EQUAL_INT(WIFI_SUCCESS, ret);
if (error != WIFI_SUCCESS) {
printf("[Setup]register wifi event fail!\n");
return FALSE;
}
return TRUE;
......@@ -248,11 +292,8 @@ static BOOL WifiServiceFuncTestSuiteTearDown(void)
* @tc.number : SUB_COMMUNICATION_WIFISERVICE_SDK_0100
* @tc.name : Test enable and disable wifi interface
* @tc.desc : [C- SOFTWARE -0200]
* @tc.size : MEDIUM
* @tc.type : FUNC
* @tc.level : Level 2
*/
LITE_TEST_CASE(WifiServiceFuncTestSuite, testEnableDisableWifi, LEVEL2)
LITE_TEST_CASE(WifiServiceFuncTestSuite, testEnableDisableWifi, Function | MediumTest | Level2)
{
int stat = IsWifiActive();
TEST_ASSERT_EQUAL_INT(stat, WIFI_STATE_NOT_AVALIABLE);
......@@ -282,11 +323,8 @@ LITE_TEST_CASE(WifiServiceFuncTestSuite, testEnableDisableWifi, LEVEL2)
* @tc.number : SUB_COMMUNICATION_WIFISERVICE_SDK_0200
* @tc.name : Test scan and get scan info interface
* @tc.desc : [C- SOFTWARE -0200]
* @tc.size : MEDIUM
* @tc.type : FUNC
* @tc.level : Level 2
*/
LITE_TEST_CASE(WifiServiceFuncTestSuite, testScan, LEVEL2)
LITE_TEST_CASE(WifiServiceFuncTestSuite, testScan, Function | MediumTest | Level2)
{
unsigned int size = WIFI_SCAN_HOTSPOT_LIMIT;
WifiErrorCode error = EnableWifi();
......@@ -322,20 +360,17 @@ LITE_TEST_CASE(WifiServiceFuncTestSuite, testScan, LEVEL2)
* @tc.number : SUB_COMMUNICATION_WIFISERVICE_SDK_0300
* @tc.name : Test connect and disconnect interface
* @tc.desc : [C- SOFTWARE -0200]
* @tc.size : MEDIUM
* @tc.type : FUNC
* @tc.level : Level 2
*/
LITE_TEST_CASE(WifiServiceFuncTestSuite, testConnectDisConnect, LEVEL2)
LITE_TEST_CASE(WifiServiceFuncTestSuite, testConnectDisConnect, Function | MediumTest | Level2)
{
int netId = 0;
int ssidLen = 11;
WifiErrorCode error;
WifiDeviceConfig config = {0};
int ret = memcpy_s(config.ssid, WIFI_MAX_SSID_LEN, "xts_execute", ssidLen);
const char* ssid = "xts_execute";
int ret = strncpy_s(config.ssid, WIFI_MAX_SSID_LEN, ssid, strlen(ssid));
TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS);
config.securityType = WIFI_SEC_TYPE_OPEN;
error = AddDeviceConfig(&config, &netId);
WifiErrorCode error = AddDeviceConfig(&config, &netId);
TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS);
error = ConnectTo(netId);
......@@ -353,38 +388,34 @@ LITE_TEST_CASE(WifiServiceFuncTestSuite, testConnectDisConnect, LEVEL2)
* @tc.number : SUB_COMMUNICATION_WIFISERVICE_SDK_0400
* @tc.name : Test handle device config interface
* @tc.desc : [C- SOFTWARE -0200]
* @tc.size : MEDIUM
* @tc.type : FUNC
* @tc.level : Level 2
*/
LITE_TEST_CASE(WifiServiceFuncTestSuite, testHandleDeviceConfig, LEVEL2)
LITE_TEST_CASE(WifiServiceFuncTestSuite, testHandleDeviceConfig, Function | MediumTest | Level2)
{
int netId = 0;
int ssidLen = 11;
int keyLen = 8;
int freq = 20;
const char* ssid1 = "XtsTestWifi1";
const char* ssid2 = "XtsTestWifi2";
const char* ssid3 = "XtsTestWifi3";
const char* info = "12345678";
unsigned char bssid[WIFI_MAC_LEN] = {0xac, 0x75, 0x1d, 0xd8, 0x55, 0xc1};
WifiDeviceConfig config = {0};
config.freq = freq;
config.freq = 20;
config.securityType = WIFI_SEC_TYPE_SAE;
config.wapiPskType = WIFI_PSK_TYPE_ASCII;
int ret = memcpy_s(config.ssid, WIFI_MAX_SSID_LEN, "XtsTestWifi", ssidLen);
int ret = strncpy_s(config.ssid, WIFI_MAX_SSID_LEN, ssid1, strlen(ssid1));
TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS);
ret = memcpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, "12345678", keyLen);
ret = strncpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, info, strlen(info));
TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS);
ret = memcpy_s(config.bssid, WIFI_MAC_LEN, bssid, WIFI_MAC_LEN);
TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS);
WifiErrorCode error = AddDeviceConfig(&config, &netId);
TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS);
ssidLen += 1;
int addCount = 9;
for (int i = 0; i < addCount; i++) {
for (int i = 0; i < WIFI_MAX_CONFIG_SIZE - 1; i++) {
config.securityType = WIFI_SEC_TYPE_PSK;
config.wapiPskType = WIFI_PSK_TYPE_HEX;
ret = memcpy_s(config.ssid, WIFI_MAX_SSID_LEN, "XtsTestWifi2", ssidLen);
ret = strncpy_s(config.ssid, WIFI_MAX_SSID_LEN, ssid2, sizeof(ssid2));
TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS);
ret = memcpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, "01234567", keyLen);
ret = strncpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, info, strlen(info));
TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS);
error = AddDeviceConfig(&config, &netId);
TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS);
......@@ -394,9 +425,9 @@ LITE_TEST_CASE(WifiServiceFuncTestSuite, testHandleDeviceConfig, LEVEL2)
}
}
ret = memcpy_s(config.ssid, WIFI_MAX_SSID_LEN, "XtsTestWifi3", ssidLen);
ret = strncpy_s(config.ssid, WIFI_MAX_SSID_LEN, ssid3, strlen(ssid3));
TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS);
ret = memcpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, "01234567", keyLen);
ret = strncpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, info, strlen(info));
TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS);
config.securityType = WIFI_SEC_TYPE_PSK;
error = AddDeviceConfig(&config, &netId);
......@@ -421,18 +452,15 @@ LITE_TEST_CASE(WifiServiceFuncTestSuite, testHandleDeviceConfig, LEVEL2)
* @tc.number : SUB_COMMUNICATION_WIFISERVICE_SDK_0500
* @tc.name : Test handle AP config interface
* @tc.desc : [C- SOFTWARE -0200]
* @tc.size : MEDIUM
* @tc.type : FUNC
* @tc.level : Level 2
*/
LITE_TEST_CASE(WifiServiceFuncTestSuite, testHandleHotspotConfig, LEVEL2)
LITE_TEST_CASE(WifiServiceFuncTestSuite, testHandleHotspotConfig, Function | MediumTest | Level2)
{
int keyLen = 9;
int ssidLen = 10;
const char* ssid = "XtsTestAp";
const char* info = "12345678";
HotspotConfig config = {0};
int ret = memcpy_s(config.ssid, WIFI_MAX_SSID_LEN, "XtsTestAp", ssidLen);
int ret = strncpy_s(config.ssid, WIFI_MAX_SSID_LEN, ssid, strlen(ssid));
TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS);
ret = memcpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, "12345678", keyLen);
ret = strncpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, info, strlen(info));
TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS);
config.securityType = WIFI_SEC_TYPE_PSK;
WifiErrorCode error = SetHotspotConfig(&config);
......@@ -467,18 +495,15 @@ LITE_TEST_CASE(WifiServiceFuncTestSuite, testHandleHotspotConfig, LEVEL2)
* @tc.number : SUB_COMMUNICATION_WIFISERVICE_SDK_0600
* @tc.name : Test enable and disable AP interface
* @tc.desc : [C- SOFTWARE -0200]
* @tc.size : MEDIUM
* @tc.type : FUNC
* @tc.level : Level 2
*/
LITE_TEST_CASE(WifiServiceFuncTestSuite, testEnableDisableHotSpot, LEVEL2)
LITE_TEST_CASE(WifiServiceFuncTestSuite, testEnableDisableHotSpot, Function | MediumTest | Level2)
{
int ssidLen = 10;
int keyLen = 9;
const char* ssid = "XtsTestAp";
const char* info = "12345678";
HotspotConfig config = {0};
int ret = memcpy_s(config.ssid, WIFI_MAX_SSID_LEN, "XtsTestAp", ssidLen);
int ret = strncpy_s(config.ssid, WIFI_MAX_SSID_LEN, ssid, strlen(ssid));
TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS);
ret = memcpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, "12345678", keyLen);
ret = strncpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, info, strlen(info));
TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS);
config.securityType = WIFI_SEC_TYPE_PSK;
WifiErrorCode error = SetHotspotConfig(&config);
......@@ -520,11 +545,8 @@ LITE_TEST_CASE(WifiServiceFuncTestSuite, testEnableDisableHotSpot, LEVEL2)
* @tc.number : SUB_COMMUNICATION_WIFISERVICE_SDK_0700
* @tc.name : Test get signal Level interface
* @tc.desc : [C- SOFTWARE -0200]
* @tc.size : MEDIUM
* @tc.type : FUNC
* @tc.level : Level 2
*/
LITE_TEST_CASE(WifiServiceFuncTestSuite, testGetSignalLevel, LEVEL2)
LITE_TEST_CASE(WifiServiceFuncTestSuite, testGetSignalLevel, Function | MediumTest | Level2)
{
int level;
int rssiNoLevel = -90;
......@@ -563,11 +585,8 @@ LITE_TEST_CASE(WifiServiceFuncTestSuite, testGetSignalLevel, LEVEL2)
* @tc.number : SUB_COMMUNICATION_WIFISERVICE_SDK_0800
* @tc.name : test adavance scan interface
* @tc.desc : [C- SOFTWARE -0200]
* @tc.size : MEDIUM
* @tc.type : FUNC
* @tc.level : Level 2
*/
LITE_TEST_CASE(WifiServiceFuncTestSuite, testAdvanceScanType, LEVEL2)
LITE_TEST_CASE(WifiServiceFuncTestSuite, testAdvanceScanType, Function | MediumTest | Level2)
{
WifiErrorCode error = EnableWifi();
TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS);
......@@ -620,11 +639,8 @@ LITE_TEST_CASE(WifiServiceFuncTestSuite, testAdvanceScanType, LEVEL2)
* @tc.number : SUB_COMMUNICATION_WIFISERVICE_SDK_0900
* @tc.name : test adavance scan interface with invalid parameter
* @tc.desc : [C- SOFTWARE -0200]
* @tc.size : MEDIUM
* @tc.type : FUNC
* @tc.level : Level 2
*/
LITE_TEST_CASE(WifiServiceFuncTestSuite, testAdvanceScanInvalidParam01, LEVEL2)
LITE_TEST_CASE(WifiServiceFuncTestSuite, testAdvanceScanInvalidParam01, Function | MediumTest | Level2)
{
WifiErrorCode error = EnableWifi();
TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS);
......@@ -649,13 +665,10 @@ LITE_TEST_CASE(WifiServiceFuncTestSuite, testAdvanceScanInvalidParam01, LEVEL2)
/**
* @tc.number : SUB_COMMUNICATION_WIFISERVICE_SDK_1000
* @tc.name : test adavance scan interface with invalid parameter
* @tc.name : test adavance scan interface with different invalid scantype
* @tc.desc : [C- SOFTWARE -0200]
* @tc.size : MEDIUM
* @tc.type : FUNC
* @tc.level : Level 2
*/
LITE_TEST_CASE(WifiServiceFuncTestSuite, testAdvanceScanInvalidParam02, LEVEL2)
LITE_TEST_CASE(WifiServiceFuncTestSuite, testAdvanceScanInvalidParam02, Function | MediumTest | Level2)
{
WifiErrorCode error = EnableWifi();
TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册