提交 6e370538 编写于 作者: L liuhonggang123

HDF test case

Signed-off-by: Nliuhonggang123 <honggang.liu@huawei.com>
Change-Id: Ibdf23a49ebf85b0d9e3b13df106b078f4a292c02
上级 971b4768
# 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("//build/ohos_var.gni")
group("hdfacttest") {
testonly = true
if (is_standard_system) {
deps = [
"input:hdf_xtstest_input",
"sensor:hdf_xtstest_sensor",
"wlan/wifi:hdf_xtstest_wifi",
]
}
}
# 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("//build/ohos_var.gni")
import("//drivers/adapter/uhdf2/uhdf.gni")
import("//test/xts/tools/build/suite.gni")
module_output_path = "hdf/input"
ohos_moduletest_suite("hdf_xtstest_input") {
module_out_path = module_output_path
include_dirs = [
"//drivers/framework/test/unittest/include",
"//drivers/peripheral/input/hal/include",
"//drivers/peripheral/input/interfaces/include",
]
sources = [ "./common/hdi_input_test.cpp" ]
cflags = [
"-Wall",
"-Wextra",
"-Werror",
"-fsigned-char",
"-fno-common",
"-fno-strict-aliasing",
]
deps = [
"$hdf_uhdf_path/test/unittest/common:libhdf_test_common",
"$hdf_uhdf_path/utils:libhdf_utils",
"//drivers/peripheral/input/hal:hdi_input",
"//utils/native/base:utils",
]
if (is_standard_system) {
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
} else {
external_deps = [ "hilog:libhilog" ]
}
}
{
"kits": [
{
"push": [
"hdf_xtstest_input->/data/local/tmp/hdf_xtstest_input"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "hdf_xtstest_input",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for hdf_xtstest_input Tests"
}
\ No newline at end of file
此差异已折叠。
# 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("//build/ohos_var.gni")
import("//drivers/adapter/uhdf2/uhdf.gni")
import("//test/xts/tools/build/suite.gni")
module_output_path = "hdf/sensor"
ohos_moduletest_suite("hdf_xtstest_sensor") {
module_out_path = module_output_path
include_dirs = []
sources = [ "./common/hdf_sensor_test.cpp" ]
cflags = [
"-Wall",
"-Wextra",
"-Werror",
"-fsigned-char",
"-fno-common",
"-fno-strict-aliasing",
]
deps = [
"$hdf_uhdf_path/utils:libhdf_utils",
"//drivers/peripheral/sensor/hal:hdi_sensor",
"//utils/native/base:utils",
]
if (is_standard_system) {
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
} else {
external_deps = [ "hilog:libhilog" ]
}
}
{
"kits": [
{
"push": [
"hdf_xtstest_sensor->/data/local/tmp/hdf_xtstest_sensor"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "hdf_xtstest_sensor",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for hdf_xtstest_sensor Tests"
}
\ No newline at end of file
/*
* 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 <cmath>
#include <cstdio>
#include <unistd.h>
#include <gtest/gtest.h>
#include <securec.h>
#include "hdf_base.h"
#include "hdf_log.h"
#include "osal_time.h"
#include "sensor_if.h"
#include "sensor_type.h"
using namespace testing::ext;
namespace {
struct SensorValueRange {
float highThreshold;
float lowThreshold;
};
struct SensorDevelopmentList {
int32_t sensorTypeId;
char sensorName[SENSOR_NAME_MAX_LEN];
char vendorName[SENSOR_NAME_MAX_LEN];
int32_t dataForm; // 0: fixed, 1: range
int32_t dataDimension;
struct SensorValueRange *valueRange;
};
static struct SensorValueRange g_testRange[] = {{1e5, 0}};
static struct SensorValueRange g_accelRange[] = {{78, -78}, {78, -78}, {78, -78}};
static struct SensorValueRange g_alsRange[] = {{10000, 0}, {10000, 0}, {10000, 0}, {10000, 0}};
static struct SensorValueRange g_proximityRange[] = {{5, 0}};
static struct SensorValueRange g_hallRange[] = {{1, 0}};
static struct SensorValueRange g_barometerRange[] = {{1100, -1100}, {1100, -1100}};
static struct SensorValueRange g_magneticRange[] = {{35, -35}, {35, -35}, {35, -35}};
static struct SensorDevelopmentList g_sensorList[] = {
{SENSOR_TYPE_NONE, "sensor_test", "default", 1, 1, g_testRange},
{SENSOR_TYPE_ACCELEROMETER, "accelerometer", "borsh_bmi160", 1, 3, g_accelRange},
{SENSOR_TYPE_PROXIMITY, "proximitymeter", "stk3338", 0, 1, g_proximityRange},
{SENSOR_TYPE_HALL, "hallrometer", "akm_ak8789", 0, 1, g_hallRange},
{SENSOR_TYPE_BAROMETER, "barometer", "borsh_bmp180", 1, 2, g_barometerRange},
{SENSOR_TYPE_AMBIENT_LIGHT, "als", "rohm_bh1745", 1, 4, g_alsRange},
{SENSOR_TYPE_MAGNETIC_FIELD, "magnetometer", "st_lsm303", 1, 3, g_magneticRange},
};
static int g_listNum = sizeof(g_sensorList) / sizeof(g_sensorList[0]);
static uint32_t g_sensorDataFlag = 1;
const int32_t SENSOR_ID = 0;
const int32_t SENSOR_INTERVAL = 200000000;
const int32_t SENSOR_POLL_TIME = 1;
const int32_t SENSOR_WAIT_TIME = 400;
const struct SensorInterface *g_sensorDev = nullptr;
void SensorDataVerification(const float &data, const struct SensorDevelopmentList &sensorNode)
{
for (int32_t j = 0; j < sensorNode.dataDimension; ++j) {
HDF_LOGE("sensor id :[%d], data[%d]: %f\n\r", sensorNode.sensorTypeId, j + 1, *(&data + j));
if (sensorNode.dataForm == 0) {
if (*(&data + j) == sensorNode.valueRange[j].highThreshold ||
*(&data + j) == sensorNode.valueRange[j].lowThreshold) {
g_sensorDataFlag &= 1;
} else {
g_sensorDataFlag = 0;
HDF_LOGE("%s: %s Not expected\n\r", __func__, sensorNode.sensorName);
}
}
if (sensorNode.dataForm == 1) {
if (*(&data + j) > sensorNode.valueRange[j].lowThreshold &&
*(&data + j) < sensorNode.valueRange[j].highThreshold) {
g_sensorDataFlag &= 1;
HDF_LOGE("g_sensorDataFlag = 1;");
} else {
g_sensorDataFlag = 0;
HDF_LOGE("%s: %s Not expected\n\r", __func__, sensorNode.sensorName);
}
}
}
}
int SensorTestDataCallback(const struct SensorEvents *event)
{
if (event == nullptr || event->data == nullptr) {
return -1;
}
float *data = (float*)event->data;
for (int i = 0; i < g_listNum; ++i) {
if (event->sensorId == g_sensorList[i].sensorTypeId) {
SensorDataVerification(*data, g_sensorList[i]);
}
}
return 0;
}
}
class HdfSensorTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void HdfSensorTest::SetUpTestCase()
{
g_sensorDev = NewSensorInterfaceInstance();
if (g_sensorDev == nullptr) {
HDF_LOGE("test sensorHdi get Module instance failed\n\r");
}
}
void HdfSensorTest::TearDownTestCase()
{
if (g_sensorDev != nullptr) {
FreeSensorInterfaceInstance();
g_sensorDev = nullptr;
}
}
void HdfSensorTest::SetUp()
{
}
void HdfSensorTest::TearDown()
{
}
/**
* @tc.name: GetSensorInstance001
* @tc.desc: Create a sensor instance and check whether the instance is empty.
* @tc.type: FUNC
*/
HWTEST_F(HdfSensorTest, GetSensorInstance001, Function | MediumTest | Level1)
{
ASSERT_NE(nullptr, g_sensorDev);
const struct SensorInterface *sensorDev = NewSensorInterfaceInstance();
EXPECT_EQ(sensorDev, g_sensorDev);
}
/**
* @tc.name: RemoveSensorInstance001
* @tc.desc: The sensor instance is successfully removed.
* @tc.type: FUNC
*/
HWTEST_F(HdfSensorTest, RemoveSensorInstance001, Function | MediumTest | Level1)
{
int32_t ret = FreeSensorInterfaceInstance();
ASSERT_EQ(0, ret);
ret = FreeSensorInterfaceInstance();
EXPECT_EQ(0, ret);
g_sensorDev = NewSensorInterfaceInstance();
if (g_sensorDev == nullptr) {
HDF_LOGE("test sensorHdi get Module instance failed\n\r");
ASSERT_EQ(0, ret);
}
}
/**
* @tc.name: RegisterDataCb001
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
* @tc.type: FUNC
*/
HWTEST_F(HdfSensorTest, RegisterSensorDataCb001, Function | MediumTest | Level1)
{
int32_t ret = g_sensorDev->Register(SensorTestDataCallback);
EXPECT_EQ(0, ret);
ret = g_sensorDev->Unregister();
EXPECT_EQ(0, ret);
}
/**
* @tc.name: RegisterDataCb002
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
* @tc.type: FUNC
*/
HWTEST_F(HdfSensorTest, RegisterSensorDataCb002, Function | MediumTest | Level1)
{
int32_t ret = g_sensorDev->Register(nullptr);
EXPECT_EQ(SENSOR_NULL_PTR, ret);
ret = g_sensorDev->Unregister();
EXPECT_EQ(0, ret);
}
/**
* @tc.name: GetSensorList001
* @tc.desc: Obtains information about all sensors in the system. Validity check of input parameters.
* @tc.type: FUNC
*/
HWTEST_F(HdfSensorTest, GetSensorList001, Function | MediumTest | Level1)
{
struct SensorInformation *sensorInfo = nullptr;
struct SensorInformation *info = nullptr;
int32_t count = 0;
int j;
int32_t ret = g_sensorDev->GetAllSensors(&sensorInfo, &count);
EXPECT_EQ(0, ret);
if (sensorInfo == nullptr) {
EXPECT_NE(nullptr, sensorInfo);
return;
}
HDF_LOGE("get sensor list num[%d]\n\r", count);
info = sensorInfo;
for (int i = 0; i < count; ++i) {
HDF_LOGE("get sensoriId[%d], info name[%s], power[%f]\n\r", info->sensorId, info->sensorName, info->power);
for (j = 0; j < g_listNum; ++j) {
if (info->sensorId == g_sensorList[j].sensorTypeId) {
EXPECT_STREQ(g_sensorList[j].sensorName, info->sensorName);
EXPECT_STREQ(g_sensorList[j].vendorName, info->vendorName);
break;
}
}
if (j == g_listNum) {
EXPECT_NE(g_listNum, j);
HDF_LOGE("%s: The sensor ID[%d] does not match. Please check the use case or the reported sensor ID",
__func__, info->sensorId);
}
info++;
}
}
/**
* @tc.name: GetSensorList002
* @tc.desc: Obtains information about all sensors in the system. The operations include obtaining sensor information,
* subscribing to or unsubscribing from sensor data, enabling or disabling a sensor,
* setting the sensor data reporting mode, and setting sensor options such as the accuracy and measurement range.
* @tc.type: FUNC
*/
HWTEST_F(HdfSensorTest, GetSensorList002, Function | MediumTest | Level1)
{
struct SensorInformation *sensorInfo = nullptr;
int32_t count = 0;
int32_t ret = g_sensorDev->GetAllSensors(nullptr, &count);
EXPECT_EQ(SENSOR_NULL_PTR, ret);
ret = g_sensorDev->GetAllSensors(&sensorInfo, nullptr);
EXPECT_EQ(SENSOR_NULL_PTR, ret);
ret = g_sensorDev->GetAllSensors(nullptr, nullptr);
EXPECT_EQ(SENSOR_NULL_PTR, ret);
}
/**
* @tc.name: EnableSensor001
* @tc.desc: Enables the sensor unavailable in the sensor list based on the specified sensor ID.
* @tc.type: FUNC
*/
HWTEST_F(HdfSensorTest, EnableSensor001, Function | MediumTest | Level1)
{
int32_t ret = g_sensorDev->Register(SensorTestDataCallback);
EXPECT_EQ(0, ret);
struct SensorInformation *sensorInfo = nullptr;
struct SensorInformation *info = nullptr;
int32_t count = 0;
ret = g_sensorDev->GetAllSensors(&sensorInfo, &count);
EXPECT_EQ(0, ret);
if (sensorInfo == nullptr) {
EXPECT_NE(nullptr, sensorInfo);
return;
}
info = sensorInfo;
for (int i = 0; i < count; i++) {
ret = g_sensorDev->SetBatch(SENSOR_ID, SENSOR_INTERVAL, SENSOR_POLL_TIME);
EXPECT_EQ(0, ret);
ret = g_sensorDev->Enable(info->sensorId);
EXPECT_EQ(0, ret);
OsalSleep(SENSOR_POLL_TIME);
ret = g_sensorDev->Disable(info->sensorId);
EXPECT_EQ(0, ret);
info++;
}
ret = g_sensorDev->Unregister();
EXPECT_EQ(0, ret);
}
/**
* @tc.name: EnableSensor002
* @tc.desc: Enables the sensor available in the sensor list based on the specified sensor ID.
* @tc.type: FUNC
*/
HWTEST_F(HdfSensorTest, EnableSensor002, Function | MediumTest | Level1)
{
struct SensorInformation *sensorInfo = nullptr;
int32_t count = 0;
int32_t ret = g_sensorDev->GetAllSensors(&sensorInfo, &count);
EXPECT_EQ(0, ret);
ret = g_sensorDev->Enable(-1);
EXPECT_EQ(-2, ret);
ret = g_sensorDev->Disable(-1);
EXPECT_EQ(-2, ret);
}
/**
* @tc.name: SetSensorBatch001
* @tc.desc: Sets the sampling time and data report interval for sensors in batches.
* @tc.type: FUNC
*/
HWTEST_F(HdfSensorTest, SetSensorBatch001, Function | MediumTest | Level1)
{
struct SensorInformation *sensorInfo = nullptr;
int32_t count = 0;
int32_t ret = g_sensorDev->Register(SensorTestDataCallback);
EXPECT_EQ(0, ret);
ret = g_sensorDev->GetAllSensors(&sensorInfo, &count);
EXPECT_EQ(0, ret);
ret = g_sensorDev->SetBatch(SENSOR_ID, SENSOR_INTERVAL, SENSOR_POLL_TIME);
EXPECT_EQ(0, ret);
ret = g_sensorDev->Enable(SENSOR_ID);
EXPECT_EQ(0, ret);
OsalMSleep(SENSOR_WAIT_TIME);
ret = g_sensorDev->Disable(SENSOR_ID);
EXPECT_EQ(0, ret);
ret = g_sensorDev->Unregister();
EXPECT_EQ(0, ret);
}
/** @tc.name: SetSensorBatch002
@tc.desc: Sets the sampling time and data report interval for sensors in batches.
@tc.type: FUNC
*/
HWTEST_F(HdfSensorTest, SetSensorBatch002, Function | MediumTest | Level1)
{
struct SensorInformation *sensorInfo = nullptr;
int32_t count = 0;
int32_t ret = g_sensorDev->GetAllSensors(&sensorInfo, &count);
EXPECT_EQ(0, ret);
ret = g_sensorDev->SetBatch(-1, 0, 0);
EXPECT_EQ(-2, ret);
}
/**
* @tc.name: SetSensorMode001
* @tc.desc: Sets the data reporting mode for the specified sensor.
* @tc.type: FUNC
*/
HWTEST_F(HdfSensorTest, SetSensorMode001, Function | MediumTest | Level1)
{
struct SensorInformation *sensorInfo = nullptr;
int32_t count = 0;
int32_t ret = g_sensorDev->Register(SensorTestDataCallback);
EXPECT_EQ(0, ret);
ret = g_sensorDev->GetAllSensors(&sensorInfo, &count);
EXPECT_EQ(0, ret);
ret = g_sensorDev->SetBatch(SENSOR_ID, SENSOR_INTERVAL, SENSOR_POLL_TIME);
EXPECT_EQ(0, ret);
if (SENSOR_ID == SENSOR_TYPE_HALL) {
ret = g_sensorDev->SetMode(SENSOR_ID, SENSOR_MODE_ON_CHANGE);
EXPECT_EQ(0, ret);
} else {
ret = g_sensorDev->SetMode(SENSOR_ID, SENSOR_MODE_REALTIME);
EXPECT_EQ(0, ret);
}
ret = g_sensorDev->Enable(SENSOR_ID);
EXPECT_EQ(0, ret);
OsalMSleep(SENSOR_WAIT_TIME);
ret = g_sensorDev->Disable(SENSOR_ID);
EXPECT_EQ(0, ret);
ret = g_sensorDev->Unregister();
EXPECT_EQ(0, ret);
}
/**
* @tc.name: SetSensorMode002
* @tc.desc: Sets the data reporting mode for the specified sensor.The current real-time polling mode is valid.
* Other values are invalid.
* @tc.type: FUNC
*/
HWTEST_F(HdfSensorTest, SetSensorMode002, Function | MediumTest | Level1)
{
struct SensorInformation *sensorInfo = nullptr;
int32_t count = 0;
int32_t ret = g_sensorDev->Register(SensorTestDataCallback);
EXPECT_EQ(0, ret);
ret = g_sensorDev->GetAllSensors(&sensorInfo, &count);
EXPECT_EQ(0, ret);
ret = g_sensorDev->SetBatch(SENSOR_ID, SENSOR_INTERVAL, SENSOR_POLL_TIME);
EXPECT_EQ(0, ret);
ret = g_sensorDev->SetMode(SENSOR_ID, SENSOR_MODE_DEFAULT);
EXPECT_EQ(-1, ret);
ret = g_sensorDev->Enable(SENSOR_ID);
EXPECT_EQ(0, ret);
OsalMSleep(SENSOR_WAIT_TIME);
ret = g_sensorDev->Disable(SENSOR_ID);
EXPECT_EQ(0, ret);
ret = g_sensorDev->Unregister();
EXPECT_EQ(0, ret);
}
/**
* @tc.name: SetSensorOption001
* @tc.desc: Sets options for the specified sensor, including its measurement range and accuracy.
* @tc.type: FUNC
*/
HWTEST_F(HdfSensorTest, SetSensorOption001, Function | MediumTest | Level1)
{
struct SensorInformation *sensorInfo = nullptr;
int32_t count = 0;
int32_t ret = g_sensorDev->Register(SensorTestDataCallback);
EXPECT_EQ(0, ret);
ret = g_sensorDev->GetAllSensors(&sensorInfo, &count);
EXPECT_EQ(0, ret);
ret = g_sensorDev->SetBatch(SENSOR_ID, SENSOR_INTERVAL, SENSOR_POLL_TIME);
EXPECT_EQ(0, ret);
ret = g_sensorDev->SetOption(SENSOR_ID, 0);
EXPECT_EQ(0, ret);
ret = g_sensorDev->Enable(SENSOR_ID);
EXPECT_EQ(0, ret);
OsalMSleep(SENSOR_WAIT_TIME);
ret = g_sensorDev->Disable(SENSOR_ID);
EXPECT_EQ(0, ret);
ret = g_sensorDev->Unregister();
EXPECT_EQ(0, ret);
}
# 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("//build/ohos_var.gni")
import("//drivers/adapter/uhdf2/uhdf.gni")
import("//test/xts/tools/build/suite.gni")
module_output_path = "hdf/wlan"
ohos_moduletest_suite("hdf_xtstest_wifi") {
module_out_path = module_output_path
include_dirs = [
"//drivers/framework/test/unittest/include",
"//drivers/peripheral/wlan/client/include",
"//drivers/peripheral/wlan/hal/include",
"//drivers/peripheral/wlan/interfaces/include",
]
sources = [ "./common/wifi_hal_test.cpp" ]
cflags = [
"-Wall",
"-Wextra",
"-Werror",
"-fsigned-char",
"-fno-common",
"-fno-strict-aliasing",
]
deps = [
"$hdf_uhdf_path/test/unittest/common:libhdf_test_common",
"$hdf_uhdf_path/utils:libhdf_utils",
"//drivers/peripheral/wlan/client:wifi_driver_client",
"//drivers/peripheral/wlan/hal:wifi_hal",
"//utils/native/base:utils",
]
if (is_standard_system) {
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
} else {
external_deps = [ "hilog:libhilog" ]
}
}
{
"kits": [
{
"push": [
"hdf_xtstest_wifi->/data/local/tmp/hdf_xtstest_wifi"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "hdf_xtstest_wifi",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for hdf_xtstest_wifi Tests"
}
\ No newline at end of file
/*
* 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.
*/
#ifndef HDF_WIFI_TEST_H
#define HDF_WIFI_TEST_H
// wifi test case number
enum HdfWiFiTestCaseCmd {
/* flow control. */
WIFI_FLOW_CONTROL_INIT,
WIFI_FLOW_CONTROL_DEINIT,
WIFI_FLOW_CONTROL_GET_QUEUE_ID,
WIFI_FLOW_CONTROL_SEND_DATA,
WIFI_FLOW_CONTROL_END = 50,
/* netdevice. */
WIFI_NET_DEVICE_INIT = WIFI_FLOW_CONTROL_END,
WIFI_NET_DEVICE_DEINIT,
WIFI_NET_DEVICE_ADD,
WIFI_NET_DEVICE_DELETE,
WIFI_NET_DEVICE_GET,
WIFI_NET_DEVICE_GET_COUNT,
WIFI_NET_DEVICE_GET_CAP,
WIFI_NET_DEVICE_SET_ADDR,
WIFI_NET_DEVICE_SET_STATUS,
WIFI_NET_DEVICE_SET_LINK_STATUS,
WIFI_NET_DEVICE_RX,
WIFI_NET_DEVICE_DHCPC,
WIFI_NET_DEVICE_DHCPS,
WIFI_NET_DEVICE_END = 100,
/* netbuff */
WIFI_NET_BUF_TEST = WIFI_NET_DEVICE_END,
WIFI_NET_BUF_QUEUE_TEST,
WIFI_NET_BUFF_END = 150,
/* module */
WIFI_MODULE_CREATE_MODULE = WIFI_NET_BUFF_END,
WIFI_MODULE_DELETE_MODULE,
WIFI_MODULE_ADD_FEATURE,
WIFI_MODULE_DELETE_FEATURE,
WIFI_MODULE_END = 200,
/* message */
WIFI_MESSAGE_QUEUE_001 = WIFI_MODULE_END,
WIFI_MESSAGE_QUEUE_002,
WIFI_MESSAGE_QUEUE_003,
WIFI_MESSAGE_SINGLE_NODE_001,
WIFI_MESSAGE_SINGLE_NODE_002,
WIFI_MESSAGE_SINGLE_NODE_003,
WIFI_MESSAGE_SINGLE_NODE_004,
WIFI_MESSAGE_SINGLE_NODE_005,
WIFI_MESSAGE_END = 300,
};
#endif // HDF_WIFI_TEST_H
/*
* 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 <cstdint>
#include <gtest/gtest.h>
#include "hdf_base.h"
#include "hdf_uhdf_test.h"
#include "hdf_wifi_test.h"
#include "hdf_sbuf.h"
#include "wifi_hal.h"
#include "wifi_hal_ap_feature.h"
#include "wifi_hal_base_feature.h"
#include "wifi_hal_sta_feature.h"
using namespace testing::ext;
namespace HalTest {
struct IWiFi *g_wifi = nullptr;
const int32_t WLAN_TX_POWER = 160;
class WifiHalTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void WifiHalTest::SetUpTestCase()
{
int ret;
ret = WifiConstruct(&g_wifi);
ASSERT_EQ(HDF_SUCCESS, ret);
}
void WifiHalTest::TearDownTestCase()
{
int ret;
ret = WifiDestruct(&g_wifi);
ASSERT_EQ(HDF_SUCCESS, ret);
}
void WifiHalTest::SetUp()
{
int ret;
ret = g_wifi->start(nullptr);
ASSERT_EQ(HDF_ERR_INVALID_PARAM, ret);
ret = g_wifi->start(g_wifi);
ASSERT_EQ(HDF_SUCCESS, ret);
}
void WifiHalTest::TearDown()
{
int ret;
ret = g_wifi->stop(nullptr);
ASSERT_EQ(HDF_ERR_INVALID_PARAM, ret);
ret = g_wifi->stop(g_wifi);
ASSERT_EQ(HDF_SUCCESS, ret);
}
static void ParseScanResult(const WifiScanResult *scanResult)
{
printf("ParseScanResult: flags=%d, caps=%d, freq=%d, beaconInt=%d,\n",
scanResult->flags, scanResult->caps, scanResult->freq, scanResult->beaconInt);
printf("ParseScanResult: qual=%d, beaconIeLen=%d, level=%d, age=%d, ieLen=%d,\n",
scanResult->qual, scanResult->beaconIeLen, scanResult->level, scanResult->age, scanResult->ieLen);
}
static int32_t HalCallbackEventScanResult(uint32_t eventId, void *data, const char *ifName)
{
printf("HalCallbackEventScanResult ifName = %s, eventId = %d\n", ifName, eventId);
switch (eventId) {
case WIFI_EVENT_SCAN_DONE:
printf("HalCallbackEventScanResult WIFI_EVENT_SCAN_DONE Process\n");
break;
case WIFI_EVENT_SCAN_RESULT:
ParseScanResult((const WifiScanResult *)data);
break;
default:
break;
}
return HDF_SUCCESS;
}
/**
* @tc.name: WifiHalCreateAndDestroyFeature001
* @tc.desc: Wifi hal create and destroy feature function test
* @tc.type: FUNC
*/
HWTEST_F(WifiHalTest, WifiHalCreateAndDestroyFeature001, Function | MediumTest | Level1)
{
int ret;
struct IWiFiAp *apFeature = nullptr;
ret = g_wifi->createFeature(PROTOCOL_80211_IFTYPE_AP, (struct IWiFiBaseFeature **)&apFeature);
EXPECT_EQ(HDF_SUCCESS, ret);
EXPECT_NE(nullptr, apFeature);
ret = g_wifi->destroyFeature(nullptr);
EXPECT_NE(HDF_SUCCESS, ret);
ret = g_wifi->destroyFeature((struct IWiFiBaseFeature *)apFeature);
EXPECT_EQ(HDF_SUCCESS, ret);
}
/**
* @tc.name: WifiHalCreateAndDestroyFeature002
* @tc.desc: Wifi hal create and destroy feature function test
* @tc.type: FUNC
*/
HWTEST_F(WifiHalTest, WifiHalCreateAndDestroyFeature002, Function | MediumTest | Level1)
{
int ret;
struct IWiFiSta *staFeature = nullptr;
ret = g_wifi->createFeature(PROTOCOL_80211_IFTYPE_STATION, (struct IWiFiBaseFeature **)&staFeature);
EXPECT_EQ(HDF_SUCCESS, ret);
EXPECT_NE(nullptr, staFeature);
ret = g_wifi->destroyFeature(nullptr);
EXPECT_NE(HDF_SUCCESS, ret);
ret = g_wifi->destroyFeature((struct IWiFiBaseFeature *)staFeature);
EXPECT_EQ(HDF_SUCCESS, ret);
}
/**
* @tc.name: WifiHalGetFeatureByIfName001
* @tc.desc: Wifi hal get feature by ifname function test
* @tc.type: FUNC
*/
HWTEST_F(WifiHalTest, WifiHalGetFeatureByIfName001, Function | MediumTest | Level1)
{
int ret;
struct IWiFiAp *apFeature = nullptr;
struct IWiFiAp *apFeatureGet = nullptr;
const char *ifName0 = "wlanTest";
const char *ifName1 = "wlan0";
ret = g_wifi->createFeature(PROTOCOL_80211_IFTYPE_AP, (struct IWiFiBaseFeature **)&apFeature);
EXPECT_EQ(HDF_SUCCESS, ret);
EXPECT_NE(nullptr, apFeature);
ret = g_wifi->getFeatureByIfName(ifName0, (struct IWiFiBaseFeature **)&apFeatureGet);
EXPECT_NE(HDF_SUCCESS, ret);
ret = g_wifi->getFeatureByIfName(ifName1, (struct IWiFiBaseFeature **)&apFeatureGet);
EXPECT_EQ(HDF_SUCCESS, ret);
EXPECT_NE(nullptr, apFeatureGet);
ret = g_wifi->destroyFeature((struct IWiFiBaseFeature *)apFeature);
EXPECT_EQ(HDF_SUCCESS, ret);
}
static int32_t HalCallbackEvent(uint32_t event, void *respData, const char *ifName)
{
(void)event;
if (respData == nullptr) {
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
/**
* @tc.name: WifiHalRegisterEventCallback001
* @tc.desc: Wifi hal register callback function test
* @tc.type: FUNC
*/
HWTEST_F(WifiHalTest, WifiHalRegisterEventCallback001, Function | MediumTest | Level1)
{
int ret;
ret = g_wifi->registerEventCallback(HalCallbackEvent, "wlan0");
EXPECT_EQ(HDF_SUCCESS, ret);
}
/**
* @tc.name: WifiHalUnRegisterEventCallback001
* @tc.desc: Wifi hal unregister callback function test
* @tc.type: FUNC
*/
HWTEST_F(WifiHalTest, WifiHalUnRegisterEventCallback001, Function | MediumTest | Level1)
{
int ret;
ret = g_wifi->unregisterEventCallback(HalCallbackEvent, "wlan0");
EXPECT_EQ(HDF_SUCCESS, ret);
}
/**
* @tc.name: WifiHalGetNetworkIfaceName001
* @tc.desc: Wifi hal get network iface name function test
* @tc.type: FUNC
*/
HWTEST_F(WifiHalTest, WifiHalGetNetworkIfaceName001, Function | MediumTest | Level1)
{
int ret;
struct IWiFiAp *apFeature = nullptr;
ret = g_wifi->createFeature(PROTOCOL_80211_IFTYPE_AP, (struct IWiFiBaseFeature **)&apFeature);
EXPECT_EQ(HDF_SUCCESS, ret);
EXPECT_NE(nullptr, apFeature);
const char *ifName = apFeature->baseFeature.getNetworkIfaceName((const struct IWiFiBaseFeature *)apFeature);
EXPECT_NE(nullptr, ifName);
ret = strcmp(ifName, "wlan0");
EXPECT_EQ(0, ret);
ret = g_wifi->destroyFeature((struct IWiFiBaseFeature *)apFeature);
EXPECT_EQ(HDF_SUCCESS, ret);
}
/**
* @tc.name: WifiHalGetGetFeatureType001
* @tc.desc: Wifi hal get feature type function test
* @tc.type: FUNC
*/
HWTEST_F(WifiHalTest, WifiHalGetGetFeatureType001, Function | MediumTest | Level1)
{
int ret;
struct IWiFiAp *apFeature = nullptr;
int32_t type;
ret = g_wifi->createFeature(PROTOCOL_80211_IFTYPE_AP, (struct IWiFiBaseFeature **)&apFeature);
EXPECT_EQ(HDF_SUCCESS, ret);
EXPECT_NE(nullptr, apFeature);
type = apFeature->baseFeature.getFeatureType((struct IWiFiBaseFeature *)apFeature);
EXPECT_EQ(PROTOCOL_80211_IFTYPE_AP, type);
ret = g_wifi->destroyFeature((struct IWiFiBaseFeature *)apFeature);
EXPECT_EQ(HDF_SUCCESS, ret);
}
/**
* @tc.name: WifiHalSetMacAddress001
* @tc.desc: Wifi hal set Mac address function test
* @tc.type: FUNC
*/
HWTEST_F(WifiHalTest, WifiHalSetMacAddress001, Function | MediumTest | Level1)
{
int ret;
struct IWiFiAp *apFeature = nullptr;
unsigned char errorMac[ETH_ADDR_LEN] = {0x11, 0x34, 0x56, 0x78, 0xab, 0xcd};
unsigned char mac[ETH_ADDR_LEN] = {0x12, 0x34, 0x56, 0x78, 0xab, 0xcd};
ret = g_wifi->createFeature(PROTOCOL_80211_IFTYPE_AP, (struct IWiFiBaseFeature **)&apFeature);
EXPECT_EQ(HDF_SUCCESS, ret);
EXPECT_NE(nullptr, apFeature);
ret = apFeature->baseFeature.setMacAddress((struct IWiFiBaseFeature *)apFeature, nullptr, 0);
EXPECT_NE(HDF_SUCCESS, ret);
ret = apFeature->baseFeature.setMacAddress((struct IWiFiBaseFeature *)apFeature, errorMac, ETH_ADDR_LEN);
EXPECT_NE(HDF_SUCCESS, ret);
ret = apFeature->baseFeature.setMacAddress((struct IWiFiBaseFeature *)apFeature, mac, ETH_ADDR_LEN);
EXPECT_EQ(HDF_SUCCESS, ret);
ret = g_wifi->destroyFeature((struct IWiFiBaseFeature *)apFeature);
EXPECT_EQ(HDF_SUCCESS, ret);
}
/**
* @tc.name: WifiHalSetMacAddress002
* @tc.desc: Wifi hal set Mac address function test
* @tc.type: FUNC
*/
HWTEST_F(WifiHalTest, WifiHalSetMacAddress002, Function | MediumTest | Level1)
{
int ret;
struct IWiFiSta *staFeature = nullptr;
unsigned char errorMac[ETH_ADDR_LEN] = {0};
unsigned char mac[ETH_ADDR_LEN] = {0x12, 0x34, 0x56, 0x78, 0xab, 0xcd};
ret = g_wifi->createFeature(PROTOCOL_80211_IFTYPE_STATION, (struct IWiFiBaseFeature **)&staFeature);
EXPECT_EQ(HDF_SUCCESS, ret);
EXPECT_NE(nullptr, staFeature);
ret = staFeature->baseFeature.setMacAddress((struct IWiFiBaseFeature *)staFeature, nullptr, 0);
EXPECT_NE(HDF_SUCCESS, ret);
ret = staFeature->baseFeature.setMacAddress((struct IWiFiBaseFeature *)staFeature, errorMac, ETH_ADDR_LEN);
EXPECT_NE(HDF_SUCCESS, ret);
ret = staFeature->baseFeature.setMacAddress((struct IWiFiBaseFeature *)staFeature, mac, ETH_ADDR_LEN);
EXPECT_EQ(HDF_SUCCESS, ret);
ret = g_wifi->destroyFeature((struct IWiFiBaseFeature *)staFeature);
EXPECT_EQ(HDF_SUCCESS, ret);
}
/**
* @tc.name: WifiHalSetTxPower001
* @tc.desc: Wifi hal set transmit power function test
* @tc.type: FUNC
*/
HWTEST_F(WifiHalTest, WifiHalSetTxPower001, Function | MediumTest | Level1)
{
int ret;
struct IWiFiAp *apFeature = nullptr;
ret = g_wifi->createFeature(PROTOCOL_80211_IFTYPE_AP, (struct IWiFiBaseFeature **)&apFeature);
EXPECT_EQ(HDF_SUCCESS, ret);
EXPECT_NE(nullptr, apFeature);
ret = apFeature->baseFeature.setTxPower((struct IWiFiBaseFeature *)apFeature, 0);
EXPECT_NE(HDF_SUCCESS, ret);
ret = apFeature->baseFeature.setTxPower((struct IWiFiBaseFeature *)apFeature, WLAN_TX_POWER);
EXPECT_EQ(HDF_SUCCESS, ret);
ret = g_wifi->destroyFeature((struct IWiFiBaseFeature *)apFeature);
EXPECT_EQ(HDF_SUCCESS, ret);
}
/**
* @tc.name: WifiHalSetCountryCode001
* @tc.desc: Wifi hal set country code function test
* @tc.type: FUNC
*/
HWTEST_F(WifiHalTest, WifiHalSetCountryCode001, Function | MediumTest | Level1)
{
int ret;
struct IWiFiAp *apFeature = nullptr;
ret = g_wifi->createFeature(PROTOCOL_80211_IFTYPE_AP, (struct IWiFiBaseFeature **)&apFeature);
EXPECT_EQ(HDF_SUCCESS, ret);
EXPECT_NE(nullptr, apFeature);
ret = apFeature->setCountryCode(apFeature, nullptr, 0);
EXPECT_NE(HDF_SUCCESS, ret);
ret = apFeature->setCountryCode(apFeature, "CN", 2);
EXPECT_EQ(HDF_SUCCESS, ret);
ret = g_wifi->destroyFeature((struct IWiFiBaseFeature *)apFeature);
EXPECT_EQ(HDF_SUCCESS, ret);
}
HWTEST_F(WifiHalTest, WifiHalStartScan001, Function | MediumTest | Level1)
{
int ret;
struct IWiFiSta *staFeature = nullptr;
const char *ifName = "wlan0";
WifiScan scan = {0};
ret = g_wifi->registerEventCallback(HalCallbackEventScanResult, ifName);
EXPECT_EQ(HDF_SUCCESS, ret);
ret = g_wifi->createFeature(PROTOCOL_80211_IFTYPE_STATION, (struct IWiFiBaseFeature **)&staFeature);
EXPECT_EQ(HDF_SUCCESS, ret);
EXPECT_NE(nullptr, staFeature);
ret = staFeature->startScan(ifName, &scan);
EXPECT_EQ(HDF_SUCCESS, ret);
sleep(10);
}
};
\ No newline at end of file
......@@ -39,6 +39,7 @@ _all_test_packages = [
"${ACTS_ROOT}/ace:ace",
"${ACTS_ROOT}/storage:storage",
"${ACTS_ROOT}/distributedhardware:distributedhardware",
"${ACTS_ROOT}/hdf:hdfacttest",
]
_all_test_packages_ivi = [
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册