diff --git a/hdf/BUILD.gn b/hdf/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..5c4d4ee8b2e14b6569349971de2c2c4a349bfeb6 --- /dev/null +++ b/hdf/BUILD.gn @@ -0,0 +1,23 @@ +# 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", + ] + } +} diff --git a/hdf/input/BUILD.gn b/hdf/input/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..b84ab427c7d4f07b3c2f3a5674b3bca53d41c5f7 --- /dev/null +++ b/hdf/input/BUILD.gn @@ -0,0 +1,46 @@ +# 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" ] + } +} diff --git a/hdf/input/Test.json b/hdf/input/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..77e7e4d1baf17cc1182542862b7fc8fe41c1c9e3 --- /dev/null +++ b/hdf/input/Test.json @@ -0,0 +1,18 @@ +{ + "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 diff --git a/hdf/input/common/hdi_input_test.cpp b/hdf/input/common/hdi_input_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..58069707c30e1a91263231b155afb3c36a45646c --- /dev/null +++ b/hdf/input/common/hdi_input_test.cpp @@ -0,0 +1,768 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include "osal_time.h" +#include "hdf_log.h" +#include "input_manager.h" + +using namespace testing::ext; + +namespace { + IInputInterface *g_inputInterface; + InputEventCb g_callback; + InputHostCb g_hotplugCb; + + static void ReportHotPlugEventPkgCallback(const HotPlugEvent *msg); + static void ReportEventPkgCallback(const EventPackage **pkgs, uint32_t count, uint32_t devIndex); + static void CloseOnlineDev(DevDesc *sta, int32_t len); + static void OpenOnlineDev(DevDesc *sta, int32_t len); + const int INIT_DEFAULT_VALUE = 255; + const int KEEP_ALIVE_TIME_MS = 15000; + const int TOUCH_INDEX = 1; + const int INVALID_INDEX = 5; + const int NAME_MAX_LEN = 10; + const int TEST_RESULT_LEN = 32; + const int MAX_DEVICES = 32; + + #define INPUT_CHECK_NULL_POINTER(pointer, ret) do { \ + if ((pointer) == NULL) { \ + HDF_LOGE("%s: null pointer", __func__); \ + ASSERT_EQ ((ret), INPUT_SUCCESS); \ + } \ + } while (0) + + static void ReportEventPkgCallback(const EventPackage **pkgs, uint32_t count, uint32_t devIndex) + { + if (pkgs == NULL) { + return; + } + for (uint32_t i = 0; i < count; i++) { + printf("%s: pkgs[%d] = 0x%x, 0x%x, %d\n", __func__, i, pkgs[i]->type, pkgs[i]->code, pkgs[i]->value); + } + } + + static void ReportHotPlugEventPkgCallback(const HotPlugEvent *msg) + { + int32_t ret; + if (msg == NULL) { + return; + } + HDF_LOGI("%s: status =%d devId=%d type =%d", __func__, msg->status, msg->devIndex, msg->devType); + + if (msg->status == 0) { + ret = g_inputInterface->iInputManager->OpenInputDevice(msg->devIndex); + if (ret) { + HDF_LOGE("%s: open device[%u] failed, ret %d", __func__, msg->devIndex, ret); + } + + ret = g_inputInterface->iInputReporter->RegisterReportCallback(msg->devIndex, &g_callback); + if (ret) { + HDF_LOGE("%s: register callback failed for device[%d], ret %d", __func__, msg->devIndex, ret); + } + } else { + ret = g_inputInterface->iInputReporter->UnregisterReportCallback(msg->devIndex); + if (ret) { + HDF_LOGE("%s: unregister callback failed, ret %d", __func__, ret); + } + + ret = g_inputInterface->iInputManager->CloseInputDevice(msg->devIndex); + if (ret) { + HDF_LOGE("%s: close device failed, ret %d", __func__, ret); + } + } + } + + static void OpenOnlineDev(DevDesc *sta, int32_t len) + { + int32_t ret = g_inputInterface->iInputManager->ScanInputDevice(sta, len); + if (ret) { + HDF_LOGE("%s: scan device failed, ret %d", __func__, ret); + } + ASSERT_EQ(ret, INPUT_SUCCESS); + + for (int32_t i = 0; i < len; i++) { + if (sta[i].devIndex == 0) { + break; + } + ret = g_inputInterface->iInputManager->OpenInputDevice(sta[i].devIndex); + if (ret) { + HDF_LOGE("%s: open device[%d] failed, ret %d", __func__, sta[i].devIndex, ret); + } + ASSERT_EQ(ret, INPUT_SUCCESS); + + ret = g_inputInterface->iInputReporter->RegisterReportCallback(sta[i].devIndex, &g_callback); + if (ret) { + HDF_LOGE("%s: register callback failed for device[%d], ret %d", __func__, sta[i].devIndex, ret); + } + ASSERT_EQ(ret, INPUT_SUCCESS); + } + } + + static void CloseOnlineDev(DevDesc *sta, int32_t len) + { + int32_t ret = g_inputInterface->iInputManager->ScanInputDevice(sta, len); + if (ret) { + HDF_LOGE("%s: scan device failed, ret %d", __func__, ret); + } + ASSERT_EQ(ret, INPUT_SUCCESS); + + for (int32_t i = 0; i < len; i++) { + if (sta[i].devIndex == 0) { + break; + } + ret = g_inputInterface->iInputReporter->UnregisterReportCallback(sta[i].devIndex); + if (ret) { + HDF_LOGE("%s: register callback failed for device[%d], ret %d", __func__, sta[i].devIndex, ret); + } + ASSERT_EQ(ret, INPUT_SUCCESS); + + ret = g_inputInterface->iInputManager->CloseInputDevice(sta[i].devIndex); + if (ret) { + HDF_LOGE("%s: close device[%d] failed, ret %d", __func__, sta[i].devIndex, ret); + } + ASSERT_EQ(ret, INPUT_SUCCESS); + } + } +} + +class HdiInputTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void HdiInputTest::SetUpTestCase() +{ + int32_t ret = GetInputInterface(&g_inputInterface); + if (ret != INPUT_SUCCESS) { + HDF_LOGE("%s: get input hdi failed, ret %d", __func__, ret); + } + + g_callback.EventPkgCallback = ReportEventPkgCallback; + g_hotplugCb.HotPlugCallback = ReportHotPlugEventPkgCallback; +} + +void HdiInputTest::TearDownTestCase() +{ + ReleaseInputInterface(g_inputInterface); +} + +void HdiInputTest::SetUp() +{ +} + +void HdiInputTest::TearDown() +{ +} + +/** + * @tc.name: ScanInputDevice + * @tc.desc: ScanInputDevice test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, ScanInputDevice, Function | MediumTest | Level1) +{ + DevDesc sta[MAX_DEVICES]; + + HDF_LOGI("%s: [Input] RegisterCallbackAndReportData001 enter", __func__); + int32_t ret; + + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR); + + ret = g_inputInterface->iInputManager->ScanInputDevice(sta, sizeof(sta)/sizeof(DevDesc)); + if (!ret) { + HDF_LOGI("%s:%d, %d, %d, %d", __func__, sta[0].devType, sta[0].devIndex, sta[1].devType, sta[1].devIndex); + } + + EXPECT_EQ(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: HotPlugCallback + * @tc.desc: HotPlugCallback test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, HotPlugCallback, Function | MediumTest | Level3) +{ + HDF_LOGI("%s: [Input] HotPlugCallback Testcase enter", __func__); + int32_t ret = INPUT_SUCCESS; + DevDesc sta[MAX_DEVICES]; + + ret = memset_s(sta, sizeof(sta), 0, sizeof(sta)); + if (ret != 0) { + HDF_LOGE("%s: memcpy failed, line %d", __func__, __LINE__); + } + + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputReporter, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR); + + ret = g_inputInterface->iInputReporter->RegisterHotPlugCallback(&g_hotplugCb); + if (ret) { + HDF_LOGE("%s: register hotplug callback failed for device manager, ret %d", __func__, ret); + } + ASSERT_EQ(ret, INPUT_SUCCESS); + + OpenOnlineDev(sta, MAX_DEVICES); + + HDF_LOGI("%s: wait 15s for testing, pls hotplug now", __func__); + HDF_LOGI("%s: The event data is as following:", __func__); + OsalMSleep(KEEP_ALIVE_TIME_MS); + + ret = memset_s(sta, sizeof(sta), 0, sizeof(sta)); + if (ret != 0) { + HDF_LOGE("%s: memcpy failed, line %d", __func__, __LINE__); + } + + CloseOnlineDev(sta, MAX_DEVICES); + + ret = g_inputInterface->iInputReporter->UnregisterHotPlugCallback(); + if (ret) { + HDF_LOGE("%s: unregister hotplug callback failed for device manager, ret %d", __func__, ret); + } + EXPECT_EQ(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: OpenInputDev001 + * @tc.desc: open input device test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, OpenInputDev001, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] OpenInputDev001 enter", __func__); + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR); + int32_t ret = g_inputInterface->iInputManager->OpenInputDevice(TOUCH_INDEX); + if (ret) { + HDF_LOGE("%s: open device1 failed, ret %d", __func__, ret); + } + EXPECT_EQ(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: OpenInputDevice002 + * @tc.desc: open input device test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, OpenInputDevice002, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] OpenInputDev002 enter", __func__); + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR); + /* Device "5" is used for testing nonexistent device node */ + int32_t ret = g_inputInterface->iInputManager->OpenInputDevice(INVALID_INDEX); + if (ret) { + HDF_LOGE("%s: device5 dose not exist, can't open it, ret %d", __func__, ret); + } + EXPECT_NE(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: CloseInputDevice001 + * @tc.desc: close input device test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, CloseInputDevice001, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] CloseInputDev001 enter", __func__); + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR); + int32_t ret = g_inputInterface->iInputManager->CloseInputDevice(TOUCH_INDEX); + if (ret) { + HDF_LOGE("%s: close device1 failed, ret %d", __func__, ret); + } + EXPECT_EQ(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: CloseInputDevice002 + * @tc.desc: close input device test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, CloseInputDevice002, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] CloseInputDev002 enter", __func__); + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR); + /* Device "5" is used for testing nonexistent device node */ + int32_t ret = g_inputInterface->iInputManager->CloseInputDevice(INVALID_INDEX); + if (ret) { + HDF_LOGE("%s: device5 doesn't exist, can't close it, ret %d", __func__, ret); + } + EXPECT_NE(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: GetInputDevice001 + * @tc.desc: get input device info test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, GetInputDevice001, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] GetInputDevice001 enter", __func__); + DeviceInfo *dev = NULL; + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR); + + int32_t ret = g_inputInterface->iInputManager->OpenInputDevice(TOUCH_INDEX); + if (ret) { + HDF_LOGE("%s: open device1 failed, ret %d", __func__, ret); + } + ASSERT_EQ(ret, INPUT_SUCCESS); + + ret = g_inputInterface->iInputManager->GetInputDevice(TOUCH_INDEX, &dev); + if (ret) { + HDF_LOGE("%s: get device1 failed, ret %d", __func__, ret); + } + + HDF_LOGI("%s: devindex = %u, devType = %u", __func__, dev->devIndex, + dev->devType); + HDF_LOGI("%s: chipInfo = %s, vendorName = %s, chipName = %s", + __func__, dev->chipInfo, dev->vendorName, dev->chipName); + EXPECT_EQ(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: GetInputDeviceList001 + * @tc.desc: get input device list info test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, GetInputDeviceList001, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] GetInputDeviceList001 enter", __func__); + int32_t ret; + uint32_t num = 0; + DeviceInfo *dev[MAX_INPUT_DEV_NUM] = {0}; + + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR); + ret = g_inputInterface->iInputManager->GetInputDeviceList(&num, dev, MAX_INPUT_DEV_NUM); + if (ret) { + HDF_LOGE("%s: get device list failed, ret %d", __func__, ret); + } + ret = num <= MAX_INPUT_DEV_NUM ? HDF_SUCCESS : HDF_FAILURE; /* num <= MAX_INPUT_DEV_NUM return true */ + ASSERT_EQ(ret, INPUT_SUCCESS); + + + for (uint32_t i = 0; i < num; i++) { + HDF_LOGI("%s: num = %u, device[%d]'s info is:", __func__, num, i); + HDF_LOGI("%s: index = %u, devType = %u", __func__, dev[i]->devIndex, + dev[i]->devType); + HDF_LOGI("%s: chipInfo = %s, vendorName = %s, chipName = %s", + __func__, dev[i]->chipInfo, dev[i]->vendorName, dev[i]->chipName); + } + EXPECT_EQ(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: GetDeviceType001 + * @tc.desc: get input device type test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, GetDeviceType001, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] GetDeviceType001 enter", __func__); + int32_t ret; + uint32_t devType = INIT_DEFAULT_VALUE; + + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR); + ret = g_inputInterface->iInputController->GetDeviceType(TOUCH_INDEX, &devType); + if (ret) { + HDF_LOGE("%s: get device1's type failed, ret %d", __func__, ret); + } + HDF_LOGI("%s: device1's type is %u", __func__, devType); + EXPECT_EQ(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: GetChipInfo001 + * @tc.desc: get input device chip info test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, GetChipInfo001, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] GetChipInfo001 enter", __func__); + int32_t ret; + char chipInfo[CHIP_INFO_LEN] = {0}; + + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR); + ret = g_inputInterface->iInputController->GetChipInfo(TOUCH_INDEX, chipInfo, CHIP_INFO_LEN); + if (ret) { + HDF_LOGE("%s: get device1's chip info failed, ret %d", __func__, ret); + } + HDF_LOGI("%s: device1's chip info is %s", __func__, chipInfo); + EXPECT_EQ(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: GetInputDevice002 + * @tc.desc: get input device chip info test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, GetInputDevice002, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] GetInputDevice002 enter", __func__); + int32_t ret; + DeviceInfo *dev = NULL; + + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR); + ret = g_inputInterface->iInputManager->GetInputDevice(TOUCH_INDEX, &dev); + if (ret) { + HDF_LOGE("%s: get device1 failed, ret %d", __func__, ret); + } + + HDF_LOGI("%s: After fill the info, new device0's info is:", __func__); + HDF_LOGI("%s: new devindex = %u, devType = %u", __func__, dev->devIndex, + dev->devType); + HDF_LOGI("%s: new chipInfo = %s, vendorName = %s, chipName = %s", + __func__, dev->chipInfo, dev->vendorName, dev->chipName); + EXPECT_EQ(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: RegisterCallback001 + * @tc.desc: get input device chip info test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, RegisterCallback001, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] RegisterCallbac001 enter", __func__); + int32_t ret; + + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputReporter, INPUT_NULL_PTR); + /* Device "5" is used for testing nonexistent device node */ + ret = g_inputInterface->iInputReporter->RegisterReportCallback(INVALID_INDEX, &g_callback); + if (ret) { + HDF_LOGE("%s: device2 dose not exist, can't register callback to it, ret %d", __func__, ret); + } + EXPECT_NE(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: SetPowerStatus001 + * @tc.desc: set device power status test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, SetPowerStatus001, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] SetPowerStatus001 enter", __func__); + int32_t ret; + uint32_t setStatus = INPUT_LOW_POWER; + + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR); + ret = g_inputInterface->iInputController->SetPowerStatus(TOUCH_INDEX, setStatus); + if (ret) { + HDF_LOGE("%s: set device1's power status failed, ret %d", __func__, ret); + } + EXPECT_EQ(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: SetPowerStatus002 + * @tc.desc: set device power status test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, SetPowerStatus002, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] SetPowerStatus002 enter", __func__); + int32_t ret; + uint32_t setStatus = INPUT_LOW_POWER; + + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR); + /* Device "5" is used for testing nonexistent device node */ + ret = g_inputInterface->iInputController->SetPowerStatus(INVALID_INDEX, setStatus); + if (ret) { + HDF_LOGE("%s: set device5's power status failed, ret %d", __func__, ret); + } + EXPECT_NE(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: GetPowerStatus001 + * @tc.desc: get device power status test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, GetPowerStatus001, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] GetPowerStatus001 enter", __func__); + int32_t ret; + uint32_t getStatus = 0; + + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR); + ret = g_inputInterface->iInputController->GetPowerStatus(TOUCH_INDEX, &getStatus); + if (ret) { + HDF_LOGE("%s: get device1's power status failed, ret %d", __func__, ret); + } + HDF_LOGI("%s: device1's power status is %d:", __func__, getStatus); + EXPECT_EQ(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: GetPowerStatus002 + * @tc.desc: get device power status test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, GetPowerStatus002, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] GetPowerStatus002 enter", __func__); + int32_t ret; + uint32_t getStatus = 0; + + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR); + /* Device "5" is used for testing nonexistent device node */ + ret = g_inputInterface->iInputController->GetPowerStatus(INVALID_INDEX, &getStatus); + if (ret) { + HDF_LOGE("%s: get device5's power status failed, ret %d", __func__, ret); + } + EXPECT_NE(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: GetVendorName001 + * @tc.desc: get device vendor name test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, GetVendorName001, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] GetVendorName001 enter", __func__); + int32_t ret; + char vendorName[NAME_MAX_LEN] = {0}; + + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR); + ret = g_inputInterface->iInputController->GetVendorName(TOUCH_INDEX, vendorName, NAME_MAX_LEN); + if (ret) { + HDF_LOGE("%s: get device1's vendor name failed, ret %d", __func__, ret); + } + HDF_LOGI("%s: device1's vendor name is %s:", __func__, vendorName); + EXPECT_EQ(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: GetVendorName002 + * @tc.desc: get device vendor name test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, GetVendorName002, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] GetVendorName002 enter", __func__); + int32_t ret; + char vendorName[NAME_MAX_LEN] = {0}; + + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR); + /* Device "5" is used for testing nonexistent device node */ + ret = g_inputInterface->iInputController->GetVendorName(INVALID_INDEX, vendorName, NAME_MAX_LEN); + if (ret) { + HDF_LOGE("%s: get device5's vendor name failed, ret %d", __func__, ret); + } + EXPECT_NE(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: GetChipName001 + * @tc.desc: get device chip name test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, GetChipName001, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] GetChipName001 enter", __func__); + int32_t ret; + char chipName[NAME_MAX_LEN] = {0}; + + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR); + ret = g_inputInterface->iInputController->GetChipName(TOUCH_INDEX, chipName, NAME_MAX_LEN); + if (ret) { + HDF_LOGE("%s: get device1's chip name failed, ret %d", __func__, ret); + } + HDF_LOGI("%s: device1's chip name is %s", __func__, chipName); + EXPECT_EQ(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: GetChipName002 + * @tc.desc: get device chip name test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, GetChipName002, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] GetChipName002 enter", __func__); + int32_t ret; + char chipName[NAME_MAX_LEN] = {0}; + + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR); + /* Device "5" is used for testing nonexistent device node */ + ret = g_inputInterface->iInputController->GetChipName(INVALID_INDEX, chipName, NAME_MAX_LEN); + if (ret) { + HDF_LOGE("%s: get device5's chip name failed, ret %d", __func__, ret); + } + EXPECT_NE(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: SetGestureMode001 + * @tc.desc: set device gesture mode test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, SetGestureMode001, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] SetGestureMode001 enter", __func__); + int32_t ret; + uint32_t gestureMode = 1; + + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR); + ret = g_inputInterface->iInputController->SetGestureMode(TOUCH_INDEX, gestureMode); + if (ret) { + HDF_LOGE("%s: get device1's gestureMode failed, ret %d", __func__, ret); + } + EXPECT_EQ(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: SetGestureMode002 + * @tc.desc: set device gesture mode test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, SetGestureMode002, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] SetGestureMode001 enter", __func__); + int32_t ret; + uint32_t gestureMode = 1; + + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR); + /* Device "5" is used for testing nonexistent device node */ + ret = g_inputInterface->iInputController->SetGestureMode(INVALID_INDEX, gestureMode); + if (ret) { + HDF_LOGE("%s: get device1's gestureMode failed, ret %d", __func__, ret); + } + EXPECT_NE(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: RunCapacitanceTest001 + * @tc.desc: set device gesture mode test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, RunCapacitanceTest001, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] RunCapacitanceTest001 enter", __func__); + int32_t ret; + char result[TEST_RESULT_LEN] = {0}; + uint32_t testType = MMI_TEST; + + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR); + ret = g_inputInterface->iInputController->RunCapacitanceTest(TOUCH_INDEX, testType, result, TEST_RESULT_LEN); + if (ret) { + HDF_LOGE("%s: get device1's gestureMode failed, ret %d", __func__, ret); + } + EXPECT_EQ(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: RunCapacitanceTest001 + * @tc.desc: set device gesture mode test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, RunExtraCommand001, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] RunExtraCommand001 enter", __func__); + int32_t ret; + InputExtraCmd extraCmd = {0}; + extraCmd.cmdCode = "WakeUpMode"; + extraCmd.cmdValue = "Enable"; + + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR); + ret = g_inputInterface->iInputController->RunExtraCommand(TOUCH_INDEX, &extraCmd); + if (ret) { + HDF_LOGE("%s: get device1's gestureMode failed, ret %d", __func__, ret); + } + EXPECT_EQ(ret, INPUT_SUCCESS); +} + +/** + * @tc.name: RegisterCallbackAndReportData001 + * @tc.desc: get input device chip info test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, RegisterCallbackAndReportData001, Function | MediumTest | Level3) +{ + HDF_LOGI("%s: [Input] RegisterCallbackAndReportData001 enter", __func__); + int32_t ret; + + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputReporter, INPUT_NULL_PTR); + + ret = g_inputInterface->iInputReporter->RegisterReportCallback(TOUCH_INDEX, &g_callback); + if (ret) { + HDF_LOGE("%s: register callback failed for device 1, ret %d", __func__, ret); + } + EXPECT_EQ(ret, INPUT_SUCCESS); + HDF_LOGI("%s: wait 15s for testing, pls touch the panel now", __func__); + HDF_LOGI("%s: The event data is as following:", __func__); + OsalMSleep(KEEP_ALIVE_TIME_MS); +} + +/** + * @tc.name: UnregisterReportCallback001 + * @tc.desc: get input device chip info test + * @tc.type: FUNC + */ +HWTEST_F(HdiInputTest, UnregisterReportCallback001, Function | MediumTest | Level1) +{ + HDF_LOGI("%s: [Input] UnregisterReportCallback001 enter", __func__); + int32_t ret; + INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputReporter, INPUT_NULL_PTR); + INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR); + + ret = g_inputInterface->iInputReporter->UnregisterReportCallback(TOUCH_INDEX); + if (ret) { + HDF_LOGE("%s: unregister callback failed for device1, ret %d", __func__, ret); + } + EXPECT_EQ(ret, INPUT_SUCCESS); + + ret = g_inputInterface->iInputManager->CloseInputDevice(TOUCH_INDEX); + if (ret) { + HDF_LOGE("%s: close device1 failed, ret %d", __func__, ret); + } + EXPECT_EQ(ret, INPUT_SUCCESS); + HDF_LOGI("%s: Close the device1 successfully after all test", __func__); +} diff --git a/hdf/sensor/BUILD.gn b/hdf/sensor/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..8c90869541af5e85074a805269c3f9b045399d22 --- /dev/null +++ b/hdf/sensor/BUILD.gn @@ -0,0 +1,42 @@ +# 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" ] + } +} diff --git a/hdf/sensor/Test.json b/hdf/sensor/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..f5d9e1e693e5f24b70994b21492133d6c23f53df --- /dev/null +++ b/hdf/sensor/Test.json @@ -0,0 +1,18 @@ +{ + "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 diff --git a/hdf/sensor/common/hdf_sensor_test.cpp b/hdf/sensor/common/hdf_sensor_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..1a5bb126c9b0948f24c156055b59499c470bc555 --- /dev/null +++ b/hdf/sensor/common/hdf_sensor_test.cpp @@ -0,0 +1,442 @@ +/* + * 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 +#include +#include +#include +#include +#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); +} diff --git a/hdf/wlan/wifi/BUILD.gn b/hdf/wlan/wifi/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..a28f1018c67b46ee04858db9f16fada7a341760e --- /dev/null +++ b/hdf/wlan/wifi/BUILD.gn @@ -0,0 +1,48 @@ +# 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" ] + } +} diff --git a/hdf/wlan/wifi/Test.json b/hdf/wlan/wifi/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..1518031296b196bcf17becb45e94252f22c6a5ae --- /dev/null +++ b/hdf/wlan/wifi/Test.json @@ -0,0 +1,18 @@ +{ + "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 diff --git a/hdf/wlan/wifi/common/hdf_wifi_test.h b/hdf/wlan/wifi/common/hdf_wifi_test.h new file mode 100755 index 0000000000000000000000000000000000000000..480d080bf085c28e7c83723fdabe3d45bee25f7c --- /dev/null +++ b/hdf/wlan/wifi/common/hdf_wifi_test.h @@ -0,0 +1,64 @@ +/* + * 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 diff --git a/hdf/wlan/wifi/common/wifi_hal_test.cpp b/hdf/wlan/wifi/common/wifi_hal_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..12055c506e952c6e81915edfcbc30dbbd769c21a --- /dev/null +++ b/hdf/wlan/wifi/common/wifi_hal_test.cpp @@ -0,0 +1,356 @@ +/* + * 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 +#include +#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 diff --git a/test_packages.gni b/test_packages.gni index a495343d05542a3ec6bed4a37d2a3d9552cbf441..291d6a354e78608352799d673e2525f2c53a8664 100755 --- a/test_packages.gni +++ b/test_packages.gni @@ -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 = [