diff --git a/.gitee/ISSUE_TEMPLATE.zh-CN.md b/.gitee/ISSUE_TEMPLATE.zh-CN.md new file mode 100755 index 0000000000000000000000000000000000000000..f09d98dde9597de75ffcdb237c2b580b8fffa3f9 --- /dev/null +++ b/.gitee/ISSUE_TEMPLATE.zh-CN.md @@ -0,0 +1,13 @@ +### 该问题是怎么引起的? + + + +### 重现步骤 + + + +### 报错信息 + + + + diff --git a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md new file mode 100755 index 0000000000000000000000000000000000000000..33948fdcb51264545ce5ae797f5310a1c06f871d --- /dev/null +++ b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md @@ -0,0 +1,15 @@ +### 相关的Issue + + +### 原因(目的、解决的问题等) + + +### 描述(做了什么,变更了什么) + + +### 测试用例(新增、改动、可能影响的功能) + + + + + diff --git a/BUILD.gn b/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..37dc04d2583cece60072ddd90cd6036ceb833e28 --- /dev/null +++ b/BUILD.gn @@ -0,0 +1,101 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") +import("//build/lite/config/subsystem/aafwk/config.gni") + +lite_component("acts_compoment") { + all_features = [] + features = [] + if (ohos_xts_test_args != "") { + all_features += [ ohos_xts_test_args ] + } else { + if(ohos_kernel_type == "liteos_riscv") { + all_features += [ + "//test/xts/acts/communication_lite/lwip_hal:ActsLwipTest", + "//test/xts/acts/communication_lite/softbus_hal:ActsSoftBusTest", + "//test/xts/acts/communication_lite/wifiservice_hal:ActsWifiServiceTest", + "//test/xts/acts/utils_lite/utilsfile_hal:ActsUtilsFileTest", + "//test/xts/acts/utils_lite/parameter_hal:ActsParameterTest", + "//test/xts/acts/iot_hardware_lite/wifiiot_hal:ActsWifiIotTest", + "//test/xts/acts/kernel_lite/kernelcmsis_hal:ActsCMSISTest", + "//test/xts/acts/kernel_lite/kernelkal_hal:ActsKalTest", + "//test/xts/acts/hiviewdfx_lite/dfx_hal:ActsDfxFuncTest", + "//test/xts/acts/utils_lite/kvstore_hal:ActsKvStoreTest", + "//test/xts/acts/security_lite/datahuks_hal:ActsSecurityDataTest", + "//test/xts/acts/distributedschedule_lite/samgr_hal:ActsSamgrTest", + ] + } else if(ohos_kernel_type == "liteos_a") { + all_features += [ + "//test/xts/acts/kernel_lite:ActsKernelTest", + "//test/xts/acts/security_lite:securitytest", + "//test/xts/acts/utils_lite/kvstore_posix:ActsKvStoreTest", + "//test/xts/acts/startup_lite/parameter_posix:ActsParameterTest", + "//test/xts/acts/startup_lite/bootstrap_posix:ActsBootstrapTest", + #"//test/xts/acts/multimedia_lite/multimedia_posix/camera:ActsMediaCameraTest", + "//test/xts/acts/open_posix_testsuite/conformance/interfaces:ActsOpenPosixTest", + "//test/xts/acts/distributedschedule_lite/samgr_posix:ActsSamgrTest", + #"//test/xts/acts/multimedia_lite/multimedia_posix/recorder:ActsMediaRecorderTest", + #"//test/xts/acts/uikit_lite:uikit_test", + "//test/xts/acts/appexecfwk_lite/bundlems_posix:ActsBundleMgrTest", + "//test/xts/acts/communication_lite/softbus_posix:ActsSoftBusTest", + "//test/xts/acts/communication_lite/lwip_posix:ActsLwipTest", + ] + if (enable_ohos_appexecfwk_feature_ability == true) { + all_features += [ + "//test/xts/acts/appexecfwk_lite/abilityms_posix:ActsAbilityMgrTest", + ] + } + } else if(ohos_kernel_type == "linux") { + all_features += [ + "//test/xts/acts/utils_lite/kvstore_posix:ActsKvStoreTest", + "//test/xts/acts/startup_lite/parameter_posix:ActsParameterTest" + ] + } + } + + if (ohos_build_type == "debug") { + _all_features = "" + _product_json = rebase_path("//build/lite/product/${product}.json") + foreach(one_feature, all_features) { + _all_features = _all_features + one_feature + "," + } + _args = [ + "--method_name", "filter_by_subsystem", + "--arguments", "testsuites=${_all_features}#product_json=${_product_json}" + ] + features += exec_script(rebase_path("//test/xts/tools/build/utils.py"), _args, "list lines") + } +} + +test_suite("acts") { + deps = [ ":acts_compoment" ] + version = "OpenHarmony-ACTS-1.11.0" + if (ohos_kernel_type == "liteos_a") { + deps += [ "//test/xts/tools/others/query:query" ] + copy("query_copy") { + sources = ["$root_out_dir/bin/query.bin"] + outputs = ["$root_out_dir/suites/acts/resource/tools/query.bin"] + } + } +} + +generate_notice_file("acts_notice_file") { + module_name = "acts" + module_source_dir_list = [ + "//third_party/googletest", + "//third_party/unity", + "//third_party/bounds_checking_function", + "//third_party/iniparser" + ] +} diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000000000000000000000000000000000000..4a459866a57c25462afad17f3fe0b50d440da080 --- /dev/null +++ b/LICENSE @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/appexecfwk_lite/abilityms_posix/BUILD.gn b/appexecfwk_lite/abilityms_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..472c88c73336a3c9f804f6f99220f1b7256db5d7 --- /dev/null +++ b/appexecfwk_lite/abilityms_posix/BUILD.gn @@ -0,0 +1,70 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") +import("//build/lite/config/subsystem/aafwk/config.gni") + +hcpptest_suite("ActsAbilityMgrTest") { + suite_name = "acts" + sources = [ + "src/AbilityMgrTest.cpp" + ] + ldflags = [ + "-lstdc++", + ] + + deps = [ + "//base/hiviewdfx/frameworks/hilog_lite/featured:hilog_shared", + "//foundation/aafwk/frameworks/ability_lite:aafwk_abilitykit_lite", + "//foundation/appexecfwk/frameworks/bundle_lite:bundle", + "//foundation/communication/frameworks/ipc_lite:liteipc_adapter", + "//foundation/distributedschedule/services/samgr_lite/samgr:samgr", + "//utils/native/lite/kv_store:kv_store", + ] + if (enable_ohos_appexecfwk_feature_ability == true) { + deps += [ + "//foundation/graphic/lite/frameworks/ui:ui", + "//foundation/graphic/lite/utils:graphic_utils", + "//foundation/graphic/lite/frameworks/surface", + ] + } + + include_dirs = [ + "src", + "//third_party/googletest/googletest/include", + "//foundation/aafwk/interfaces/innerkits/abilitymgr_lite", + "//foundation/aafwk/interfaces/kits/ability_lite", + "//foundation/aafwk/interfaces/kits/want_lite", + "//foundation/aafwk/services/abilitymgr_lite/include", + "//foundation/aafwk/frameworks/abilitymgr_lite/include", + "//foundation/appexecfwk/interfaces/kits/bundle_lite/", + "//foundation/appexecfwk/utils/bundle_lite", + "//foundation/appexecfwk/interfaces/innerkits/bundlemgr_lite/", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/registry", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/samgr", + "//kernel/liteos_a/kernel/include", + "//kernel/liteos_a/kernel/common", + "//third_party/bounds_checking_function/include", + "//third_party/cJSON", + "//utils/native/lite/include", + "//kernel/liteos_a/lib/libsec/include", + "//foundation/appexecfwk/interfaces/innerkits/bundlemgr_lite", + "//foundation/graphic/lite/interfaces/kits/ui", + "//foundation/graphic/lite/interfaces/kits/utils", + "//foundation/graphic/lite/interfaces/kits/config", + ] + cflags = [ "-Wno-error" ] + defines = ["OHOS_APPEXECFWK_BMS_BUNDLEMANAGER", + "ABILITY_WINDOW_SUPPORT", + ] +} diff --git a/appexecfwk_lite/abilityms_posix/Test.json b/appexecfwk_lite/abilityms_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..0bbdb9966c8716887cad27979174883fc79f2302 --- /dev/null +++ b/appexecfwk_lite/abilityms_posix/Test.json @@ -0,0 +1,28 @@ +{ + "description": "Config for abilityms test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/appexecfwk", + "target": "/test_root/appexecfwk" + },{ + "source": "resource/appexecfwk", + "target": "/test_root/appexecfwk" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/appexecfwk/ActsAbilityMgrTest.bin" + } +} \ No newline at end of file diff --git a/appexecfwk_lite/abilityms_posix/src/AbilityMgrTest.cpp b/appexecfwk_lite/abilityms_posix/src/AbilityMgrTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..472049eb8012670fabc20cc118a05adea0271a3a --- /dev/null +++ b/appexecfwk_lite/abilityms_posix/src/AbilityMgrTest.cpp @@ -0,0 +1,892 @@ +/** + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "securec.h" + +#include "ability.h" +#include "ability_connection.h" +#include "ability_env.h" +#include "ability_event_handler.h" +#include "ability_manager.h" +#include "ability_slice.h" +#include "abilityms_client.h" +#include "bundle_manager.h" +#include "want.h" + +using namespace std; +using namespace testing::ext; +using namespace OHOS; +static int32_t g_errorCode = -1; +static sem_t g_sem; +static const int32_t WAIT_TIMEOUT = 30; +static bool g_installState = false; + +extern "C" { +void __attribute__((weak)) HOS_SystemInit(void){}; +} + +/* install callback */ +static void TestBundleStateCallback(const uint8_t resultCode, const void *resultMessage) +{ + HILOG_DEBUG(HILOG_MODULE_APP, "TestBundleStateCallback resultCode: %d", resultCode); + HILOG_DEBUG(HILOG_MODULE_APP, "TestBundleStateCallback resultMessage: %s", (char *) resultMessage); + if (resultCode == 0) { + g_installState = true; + g_errorCode = resultCode; + } else { + g_installState = false; + g_errorCode = resultCode; + } + sem_post(&g_sem); +} + +/* connectAbiltiy callback */ +static void OnAbilityConnectDone(ElementName *elementName, SvcIdentity *serviceSid, int resultCode, void *storeData) +{ + printf("OnAbilityConnectDone, serviceSid is %p \n", serviceSid); + printf("elementName is %s, %s \n", elementName->bundleName, elementName->abilityName); + ClearElement(elementName); + if (serviceSid == nullptr) { + return; + } + printf("ipc callback success \n"); + // push data + IpcIo request; + char data[IPC_IO_DATA_MAX]; + IpcIoInit(&request, data, IPC_IO_DATA_MAX, 0); + int32_t data1 = 10; + int32_t data2 = 6; + IpcIoPushInt32(&request, data1); + IpcIoPushInt32(&request, data2); + // send and getReply + IpcIo reply = {nullptr}; + uintptr_t ptr = 0; + Transact(NULL, *serviceSid, 0, &request, &reply, LITEIPC_FLAG_DEFAULT, &ptr); + int result = 0; + result = IpcIoPopInt32(&reply); + if (result != 0) { + printf("execute add method, result is %d\n", result); + } + if (ptr != 0) { + FreeBuffer(nullptr, reinterpret_cast(ptr)); + } + sem_post(&g_sem); +} + +static void OnAbilityDisconnectDone(ElementName *elementName, int resultCode, void *storeData) +{ + printf("OnAbilityDisconnectDone\n"); + sem_post(&g_sem); +} + + +static IAbilityConnection g_conn = { + .OnAbilityConnectDone = OnAbilityConnectDone, + .OnAbilityDisconnectDone = OnAbilityDisconnectDone +}; + +class AbilityMgrTest: public testing :: Test { +protected: + static void SetUpTestCase(void) + { + printf("----------test case with AbilityMgrTest start-------------\n"); + HOS_SystemInit(); + AbilityMsClient::GetInstance().Initialize(); + sem_init(&g_sem, 0, 0); + bool installResult = false; + installResult = Install("/test_root/appexecfwk/testnative.hap", nullptr, TestBundleStateCallback); + struct timespec ts = {}; + clock_gettime(CLOCK_REALTIME, &ts); + ts.tv_sec += WAIT_TIMEOUT; + sem_timedwait(&g_sem, &ts); + if (installResult) { + printf("sem exit \n"); + } + } + static void TearDownTestCase(void) + { + bool uninstallResult = false; + sem_init(&g_sem, 0, 0); + uninstallResult = Uninstall("com.huawei.testnative", nullptr, TestBundleStateCallback); + sem_wait(&g_sem); + if (uninstallResult) { + printf("sem exit \n"); + } + printf("----------test case with AbilityMgrTest end-------------\n"); + } +}; + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_013 + * @tc.name : testClearElement parameter legal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(AbilityMgrTest, testClearElement, TestSize.Level0) +{ + printf("------start testClearElement------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetElementAbilityName(&element, "SecondAbility"); + if (element.abilityName != nullptr) { + printf("abilityName is %s \n", element.abilityName); + char aName[] = "SecondAbility"; + EXPECT_STREQ(element.abilityName, aName); + ClearElement(&element); + printf("AbilityName afterclear is %s \n", element.abilityName); + EXPECT_STREQ(element.abilityName, nullptr); + } + printf("------end testClearElement------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_014 + * @tc.name : testClearElement parameter illegal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(AbilityMgrTest, testClearElementIllegal, TestSize.Level2) +{ + printf("------start testClearElementIllegal------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetElementAbilityName(&element, "SecondAbility"); + if (element.abilityName != nullptr) { + printf("abilityName is %s \n", element.abilityName); + char aName[] = "SecondAbility"; + EXPECT_STREQ(element.abilityName, aName); + ClearElement(nullptr); + printf("AbilityName of element is %s \n", element.abilityName); + EXPECT_STREQ(element.abilityName, aName); + } + printf("------end testClearElementIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_015 + * @tc.name : testSetWantElement parameter legal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(AbilityMgrTest, testSetWantElement, TestSize.Level0) +{ + printf("------start testSetWantElement------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetElementDeviceID(&element, "0001000"); + SetElementBundleName(&element, "com.huawei.testnative"); + SetElementAbilityName(&element, "SecondAbility"); + if (element.abilityName !=nullptr) { + SetWantElement(&want, element); + if (want.element->abilityName != nullptr) { + printf("deviceid is %s \n", want.element->deviceId); + printf("abilityName is %s \n", want.element->abilityName); + printf("bundleName is %s \n", want.element->bundleName); + EXPECT_STREQ(want.element->deviceId, "0001000"); + EXPECT_STREQ(want.element->abilityName, "SecondAbility"); + EXPECT_STREQ(want.element->bundleName, "com.huawei.testnative"); + } + } + ClearElement(&element); + ClearWant(&want); + printf("------end testSetWantElement------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_016 + * @tc.name : testSetWantElement parameter illegal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(AbilityMgrTest, testSetWantElementIllegal, TestSize.Level2) +{ + printf("------start testSetWantElementIllegal------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetWantElement(&want, element); + if (want.element->abilityName == nullptr) { + printf("deviceid is %s \n", want.element->deviceId); + printf("abilityName is %s \n", want.element->abilityName); + printf("bundleName is %s \n", want.element->bundleName); + EXPECT_STREQ(want.element->deviceId, nullptr); + EXPECT_STREQ(want.element->abilityName, nullptr); + EXPECT_STREQ(want.element->bundleName, nullptr); + } + ClearElement(&element); + ClearWant(&want); + printf("------end testSetWantElementIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_022 + * @tc.name : testClearWant parameter illegal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(AbilityMgrTest, testClearWantIllegal, TestSize.Level2) +{ + printf("------start testClearWantIllegal------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetElementAbilityName(&element, "SecondAbility"); + if (element.abilityName != nullptr) { + SetWantElement(&want, element); + if (want.element->abilityName != nullptr) { + printf("abilityName is %s \n", want.element->abilityName); + char aName[] = "SecondAbility"; + EXPECT_STREQ(want.element->abilityName, aName); + ClearWant(nullptr); + printf("AbilityName afterclear is %s \n", want.element->abilityName); + EXPECT_STREQ(want.element->abilityName, aName); + } + } + ClearElement(&element); + ClearWant(&want); + printf("------end testClearWantIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_025 + * @tc.name : testWantToUri parameter legal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(AbilityMgrTest, testWantToUri, TestSize.Level0) +{ + printf("------start testWantToUri------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetElementDeviceID(&element, "0001000"); + SetElementBundleName(&element, "com.huawei.testnative"); + SetElementAbilityName(&element, "SecondAbility"); + if (element.abilityName !=nullptr) { + SetWantElement(&want, element); + if (want.element->abilityName !=nullptr) { + printf("deviceid is %s \n", want.element->deviceId); + printf("abilityName is %s \n", want.element->abilityName); + printf("bundleName is %s \n", want.element->bundleName); + const char *uri = WantToUri(want); + printf("uri is %s \n", uri); + const char *expectResult = "#Want;device=0001000;bundle=com.huawei.testnative;ability=SecondAbility;end"; + EXPECT_STREQ(uri, expectResult); + free((void*)uri); + } + } + ClearElement(&element); + ClearWant(&want); + printf("------end testWantToUri------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_026 + * @tc.name : testWantToUri parameter illegal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(AbilityMgrTest, testWantToUriIllegal, TestSize.Level2) +{ + printf("------start testWantToUriIllegal------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + const char *uri = WantToUri(want); + printf("uri is %s \n", uri); + const char *expectResult = "#Want;device=;bundle=;ability=;end"; + EXPECT_STREQ(uri, expectResult); + if (uri != nullptr) { + free((void*)uri); + } + printf("------end testWantToUriIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_017 + * @tc.name : testSetWantDate parameter legal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(AbilityMgrTest, testSetWantDate, TestSize.Level0) +{ + printf("------start testSetWantDate------\n"); + Want want = { nullptr }; + SetWantData(&want, "test", 5); + if (want.data != nullptr) { + printf("data is %s \n", (char*)(want.data)); + printf("dataLength is %d \n", want.dataLength); + EXPECT_STREQ((char*)(want.data), "test"); + EXPECT_TRUE(want.dataLength == 5); + } + ClearWant(&want); + printf("------end testSetWantDate------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_018 + * @tc.name : testSetWantDate parameter illegal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(AbilityMgrTest, testSetWantDateIllegal, TestSize.Level2) +{ + printf("------start testSetWantDateIllegal------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetWantData(&want, "test", -1); + printf("dataLength is %d \n", want.dataLength); + EXPECT_STREQ((char*)(want.data), nullptr); + EXPECT_TRUE(want.dataLength == 0); + SetWantData(&want, nullptr, 0); + printf("dataLength is %d \n", want.dataLength); + EXPECT_STREQ((char*)(want.data), nullptr); + EXPECT_TRUE(want.dataLength == 0); + printf("------end testSetWantDateIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_023 + * @tc.name : testWantParseUri parameter legal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(AbilityMgrTest, testWantParseUri, TestSize.Level0) +{ + printf("------start testWantParseUri------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetElementDeviceID(&element, "0001000"); + SetElementBundleName(&element, "com.huawei.testnative"); + SetElementAbilityName(&element, "SecondAbility"); + if (element.abilityName != nullptr) { + SetWantElement(&want, element); + if (want.element->abilityName != nullptr) { + printf("deviceid is %s \n", want.element->deviceId); + printf("abilityName is %s \n", want.element->abilityName); + printf("bundleName is %s \n", want.element->bundleName); + const char *uri = WantToUri(want); + Want *want2 = WantParseUri(uri); + printf("uri is %s \n", uri); + if (uri != nullptr) { + free((void*)uri); + } + printf("want is %s \n", want2->element->deviceId); + EXPECT_STREQ(want2->element->deviceId, want.element->deviceId); + EXPECT_STREQ(want2->element->abilityName, want.element->abilityName); + EXPECT_STREQ(want2->element->bundleName, want.element->bundleName); + free(want2); + } + } + ClearElement(&element); + ClearWant(&want); + printf("------end testWantParseUri------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_024 + * @tc.name : testWantParseUri parameter illegal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(AbilityMgrTest, testWantParseUriIllegal, TestSize.Level2) +{ + printf("------start testWantParseUriIllegal------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetElementBundleName(&element, nullptr); + SetWantElement(&want, element); + const char *uri = WantToUri(want); + // empty + printf("uri is %s \n", uri); + Want *want2 = WantParseUri(uri); + if (uri != nullptr) { + free((void*)uri); + } + if (want2 != nullptr) { + printf("want is %s \n", want2->element->bundleName); + EXPECT_STREQ(want2->element->deviceId, ""); + EXPECT_STREQ(want2->element->abilityName, ""); + EXPECT_STREQ(want2->element->bundleName, ""); + free(want2); + } + // nullptr + Want *want4 = WantParseUri(nullptr); + printf("want4 is %p \n", want4); + EXPECT_TRUE(want4 == nullptr); + const char *str = "test"; + // error format + Want *want1 = WantParseUri(str); + printf("want is %p \n", want1); + EXPECT_TRUE(want1 == nullptr); + Want *want3 = WantParseUri(""); + printf("want is %p \n", want3); + EXPECT_TRUE(want3 == nullptr); + free(want1); + free(want3); + ClearElement(&element); + ClearWant(&want); + printf("------end testWantParseUriIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_030 + * @tc.name : testGetBundleNameIllegal parameter illegal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(AbilityMgrTest, testGetBundleNameIllegal, TestSize.Level1) +{ + printf("------start testGetBundleNameIllegal------\n"); + Want want; + memset_s(&want, sizeof(Want), 0, sizeof(Want)); + ElementName element; + memset_s(&element, sizeof(ElementName), 0, sizeof(ElementName)); + SetElementBundleName(&element, "com.huawei.testnative"); + SetElementAbilityName(&element, "ServiceAbility"); + SetWantElement(&want, element); + int result = StartAbility(&want); + sleep(2); + printf("ret is %d \n", result); + const char * bundleName1 = GetBundleName(); + printf("result of startAbility is %s \n", bundleName1); + EXPECT_STREQ(bundleName1, ""); + printf("------end testGetBundleNameIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_031 + * @tc.name : testGetSrcPathIllegal parameter illegal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(AbilityMgrTest, testGetSrcPathIllegal, TestSize.Level1) +{ + printf("------start testGetSrcPathIllegal------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetElementBundleName(&element, "com.huawei.testnative"); + SetElementAbilityName(&element, "ServiceAbility"); + SetWantElement(&want, element); + int result = StartAbility(&want); + sleep(2); + printf("ret is %d \n", result); + const char * srcPath = GetSrcPath(); + printf("result of startAbility is %s \n", srcPath); + EXPECT_STREQ(srcPath, ""); + printf("------end testGetSrcPathIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_032 + * @tc.name : testGetDataPath parameter illegal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(AbilityMgrTest, testGetDataPathIllegal, TestSize.Level1) +{ + printf("------start testGetDataPathIllegal------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetElementBundleName(&element, "com.huawei.testnative"); + SetElementAbilityName(&element, "ServiceAbility"); + SetWantElement(&want, element); + int result = StartAbility(&want); + sleep(2); + printf("ret is %d \n", result); + const char * dataPath = GetDataPath(); + printf("result of startAbility is %s \n", dataPath); + EXPECT_STREQ(dataPath, ""); + printf("------end testGetDataPathIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_019 + * @tc.name : testDump parameter illegal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(AbilityMgrTest, testDumpIllegal, TestSize.Level1) +{ + printf("------start testDump------\n"); + Want want; + memset_s(&want, sizeof(Want), 0, sizeof(Want)); + ElementName element; + memset_s(&element, sizeof(ElementName), 0, sizeof(ElementName)); + SetElementBundleName(&element, "com.huawei.testnative"); + SetElementAbilityName(&element, "ServiceAbility"); + SetWantElement(&want, element); + Ability *ability = new Ability(); + int result = ability->StartAbility(want); + sleep(3); + printf("ret is %d \n", result); + EXPECT_EQ(result, 0); + char *extra = (char*)"test"; + ability->Dump(extra); + printf("------end testDump------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_005 + * @tc.name : testStartAbilityIllegal parameter illegal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(AbilityMgrTest, testStartAbilityIllegal, TestSize.Level2) +{ + printf("------start testStartAbilityIllegal------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetElementBundleName(&element, "com.huawei.testnative"); + SetElementAbilityName(&element, "ServiceAbility"); + SetWantElement(&want, element); + int result = StartAbility(nullptr); + printf("ret is %d \n", result); + int expect = -1; + EXPECT_EQ(result, expect); + ClearElement(&element); + ClearWant(&want); + printf("------end testStartAbilityIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_007 + * @tc.name : testStopAbilityIllegal parameter illegal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(AbilityMgrTest, testStopAbilityIllegal, TestSize.Level2) +{ + printf("------start testStopAbilityIllegal------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetElementBundleName(&element, "com.huawei.testnative"); + SetElementAbilityName(&element, "ServiceAbility"); + SetWantElement(&want, element); + g_errorCode = StartAbility(&want); + printf("ret is %d \n", g_errorCode); + EXPECT_EQ(g_errorCode, 0); + g_errorCode = StopAbility(nullptr); + printf("ret of stop is %d \n", g_errorCode); + EXPECT_EQ(g_errorCode, -1); + printf("------end testStopAbilityIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_008 + * @tc.name : testConnectAbiltiy parameter legal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(AbilityMgrTest, testConnectAbiltiy, TestSize.Level1) +{ + printf("------start testConnectAbiltiy------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetElementBundleName(&element, "com.huawei.testnative"); + SetElementAbilityName(&element, "ServiceAbility"); + SetWantElement(&want, element); + sem_init(&g_sem, 0, 0); + g_errorCode = ConnectAbility(&want, &g_conn, this); + struct timespec ts = {}; + clock_gettime(CLOCK_REALTIME, &ts); + ts.tv_sec += WAIT_TIMEOUT; + sem_timedwait(&g_sem, &ts); + printf("sem exit \n"); + printf("ret is %d \n ", g_errorCode); + EXPECT_EQ(g_errorCode, 0); + ClearElement(&element); + ClearWant(&want); + printf("------end testConnectAbiltiy------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_009 + * @tc.name : testConnectAbiltiyIllegal parameter illegal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(AbilityMgrTest, testConnectAbiltiyIllegal, TestSize.Level1) +{ + printf("------start testConnectAbiltiyIllegal------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetElementBundleName(&element, "com.huawei.testnative"); + SetElementAbilityName(&element, "ServiceAbility"); + SetWantElement(&want, element); + g_errorCode = ConnectAbility(nullptr, &g_conn, this); + printf("ret1 is %d \n ", g_errorCode); + EXPECT_EQ(g_errorCode, -1); + g_errorCode = ConnectAbility(&want, nullptr, this); + printf("ret2 is %d \n ", g_errorCode); + EXPECT_EQ(g_errorCode, -1); + ClearElement(&element); + ClearWant(&want); + printf("------end testConnectAbiltiyIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_011 + * @tc.name : testDisConnectAbiltiyIllegal parameter illegal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(AbilityMgrTest, testDisConnectAbiltiyIllegal, TestSize.Level1) +{ + printf("------start testDisConnectAbiltiyIllegal------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetElementBundleName(&element, "com.huawei.testnative"); + SetElementAbilityName(&element, "ServiceAbility"); + SetWantElement(&want, element); + sem_init(&g_sem, 0, 0); + g_errorCode = ConnectAbility(&want, &g_conn, this); + struct timespec ts = {}; + clock_gettime(CLOCK_REALTIME, &ts); + ts.tv_sec += WAIT_TIMEOUT; + sem_timedwait(&g_sem, &ts); + printf("sem exit \n"); + printf("ret is of connect is %d \n ", g_errorCode); + EXPECT_EQ(g_errorCode, 0); + g_errorCode = DisconnectAbility(nullptr); + int expect = -10; + EXPECT_EQ(g_errorCode, expect); + printf("ret of disconnect is %d \n ", g_errorCode); + ClearElement(&element); + ClearWant(&want); + printf("------end testDisConnectAbiltiyIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_012 + * @tc.name : testTerminateAbility parameter legal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(AbilityMgrTest, testTerminateAbility, TestSize.Level1) +{ + printf("------start testTerminateAbility------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetElementBundleName(&element, "com.huawei.testnative"); + SetElementAbilityName(&element, "SecondAbility"); + SetWantElement(&want, element); + int result1 = StartAbility(&want); + sleep(5); + printf("result1 of startAbility is %d \n", result1); + EXPECT_EQ(result1, 0); + Ability *ability = new Ability(); + int result2 = ability->TerminateAbility(); + sleep(5); + printf("result2 of TerminateAbility is %d \n", result2); + EXPECT_EQ(result2, 0); + ClearElement(&element); + ClearWant(&want); + delete ability; + printf("------end testTerminateAbility------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_WANT_004 + * @tc.name : test Want Not Match BundleInfo + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(AbilityMgrTest, testWantNotMathBundle, TestSize.Level2) +{ + printf("------start testWantNotMathBundle------\n"); + Want want; + memset_s(&want, sizeof(Want), 0, sizeof(Want)); + ElementName element; + char aName[] = "NoThisAbility"; + memset_s(&element, sizeof(ElementName), 0, sizeof(ElementName)); + SetElementAbilityName(&element, aName); + SetElementBundleName(&element, "com.huawei.nothishap"); + SetWantElement(&want, element); + AbilityInfo abilityInfo; + memset_s(&abilityInfo, sizeof(AbilityInfo), 0, sizeof(AbilityInfo)); + g_errorCode = QueryAbilityInfo(&want, &abilityInfo); + printf("ret is %d \n", g_errorCode); + EXPECT_TRUE(g_errorCode != 0); + int result = StartAbility(&want); + sleep(2); + printf("result of startAbility is %d \n", result); + EXPECT_TRUE(result == 0); + printf("element is %s \n", want.element->bundleName); + printf("------end testWantNotMathBundle------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_WANT_002 + * @tc.name : testWantOnlyMathBundle + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(AbilityMgrTest, testWantOnlyMathBundleName, TestSize.Level1) +{ + printf("------start testWantOnlyMathBundleName------\n"); + Want want; + memset_s(&want, sizeof(Want), 0, sizeof(Want)); + ElementName element; + char aName[] = "Ability"; + memset_s(&element, sizeof(ElementName), 0, sizeof(ElementName)); + SetElementAbilityName(&element, aName); + SetElementBundleName(&element, "com.huawei.testnative"); + SetWantElement(&want, element); + AbilityInfo abilityInfo; + memset_s(&abilityInfo, sizeof(AbilityInfo), 0, sizeof(AbilityInfo)); + g_errorCode = QueryAbilityInfo(&want, &abilityInfo); + printf("ret is %d \n", g_errorCode); + EXPECT_TRUE(g_errorCode != 0); + int result = StartAbility(&want); + sleep(2); + printf("result of startAbility is %d \n", result); + EXPECT_TRUE(result == 0); + printf("element is %s \n", want.element->bundleName); + printf("------end testWantOnlyMathBundleName------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_WANT_003 + * @tc.name : testWantOnlyMathAbility + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(AbilityMgrTest, testWantOnlyMathAbility, TestSize.Level1) +{ + printf("------start testWantOnlyMathAbility------\n"); + Want want; + memset_s(&want, sizeof(Want), 0, sizeof(Want)); + ElementName element; + char aName[] = "MainAbility"; + memset_s(&element, sizeof(ElementName), 0, sizeof(ElementName)); + SetElementAbilityName(&element, aName); + SetElementBundleName(&element, "com.huawei.test"); + SetWantElement(&want, element); + AbilityInfo abilityInfo; + memset_s(&abilityInfo, sizeof(AbilityInfo), 0, sizeof(AbilityInfo)); + g_errorCode = QueryAbilityInfo(&want, &abilityInfo); + printf("ret is %d \n", g_errorCode); + EXPECT_TRUE(g_errorCode != 0); + int result = StartAbility(&want); + sleep(2); + printf("result of startAbility is %d \n", result); + EXPECT_TRUE(result == 0); + printf("element is %s \n", want.element->abilityName); + printf("------end testWantOnlyMathAbility------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_WANT_006 + * @tc.name : test WantData Not Match DataLength + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(AbilityMgrTest, testWantDataNotMatchLength, TestSize.Level2) +{ + printf("------start testWantDataNotMatchLength------\n"); + Want want; + memset_s(&want, sizeof(Want), 0, sizeof(Want)); + ElementName element; + memset_s(&element, sizeof(ElementName), 0, sizeof(ElementName)); + SetElementAbilityName(&element, "SecondAbility"); + SetElementBundleName(&element, "com.huawei.testnative"); + SetWantElement(&want, element); + SetWantData(&want, "test", 3); + int result = StartAbility(&want); + sleep(2); + printf("result of startAbility is %d \n", result); + EXPECT_TRUE(result == 0); + EXPECT_EQ(want.dataLength, 3); + printf("------end testWantDataNotMatchLength------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_40 + * @tc.name : PostTask parameter illegal test that callback is null + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(AbilityMgrTest, testPostTask, TestSize.Level1) +{ + printf("------start testPostTask------\n"); + const char *hapPath = (char*)"testnative.hap"; + AbilityEventHandler eventHandler1; + auto task = [this, hapPath]{ + sem_init(&g_sem, 0, 0); + bool installResult = Install(hapPath, nullptr, TestBundleStateCallback); + sem_wait(&g_sem); + printf("installResult is %d \n", installResult); + EXPECT_TRUE(installResult); + + AbilityEventHandler *eventHandler2 = AbilityEventHandler::GetCurrentHandler(); + eventHandler2->PostQuit(); + }; + eventHandler1.PostTask(task); + eventHandler1.Run(); + printf("------end testPostTask------\n"); +} diff --git a/appexecfwk_lite/bundlems_posix/BUILD.gn b/appexecfwk_lite/bundlems_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..ea737ae0db14f09e3c545aedb1f9329ab099f9a0 --- /dev/null +++ b/appexecfwk_lite/bundlems_posix/BUILD.gn @@ -0,0 +1,53 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsBundleMgrTest") { + suite_name = "acts" + sources = [ + "src/BundleMgrTest.cpp" + ] + + include_dirs = [ + "src", + "//foundation/aafwk/interfaces/innerkits/abilitymgr_lite", + "//foundation/aafwk/interfaces/kits/ability_lite", + "//foundation/aafwk/interfaces/kits/want_lite", + "//foundation/aafwk/services/abilitymgr_lite/include", + "//foundation/appexecfwk/interfaces/kits/bundle_lite/", + "//foundation/appexecfwk/utils/bundle_lite", + "//foundation/appexecfwk/interfaces/innerkits/bundlemgr_lite/", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/samgr", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/registry", + "//third_party/googletest/googletest/include", + "//utils/native/lite/include", + "//foundation/aafwk/interfaces/innerkits/intent_lite", + "//kernel/liteos_a/kernel/include", + "//kernel/liteos_a/kernel/common", + "//third_party/cJSON", + ] + ldflags = [ + "-lstdc++", + + ] + deps = [ + "//base/hiviewdfx/frameworks/hilog_lite/featured:hilog_shared", + "//foundation/appexecfwk/frameworks/bundle_lite:bundle", + "//foundation/communication/frameworks/ipc_lite:liteipc_adapter", + "//foundation/distributedschedule/services/samgr_lite/samgr:samgr", + ] + + cflags = [ "-Wno-error" ] + defines = ["OHOS_APPEXECFWK_BMS_BUNDLEMANAGER"] +} diff --git a/appexecfwk_lite/bundlems_posix/Test.json b/appexecfwk_lite/bundlems_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..5374f0aada90fe06d12765b2d60ee833f38ac358 --- /dev/null +++ b/appexecfwk_lite/bundlems_posix/Test.json @@ -0,0 +1,28 @@ +{ + "description": "Config for bundlemgr test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/appexecfwk", + "target": "/test_root/appexecfwk" + },{ + "source": "resource/appexecfwk", + "target": "/test_root/appexecfwk" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/appexecfwk/ActsBundleMgrTest.bin" + } +} \ No newline at end of file diff --git a/appexecfwk_lite/bundlems_posix/src/BundleMgrTest.cpp b/appexecfwk_lite/bundlems_posix/src/BundleMgrTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..9501a41a2596feb67b43cd4fde523426c7935e5d --- /dev/null +++ b/appexecfwk_lite/bundlems_posix/src/BundleMgrTest.cpp @@ -0,0 +1,723 @@ +/** + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "securec.h" +#include "bundle_info.h" +#include "bundle_manager.h" +#include "want.h" + +using namespace std; +using namespace testing::ext; +using namespace OHOS; +static bool g_installState = false; +static int g_errorCode = -1; +static sem_t g_sem; +static const int32_t WAIT_TIMEOUT = 60; + +extern "C" { +void __attribute__((weak)) HOS_SystemInit(void){}; +} + +/* callback */ +static void TestBundleStateCallback(const uint8_t resultCode, const void *resultMessage) +{ + HILOG_DEBUG(HILOG_MODULE_APP, "TestBundleStateCallback resultCode: %d", resultCode); + HILOG_DEBUG(HILOG_MODULE_APP, "TestBundleStateCallback resultMessage: %s", (char *) resultMessage); + if (resultCode == 0) { + g_installState = true; + g_errorCode = resultCode; + } else { + g_installState = false; + g_errorCode = resultCode; + } + sem_post(&g_sem); +} + +class BundleMgrTest : public testing::Test { +protected: + static void SetUpTestCase(void) + { + printf("----------test case with BundleMgrTest start-------------\n"); + HOS_SystemInit(); + sem_init(&g_sem, 0, 0); + bool installResult = Install("/test_root/appexecfwk/testjsdemo.hap", nullptr, TestBundleStateCallback); + sem_wait(&g_sem); + EXPECT_TRUE(installResult); + } + static void TearDownTestCase(void) + { + sem_init(&g_sem, 0, 0); + bool uninstallState = Uninstall("com.huawei.testjsdemo", nullptr, TestBundleStateCallback); + sem_wait(&g_sem); + EXPECT_TRUE(uninstallState); + printf("----------test case with BundleMgrTest end-------------\n"); + } +}; + + +/** + * @tc.number : SUB_APPEXECFWK_BMS_API_044 + * @tc.name : ClearAbilityInfo parameter illegal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(BundleMgrTest, testClearAbilityInfoIllegal, TestSize.Level2) +{ + printf("------start testClearAbilityInfoIllegal------\n"); + // abilityInfo is nullptr + AbilityInfo abilityInfo; + memset_s(&abilityInfo, sizeof(abilityInfo), 0, sizeof(abilityInfo)); + abilityInfo.bundleName = (char*)"com.huawei.testjsdemo"; + printf("abilityInfo.bundleName is %s \n", abilityInfo.bundleName); + ClearAbilityInfo(nullptr); + EXPECT_STREQ(abilityInfo.bundleName, "com.huawei.testjsdemo"); + printf("------end testClearAbilityInfoIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_BMS_API_045 + * @tc.name : ClearAbilityInfo parameter legal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(BundleMgrTest, testClearBundleInfoIllegal, TestSize.Level2) +{ + printf("------start testClearBundleInfoIllegal------\n"); + BundleInfo bundleInfo; + memset_s(&bundleInfo, sizeof(bundleInfo), 0, sizeof(bundleInfo)); + bundleInfo.bundleName = (char*)"com.huawei.testjsdemo"; + printf("abilityInfo.bundleName is %s \n", bundleInfo.bundleName); + ClearBundleInfo(nullptr); + printf("abilityInfo.bundleName afterclear is %s \n", bundleInfo.bundleName); + EXPECT_STREQ(bundleInfo.bundleName, "com.huawei.testjsdemo"); + printf("------end testClearBundleInfoIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_BMS_API_046 + * @tc.name : ClearAbilityInfo parameter legal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(BundleMgrTest, testClearModuleInfoIllegal, TestSize.Level1) +{ + printf("------start testClearModuleInfoIllegal------\n"); + ModuleInfo moduleInfo; + memset_s(&moduleInfo, sizeof(moduleInfo), 0, sizeof(moduleInfo)); + moduleInfo.description = (char*)"test app"; + moduleInfo.moduleType = (char*)"entry"; + printf("mouduleInfo.description is %s \n", moduleInfo.description); + printf("mouduleInfo.moduleType is %s \n", moduleInfo.moduleType); + ClearModuleInfo(nullptr); + EXPECT_STREQ(moduleInfo.description, "test app"); + EXPECT_STREQ(moduleInfo.moduleType, "entry"); + printf("------end testClearModuleInfoIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_009 + * @tc.name : testAbilityMgrSetWantElement parameter legal test + * @tc.desc : [C- SOFTWARE -0100] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(BundleMgrTest, testSetElementAbilityName, TestSize.Level0) +{ + printf("------start testSetElementAbilityName------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetElementAbilityName(&element, "SecondAbility"); + SetWantElement(&want, element); + printf("element is %s \n", want.element->abilityName); + char aName[] = "SecondAbility"; + printf("aName is %s \n", aName); + EXPECT_STREQ(want.element->abilityName, aName); + ClearElement(&element); + ClearWant(&want); + printf("------end testSetElementAbilityName------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_010 + * @tc.name : testSetElementAbilityName parameter illegal test + * @tc.desc : [C- SOFTWARE -0100] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 3 + */ +HWTEST_F(BundleMgrTest, testSetElementAbilityNameIllegal, TestSize.Level2) +{ + printf("------start testSetElementAbilityNameIllegal------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetElementAbilityName(&element, nullptr); + SetWantElement(&want, element); + printf("AbilityName1 is %s \n", want.element->abilityName); + EXPECT_STREQ(want.element->abilityName, nullptr); + char aName[] = ""; + SetElementAbilityName(&element, aName); + SetWantElement(&want, element); + printf("AbilityName2 is %s \n", want.element->abilityName); + EXPECT_STREQ(want.element->abilityName, ""); + ClearElement(&element); + ClearWant(&want); + printf("------end testSetElementAbilityNameIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_007 + * @tc.name : testSetElementBundleName parameter legal test + * @tc.desc : [C- SOFTWARE -0100] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(BundleMgrTest, testSetElementBundleName, TestSize.Level0) +{ + printf("------start testSetElementBundleName------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetElementBundleName(&element, "com.huawei.testjsdemo"); + SetWantElement(&want, element); + printf("element is %s \n", want.element->bundleName); + char bName[] = "com.huawei.testjsdemo"; + EXPECT_STREQ(want.element->bundleName, bName); + ClearElement(&element); + ClearWant(&want); + printf("------end testSetElementBundleName------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_008 + * @tc.name : testAbilityMgrSetWantElement parameter illegal test + * @tc.desc : [C- SOFTWARE -0100] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(BundleMgrTest, testSetElementBundleNameIllegal, TestSize.Level2) +{ + printf("------start testSetElementBundleNameIllegal------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetElementBundleName(&element, ""); + SetWantElement(&want, element); + printf("BundleName1 is %s \n", want.element->bundleName); + char bName[] = ""; + EXPECT_STREQ(want.element->bundleName, bName); + SetElementBundleName(&element, nullptr); + SetWantElement(&want, element); + printf("BundleName2 is %s \n", want.element->bundleName); + EXPECT_STREQ(want.element->bundleName, nullptr); + ClearElement(&element); + ClearWant(&want); + printf("------end testSetElementBundleNameIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_005 + * @tc.name : testSetElementDeviceID parameter legal test + * @tc.desc : [C- SOFTWARE -0100] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(BundleMgrTest, testSetElementDeviceID, TestSize.Level0) +{ + printf("------start testSetElementDeviceID------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetElementDeviceID(&element, "0001000"); + SetWantElement(&want, element); + printf("element is %s \n", want.element->deviceId); + char dID[] = "0001000"; + EXPECT_STREQ(want.element->deviceId, dID); + ClearElement(&element); + ClearWant(&want); + printf("------end testSetElementDeviceID------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_AMS_API_006 + * @tc.name : testSetElementDeviceID parameter illegal test + * @tc.desc : [C- SOFTWARE -0100] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(BundleMgrTest, testSetElementDeviceIDIllegal, TestSize.Level2) +{ + printf("------start testSetElementDeviceIDIllegal------\n"); + Want want = { nullptr }; + ElementName element = { nullptr }; + SetElementDeviceID(&element, ""); + SetWantElement(&want, element); + printf("element is %s \n", want.element->deviceId); + char dID[] = ""; + EXPECT_STREQ(want.element->deviceId, dID); + SetElementDeviceID(&element, nullptr); + SetWantElement(&want, element); + printf("element is %s \n", want.element->deviceId); + EXPECT_STREQ(want.element->deviceId, nullptr); + ClearElement(&element); + ClearWant(&want); + printf("------end testSetElementDeviceIDIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_BMS_API_007 + * @tc.name : Install parameter illegal test that callback is null + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(BundleMgrTest, testInstallWithNullptr, TestSize.Level2) +{ + printf("------start testInstallWithNullptr------\n"); + string hapPath = "/test_root/appexecfwk/testnative.hap"; + bool isInstallSuccess = Install(hapPath.c_str(), nullptr, nullptr); + EXPECT_FALSE(isInstallSuccess); + printf("install result is %d \n", isInstallSuccess); + printf("------end testInstallWithNullptr------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_BMS_API_004 + * @tc.name : Install parameter illegal test that path is null + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(BundleMgrTest, testInstallWithNullPath, TestSize.Level2) +{ + printf("------start testInstallWithNullPath------\n"); + bool isInstallSuccess = Install(nullptr, nullptr, TestBundleStateCallback); + EXPECT_FALSE(isInstallSuccess); + printf("install result is %d \n", isInstallSuccess); + printf("------end testInstallWithNullPath------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_BMS_API_002 + * @tc.name : Install parameter illegal test that ErrorPath is wrong + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(BundleMgrTest, testInstallWithErrorPath, TestSize.Level2) +{ + printf("------start testBundleMgrInstallWithErrorPath------\n"); + string hapPath = "/test_root/appexecfwk/nothishap.hap"; + bool isInstallSuccess = false; + sem_init(&g_sem, 0, 0); + bool installResult = Install(hapPath.c_str(), nullptr, TestBundleStateCallback); + sem_wait(&g_sem); + if (g_errorCode == 0) { + isInstallSuccess = true; + }else if (g_errorCode > 0) { + isInstallSuccess = false; + HILOG_DEBUG(HILOG_MODULE_APP, "TestBundleMgrInstall failed,g_errorCode is: %d", g_errorCode); + } + EXPECT_FALSE(isInstallSuccess); + printf("install result is %d", installResult); + printf("------end testBundleMgrInstallWithErrorPath------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_BMS_API_003 + * @tc.name : Install parameter illegal test that Path is empty + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(BundleMgrTest, testBundleMgrInstallEmpty, TestSize.Level2) +{ + printf("------start testBundleMgrInstallEmpty------\n"); + string hapPath = ""; + bool isInstallSuccess = false; + sem_init(&g_sem, 0, 0); + bool installResult = Install(hapPath.c_str(), nullptr, TestBundleStateCallback); + sem_wait(&g_sem); + if (g_errorCode == 0) { + isInstallSuccess = true; + }else if (g_errorCode > 0) { + isInstallSuccess = false; + HILOG_DEBUG(HILOG_MODULE_APP, "TestBundleMgrInstall failed,g_errorCode is: %d", g_errorCode); + } + EXPECT_FALSE(isInstallSuccess); + printf("install result is %d", installResult); + printf("------end testBundleMgrInstallEmpty------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_BMS_API_009 + * @tc.name : Install parameter illegal test that file is *.bin + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(BundleMgrTest, testBundleMgrInstallBin, TestSize.Level1) +{ + printf("------start testBundleMgrInstallBin------\n"); + string hapPath = "/test_root/appexecfwk/testdemo.bin"; + bool isInstallSuccess = false; + sem_init(&g_sem, 0, 0); + bool installResult = Install(hapPath.c_str(), nullptr, TestBundleStateCallback); + sem_wait(&g_sem); + if (g_errorCode == 0) { + isInstallSuccess = true; + }else if (g_errorCode > 0) { + isInstallSuccess = false; + HILOG_DEBUG(HILOG_MODULE_APP, "TestBundleMgrInstall failed,g_errorCode is: %d", g_errorCode); + } + EXPECT_FALSE(isInstallSuccess); + printf("install result is %d", installResult); + printf("------end testBundleMgrInstallBin------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_BMS_API_014 + * @tc.name : Uninstall parameter illegal test that callback is null + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(BundleMgrTest, testUninstallNullCallback, TestSize.Level2) +{ + printf("------start testUninstallNullCallback------\n"); + const char *bundleName = (char*)"com.huawei.testdemo"; + bool isUninstallSuccess = Uninstall(bundleName, nullptr, nullptr); + EXPECT_FALSE(isUninstallSuccess); + printf("uninstall result is %d", isUninstallSuccess); + printf("------end testUninstallNullCallback------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_BMS_API_013 + * @tc.name : Uninstall parameter illegal test that bundleName is null + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(BundleMgrTest, testUninstallnullBundleName, TestSize.Level2) +{ + printf("------start testUninstallnullBundleName------\n"); + const char *bundleName = (char*)"com.huawei.testnative"; + bool isUninstallSuccess = Uninstall(nullptr, nullptr, TestBundleStateCallback); + EXPECT_FALSE(isUninstallSuccess); + printf("uninstall result is %d", isUninstallSuccess); + printf("------end testUninstallnullBundleName------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_BMS_API_010 + * @tc.name : Uninstall parameter legal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(BundleMgrTest, testUninstallright, TestSize.Level0) +{ + printf("------start testUninstallright------\n"); + string hapPath = "/test_root/appexecfwk/testnative.hap"; + sem_init(&g_sem, 0, 0); + bool installResult = Install(hapPath.c_str(), nullptr, TestBundleStateCallback); + sem_wait(&g_sem); + EXPECT_TRUE(installResult); + sleep(1); + const char *bundleName = (char*)"com.huawei.testnative"; + bool isUninstallSuccess = false; + sem_init(&g_sem, 0, 0); + bool uninstallState = Uninstall(bundleName, nullptr, TestBundleStateCallback); + sem_wait(&g_sem); + printf("uninstall result is %d", uninstallState); + if (g_installState) { + isUninstallSuccess = true; + }else if (g_errorCode > 0) { + isUninstallSuccess = false; + HILOG_DEBUG(HILOG_MODULE_APP, "TestBundleMgrUninstall failed,g_errorCode is: %d", g_errorCode); + } + EXPECT_TRUE(uninstallState); + printf("uninstall result is %d", isUninstallSuccess); + printf("------end testUninstallright------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_BMS_API_011 + * @tc.name : Uninstall parameter illegal test that bundleName is wrong + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(BundleMgrTest, testUninstallErrorName, TestSize.Level2) +{ + printf("------start testUninstallErrorName------\n"); + const char *bundleName = (char*)"com.huawei.nothisBundleName"; + bool isUninstallSuccess = false; + sem_init(&g_sem, 0, 0); + bool uninstallState = Uninstall(bundleName, nullptr, TestBundleStateCallback); + sem_wait(&g_sem); + printf("uninstall resute is %d", uninstallState); + if (g_installState) { + isUninstallSuccess = true; + }else if (g_errorCode > 0) { + isUninstallSuccess = false; + HILOG_DEBUG(HILOG_MODULE_APP, "TestBundleMgrUninstall failed,g_errorCode is: %d", g_errorCode); + } + EXPECT_FALSE(isUninstallSuccess); + printf("uninstall result is %d", isUninstallSuccess); + printf("------end testUninstallErrorName------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_BMS_API_012 + * @tc.name : Uninstall parameter illegal test that bundleName is empty + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(BundleMgrTest, testUninstallEmptyName, TestSize.Level2) +{ + printf("------start testUninstallEmptyName------\n"); + const char *bundleName = (char*)""; + bool isUninstallSuccess = false; + sem_init(&g_sem, 0, 0); + bool uninstallState = Uninstall(bundleName, nullptr, TestBundleStateCallback); + sem_wait(&g_sem); + printf("uninstall resute is %d", uninstallState); + if (g_installState) { + isUninstallSuccess = true; + }else if (g_errorCode > 0) { + isUninstallSuccess = false; + HILOG_DEBUG(HILOG_MODULE_APP, "TestBundleMgrUninstall failed,g_errorCode is: %d", g_errorCode); + } + EXPECT_FALSE(isUninstallSuccess); + printf("uninstall result is %d", isUninstallSuccess); + printf("------end testUninstallEmptyName------\n"); +} + + +/** + * @tc.number : SUB_APPEXECFWK_BMS_API_041 + * @tc.name : QueryAbilityInfo parameter illegal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(BundleMgrTest, testQueryAbilityInfoIllegal, TestSize.Level2) +{ + printf("------start testQueryAbilityInfoIllegal------\n"); + AbilityInfo abilityInfo; + memset_s(&abilityInfo, sizeof(AbilityInfo), 0, sizeof(AbilityInfo)); + // want is nullptr + g_errorCode = QueryAbilityInfo(nullptr, &abilityInfo); + printf("ret is %d \n", g_errorCode); + EXPECT_TRUE(g_errorCode == 4); + // abilityInfo is nullptr + Want want; + memset_s(&want, sizeof(Want), 0, sizeof(Want)); + ElementName element; + memset_s(&element, sizeof(ElementName), 0, sizeof(ElementName)); + SetElementAbilityName(&element, "MainAbility"); + SetElementBundleName(&element, "com.huawei.testjsdemo"); + SetWantElement(&want, element); + SetWantData(&want, "test", 4); + g_errorCode = QueryAbilityInfo(&want, nullptr); + printf("ret is %d \n", g_errorCode); + EXPECT_TRUE(g_errorCode == 4); + // content of want is "" + Want want1 = { nullptr }; + ElementName element1 = { nullptr }; + SetElementBundleName(&element1, ""); + SetElementAbilityName(&element1, ""); + SetWantElement(&want1, element1); + AbilityInfo abilityInfo1; + g_errorCode = QueryAbilityInfo(&want1, &abilityInfo1); + printf("abilityInfo is null \n"); + printf("ret is %d \n", g_errorCode); + EXPECT_TRUE(g_errorCode == 2); + printf("------end testQueryAbilityInfoIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_BMS_API_030 + * @tc.name : GetBundleInfo parameter illegal test. + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(BundleMgrTest, testGetBundleInfoIllegal, TestSize.Level2) +{ + printf("------start testGetBundleInfoIllegal------\n"); + BundleInfo bundleInfo; + memset_s(&bundleInfo, sizeof(bundleInfo), 0, sizeof(bundleInfo)); + const char *bundleName = (char*)"com.huawei.nothishap"; + int32_t flags = 0; + // error bundleName + g_errorCode = GetBundleInfo(bundleName, flags, &bundleInfo); + printf("bundleInfo1.bundleName is %s \n", bundleInfo.bundleName); + printf("bundleInfo1.versionCode is %d \n", bundleInfo.versionCode); + printf("bundleInfo1.codePath is %s \n", bundleInfo.codePath); + EXPECT_EQ(g_errorCode, 2); + // bundleName = nullptr + g_errorCode = GetBundleInfo(nullptr, flags, &bundleInfo); + printf("abilityInfo2 is %d \n", g_errorCode); + EXPECT_TRUE(g_errorCode == 4); + printf("bundleInfo2.bundleName is %s \n", bundleInfo.bundleName); + printf("bundleInfo2.versionCode is %d \n", bundleInfo.versionCode); + printf("bundleInfo2.codePath is %s \n", bundleInfo.codePath); + // bunldeName = "" + g_errorCode = GetBundleInfo("", flags, &bundleInfo); + printf("bundleInfo3.bundleName is %s \n", bundleInfo.bundleName); + printf("bundleInfo3.versionCode is %d \n", bundleInfo.versionCode); + printf("bundleInfo3.codePath is %s \n", bundleInfo.codePath); + EXPECT_TRUE(g_errorCode == 2); + // flags not exit + g_errorCode = GetBundleInfo("com.huawei.testjsdemo", 2, &bundleInfo); + sleep(2); + printf("bundleInfo3.bundleName is %s \n", bundleInfo.bundleName); + printf("bundleInfo3.versionCode is %d \n", bundleInfo.versionCode); + printf("bundleInfo3.codePath is %s \n", bundleInfo.codePath); + EXPECT_EQ(g_errorCode, 1); + printf("------end testGetBundleInfoIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_BMS_API_043 + * @tc.name : GetBundleInfos parameter illegal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(BundleMgrTest, testGetBundleInfosIllegal, TestSize.Level2) +{ + printf("------start testGetBundleInfosIllegal------\n"); + BundleInfo *bundleInfos = {nullptr}; + int32_t *length = nullptr; + const char *bundleName = (char*)"com.huawei.nothishap"; + int32_t flags = 0; + g_errorCode = GetBundleInfos(flags, nullptr, length); + printf("bundleInfos1 is %x \n", bundleInfos); + EXPECT_EQ(g_errorCode, 4); + g_errorCode = GetBundleInfos(flags, &bundleInfos, nullptr); + printf("g_errorCode is %d \n", g_errorCode); + EXPECT_TRUE(g_errorCode == 4); + printf("bundleInfos2 is %x \n", bundleInfos); + g_errorCode = GetBundleInfos(2, &bundleInfos, length); + printf("g_errorCode is %d \n", g_errorCode); + EXPECT_EQ(g_errorCode, 4); + printf("------end testGetBundleInfosIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_BMS_API_039 + * @tc.name : GetBundleInfosByMetaData parameter illegal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(BundleMgrTest, testGetBundleInfosByMetaDataIllegal, TestSize.Level2) +{ + printf("------start testGetBundleInfosByMetaDataIllegal------\n"); + BundleInfo *bundleInfos = {nullptr}; + int32_t length = 0; + const char *metaDataKey = "appId"; + g_errorCode = GetBundleInfosByMetaData(nullptr, &bundleInfos, &length); + printf("bundleInfos1 is %x \n", bundleInfos); + EXPECT_EQ(g_errorCode, 4); + g_errorCode = GetBundleInfosByMetaData(metaDataKey, &bundleInfos, nullptr); + printf("g_errorCode is %d \n", g_errorCode); + EXPECT_TRUE(g_errorCode == 4); + printf("bundleInfos2 is %x \n", bundleInfos); + g_errorCode = GetBundleInfosByMetaData(metaDataKey, nullptr, &length); + printf("g_errorCode is %d \n", g_errorCode); + EXPECT_TRUE(g_errorCode == 4); + const char *metaDataKey1 = "noThisKey"; + printf("metaDataKey is %s \n", metaDataKey1); + g_errorCode = GetBundleInfosByMetaData(metaDataKey1, &bundleInfos, &length); + printf("GetBundleInfosByMetaData result is %d \n", g_errorCode); + EXPECT_EQ(g_errorCode, 2); + const char *metaDataKey2 = ""; + g_errorCode = GetBundleInfosByMetaData(metaDataKey2, &bundleInfos, &length); + printf("GetBundleInfosByMetaData result is %d \n", g_errorCode); + EXPECT_EQ(g_errorCode, 2); + printf("------end testGetBundleInfosByMetaDataIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_BMS_API_037 + * @tc.name : QueryKeepAliveBundleInfos parameter illegal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(BundleMgrTest, testQueryKeepAliveBundleInfosIllegal, TestSize.Level2) +{ + printf("------start testQueryKeepAliveBundleInfosIllegal------\n"); + BundleInfo *bundleInfos = {nullptr}; + int32_t length = 0; + const char *metaDataKey = "appId"; + g_errorCode = QueryKeepAliveBundleInfos(nullptr, &length); + printf("g_errorCode1 is %d \n", g_errorCode); + EXPECT_EQ(g_errorCode, 4); + g_errorCode = QueryKeepAliveBundleInfos(&bundleInfos, nullptr); + printf("g_errorCode2 is %d \n", g_errorCode); + EXPECT_TRUE(g_errorCode == 4); + printf("------end testQueryKeepAliveBundleInfosIllegal------\n"); +} + +/** + * @tc.number : SUB_APPEXECFWK_BMS_API_034 + * @tc.name : GetBundleNameForUid parameter nullptr test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(BundleMgrTest, testGetBundleNameForUidWithNullptr, TestSize.Level2) +{ + printf("------start testGetBundleNameForUidWithNullptr------\n"); + int32_t resultCode = GetBundleNameForUid(0, nullptr); + EXPECT_EQ(resultCode, 4); + printf("GetBundleNameForUid result is %d \n", resultCode); + printf("------end testGetBundleNameForUidWithNullptr------\n"); +} diff --git a/communication_lite/lwip_hal/BUILD.gn b/communication_lite/lwip_hal/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..b78a93502455285968be52c28ef82bc912334357 --- /dev/null +++ b/communication_lite/lwip_hal/BUILD.gn @@ -0,0 +1,29 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") +hctest_suite("ActsLwipTest") { + suite_name = "acts" + + sources = [ + "src/lwip_func_test.c", + ] + + include_dirs = [ + "//vendor/hisi/hi3861/hi3861/third_party/lwip_sack/include", + "//kernel/liteos_m/components/cmsis", + "//kernel/liteos_m/components/cmsis/2.0", + ] + + cflags = ["-Wno-error"] +} diff --git a/communication_lite/lwip_hal/Test.tmpl b/communication_lite/lwip_hal/Test.tmpl new file mode 100755 index 0000000000000000000000000000000000000000..be8407e1286041a5af2bdc75a15633337376eb9d --- /dev/null +++ b/communication_lite/lwip_hal/Test.tmpl @@ -0,0 +1,19 @@ +{ + "description": "Config for $module test cases", + "environment": [ + { + "type": "device", + "label": "wifiiot" + } + ], + "kits": [ + { + "type": "DeployKit", + "timeout": "20000", + "burn_file": "$subsystem/$module.bin" + } + ], + "driver": { + "type": "CTestLite" + } +} \ No newline at end of file diff --git a/communication_lite/lwip_hal/src/lwip_func_test.c b/communication_lite/lwip_hal/src/lwip_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..f8c6c3f2aa1cbcf634d38f9ea3b398e4d153771f --- /dev/null +++ b/communication_lite/lwip_hal/src/lwip_func_test.c @@ -0,0 +1,609 @@ +/* + * Copyright (c) 2020 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 "hctest.h" +#include "lwip/sockets.h" +#include "lwip/inet.h" +#include "lwip/tcp.h" +#include "securec.h" +#include "cmsis_os2.h" +#include +#include +#include +#include + +#define LOCAL_HOST "127.0.0.1" +#define STACK_PORT 2277 +#define STACK_IP LOCAL_HOST +#define PEER_PORT STACK_PORT +#define PEER_IP LOCAL_HOST +#define UDP_MSG "Hi, I am UDP" +#define SRV_MSG "Hi, I am TCP server" +#define CLI_MSG "Hi, I am TCP client" +#define BUF_SIZE (1024 * 8) +#define LWIP_TEST_SUCCESS 0 +#define LWIP_TEST_FAIL (-1) +#define DEF_TASK_STACK 2000 +#define DEF_TASK_PRIORITY 20 +#define ONE_SECOND 1 +#define TIMEOUT 4 + +static char g_buf[BUF_SIZE + 1] = {0}; +static int g_clientWait = 0; +static int g_clientWaitOver = 0; +static int g_serverWait = 0; +static int g_serverWaitOver = 0; +static int g_clientResult = 0; +static int g_serverResult = 0; + +static void waitClient(void) +{ + while (1) { + sleep(ONE_SECOND); + if (g_clientWait) { + break; + } + } + g_clientWaitOver = 1; + g_clientWait = 0; +} + +static void waitServer(void) +{ + while (1) { + sleep(ONE_SECOND); + if (g_serverWait) { + break; + } + } + g_serverWaitOver = 1; + g_serverWait = 0; +} + +static void SampleTcpServerTask(void) +{ + int ret; + int sfd = -1; + int lsfd = -1; + struct msghdr msg = {0}; + struct iovec iov[2] = {}; + struct sockaddr_in srvAddr = {0}; + struct sockaddr_in clnAddr = {0}; + socklen_t clnAddrLen = sizeof(clnAddr); + static char buf[BUF_SIZE + 1] = {0}; + + lsfd = socket(AF_INET, SOCK_STREAM, 0); + printf("[tcp server]create socket[server]\n"); + TEST_ASSERT_NOT_EQUAL(lsfd, LWIP_TEST_FAIL); + + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(STACK_IP); + srvAddr.sin_port = htons(STACK_PORT); + ret = bind(lsfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr)); + printf("[tcp server]bind %s:%d,ret=%d\n", inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_SUCCESS); + + ret = listen(lsfd, 0); + printf("[tcp server]listen,ret=%d\n", ret); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_SUCCESS); + + waitServer(); + sfd = accept(lsfd, (struct sockaddr*)&clnAddr, &clnAddrLen); + printf("[tcp server]accept <%s:%d>\n", inet_ntoa(clnAddr.sin_addr), ntohs(clnAddr.sin_port)); + TEST_ASSERT_NOT_EQUAL(sfd, LWIP_TEST_FAIL); + + int srvMsgLen = strlen(SRV_MSG); + memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + ret = strcpy_s(buf, BUF_SIZE, SRV_MSG); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_SUCCESS); + ret = send(sfd, buf, srvMsgLen, 0); + printf("[tcp server]send, ret=%d\n", ret); + TEST_ASSERT_EQUAL_INT(ret, srvMsgLen); + + memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + ret = recv(sfd, buf, sizeof(buf), 0); + printf("[tcp server]recv, ret=%d\n", ret); + TEST_ASSERT_EQUAL_INT(ret, strlen(CLI_MSG)); + + waitServer(); + int len = 2; + clnAddr.sin_family = AF_INET; + clnAddr.sin_addr.s_addr = inet_addr(PEER_IP); + clnAddr.sin_port = htons(PEER_PORT); + memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + ret = strcpy_s(buf, BUF_SIZE, SRV_MSG); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_SUCCESS); + msg.msg_name = &clnAddr; + msg.msg_namelen = sizeof(clnAddr); + msg.msg_iov = iov; + msg.msg_iovlen = len; + iov[0].iov_base = buf; + iov[0].iov_len = srvMsgLen; + iov[1].iov_base = buf; + iov[1].iov_len = srvMsgLen; + ret = sendmsg(sfd, &msg, 0); + printf("[tcp server]sendmsg, ret=%d\n", ret); + TEST_ASSERT_EQUAL_INT(ret, len * srvMsgLen); + + waitServer(); + memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + ret = recv(sfd, buf, sizeof(buf), 0); + printf("[tcp server]recv, ret=%d\n", ret); + TEST_ASSERT_EQUAL_INT(ret, len * strlen(CLI_MSG)); + + ret = shutdown(sfd, SHUT_RDWR); + printf("[tcp server]shutdown, ret=%d\n", ret); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_SUCCESS); + + lwip_close(sfd); + lwip_close(lsfd); + g_serverResult = 1; + waitServer(); +} + +static void SampleTcpClientTask(void) +{ + int ret; + int sfd = -1; + struct msghdr msg = {0}; + struct iovec iov[2] = {}; + struct sockaddr addr; + socklen_t addrLen = sizeof(addr); + struct sockaddr_in srvAddr = {0}; + struct sockaddr_in clnAddr = {0}; + static char buf[BUF_SIZE+1] = {0}; + + sfd = socket(AF_INET, SOCK_STREAM, 0); + printf("[tcp client]create socket[client]\n"); + TEST_ASSERT_NOT_EQUAL(sfd, LWIP_TEST_FAIL); + + waitClient(); + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(PEER_IP); + srvAddr.sin_port = htons(PEER_PORT); + ret = connect(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr)); + printf("[tcp client]connect %s:%d, ret=%d\n", inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_SUCCESS); + + ret = getpeername(sfd, &addr, &addrLen); + printf("[tcp client]getpeername %s:%d, ret=%d\n", inet_ntoa(((struct sockaddr_in*)&addr)->sin_addr), + ntohs(((struct sockaddr_in*)&addr)->sin_port), ret); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_SUCCESS); + TEST_ASSERT_EQUAL_INT(addrLen, sizeof(struct sockaddr_in)); + TEST_ASSERT_EQUAL_INT(((struct sockaddr_in*)&addr)->sin_addr.s_addr, inet_addr(PEER_IP)); + + ret = getsockname(sfd, &addr, &addrLen); + printf("[tcp client]getsockname %s:%d, ret=%d\n", inet_ntoa(((struct sockaddr_in*)&addr)->sin_addr), + ntohs(((struct sockaddr_in*)&addr)->sin_port), ret); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_SUCCESS); + TEST_ASSERT_EQUAL_INT(addrLen, sizeof(struct sockaddr_in)); + TEST_ASSERT_EQUAL_INT(((struct sockaddr_in*)&addr)->sin_addr.s_addr, inet_addr(STACK_IP)); + + int cliMsgLen = strlen(CLI_MSG); + memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + ret = strcpy_s(buf, BUF_SIZE, CLI_MSG); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_SUCCESS); + ret = send(sfd, buf, cliMsgLen, 0); + printf("[tcp client]send, ret=%d\n", ret); + TEST_ASSERT_EQUAL_INT(ret, cliMsgLen); + + memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + ret = recv(sfd, buf, sizeof(buf), 0); + printf("[tcp client]recv,ret=%d\n", ret); + TEST_ASSERT_EQUAL_INT(ret, strlen(SRV_MSG)); + + waitClient(); + int len = 2; + clnAddr.sin_family = AF_INET; + clnAddr.sin_addr.s_addr = inet_addr(PEER_IP); + clnAddr.sin_port = htons(PEER_PORT); + memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + ret = strcpy_s(buf, BUF_SIZE, CLI_MSG); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_SUCCESS); + msg.msg_name = &clnAddr; + msg.msg_namelen = sizeof(clnAddr); + msg.msg_iov = iov; + msg.msg_iovlen = len; + iov[0].iov_base = buf; + iov[0].iov_len = cliMsgLen; + iov[1].iov_base = buf; + iov[1].iov_len = cliMsgLen; + ret = sendmsg(sfd, &msg, 0); + printf("[tcp client]sendmsg, ret=%d\n", ret); + TEST_ASSERT_EQUAL_INT(ret, len * cliMsgLen); + + waitClient(); + memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + ret = recv(sfd, buf, sizeof(buf), 0); + printf("[tcp client]recv, ret=%d\n", ret); + TEST_ASSERT_EQUAL_INT(ret, len * strlen(SRV_MSG)); + + ret = shutdown(sfd, SHUT_RDWR); + printf("[tcp client]shutdown, ret=%d\n", ret); + TEST_ASSERT_EQUAL_INT(ret, 0); + + lwip_close(sfd); + g_clientResult = 1; + waitClient(); +} + +/** + * @tc.desc : register a test suite, this suite is used to test function + * @param : subsystem name is communication + * @param : module name is lwip + * @param : test suit name is LwipFuncTestSuite + */ +LITE_TEST_SUIT(communication, lwip, LwipFuncTestSuite); + +/** + * @tc.setup : setup for every testcase + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL LwipFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for every testcase + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL LwipFuncTestSuiteTearDown(void) +{ + printf("+----------------------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number : SUB_COMMUNICATION_LWIP_SDK_0100 + * @tc.name : test upd + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(LwipFuncTestSuite, testUdp, LEVEL2) +{ + int sfd; + int ret; + int len = 2; + struct msghdr msg = {0}; + struct iovec iov[2] = {0}; + struct sockaddr_in srvAddr = {0}; + struct sockaddr_in clnAddr = {0}; + socklen_t clnAddrLen = sizeof(clnAddr); + + sfd = socket(AF_INET, SOCK_DGRAM, 0); + TEST_ASSERT_NOT_EQUAL(sfd, LWIP_TEST_FAIL); + + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(STACK_IP); + srvAddr.sin_port = htons(STACK_PORT); + ret = bind(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr)); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_SUCCESS); + + clnAddr.sin_family = AF_INET; + clnAddr.sin_addr.s_addr = inet_addr(PEER_IP); + clnAddr.sin_port = htons(PEER_PORT); + memset_s(g_buf, BUF_SIZE, 0, BUF_SIZE); + ret = strcpy_s(g_buf, BUF_SIZE, UDP_MSG); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_SUCCESS); + ret = sendto(sfd, g_buf, strlen(UDP_MSG), 0, (struct sockaddr*)&clnAddr, (socklen_t)sizeof(clnAddr)); + TEST_ASSERT_NOT_EQUAL(ret, LWIP_TEST_FAIL); + + memset_s(g_buf, BUF_SIZE, 0, BUF_SIZE); + ret = recvfrom(sfd, g_buf, sizeof(g_buf), 0, (struct sockaddr*)&clnAddr, &clnAddrLen); + TEST_ASSERT_EQUAL_INT(ret, strlen(UDP_MSG)); + + clnAddr.sin_family = AF_INET; + clnAddr.sin_addr.s_addr = inet_addr(PEER_IP); + clnAddr.sin_port = htons(PEER_PORT); + memset_s(g_buf, BUF_SIZE, 0, BUF_SIZE); + ret = strcpy_s(g_buf, BUF_SIZE, UDP_MSG); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_SUCCESS); + msg.msg_name = &clnAddr; + msg.msg_namelen = sizeof(clnAddr); + msg.msg_iov = iov; + msg.msg_iovlen = len; + iov[0].iov_base = g_buf; + iov[0].iov_len = strlen(UDP_MSG); + iov[1].iov_base = g_buf; + iov[1].iov_len = strlen(UDP_MSG); + ret = sendmsg(sfd, &msg, 0); + TEST_ASSERT_EQUAL_INT(ret, len * strlen(UDP_MSG)); + + ret = lwip_close(sfd); + TEST_ASSERT_NOT_EQUAL(ret, LWIP_TEST_FAIL); +} + +/** + * @tc.number : SUB_COMMUNICATION_LWIP_SDK_0200 + * @tc.name : test socket operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(LwipFuncTestSuite, testSocketOpt, LEVEL2) +{ + int ret; + struct timeval timeout; + socklen_t len; + + int fd; + fd = socket(AF_INET, SOCK_STREAM, 0); + TEST_ASSERT_NOT_EQUAL(fd, LWIP_TEST_FAIL); + + int error = -1; + len = sizeof(error); + ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_SUCCESS); + TEST_ASSERT_EQUAL_INT(error, LWIP_TEST_SUCCESS); + len = sizeof(timeout); + ret = getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, &len); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_SUCCESS); + + int sec = 1000; + timeout.tv_sec = sec; + len = sizeof(timeout); + ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, len); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_SUCCESS); + + memset_s(&timeout, len, 0, len); + ret = getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, &len); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_SUCCESS); + + error = -1; + len = sizeof(error); + ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_SUCCESS); + TEST_ASSERT_EQUAL_INT(error, LWIP_TEST_SUCCESS); + + int flag = 1; + ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag)); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_SUCCESS); + + ret = lwip_close(fd); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_SUCCESS); +} + +/** + * @tc.number : SUB_COMMUNICATION_LWIP_SDK_0300 + * @tc.name : test inet conversion + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(LwipFuncTestSuite, testInetConv, LEVEL2) +{ + int ret; + struct in_addr in; + ret = inet_pton(AF_INET, "300.10.10.10", &in); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_SUCCESS); + + ret = inet_pton(AF_INET, "10.11.12.13", &in); + TEST_ASSERT_EQUAL_INT(ret, 1); +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + TEST_ASSERT_EQUAL_INT(in.s_addr, 0x0d0c0b0a); +#else + TEST_ASSERT_EQUAL_INT(in.s_addr, 0x0a0b0c0d); +#endif + + const char *p = inet_ntoa(in); + TEST_ASSERT_NOT_NULL(p); + TEST_ASSERT_EQUAL_INT(strcmp(p, "10.11.12.13"), 0); + + int bufLen = 32; + char buf[bufLen]; + p = inet_ntop(AF_INET, &in, buf, sizeof(buf)); + TEST_ASSERT_NOT_NULL(p); + TEST_ASSERT_EQUAL_INT(strcmp(p, "10.11.12.13"), 0); +} + +/** + * @tc.number : SUB_COMMUNICATION_LWIP_SDK_0400 + * @tc.name : test tcp + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(LwipFuncTestSuite, testTcp, LEVEL2) +{ + osThreadAttr_t attrServer; + attrServer.name = "SampleTcpServerTask"; + attrServer.attr_bits = 0U; + attrServer.cb_mem = NULL; + attrServer.cb_size = 0U; + attrServer.stack_mem = NULL; + attrServer.stack_size = DEF_TASK_STACK; + attrServer.priority = DEF_TASK_PRIORITY; + + osThreadAttr_t attrClient; + attrClient.name = "SampleTcpClientTask"; + attrClient.attr_bits = 0U; + attrClient.cb_mem = NULL; + attrClient.cb_size = 0U; + attrClient.stack_mem = NULL; + attrClient.stack_size = DEF_TASK_STACK; + attrClient.priority = DEF_TASK_PRIORITY; + + osThreadId_t serverTaskId = osThreadNew((osThreadFunc_t)SampleTcpServerTask, NULL, &attrServer); + TEST_ASSERT_NOT_NULL(serverTaskId); + if (serverTaskId == NULL) { + printf("[testTcp]create server task fail!\n"); + } + osThreadId_t clientTaskId = osThreadNew((osThreadFunc_t)SampleTcpClientTask, NULL, &attrClient); + TEST_ASSERT_NOT_NULL(clientTaskId); + if (clientTaskId == NULL) { + printf("[testTcp]create client task fail!\n"); + } + + sleep(ONE_SECOND); + int timeout = TIMEOUT; + g_serverWait = 1; + g_clientWait = 1; + while (timeout > 0) { + if (g_serverWaitOver == 1 && g_clientWaitOver == 1) { + printf("[testTcp] wait success[1]!\n"); + break; + } + timeout--; + sleep(ONE_SECOND); + printf("[testTcp] wait[1]...\n"); + } + + sleep(ONE_SECOND); + timeout = TIMEOUT; + g_serverWait = 1; + g_clientWait = 1; + while (timeout > 0) { + if (g_serverWaitOver == 1 && g_clientWaitOver == 1) { + printf("[testTcp] wait success[2]!\n"); + break; + } + timeout--; + sleep(ONE_SECOND); + printf("[testTcp] wait[2]...\n"); + } + + sleep(ONE_SECOND); + timeout = TIMEOUT; + g_serverWait = 1; + g_clientWait = 1; + while (timeout > 0) { + if (g_serverWaitOver == 1 && g_clientWaitOver == 1) { + printf("[testTcp] wait success[3]!\n"); + break; + } + timeout--; + sleep(ONE_SECOND); + printf("[testTcp] wait[3]...\n"); + } + sleep(ONE_SECOND); + timeout = TIMEOUT; + g_serverWait = 1; + g_clientWait = 1; + while (timeout > 0) { + if (g_serverWaitOver == 1 && g_clientWaitOver == 1) { + printf("[testTcp] wait success[4]!\n"); + break; + } + timeout--; + sleep(ONE_SECOND); + printf("[testTcp] wait[4]...\n"); + } + TEST_ASSERT_EQUAL_INT(g_clientResult, 1); + TEST_ASSERT_EQUAL_INT(g_serverResult, 1); +} + +/** + * @tc.number : SUB_COMMUNICATION_LWIP_SDK_0500 + * @tc.name : test invalid parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(LwipFuncTestSuite, testInvalidParameter, LEVEL2) +{ + int ret; + int fdFail = -1; + int fdSuccess = -1; + + fdFail = socket(0, 0, 0); + TEST_ASSERT_EQUAL_INT(fdFail, LWIP_TEST_FAIL); + fdSuccess = socket(AF_INET, SOCK_STREAM, 0); + TEST_ASSERT_NOT_EQUAL(fdSuccess, LWIP_TEST_FAIL); + + ret = bind(fdFail, NULL, sizeof(struct sockaddr_in)); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + ret = bind(fdSuccess, NULL, sizeof(struct sockaddr_in)); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + + ret = connect(fdFail, NULL, sizeof(struct sockaddr)); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + ret = connect(fdSuccess, NULL, sizeof(struct sockaddr)); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + + ret = accept(fdFail, NULL, NULL); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + ret = accept(fdSuccess, NULL, NULL); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + + ret = getsockname(fdFail, NULL, NULL); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + ret = getsockname(fdSuccess, NULL, NULL); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + + ret = getpeername(fdFail, NULL, NULL); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + ret = getpeername(fdSuccess, NULL, NULL); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + + ret = send(fdFail, NULL, strlen(SRV_MSG), 0); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + ret = send(fdSuccess, NULL, strlen(SRV_MSG), 0); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + + ret = sendto(fdFail, NULL, strlen(SRV_MSG), 0, NULL, (socklen_t)sizeof(struct sockaddr_in)); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + ret = sendto(fdSuccess, NULL, strlen(SRV_MSG), 0, NULL, (socklen_t)sizeof(struct sockaddr_in)); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + + ret = recv(fdFail, NULL, sizeof(SRV_MSG), 0); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + ret = recv(fdSuccess, NULL, sizeof(SRV_MSG), 0); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + + ret = recvfrom(fdFail, NULL, sizeof(SRV_MSG), 0, NULL, NULL); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + ret = recvfrom(fdSuccess, NULL, sizeof(SRV_MSG), 0, NULL, NULL); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + + ret = setsockopt(fdFail, SOL_SOCKET, SO_RCVTIMEO, NULL, (socklen_t)sizeof(struct timeval)); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + ret = setsockopt(fdSuccess, SOL_SOCKET, SO_RCVTIMEO, NULL, (socklen_t)sizeof(struct timeval)); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + + ret = getsockopt(fdFail, SOL_SOCKET, SO_RCVTIMEO, NULL, (socklen_t*)sizeof(struct timeval)); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + ret = getsockopt(fdSuccess, SOL_SOCKET, SO_RCVTIMEO, NULL, (socklen_t*)sizeof(struct timeval)); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + + ret = sendmsg(fdFail, NULL, 0); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + ret = sendmsg(fdSuccess, NULL, 0); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + + ret = listen(fdFail, 0); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + ret = listen(fdSuccess, -1); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + + ret = select(fdFail, NULL, NULL, NULL, NULL); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + + ret = shutdown(fdFail, SHUT_RD); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + ret = shutdown(fdSuccess, -1); + TEST_ASSERT_EQUAL_INT(ret, LWIP_TEST_FAIL); + + ret = lwip_close(fdSuccess); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +RUN_TEST_SUITE(LwipFuncTestSuite); \ No newline at end of file diff --git a/communication_lite/lwip_posix/BUILD.gn b/communication_lite/lwip_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..b49c007f44779cfcc26acc9fb6ec2491e8ae45c8 --- /dev/null +++ b/communication_lite/lwip_posix/BUILD.gn @@ -0,0 +1,33 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsLwipTest") { + suite_name = "acts" + sources = [ + "src/ActsLwipTest.cpp", + ] + + defines = [ + "_GNU_SOURCE", + "restrict=", + ] + + deps = [ + "//test/xts/tools/hcpptest:hcpptest", + "//base/security/frameworks/huks_lite/source:huks", + ] + + cflags = ["-Wno-error"] +} diff --git a/communication_lite/lwip_posix/Test.json b/communication_lite/lwip_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..b0a1cb951776ebf6f442c4f159e06df19623e31c --- /dev/null +++ b/communication_lite/lwip_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for hcpptest demo test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/communication", + "target": "/test_root/communication" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/communication/ActsLwipTest.bin" + } +} \ No newline at end of file diff --git a/communication_lite/lwip_posix/src/ActsLwipTest.cpp b/communication_lite/lwip_posix/src/ActsLwipTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..527b426f07bcb04f4038cafa25af340a758eb859 --- /dev/null +++ b/communication_lite/lwip_posix/src/ActsLwipTest.cpp @@ -0,0 +1,507 @@ +/** + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include "sys/socket.h" +#include "arpa/inet.h" +#include "netinet/tcp.h" +#include "securec.h" +#include +#include +#include + +using namespace std; +using namespace testing::ext; + +static const int STACK_PORT = 2277; +static const int PEER_PORT = 2277; +static const int BUF_SIZE = (1024 * 8); +static const int LWIP_TEST_SUCCESS = 0; +static const int LWIP_TEST_FAIL = -1; +static char g_buf[BUF_SIZE + 1] = {0}; +static const char* g_udpMsg = "Hi, I am UDP"; +static const char* g_srvMsg = "Hi, I am TCP server"; +static const char* g_cliMsg = "Hi, I am TCP client"; +static const char* g_localHost = "127.0.0.1"; + +static pthread_barrier_t g_barrier; +#define WAIT() pthread_barrier_wait(&g_barrier) + +class ActsLwipTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +static void* SampleTcpServerTask(void *p) +{ + int ret; + int sfd = -1; + int lsfd = -1; + static char buf[BUF_SIZE + 1] = {0}; + struct msghdr msg = {0}; + struct iovec iov[2] = {}; + struct sockaddr_in srvAddr = {0}; + struct sockaddr_in clnAddr = {0}; + socklen_t clnAddrLen = sizeof(clnAddr); + + lsfd = socket(AF_INET, SOCK_STREAM, 0); + printf("[tcp server]create socket[server]\n"); + EXPECT_NE(lsfd, LWIP_TEST_FAIL); + + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(g_localHost); + srvAddr.sin_port = htons(STACK_PORT); + ret = ::bind(lsfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr)); + printf("[tcp server]bind %s:%d,ret=%d\n", inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + + ret = listen(lsfd, 0); + printf("[tcp server]listen,ret=%d\n", ret); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + + WAIT(); + sfd = accept(lsfd, (struct sockaddr*)&clnAddr, &clnAddrLen); + printf("[tcp server]accept <%s:%d>\n", inet_ntoa(clnAddr.sin_addr), ntohs(clnAddr.sin_port)); + EXPECT_NE(sfd, LWIP_TEST_FAIL); + + int srvMsgLen = strlen(g_srvMsg); + memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + ret = strcpy_s(buf, BUF_SIZE, g_srvMsg); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + ret = send(sfd, buf, srvMsgLen, 0); + printf("[tcp server]send, ret=%d\n", ret); + EXPECT_EQ(ret, srvMsgLen); + + memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + ret = recv(sfd, buf, sizeof(buf), 0); + printf("[tcp server]recv, ret=%d\n", ret); + EXPECT_EQ(ret, strlen(g_cliMsg)); + + WAIT(); + int len = 2; + clnAddr.sin_family = AF_INET; + clnAddr.sin_addr.s_addr = inet_addr(g_localHost); + clnAddr.sin_port = htons(PEER_PORT); + memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + ret = strcpy_s(buf, BUF_SIZE, g_srvMsg); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + msg.msg_name = &clnAddr; + msg.msg_namelen = sizeof(clnAddr); + msg.msg_iov = iov; + msg.msg_iovlen = len; + iov[0].iov_base = buf; + iov[0].iov_len = srvMsgLen; + iov[1].iov_base = buf; + iov[1].iov_len = srvMsgLen; + ret = sendmsg(sfd, &msg, 0); + printf("[tcp server]sendmsg, ret=%d\n", ret); + EXPECT_EQ(ret, len * srvMsgLen); + + WAIT(); + memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + memset_s(&msg, sizeof(msg), 0, sizeof(msg)); + msg.msg_name = &clnAddr; + msg.msg_namelen = sizeof(clnAddr); + msg.msg_iov = iov; + msg.msg_iovlen = 1; + iov[0].iov_base = buf; + iov[0].iov_len = sizeof(buf); + ret = recvmsg(sfd, &msg, 0); + printf("[tcp server]recvmsg on socket %d: %d\n", sfd, ret); + EXPECT_EQ(ret, len * strlen(g_cliMsg)); + + ret = shutdown(sfd, SHUT_RDWR); + printf("[tcp server]shutdown, ret=%d\n", ret); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + + ret = close(sfd); + EXPECT_NE(ret, LWIP_TEST_FAIL); + ret = close(lsfd); + EXPECT_NE(ret, LWIP_TEST_FAIL); + return nullptr; +} + +static void* SampleTcpClientTask(void *p) +{ + int ret; + int sfd = -1; + struct msghdr msg = {0}; + struct iovec iov[2] = {}; + struct sockaddr addr; + socklen_t addrLen = sizeof(addr); + struct sockaddr_in srvAddr = {0}; + struct sockaddr_in clnAddr = {0}; + static char buf[BUF_SIZE + 1] = {0}; + + sfd = socket(AF_INET, SOCK_STREAM, 0); + printf("[tcp client]create socket[client]\n"); + EXPECT_NE(sfd, LWIP_TEST_FAIL); + + WAIT(); + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(g_localHost); + srvAddr.sin_port = htons(PEER_PORT); + ret = connect(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr)); + printf("[tcp client]connect %s:%d, ret=%d\n", inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + + ret = getpeername(sfd, &addr, &addrLen); + printf("[tcp client]getpeername %s:%d, ret=%d\n", inet_ntoa(((struct sockaddr_in*)&addr)->sin_addr), + ntohs(((struct sockaddr_in*)&addr)->sin_port), ret); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + EXPECT_EQ(addrLen, sizeof(struct sockaddr_in)); + EXPECT_EQ(((struct sockaddr_in*)&addr)->sin_addr.s_addr, inet_addr(g_localHost)); + + ret = getsockname(sfd, &addr, &addrLen); + printf("[tcp client]getsockname %s:%d, ret=%d\n", inet_ntoa(((struct sockaddr_in*)&addr)->sin_addr), + ntohs(((struct sockaddr_in*)&addr)->sin_port), ret); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + EXPECT_EQ(addrLen, sizeof(struct sockaddr_in)); + EXPECT_EQ(((struct sockaddr_in*)&addr)->sin_addr.s_addr, inet_addr(g_localHost)); + + int cliMsgLen = strlen(g_cliMsg); + memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + ret = strcpy_s(buf, BUF_SIZE, g_cliMsg); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + ret = send(sfd, buf, cliMsgLen, 0); + printf("[tcp client]send, ret=%d\n", ret); + EXPECT_EQ(ret, cliMsgLen); + + memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + ret = recv(sfd, buf, sizeof(buf), 0); + printf("[tcp client]recv,ret=%d\n", ret); + EXPECT_EQ(ret, strlen(g_srvMsg)); + + WAIT(); + int len = 2; + clnAddr.sin_family = AF_INET; + clnAddr.sin_addr.s_addr = inet_addr(g_localHost); + clnAddr.sin_port = htons(PEER_PORT); + memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + ret = strcpy_s(buf, BUF_SIZE, g_cliMsg); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + msg.msg_name = &clnAddr; + msg.msg_namelen = sizeof(clnAddr); + msg.msg_iov = iov; + msg.msg_iovlen = len; + iov[0].iov_base = buf; + iov[0].iov_len = cliMsgLen; + iov[1].iov_base = buf; + iov[1].iov_len = cliMsgLen; + ret = sendmsg(sfd, &msg, 0); + printf("[tcp client]sendmsg, ret=%d\n", ret); + EXPECT_EQ(ret, len * cliMsgLen); + + WAIT(); + memset_s(buf, BUF_SIZE, 0, BUF_SIZE); + memset_s(&msg, sizeof(msg), 0, sizeof(msg)); + msg.msg_name = &clnAddr; + msg.msg_namelen = sizeof(clnAddr); + msg.msg_iov = iov; + msg.msg_iovlen = 1; + iov[0].iov_base = buf; + iov[0].iov_len = sizeof(buf); + ret = recvmsg(sfd, &msg, 0); + printf("[tcp client]recvmsg, ret=%d\n", ret); + EXPECT_EQ(ret, len * strlen(g_srvMsg)); + + ret = shutdown(sfd, SHUT_RDWR); + printf("[tcp client]shutdown, ret=%d\n", ret); + EXPECT_EQ(ret, 0); + + ret = close(sfd); + EXPECT_NE(ret, LWIP_TEST_FAIL); + return nullptr; +} + +/** + * @tc.number : SUB_COMMUNICATION_LWIP_SDK_0100 + * @tc.name : test upd + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(ActsLwipTest, testUdp, TestSize.Level2) +{ + int sfd; + int ret; + int len = 2; + struct msghdr msg = {0}; + struct iovec iov[2] = {0}; + struct sockaddr_in srvAddr = {0}; + struct sockaddr_in clnAddr = {0}; + socklen_t clnAddrLen = sizeof(clnAddr); + + sfd = socket(AF_INET, SOCK_DGRAM, 0); + EXPECT_NE(sfd, LWIP_TEST_FAIL); + + srvAddr.sin_family = AF_INET; + srvAddr.sin_addr.s_addr = inet_addr(g_localHost); + srvAddr.sin_port = htons(STACK_PORT); + ret = ::bind(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr)); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + + clnAddr.sin_family = AF_INET; + clnAddr.sin_addr.s_addr = inet_addr(g_localHost); + clnAddr.sin_port = htons(PEER_PORT); + memset_s(g_buf, BUF_SIZE, 0, BUF_SIZE); + ret = strcpy_s(g_buf, BUF_SIZE, g_udpMsg); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + ret = sendto(sfd, g_buf, strlen(g_udpMsg), 0, (struct sockaddr*)&clnAddr, (socklen_t)sizeof(clnAddr)); + EXPECT_NE(ret, LWIP_TEST_FAIL); + + memset_s(g_buf, BUF_SIZE, 0, BUF_SIZE); + ret = recvfrom(sfd, g_buf, sizeof(g_buf), 0, (struct sockaddr*)&clnAddr, &clnAddrLen); + EXPECT_EQ(ret, strlen(g_udpMsg)); + + clnAddr.sin_family = AF_INET; + clnAddr.sin_addr.s_addr = inet_addr(g_localHost); + clnAddr.sin_port = htons(PEER_PORT); + memset_s(g_buf, BUF_SIZE, 0, BUF_SIZE); + ret = strcpy_s(g_buf, BUF_SIZE, g_udpMsg); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + msg.msg_name = &clnAddr; + msg.msg_namelen = sizeof(clnAddr); + msg.msg_iov = iov; + msg.msg_iovlen = len; + iov[0].iov_base = g_buf; + iov[0].iov_len = strlen(g_udpMsg); + iov[1].iov_base = g_buf; + iov[1].iov_len = strlen(g_udpMsg); + ret = sendmsg(sfd, &msg, 0); + EXPECT_EQ(ret, len*strlen(g_udpMsg)); + + ret = close(sfd); + EXPECT_NE(ret, LWIP_TEST_FAIL); +} + +/** + * @tc.number : SUB_COMMUNICATION_LWIP_SDK_0200 + * @tc.name : test socket operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(ActsLwipTest, testSocketOpt, TestSize.Level2) +{ + int ret; + struct timeval timeout; + socklen_t len; + + int fd; + fd = socket(AF_INET, SOCK_STREAM, 0); + EXPECT_NE(fd, LWIP_TEST_FAIL); + + int error = -1; + len = sizeof(error); + ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + EXPECT_EQ(error, LWIP_TEST_SUCCESS); + len = sizeof(timeout); + ret = getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, &len); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + + timeout.tv_sec = 1000; + len = sizeof(timeout); + ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, len); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + + memset_s(&timeout, len, 0, len); + ret = getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, &len); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + + error = -1; + len = sizeof(error); + ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + EXPECT_EQ(error, LWIP_TEST_SUCCESS); + + int flag = 1; + ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag)); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + + ret = close(fd); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); +} + +/** + * @tc.number : SUB_COMMUNICATION_LWIP_SDK_0300 + * @tc.name : test inet conversion + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(ActsLwipTest, testInetConv, TestSize.Level2) +{ + int ret; + struct in_addr in; + ret = inet_pton(AF_INET, "300.10.10.10", &in); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + + ret = inet_pton(AF_INET, "10.11.12.13", &in); + EXPECT_EQ(ret, 1); +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + EXPECT_EQ(in.s_addr, 0x0d0c0b0a); +#else + EXPECT_EQ(in.s_addr, 0x0a0b0c0d); +#endif + + const char *p = inet_ntoa(in); + EXPECT_EQ(strcmp(p, "10.11.12.13"), 0); + + int bufLen = 32; + char buf[bufLen]; + p = inet_ntop(AF_INET, &in, buf, sizeof(buf)); + EXPECT_EQ(strcmp(p, "10.11.12.13"), 0); +} + +/** + * @tc.number : SUB_COMMUNICATION_LWIP_SDK_0400 + * @tc.name : test tcp + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(ActsLwipTest, testTcp, TestSize.Level2) +{ + int ret; + pthread_t srv; + pthread_t cli; + + ret = pthread_barrier_init(&g_barrier, 0, 2); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + + ret = pthread_create(&srv, nullptr, SampleTcpServerTask, nullptr); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + ret = pthread_create(&cli, nullptr, SampleTcpClientTask, nullptr); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + + ret = pthread_join(cli, nullptr); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + ret = pthread_join(srv, nullptr); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); + + ret = pthread_barrier_destroy(&g_barrier); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); +} + +/** + * @tc.number : SUB_COMMUNICATION_LWIP_SDK_0500 + * @tc.name : test invalid parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(ActsLwipTest, testInvalidParameter, TestSize.Level2) +{ + int ret; + int fdFail = -1; + int fdSuccess = -1; + + fdFail = socket(0, 0, 0); + EXPECT_EQ(fdFail, LWIP_TEST_FAIL); + fdSuccess = socket(AF_INET, SOCK_STREAM, 0); + EXPECT_NE(fdSuccess, LWIP_TEST_FAIL); + + ret = ::bind(fdFail, nullptr, sizeof(struct sockaddr_in)); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + ret = ::bind(fdSuccess, nullptr, sizeof(struct sockaddr_in)); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + + ret = connect(fdFail, nullptr, sizeof(struct sockaddr)); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + ret = connect(fdSuccess, nullptr, sizeof(struct sockaddr)); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + + ret = accept(fdFail, nullptr, nullptr); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + ret = accept(fdSuccess, nullptr, nullptr); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + + ret = getsockname(fdFail, nullptr, nullptr); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + ret = getsockname(fdSuccess, nullptr, nullptr); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + + ret = getpeername(fdFail, nullptr, nullptr); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + ret = getpeername(fdSuccess, nullptr, nullptr); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + + ret = send(fdFail, nullptr, strlen(g_srvMsg), 0); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + ret = send(fdSuccess, nullptr, strlen(g_srvMsg), 0); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + + ret = sendto(fdFail, nullptr, strlen(g_srvMsg), 0, nullptr, (socklen_t)sizeof(struct sockaddr_in)); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + ret = sendto(fdSuccess, nullptr, strlen(g_srvMsg), 0, nullptr, (socklen_t)sizeof(struct sockaddr_in)); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + + ret = recv(fdFail, nullptr, sizeof(g_srvMsg), 0); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + ret = recv(fdSuccess, nullptr, sizeof(g_srvMsg), 0); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + + struct msghdr msg = {0}; + ret = recvmsg(fdFail, &msg, 0); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + ret = recvmsg(fdSuccess, &msg, 0); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + + ret = recvfrom(fdFail, nullptr, sizeof(g_srvMsg), 0, nullptr, nullptr); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + ret = recvfrom(fdSuccess, nullptr, sizeof(g_srvMsg), 0, nullptr, nullptr); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + + ret = setsockopt(fdFail, SOL_SOCKET, SO_RCVTIMEO, nullptr, (socklen_t)sizeof(struct timeval)); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + ret = setsockopt(fdSuccess, SOL_SOCKET, SO_RCVTIMEO, nullptr, (socklen_t)sizeof(struct timeval)); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + ret = getsockopt(fdFail, SOL_SOCKET, SO_RCVTIMEO, nullptr, (socklen_t*)sizeof(struct timeval)); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + ret = getsockopt(fdSuccess, SOL_SOCKET, SO_RCVTIMEO, nullptr, (socklen_t*)sizeof(struct timeval)); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + + ret = sendmsg(fdFail, nullptr, 0); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + ret = sendmsg(fdSuccess, nullptr, 0); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + + ret = listen(fdFail, 0); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + ret = select(fdFail, nullptr, nullptr, nullptr, nullptr); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + + ret = shutdown(fdFail, SHUT_RD); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + ret = shutdown(fdSuccess, -1); + EXPECT_EQ(ret, LWIP_TEST_FAIL); + + ret = close(fdSuccess); + EXPECT_EQ(ret, LWIP_TEST_SUCCESS); +} diff --git a/communication_lite/softbus_hal/BUILD.gn b/communication_lite/softbus_hal/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..3fa954f954235803c74c47994a7e589f09f483b0 --- /dev/null +++ b/communication_lite/softbus_hal/BUILD.gn @@ -0,0 +1,42 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") +hctest_suite("ActsSoftBusTest") { + suite_name = "acts" + sources = [ + "src/softbus_func_test.c", + ] + + defines = ["HOS_DISCOVERY_3861_BOARD"] + include_dirs = [ + "//vendor/hisi/hi3861/hi3861/include", + "//vendor/hisi/hi3861/hi3861/components/lwip_sack/include", + "//vendor/hisi/hi3861/hi3861/third_party/cjson", + "//third_party/bounds_checking_function/include", + "//kernel/liteos_m/components/cmsis", + "//kernel/liteos_m/components/cmsis/2.0", + "//foundation/communication/interfaces/kits/wifi_lite/wifiservice", + "//foundation/communication/frameworks/wifi_lite/wifiservice/source", + "//foundation/communication/services/softbus_lite/discovery/discovery_service/include", + "//foundation/communication/services/softbus_lite/discovery/include", + "//foundation/communication/interfaces/kits/softbus_lite/discovery", + "//foundation/communication/interfaces/kits/softbus_lite/transport" + ] + + deps = [ + "//foundation/communication/services/softbus_lite:softbus", + ] + + cflags = [ "-Wno-error" ] +} diff --git a/communication_lite/softbus_hal/Test.tmpl b/communication_lite/softbus_hal/Test.tmpl new file mode 100755 index 0000000000000000000000000000000000000000..be8407e1286041a5af2bdc75a15633337376eb9d --- /dev/null +++ b/communication_lite/softbus_hal/Test.tmpl @@ -0,0 +1,19 @@ +{ + "description": "Config for $module test cases", + "environment": [ + { + "type": "device", + "label": "wifiiot" + } + ], + "kits": [ + { + "type": "DeployKit", + "timeout": "20000", + "burn_file": "$subsystem/$module.bin" + } + ], + "driver": { + "type": "CTestLite" + } +} \ No newline at end of file diff --git a/communication_lite/softbus_hal/src/softbus_func_test.c b/communication_lite/softbus_hal/src/softbus_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..9a2e859cee641313bc28975a2e7bcddae7d21473 --- /dev/null +++ b/communication_lite/softbus_hal/src/softbus_func_test.c @@ -0,0 +1,1161 @@ +/* + * Copyright (c) 2020 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 "hctest.h" +#include "discovery_service.h" +#include "session.h" +#include "securec.h" +#include +#include + +#define PUB_SUCCESS 1 +#define PUB_FAIL (-1) +#define TESTCASE_COUNT 23 +#define ERROR_SESSION_ID (-1) +#define SESSION_NAME_LEN 64 +#define SOFTBUS_TEST_SUCCESS 0 +#define SOFTBUS_TEST_FAIL (-1) +#define ONE_SECOND 1 +#define DEF_TIMEOUT 6 +#define DEF_DEVTYPE "L0" +#define DEF_DEVID "sb_test_default_devid" +#define DEF_PUB_ID 33113322 +#define DEF_PUB_MODULE_NAME "sb_pub_module_name" +#define DEF_PUB_CAPABILITY "ddmpCapability" +#define DEF_PUB_CAPABILITYDATA_LEN 2 +#define DEVID_MAX_LEN 96 + +static int g_pubFlag = 0; +static int g_setUpFlag = 0; +static int g_caseExeCount = 0; +static unsigned char* g_pubCapabilityData = (unsigned char*)"Hi"; +static IPublishCallback g_pubCallback = {0}; +static struct ISessionListener *g_sessionListenerCallback = NULL; + +static void ResetPubFlag(void) +{ + g_pubFlag = 0; +} + +static void WaitPublishResult(void) +{ + int timeout = DEF_TIMEOUT; + while (timeout > 0) { + sleep(ONE_SECOND); + timeout--; + if (g_pubFlag == PUB_SUCCESS || g_pubFlag == PUB_FAIL) { + printf("checkPublish:wait[%d].\n", DEF_TIMEOUT - timeout); + break; + } + } + if (timeout <= 0) { + printf("checkPublish:timeout!\n"); + } +} + +/** + * callback of publish success + */ +static void SbPublishSuccess(int pubId) +{ + printf("[PubSuccess]publish success id[%d].\n", pubId); + g_pubFlag = PUB_SUCCESS; +} + +/** + * callback of publish fail + */ +static void SbPublishFail(int pubId, PublishFailReason reason) +{ + printf("[PubFail]publish fail id[%d],reason[%d].\n", pubId, reason); + g_pubFlag = PUB_FAIL; +} + +/** + * callback of session opened + */ +static int SbSessionOpened(int sessionId) +{ + if (sessionId < 0) { + printf("[Session opened]sessionId is invalid.\n"); + } + return SOFTBUS_TEST_SUCCESS; +} + +/** + * callback of session closed + */ +static void SbSessionClosed(int sessionId) +{ + if (sessionId < 0) { + printf("[Session closed]sessionId is invalid.\n"); + } + printf("[Session closed]session closed.\n"); +} + +/** + * callback of received data + */ +static void SbOnBytesReceived(int sessionId, const void *data, unsigned int len) +{ + if (sessionId < 0 || data == NULL) { + printf("[Session recevie]id or data invalid, .\n"); + } + printf("[Session recevie]receive data, length[%d].\n", len); +} + +/** + * init service during first publish + */ +static void DefaultPublishToInitService(void) +{ + PublishInfo *pubInfo = NULL; + pubInfo = (PublishInfo *)malloc(sizeof(PublishInfo)); + if (pubInfo == NULL) { + printf("[DefaultPublishToInitService]malloc fail!\n"); + return; + } + (void)memset_s(pubInfo, sizeof(PublishInfo), 0, sizeof(PublishInfo)); + pubInfo->publishId = DEF_PUB_ID; + pubInfo->mode = DISCOVER_MODE_PASSIVE; + pubInfo->medium = COAP; + pubInfo->freq = MID; + pubInfo->capability = DEF_PUB_CAPABILITY; + pubInfo->capabilityData = g_pubCapabilityData; + pubInfo->dataLen = DEF_PUB_CAPABILITYDATA_LEN; + + ResetPubFlag(); + int ret = PublishService(DEF_PUB_MODULE_NAME, pubInfo, &g_pubCallback); + if (ret != SOFTBUS_TEST_SUCCESS) { + printf("[DefaultPublishToInitService]call PublishService fail!\n"); + } else { + WaitPublishResult(); + if (g_pubFlag != PUB_SUCCESS) { + printf("[DefaultPublishToInitService]call PublishService fail!\n"); + ret = SOFTBUS_TEST_FAIL; + } + } + free(pubInfo); +} + +/** + * undo the first publish + */ +static void UnDefaultPublish(void) +{ + int ret; + ret = UnPublishService(DEF_PUB_MODULE_NAME, DEF_PUB_ID); + if (ret != SOFTBUS_TEST_SUCCESS) { + printf("[UnDefaultPublish]unpublish fail!\n"); + } +} + +/** + * @tc.desc : register a test suite, this suite is used to test function + * @param : subsystem name is communication + * @param : module name is softbus + * @param : test suit name is SoftBusFuncTestSuite + */ +LITE_TEST_SUIT(communication, softbus, SoftBusFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL SoftBusFuncTestSuiteSetUp(void) +{ + if (g_setUpFlag == 0) { + g_pubCallback.onPublishSuccess = SbPublishSuccess; + g_pubCallback.onPublishFail = SbPublishFail; + g_sessionListenerCallback = (struct ISessionListener*)malloc(sizeof(struct ISessionListener)); + if (g_sessionListenerCallback == NULL) { + printf("SetUp:malloc(g_sessionListenerCallback) fail!\n"); + return FALSE; + } + g_sessionListenerCallback->onSessionOpened = SbSessionOpened; + g_sessionListenerCallback->onSessionClosed = SbSessionClosed; + g_sessionListenerCallback->onBytesReceived = SbOnBytesReceived; + g_setUpFlag = 1; + + DefaultPublishToInitService(); + UnDefaultPublish(); + } + g_caseExeCount++; + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL SoftBusFuncTestSuiteTearDown(void) +{ + if (g_caseExeCount == TESTCASE_COUNT) { + if (g_sessionListenerCallback != NULL) { + free(g_sessionListenerCallback); + g_sessionListenerCallback = NULL; + } + } + printf("+----------------------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_0100 + * @tc.name : abnormal parameter test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 3 + */ +LITE_TEST_CASE(SoftBusFuncTestSuite, testSetNumGreaterThanMax, LEVEL3) +{ + CommonDeviceInfo *devInfo = NULL; + devInfo = (CommonDeviceInfo *)malloc(sizeof(CommonDeviceInfo)); + TEST_ASSERT_NOT_NULL(devInfo); + (void)memset_s(devInfo, sizeof(CommonDeviceInfo), 0, sizeof(CommonDeviceInfo)); + devInfo->key = COMM_DEVICE_KEY_DEVID; + devInfo->value = DEF_DEVID; + + int ret = SetCommonDeviceInfo(devInfo, COMM_DEVICE_KEY_MAX + 1); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + int num = 0; + ret = SetCommonDeviceInfo(devInfo, num); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + num = 1; + ret = SetCommonDeviceInfo(NULL, num); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + free(devInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_0200 + * @tc.name : set ID value less than maximum value + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SoftBusFuncTestSuite, testSetDevIdLessThanMax, LEVEL2) +{ + CommonDeviceInfo *devInfo = NULL; + devInfo = (CommonDeviceInfo *)malloc(sizeof(CommonDeviceInfo)); + TEST_ASSERT_NOT_NULL(devInfo); + (void)memset_s(devInfo, sizeof(CommonDeviceInfo), 0, sizeof(CommonDeviceInfo)); + devInfo->key = COMM_DEVICE_KEY_DEVID; + devInfo->value = + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890abcde"; + int num = 1; + int ret = SetCommonDeviceInfo(devInfo, num); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + free(devInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_0300 + * @tc.name : set ID value equal and greater maximum value + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 3 + */ +LITE_TEST_CASE(SoftBusFuncTestSuite, testSetDevIdEqualMax, LEVEL3) +{ + CommonDeviceInfo *devInfo = NULL; + devInfo = (CommonDeviceInfo *)malloc(sizeof(CommonDeviceInfo)); + TEST_ASSERT_NOT_NULL(devInfo); + (void)memset_s(devInfo, sizeof(CommonDeviceInfo), 0, sizeof(CommonDeviceInfo)); + devInfo->key = COMM_DEVICE_KEY_DEVID; + devInfo->value = + "abcdef123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; + int num = 1; + int ret = SetCommonDeviceInfo(devInfo, num); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + devInfo->value = + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890abcdefg"; + ret = SetCommonDeviceInfo(devInfo, num); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + free(devInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_0400 + * @tc.name : set ID value with special characters + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SoftBusFuncTestSuite, testSetDevIdSpecialChars, LEVEL2) +{ + CommonDeviceInfo *devInfo = NULL; + devInfo = (CommonDeviceInfo *)malloc(sizeof(CommonDeviceInfo)); + TEST_ASSERT_NOT_NULL(devInfo); + (void)memset_s(devInfo, sizeof(CommonDeviceInfo), 0, sizeof(CommonDeviceInfo)); + devInfo->key = COMM_DEVICE_KEY_DEVID; + devInfo->value = "!@#$%^&*()_+:>key = COMM_DEVICE_KEY_DEVNAME; + devInfo->value = "123456789012345678901234567890123456789012345678901234567890abc"; + int num = 1; + int ret = SetCommonDeviceInfo(devInfo, num); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + free(devInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_0600 + * @tc.name : set name value equal and greater maximum value + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 3 + */ +LITE_TEST_CASE(SoftBusFuncTestSuite, testSetDevNameEqualMax, LEVEL3) +{ + CommonDeviceInfo *devInfo = NULL; + devInfo = (CommonDeviceInfo *)malloc(sizeof(CommonDeviceInfo)); + TEST_ASSERT_NOT_NULL(devInfo); + (void)memset_s(devInfo, sizeof(CommonDeviceInfo), 0, sizeof(CommonDeviceInfo)); + devInfo->key = COMM_DEVICE_KEY_DEVNAME; + devInfo->value = "abcd123456789012345678901234567890123456789012345678901234567890"; + int num = 1; + int ret = SetCommonDeviceInfo(devInfo, num); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + + devInfo->value = "123456789012345678901234567890123456789012345678901234567890abcde"; + ret = SetCommonDeviceInfo(devInfo, num); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + free(devInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_0700 + * @tc.name : set name value with special characters + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SoftBusFuncTestSuite, testSetDevNameSpecialChars, LEVEL2) +{ + CommonDeviceInfo *devInfo = NULL; + devInfo = (CommonDeviceInfo *)malloc(sizeof(CommonDeviceInfo)); + TEST_ASSERT_NOT_NULL(devInfo); + (void)memset_s(devInfo, sizeof(CommonDeviceInfo), 0, sizeof(CommonDeviceInfo)); + devInfo->key = COMM_DEVICE_KEY_DEVNAME; + devInfo->value = "!@#$%^&*()_+:>key = COMM_DEVICE_KEY_DEVTYPE; + devInfo->value = "error"; + int num = 1; + int ret = SetCommonDeviceInfo(devInfo, num); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + free(devInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_0900 + * @tc.name : set type value not match actual + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SoftBusFuncTestSuite, testSetDevTypeNotMacthActual, LEVEL2) +{ + CommonDeviceInfo *devInfo = NULL; + devInfo = (CommonDeviceInfo *)malloc(sizeof(CommonDeviceInfo)); + TEST_ASSERT_NOT_NULL(devInfo); + (void)memset_s(devInfo, sizeof(CommonDeviceInfo), 0, sizeof(CommonDeviceInfo)); + devInfo->key = COMM_DEVICE_KEY_DEVTYPE; + devInfo->value = "PAD"; + unsigned int num = 1; + int ret = SetCommonDeviceInfo(devInfo, num); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + free(devInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_1000 + * @tc.name : set key is error + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SoftBusFuncTestSuite, testSetDevKeyIsError, LEVEL2) +{ + CommonDeviceInfo *devInfo = NULL; + devInfo = (CommonDeviceInfo *)malloc(sizeof(CommonDeviceInfo)); + TEST_ASSERT_NOT_NULL(devInfo); + (void)memset_s(devInfo, sizeof(CommonDeviceInfo), 0, sizeof(CommonDeviceInfo)); + int errorKey = 10; + devInfo->key = errorKey; + devInfo->value = DEF_DEVID; + unsigned int num = 1; + int ret = SetCommonDeviceInfo(devInfo, num); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + free(devInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_1100 + * @tc.name : set all three + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SoftBusFuncTestSuite, testSetAllDevInfo, LEVEL2) +{ + int num = 3; + CommonDeviceInfo *devInfo = NULL; + int size = sizeof(CommonDeviceInfo)*num; + devInfo = (CommonDeviceInfo *)malloc(size); + TEST_ASSERT_NOT_NULL(devInfo); + (void)memset_s(devInfo, size, 0, size); + devInfo[2].key = COMM_DEVICE_KEY_DEVID; + devInfo[2].value = DEF_DEVID; + devInfo[0].key = COMM_DEVICE_KEY_DEVTYPE; + devInfo[0].value = DEF_DEVTYPE; + devInfo[1].key = COMM_DEVICE_KEY_DEVNAME; + devInfo[1].value = "sb_test_default_devname"; + + int ret = SetCommonDeviceInfo(devInfo, num); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + free(devInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_1200 + * @tc.name : first set id and type ,but type is error, will set fail, then set name, will success + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SoftBusFuncTestSuite, testSetTwoInfoOneIsError, LEVEL2) +{ + int num = 2; + CommonDeviceInfo *devInfo = NULL; + int size = sizeof(CommonDeviceInfo)*num; + devInfo = (CommonDeviceInfo *)malloc(size); + TEST_ASSERT_NOT_NULL(devInfo); + (void)memset_s(devInfo, size, 0, size); + devInfo[0].key = COMM_DEVICE_KEY_DEVID; + devInfo[0].value = DEF_DEVTYPE; + devInfo[1].key = COMM_DEVICE_KEY_DEVTYPE; + devInfo[1].value = "error"; + + int ret = SetCommonDeviceInfo(devInfo, num); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + num = 1; + devInfo[0].key = COMM_DEVICE_KEY_DEVNAME; + devInfo[0].value = "testSetTwoOneIsError"; + ret = SetCommonDeviceInfo(devInfo, num); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + free(devInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_1300 + * @tc.name : Test publish with invalid parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SoftBusFuncTestSuite, testPublishParameterIsNull, LEVEL2) +{ + PublishInfo *pubInfo = NULL; + pubInfo = (PublishInfo *)malloc(sizeof(PublishInfo)); + TEST_ASSERT_NOT_NULL(pubInfo); + (void)memset_s(pubInfo, sizeof(PublishInfo), 0, sizeof(PublishInfo)); + pubInfo->publishId = DEF_PUB_ID; + pubInfo->mode = DISCOVER_MODE_PASSIVE; + pubInfo->medium = COAP; + pubInfo->freq = MID; + pubInfo->capability = DEF_PUB_CAPABILITY; + pubInfo->capabilityData = g_pubCapabilityData; + pubInfo->dataLen = DEF_PUB_CAPABILITYDATA_LEN; + + ResetPubFlag(); + int ret = PublishService(NULL, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + ret = PublishService(DEF_PUB_MODULE_NAME, NULL, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + ret = PublishService(DEF_PUB_MODULE_NAME, pubInfo, NULL); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + ret = PublishService(NULL, NULL, NULL); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + free(pubInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_1400 + * @tc.name : set name value empty and less than maximum value + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SoftBusFuncTestSuite, testPubPkgNameNormal, LEVEL2) +{ + PublishInfo *pubInfo = NULL; + pubInfo = (PublishInfo *)malloc(sizeof(PublishInfo)); + TEST_ASSERT_NOT_NULL(pubInfo); + (void)memset_s(pubInfo, sizeof(PublishInfo), 0, sizeof(PublishInfo)); + pubInfo->publishId = DEF_PUB_ID; + pubInfo->mode = DISCOVER_MODE_PASSIVE; + pubInfo->medium = COAP; + pubInfo->freq = MID; + pubInfo->capability = DEF_PUB_CAPABILITY; + pubInfo->capabilityData = g_pubCapabilityData; + pubInfo->dataLen = DEF_PUB_CAPABILITYDATA_LEN; + + ResetPubFlag(); + char *pkgNameEmpty = ""; + int ret = PublishService(pkgNameEmpty, pubInfo, &g_pubCallback); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_SUCCESS); + + ResetPubFlag(); + char *pkgNameLessMax = "123456789012345678901234567890123456789012345678901234567890abc"; + ret = PublishService(pkgNameLessMax, pubInfo, &g_pubCallback); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_SUCCESS); + + ret = UnPublishService(pkgNameEmpty, DEF_PUB_ID); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + ret = UnPublishService(pkgNameLessMax, DEF_PUB_ID); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + free(pubInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_1500 + * @tc.name : set package name value equal and greater than maximum value + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SoftBusFuncTestSuite, testPublishPkgNameAbnormal, LEVEL2) +{ + PublishInfo *pubInfo = NULL; + pubInfo = (PublishInfo *)malloc(sizeof(PublishInfo)); + TEST_ASSERT_NOT_NULL(pubInfo); + (void)memset_s(pubInfo, sizeof(PublishInfo), 0, sizeof(PublishInfo)); + pubInfo->publishId = DEF_PUB_ID; + pubInfo->mode = DISCOVER_MODE_PASSIVE; + pubInfo->medium = COAP; + pubInfo->freq = MID; + pubInfo->capability = DEF_PUB_CAPABILITY; + pubInfo->capabilityData = g_pubCapabilityData; + pubInfo->dataLen = DEF_PUB_CAPABILITYDATA_LEN; + + ResetPubFlag(); + int ret = PublishService(NULL, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + + ResetPubFlag(); + char *pkgNameMax = "123456789012345678901234567890123456789012345678901234567890abcd"; + ret = PublishService(pkgNameMax, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + + ResetPubFlag(); + char *pkgNameMoreMax = "abcde123456789012345678901234567890123456789012345678901234567890"; + ret = PublishService(pkgNameMoreMax, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + + ret = UnPublishService(pkgNameMax, DEF_PUB_ID); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + ret = UnPublishService(pkgNameMoreMax, DEF_PUB_ID); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + free(pubInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_1600 + * @tc.name : test publish limit + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SoftBusFuncTestSuite, testPublishCountLimit, LEVEL2) +{ + PublishInfo *pubInfo = NULL; + pubInfo = (PublishInfo *)malloc(sizeof(PublishInfo)); + TEST_ASSERT_NOT_NULL(pubInfo); + (void)memset_s(pubInfo, sizeof(PublishInfo), 0, sizeof(PublishInfo)); + pubInfo->publishId = DEF_PUB_ID; + pubInfo->mode = DISCOVER_MODE_PASSIVE; + pubInfo->medium = COAP; + pubInfo->freq = MID; + pubInfo->capability = DEF_PUB_CAPABILITY; + pubInfo->capabilityData = g_pubCapabilityData; + pubInfo->dataLen = DEF_PUB_CAPABILITYDATA_LEN; + + ResetPubFlag(); + char *pkgNameOne = "one"; + int ret = PublishService(pkgNameOne, pubInfo, &g_pubCallback); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_SUCCESS); + + ResetPubFlag(); + char *pkgNameTwo = "two"; + ret = PublishService(pkgNameTwo, pubInfo, &g_pubCallback); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_SUCCESS); + + ResetPubFlag(); + char *pkgNameThree = "three"; + ret = PublishService(pkgNameThree, pubInfo, &g_pubCallback); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_SUCCESS); + + ResetPubFlag(); + char *pkgNameFour = "four"; + ret = PublishService(pkgNameFour, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + ResetPubFlag(); + pubInfo->publishId = DEF_PUB_ID + 1; + ret = PublishService(pkgNameOne, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + ResetPubFlag(); + ret = PublishService(pkgNameFour, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + pubInfo->publishId = DEF_PUB_ID; + + ResetPubFlag(); + ret = PublishService(pkgNameTwo, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + + ret = UnPublishService(pkgNameOne, DEF_PUB_ID); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + ResetPubFlag(); + ret = PublishService(pkgNameOne, pubInfo, &g_pubCallback); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_SUCCESS); + ResetPubFlag(); + ret = PublishService(pkgNameOne, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + + ret = UnPublishService(pkgNameThree, DEF_PUB_ID); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + ResetPubFlag(); + ret = PublishService(pkgNameFour, pubInfo, &g_pubCallback); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_SUCCESS); + + ret = UnPublishService(pkgNameTwo, DEF_PUB_ID); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + ret = UnPublishService(pkgNameOne, DEF_PUB_ID); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + ret = UnPublishService(pkgNameThree, DEF_PUB_ID); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + ret = UnPublishService(pkgNameFour, DEF_PUB_ID); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + + char *pkgNameComm = "common"; + int pubIdOne = 110; + pubInfo->publishId = pubIdOne; + ResetPubFlag(); + ret = PublishService(pkgNameComm, pubInfo, &g_pubCallback); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_SUCCESS); + int pubIdTwo = 220; + pubInfo->publishId = pubIdTwo; + ResetPubFlag(); + ret = PublishService(pkgNameComm, pubInfo, &g_pubCallback); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_SUCCESS); + int pubIdThree = 330; + pubInfo->publishId = pubIdThree; + ResetPubFlag(); + ret = PublishService(pkgNameComm, pubInfo, &g_pubCallback); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_SUCCESS); + + int pubIdFour = 440; + pubInfo->publishId = pubIdFour; + ResetPubFlag(); + ret = PublishService(pkgNameComm, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + pubInfo->publishId = pubIdThree; + ResetPubFlag(); + ret = PublishService(pkgNameOne, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + pubInfo->publishId = pubIdFour; + ResetPubFlag(); + ret = PublishService(pkgNameOne, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + + ResetPubFlag(); + pubInfo->publishId = pubIdOne; + ret = PublishService(pkgNameComm, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + + ret = UnPublishService(pkgNameComm, pubIdOne); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + pubInfo->publishId = pubIdOne; + ResetPubFlag(); + ret = PublishService(pkgNameComm, pubInfo, &g_pubCallback); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_SUCCESS); + ResetPubFlag(); + ret = PublishService(pkgNameComm, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + + ret = UnPublishService(pkgNameComm, pubIdOne); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + int pubIdFive = 555; + pubInfo->publishId = pubIdFive; + ResetPubFlag(); + ret = PublishService(pkgNameComm, pubInfo, &g_pubCallback); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_SUCCESS); + + ret = UnPublishService(pkgNameComm, pubIdFive); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + ret = UnPublishService(pkgNameComm, pubIdThree); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + ret = UnPublishService(pkgNameComm, pubIdTwo); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + ret = UnPublishService(pkgNameComm, pubIdOne); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + + free(pubInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_1700 + * @tc.name : set capability value not in list + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 3 + */ +LITE_TEST_CASE(SoftBusFuncTestSuite, testPublishCapabilityError, LEVEL3) +{ + PublishInfo *pubInfo = NULL; + pubInfo = (PublishInfo *)malloc(sizeof(PublishInfo)); + TEST_ASSERT_NOT_NULL(pubInfo); + (void)memset_s(pubInfo, sizeof(PublishInfo), 0, sizeof(PublishInfo)); + pubInfo->publishId = DEF_PUB_ID; + pubInfo->mode = DISCOVER_MODE_PASSIVE; + pubInfo->medium = COAP; + pubInfo->freq = MID; + pubInfo->capability = "error capability"; + pubInfo->capabilityData = g_pubCapabilityData; + pubInfo->dataLen = DEF_PUB_CAPABILITYDATA_LEN; + + ResetPubFlag(); + int ret = PublishService(DEF_PUB_MODULE_NAME, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + free(pubInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_1800 + * @tc.name : this case used to cover interface only + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 3 + */ +LITE_TEST_CASE(SoftBusFuncTestSuite, testSessionSample, LEVEL3) +{ + int randomId = 5; + char *moduleName = "default_test_module_name"; + int ret = CreateSessionServer(moduleName, "ohos", g_sessionListenerCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + + char mySessionName[SESSION_NAME_LEN] = {0}; + ret = GetMySessionName(randomId, (char *)mySessionName, SESSION_NAME_LEN); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + + char peerSeesionName[SESSION_NAME_LEN] = {0}; + ret = GetPeerSessionName(randomId, (char *)peerSeesionName, SESSION_NAME_LEN); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + + char peerDeviceId[DEVID_MAX_LEN] = {0}; + ret = GetPeerDeviceId(randomId, (char *)peerDeviceId, DEVID_MAX_LEN); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + + int size = 10; + char *sampleCharData = "L0->phone"; + ret = SendBytes(randomId, sampleCharData, size); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + + CloseSession(randomId); + + ret = RemoveSessionServer(moduleName, (char *)mySessionName); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_1900 + * @tc.name : test pubInfo-publishId mode medium invalid value + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 3 + */ +LITE_TEST_CASE(SoftBusFuncTestSuite, testPublishInfoInvalidValue, LEVEL3) +{ + int pubId = -1; + PublishInfo *pubInfo = NULL; + pubInfo = (PublishInfo *)malloc(sizeof(PublishInfo)); + TEST_ASSERT_NOT_NULL(pubInfo); + (void)memset_s(pubInfo, sizeof(PublishInfo), 0, sizeof(PublishInfo)); + pubInfo->publishId = pubId; + pubInfo->mode = DISCOVER_MODE_PASSIVE; + pubInfo->medium = COAP; + pubInfo->freq = MID; + pubInfo->capability = DEF_PUB_CAPABILITY; + pubInfo->capabilityData = g_pubCapabilityData; + pubInfo->dataLen = DEF_PUB_CAPABILITYDATA_LEN; + + ResetPubFlag(); + int ret = PublishService(DEF_PUB_MODULE_NAME, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + + pubInfo->publishId = DEF_PUB_ID; + pubInfo->mode = DISCOVER_MODE_ACTIVE; + ResetPubFlag(); + ret = PublishService(DEF_PUB_MODULE_NAME, pubInfo, &g_pubCallback); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_SUCCESS); + ret = UnPublishService(DEF_PUB_MODULE_NAME, DEF_PUB_ID); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + + pubInfo->mode = DISCOVER_MODE_PASSIVE; + pubInfo->medium = BLE; + ResetPubFlag(); + ret = PublishService(DEF_PUB_MODULE_NAME, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + + pubInfo->medium = AUTO; + ResetPubFlag(); + ret = PublishService(DEF_PUB_MODULE_NAME, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + + pubInfo->medium = 10; + ResetPubFlag(); + ret = PublishService(DEF_PUB_MODULE_NAME, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + + ret = UnPublishService(DEF_PUB_MODULE_NAME, DEF_PUB_ID); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + free(pubInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_2000 + * @tc.name : test pubInfo-freq value + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 3 + */ +LITE_TEST_CASE(SoftBusFuncTestSuite, testPublishInfoFreq, LEVEL3) +{ + PublishInfo *pubInfo = NULL; + pubInfo = (PublishInfo *)malloc(sizeof(PublishInfo)); + TEST_ASSERT_NOT_NULL(pubInfo); + (void)memset_s(pubInfo, sizeof(PublishInfo), 0, sizeof(PublishInfo)); + pubInfo->publishId = DEF_PUB_ID; + pubInfo->mode = DISCOVER_MODE_PASSIVE; + pubInfo->medium = COAP; + pubInfo->freq = LOW; + pubInfo->capability = DEF_PUB_CAPABILITY; + pubInfo->capabilityData = g_pubCapabilityData; + pubInfo->dataLen = DEF_PUB_CAPABILITYDATA_LEN; + + ResetPubFlag(); + int ret = PublishService(DEF_PUB_MODULE_NAME, pubInfo, &g_pubCallback); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_SUCCESS); + ret = UnPublishService(DEF_PUB_MODULE_NAME, DEF_PUB_ID); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + + pubInfo->freq = HIGH; + ResetPubFlag(); + ret = PublishService(DEF_PUB_MODULE_NAME, pubInfo, &g_pubCallback); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_SUCCESS); + ret = UnPublishService(DEF_PUB_MODULE_NAME, DEF_PUB_ID); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + + pubInfo->freq = SUPER_HIGH; + ResetPubFlag(); + ret = PublishService(DEF_PUB_MODULE_NAME, pubInfo, &g_pubCallback); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_SUCCESS); + ret = UnPublishService(DEF_PUB_MODULE_NAME, DEF_PUB_ID); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + + pubInfo->freq = -1; + ResetPubFlag(); + ret = PublishService(DEF_PUB_MODULE_NAME, pubInfo, &g_pubCallback); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_SUCCESS); + ret = UnPublishService(DEF_PUB_MODULE_NAME, DEF_PUB_ID); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + + free(pubInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_2100 + * @tc.name : test pubInfo-capability invalid value + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 3 + */ +LITE_TEST_CASE(SoftBusFuncTestSuite, testPublishInfoCapability, LEVEL3) +{ + PublishInfo *pubInfo = NULL; + pubInfo = (PublishInfo *)malloc(sizeof(PublishInfo)); + TEST_ASSERT_NOT_NULL(pubInfo); + (void)memset_s(pubInfo, sizeof(PublishInfo), 0, sizeof(PublishInfo)); + pubInfo->publishId = DEF_PUB_ID; + pubInfo->mode = DISCOVER_MODE_PASSIVE; + pubInfo->medium = COAP; + pubInfo->freq = MID; + pubInfo->capability = "hicall"; + pubInfo->capabilityData = g_pubCapabilityData; + pubInfo->dataLen = DEF_PUB_CAPABILITYDATA_LEN; + + ResetPubFlag(); + int ret = PublishService(DEF_PUB_MODULE_NAME, pubInfo, &g_pubCallback); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_SUCCESS); + + pubInfo->capability = "error capability"; + ResetPubFlag(); + ret = PublishService(DEF_PUB_MODULE_NAME, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + + pubInfo->capability = NULL; + ResetPubFlag(); + ret = PublishService(DEF_PUB_MODULE_NAME, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + + ret = UnPublishService(DEF_PUB_MODULE_NAME, DEF_PUB_ID); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + free(pubInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_2200 + * @tc.name : set capabilitydata value invalid + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 3 + */ +LITE_TEST_CASE(SoftBusFuncTestSuite, testPublishCapabilityDataError, LEVEL3) +{ + PublishInfo *pubInfo = NULL; + pubInfo = (PublishInfo *)malloc(sizeof(PublishInfo)); + TEST_ASSERT_NOT_NULL(pubInfo); + (void)memset_s(pubInfo, sizeof(PublishInfo), 0, sizeof(PublishInfo)); + pubInfo->publishId = DEF_PUB_ID; + pubInfo->mode = DISCOVER_MODE_PASSIVE; + pubInfo->medium = COAP; + pubInfo->freq = MID; + pubInfo->capability = DEF_PUB_CAPABILITY; + pubInfo->capabilityData = NULL; + pubInfo->dataLen = DEF_PUB_CAPABILITYDATA_LEN; + + ResetPubFlag(); + int ret = PublishService(DEF_PUB_MODULE_NAME, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + + pubInfo->capabilityData = (unsigned char *)"1"; + pubInfo->dataLen = DEF_PUB_CAPABILITYDATA_LEN - 1; + ResetPubFlag(); + ret = PublishService(DEF_PUB_MODULE_NAME, pubInfo, &g_pubCallback); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_SUCCESS); + + pubInfo->capabilityData = (unsigned char *)"123"; + pubInfo->dataLen = DEF_PUB_CAPABILITYDATA_LEN + 1; + ResetPubFlag(); + ret = PublishService(DEF_PUB_MODULE_NAME, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + + pubInfo->capabilityData = g_pubCapabilityData; + pubInfo->dataLen = DEF_PUB_CAPABILITYDATA_LEN - 1; + ResetPubFlag(); + ret = PublishService(DEF_PUB_MODULE_NAME, pubInfo, &g_pubCallback); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_FAIL); + + ret = UnPublishService(DEF_PUB_MODULE_NAME, DEF_PUB_ID); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + free(pubInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_2300 + * @tc.name : test unpublish invalid parameters + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SoftBusFuncTestSuite, testUnPublishInvalidParam, LEVEL2) +{ + PublishInfo *pubInfo = NULL; + pubInfo = (PublishInfo *)malloc(sizeof(PublishInfo)); + TEST_ASSERT_NOT_NULL(pubInfo); + (void)memset_s(pubInfo, sizeof(PublishInfo), 0, sizeof(PublishInfo)); + pubInfo->publishId = DEF_PUB_ID; + pubInfo->mode = DISCOVER_MODE_PASSIVE; + pubInfo->medium = COAP; + pubInfo->freq = MID; + pubInfo->capability = DEF_PUB_CAPABILITY; + pubInfo->capabilityData = g_pubCapabilityData; + pubInfo->dataLen = DEF_PUB_CAPABILITYDATA_LEN; + + ResetPubFlag(); + int ret = PublishService(DEF_PUB_MODULE_NAME, pubInfo, &g_pubCallback); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + TEST_ASSERT_EQUAL_INT(g_pubFlag, PUB_SUCCESS); + + ret = UnPublishService(DEF_PUB_MODULE_NAME, DEF_PUB_ID); + TEST_ASSERT_EQUAL_INT(ret, SOFTBUS_TEST_SUCCESS); + ret = UnPublishService(DEF_PUB_MODULE_NAME, DEF_PUB_ID); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + + ret = UnPublishService(NULL, DEF_PUB_ID); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + ret = UnPublishService(DEF_PUB_MODULE_NAME, -1); + TEST_ASSERT_NOT_EQUAL(ret, SOFTBUS_TEST_SUCCESS); + free(pubInfo); +} + +RUN_TEST_SUITE(SoftBusFuncTestSuite); diff --git a/communication_lite/softbus_posix/BUILD.gn b/communication_lite/softbus_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..b69a380c0b15d92e93767d9fd23bcab48112c9f1 --- /dev/null +++ b/communication_lite/softbus_posix/BUILD.gn @@ -0,0 +1,57 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsSoftBusTest") { + suite_name = "acts" + sources = [ + "src/ActsSoftBusTest.cpp", + ] + + include_dirs = [ + "//foundation/communication/services/softbus_lite/discovery/coap/include", + "//foundation/communication/services/softbus_lite/os_adapter/include", + "//foundation/communication/interfaces/kits/softbus_lite/discovery", + "//foundation/communication/interfaces/kits/softbus_lite/transport", + "//foundation/communication/services/softbus_lite/discovery/discovery_service/include", + "//foundation/communication/services/softbus_lite/authmanager/include", + "//foundation/communication/services/softbus_lite/trans_service/include/libdistbus", + "//foundation/communication/services/softbus_lite/trans_service/include/utils", + "//foundation/communication/services/softbus_lite/trans_service/source/libdistbus", + "//foundation/communication/services/softbus_lite/trans_service/source/utils", + "//third_party/cJSON", + "//third_party/mbedtls/include", + "//third_party/bounds_checking_function/include", + "//kernel/liteos_a/lib/libsec/include", + "//vendor/hisi/hi3861/hi3861/include", + "//vendor/hisi/hi3861/hi3861/third_party/lwip_sack/include", + "//vendor/hisi/hi3861/hi3861/third_party/cjson", + "//vendor/hisi/hi3861/hi3861/third_party/mbedtls/include", + "//base/startup/interfaces/kits/syspara_lite/include", + "//base/security/interfaces/innerkits/hichainsdk_lite", + "//base/security/services/hichainsdk_lite/source/huks_adapter/", + ] + + defines = [ + "_GNU_SOURCE" + ] + + deps = [ + "//foundation/communication/services/softbus_lite:softbus_lite", + "//base/security/frameworks/huks_lite/source:huks", + "//test/xts/tools/hcpptest:hcpptest", + ] + + cflags = [ "-Wno-error" ] +} diff --git a/communication_lite/softbus_posix/Test.json b/communication_lite/softbus_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..1bb1afc22c2af1a9cf7c565df71aadcf363dbb5e --- /dev/null +++ b/communication_lite/softbus_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for hcpptest demo test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/communication", + "target": "/test_root/communication" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/communication/ActsSoftBusTest.bin" + } +} \ No newline at end of file diff --git a/communication_lite/softbus_posix/src/ActsSoftBusTest.cpp b/communication_lite/softbus_posix/src/ActsSoftBusTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..37c8624b1289dcfe4a56799eecb448d094da7325 --- /dev/null +++ b/communication_lite/softbus_posix/src/ActsSoftBusTest.cpp @@ -0,0 +1,427 @@ +/** + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include "discovery_service.h" +#include "session.h" +#include "securec.h" +#include +#include +#include + +using namespace std; +using namespace testing::ext; + +static const int PUB_SUCCESS = 1; +static const int PUB_FAIL = -1; +static const int TESTCASE_COUNT = 18; +static const int ERROR_SESSION_ID = -1; +static const int SESSION_NAME_LEN = 64; +static const int DEVID_MAX_LEN = 96; +static const int SOFTBUS_TEST_SUCCESS = 0; +static const int SOFTBUS_TEST_FAIL = -1; +static const int ONE_SECOND = 1; +static const int DEF_TIMEOUT = 6; +static const int DEF_PUB_ID = 33113322; +static const int DEF_PUB_CAPABILITY_DATA_LEN = 2; + +static int g_pubFlag = 0; +static int g_caseExeCount = 0; +static const char* g_sessionName = "ohos"; +static const char* g_moduleName = "default_test_module_name"; +static const char* g_devType = "L0"; +static const char* g_devId = "sb_test_default_devid"; +static const char* g_devName = "sb_test_default_devname"; +static const char* g_pubModuleName = "sb_pub_module_name"; +static const char* g_pubCapability = "ddmpCapability"; +static unsigned char* g_pubCapabilityData = (unsigned char*)"Hi"; +static IPublishCallback g_pubCallback = {0}; +static struct ISessionListener *g_sessionListenerCallback = nullptr; + +static void ResetPubFlag(void) +{ + g_pubFlag = 0; +} + +static void WaitPublishResult(void) +{ + int timeout = DEF_TIMEOUT; + while (timeout > 0) { + sleep(ONE_SECOND); + timeout--; + if (g_pubFlag == PUB_SUCCESS || g_pubFlag == PUB_FAIL) { + printf("checkPublish:wait[%d].\n", DEF_TIMEOUT - timeout); + break; + } + } + if (timeout <= 0) { + printf("checkPublish:timeout!\n"); + } +} + +/** + * callback of publish success + */ +void SbPublishSuccess(int pubId) +{ + printf("[PubSuccess]publish success id[%d].\n", pubId); + g_pubFlag = PUB_SUCCESS; +} + +/** + * callback of publish fail + */ +void SbPublishFail(int pubId, PublishFailReason reason) +{ + printf("[PubFail]publish fail id[%d],reason[%d].\n", pubId, reason); + g_pubFlag = PUB_FAIL; +} + +/** + * callback of session opened + */ +int SbSessionOpened(int sessionId) +{ + printf("[Session opened]sid[%d].\n", sessionId); + return SOFTBUS_TEST_SUCCESS; +} + +/** + * callback of session closed + */ +void SbSessionClosed(int sessionId) +{ + printf("[Session closed]sid[%d].\n", sessionId); +} + +/** + * callback of received data + */ +void SbOnBytesReceived(int sessionId, const void *data, unsigned int len) +{ + printf("[Session recevie bytes]sid[%d], data len[%d].\n", sessionId, len); +} + +/** + * init service during first publish + */ +static void DefaultPublishToInitService(void) +{ + PublishInfo *pubInfo = NULL; + pubInfo = (PublishInfo *)malloc(sizeof(PublishInfo)); + if (pubInfo == NULL) { + printf("[DefaultPublishToInitService]malloc fail!\n"); + return; + } + (void)memset_s(pubInfo, sizeof(PublishInfo), 0, sizeof(PublishInfo)); + pubInfo->publishId = DEF_PUB_ID; + pubInfo->mode = DISCOVER_MODE_PASSIVE; + pubInfo->medium = COAP; + pubInfo->freq = MID; + pubInfo->capability = g_pubCapability; + pubInfo->capabilityData = g_pubCapabilityData; + pubInfo->dataLen = DEF_PUB_CAPABILITY_DATA_LEN; + + ResetPubFlag(); + int ret = PublishService(g_pubModuleName, pubInfo, &g_pubCallback); + if (ret != SOFTBUS_TEST_SUCCESS) { + printf("[DefaultPublishToInitService]call PublishService fail!\n"); + } else { + WaitPublishResult(); + if (g_pubFlag != PUB_SUCCESS) { + printf("[DefaultPublishToInitService]call PublishService fail!\n"); + ret = SOFTBUS_TEST_FAIL; + } + } + free(pubInfo); +} + +/** + * undo the first publish + */ +static void UnDefaultPublish(void) +{ + int ret = UnPublishService(g_pubModuleName, DEF_PUB_ID); + if (ret != SOFTBUS_TEST_SUCCESS) { + printf("[UnDefaultPublish]unpublish fail!\n"); + } +} + +class ActsSoftBusTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + g_pubCallback.onPublishSuccess = SbPublishSuccess; + g_pubCallback.onPublishFail = SbPublishFail; + g_sessionListenerCallback = (struct ISessionListener*)malloc(sizeof(struct ISessionListener)); + g_sessionListenerCallback->onSessionOpened = SbSessionOpened; + g_sessionListenerCallback->onSessionClosed = SbSessionClosed; + g_sessionListenerCallback->onBytesReceived = SbOnBytesReceived; + DefaultPublishToInitService(); + UnDefaultPublish(); + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + if (g_sessionListenerCallback != nullptr) { + free(g_sessionListenerCallback); + g_sessionListenerCallback = nullptr; + } + } + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_0100 + * @tc.name : abnormal parameter test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 3 + */ +HWTEST_F(ActsSoftBusTest, testSetNumGreaterThanMax, TestSize.Level3) +{ + CommonDeviceInfo *devInfo = NULL; + devInfo = (CommonDeviceInfo *)malloc(sizeof(CommonDeviceInfo)); + ASSERT_EQ(devInfo != NULL, true); + (void)memset_s(devInfo, sizeof(CommonDeviceInfo), 0, sizeof(CommonDeviceInfo)); + devInfo->key = COMM_DEVICE_KEY_DEVID; + devInfo->value = g_devId; + + int ret = SetCommonDeviceInfo(devInfo, COMM_DEVICE_KEY_MAX + 1); + EXPECT_NE(ret, SOFTBUS_TEST_SUCCESS); + int num = 0; + ret = SetCommonDeviceInfo(devInfo, num); + EXPECT_NE(ret, SOFTBUS_TEST_SUCCESS); + num = 1; + ret = SetCommonDeviceInfo(NULL, num); + EXPECT_NE(ret, SOFTBUS_TEST_SUCCESS); + free(devInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_0300 + * @tc.name : set ID value equal and greater maximum value + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 3 + */ +HWTEST_F(ActsSoftBusTest, testSetDevIdEqualMax, TestSize.Level3) +{ + CommonDeviceInfo *devInfo = NULL; + devInfo = (CommonDeviceInfo *)malloc(sizeof(CommonDeviceInfo)); + ASSERT_EQ(devInfo != NULL, true); + (void)memset_s(devInfo, sizeof(CommonDeviceInfo), 0, sizeof(CommonDeviceInfo)); + devInfo->key = COMM_DEVICE_KEY_DEVID; + devInfo->value = (char *) + "abcdef123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; + int num = 1; + int ret = SetCommonDeviceInfo(devInfo, num); + EXPECT_NE(ret, SOFTBUS_TEST_SUCCESS); + devInfo->value = (char *) + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890abcdefg"; + ret = SetCommonDeviceInfo(devInfo, num); + EXPECT_NE(ret, SOFTBUS_TEST_SUCCESS); + free(devInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_0600 + * @tc.name : set name value equal and greater maximum value + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 3 + */ +HWTEST_F(ActsSoftBusTest, testSetDevNameEqualMax, TestSize.Level3) +{ + CommonDeviceInfo *devInfo = NULL; + devInfo = (CommonDeviceInfo *)malloc(sizeof(CommonDeviceInfo)); + ASSERT_EQ(devInfo != NULL, true); + (void)memset_s(devInfo, sizeof(CommonDeviceInfo), 0, sizeof(CommonDeviceInfo)); + devInfo->key = COMM_DEVICE_KEY_DEVNAME; + devInfo->value = (char *)"abcd123456789012345678901234567890123456789012345678901234567890"; + int num = 1; + int ret = SetCommonDeviceInfo(devInfo, num); + EXPECT_NE(ret, SOFTBUS_TEST_SUCCESS); + + devInfo->value = (char *)"123456789012345678901234567890123456789012345678901234567890abcde"; + ret = SetCommonDeviceInfo(devInfo, num); + EXPECT_NE(ret, SOFTBUS_TEST_SUCCESS); + free(devInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_0800 + * @tc.name : set type value not in enum + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 3 + */ +HWTEST_F(ActsSoftBusTest, testSetDevTypeError, TestSize.Level3) +{ + CommonDeviceInfo *devInfo = NULL; + devInfo = (CommonDeviceInfo *)malloc(sizeof(CommonDeviceInfo)); + ASSERT_EQ(devInfo != NULL, true); + (void)memset_s(devInfo, sizeof(CommonDeviceInfo), 0, sizeof(CommonDeviceInfo)); + devInfo->key = COMM_DEVICE_KEY_DEVTYPE; + devInfo->value = (char *)"error"; + int num = 1; + int ret = SetCommonDeviceInfo(devInfo, num); + EXPECT_NE(ret, SOFTBUS_TEST_SUCCESS); + free(devInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_1000 + * @tc.name : set key is error + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(ActsSoftBusTest, testSetDevKeyIsError, TestSize.Level2) +{ + CommonDeviceInfo *devInfo = NULL; + devInfo = (CommonDeviceInfo *)malloc(sizeof(CommonDeviceInfo)); + ASSERT_EQ(devInfo != NULL, true); + (void)memset_s(devInfo, sizeof(CommonDeviceInfo), 0, sizeof(CommonDeviceInfo)); + devInfo->key = COMM_DEVICE_KEY_MAX; + devInfo->value = g_devId; + unsigned int num = 1; + int ret = SetCommonDeviceInfo(devInfo, num); + EXPECT_NE(ret, SOFTBUS_TEST_SUCCESS); + free(devInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_1300 + * @tc.name : Test publish with invalid parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(ActsSoftBusTest, testPublishParameterIsNull, TestSize.Level2) +{ + PublishInfo *pubInfo = NULL; + pubInfo = (PublishInfo *)malloc(sizeof(PublishInfo)); + ASSERT_EQ(pubInfo!= NULL, true); + (void)memset_s(pubInfo, sizeof(PublishInfo), 0, sizeof(PublishInfo)); + pubInfo->publishId = DEF_PUB_ID; + pubInfo->mode = DISCOVER_MODE_PASSIVE; + pubInfo->medium = COAP; + pubInfo->freq = MID; + pubInfo->capability = g_pubCapability; + pubInfo->capabilityData = g_pubCapabilityData; + pubInfo->dataLen = DEF_PUB_CAPABILITY_DATA_LEN; + + ResetPubFlag(); + int ret = PublishService(NULL, pubInfo, &g_pubCallback); + EXPECT_NE(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + EXPECT_EQ(g_pubFlag, PUB_FAIL); + ret = PublishService(g_pubModuleName, NULL, &g_pubCallback); + EXPECT_NE(ret, SOFTBUS_TEST_SUCCESS); + ret = PublishService(g_pubModuleName, pubInfo, NULL); + EXPECT_NE(ret, SOFTBUS_TEST_SUCCESS); + ret = PublishService(NULL, NULL, NULL); + EXPECT_NE(ret, SOFTBUS_TEST_SUCCESS); + free(pubInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_1500 + * @tc.name : set package name value equal and greater than maximum value(64,65) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(ActsSoftBusTest, testPublishPkgNameAbnormal, TestSize.Level2) +{ + PublishInfo *pubInfo = NULL; + pubInfo = (PublishInfo *)malloc(sizeof(PublishInfo)); + ASSERT_EQ(pubInfo!= NULL, true); + (void)memset_s(pubInfo, sizeof(PublishInfo), 0, sizeof(PublishInfo)); + pubInfo->publishId = DEF_PUB_ID; + pubInfo->mode = DISCOVER_MODE_PASSIVE; + pubInfo->medium = COAP; + pubInfo->freq = MID; + pubInfo->capability = g_pubCapability; + pubInfo->capabilityData = g_pubCapabilityData; + pubInfo->dataLen = DEF_PUB_CAPABILITY_DATA_LEN; + + ResetPubFlag(); + int ret = PublishService(NULL, pubInfo, &g_pubCallback); + EXPECT_NE(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + EXPECT_EQ(g_pubFlag, PUB_FAIL); + + ResetPubFlag(); + const char *pkgNameMax = "123456789012345678901234567890123456789012345678901234567890abcd"; + ret = PublishService(pkgNameMax, pubInfo, &g_pubCallback); + EXPECT_NE(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + EXPECT_EQ(g_pubFlag, PUB_FAIL); + + ResetPubFlag(); + const char *pkgNameMoreMax = "abcde123456789012345678901234567890123456789012345678901234567890"; + ret = PublishService(pkgNameMoreMax, pubInfo, &g_pubCallback); + EXPECT_NE(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + EXPECT_EQ(g_pubFlag, PUB_FAIL); + + ret = UnPublishService(pkgNameMax, DEF_PUB_ID); + EXPECT_NE(ret, SOFTBUS_TEST_SUCCESS); + ret = UnPublishService(pkgNameMoreMax, DEF_PUB_ID); + EXPECT_NE(ret, SOFTBUS_TEST_SUCCESS); + free(pubInfo); +} + +/** + * @tc.number : SUB_COMMUNICATION_SOFTBUS_SDK_1700 + * @tc.name : set capability value not in list + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 3 + */ +HWTEST_F(ActsSoftBusTest, testPublishCapabilityError, TestSize.Level3) +{ + PublishInfo *pubInfo = NULL; + pubInfo = (PublishInfo *)malloc(sizeof(PublishInfo)); + EXPECT_EQ(pubInfo!= NULL, true); + (void)memset_s(pubInfo, sizeof(PublishInfo), 0, sizeof(PublishInfo)); + pubInfo->publishId = DEF_PUB_ID; + pubInfo->mode = DISCOVER_MODE_PASSIVE; + pubInfo->medium = COAP; + pubInfo->freq = MID; + pubInfo->capability = (char *)"error capability"; + pubInfo->capabilityData = g_pubCapabilityData; + pubInfo->dataLen = DEF_PUB_CAPABILITY_DATA_LEN; + + ResetPubFlag(); + int ret = PublishService(g_pubModuleName, pubInfo, &g_pubCallback); + EXPECT_NE(ret, SOFTBUS_TEST_SUCCESS); + WaitPublishResult(); + EXPECT_EQ(g_pubFlag, PUB_FAIL); + free(pubInfo); +} diff --git a/communication_lite/wifiservice_hal/BUILD.gn b/communication_lite/wifiservice_hal/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..746633f7324e7aea075c2ecaad3266fa8d114afe --- /dev/null +++ b/communication_lite/wifiservice_hal/BUILD.gn @@ -0,0 +1,29 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") +hctest_suite("ActsWifiServiceTest") { + suite_name = "acts" + sources = [ + "src/wifiservice_func_test.c", + ] + + include_dirs = [ + "//foundation/communication/interfaces/kits/wifi_lite/wifiservice", + "//vendor/hisi/hi3861/hi3861/third_party/lwip_sack/include", + "//kernel/liteos_m/components/cmsis", + "//kernel/liteos_m/components/cmsis/2.0", + ] + + cflags = [ "-Wno-error" ] +} diff --git a/communication_lite/wifiservice_hal/Test.tmpl b/communication_lite/wifiservice_hal/Test.tmpl new file mode 100755 index 0000000000000000000000000000000000000000..be8407e1286041a5af2bdc75a15633337376eb9d --- /dev/null +++ b/communication_lite/wifiservice_hal/Test.tmpl @@ -0,0 +1,19 @@ +{ + "description": "Config for $module test cases", + "environment": [ + { + "type": "device", + "label": "wifiiot" + } + ], + "kits": [ + { + "type": "DeployKit", + "timeout": "20000", + "burn_file": "$subsystem/$module.bin" + } + ], + "driver": { + "type": "CTestLite" + } +} \ No newline at end of file diff --git a/communication_lite/wifiservice_hal/src/wifiservice_func_test.c b/communication_lite/wifiservice_hal/src/wifiservice_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..04f9b23b9c8ff563427aed2d50f7f9d03b675db9 --- /dev/null +++ b/communication_lite/wifiservice_hal/src/wifiservice_func_test.c @@ -0,0 +1,724 @@ +/* + * Copyright (c) 2020 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 "hctest.h" +#include "hos_types.h" +#include "wifi_device.h" +#include "wifi_hotspot.h" +#include "lwip/netif.h" +#include "lwip/netifapi.h" +#include "lwip/ip4_addr.h" +#include "cmsis_os2.h" +#include + +#define DEF_TIMEOUT 15 +#define ONE_SECOND 1 +#define LEVEL_ERROR (-1) +#define LEVEL_ONE 1 +#define LEVEL_TWO 2 +#define LEVEL_THREE 3 +#define LEVEL_FOUR 4 +#define DEF_TASK_STACK 2000 +#define DEF_TASK_PRIORITY 20 +#define DEPE_AP_SSID "xts_execute" +#define DEF_NET_IF "wlan0" + +static int g_apEnableSuccess = 0; +static int g_staScanSuccess = 0; +struct netif *g_wsNetInterface = NULL; +WifiEvent g_wifiEventHandler = {0}; + +/** + * callback task for wifi scan + */ +static void WifiScanStateTask(void) +{ + WifiScanInfo* info = malloc(sizeof(WifiScanInfo) * WIFI_SCAN_HOTSPOT_LIMIT); + if (info == NULL) { + printf("WifiScanStateTask:malloc fail.\n"); + return; + } + unsigned int checkSize = WIFI_SCAN_HOTSPOT_LIMIT; + WifiErrorCode error = GetScanInfoList(info, &checkSize); + if (error != WIFI_SUCCESS) { + printf("WifiScanStateTask:get info fail, error is %d.\n", error); + } else { + printf("WifiScanStateTask:get scan size is %d.\n", checkSize); + g_staScanSuccess = 1; + } + free(info); + info = NULL; +} + +/** + * callback task for connection + */ +static void WifiConnectionStateTask(void) +{ + WifiLinkedInfo linkInfo = {0}; + WifiErrorCode error = GetLinkedInfo(&linkInfo); + if (error != WIFI_SUCCESS) { + printf("WifiConnectionChanged:get link info fail, error is %d.\n", error); + return; + } + if (linkInfo.connState != WIFI_CONNECTED) { + printf("WifiConnectionChanged:connect fail!\n"); + return; + } + printf("WifiConnectionChanged:connect success.\n"); +} + +/** + * callback function for hotspot + */ +static void HotspotStateTask(void) +{ + StationInfo info[WIFI_MAX_STA_NUM] = {0}; + unsigned int size = WIFI_MAX_STA_NUM; + WifiErrorCode error = GetStationList(info, &size); + if (error != WIFI_SUCCESS) { + printf("HotspotStaJoin:get list fail, error is %d.\n", error); + return; + } + printf("HotspotStaJoin:list size is %d.\n", size); + g_apEnableSuccess++; +} + +/** + * callback function for wifi scan + */ +static void OnWifiScanStateChangedHandler(int state, int size) +{ + if (state != WIFI_STATE_AVALIABLE) { + printf("ScanStateChanged:state is unavaliable.\n"); + } else { + printf("ScanStateChanged:state[%d], size[%d].\n", state, size); + osThreadAttr_t attr; + attr.name = "WifiScanStateTask"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = DEF_TASK_STACK; + attr.priority = DEF_TASK_PRIORITY; + if (osThreadNew((osThreadFunc_t)WifiScanStateTask, NULL, &attr) == NULL) { + printf("ScanStateChanged:create task fail!\n"); + } + } +} + +/** + * callback function for wifi connection + */ +static void OnWifiConnectionChangedHandler(int state, WifiLinkedInfo* info) +{ + if (info == NULL) { + printf("WifiConnectionChanged:info is null, stat is %d.\n", state); + } else { + osThreadAttr_t attr; + attr.name = "WifiConnectionStateTask"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = DEF_TASK_STACK; + attr.priority = DEF_TASK_PRIORITY; + if (osThreadNew((osThreadFunc_t)WifiConnectionStateTask, NULL, &attr) == NULL) { + printf("WifiConnectionStateTask:create task fail!\n"); + } + } +} + +/** + * callback function for STA join AP + */ +static void OnHotspotStaJoinHandler(StationInfo* info) +{ + if (info == NULL) { + printf("HotspotStaJoin:info is null.\n"); + } else { + osThreadAttr_t attr; + attr.name = "HotspotStateTask"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = DEF_TASK_STACK; + attr.priority = DEF_TASK_PRIORITY; + if (osThreadNew((osThreadFunc_t)HotspotStateTask, NULL, &attr) == NULL) { + printf("HotspotStaJoin:create task fail!\n"); + } + } +} + +/** + * callback function for STA leave AP + */ +static void OnHotspotStaLeaveHandler(StationInfo* info) +{ + if (info == NULL) { + printf("HotspotStaLeave:info is null.\n"); + } else { + g_apEnableSuccess--; + } +} + +/** + * callback function for AP + */ +static void OnHotspotStateChangedHandler(int state) +{ + printf("HotspotStateChanged:state is %d.\n", state); +} + +/** + * common wait scan result + */ +static void WaitSacnResult(void) +{ + int scanTimeout = DEF_TIMEOUT; + while (scanTimeout > 0) { + sleep(ONE_SECOND); + scanTimeout--; + if (g_staScanSuccess == 1) { + printf("WaitSacnResult:wait success[%d]s\n", (DEF_TIMEOUT - scanTimeout)); + break; + } + } + if (scanTimeout <= 0) { + printf("WaitSacnResult:timeout!\n"); + } +} + +/** + * @tc.desc : register a test suite, this test suite is used to test basic functions + * @param : subsystem name is communication + * @param : module name is wifiaware + * @param : test suit name is WifiAwareReliTestSuite + */ +LITE_TEST_SUIT(communication, wifiservice, WifiServiceFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL WifiServiceFuncTestSuiteSetUp(void) +{ + g_wifiEventHandler.OnWifiScanStateChanged = OnWifiScanStateChangedHandler; + g_wifiEventHandler.OnWifiConnectionChanged = OnWifiConnectionChangedHandler; + g_wifiEventHandler.OnHotspotStaJoin = OnHotspotStaJoinHandler; + g_wifiEventHandler.OnHotspotStaLeave = OnHotspotStaLeaveHandler; + g_wifiEventHandler.OnHotspotStateChanged = OnHotspotStateChangedHandler; + WifiErrorCode error = RegisterWifiEvent(&g_wifiEventHandler); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + if (error != WIFI_SUCCESS) { + return FALSE; + } + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL WifiServiceFuncTestSuiteTearDown(void) +{ + WifiErrorCode error = UnRegisterWifiEvent(&g_wifiEventHandler); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + printf("+-------------------------------------------+\n"); + if (error != WIFI_SUCCESS) { + return FALSE; + } + return TRUE; +} + +/** + * @tc.number : SUB_COMMUNICATION_WIFISERVICE_SDK_0100 + * @tc.name : Test enable and disable wifi interface + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(WifiServiceFuncTestSuite, testEnableDisableWifi, LEVEL2) +{ + int stat = IsWifiActive(); + TEST_ASSERT_EQUAL_INT(stat, WIFI_STATE_NOT_AVALIABLE); + + WifiErrorCode error = EnableWifi(); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + stat = IsWifiActive(); + TEST_ASSERT_EQUAL_INT(stat, WIFI_STATE_AVALIABLE); + + error = EnableWifi(); + TEST_ASSERT_EQUAL_INT(error, ERROR_WIFI_BUSY); + stat = IsWifiActive(); + TEST_ASSERT_EQUAL_INT(stat, WIFI_STATE_AVALIABLE); + + error = DisableWifi(); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + stat = IsWifiActive(); + TEST_ASSERT_EQUAL_INT(stat, WIFI_STATE_NOT_AVALIABLE); + + error = DisableWifi(); + TEST_ASSERT_EQUAL_INT(error, ERROR_WIFI_NOT_STARTED); + stat = IsWifiActive(); + TEST_ASSERT_EQUAL_INT(stat, WIFI_STATE_NOT_AVALIABLE); +} + +/** + * @tc.number : SUB_COMMUNICATION_WIFISERVICE_SDK_0200 + * @tc.name : Test scan and get scan info interface + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(WifiServiceFuncTestSuite, testScan, LEVEL2) +{ + unsigned int size = WIFI_SCAN_HOTSPOT_LIMIT; + WifiErrorCode error = EnableWifi(); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + int stat = IsWifiActive(); + TEST_ASSERT_EQUAL_INT(stat, WIFI_STATE_AVALIABLE); + + WifiScanInfo* info = malloc(sizeof(WifiScanInfo) * WIFI_SCAN_HOTSPOT_LIMIT); + TEST_ASSERT_NOT_NULL(info); + error = GetScanInfoList(info, &size); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + TEST_ASSERT_EQUAL_INT(size, 0); + + g_staScanSuccess = 0; + error = Scan(); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + WaitSacnResult(); + TEST_ASSERT_EQUAL_INT(g_staScanSuccess, 1); + + size = WIFI_SCAN_HOTSPOT_LIMIT; + error = GetScanInfoList(info, &size); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + TEST_ASSERT_NOT_EQUAL(size, WIFI_SCAN_HOTSPOT_LIMIT); + free(info); + + error = DisableWifi(); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + stat = IsWifiActive(); + TEST_ASSERT_EQUAL_INT(stat, WIFI_STATE_NOT_AVALIABLE); +} + +/** + * @tc.number : SUB_COMMUNICATION_WIFISERVICE_SDK_0300 + * @tc.name : Test connect and disconnect interface + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(WifiServiceFuncTestSuite, testConnectDisConnect, LEVEL2) +{ + int netId = 0; + int ssidLen = 11; + WifiErrorCode error; + WifiDeviceConfig config = {0}; + int ret = memcpy_s(config.ssid, WIFI_MAX_SSID_LEN, "xts_execute", ssidLen); + TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS); + config.securityType = WIFI_SEC_TYPE_OPEN; + error = AddDeviceConfig(&config, &netId); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + + error = ConnectTo(netId); + TEST_ASSERT_NOT_EQUAL(error, WIFI_SUCCESS); + unsigned char mac[WIFI_MAC_LEN]; + error = GetDeviceMacAddress((unsigned char *)mac); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + error = Disconnect(); + TEST_ASSERT_NOT_EQUAL(error, WIFI_SUCCESS); + error = RemoveDevice(netId); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); +} + +/** + * @tc.number : SUB_COMMUNICATION_WIFISERVICE_SDK_0400 + * @tc.name : Test handle device config interface + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(WifiServiceFuncTestSuite, testHandleDeviceConfig, LEVEL2) +{ + int netId = 0; + int ssidLen = 11; + int keyLen = 8; + int freq = 20; + unsigned char bssid[WIFI_MAC_LEN] = {0xac, 0x75, 0x1d, 0xd8, 0x55, 0xc1}; + WifiDeviceConfig config = {0}; + config.freq = freq; + config.securityType = WIFI_SEC_TYPE_SAE; + config.wapiPskType = WIFI_PSK_TYPE_ASCII; + int ret = memcpy_s(config.ssid, WIFI_MAX_SSID_LEN, "XtsTestWifi", ssidLen); + TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS); + ret = memcpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, "12345678", keyLen); + TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS); + ret = memcpy_s(config.bssid, WIFI_MAC_LEN, bssid, WIFI_MAC_LEN); + TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS); + WifiErrorCode error = AddDeviceConfig(&config, &netId); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + + ssidLen += 1; + int addCount = 9; + for (int i = 0; i < addCount; i++) { + config.securityType = WIFI_SEC_TYPE_PSK; + config.wapiPskType = WIFI_PSK_TYPE_HEX; + ret = memcpy_s(config.ssid, WIFI_MAX_SSID_LEN, "XtsTestWifi2", ssidLen); + TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS); + ret = memcpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, "01234567", keyLen); + TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS); + error = AddDeviceConfig(&config, &netId); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + if (error != WIFI_SUCCESS) { + printf("Add fail[%d].\n", i); + break; + } + } + + ret = memcpy_s(config.ssid, WIFI_MAX_SSID_LEN, "XtsTestWifi3", ssidLen); + TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS); + ret = memcpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, "01234567", keyLen); + TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS); + config.securityType = WIFI_SEC_TYPE_PSK; + error = AddDeviceConfig(&config, &netId); + TEST_ASSERT_EQUAL_INT(error, ERROR_WIFI_BUSY); + + WifiDeviceConfig allConfig[WIFI_MAX_CONFIG_SIZE] = {0}; + unsigned int size = WIFI_MAX_CONFIG_SIZE; + error = GetDeviceConfigs(allConfig, &size); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + TEST_ASSERT_EQUAL_INT(size, WIFI_MAX_CONFIG_SIZE); + + for (int i = 0; i < WIFI_MAX_CONFIG_SIZE; i++) { + error = RemoveDevice(allConfig[i].netId); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + } + + error = GetDeviceConfigs(allConfig, &size); + TEST_ASSERT_EQUAL_INT(error, ERROR_WIFI_NOT_AVAILABLE); +} + +/** + * @tc.number : SUB_COMMUNICATION_WIFISERVICE_SDK_0500 + * @tc.name : Test handle AP config interface + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(WifiServiceFuncTestSuite, testHandleHotspotConfig, LEVEL2) +{ + int keyLen = 9; + int ssidLen = 10; + HotspotConfig config = {0}; + int ret = memcpy_s(config.ssid, WIFI_MAX_SSID_LEN, "XtsTestAp", ssidLen); + TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS); + ret = memcpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, "12345678", keyLen); + TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS); + config.securityType = WIFI_SEC_TYPE_PSK; + WifiErrorCode error = SetHotspotConfig(&config); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + + HotspotConfig getConfig = {0}; + error = GetHotspotConfig(&getConfig); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + TEST_ASSERT_EQUAL_INT(config.securityType, WIFI_SEC_TYPE_PSK); + + int band = 11; + int bandOrig = 11; + error = SetBand(band); + TEST_ASSERT_NOT_EQUAL(error, WIFI_SUCCESS); + error = GetBand(&band); + TEST_ASSERT_NOT_EQUAL(error, WIFI_SUCCESS); + TEST_ASSERT_EQUAL_INT(band, bandOrig); + + error = SetBand(HOTSPOT_BAND_TYPE_2G); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + error = GetBand(&band); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + TEST_ASSERT_EQUAL_INT(band, HOTSPOT_BAND_TYPE_2G); + + HotspotConfig getConfigAgain = {0}; + error = GetHotspotConfig(&getConfigAgain); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + TEST_ASSERT_EQUAL_INT(getConfigAgain.band, HOTSPOT_BAND_TYPE_2G); +} + +/** + * @tc.number : SUB_COMMUNICATION_WIFISERVICE_SDK_0600 + * @tc.name : Test enable and disable AP interface + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(WifiServiceFuncTestSuite, testEnableDisableHotSpot, LEVEL2) +{ + int ssidLen = 10; + int keyLen = 9; + HotspotConfig config = {0}; + int ret = memcpy_s(config.ssid, WIFI_MAX_SSID_LEN, "XtsTestAp", ssidLen); + TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS); + ret = memcpy_s(config.preSharedKey, WIFI_MAX_KEY_LEN, "12345678", keyLen); + TEST_ASSERT_EQUAL_INT(ret, WIFI_SUCCESS); + config.securityType = WIFI_SEC_TYPE_PSK; + WifiErrorCode error = SetHotspotConfig(&config); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + + int stat = IsHotspotActive(); + TEST_ASSERT_EQUAL_INT(stat, WIFI_HOTSPOT_NOT_ACTIVE); + error = EnableHotspot(); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + stat = IsHotspotActive(); + TEST_ASSERT_EQUAL_INT(stat, WIFI_HOTSPOT_ACTIVE); + error = EnableHotspot(); + TEST_ASSERT_NOT_EQUAL(error, WIFI_SUCCESS); + stat = IsHotspotActive(); + TEST_ASSERT_EQUAL_INT(stat, WIFI_HOTSPOT_ACTIVE); + + int timeout = 3; + g_apEnableSuccess = 0; + while (timeout > 0) { + sleep(ONE_SECOND); + timeout--; + if (g_apEnableSuccess >= 1) { + printf("Wait %d seconds.\n", (DEF_TIMEOUT - timeout)); + break; + } + } + + error = DisableHotspot(); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + stat = IsHotspotActive(); + TEST_ASSERT_EQUAL_INT(stat, WIFI_HOTSPOT_NOT_ACTIVE); + error = DisableHotspot(); + TEST_ASSERT_NOT_EQUAL(error, WIFI_SUCCESS); + stat = IsHotspotActive(); + TEST_ASSERT_EQUAL_INT(stat, WIFI_HOTSPOT_NOT_ACTIVE); +} + +/** + * @tc.number : SUB_COMMUNICATION_WIFISERVICE_SDK_0700 + * @tc.name : Test get signal Level interface + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(WifiServiceFuncTestSuite, testGetSignalLevel, LEVEL2) +{ + int level; + int rssiNoLevel = -90; + int rssiOf2gLevel1 = -88; + int rssiOf2gLevel2 = -82; + int rssiOf2gLevel3 = -75; + int rssiOf5gLevel1 = -85; + int rssiOf5gLevel2 = -79; + int rssiOf5gLevel3 = -72; + int rssiBothLevel4 = -65; + + level = GetSignalLevel(rssiNoLevel, HOTSPOT_BAND_TYPE_2G); + TEST_ASSERT_EQUAL_INT(level, LEVEL_ERROR); + level = GetSignalLevel(rssiOf2gLevel1, HOTSPOT_BAND_TYPE_2G); + TEST_ASSERT_EQUAL_INT(level, LEVEL_ONE); + level = GetSignalLevel(rssiOf2gLevel2, HOTSPOT_BAND_TYPE_2G); + TEST_ASSERT_EQUAL_INT(level, LEVEL_TWO); + level = GetSignalLevel(rssiOf2gLevel3, HOTSPOT_BAND_TYPE_2G); + TEST_ASSERT_EQUAL_INT(level, LEVEL_THREE); + level = GetSignalLevel(rssiBothLevel4, HOTSPOT_BAND_TYPE_2G); + TEST_ASSERT_EQUAL_INT(level, LEVEL_FOUR); + + level = GetSignalLevel(rssiNoLevel, HOTSPOT_BAND_TYPE_5G); + TEST_ASSERT_EQUAL_INT(level, -1); + level = GetSignalLevel(rssiOf5gLevel1, HOTSPOT_BAND_TYPE_5G); + TEST_ASSERT_EQUAL_INT(level, LEVEL_ONE); + level = GetSignalLevel(rssiOf5gLevel2, HOTSPOT_BAND_TYPE_5G); + TEST_ASSERT_EQUAL_INT(level, LEVEL_TWO); + level = GetSignalLevel(rssiOf5gLevel3, HOTSPOT_BAND_TYPE_5G); + TEST_ASSERT_EQUAL_INT(level, LEVEL_THREE); + level = GetSignalLevel(rssiBothLevel4, HOTSPOT_BAND_TYPE_5G); + TEST_ASSERT_EQUAL_INT(level, LEVEL_FOUR); +} + +/** + * @tc.number : SUB_COMMUNICATION_WIFISERVICE_SDK_0800 + * @tc.name : test adavance scan interface + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(WifiServiceFuncTestSuite, testAdvanceScanType, LEVEL2) +{ + WifiErrorCode error = EnableWifi(); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + int stat = IsWifiActive(); + TEST_ASSERT_EQUAL_INT(stat, WIFI_STATE_AVALIABLE); + + int freq = 2460; + WifiScanParams scanParams = {0}; + char bssid[WIFI_MAC_LEN] = {0xac, 0x75, 0x1d, 0xd8, 0x55, 0xc1}; + strcpy_s(scanParams.ssid, sizeof(scanParams.ssid), "wifi_service_xts"); + scanParams.ssidLen = strlen(scanParams.ssid); + scanParams.freqs = freq; + memcpy_s(scanParams.bssid, sizeof(scanParams.bssid), bssid, sizeof(bssid)); + + scanParams.scanType = WIFI_SSID_SCAN; + g_staScanSuccess = 0; + error = AdvanceScan(&scanParams); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + WaitSacnResult(); + TEST_ASSERT_EQUAL_INT(g_staScanSuccess, 1); + + scanParams.scanType = WIFI_FREQ_SCAN; + g_staScanSuccess = 0; + error = AdvanceScan(&scanParams); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + WaitSacnResult(); + TEST_ASSERT_EQUAL_INT(g_staScanSuccess, 1); + + scanParams.scanType = WIFI_BSSID_SCAN; + g_staScanSuccess = 0; + error = AdvanceScan(&scanParams); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + WaitSacnResult(); + TEST_ASSERT_EQUAL_INT(g_staScanSuccess, 1); + + scanParams.scanType = WIFI_BAND_SCAN; + g_staScanSuccess = 0; + error = AdvanceScan(&scanParams); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + WaitSacnResult(); + TEST_ASSERT_EQUAL_INT(g_staScanSuccess, 1); + + error = DisableWifi(); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + stat = IsWifiActive(); + TEST_ASSERT_EQUAL_INT(stat, WIFI_STATE_NOT_AVALIABLE); +} + +/** + * @tc.number : SUB_COMMUNICATION_WIFISERVICE_SDK_0900 + * @tc.name : test adavance scan interface with invalid parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(WifiServiceFuncTestSuite, testAdvanceScanInvalidParam01, LEVEL2) +{ + WifiErrorCode error = EnableWifi(); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + int stat = IsWifiActive(); + TEST_ASSERT_EQUAL_INT(stat, WIFI_STATE_AVALIABLE); + + g_staScanSuccess = 0; + error = AdvanceScan(NULL); + TEST_ASSERT_EQUAL_INT(error, ERROR_WIFI_UNKNOWN); + TEST_ASSERT_EQUAL_INT(g_staScanSuccess, 0); + + WifiScanParams scanParams = {0}; + error = AdvanceScan(&scanParams); + TEST_ASSERT_EQUAL_INT(error, ERROR_WIFI_UNKNOWN); + TEST_ASSERT_EQUAL_INT(g_staScanSuccess, 0); + + error = DisableWifi(); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + stat = IsWifiActive(); + TEST_ASSERT_EQUAL_INT(stat, WIFI_STATE_NOT_AVALIABLE); +} + +/** + * @tc.number : SUB_COMMUNICATION_WIFISERVICE_SDK_1000 + * @tc.name : test adavance scan interface with invalid parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(WifiServiceFuncTestSuite, testAdvanceScanInvalidParam02, LEVEL2) +{ + WifiErrorCode error = EnableWifi(); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + int stat = IsWifiActive(); + TEST_ASSERT_EQUAL_INT(stat, WIFI_STATE_AVALIABLE); + + WifiScanParams* scanParams = malloc(sizeof(WifiScanParams)); + TEST_ASSERT_NOT_NULL(scanParams); + memset_s(scanParams, sizeof(WifiScanParams), 0, sizeof(WifiScanParams)); + + g_staScanSuccess = 0; + error = AdvanceScan(scanParams); + TEST_ASSERT_EQUAL_INT(error, ERROR_WIFI_UNKNOWN); + TEST_ASSERT_EQUAL_INT(g_staScanSuccess, 0); + + scanParams->scanType = WIFI_BSSID_SCAN; + error = AdvanceScan(scanParams); + TEST_ASSERT_EQUAL_INT(error, ERROR_WIFI_UNKNOWN); + TEST_ASSERT_EQUAL_INT(g_staScanSuccess, 0); + + scanParams->scanType = WIFI_SSID_SCAN; + error = AdvanceScan(scanParams); + TEST_ASSERT_EQUAL_INT(error, ERROR_WIFI_UNKNOWN); + TEST_ASSERT_EQUAL_INT(g_staScanSuccess, 0); + + scanParams->scanType = WIFI_FREQ_SCAN; + error = AdvanceScan(scanParams); + TEST_ASSERT_EQUAL_INT(error, ERROR_WIFI_UNKNOWN); + TEST_ASSERT_EQUAL_INT(g_staScanSuccess, 0); + + scanParams->scanType = WIFI_BAND_SCAN; + error = AdvanceScan(scanParams); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + TEST_ASSERT_EQUAL_INT(g_staScanSuccess, 0); + + int errorType = -1; + scanParams->scanType = errorType; + error = AdvanceScan(scanParams); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + TEST_ASSERT_EQUAL_INT(g_staScanSuccess, 0); + + char bssid[WIFI_MAC_LEN] = {0xac, 0x75, 0x1d, 0xd8, 0x55, 0xc1}; + memcpy_s(scanParams->bssid, sizeof(scanParams->bssid), bssid, sizeof(bssid)); + scanParams->scanType = WIFI_BSSID_SCAN; + error = AdvanceScan(scanParams); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + WaitSacnResult(); + TEST_ASSERT_EQUAL_INT(g_staScanSuccess, 1); + + memset_s(scanParams, sizeof(WifiScanParams), 0, sizeof(WifiScanParams)); + strcpy_s(scanParams->ssid, sizeof(scanParams->ssid), "wifi_service_xts"); + scanParams->scanType = WIFI_SSID_SCAN; + g_staScanSuccess = 0; + error = AdvanceScan(scanParams); + TEST_ASSERT_EQUAL_INT(error, ERROR_WIFI_UNKNOWN); + TEST_ASSERT_EQUAL_INT(g_staScanSuccess, 0); + + error = DisableWifi(); + TEST_ASSERT_EQUAL_INT(error, WIFI_SUCCESS); + stat = IsWifiActive(); + TEST_ASSERT_EQUAL_INT(stat, WIFI_STATE_NOT_AVALIABLE); + + free(scanParams); +} + +RUN_TEST_SUITE(WifiServiceFuncTestSuite); diff --git a/distributedschedule_lite/samgr_hal/BUILD.gn b/distributedschedule_lite/samgr_hal/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..db255e705cde0346c04bb4b1356345231d4e84e8 --- /dev/null +++ b/distributedschedule_lite/samgr_hal/BUILD.gn @@ -0,0 +1,68 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hctest_suite("ActsSamgrTest") { + suite_name = "acts" + sources = [ + "utils/samgr_maintenance.c", + + "src/service_func_test.c", + "src/feature_func_test.c", + "src/defaultfeatureapi_func_test.c", + "src/featureapi_func_test.c", + "src/iunknown_func_test.c", + + "src/sendrequest_func_test.c", + "src/sendresponse_func_test.c", + "src/sendsharerequest_func_test.c", + + "src/broadcast_subscribe_func_test.c", + "src/broadcast_publish_func_test.c", + + "src/taskpool_notask_func_test.c", + "src/taskpool_singletask_func_test.c", + "src/taskpool_specifiedtask_func_test.c", + "src/taskpool_sharedtask_func_test.c", + + "src/common_func_test.c", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "//third_party/unity/src", + "//kernel/liteos_m/components/cmsis", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/samgr", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/communication/broadcast", + "//foundation/distributedschedule/services/samgr_lite/samgr/adapter", + "//foundation/distributedschedule/services/samgr_lite/samgr/source", + "//vendor/hisi/hi3861/hi3861/include", + "//vendor/hisi/hi3861/hi3861/components/lwip_sack/include", + "//kernel/liteos_m/components/cmsis/2.0", + "src", + "utils", + ] + deps = [ + "//test/xts/tools/hctest:hctest", + ] + public_deps = [ + "//foundation/distributedschedule/services/samgr_lite/samgr/adapter:samgr_adapter", + ] + defines = [ + "UNITY_INCLUDE_CONFIG_H", + ] + + cflags = [ "-Wno-error" ] +} + diff --git a/distributedschedule_lite/samgr_hal/Test.tmpl b/distributedschedule_lite/samgr_hal/Test.tmpl new file mode 100755 index 0000000000000000000000000000000000000000..be8407e1286041a5af2bdc75a15633337376eb9d --- /dev/null +++ b/distributedschedule_lite/samgr_hal/Test.tmpl @@ -0,0 +1,19 @@ +{ + "description": "Config for $module test cases", + "environment": [ + { + "type": "device", + "label": "wifiiot" + } + ], + "kits": [ + { + "type": "DeployKit", + "timeout": "20000", + "burn_file": "$subsystem/$module.bin" + } + ], + "driver": { + "type": "CTestLite" + } +} \ No newline at end of file diff --git a/distributedschedule_lite/samgr_hal/src/broadcast_publish_func_test.c b/distributedschedule_lite/samgr_hal/src/broadcast_publish_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..27a8e4b6c94ce1488e7b5575d2bf462078a7d339 --- /dev/null +++ b/distributedschedule_lite/samgr_hal/src/broadcast_publish_func_test.c @@ -0,0 +1,367 @@ +/** + * Copyright (c) 2020 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. + * + * Description : testcases for distributedschedule_lite subsystem + * Create : 2020/04/19 + */ + +#include +#include "hctest.h" +#include "samgr_lite.h" +#include "broadcast_interface.h" + +#define PRESSURE_BASE (1024 * 10) +#define TEST_LEN 10 +#define OPER_INTERVAL 200 +#define BROADCASR_TEST_SERVICE "S_broadcast2" + +static void C1Callback(Consumer *consumer, const Topic *topic, const Request *request) +{ + (void)consumer; + (void)topic; + (void)request; +} +static void C2Callback(Consumer *consumer, const Topic *topic, const Request *request) +{ + (void)consumer; + (void)topic; + (void)request; +} + +static BOOL Equal(const Consumer *current, const Consumer *other) +{ + if (current->Notify == other->Notify) { + return TRUE; + } else { + return FALSE; + } +} + +static const char *GetName(Service *service) +{ + (void)service; + return BROADCASR_TEST_SERVICE; +}; + +static Identity g_identity = { -1, -1, NULL}; + +static BOOL Initialize(Service *service, Identity identity) +{ + g_identity = identity; + (void)service; + return TRUE; +}; + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)service; + (void)msg; + return FALSE; +}; + +static TaskConfig GetTaskConfig(Service *service) +{ + TaskConfig config = {LEVEL_HIGH, PRI_NORMAL, 0x800, 20, SHARED_TASK}; // share with broadcast + (void)service; + return config; +}; + +static Service g_service = {GetName, Initialize, MessageHandle, GetTaskConfig}; +static void Init(void) +{ + BOOL result = SAMGR_GetInstance()->RegisterService(&g_service); + if (result == FALSE) { + printf("[hctest]E RegisterService failed.\n"); + } +} +SYSEX_SERVICE_INIT(Init); + +static PubSubInterface *CASE_GetIUnknown(void) +{ + PubSubInterface *fapi = NULL; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(BROADCAST_SERVICE, PUB_SUB_FEATURE); + if (iUnknown == NULL) { + printf("[hctest]CASE_GetIUnknown error "); + return NULL; + } + + int result = iUnknown->QueryInterface(iUnknown, 0, (void **)&fapi); + if (result != 0 || fapi == NULL) { + printf("[hctest]CASE_GetIUnknown error "); + } + return fapi; +} + +static void CASE_ReleaseIUnknown(PubSubInterface *fapi) +{ + fapi->Release((IUnknown *)fapi); +} + +LITE_TEST_SUIT(test, broadcast, Broadcast02TestSuite); + +static BOOL Broadcast02TestSuiteSetUp(void) +{ + LOS_Msleep(OPER_INTERVAL); + return TRUE; +} + +static BOOL Broadcast02TestSuiteTearDown(void) +{ + return TRUE; +} + +/** + * @tc.number : DMSLite_SAMGR_Publish_0010 + * @tc.name : Provider can publish a broadcast message + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(Broadcast02TestSuite, testPublish0010, LEVEL1) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == NULL) { + TEST_FAIL(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == NULL) { + TEST_FAIL(); + } + + Provider *provider = &fapi->provider; + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + static Consumer c2 = {.identity = &g_identity, .Notify = C2Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c2); + + BOOL result = provider->Publish((IUnknown *)fapi, &topic0, (uint8 *) "==>111<==", TEST_LEN); + TEST_ASSERT_EQUAL_INT(1, result); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_Publish_0020 + * @tc.name : Provider failed to publish broadcast for the specified topic not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(Broadcast02TestSuite, testPublish0020, LEVEL2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == NULL) { + TEST_FAIL(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == NULL) { + TEST_FAIL(); + } + + Provider *provider = &fapi->provider; + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + static Consumer c2 = {.identity = &g_identity, .Notify = C2Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c2); + + Topic noExisttopic = 99; + BOOL result = provider->Publish((IUnknown *)fapi, &noExisttopic, (uint8 *) "==>111<==", TEST_LEN); + TEST_ASSERT_EQUAL_INT(result, 0); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_Publish_0030 + * @tc.name : Provider failed to publish broadcast for len and data not match + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(Broadcast02TestSuite, testPublish0030, LEVEL2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == NULL) { + TEST_FAIL(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == NULL) { + TEST_FAIL(); + } + + Provider *provider = &fapi->provider; + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + static Consumer c2 = {.identity = &g_identity, .Notify = C2Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c2); + + BOOL result = provider->Publish((IUnknown *)fapi, &topic0, (uint8 *) "==>111<==", TEST_LEN - 1); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + result = provider->Publish((IUnknown *)fapi, &topic0, (uint8 *) "==>111<==", TEST_LEN + 1); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_Publish_0040 + * @tc.name : Provider publish broadcast successfully for 0 and max lenth message + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(Broadcast02TestSuite, testPublish0040, LEVEL2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == NULL) { + TEST_FAIL(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == NULL) { + TEST_FAIL(); + } + + Provider *provider = &fapi->provider; + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + static Consumer c2 = {.identity = &g_identity, .Notify = C2Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c2); + + BOOL result = provider->Publish((IUnknown *)fapi, &topic0, (uint8 *) "", 0); + TEST_ASSERT_EQUAL_INT(result, 0); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_Publish_0050 + * @tc.name : Provider publish broadcast successfully for no consumer + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(Broadcast02TestSuite, testPublish0050, LEVEL2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == NULL) { + TEST_FAIL(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == NULL) { + TEST_FAIL(); + } + + Provider *provider = &fapi->provider; + if (provider == NULL) { + printf("[hctest]E provider is NULL. \n"); + } + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + + BOOL result = provider->Publish((IUnknown *)fapi, &topic0, (uint8 *) "==>111<==", TEST_LEN); + TEST_ASSERT_EQUAL_INT(result, 1); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_Publish_0060 + * @tc.name : Provider publish broadcast successfully for multi consumers + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(Broadcast02TestSuite, testPublish0060, LEVEL2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == NULL) { + TEST_FAIL(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == NULL) { + TEST_FAIL(); + } + + Provider *provider = &fapi->provider; + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + static Consumer c2 = {.identity = &g_identity, .Notify = C2Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c2); + + BOOL result = provider->Publish((IUnknown *)fapi, &topic0, (uint8 *) "==>111<==", TEST_LEN); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_Publish_0070 + * @tc.name : Provider send broadcast repeatedly, no memory leak + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(Broadcast02TestSuite, testPublish0070, LEVEL2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == NULL) { + TEST_FAIL(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == NULL) { + TEST_FAIL(); + } + + Provider *provider = &fapi->provider; + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + static Consumer c2 = {.identity = &g_identity, .Notify = C2Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c2); + + for (int i = 0; i < PRESSURE_BASE; i++) { + BOOL result = provider->Publish((IUnknown *)fapi, &topic0, (uint8 *) "==>111<==", TEST_LEN); + TEST_ASSERT_EQUAL_INT(result, TRUE); + } + + CASE_ReleaseIUnknown(fapi); +} + +RUN_TEST_SUITE(Broadcast02TestSuite); \ No newline at end of file diff --git a/distributedschedule_lite/samgr_hal/src/broadcast_subscribe_func_test.c b/distributedschedule_lite/samgr_hal/src/broadcast_subscribe_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..f8d85d11c31c4d9fa65550c6ec591e4cab6489df --- /dev/null +++ b/distributedschedule_lite/samgr_hal/src/broadcast_subscribe_func_test.c @@ -0,0 +1,572 @@ +/** + * Copyright (c) 2020 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. + * + * Description : testcases for distributedschedule_lite subsystem + * Create : 2020/04/19 + */ + +#include +#include "hctest.h" +#include "samgr_lite.h" +#include "broadcast_interface.h" + +#define TEST_LEN 10 +#define OPER_INTERVAL 200 +#define BROADCASR_TEST_SERVICE "S_broadcast1" + +static void C1Callback(Consumer *consumer, const Topic *topic, const Request *request) +{ + (void)consumer; + (void)topic; + (void)request; +} +static void C2Callback(Consumer *consumer, const Topic *topic, const Request *request) +{ + (void)consumer; + (void)topic; + (void)request; +} + +static BOOL Equal(const Consumer *current, const Consumer *other) +{ + if (current->Notify == other->Notify) { + return TRUE; + } else { + return FALSE; + } +} + +static const char *GetName(Service *service) +{ + (void)service; + return BROADCASR_TEST_SERVICE; +}; + +static Identity g_identity = { -1, -1, NULL}; +static BOOL Initialize(Service *service, Identity identity) +{ + g_identity = identity; + (void)service; + return TRUE; +}; + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)service; + (void)msg; + return FALSE; +}; + +static TaskConfig GetTaskConfig(Service *service) +{ + TaskConfig config = {LEVEL_HIGH, PRI_NORMAL, 0x800, 20, SHARED_TASK}; // share with broadcast + (void)service; + return config; +}; + +static Service g_service = {GetName, Initialize, MessageHandle, GetTaskConfig}; +static void Init(void) +{ + BOOL result = SAMGR_GetInstance()->RegisterService(&g_service); + if (result == FALSE) { + printf("[hctest]E RegisterService failed. \n"); + } +} +SYSEX_SERVICE_INIT(Init); + +static PubSubInterface *CASE_GetIUnknown(void) +{ + PubSubInterface *fapi = NULL; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(BROADCAST_SERVICE, PUB_SUB_FEATURE); + if (iUnknown == NULL) { + printf("[hctest]failed to GetIUnknown "); + return NULL; + } + + int result = iUnknown->QueryInterface(iUnknown, 0, (void **)&fapi); + if (result != 0 || fapi == NULL) { + printf("[hctest]failed to QueryInterface "); + } + return fapi; +} + +static void CASE_ReleaseIUnknown(PubSubInterface *fapi) +{ + fapi->Release((IUnknown *)fapi); +} + +LITE_TEST_SUIT(test, broadcast, Broadcast01TestSuite); + +static BOOL Broadcast01TestSuiteSetUp(void) +{ + LOS_Msleep(OPER_INTERVAL); + + return TRUE; +} + +static BOOL Broadcast01TestSuiteTearDown(void) +{ + return TRUE; +} + +/** + * @tc.number : DMSLite_SAMGR_AddTopic_0010 + * @tc.name : Valid topic can be added successfully + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(Broadcast01TestSuite, testAddTopic0010, LEVEL1) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == NULL) { + TEST_FAIL(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == NULL) { + TEST_FAIL(); + } + + Topic topic0 = 11; + int result = subscriber->AddTopic((IUnknown *)fapi, &topic0); + TEST_ASSERT_EQUAL_INT(result == 0, TRUE); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_AddTopic_0020 + * @tc.name : Topic which is NULL or already existing can not be added + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(Broadcast01TestSuite, testAddTopic0020, LEVEL2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == NULL) { + TEST_FAIL(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == NULL) { + TEST_FAIL(); + } + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + + int result = subscriber->AddTopic((IUnknown *)fapi, NULL); + TEST_ASSERT_EQUAL_INT(result != 0, TRUE); + + result = subscriber->AddTopic((IUnknown *)fapi, &topic0); + TEST_ASSERT_EQUAL_INT(result != 0, TRUE); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_Subscribe_0010 + * @tc.name : Consumer can subscribe to a topic + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(Broadcast01TestSuite, testSubscribe0010, LEVEL1) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == NULL) { + TEST_FAIL(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == NULL) { + TEST_FAIL(); + } + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + + Topic topic0 = 9; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + int result = subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + TEST_ASSERT_EQUAL_INT(result == 0, TRUE); + + subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_Subscribe_0020 + * @tc.name : Consumer can not subscribe to the topic which is NULL or does not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(Broadcast01TestSuite, testSubscribe0020, LEVEL2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == NULL) { + TEST_FAIL(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == NULL) { + TEST_FAIL(); + } + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + int result = subscriber->Subscribe((IUnknown *)fapi, NULL, &c1); + TEST_ASSERT_EQUAL_INT(result != 0, TRUE); + + Topic noExistTopic = -200; + result = subscriber->Subscribe((IUnknown *)fapi, &noExistTopic, &c1); + TEST_ASSERT_EQUAL_INT(result != 0, TRUE); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_Subscribe_0030 + * @tc.name : Consumer which is NULL can not subscribe to a topic + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(Broadcast01TestSuite, testSubscribe0030, LEVEL2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == NULL) { + TEST_FAIL(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == NULL) { + TEST_FAIL(); + } + Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + int result = subscriber->Subscribe((IUnknown *)fapi, &topic0, NULL); + TEST_ASSERT_EQUAL_INT(result != 0, TRUE); + + subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_Subscribe_0040 + * @tc.name : Consumer can not subscribe to the same topic twice + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(Broadcast01TestSuite, testSubscribe0040, LEVEL2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == NULL) { + TEST_FAIL(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == NULL) { + TEST_FAIL(); + } + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + int result = subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + TEST_ASSERT_EQUAL_INT(result != 0, TRUE); + + subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_UnSubscribe_0010 + * @tc.name : Consumer can unsubscribe a topic + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(Broadcast01TestSuite, testUnsubscribe0010, LEVEL1) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == NULL) { + TEST_FAIL(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == NULL) { + TEST_FAIL(); + } + + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + + Consumer *result = subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + TEST_ASSERT_EQUAL_INT(result != NULL, TRUE); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_UnSubscribe_0020 + * @tc.name : Consumer can not unsubscribe a topic if the specified topic-comsumer relationship is NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(Broadcast01TestSuite, testUnsubscribe0020, LEVEL2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == NULL) { + TEST_FAIL(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == NULL) { + TEST_FAIL(); + } + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + + Consumer *result = subscriber->Unsubscribe((IUnknown *)fapi, NULL, &c1); + TEST_ASSERT_EQUAL_INT(result==NULL, TRUE); // failed + + result = subscriber->Unsubscribe((IUnknown *)fapi, &topic0, NULL); + TEST_ASSERT_EQUAL_INT(result==NULL, TRUE); + + subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_UnSubscribe_0030 + * @tc.name : Consumer can not unsubscribe a topic if the specified topic-comsumer relationship not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(Broadcast01TestSuite, testUnsubscribe0030, LEVEL2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == NULL) { + TEST_FAIL(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == NULL) { + TEST_FAIL(); + } + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + static Consumer c2 = {.identity = &g_identity, .Notify = C2Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + + Consumer *result = subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c2); + TEST_ASSERT_EQUAL_INT(result==NULL, TRUE); + + subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_ModifyConsumer_0010 + * @tc.name : Consumer can modify subscription relationship + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(Broadcast01TestSuite, testModifyConsumer0010, LEVEL2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == NULL) { + TEST_FAIL(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == NULL) { + TEST_FAIL(); + } + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + static Consumer c2 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + + Consumer *result = subscriber->ModifyConsumer((IUnknown *)fapi, &topic0, &c1, &c2); + TEST_ASSERT_EQUAL_INT(result != NULL, TRUE); + + subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_ModifyConsumer_0020 + * @tc.name : Consumer can not modify subscription relationship if the input parameter is NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(Broadcast01TestSuite, testModifyConsumer0020, LEVEL2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == NULL) { + TEST_FAIL(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == NULL) { + TEST_FAIL(); + } + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + static Consumer c2 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + + Consumer *result = subscriber->ModifyConsumer((IUnknown *)fapi, NULL, &c1, &c2); + TEST_ASSERT_EQUAL_INT(result!=NULL, 0); + + result = subscriber->ModifyConsumer((IUnknown *)fapi, &topic0, NULL, &c2); + TEST_ASSERT_EQUAL_INT(result!=NULL, 0); + + result = subscriber->ModifyConsumer((IUnknown *)fapi, &topic0, &c1, NULL); + TEST_ASSERT_EQUAL_INT(result!=NULL, 0); + + subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_ModifyConsumer_0030 + * @tc.name : Consumer can not modify subscription relationship if the specified topic not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(Broadcast01TestSuite, testModifyConsumer0030, LEVEL2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == NULL) { + TEST_FAIL(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == NULL) { + TEST_FAIL(); + } + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + static Consumer c2 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + + Topic noExistTopic = 99; + Consumer *result = subscriber->ModifyConsumer((IUnknown *)fapi, &noExistTopic, &c1, &c2); + TEST_ASSERT_EQUAL_INT(result==NULL, 1); + + subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_ModifyConsumer_0040 + * @tc.name : Consumer can not modify subscription relationship if the specified old consumer not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(Broadcast01TestSuite, testModifyConsumer0040, LEVEL2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == NULL) { + TEST_FAIL(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == NULL) { + TEST_FAIL(); + } + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + static Consumer c2 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + + Topic noExistTopic = 99; + Consumer *result = subscriber->ModifyConsumer((IUnknown *)fapi, &noExistTopic, &c2, &c2); + TEST_ASSERT_EQUAL_INT(result==NULL, 1); + + subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_ModifyConsumer_0050 + * @tc.name : Consumer can modify subscription relationship if the new consumer is the same as old consumer + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(Broadcast01TestSuite, testModifyConsumer0050, LEVEL2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == NULL) { + TEST_FAIL(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == NULL) { + TEST_FAIL(); + } + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + + Consumer *result = subscriber->ModifyConsumer((IUnknown *)fapi, &topic0, &c1, &c1); + TEST_ASSERT_EQUAL_INT(result != NULL, TRUE); + + subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + + CASE_ReleaseIUnknown(fapi); +} + +RUN_TEST_SUITE(Broadcast01TestSuite); \ No newline at end of file diff --git a/distributedschedule_lite/samgr_hal/src/common_func_test.c b/distributedschedule_lite/samgr_hal/src/common_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..76b9a83619b853dc9ebdf05d6b49a1e1c54165af --- /dev/null +++ b/distributedschedule_lite/samgr_hal/src/common_func_test.c @@ -0,0 +1,390 @@ +/** + * Copyright (c) 2020 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. + * + * Description : testcases for distributedschedule_lite subsystem + * Create : 2020/04/19 + */ + +#include +#include "hctest.h" +#include "common.h" + +#define OPER_INTERVAL 200 // 200 ms +#define RUN_TIMES 10 + +typedef struct Node { + const int id; + const char *name; +} Node; + +static const Node *GetNode(const Node *node1) +{ + return node1; +} + +static int CompareNode(const Node *node1, const Node *node2) +{ + if (node1->id < node2->id) { + return -1; + } else if (node1->id == node2->id) { + return 0; + } else { + return 1; + } +} + +LITE_TEST_SUIT(test, samgr, CommonTestSuite); + +static BOOL CommonTestSuiteSetUp(void) +{ + LOS_Msleep(OPER_INTERVAL); + return TRUE; +} + +static BOOL CommonTestSuiteTearDown(void) +{ + return TRUE; +} + +/** + * @tc.number : DMSLite_SAMGR_Common_0010 + * @tc.name : The vector operation after initialization is correct + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(CommonTestSuite, testCommon0010, LEVEL2) +{ + Vector nodeVector = VECTOR_Make((VECTOR_Key)GetNode, (VECTOR_Compare)CompareNode); + TEST_ASSERT_EQUAL_INT(&nodeVector != NULL, TRUE); + + int16 vectorSize = VECTOR_Size(&nodeVector); + TEST_ASSERT_EQUAL_INT(vectorSize == 0, TRUE); + + int16 vectorNum = VECTOR_Num(&nodeVector); + TEST_ASSERT_EQUAL_INT(vectorNum == 0, TRUE); + + Node *vectorAt = (Node *)VECTOR_At(&nodeVector, (int16)0); + TEST_ASSERT_EQUAL_INT(vectorAt == NULL, TRUE); + + Node node = {1, "node1"}; + Node *vectorSwap = (Node *)VECTOR_Swap(&nodeVector, (int16)0, &node); + TEST_ASSERT_EQUAL_INT(vectorSwap == NULL, TRUE); + + int16 indexFind = VECTOR_Find(&nodeVector, &node); + TEST_ASSERT_EQUAL_INT(INVALID_INDEX, indexFind); + + int16 indexFindByKey = VECTOR_FindByKey(&nodeVector, &node); + TEST_ASSERT_EQUAL_INT(INVALID_INDEX, indexFindByKey); + + VECTOR_Clear(&nodeVector); +} + +/** + * @tc.number : DMSLite_SAMGR_Common_0020 + * @tc.name : The vector operation is correct when only 1 element + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(CommonTestSuite, testCommon0020, LEVEL2) +{ + Vector nodeVector = VECTOR_Make((VECTOR_Key)GetNode, (VECTOR_Compare)CompareNode); + + Node node = {1, "node1"}; + int16 resultAdd = VECTOR_Add(&nodeVector, &node); + TEST_ASSERT_EQUAL_INT(resultAdd == 0, TRUE); + + int16 vectorSize = VECTOR_Size(&nodeVector); + TEST_ASSERT_EQUAL_INT(vectorSize == 1, TRUE); + + int16 vectorNum = VECTOR_Num(&nodeVector); + TEST_ASSERT_EQUAL_INT(vectorNum == 1, TRUE); + + Node *vectorAt = (Node *)VECTOR_At(&nodeVector, (int16)0); + TEST_ASSERT_EQUAL_INT(vectorAt != NULL, TRUE); + + Node node2 = {2, "node2"}; + VECTOR_Swap(&nodeVector, (int16)0, &node2); + + int16 indexFind = VECTOR_Find(&nodeVector, &node2); + TEST_ASSERT_EQUAL_INT(indexFind == 0, TRUE); + + int16 indexFindByKey = VECTOR_FindByKey(&nodeVector, &node2); + TEST_ASSERT_EQUAL_INT(indexFindByKey == 0, TRUE); + + VECTOR_Clear(&nodeVector); +} + +/** + * @tc.number : DMSLite_SAMGR_Common_0030 + * @tc.name : The vector operation is correct when multi elements + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(CommonTestSuite, testCommon0030, LEVEL2) +{ + Vector nodeVector = VECTOR_Make((VECTOR_Key)GetNode, (VECTOR_Compare)CompareNode); + + Node node[] = { + {0, "node"}, + {1, "node"}, + {2, "node"}, + {3, "node"}, + {4, "node"}, + {5, "node"}, + {6, "node"}, + {7, "node"}, + {8, "node"}, + {9, "node"}, + }; + + for (int i = 0; i < RUN_TIMES; i++) { + int16 resultAdd = VECTOR_Add(&nodeVector, &(node[i])); + TEST_ASSERT_EQUAL_INT(i, resultAdd); + } + + int16 vectorSize = VECTOR_Size(&nodeVector); + TEST_ASSERT_EQUAL_INT(vectorSize == RUN_TIMES, TRUE); + + int16 vectorNum = VECTOR_Num(&nodeVector); + TEST_ASSERT_EQUAL_INT(vectorNum == RUN_TIMES, TRUE); + + for (int i = 0; i < RUN_TIMES; i++) { + Node *vectorAt = (Node *)VECTOR_At(&nodeVector, (int16)i); + TEST_ASSERT_EQUAL_INT(vectorAt != NULL, TRUE); + TEST_ASSERT_EQUAL_INT(vectorAt->id == i, TRUE); + + int16 indexFind = VECTOR_Find(&nodeVector, &node[i]); + TEST_ASSERT_EQUAL_INT(indexFind == i, TRUE); + + int16 indexFindByKey = VECTOR_FindByKey(&nodeVector, &node[i]); + TEST_ASSERT_EQUAL_INT(indexFindByKey == i, TRUE); + } + + Node nodeX = {99, "node"}; + Node *resultNode = (Node *)VECTOR_Swap(&nodeVector, (int16)0, &nodeX); + TEST_ASSERT_EQUAL_INT(TRUE, resultNode != NULL); + TEST_ASSERT_EQUAL_INT(resultNode->id == 0, TRUE); + + VECTOR_Clear(&nodeVector); +} + +/** + * @tc.number : DMSLite_SAMGR_Common_0040 + * @tc.name : The vector operation is correct after delete some elements + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(CommonTestSuite, testCommon0040, LEVEL2) +{ + Vector nodeVector = VECTOR_Make((VECTOR_Key)GetNode, (VECTOR_Compare)CompareNode); + Node node[] = { + {0, "node"}, + {1, "node"}, + {2, "node"}, + {3, "node"}, + {4, "node"}, + {5, "node"}, + {6, "node"}, + {7, "node"}, + {8, "node"}, + {9, "node"}, + }; + for (int i = 0; i < RUN_TIMES; i++) { + VECTOR_Add(&nodeVector, &(node[i])); + } + + for (int i = 0; i < RUN_TIMES; i++) { + Node *resultNode = (Node *)VECTOR_Swap(&nodeVector, (int16)i, NULL); + TEST_ASSERT_EQUAL_INT(TRUE, resultNode != NULL); + TEST_ASSERT_EQUAL_INT(i, resultNode->id); + + int16 vectorSize = VECTOR_Size(&nodeVector); + TEST_ASSERT_EQUAL_INT(RUN_TIMES, vectorSize); + + int16 vectorNum = VECTOR_Num(&nodeVector); + TEST_ASSERT_EQUAL_INT(RUN_TIMES - (i + 1), vectorNum); + + Node *vectorAt = (Node *)VECTOR_At(&nodeVector, (int16)i); + TEST_ASSERT_EQUAL_INT(TRUE, vectorAt == NULL); + + int16 indexFind = VECTOR_Find(&nodeVector, &node[i]); + TEST_ASSERT_EQUAL_INT(INVALID_INDEX, indexFind); + + int16 indexFindByKey = VECTOR_FindByKey(&nodeVector, &node[i]); + TEST_ASSERT_EQUAL_INT(INVALID_INDEX, indexFindByKey); + } + + VECTOR_Clear(&nodeVector); +} + +/** + * @tc.number : DMSLite_SAMGR_Common_0050 + * @tc.name : The vector operation is correct after add and delete some elements + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(CommonTestSuite, testCommon0050, LEVEL2) +{ + Vector nodeVector = VECTOR_Make((VECTOR_Key)GetNode, (VECTOR_Compare)CompareNode); + Node node[] = { + {0, "node"}, + {1, "node"}, + {2, "node"}, + {3, "node"}, + {4, "node"}, + {5, "node"}, + {6, "node"}, + {7, "node"}, + {8, "node"}, + {9, "node"}, + }; + for (int i = 0; i < (RUN_TIMES * RUN_TIMES); i++) { + for (int j = 0; j < RUN_TIMES; j++) { + VECTOR_Add(&nodeVector, &(node[j])); + } + for (int j = 0; j < RUN_TIMES; j++) { + VECTOR_Swap(&nodeVector, (int16)j, NULL); + } + } + + for (int i = 0; i < RUN_TIMES; i++) { + VECTOR_Add(&nodeVector, &(node[i])); + } + printf("[hctest]test start \n"); + for (int i = 0; i < RUN_TIMES; i++) { + int16 indexFind = VECTOR_Find(&nodeVector, &node[i]); + TEST_ASSERT_EQUAL_INT(indexFind >= 0, TRUE); + + int16 indexFindByKey = VECTOR_FindByKey(&nodeVector, &node[i]); + TEST_ASSERT_EQUAL_INT(indexFindByKey >= 0, TRUE); + + Node *resultNode = (Node *)VECTOR_Swap(&nodeVector, indexFind, NULL); + TEST_ASSERT_EQUAL_INT(TRUE, resultNode != NULL); + TEST_ASSERT_EQUAL_INT(i, resultNode->id); + + int16 vectorSize = VECTOR_Size(&nodeVector); + TEST_ASSERT_EQUAL_INT(vectorSize > (RUN_TIMES - (i + 1)), TRUE); + + int16 vectorNum = VECTOR_Num(&nodeVector); + TEST_ASSERT_EQUAL_INT(RUN_TIMES - (i + 1), vectorNum); + + Node *vectorAt = (Node *)VECTOR_At(&nodeVector, indexFind); + TEST_ASSERT_EQUAL_INT(TRUE, vectorAt == NULL); + } + + VECTOR_Clear(&nodeVector); +} + +/** + * @tc.number : DMSLite_SAMGR_Common_0060 + * @tc.name : If vector or element is NULL adding element fails + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(CommonTestSuite, testCommon0060, LEVEL2) +{ + Vector nodeVector = VECTOR_Make((VECTOR_Key)GetNode, (VECTOR_Compare)CompareNode); + + Node node = {1, "node1"}; + int16 resultAdd = VECTOR_Add(NULL, &node); + TEST_ASSERT_EQUAL_INT(INVALID_INDEX, resultAdd); + + resultAdd = VECTOR_Add(&nodeVector, NULL); + TEST_ASSERT_EQUAL_INT(INVALID_INDEX, resultAdd); + + VECTOR_Clear(&nodeVector); +} + +/** + * @tc.number : DMSLite_SAMGR_Common_0070 + * @tc.name : If vector is NULL deleting element fails + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(CommonTestSuite, testCommon0070, LEVEL2) +{ + Vector nodeVector = VECTOR_Make((VECTOR_Key)GetNode, (VECTOR_Compare)CompareNode); + Node node = {1, "node1"}; + VECTOR_Add(&nodeVector, &node); + + Node *vectorSwap = (Node *)VECTOR_Swap(NULL, (int16)0, NULL); + TEST_ASSERT_EQUAL_INT(TRUE, vectorSwap == NULL); + + VECTOR_Clear(&nodeVector); +} + +/** + * @tc.number : DMSLite_SAMGR_Common_0080 + * @tc.name : If vector is NULL getting information from vector fails + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(CommonTestSuite, testCommon0080, LEVEL2) +{ + Vector nodeVector = VECTOR_Make((VECTOR_Key)GetNode, (VECTOR_Compare)CompareNode); + Node node = {1, "node1"}; + VECTOR_Add(&nodeVector, &node); + + int16 vectorSize = VECTOR_Size(NULL); + TEST_ASSERT_EQUAL_INT(INVALID_INDEX, vectorSize); + + int16 vectorNum = VECTOR_Num(NULL); + TEST_ASSERT_EQUAL_INT(INVALID_INDEX, vectorNum); + + Node *vectorAt = (Node *)VECTOR_At(NULL, (int16)0); + TEST_ASSERT_EQUAL_INT(TRUE, vectorAt == NULL); + + VECTOR_Clear(&nodeVector); +} + +/** + * @tc.number : DMSLite_SAMGR_Common_0090 + * @tc.name : If vector is NULL searching from vector fails + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(CommonTestSuite, testCommon0090, LEVEL2) +{ + Vector nodeVector = VECTOR_Make((VECTOR_Key)GetNode, (VECTOR_Compare)CompareNode); + Node node = {1, "node1"}; + VECTOR_Add(&nodeVector, &node); + + int16 indexFind = VECTOR_Find(NULL, &node); + TEST_ASSERT_EQUAL_INT(INVALID_INDEX, indexFind); + + int16 indexFindByKey = VECTOR_FindByKey(NULL, &node); + TEST_ASSERT_EQUAL_INT(INVALID_INDEX, indexFindByKey); + + VECTOR_Clear(&nodeVector); +} + +RUN_TEST_SUITE(CommonTestSuite); \ No newline at end of file diff --git a/distributedschedule_lite/samgr_hal/src/defaultfeatureapi_func_test.c b/distributedschedule_lite/samgr_hal/src/defaultfeatureapi_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..061ba3347f7bb6ce1a095f07bee224253338b900 --- /dev/null +++ b/distributedschedule_lite/samgr_hal/src/defaultfeatureapi_func_test.c @@ -0,0 +1,315 @@ +/* + * Copyright (c) 2020 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 "hctest.h" +#include "samgr_lite.h" + +#define PRESSURE_BASE (1024 * 10) + +typedef struct DemoApi { + INHERIT_IUNKNOWN; +} DemoApi; + +typedef struct ExampleService { + INHERIT_SERVICE; + Identity identity; +} ExampleService; + +static DemoApi g_api = { + DEFAULT_IUNKNOWN_IMPL, +}; + +static const char *GetName(Service *service) +{ + (void)service; + return "serviceName301"; +} + +static BOOL Initialize(Service *service, Identity identity) +{ + ExampleService *example = (ExampleService *)service; + example->identity = identity; + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)service; + (void)msg; + return FALSE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + (void)service; + TaskConfig config = {LEVEL_HIGH, PRI_ABOVE_NORMAL, 0x800, 20, SHARED_TASK}; + return config; +} + +static ExampleService g_service = { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .identity = {-1, -1, NULL}, +}; + +LITE_TEST_SUIT(test, samgr, DefaultFeatureApiTestSuite); + +static BOOL DefaultFeatureApiTestSuiteSetUp(void) +{ + BOOL result = SAMGR_GetInstance()->RegisterService((Service *)&g_service); + return result; +} + +static BOOL DefaultFeatureApiTestSuiteTearDown(void) +{ + Service *resultService = SAMGR_GetInstance()->UnregisterService("serviceName301"); + if (strcmp(resultService->GetName(resultService), "serviceName301") == 0) { + return TRUE; + } else { + printf("[hctest]failed to unregister service.\n"); + return FALSE; + } +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterDefaultFeatureApi_0010 + * @tc.name : Valid API can be registered under default feature + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(DefaultFeatureApiTestSuite, testRegisterDefaultFeatureApi0010, LEVEL1) +{ + BOOL result = SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName301", (IUnknown *)&g_api); + TEST_ASSERT_EQUAL_INT(result, TRUE); // TRUE: success; FALSE: fail + + SAMGR_GetInstance()->UnregisterDefaultFeatureApi("serviceName301"); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterDefaultFeatureApi_0020 + * @tc.name : API failed to register if the specified service is null + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(DefaultFeatureApiTestSuite, testRegisterDefaultFeatureApi0020, LEVEL2) +{ + BOOL result = SAMGR_GetInstance()->RegisterDefaultFeatureApi(NULL, (IUnknown *)&g_api); + TEST_ASSERT_EQUAL_INT(result, FALSE); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterDefaultFeatureApi_0030 + * @tc.name : API failed to register if the specified service does not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(DefaultFeatureApiTestSuite, testRegisterDefaultFeatureApi0030, LEVEL2) +{ + BOOL result = SAMGR_GetInstance()->RegisterDefaultFeatureApi("noExistService", (IUnknown *)&g_api); + TEST_ASSERT_EQUAL_INT(result, FALSE); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterDefaultFeatureApi_0040 + * @tc.name : API failed to register if the target API is NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(DefaultFeatureApiTestSuite, testRegisterDefaultFeatureApi0040, LEVEL2) +{ + BOOL result = SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName301", NULL); + TEST_ASSERT_EQUAL_INT(result, FALSE); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterDefaultFeatureApi_0050 + * @tc.name : API failed to register for the target API already exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(DefaultFeatureApiTestSuite, testRegisterDefaultFeatureApi0050, LEVEL2) +{ + SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName301", (IUnknown *)&g_api); + BOOL result = SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName301", (IUnknown *)&g_api); + TEST_ASSERT_EQUAL_INT(result, FALSE); + + SAMGR_GetInstance()->UnregisterDefaultFeatureApi("serviceName301"); +} + +/** + * @tc.number : DMSLite_SAMGR_GetDefaultFeatureApi_0010 + * @tc.name : API can be queried out from service + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(DefaultFeatureApiTestSuite, testGetDefaultFeatureApi0010, LEVEL1) +{ + SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName301", (IUnknown *)&g_api); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi("serviceName301"); + TEST_ASSERT_EQUAL_INT(resultIUnknown != NULL, TRUE); + + SAMGR_GetInstance()->UnregisterDefaultFeatureApi("serviceName301"); +} + +/** + * @tc.number : DMSLite_SAMGR_GetDefaultFeatureApi_0020 + * @tc.name : It's NULL result if the specified service name is NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(DefaultFeatureApiTestSuite, testGetDefaultFeatureApi0020, LEVEL2) +{ + SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName301", (IUnknown *)&g_api); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(NULL); + TEST_ASSERT_EQUAL_INT(resultIUnknown == NULL, TRUE); + + SAMGR_GetInstance()->UnregisterDefaultFeatureApi("serviceName301"); +} + +/** + * @tc.number : DMSLite_SAMGR_GetDefaultFeatureApi_0030 + * @tc.name : The query result is NULL for the specified service does not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(DefaultFeatureApiTestSuite, testGetDefaultFeatureApi0030, LEVEL2) +{ + SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName301", (IUnknown *)&g_api); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi("noExistService"); + TEST_ASSERT_EQUAL_INT(resultIUnknown == NULL, TRUE); + + SAMGR_GetInstance()->UnregisterDefaultFeatureApi("serviceName301"); +} + +/** + * @tc.number : DMSLite_SAMGR_GetDefaultFeatureApi_0040 + * @tc.name : The query result is the same for multi query operations + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(DefaultFeatureApiTestSuite, testGetDefaultFeatureApi0040, LEVEL2) +{ + SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName301", (IUnknown *)&g_api); + + IUnknown *resultIUnknown1 = SAMGR_GetInstance()->GetDefaultFeatureApi("serviceName301"); + IUnknown *resultIUnknown2 = SAMGR_GetInstance()->GetDefaultFeatureApi("serviceName301"); + TEST_ASSERT_EQUAL_INT(resultIUnknown1 == resultIUnknown2, TRUE); + + SAMGR_GetInstance()->UnregisterDefaultFeatureApi("serviceName301"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterDefaultFeatureApi_0010 + * @tc.name : Default feature API can be unregistered + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(DefaultFeatureApiTestSuite, testUnregisterDefaultFeatureApi0010, LEVEL1) +{ + SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName301", (IUnknown *)&g_api); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterDefaultFeatureApi("serviceName301"); + TEST_ASSERT_EQUAL_INT(resultIUnknown != NULL, TRUE); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterDefaultFeatureApi_0020 + * @tc.name : The unregister operation failed if serviceName is NULL or space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(DefaultFeatureApiTestSuite, testUnregisterDefaultFeatureApi0020, LEVEL2) +{ + SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName301", (IUnknown *)&g_api); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterDefaultFeatureApi(NULL); + TEST_ASSERT_EQUAL_INT(resultIUnknown == NULL, TRUE); + + resultIUnknown = SAMGR_GetInstance()->UnregisterDefaultFeatureApi(""); + TEST_ASSERT_EQUAL_INT(resultIUnknown == NULL, TRUE); + + SAMGR_GetInstance()->UnregisterDefaultFeatureApi("serviceName301"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterDefaultFeatureApi_0030 + * @tc.name : The unregister operation failed if the specified service does not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(DefaultFeatureApiTestSuite, testUnregisterDefaultFeatureApi0030, LEVEL2) +{ + IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterDefaultFeatureApi("noExistService"); + TEST_ASSERT_EQUAL_INT(resultIUnknown == NULL, TRUE); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterDefaultFeatureApi_0040 + * @tc.name : Register and unregister default api repeatedly, no memory leak + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(DefaultFeatureApiTestSuite, testUnregisterDefaultFeatureApi0040, LEVEL2) +{ + // RegisterService and unregister default api over and over again, if there is memory leak samgr will crash + for (int i = 0; i < PRESSURE_BASE; i++) { + BOOL result = SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName301", (IUnknown *)&g_api); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi("serviceName301"); + TEST_ASSERT_EQUAL_INT(resultIUnknown != NULL, TRUE); + + resultIUnknown = SAMGR_GetInstance()->UnregisterDefaultFeatureApi("serviceName301"); + TEST_ASSERT_EQUAL_INT(resultIUnknown != NULL, TRUE); + + resultIUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi("serviceName301"); + TEST_ASSERT_EQUAL_INT(resultIUnknown == NULL, TRUE); + } +} + +RUN_TEST_SUITE(DefaultFeatureApiTestSuite); \ No newline at end of file diff --git a/distributedschedule_lite/samgr_hal/src/feature_func_test.c b/distributedschedule_lite/samgr_hal/src/feature_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..8e51d4039cbddb8a2973faafdb270bc469021f12 --- /dev/null +++ b/distributedschedule_lite/samgr_hal/src/feature_func_test.c @@ -0,0 +1,378 @@ +/* + * Copyright (c) 2020 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 "hctest.h" +#include "samgr_lite.h" + +#define PRESSURE_BASE (1024 * 10) + +typedef struct DemoApi { + INHERIT_IUNKNOWN; +} DemoApi; + +typedef struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoApi); + Identity identity; +} DemoFeature; + +typedef struct ExampleService { + INHERIT_SERVICE; + Identity identity; +} ExampleService; + +static const char *GetName(Service *service) +{ + (void)service; + return "serviceName201"; +} + +static BOOL Initialize(Service *service, Identity identity) +{ + ExampleService *example = (ExampleService *)service; + example->identity = identity; + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)msg; + (void)service; + return TRUE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + (void)service; + TaskConfig config = { + LEVEL_HIGH, + PRI_ABOVE_NORMAL, + 0x800, + 20, + SHARED_TASK + }; + return config; +} + +static ExampleService g_service = { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .identity = {-1, -1, NULL}, +}; + +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return "featureName201"; +} +static const char *FEATURE_GetName2(Feature *feature) +{ + (void)feature; + return "featureName202"; +} +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; + (void)parent; +} +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *request) +{ + (void)feature; + (void)request; + return TRUE; +} + +static DemoFeature g_feature = { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + }, + .identity = {-1, -1, NULL}, +}; +static DemoFeature g_feature2 = { + .GetName = FEATURE_GetName2, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + }, + .identity = {-1, -1, NULL}, +}; + +LITE_TEST_SUIT(test, samgr, FeatureTestSuite); + +static BOOL FeatureTestSuiteSetUp(void) +{ + BOOL result = SAMGR_GetInstance()->RegisterService((Service *)&g_service); + return result; +} + +static BOOL FeatureTestSuiteTearDown(void) +{ + Service *resultService = SAMGR_GetInstance()->UnregisterService("serviceName201"); + if (strcmp(resultService->GetName(resultService), "serviceName201") == 0) { + return TRUE; + } else { + return FALSE; + } +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeature_0010 + * @tc.name : Valid feature can be registered + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(FeatureTestSuite, testRegisterFeature0010, LEVEL1) +{ + BOOL result = SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName201"); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeature_0020 + * @tc.name : If the specified service is null feature can not be registered + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureTestSuite, testRegisterFeature0020, LEVEL2) +{ + BOOL result = SAMGR_GetInstance()->RegisterFeature(NULL, (Feature *)&g_feature); + TEST_ASSERT_EQUAL_INT(result, FALSE); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeature_0030 + * @tc.name : If the specified feature is null feature can not be registered + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureTestSuite, testRegisterFeature0030, LEVEL2) +{ + BOOL result = SAMGR_GetInstance()->RegisterFeature("serviceName201", NULL); + TEST_ASSERT_EQUAL_INT(result, FALSE); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeature_0040 + * @tc.name : Feature can not be registered if the specified service does not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureTestSuite, testRegisterFeature0040, LEVEL2) +{ + BOOL result = SAMGR_GetInstance()->RegisterFeature("noExistServiceName", (Feature *)&g_feature); + TEST_ASSERT_EQUAL_INT(result, FALSE); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeature_0050 + * @tc.name : Feature failed to register if the same feature name already exist in samgr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureTestSuite, testRegisterFeature0050, LEVEL2) +{ + SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature); + + BOOL result = SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature); + TEST_ASSERT_EQUAL_INT(result, FALSE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName201"); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeature_0060 + * @tc.name : Multi features can be registered under one service + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureTestSuite, testRegisterFeature0060, LEVEL2) +{ + BOOL result1 = SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature); + TEST_ASSERT_EQUAL_INT(result1, TRUE); + BOOL result2 = SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature2); + TEST_ASSERT_EQUAL_INT(result2, TRUE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName201"); + SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName202"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeature_0010 + * @tc.name : Feature can be unregistered + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureTestSuite, testUnregisterFeature0010, LEVEL2) +{ + SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature); + + Feature *resultFeature = SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName201"); + TEST_ASSERT_EQUAL_INT(strcmp(resultFeature->GetName(resultFeature), "featureName201"), 0); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeature_0020 + * @tc.name : Feature can not be unregistered if the specified service is null or space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureTestSuite, testUnregisterFeature0020, LEVEL2) +{ + SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature); + + Feature *resultFeature = SAMGR_GetInstance()->UnregisterFeature(NULL, "featureName201"); + TEST_ASSERT_EQUAL_INT(resultFeature == NULL, TRUE); + + resultFeature = SAMGR_GetInstance()->UnregisterFeature("", "featureName201"); + TEST_ASSERT_EQUAL_INT(resultFeature == NULL, TRUE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName201"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeature_0030 + * @tc.name : Feature can not be unregistered if the specified feature is null or space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureTestSuite, testUnregisterFeature0030, LEVEL2) +{ + SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature); + + Feature *resultFeature = SAMGR_GetInstance()->UnregisterFeature("serviceName201", NULL); + TEST_ASSERT_EQUAL_INT(resultFeature == NULL, TRUE); + + resultFeature = SAMGR_GetInstance()->UnregisterFeature("serviceName201", ""); + TEST_ASSERT_EQUAL_INT(resultFeature == NULL, TRUE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName201"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeature_0040 + * @tc.name : Feature failed to unregister if the specified service not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureTestSuite, testUnregisterFeature0040, LEVEL2) +{ + SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature); + + Feature *resultFeature = SAMGR_GetInstance()->UnregisterFeature("noExistService", "featureName201"); + TEST_ASSERT_EQUAL_INT(resultFeature == NULL, TRUE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName201"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeature_0050 + * @tc.name : Feature failed to unregister if the specified feature not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureTestSuite, testUnregisterFeature0050, LEVEL2) +{ + SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature); + + Feature *resultFeature = SAMGR_GetInstance()->UnregisterFeature("serviceName201", "noExistFeature"); + TEST_ASSERT_EQUAL_INT(resultFeature == NULL, TRUE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName201"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeature_0060 + * @tc.name : Feature can not be unregistered if there is api under the feature + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureTestSuite, testUnregisterFeature0060, LEVEL2) +{ + SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName201", "featureName201", GET_IUNKNOWN(g_feature)); + + Feature *result = SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName201"); + TEST_ASSERT_EQUAL_INT(result == NULL, TRUE); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName201", "featureName201"); + SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName201"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeature_0070 + * @tc.name : Register and unregister feature repeatedly, no memory leak + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureTestSuite, testUnregisterFeature0070, LEVEL2) +{ + // RegisterService and unregister feature over and over again, if there is memory leak samgr will crash + for (int i = 0; i < PRESSURE_BASE; i++) { + BOOL result = SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + Feature *resultFeature = SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName201"); + TEST_ASSERT_EQUAL_INT(strcmp(resultFeature->GetName(resultFeature), "featureName201"), 0); + } +} + +RUN_TEST_SUITE(FeatureTestSuite); \ No newline at end of file diff --git a/distributedschedule_lite/samgr_hal/src/featureapi_func_test.c b/distributedschedule_lite/samgr_hal/src/featureapi_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..b04a5d5e7a1e6d70cab85d4bb4832e1c3f25afba --- /dev/null +++ b/distributedschedule_lite/samgr_hal/src/featureapi_func_test.c @@ -0,0 +1,572 @@ +/* + * Copyright (c) 2020 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 "hctest.h" +#include "samgr_lite.h" + +#define PRESSURE_BASE (1024 * 10) + +typedef struct DemoApi { + INHERIT_IUNKNOWN; +} DemoApi; + +typedef struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoApi); + Identity identity; +} DemoFeature; + +static const char *GetName(Service *service) +{ + (void)service; + return "serviceName401"; +} + +typedef struct ExampleService { + INHERIT_SERVICE; + Identity identity; +} ExampleService; + +static BOOL Initialize(Service *service, Identity identity) +{ + ExampleService *example = (ExampleService *)service; + example->identity = identity; + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)service; + (void)msg; + return FALSE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + (void)service; + TaskConfig config = { + LEVEL_HIGH, + PRI_ABOVE_NORMAL, + 0x800, + 20, + SHARED_TASK + }; + return config; +} + +static ExampleService g_service = { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .identity = {-1, -1, NULL}, +}; + +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return "featureName401"; +} +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + (void)parent; + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; +} +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *request) +{ + (void)feature; + (void)request; + return TRUE; +} + +static DemoFeature g_feature = { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + }, + .identity = {-1, -1, NULL}, +}; + +LITE_TEST_SUIT(test, samgr, FeatureApiTestSuite); + +static BOOL FeatureApiTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL FeatureApiTestSuiteTearDown(void) +{ + return TRUE; +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0010 + * @tc.name : Api can be registered under a feature + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureApiTestSuite, testRegisterFeatureApi0010, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + + BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", + GET_IUNKNOWN(g_feature)); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0020 + * @tc.name : API failed to register if the specified service name is null or space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureApiTestSuite, testRegisterFeatureApi0020, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + + BOOL result = SAMGR_GetInstance()->RegisterFeatureApi(NULL, "featureName401", GET_IUNKNOWN(g_feature)); + TEST_ASSERT_EQUAL_INT(result, FALSE); + + result = SAMGR_GetInstance()->RegisterFeatureApi("", "featureName401", GET_IUNKNOWN(g_feature)); + TEST_ASSERT_EQUAL_INT(result, FALSE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0030 + * @tc.name : API failed to register if the specified feature is space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureApiTestSuite, testRegisterFeatureApi0030, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + + BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "", GET_IUNKNOWN(g_feature)); + TEST_ASSERT_EQUAL_INT(result, FALSE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0040 + * @tc.name : API failed to register if the api is null + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureApiTestSuite, testRegisterFeatureApi0040, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + + BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", NULL); + TEST_ASSERT_EQUAL_INT(result, FALSE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0050 + * @tc.name : If the specified feature is null api will be registered as default feature api + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureApiTestSuite, testRegisterFeatureApi0050, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + + // feature is null, handle as default feature api + BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", NULL, GET_IUNKNOWN(g_feature)); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", NULL); + TEST_ASSERT_EQUAL_INT(resultIUnknown != NULL, TRUE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0060 + * @tc.name : API failed to register if the specified service name does not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureApiTestSuite, testRegisterFeatureApi0060, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + + BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("noExistService", "featureName401", GET_IUNKNOWN(g_feature)); + TEST_ASSERT_EQUAL_INT(result, FALSE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0070 + * @tc.name : API failed to register if the specified feature name does not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureApiTestSuite, testRegisterFeatureApi0070, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + + BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "noExistFeature", GET_IUNKNOWN(g_feature)); + TEST_ASSERT_EQUAL_INT(result, FALSE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0080 + * @tc.name : feature api can not be registered twice + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureApiTestSuite, testRegisterFeatureApi0080, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature)); + + BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", + GET_IUNKNOWN(g_feature)); + TEST_ASSERT_EQUAL_INT(FALSE, result); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_GetFeatureApi_0010 + * @tc.name : Service can query API by serverName-featureName + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureApiTestSuite, testGetFeatureApi0010, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature)); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName401", "featureName401"); + TEST_ASSERT_EQUAL_INT(resultIUnknown != NULL, TRUE); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_GetFeatureApi_0020 + * @tc.name : If the specified serviceName is NULL or space GetFeatureApi return NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureApiTestSuite, testGetFeatureApi0020, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature)); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->GetFeatureApi(NULL, "featureName401"); + TEST_ASSERT_EQUAL_INT(resultIUnknown == NULL, TRUE); + resultIUnknown = SAMGR_GetInstance()->GetFeatureApi("", "featureName401"); + TEST_ASSERT_EQUAL_INT(resultIUnknown == NULL, TRUE); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_GetFeatureApi_0030 + * @tc.name : If the specified featureName is NULL or space GetFeatureApi return NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureApiTestSuite, testGetFeatureApi0030, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature)); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName401", NULL); + TEST_ASSERT_EQUAL_INT(resultIUnknown == NULL, TRUE); + resultIUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName401", ""); + TEST_ASSERT_EQUAL_INT(resultIUnknown == NULL, TRUE); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_GetFeatureApi_0040 + * @tc.name : If the specified featureName does not exist GetFeatureApi return NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureApiTestSuite, testGetFeatureApi0040, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->GetFeatureApi("noExistService", "featureName401"); + TEST_ASSERT_EQUAL_INT(resultIUnknown == NULL, TRUE); + resultIUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName401", "noExistFeature"); + TEST_ASSERT_EQUAL_INT(resultIUnknown == NULL, TRUE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_GetFeatureApi_0050 + * @tc.name : If no API under the specified feature GetFeatureApi return NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureApiTestSuite, testGetFeatureApi0050, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName401", "featureName401"); + TEST_ASSERT_EQUAL_INT(resultIUnknown == NULL, TRUE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_GetFeatureApi_0060 + * @tc.name : The results of multiple queries are the same for GetFeatureApi + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureApiTestSuite, testGetFeatureApi0060, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature)); + + IUnknown *resultIUnknown1 = SAMGR_GetInstance()->GetFeatureApi("serviceName401", "featureName401"); + IUnknown *resultIUnknown2 = SAMGR_GetInstance()->GetFeatureApi("serviceName401", "featureName401"); + TEST_ASSERT_EQUAL_INT(resultIUnknown1 == resultIUnknown2, TRUE); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeatureApi_0010 + * @tc.name : FeatureApi can be unregistered + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureApiTestSuite, testUnregisterFeatureApi0010, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature)); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + TEST_ASSERT_EQUAL_INT(resultIUnknown != NULL, TRUE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeatureApi_0020 + * @tc.name : FeatureApi failed to unregister if the specified serviceName is NULL or space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureApiTestSuite, testUnregisterFeatureApi0020, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature)); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterFeatureApi(NULL, "featureName401"); + TEST_ASSERT_EQUAL_INT(resultIUnknown == NULL, TRUE); + resultIUnknown = SAMGR_GetInstance()->UnregisterFeatureApi("", "featureName401"); + TEST_ASSERT_EQUAL_INT(resultIUnknown == NULL, TRUE); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeatureApi_0030 + * @tc.name : FeatureApi failed to unregister if the specified featureName is space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureApiTestSuite, testUnregisterFeatureApi0030, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature)); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", ""); + TEST_ASSERT_EQUAL_INT(resultIUnknown == NULL, TRUE); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeatureApi_0040 + * @tc.name : FeatureApi failed to unregister if the specified serviceName does not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureApiTestSuite, testUnregisterFeatureApi0040, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature)); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterFeatureApi("noExistService", "featureName401"); + TEST_ASSERT_EQUAL_INT(resultIUnknown == NULL, TRUE); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeatureApi_0050 + * @tc.name : FeatureApi failed to unregister if the specified featureName does not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureApiTestSuite, testUnregisterFeatureApi0050, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature)); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "noExistFeature"); + TEST_ASSERT_EQUAL_INT(resultIUnknown == NULL, TRUE); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeatureApi_0060 + * @tc.name : Register and unregister feature api repeatedly, no memory leak + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(FeatureApiTestSuite, testUnregisterFeatureApi0060, LEVEL2) +{ + // RegisterService and unregister feature api over and over again, if there is memory leak samgr will crash + for (int i = 0; i < PRESSURE_BASE; i++) { + BOOL result = SAMGR_GetInstance()->RegisterService((Service *)&g_service); + TEST_ASSERT_EQUAL_INT(result, TRUE); + result = SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + TEST_ASSERT_EQUAL_INT(result, TRUE); + result = SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature)); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + TEST_ASSERT_EQUAL_INT(resultIUnknown != NULL, TRUE); + Feature *resultFeature = SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + TEST_ASSERT_EQUAL_INT(resultFeature != NULL, TRUE); + Service *resultService = SAMGR_GetInstance()->UnregisterService("serviceName401"); + TEST_ASSERT_EQUAL_INT(resultService != NULL, TRUE); + } +} + +RUN_TEST_SUITE(FeatureApiTestSuite); \ No newline at end of file diff --git a/distributedschedule_lite/samgr_hal/src/iunknown_func_test.c b/distributedschedule_lite/samgr_hal/src/iunknown_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..ed0a6edff874638481de9f1fbd7a8c55c52414ae --- /dev/null +++ b/distributedschedule_lite/samgr_hal/src/iunknown_func_test.c @@ -0,0 +1,239 @@ +/* + * Copyright (c) 2020 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 "hctest.h" +#include "samgr_lite.h" + +#define SERVICE_NAME "S_iunknown" +#define FEATURE_NAME "F_iunknown" + +typedef struct DemoApi { + INHERIT_IUNKNOWN; +} DemoApi; + +typedef struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoApi); + Identity identity; +} DemoFeature; + +static const char *GetName(Service *service) +{ + (void)service; + return SERVICE_NAME; +} + +typedef struct ExampleService { + INHERIT_SERVICE; + Identity identity; +} ExampleService; + +static BOOL Initialize(Service *service, Identity identity) +{ + ExampleService *example = (ExampleService *)service; + example->identity = identity; + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)service; + (void)msg; + return FALSE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + (void)service; + TaskConfig config = { + LEVEL_HIGH, + PRI_ABOVE_NORMAL, + 0x800, + 20, + SHARED_TASK + }; + return config; +} + +static ExampleService g_service = { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .identity = {-1, -1, NULL}, +}; + +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return FEATURE_NAME; +} +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + (void)parent; + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; +} +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *request) +{ + (void)feature; + (void)request; + return TRUE; +} + +static DemoFeature g_feature = { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ver = DEFAULT_VERSION, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + }, + .identity = {-1, -1, NULL}, +}; + +static DemoApi g_api = { + .AddRef = IUNKNOWN_AddRef, + .QueryInterface = IUNKNOWN_QueryInterface, + .Release = IUNKNOWN_Release, +}; + +LITE_TEST_SUIT(test, samgr, IUnknownTestSuite); + +static BOOL IUnknownTestSuiteSetUp(void) +{ + BOOL result1 = SAMGR_GetInstance()->RegisterService((Service *)&g_service); + BOOL result2 = SAMGR_GetInstance()->RegisterFeature(SERVICE_NAME, (Feature *)&g_feature); + if (result1 == TRUE && result2 == TRUE) { + return TRUE; + } else { + printf("[hctest]E failed to register service or feature \n"); + return FALSE; + } +} + +static BOOL IUnknownTestSuiteTearDown(void) +{ + SAMGR_GetInstance()->UnregisterFeature(SERVICE_NAME, FEATURE_NAME); + SAMGR_GetInstance()->UnregisterService(SERVICE_NAME); + return TRUE; +} + +/** + * @tc.number : DMSLite_SAMGR_GetIUnknown_0010 + * @tc.name : Use this macro GET_IUNKNOWN user can obtain the IUnknown interface from the subclass object. + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(IUnknownTestSuite, testGetIUnknown0010, LEVEL2) +{ + IUnknown *iUnknown = GET_IUNKNOWN(g_feature); + TEST_ASSERT_EQUAL_INT(TRUE, iUnknown != NULL); +} + +/** + * @tc.number : DMSLite_SAMGR_GetObject_0010 + * @tc.name : Use this macro GET_OBJECT user can obtain a outside object. + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(IUnknownTestSuite, testGetObject0010, LEVEL2) +{ + IUnknown *iUnknown = GET_IUNKNOWN(g_feature); + IUnknownEntry *entry = GET_OBJECT(iUnknown, IUnknownEntry, iUnknown); + TEST_ASSERT_EQUAL_INT(DEFAULT_VERSION, entry->ver); + TEST_ASSERT_EQUAL_INT(1, entry->ref); +} + +/** + * @tc.number : DMSLite_SAMGR_QueryInterface_0010 + * @tc.name : Use this api QueryInterface user can convert the object to the required subclass type. + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(IUnknownTestSuite, testQueryInterface0010, LEVEL2) +{ + SAMGR_GetInstance()->RegisterFeatureApi(SERVICE_NAME, FEATURE_NAME, GET_IUNKNOWN(g_feature)); + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(SERVICE_NAME, FEATURE_NAME); + DemoApi *demoApi = NULL; + int resultQuery = iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void **)&demoApi); + TEST_ASSERT_EQUAL_INT(EC_SUCCESS, resultQuery); + TEST_ASSERT_EQUAL_INT(TRUE, demoApi != NULL); + + int resultAdd = iUnknown->AddRef(iUnknown); + int resultRelease = iUnknown->Release(iUnknown); + TEST_ASSERT_EQUAL_INT(1, resultAdd - resultRelease); + + SAMGR_GetInstance()->UnregisterFeatureApi(SERVICE_NAME, FEATURE_NAME); +} + +/** + * @tc.number : DMSLite_SAMGR_QueryInterface_0020 + * @tc.name : User can not get the required subclass type if the version does not have permission. + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(IUnknownTestSuite, testQueryInterface0020, LEVEL2) +{ + SAMGR_GetInstance()->RegisterFeatureApi(SERVICE_NAME, FEATURE_NAME, GET_IUNKNOWN(g_feature)); + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(SERVICE_NAME, FEATURE_NAME); + DemoApi *demoApi = NULL; + int resultQuery = iUnknown->QueryInterface(iUnknown, 0x30, (void **)&demoApi); + TEST_ASSERT_EQUAL_INT(EC_INVALID, resultQuery); + + SAMGR_GetInstance()->UnregisterFeatureApi(SERVICE_NAME, FEATURE_NAME); +} + +/** + * @tc.number : DMSLite_SAMGR_QueryInterface_0030 + * @tc.name : User can rewrite this api "QueryInterface". + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(IUnknownTestSuite, testQueryInterface0030, LEVEL2) +{ + SAMGR_GetInstance()->RegisterFeatureApi(SERVICE_NAME, FEATURE_NAME, (IUnknown *)&g_api); + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(SERVICE_NAME, FEATURE_NAME); + DemoApi *demoApi = NULL; + int resultQuery = iUnknown->QueryInterface(iUnknown, 0, (void **)&demoApi); + TEST_ASSERT_EQUAL_INT(EC_SUCCESS, resultQuery); + TEST_ASSERT_EQUAL_INT(TRUE, demoApi != NULL); + + SAMGR_GetInstance()->UnregisterFeatureApi(SERVICE_NAME, FEATURE_NAME); +} + +RUN_TEST_SUITE(IUnknownTestSuite); \ No newline at end of file diff --git a/distributedschedule_lite/samgr_hal/src/sendrequest_func_test.c b/distributedschedule_lite/samgr_hal/src/sendrequest_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..7808784c9f57c8a876a1386224bb6620ed32d000 --- /dev/null +++ b/distributedschedule_lite/samgr_hal/src/sendrequest_func_test.c @@ -0,0 +1,717 @@ +/* + * Copyright (c) 2020 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 "securec.h" +#include "hctest.h" +#include "samgr_lite.h" + +#define OPER_INTERVAL 200 // 200 ms +#define PRESSURE_BASE (1024 * 10) + +enum MessageId { + MSG_NO, // receiver does not send response + MSG_RT, // receiver send response + MSG_FW, // receiver forward message +}; + +struct Payload { + int id; + const char *name; + int value; +}; + +typedef struct DemoApi { + INHERIT_IUNKNOWN; + BOOL(*SyncCall) + (IUnknown *iUnknown, struct Payload *payload); + int32 (*SAMGR_SendRequestProxy)(const Identity *identity, const Request *request, Handler handler); +} DemoApi; + +typedef struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoApi); + Identity identity; + int featureCalledCount; + BOOL featureStatus; + char *latestRequest; +} DemoFeature; + +typedef struct DefaultFeatureApi { + INHERIT_IUNKNOWN; +} DefaultFeatureApi; + +typedef struct ExampleService { + INHERIT_SERVICE; + INHERIT_IUNKNOWNENTRY(DefaultFeatureApi); + Identity identity; +} ExampleService; + +static BOOL SyncCall(IUnknown *iUnknown, struct Payload *payload) +{ + (void)iUnknown; + if (payload != NULL && payload->id >= 0 && payload->name != NULL) { + return TRUE; + } else { + return FALSE; + } +} + +static int32 SAMGR_SendRequestProxy(const Identity *identity, const Request *request, Handler handler) +{ + return SAMGR_SendRequest(identity, request, handler); +} + +static const char *GetName(Service *service) +{ + (void)service; + return "serviceName501"; +} + +static BOOL Initialize(Service *service, Identity identity) +{ + ExampleService *example = (ExampleService *)service; + example->identity = identity; + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)service; + (void)msg; + return FALSE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + (void)service; + TaskConfig config = {LEVEL_HIGH, PRI_ABOVE_NORMAL, 0x800, 20, SHARED_TASK}; + return config; +} + +static ExampleService g_service = { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + } +}; + +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return "featureName501"; +} + +static const char *FEATURE_GetName02(Feature *feature) +{ + (void)feature; + return "featureName502"; +} + +static const char *FEATURE_GetName03(Feature *feature) +{ + (void)feature; + return "featureName503"; +} + +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; + (void)parent; +} + +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *request) +{ + int32 returnCode = 0;; + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + demoFeature->latestRequest = (char *)request->data; + + switch (request->msgId) { + case MSG_NO: + returnCode = 0; + break; + case MSG_RT: + { + Response response = { + .data = "Yes, you did!", + .len = 0, + }; + returnCode = SAMGR_SendResponse(request, &response); + }; + break; + case MSG_FW: + { + returnCode = 0; + }; + break; + } + demoFeature->featureStatus = ((returnCode == 0) ? TRUE : FALSE); + return demoFeature->featureStatus; +} + +static BOOL FEATURE_OnMessage02(Feature *feature, Request *request) +{ + int32 returnCode = 0; + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + demoFeature->latestRequest = (char *)request->data; + + switch (request->msgId) { + case MSG_NO: + returnCode = 0; + break; + case MSG_RT: + { + Response response = { + .data = "Yes, you did!", + .len = 0, + }; + returnCode = SAMGR_SendResponse(request, &response); + }; + break; + case MSG_FW: + { + returnCode = 0; + }; + break; + } + demoFeature->featureStatus = ((returnCode == 0) ? TRUE : FALSE); + return demoFeature->featureStatus; +} + +static BOOL FEATURE_OnMessage03(Feature *feature, Request *request) +{ + int32 returnCode = 0; + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + demoFeature->latestRequest = (char *)request->data; + + switch (request->msgId) { + case MSG_NO: + returnCode = 0; + break; + case MSG_RT: + { + Response response = { + .data = "Yes, you did!", + .len = 0, + }; + returnCode = SAMGR_SendResponse(request, &response); + }; + break; + case MSG_FW: + { + returnCode = 0; + }; + break; + } + demoFeature->featureStatus = ((returnCode == 0) ? TRUE : FALSE); + return demoFeature->featureStatus; +} + +static DemoFeature g_feature = { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .SyncCall = SyncCall, + .SAMGR_SendRequestProxy = SAMGR_SendRequestProxy, + }, + .identity = {-1, -1, NULL}, + .featureCalledCount = 0, + .featureStatus = TRUE, + .latestRequest = NULL, +}; +static DemoFeature g_feature02 = { + .GetName = FEATURE_GetName02, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage02, + .ref = 0, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .SyncCall = SyncCall, + .SAMGR_SendRequestProxy = SAMGR_SendRequestProxy, + }, + .identity = {-1, 1, NULL}, + .featureCalledCount = 0, + .featureStatus = TRUE, + .latestRequest = NULL, +}; +static DemoFeature g_feature03 = { + .GetName = FEATURE_GetName03, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage03, + .ref = 0, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .SyncCall = SyncCall, + .SAMGR_SendRequestProxy = SAMGR_SendRequestProxy, + }, + .identity = {-1, 2, NULL}, + .featureCalledCount = 0, + .featureStatus = TRUE, + .latestRequest = NULL, +}; + +static void ServiceInit(void) +{ + BOOL result = SAMGR_GetInstance()->RegisterService((Service *)&g_service); + if (result == FALSE) { + printf("[hctest]E RegisterService failed. \n"); + } +} +SYSEX_SERVICE_INIT(ServiceInit); + +static void FeatureInit(void) +{ + BOOL result1 = SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName501", GET_IUNKNOWN(g_feature)); + + BOOL result2 = SAMGR_GetInstance()->RegisterFeature("serviceName501", (Feature *)&g_feature02); + BOOL result3 = SAMGR_GetInstance()->RegisterFeatureApi("serviceName501", "featureName502", + GET_IUNKNOWN(g_feature02)); + + BOOL result4 = SAMGR_GetInstance()->RegisterFeature("serviceName501", (Feature *)&g_feature03); + BOOL result5 = SAMGR_GetInstance()->RegisterFeatureApi("serviceName501", "featureName503", + GET_IUNKNOWN(g_feature03)); + if (result1 == FALSE || result2 == FALSE || result3 == FALSE || result4 == FALSE || result5 == FALSE) { + printf("[hctest]E failed to register feature or api.\n"); + } +} +SYSEX_FEATURE_INIT(FeatureInit); + +static DemoApi *GetIUnknown(const char *serviceName, const char *featureName) +{ + DemoApi *demoApi = NULL; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(serviceName, featureName); + if (iUnknown == NULL) { + printf("[hctest]failed to GetFeatureApi.\n"); + return NULL; + } + int result = iUnknown->QueryInterface(iUnknown, 0, (void **)&demoApi); + if (result == 0 && demoApi != NULL) { + return demoApi; + } else { + printf("[hctest]failed to QueryInterface.\n"); + return NULL; + } +} + +static void ReleaseIUnknown(DemoApi *demoApi) +{ + demoApi->Release((IUnknown *)demoApi); +} + +static void DemoHandlerAndCheck(const Request *request, const Response *response) +{ + char *requestData = "I wanna async call good result!"; + TEST_ASSERT_EQUAL_INT(strcmp((char *)request->data, requestData), 0); + + char *responseData = "Yes, you did!"; + TEST_ASSERT_EQUAL_INT(strcmp((char *)response->data, responseData), 0); +} + +LITE_TEST_SUIT(test, samgr, SendRequestTestSuite); + +static BOOL SendRequestTestSuiteSetUp(void) +{ + LOS_Msleep(OPER_INTERVAL); + return TRUE; +} + +static BOOL SendRequestTestSuiteTearDown(void) +{ + return TRUE; +} + +/** + * @tc.number : DMSLite_SAMGR_SyncCall_0010 + * @tc.name : Samgr support synchronous call + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(SendRequestTestSuite, testSyncCall0010, LEVEL1) +{ + DemoApi *demoApi = GetIUnknown("serviceName501", "featureName502"); + if (demoApi == NULL) { + TEST_FAIL(); + } + struct Payload payload = { + .id = 0, // api will return true + .name = "I wanna sync call good result!", + .value = 1}; + BOOL result = demoApi->SyncCall((IUnknown *)demoApi, &payload); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + struct Payload payloadX = { + .id = -1, // api will return false + .name = "I wanna sync call good result!", + .value = 1}; + result = demoApi->SyncCall((IUnknown *)demoApi, &payloadX); + TEST_ASSERT_EQUAL_INT(result, FALSE); + + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendRequest_0010 + * @tc.name : Samgr support asynchronous call + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(SendRequestTestSuite, testSendRequest0010, LEVEL1) +{ + DemoApi *demoApi = GetIUnknown("serviceName501", "featureName502"); + if (demoApi == NULL) { + TEST_FAIL(); + } + Request request = {.msgId = MSG_RT, .msgValue = 0}; + char *body = "I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName501", "featureName503"); + if (iUnknown == NULL) { + TEST_FAIL(); + } + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + + feature->featureCalledCount = 0; + int32 result = demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, NULL); + TEST_ASSERT_EQUAL_INT(result == 0, TRUE); + + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(feature->featureCalledCount == 1, TRUE); + TEST_ASSERT_EQUAL_INT(strcmp(feature->latestRequest, body), 0); + + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendRequest_0020 + * @tc.name : Feature can send an asynchronous message to itself + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SendRequestTestSuite, testSendRequest0020, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("serviceName501", "featureName502"); + if (demoApi == NULL) { + TEST_FAIL(); + } + Request request = {.msgId = MSG_RT, .msgValue = 0}; + char *body = "I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName501", "featureName502"); + if (iUnknown == NULL) { + TEST_FAIL(); + } + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + + feature->featureCalledCount = 0; + int32 result = demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, NULL); + TEST_ASSERT_EQUAL_INT(result == 0, TRUE); + + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(feature->featureCalledCount == 1, TRUE); + TEST_ASSERT_EQUAL_INT(strcmp(feature->latestRequest, body), 0); + + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendRequest_0030 + * @tc.name : Feature failed to send an asynchronous message if the specified identity does not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SendRequestTestSuite, testSendRequest0030, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("serviceName501", "featureName502"); + if (demoApi == NULL) { + TEST_FAIL(); + } + Request request = {.msgId = MSG_RT, .msgValue = 0}; + char *body = "I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + + Identity identityX = {-1, -200, NULL}; + int32 result = demoApi->SAMGR_SendRequestProxy(&identityX, &request, NULL); + TEST_ASSERT_EQUAL_INT(result != 0, TRUE); + + free(request.data); + request.data = NULL; + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendRequest_0040 + * @tc.name : Feature can send an asynchronous message with length is 0 + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SendRequestTestSuite, testSendRequest0040, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("serviceName501", "featureName502"); + if (demoApi == NULL) { + TEST_FAIL(); + } + Request request = {.msgId = MSG_RT, .msgValue = 0}; + request.len = 0; + request.data = NULL; + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName501", "featureName503"); + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + + feature->featureCalledCount = 0; + int32 result = demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, NULL); + TEST_ASSERT_EQUAL_INT(result == 0, TRUE); + + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(feature->featureCalledCount == 1, TRUE); + + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendRequest_0050 + * @tc.name : Feature failed to send an asynchronous message if id or request is NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SendRequestTestSuite, testSendRequest0050, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("serviceName501", "featureName502"); + if (demoApi == NULL) { + TEST_FAIL(); + } + Request request = {.msgId = MSG_RT, .msgValue = 0}; + char *body = ""; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName501", "featureName503"); + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + + int32 result = demoApi->SAMGR_SendRequestProxy(NULL, &request, NULL); + TEST_ASSERT_EQUAL_INT(result != 0, TRUE); + + result = demoApi->SAMGR_SendRequestProxy(&feature->identity, NULL, NULL); + TEST_ASSERT_EQUAL_INT(result != 0, TRUE); + + free(request.data); + request.data = NULL; + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendRequest_0060 + * @tc.name : Samgr will not check the matching relationship between len and data + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SendRequestTestSuite, testSendRequest0060, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("serviceName501", "featureName502"); + if (demoApi == NULL) { + TEST_FAIL(); + } + Request request = {.msgId = MSG_NO, .msgValue = 0}; + char *body = "I wanna async call good result!"; + request.len = 0; + request.data = NULL; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName501", "featureName503"); + if (iUnknown == NULL) { + TEST_FAIL(); + } + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + + int32 result = demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, NULL); + TEST_ASSERT_EQUAL_INT(result == 0, TRUE); + + Request request2 = {.msgId = MSG_NO, .msgValue = 0}; + request2.len = (int16)(strlen(body) + 1); + request2.data = malloc(request2.len); + if (request2.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request2.data, request2.len, body); + + result = demoApi->SAMGR_SendRequestProxy(&feature->identity, &request2, NULL); + TEST_ASSERT_EQUAL_INT(result == 0, TRUE); + + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendRequest_0070 + * @tc.name : Feature send an asynchronous message and register handler then can receive response + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SendRequestTestSuite, testSendRequest0070, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("serviceName501", "featureName502"); + if (demoApi == NULL) { + TEST_FAIL(); + } + Request request = {.msgId = MSG_RT, .msgValue = 0}; + char *body = "I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName501", "featureName503"); + if (iUnknown == NULL) { + TEST_FAIL(); + } + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + + int32 result = demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, DemoHandlerAndCheck); + TEST_ASSERT_EQUAL_INT(result, 0); + TEST_ASSERT_EQUAL_INT(strcmp(feature->latestRequest, body), 0); + + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendRequest_0080 + * @tc.name : Feature send an asynchronous message repeatedly, no memory leak + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SendRequestTestSuite, testSendRequest0080, LEVEL2) +{ + for (int i = 0; i < PRESSURE_BASE; i++) { + DemoApi *demoApi = GetIUnknown("serviceName501", "featureName502"); + if (demoApi == NULL) { + TEST_FAIL(); + } + Request request = {.msgId = MSG_RT, .msgValue = 0}; + char *body = "I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName501", "featureName503"); + if (iUnknown == NULL) { + TEST_FAIL(); + } + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + + int32 result = demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, DemoHandlerAndCheck); + TEST_ASSERT_EQUAL_INT(result, 0); + TEST_ASSERT_EQUAL_INT(strcmp(feature->latestRequest, body), 0); + + ReleaseIUnknown(demoApi); + } +} + +/** + * @tc.number : DMSLite_SAMGR_SendRequest_0090 + * @tc.name : Feature send an asynchronous message with 0 len repeatedly, no memory leak + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SendRequestTestSuite, testSendRequest0090, LEVEL2) +{ + for (int i = 0; i < PRESSURE_BASE; i++) { + DemoApi *demoApi = GetIUnknown("serviceName501", "featureName502"); + if (demoApi == NULL) { + TEST_FAIL(); + } + Request request = {.msgId = MSG_RT, .msgValue = 0}; + char body[]= "I wanna async call good result!"; + request.len = 0; + request.data = body; + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName501", "featureName503"); + if (iUnknown == NULL) { + TEST_FAIL(); + } + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + + int32 result = demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, DemoHandlerAndCheck); + TEST_ASSERT_EQUAL_INT(result, 0); + TEST_ASSERT_EQUAL_INT(strcmp(feature->latestRequest, body), 0); + + ReleaseIUnknown(demoApi); + } +} + +RUN_TEST_SUITE(SendRequestTestSuite); \ No newline at end of file diff --git a/distributedschedule_lite/samgr_hal/src/sendresponse_func_test.c b/distributedschedule_lite/samgr_hal/src/sendresponse_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..afc6e4aa2caa8ef815ef9c96e9e58ca40fc2767f --- /dev/null +++ b/distributedschedule_lite/samgr_hal/src/sendresponse_func_test.c @@ -0,0 +1,565 @@ +/* + * Copyright (c) 2020 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 "securec.h" +#include "hctest.h" +#include "samgr_lite.h" + +#define OPER_INTERVAL 200 // 200 ms +#define PRESSURE_BASE (1024 * 10) + +enum MessageId { + MSG_NO = 1, // receiver does not send response + MSG_RT = 2, // receiver send response + MSG_FW = 3, // receiver forward message + MSG_RT_MULTI = 4, // receiver send response +}; + +struct Payload { + int id; + const char *name; + int value; +}; + +typedef struct DemoApi { + INHERIT_IUNKNOWN; + int32 (*SAMGR_SendRequestProxy)(const Identity *identity, const Request *request, Handler handler); +} DemoApi; + +typedef struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoApi); + Identity identity; + int featureCalledCount; + BOOL featureStatus; +} DemoFeature; + +typedef struct DefaultFeatureApi { + INHERIT_IUNKNOWN; +} DefaultFeatureApi; + +typedef struct ExampleService { + INHERIT_SERVICE; + INHERIT_IUNKNOWNENTRY(DefaultFeatureApi); + Identity identity; +} ExampleService; + +static int32 SAMGR_SendRequestProxy(const Identity *identity, const Request *request, Handler handler) +{ + return SAMGR_SendRequest(identity, request, handler); +} + +static const char *GetName(Service *service) +{ + (void)service; + return "serviceName601"; +} + +static BOOL Initialize(Service *service, Identity identity) +{ + ExampleService *example = (ExampleService *)service; + example->identity = identity; + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)service; + (void)msg; + return FALSE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + (void)service; + TaskConfig config = {LEVEL_HIGH, PRI_ABOVE_NORMAL, 0x800, 20, SHARED_TASK}; // share with broadcast + return config; +} + +static ExampleService g_service = { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + } +}; + +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return "featureName601"; +} + +static const char *FEATURE_GetName02(Feature *feature) +{ + (void)feature; + return "featureName602"; +} + +static const char *FEATURE_GetName03(Feature *feature) +{ + (void)feature; + return "featureName603"; +} + +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; + (void)parent; +} + +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *request) +{ + (void)request; + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + demoFeature->featureStatus = TRUE; + + return TRUE; +} + +static BOOL FEATURE_OnMessage02(Feature *feature, Request *request) +{ + int32 returnCode = 0; + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + + switch (request->msgId) { + case MSG_NO: + returnCode = 0; + break; + case MSG_RT: + { + Response response = { + .data = "Yes, you did!", + .len = 0, + }; + returnCode = SAMGR_SendResponse(request, &response); + }; + break; + case MSG_FW: + { + Response response = { + .data = "Yes, you did!", + .len = 0, + }; + request->msgId = MSG_NO; + IUnknown *iUnknownX = SAMGR_GetInstance()->GetFeatureApi("serviceName601", "featureName602"); + DemoFeature *featureX = GET_OBJECT(iUnknownX, DemoFeature, iUnknown); + returnCode = SAMGR_SendResponseByIdentity(&featureX->identity, request, &response); + }; + break; + } + demoFeature->featureStatus = ((returnCode == 0) ? TRUE : FALSE); + return demoFeature->featureStatus; +} + +static BOOL FEATURE_OnMessage03(Feature *feature, Request *request) +{ + int32 returnCode = 0; + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + + switch (request->msgId) { + case MSG_NO: + returnCode = 0; + break; + case MSG_RT: + { + Response response = { + .data = "Yes, you did!", + .len = 0, + }; + returnCode = SAMGR_SendResponse(request, &response); + }; + break; + case MSG_FW: + { + Response response = { + .data = "Yes, you did!", + .len = 0, + }; + request->msgId = MSG_NO; + IUnknown *iUnknownX = SAMGR_GetInstance()->GetFeatureApi("serviceName601", "featureName602"); + DemoFeature *featureX = GET_OBJECT(iUnknownX, DemoFeature, iUnknown); + returnCode = SAMGR_SendResponseByIdentity(&featureX->identity, request, &response); + }; + break; + case MSG_RT_MULTI: + { + Response response = { + .data = "Yes, you did!", + .len = 0, + }; + for (int i = 0; i < PRESSURE_BASE; i++) { + int tempCode = SAMGR_SendResponse(request, &response); + if (tempCode != 0) { + printf("[hctest]E failed to SendResponse occurs: %d rt: %d \n", i, tempCode); + returnCode++; + } + } + }; + break; + } + demoFeature->featureStatus = ((returnCode == 0) ? TRUE : FALSE); + return demoFeature->featureStatus; +} + +static DemoFeature g_feature = { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .SAMGR_SendRequestProxy = SAMGR_SendRequestProxy, + }, + .identity = {-1, -1, NULL}, + .featureCalledCount = 0, + .featureStatus = TRUE, +}; +static DemoFeature g_feature02 = { + .GetName = FEATURE_GetName02, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage02, + .ref = 0, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .SAMGR_SendRequestProxy = SAMGR_SendRequestProxy, + }, + .identity = {-1, 1, NULL}, + .featureCalledCount = 0, + .featureStatus = TRUE, +}; +static DemoFeature g_feature03 = { + .GetName = FEATURE_GetName03, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage03, + .ref = 0, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .SAMGR_SendRequestProxy = SAMGR_SendRequestProxy, + }, + .identity = {-1, 2, NULL}, + .featureCalledCount = 0, + .featureStatus = TRUE, +}; + +static void ServiceInit(void) +{ + BOOL result = SAMGR_GetInstance()->RegisterService((Service *)&g_service); + if (result == FALSE) { + printf("[hctest]E RegisterService failed \n"); + } +} +SYSEX_SERVICE_INIT(ServiceInit); + +static void FeatureInit(void) +{ + BOOL result1 = SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName601", GET_IUNKNOWN(g_feature)); + + BOOL result2 = SAMGR_GetInstance()->RegisterFeature("serviceName601", (Feature *)&g_feature02); + BOOL result3 = SAMGR_GetInstance()->RegisterFeatureApi("serviceName601", "featureName602", + GET_IUNKNOWN(g_feature02)); + + BOOL result4 = SAMGR_GetInstance()->RegisterFeature("serviceName601", (Feature *)&g_feature03); + BOOL result5 = SAMGR_GetInstance()->RegisterFeatureApi("serviceName601", "featureName603", + GET_IUNKNOWN(g_feature03)); + if (result1 == FALSE || result2 == FALSE || result3 == FALSE || result4 == FALSE || result5 == FALSE) { + printf("[hctest]E failed to register feature or api.\n"); + } +} +SYSEX_FEATURE_INIT(FeatureInit); + +static DemoApi *GetIUnknown(const char *serviceName, const char *featureName) +{ + DemoApi *demoApi = NULL; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(serviceName, featureName); + if (iUnknown == NULL) { + printf("[hctest]failed to GetFeatureApi.\n"); + return NULL; + } + int result = iUnknown->QueryInterface(iUnknown, 0, (void **)&demoApi); + if (result == 0 && demoApi != NULL) { + return demoApi; + } else { + printf("[hctest]failed to QueryInterface.\n"); + return NULL; + } +} + +static void ReleaseIUnknown(DemoApi *demoApi) +{ + demoApi->Release((IUnknown *)demoApi); +} + +static void DemoHandlerAndCheck(const Request *request, const Response *response) +{ + char *requestData = "I wanna async call good result!"; + TEST_ASSERT_EQUAL_INT(strcmp((char *)request->data, requestData), 0); + + char *responseData = "Yes, you did!"; + TEST_ASSERT_EQUAL_INT(strcmp((char *)response->data, responseData), 0); +} + +static void DemoHandler(const Request *request, const Response *response) +{ + (void)request; + (void)response; +} + +LITE_TEST_SUIT(test, samgr, SendResponseTestSuite); + +static BOOL SendResponseTestSuiteSetUp(void) +{ + LOS_Msleep(OPER_INTERVAL); + return TRUE; +} + +static BOOL SendResponseTestSuiteTearDown(void) +{ + return TRUE; +} + +/** + * @tc.number : DMSLite_SAMGR_SendResponse_0010 + * @tc.name : Receiver send response successfully + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SendResponseTestSuite, testSendResponse0010, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("serviceName601", "featureName602"); + if (demoApi == NULL) { + TEST_FAIL(); + } + Request request = {.msgId = MSG_RT, .msgValue = 0}; + char *body = "I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName601", "featureName603"); + if (iUnknown == NULL) { + TEST_FAIL(); + } + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, DemoHandlerAndCheck); + + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(feature->featureStatus == TRUE, TRUE); + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendResponse_0020 + * @tc.name : Receiver can not send response if sender has not register callback + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SendResponseTestSuite, testSendResponse0020, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("serviceName601", "featureName602"); + if (demoApi == NULL) { + TEST_FAIL(); + } + Request request = {.msgId = MSG_RT, .msgValue = 0}; + char *body = "I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName601", "featureName603"); + if (iUnknown == NULL) { + TEST_FAIL(); + } + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, NULL); + + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(feature->featureStatus == FALSE, TRUE); + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendResponse_0030 + * @tc.name : Receiver send response to itself successfully + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SendResponseTestSuite, testSendResponse0030, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("serviceName601", "featureName603"); + if (demoApi == NULL) { + TEST_FAIL(); + } + Request request = {.msgId = MSG_RT, .msgValue = 0}; + char *body = "I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName601", "featureName603"); + if (iUnknown == NULL) { + TEST_FAIL(); + } + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, DemoHandler); + + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(feature->featureStatus == TRUE, TRUE); + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendResponse_0040 + * @tc.name : Receiver send response to the origin feature repeatedly + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SendResponseTestSuite, testSendResponse0040, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("serviceName601", "featureName602"); + if (demoApi == NULL) { + TEST_FAIL(); + } + Request request = {.msgId = MSG_RT_MULTI, .msgValue = 0}; // MSG_RT_MULTI: multi response + char *body = "I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName601", "featureName603"); + if (iUnknown == NULL) { + TEST_FAIL(); + } + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, DemoHandlerAndCheck); + + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(feature->featureStatus, TRUE); + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendResponseByIdentity_0010 + * @tc.name : Receiver forward message successfully + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SendResponseTestSuite, testSendResponseByIdentity0010, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("serviceName601", "featureName602"); + if (demoApi == NULL) { + TEST_FAIL(); + } + Request request = {.msgId = MSG_FW, .msgValue = 0}; + char *body = "I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName601", "featureName603"); + if (iUnknown == NULL) { + TEST_FAIL(); + } + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + feature->featureStatus = FALSE; + demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, DemoHandlerAndCheck); + + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(feature->featureStatus == TRUE, TRUE); + + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendResponseByIdentity_0020 + * @tc.name : Receiver can not forward message if the sender has not registered handler + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SendResponseTestSuite, testSendResponseByIdentity0020, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("serviceName601", "featureName602"); + if (demoApi == NULL) { + TEST_FAIL(); + } + Request request = {.msgId = MSG_FW, .msgValue = 0}; + char *body = "I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName601", "featureName603"); + if (iUnknown == NULL) { + TEST_FAIL(); + } + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, NULL); + + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(feature->featureStatus == FALSE, TRUE); + + ReleaseIUnknown(demoApi); +} + +RUN_TEST_SUITE(SendResponseTestSuite); \ No newline at end of file diff --git a/distributedschedule_lite/samgr_hal/src/sendsharerequest_func_test.c b/distributedschedule_lite/samgr_hal/src/sendsharerequest_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..d7e1b29f1942b8cac3a04444b0450c32caf66683 --- /dev/null +++ b/distributedschedule_lite/samgr_hal/src/sendsharerequest_func_test.c @@ -0,0 +1,420 @@ +/* + * Copyright (c) 2020 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 "securec.h" +#include "hctest.h" +#include "samgr_lite.h" + +#define OPER_INTERVAL 200 // 200 ms +#define PRESSURE_BASE (1024 * 10) + +enum MessageId { + MSG_NO, // receiver does not send response + MSG_RT, // receiver send response + MSG_FW, // receiver forward message +}; + +struct Payload { + int id; + const char *name; + int value; +}; + +typedef struct DemoApi { + INHERIT_IUNKNOWN; + uint32 *(*SAMGR_SendSharedRequestProxy)(const Identity *identity, const Request *request, uint32 *token, + Handler handler); + int32 (*SAMGR_SendSharedDirectRequestProxy)(const Identity *id, const Request *req, const Response *resp, + uint32 **ref, Handler handler); +} DemoApi; + +typedef struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoApi); + Identity identity; + int featureCalledCount; + BOOL featureStatus; + char *latestRequest; +} DemoFeature; + +typedef struct DefaultFeatureApi { + INHERIT_IUNKNOWN; +} DefaultFeatureApi; + +typedef struct ExampleService { + INHERIT_SERVICE; + INHERIT_IUNKNOWNENTRY(DefaultFeatureApi); + Identity identity; +} ExampleService; + +static uint32 *SAMGR_SendSharedRequestProxy(const Identity *identity, const Request *request, uint32 *token, + Handler handler) +{ + return SAMGR_SendSharedRequest(identity, request, token, handler); +} + +static int32 SAMGR_SendSharedDirectRequestProxy(const Identity *id, const Request *req, const Response *resp, + uint32 **ref, Handler handler) +{ + return SAMGR_SendSharedDirectRequest(id, req, resp, ref, handler); +} + +static const char *GetName(Service *service) +{ + (void)service; + return "S_sendShareReq"; +} + +static BOOL Initialize(Service *service, Identity identity) +{ + ExampleService *example = (ExampleService *)service; + example->identity = identity; + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)service; + (void)msg; + return FALSE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + (void)service; + TaskConfig config = {LEVEL_HIGH, PRI_ABOVE_NORMAL, 0x800, 20, SHARED_TASK}; + return config; +} + +static ExampleService g_service = { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + } +}; + +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return "feature01"; +} + +static const char *FEATURE_GetName02(Feature *feature) +{ + (void)feature; + return "feature02"; +} + +static const char *FEATURE_GetName03(Feature *feature) +{ + (void)feature; + return "feature03"; +} + +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; + (void)parent; +} + +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *request) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + demoFeature->latestRequest = (char *)request->data; + + demoFeature->featureStatus = TRUE; + return TRUE; +} + +static BOOL FEATURE_OnMessage02(Feature *feature, Request *request) +{ + int32 returnCode = 0; + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + demoFeature->latestRequest = (char *)request->data; + + switch (request->msgId) { + case MSG_NO: + returnCode = 0; + break; + case MSG_RT: + { + Response response = { + .data = "Yes, you did!", + .len = 0, + }; + returnCode = SAMGR_SendResponse(request, &response); + }; + break; + case MSG_FW: + { + returnCode = 0; + }; + break; + } + demoFeature->featureStatus = ((returnCode == 0) ? TRUE : FALSE); + return demoFeature->featureStatus; +} + +static BOOL FEATURE_OnMessage03(Feature *feature, Request *request) +{ + int32 returnCode = 0; + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + demoFeature->latestRequest = (char *)request->data; + + switch (request->msgId) { + case MSG_NO: + returnCode = 0; + break; + case MSG_RT: + { + Response response = { + .data = "Yes, you did!", + .len = 0, + }; + returnCode = SAMGR_SendResponse(request, &response); + }; + break; + case MSG_FW: + { + returnCode = 0; + }; + break; + } + demoFeature->featureStatus = ((returnCode == 0) ? TRUE : FALSE); + return demoFeature->featureStatus; +} + +static DemoFeature g_feature = { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .SAMGR_SendSharedRequestProxy = SAMGR_SendSharedRequestProxy, + .SAMGR_SendSharedDirectRequestProxy = SAMGR_SendSharedDirectRequestProxy, + }, + .identity = {-1, -1, NULL}, + .featureCalledCount = 0, + .featureStatus = TRUE, + .latestRequest = NULL, +}; +static DemoFeature g_feature02 = { + .GetName = FEATURE_GetName02, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage02, + .ref = 0, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .SAMGR_SendSharedRequestProxy = SAMGR_SendSharedRequestProxy, + .SAMGR_SendSharedDirectRequestProxy = SAMGR_SendSharedDirectRequestProxy, + }, + .identity = {-1, 1, NULL}, + .featureCalledCount = 0, + .featureStatus = TRUE, + .latestRequest = NULL, +}; +static DemoFeature g_feature03 = { + .GetName = FEATURE_GetName03, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage03, + .ref = 0, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .SAMGR_SendSharedRequestProxy = SAMGR_SendSharedRequestProxy, + .SAMGR_SendSharedDirectRequestProxy = SAMGR_SendSharedDirectRequestProxy, + }, + .identity = {-1, 2, NULL}, + .featureCalledCount = 0, + .featureStatus = TRUE, + .latestRequest = NULL, +}; + +static void ServiceInit(void) +{ + BOOL result = SAMGR_GetInstance()->RegisterService((Service *)&g_service); + if (result == FALSE) { + printf("[hctest]E RegisterService failed.\n"); + } +} +SYSEX_SERVICE_INIT(ServiceInit); + +static void FeatureInit(void) +{ + BOOL result1 = SAMGR_GetInstance()->RegisterDefaultFeatureApi("S_sendShareReq", GET_IUNKNOWN(g_feature)); + + BOOL result2 = SAMGR_GetInstance()->RegisterFeature("S_sendShareReq", (Feature *)&g_feature02); + BOOL result3 = SAMGR_GetInstance()->RegisterFeatureApi("S_sendShareReq", "feature02", + GET_IUNKNOWN(g_feature02)); + + BOOL result4 = SAMGR_GetInstance()->RegisterFeature("S_sendShareReq", (Feature *)&g_feature03); + BOOL result5 = SAMGR_GetInstance()->RegisterFeatureApi("S_sendShareReq", "feature03", + GET_IUNKNOWN(g_feature03)); + if (result1 == FALSE || result2 == FALSE || result3 == FALSE || result4 == FALSE || result5 == FALSE) { + printf("[hctest]E failed to register feature or api.\n"); + } +} +SYSEX_FEATURE_INIT(FeatureInit); + +static DemoApi *GetIUnknown(const char *serviceName, const char *featureName) +{ + DemoApi *demoApi = NULL; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(serviceName, featureName); + if (iUnknown == NULL) { + printf("[hctest]failed to GetFeatureApi.\n"); + return NULL; + } + int result = iUnknown->QueryInterface(iUnknown, 0, (void **)&demoApi); + if (result == 0 && demoApi != NULL) { + return demoApi; + } else { + printf("[hctest]failed to QueryInterface.\n"); + return NULL; + } +} + +static void ReleaseIUnknown(DemoApi *demoApi) +{ + demoApi->Release((IUnknown *)demoApi); +} + +static void DemoHandlerAndCheck(const Request *request, const Response *response) +{ + char *requestData = "I wanna async call good result!"; + TEST_ASSERT_EQUAL_INT(strcmp((char *)request->data, requestData), 0); + + char *responseData = "Yes, you did!"; + TEST_ASSERT_EQUAL_INT(strcmp((char *)response->data, responseData), 0); +} + +LITE_TEST_SUIT(test, samgr, SendSharedRequestTestSuite); + +static BOOL SendSharedRequestTestSuiteSetUp(void) +{ + LOS_Msleep(OPER_INTERVAL); + return TRUE; +} + +static BOOL SendSharedRequestTestSuiteTearDown(void) +{ + return TRUE; +} + +/** + * @tc.number : DMSLite_SAMGR_SendSharedRequest_0010 + * @tc.name : Feature sends a response to a specified feature after processing the original request. + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SendSharedRequestTestSuite, testSendSharedRequest0010, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("S_sendShareReq", "feature02"); + if (demoApi == NULL) { + TEST_FAIL(); + } + Request request = {.msgId = MSG_RT, .msgValue = 0}; + char *body = "I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("S_sendShareReq", "feature03"); + if (iUnknown == NULL) { + TEST_FAIL(); + } + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + + feature->featureCalledCount = 0; + uint32 *token = NULL; + token = demoApi->SAMGR_SendSharedRequestProxy(&feature->identity, &request, token, DemoHandlerAndCheck); + + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(feature->featureCalledCount, 1); + TEST_ASSERT_EQUAL_INT(strcmp(feature->latestRequest, body), 0); + + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendSharedDirectRequest_0010 + * @tc.name : Sends a request and response of a caller to the feature thread + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SendSharedRequestTestSuite, testSendSharedDirectRequest0010, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("S_sendShareReq", "feature02"); + if (demoApi == NULL) { + TEST_FAIL(); + } + Request request = {.msgId = MSG_RT, .msgValue = 0}; + char *body = "I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("S_sendShareReq", "feature03"); + if (iUnknown == NULL) { + TEST_FAIL(); + } + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + + feature->featureCalledCount = 0; + Response response = { + .data = "Yes, you did!", + .len = 0, + }; + uint32 *token = NULL; + int32 result = demoApi->SAMGR_SendSharedDirectRequestProxy(&feature->identity, &request, &response, + &token, DemoHandlerAndCheck); + TEST_ASSERT_EQUAL_INT(result, 0); + + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(feature->featureCalledCount, 0); + + ReleaseIUnknown(demoApi); +} + +RUN_TEST_SUITE(SendSharedRequestTestSuite); \ No newline at end of file diff --git a/distributedschedule_lite/samgr_hal/src/service_func_test.c b/distributedschedule_lite/samgr_hal/src/service_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..1c3d01f16eb2dfc7ec239ab0590569feaaf81e1d --- /dev/null +++ b/distributedschedule_lite/samgr_hal/src/service_func_test.c @@ -0,0 +1,302 @@ +/* + * Copyright (c) 2020 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 "hctest.h" +#include "samgr_lite.h" + +#define OPER_INTERVAL 200 // 200 ms +#define PRESSURE_BASE (1024 * 10) + +typedef struct DefaultFeatureApi { + INHERIT_IUNKNOWN; +} DefaultFeatureApi; + +typedef struct ExampleService { + INHERIT_SERVICE; + INHERIT_IUNKNOWNENTRY(DefaultFeatureApi); + Identity identity; +} ExampleService; + +typedef struct DemoApi { + INHERIT_IUNKNOWN; +} DemoApi; + +typedef struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoApi); + Identity identity; +} DemoFeature; + +static const char *GetName(Service *service) +{ + (void)service; + return "serviceName101"; +} + +static BOOL Initialize(Service *service, Identity identity) +{ + ExampleService *example = (ExampleService *)service; + example->identity = identity; + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)msg; + (void)service; + return FALSE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + (void)service; + TaskConfig config = {LEVEL_HIGH, PRI_ABOVE_NORMAL, 0x800, 20, SHARED_TASK}; + return config; +} + +static ExampleService g_service = { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + } +}; + +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return "featureName101"; +} +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; + (void)parent; +} +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *request) +{ + (void)feature; + (void)request; + return TRUE; +} + +static DemoFeature g_feature = { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + }, + .identity = {-1, -1, NULL}, +}; + +LITE_TEST_SUIT(test, samgr, ServiceTestSuite); + +static BOOL ServiceTestSuiteSetUp(void) +{ + LOS_Msleep(OPER_INTERVAL); + return TRUE; +} + +static BOOL ServiceTestSuiteTearDown(void) +{ + return TRUE; +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterService_0010 + * @tc.name : Valid service can be registered + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ServiceTestSuite, testRegisterService0010, LEVEL1) +{ + BOOL result = SAMGR_GetInstance()->RegisterService((Service *)&g_service); + TEST_ASSERT_EQUAL_INT(result, TRUE); // TRUE: regist success; FALSE: regist fail + + SAMGR_GetInstance()->UnregisterService("serviceName101"); +}; + +/** + * @tc.number : DMSLite_SAMGR_RegisterService_0020 + * @tc.name : Service which is NULL failed to register + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(ServiceTestSuite, testRegisterService0020, LEVEL2) +{ + BOOL result = SAMGR_GetInstance()->RegisterService(NULL); + TEST_ASSERT_EQUAL_INT(result, FALSE); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterService_0030 + * @tc.name : Service which already exist in samgr failed to register + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(ServiceTestSuite, testRegisterService0030, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + BOOL result = SAMGR_GetInstance()->RegisterService((Service *)&g_service); + TEST_ASSERT_EQUAL_INT(result, FALSE); + SAMGR_GetInstance()->UnregisterService("serviceName101"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterService_0010 + * @tc.name : Service can be unregistered + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(ServiceTestSuite, testUnregisterService0010, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + Service *resultService = SAMGR_GetInstance()->UnregisterService("serviceName101"); + + // when unregist service samgr will return the target service + TEST_ASSERT_EQUAL_INT(strcmp(resultService->GetName(resultService), "serviceName101"), 0); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterService_0020 + * @tc.name : Service which contains NULL failed to unregister + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(ServiceTestSuite, testUnregisterService0020, LEVEL2) +{ + Service *resultService = SAMGR_GetInstance()->UnregisterService(NULL); + TEST_ASSERT_EQUAL_INT(resultService == NULL, TRUE); + + resultService = SAMGR_GetInstance()->UnregisterService(""); + TEST_ASSERT_EQUAL_INT(resultService == NULL, TRUE); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterService_0030 + * @tc.name : Service which does not exist in samgr failed to unregister + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(ServiceTestSuite, testUnregisterService0030, LEVEL2) +{ + Service *resultService = SAMGR_GetInstance()->UnregisterService("noExistServiceName"); + TEST_ASSERT_EQUAL_INT(resultService == NULL, TRUE); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterService_0040 + * @tc.name : Service which contains api failed to unregister + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(ServiceTestSuite, testUnregisterService0040, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName101", GET_IUNKNOWN(g_service)); + + Service *resultService = SAMGR_GetInstance()->UnregisterService("serviceName101"); + TEST_ASSERT_EQUAL_INT(resultService == NULL, TRUE); + + SAMGR_GetInstance()->UnregisterDefaultFeatureApi("serviceName101"); + SAMGR_GetInstance()->UnregisterService("serviceName101"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterService_0050 + * @tc.name : Service which contains feature failed to unregister + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(ServiceTestSuite, testUnregisterService0050, LEVEL2) +{ + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName101", (Feature *)&g_feature); + + Service *resultService = SAMGR_GetInstance()->UnregisterService("serviceName101"); + TEST_ASSERT_EQUAL_INT(resultService == NULL, TRUE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName101", "featureName101"); + SAMGR_GetInstance()->UnregisterService("serviceName101"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterService_0060 + * @tc.name : Register and unregister service repeatedly, no memory leak + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(ServiceTestSuite, testUnregisterService0060, LEVEL2) +{ + // RegisterService and unregister service over and over again, if there is memory leak samgr will crash + for (int i = 0; i < PRESSURE_BASE; i++) { + BOOL result = SAMGR_GetInstance()->RegisterService((Service *)&g_service); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + Service *resultService = SAMGR_GetInstance()->UnregisterService("serviceName101"); + TEST_ASSERT_EQUAL_INT(strcmp(resultService->GetName(resultService), "serviceName101"), 0); + } +} + +/** + * @tc.number : DMSLite_SAMGR_Bootstrap_0010 + * @tc.name : Restart SAMGR service function is normal. + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(ServiceTestSuite, testBootstrap0010, LEVEL2) +{ + SAMGR_Bootstrap(); + LOS_Msleep(OPER_INTERVAL); + + SamgrLite *samgrLite = SAMGR_GetInstance(); + TEST_ASSERT_EQUAL_INT(TRUE, samgrLite != NULL); +}; + +RUN_TEST_SUITE(ServiceTestSuite); \ No newline at end of file diff --git a/distributedschedule_lite/samgr_hal/src/taskpool_notask_func_test.c b/distributedschedule_lite/samgr_hal/src/taskpool_notask_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..8d19629870705b2d26a9076f34d29891c9e01e1e --- /dev/null +++ b/distributedschedule_lite/samgr_hal/src/taskpool_notask_func_test.c @@ -0,0 +1,241 @@ +/** + * Copyright (c) 2020 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. + * + * Description : testcases for distributedschedule_lite subsystem + * Create : 2020/04/19 + */ + +#include +#include "hctest.h" +#include "samgr_lite.h" + +#define OPER_INTERVAL 200 // 200 ms + +typedef struct DemoApi { + INHERIT_IUNKNOWN; + BOOL (*FeatureApi001)(IUnknown *iUnknown, char *para1); +} DemoApi; + +typedef struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoApi); + Identity identity; +} DemoFeature; + +typedef struct DefaultFeatureApi { + INHERIT_IUNKNOWN; + BOOL (*DefaultApi001)(IUnknown *iUnknown, char *para1); +} DefaultFeatureApi; + +typedef struct DemoService { + INHERIT_SERVICE; + INHERIT_IUNKNOWNENTRY(DefaultFeatureApi); + Identity identity; +} DemoService; + +static BOOL DefaultApi001(IUnknown *iUnknown, char *para1) +{ + (void)iUnknown; + (void)para1; + return TRUE; +} + +static BOOL FeatureApi001(IUnknown *iUnknown, char *para1) +{ + (void)iUnknown; + (void)para1; + return TRUE; +} + +static const char *GetName(Service *service) +{ + (void)service; + return "Service_NoTask"; +} + +static BOOL Initialize(Service *service, Identity identity) +{ + DemoService *service1 = (DemoService *)service; + service1->identity = identity; + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)service; + (void)msg; + return FALSE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + (void)service; + TaskConfig config = {LEVEL_HIGH, PRI_NORMAL, 0x800, 20, NO_TASK}; + return config; +} + +static DemoService g_createService = { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .DefaultApi001 = DefaultApi001, + } +}; + +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return "featureName501"; +} + +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; + (void)parent; +} + +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *request) +{ + (void)feature; + Response response = { + .data = "Yes, you did!", + .len = 0 + }; + SAMGR_SendResponse(request, &response); + return TRUE; +} + +static DemoFeature g_createFeature = { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .FeatureApi001 = FeatureApi001, + }, + .identity = {-1, -1, NULL}, +}; + +static void ServiceInit(void) +{ + BOOL result = SAMGR_GetInstance()->RegisterService((Service *)&g_createService); + if (result == FALSE) { + printf("[hctest]E RegisterService failed. \n"); + } +} +SYSEX_SERVICE_INIT(ServiceInit); + +static void FeatureInit(void) +{ + BOOL result1 = SAMGR_GetInstance()->RegisterDefaultFeatureApi("Service_NoTask", GET_IUNKNOWN(g_createService)); + + BOOL result2 = SAMGR_GetInstance()->RegisterFeature("Service_NoTask", (Feature *)&g_createFeature); + BOOL result3 = SAMGR_GetInstance()->RegisterFeatureApi("Service_NoTask", "featureName501", + GET_IUNKNOWN(g_createFeature)); + if (result1 == FALSE || result2 == FALSE || result3 == FALSE) { + printf("[hctest]E failed to register feature or api.\n"); + } +} +SYSEX_FEATURE_INIT(FeatureInit); + +static DemoApi *GetIUnknown(const char *serviceName, const char *featureName) +{ + DemoApi *demoApi = NULL; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(serviceName, featureName); + if (iUnknown == NULL) { + return NULL; + } + int result = iUnknown->QueryInterface(iUnknown, 0, (void **)&demoApi); + if (result == 0 && demoApi != NULL) { + return demoApi; + } else { + return NULL; + } +} + +static DefaultFeatureApi *GetDefaultIUnknown(const char *serviceName) +{ + DefaultFeatureApi *defaultApi = NULL; + IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(serviceName); + if (iUnknown == NULL) { + printf("[hctest]failed to GetFeatureApi.\n"); + return NULL; + } + int result = iUnknown->QueryInterface(iUnknown, 0, (void **)&defaultApi); + if (result == 0 && defaultApi != NULL) { + return defaultApi; + } else { + printf("[hctest]failed to QueryInterface.\n"); + return NULL; + } +} + +static void ReleaseIUnknown(DemoApi *demoApi) +{ + demoApi->Release((IUnknown *)demoApi); +} + +LITE_TEST_SUIT(distributedschedule, samgr, TaskPoolNoTaskFuncTestSuite); + +static BOOL TaskPoolNoTaskFuncTestSuiteSetUp(void) +{ + LOS_Msleep(OPER_INTERVAL); + return TRUE; +} + +static BOOL TaskPoolNoTaskFuncTestSuiteTearDown(void) +{ + return TRUE; +} + +/** + * @tc.number : DMSLite_SAMGR_Taskpool_NoTask_0010 + * @tc.name : Service without task can handle direct calls + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(TaskPoolNoTaskFuncTestSuite, testNoTask0010, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("Service_NoTask", "featureName501"); + if (demoApi == NULL) { + TEST_FAIL(); + } + BOOL result = demoApi->FeatureApi001((IUnknown *)demoApi, "xxxx"); + TEST_ASSERT_EQUAL_INT(result, TRUE); + ReleaseIUnknown(demoApi); + + DefaultFeatureApi *defaultApi = GetDefaultIUnknown("Service_NoTask"); + if (defaultApi == NULL) { + TEST_FAIL(); + } + result = defaultApi->DefaultApi001((IUnknown *)defaultApi, "yyyy"); + TEST_ASSERT_EQUAL_INT(result, TRUE); +}; + +RUN_TEST_SUITE(TaskPoolNoTaskFuncTestSuite); \ No newline at end of file diff --git a/distributedschedule_lite/samgr_hal/src/taskpool_sharedtask_func_test.c b/distributedschedule_lite/samgr_hal/src/taskpool_sharedtask_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..e2c079aa17ada0fb0b694babeb784133ecdf858a --- /dev/null +++ b/distributedschedule_lite/samgr_hal/src/taskpool_sharedtask_func_test.c @@ -0,0 +1,482 @@ +/** + * Copyright (c) 2020 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. + * + * Description : testcases for distributedschedule_lite subsystem + * Create : 2020/05/16 + */ + +#include +#include +#include "securec.h" +#include "cmsis_os2.h" +#include "hctest.h" +#include "samgr_lite.h" + +#define OPER_INTERVAL 200 // 200ms +#define TARGET_NUM 2 + +static const char *GetName(Service *service); +static BOOL Initialize(Service *service, Identity identity); +static BOOL MessageHandle(Service *service, Request *msg); +static TaskConfig GetTaskConfig(Service *service); + +static const char *FEATURE_GetName(Feature *feature); +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity); +static void FEATURE_OnStop(Feature *feature, Identity identity); +static BOOL FEATURE_OnMessage(Feature *feature, Request *request); + +static void *g_threadID11; // for the first service threadID +static void *g_threadID12; // for the first feature threadID +static void *g_threadID21; // for the second service threadID +static void *g_threadID22; // for the second feature threadID + +typedef struct DemoApi { + INHERIT_IUNKNOWN; + BOOL(*FeatureApi001) + (IUnknown *iUnknown, char *para1); + int32 (*SendRequestProxyF)(const Identity *identity, const Request *request, Handler handler); +} DemoApi; + +typedef struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoApi); + Identity identity; + int featureCalledCount; +} DemoFeature; + +typedef struct DefaultFeatureApi { + INHERIT_IUNKNOWN; + BOOL(*DefaultApi001) + (IUnknown *iUnknown, char *para1); + int32 (*SendRequestProxyDF)(const Identity *identity, const Request *request, Handler handler); +} DefaultFeatureApi; + +typedef struct DemoService { + INHERIT_SERVICE; + INHERIT_IUNKNOWNENTRY(DefaultFeatureApi); + Identity identity; + int serviceCalledCount; +} DemoService; + +static BOOL DefaultApi001(IUnknown *iUnknown, char *para1) +{ + (void)iUnknown; + (void)para1; + return TRUE; +} +static int32 SendRequestProxyDF(const Identity *identity, const Request *request, Handler handler) +{ + return SAMGR_SendRequest(identity, request, handler); +} + +static BOOL FeatureApi001(IUnknown *iUnknown, char *para1) +{ + (void)iUnknown; + (void)para1; + return TRUE; +} +static int32 SendRequestProxyF(const Identity *identity, const Request *request, Handler handler) +{ + return SAMGR_SendRequest(identity, request, handler); +} + +static DemoService g_service[] = { + { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .DefaultApi001 = DefaultApi001, + .SendRequestProxyDF = SendRequestProxyDF, + }, + .serviceCalledCount = 0, + }, + { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .DefaultApi001 = DefaultApi001, + .SendRequestProxyDF = SendRequestProxyDF, + }, + .serviceCalledCount = 0, + } +}; + +static const char *GetName(Service *service) +{ + if (service == (Service *)&g_service[0]) { + return "SharedTask01"; + } else { + return "SharedTask02"; + } +} + +static BOOL Initialize(Service *service, Identity identity) +{ + DemoService *demoService = (DemoService *)service; + demoService->identity = identity; + + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)msg; + DemoService *demoService = (DemoService *)service; + demoService->serviceCalledCount++; + if (service == (Service *)&g_service[0]) { + g_threadID11 = osThreadGetId(); + } else { + g_threadID21 = osThreadGetId(); + } + return TRUE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + TaskConfig config = {LEVEL_HIGH, PRI_NORMAL, 1600, 20, SHARED_TASK}; + if (service == (Service *)&g_service[0]) { + config.priority = PRI_NORMAL; + } else { + config.priority = PRI_NORMAL + 1; + } + return config; +} + +static DemoFeature g_createFeature[] = { + { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .FeatureApi001 = FeatureApi001, + .SendRequestProxyF = SendRequestProxyF, + }, + .identity = {-1, -1, NULL}, + .featureCalledCount = 0, + }, + { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .FeatureApi001 = FeatureApi001, + .SendRequestProxyF = SendRequestProxyF, + }, + .identity = {-1, -1, NULL}, + .featureCalledCount = 0, + }, +}; + +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return "featureName501"; +} + +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + (void)parent; + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; +} + +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *request) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + + printf("[hctest]FEATURE_OnMessage request msgId is %d \n", request->msgId); + if (feature == (Feature *)&g_createFeature[0]) { + g_threadID12 = osThreadGetId(); + } else { + g_threadID22 = osThreadGetId(); + } + return TRUE; +} + +static void ServiceInit(void) +{ + for (int i = 0; i < TARGET_NUM; i++) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service[i]); + } +} +SYS_SERVICE_INIT(ServiceInit); + +static void FeatureInit(void) +{ + for (int i = 0; i < TARGET_NUM; i++) { + SAMGR_GetInstance()->RegisterDefaultFeatureApi(g_service[i].GetName((Service *)&g_service[i]), + GET_IUNKNOWN(g_service[i])); + + SAMGR_GetInstance()->RegisterFeature(g_service[i].GetName((Service *)&g_service[i]), + (Feature *)&g_createFeature[i]); + SAMGR_GetInstance()->RegisterFeatureApi(g_service[i].GetName((Service *)&g_service[i]), "featureName501", + GET_IUNKNOWN(g_createFeature[i])); + } +} +SYS_FEATURE_INIT(FeatureInit); + +static DemoApi *GetIUnknown(const char *serviceName, const char *featureName) +{ + DemoApi *demoApi = NULL; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(serviceName, featureName); + if (iUnknown == NULL) { + return NULL; + } + int result = iUnknown->QueryInterface(iUnknown, 0, (void **)&demoApi); + if (result == 0 && demoApi != NULL) { + return demoApi; + } else { + return NULL; + } +} + +static DefaultFeatureApi *GetDefaultIUnknown(const char *serviceName) +{ + DefaultFeatureApi *defaultApi = NULL; + IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(serviceName); + if (iUnknown == NULL) { + return NULL; + } + int result = iUnknown->QueryInterface(iUnknown, 0, (void **)&defaultApi); + if (result == 0 && defaultApi != NULL) { + return defaultApi; + } else { + return NULL; + } +} + +LITE_TEST_SUIT(distributedschedule, taskpool, ShareTaskFuncTestSuite); + +static BOOL ShareTaskFuncTestSuiteSetUp(void) +{ + LOS_Msleep(OPER_INTERVAL); + return TRUE; +} + +static BOOL ShareTaskFuncTestSuiteTearDown(void) +{ + return TRUE; +} + +/** + * @tc.number : SUB_DSS_samgrLite_sharedtask_0010 + * @tc.name : the first task function is ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(ShareTaskFuncTestSuite, testSharedTask0010, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("SharedTask01", "featureName501"); + if (demoApi == NULL) { + TEST_FAIL(); + } + BOOL result = demoApi->FeatureApi001((IUnknown *)demoApi, "xxxx"); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + g_createFeature[0].featureCalledCount = 0; + Request request = {.msgId = 0, .msgValue = 0}; + char *body = "I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + int32 result2 = demoApi->SendRequestProxyF(&(g_createFeature[0].identity), &request, NULL); + TEST_ASSERT_EQUAL_INT(result2 == 0, TRUE); + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(g_createFeature[0].featureCalledCount == 1, TRUE); + + // *************************** // + DefaultFeatureApi *defaultApi = GetDefaultIUnknown("SharedTask01"); + if (defaultApi == NULL) { + TEST_FAIL(); + } + result = defaultApi->DefaultApi001((IUnknown *)defaultApi, "yyyy"); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + g_service[0].serviceCalledCount = 0; + Request request2 = {.msgId = 0, .msgValue = 0}; + char *body2 = "I want to call defaultFeature!"; + request2.len = (int16)(strlen(body2) + 1); + request2.data = malloc(request2.len); + if (request2.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request2.data, request2.len, body2); + result2 = defaultApi->SendRequestProxyDF(&(g_service[0].identity), &request2, NULL); + TEST_ASSERT_EQUAL_INT(result2 == 0, TRUE); + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(g_service[0].serviceCalledCount == 1, TRUE); +}; + +/** + * @tc.number : SUB_DSS_samgrLite_sharedtask_0020 + * @tc.name : the second task function is ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(ShareTaskFuncTestSuite, testSharedTask0020, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("SharedTask02", "featureName501"); + if (demoApi == NULL) { + TEST_FAIL(); + } + BOOL result = demoApi->FeatureApi001((IUnknown *)demoApi, "xxxx"); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + g_createFeature[1].featureCalledCount = 0; + Request request = {.msgId = 0, .msgValue = 0}; + char *body = "I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + int32 result2 = demoApi->SendRequestProxyF(&(g_createFeature[1].identity), &request, NULL); + TEST_ASSERT_EQUAL_INT(result2 == 0, TRUE); + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(g_createFeature[1].featureCalledCount == 1, TRUE); + + // *************************** // + DefaultFeatureApi *defaultApi = GetDefaultIUnknown("SharedTask02"); + if (defaultApi == NULL) { + TEST_FAIL(); + } + result = defaultApi->DefaultApi001((IUnknown *)defaultApi, "yyyy"); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + g_service[1].serviceCalledCount = 0; + Request request2 = {.msgId = 0, .msgValue = 0}; + char *body2 = "I want to call defaultFeature!"; + request2.len = (int16)(strlen(body2) + 1); + request2.data = malloc(request2.len); + if (request2.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request2.data, request2.len, body2); + result2 = defaultApi->SendRequestProxyDF(&(g_service[1].identity), &request2, NULL); + TEST_ASSERT_EQUAL_INT(result2 == 0, TRUE); + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(g_service[1].serviceCalledCount == 1, TRUE); +}; + +/** + * @tc.number : SUB_DSS_samgrLite_sharedtask_0030 + * @tc.name : PRI_LOW function is ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(ShareTaskFuncTestSuite, testSharedTask0030, LEVEL2) +{ + DefaultFeatureApi *defaultApi = GetDefaultIUnknown("SharedTask01"); + if (defaultApi == NULL) { + TEST_FAIL(); + } + Request request = {.msgId = 0, .msgValue = 0}; + char *body = "I want to call defaultFeature!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + defaultApi->SendRequestProxyDF(&(g_service[0].identity), &request, NULL); + + DefaultFeatureApi *defaultApi2 = GetDefaultIUnknown("SharedTask01"); + if (defaultApi2 == NULL) { + TEST_FAIL(); + } + Request request2 = {.msgId = 0, .msgValue = 0}; + request2.len = (int16)(strlen(body) + 1); + request2.data = malloc(request2.len); + if (request2.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request2.data, request2.len, body); + defaultApi2->SendRequestProxyDF(&(g_service[1].identity), &request2, NULL); + + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(g_threadID11 == g_threadID21, TRUE); +}; + +/** + * @tc.number : SUB_DSS_samgrLite_sharedtask_0040 + * @tc.name : PRI_LOW function is ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(ShareTaskFuncTestSuite, testSharedTask0040, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("SharedTask01", "featureName501"); + if (demoApi == NULL) { + TEST_FAIL(); + } + Request request1 = {.msgId = 1, .msgValue = 0}; + char *body = "I wanna async call good result!"; + request1.len = (int16)(strlen(body) + 1); + request1.data = malloc(request1.len); + if (request1.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request1.data, request1.len, body); + demoApi->SendRequestProxyF(&(g_createFeature[0].identity), &request1, NULL); + + DemoApi *demoApi2 = GetIUnknown("SharedTask02", "featureName501"); + if (demoApi2 == NULL) { + TEST_FAIL(); + } + Request request2 = {.msgId = 1 + 1, .msgValue = 0}; + request2.len = (int16)(strlen(body) + 1); + request2.data = malloc(request2.len); + if (request2.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request2.data, request2.len, body); + demoApi2->SendRequestProxyF(&(g_createFeature[1].identity), &request2, NULL); + + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(g_threadID12 == g_threadID22, TRUE); +}; +RUN_TEST_SUITE(ShareTaskFuncTestSuite); \ No newline at end of file diff --git a/distributedschedule_lite/samgr_hal/src/taskpool_singletask_func_test.c b/distributedschedule_lite/samgr_hal/src/taskpool_singletask_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..b7adf7e1c5a60304b2bbf512b081eab2cfe18094 --- /dev/null +++ b/distributedschedule_lite/samgr_hal/src/taskpool_singletask_func_test.c @@ -0,0 +1,589 @@ +/* + * Copyright (c) 2020 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 "securec.h" +#include "hctest.h" +#include "samgr_lite.h" + +#define OPER_INTERVAL 200 // 200 ms +#define SERVICE_NUM 4 +#define INDEX0 0 +#define INDEX1 1 +#define INDEX2 2 +#define INDEX3 3 + +static char *g_serviceNameArray[] = {"SingleTS01", "SingleTS02", "SingleTS03", "SingleTS04"}; + +static const char *GetName(Service *service); +static BOOL Initialize(Service *service, Identity identity); +static BOOL MessageHandle(Service *service, Request *msg); +static TaskConfig GetTaskConfig(Service *service); + +static Vector g_nodeVector; +typedef struct Node { + int id; + const char *name; +} Node; +static const Node *GetNode(const Node *node) +{ + return node; +} +static int CompareNode(const Node *node1, const Node *node2) +{ + if (node1->id < node2->id) { + return -1; + } else if (node1->id == node2->id) { + return 0; + } else { + return 1; + } +} + +typedef struct DemoApi { + INHERIT_IUNKNOWN; + BOOL (*FeatureApi001)(IUnknown *iUnknown, char *para1); + int32 (*SendRequestProxyF)(const Identity *identity, const Request *request, Handler handler); +} DemoApi; + +typedef struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoApi); + Identity identity; + int featureCalledCount; +} DemoFeature; + +typedef struct DefaultFeatureApi { + INHERIT_IUNKNOWN; + BOOL (*DefaultApi001)(IUnknown *iUnknown, char *para1); + int32 (*SendRequestProxyDF)(const Identity *identity, const Request *request, Handler handler); +} DefaultFeatureApi; + +typedef struct DemoService { + INHERIT_SERVICE; + INHERIT_IUNKNOWNENTRY(DefaultFeatureApi); + Identity identity; + int serviceCalledCount; +} DemoService; + +static BOOL DefaultApi001(IUnknown *iUnknown, char *para1) +{ + (void)iUnknown; + (void)para1; + return TRUE; +} +static int32 SendRequestProxyDF(const Identity *identity, const Request *request, Handler handler) +{ + return SAMGR_SendRequest(identity, request, handler); +} + +static BOOL FeatureApi001(IUnknown *iUnknown, char *para1) +{ + (void)iUnknown; + (void)para1; + return TRUE; +} +static int32 SendRequestProxyF(const Identity *identity, const Request *request, Handler handler) +{ + return SAMGR_SendRequest(identity, request, handler); +} + +static DemoService g_service[] = { + { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .DefaultApi001 = DefaultApi001, + .SendRequestProxyDF = SendRequestProxyDF, + }, + .serviceCalledCount = 0, + }, + { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .DefaultApi001 = DefaultApi001, + .SendRequestProxyDF = SendRequestProxyDF, + }, + .serviceCalledCount = 0, + }, + { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .DefaultApi001 = DefaultApi001, + .SendRequestProxyDF = SendRequestProxyDF, + }, + .serviceCalledCount = 0, + }, + { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .DefaultApi001 = DefaultApi001, + .SendRequestProxyDF = SendRequestProxyDF, + }, + .serviceCalledCount = 0, + } +}; + +static const char *GetName(Service *service) +{ + if (service == (Service *)&g_service[INDEX0]) { + return g_serviceNameArray[INDEX0]; + } else if (service == (Service *)&g_service[INDEX1]) { + return g_serviceNameArray[INDEX1]; + } else if (service == (Service *)&g_service[INDEX2]) { + return g_serviceNameArray[INDEX2]; + } else { + return g_serviceNameArray[INDEX3]; + } +} + +static int g_initlizationOrder = 0; +static BOOL Initialize(Service *service, Identity identity) +{ + DemoService *demoService = (DemoService *)service; + demoService->identity = identity; + + g_initlizationOrder++; + Node *node = (Node *)malloc(sizeof(Node)); + if (node == NULL) { + TEST_FAIL(); + } + node->id = g_initlizationOrder; + node->name = service->GetName(service); + VECTOR_Add(&g_nodeVector, node); + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)msg; + DemoService *demoService = (DemoService *)service; + demoService->serviceCalledCount++; + return TRUE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + // stackSize: valid stackSize is [1600, 342000), the L0 RAM size is 342000, if stackSize <= 800, system will crash + // queueSize: [0, system upper limit), 0: will not create taskpool, the max value depends on RAM size + // priority: PRI_ABOVE_NORMAL PRI_NORMAL PRI_BELOW_NORMAL PRI_LOW + + TaskConfig config = { LEVEL_HIGH, PRI_NORMAL, 1600, 2, SINGLE_TASK }; + if (service == (Service *)&g_service[INDEX0]) { + config.priority = PRI_LOW; + } else if (service == (Service *)&g_service[INDEX1]) { + config.priority = PRI_BELOW_NORMAL; + } else if (service == (Service *)&g_service[INDEX2]) { + config.priority = PRI_NORMAL; + } else { + config.priority = PRI_ABOVE_NORMAL; + } + return config; +} + +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return "featureName501"; +} + +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + (void)parent; + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; +} + +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *request) +{ + (void)request; + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + + return TRUE; +} + +static DemoFeature g_createFeature = { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .FeatureApi001 = FeatureApi001, + .SendRequestProxyF = SendRequestProxyF, + }, + .identity = {-1, -1, NULL}, + .featureCalledCount = 0, +}; + +static void ServiceInit(void) +{ + g_nodeVector = VECTOR_Make((VECTOR_Key)GetNode, (VECTOR_Compare)CompareNode); + for (int i = 0; i < SERVICE_NUM; i++) { + BOOL result = SAMGR_GetInstance()->RegisterService((Service *)&g_service[i]); + if (result == FALSE) { + printf("[hctest]E RegisterService failed, occurs: %d\n", i); + } + } +} +SYS_SERVICE_INIT(ServiceInit); + +static void FeatureInit(void) +{ + for (int i = 0; i < SERVICE_NUM; i++) { + BOOL result1 = SAMGR_GetInstance()->RegisterDefaultFeatureApi(g_service[i].GetName((Service *)&g_service[i]), + GET_IUNKNOWN(g_service[i])); + BOOL result2 = SAMGR_GetInstance()->RegisterFeature(g_service[i].GetName((Service *)&g_service[i]), + (Feature *)&g_createFeature); + BOOL result3 = SAMGR_GetInstance()->RegisterFeatureApi(g_service[i].GetName((Service *)&g_service[i]), + "featureName501", GET_IUNKNOWN(g_createFeature)); + if (result1 == FALSE || result2 == FALSE || result3 == FALSE) { + printf("[hctest]E failed to register feature or api.\n"); + } + } +} +SYS_FEATURE_INIT(FeatureInit); + +static DemoApi *GetIUnknown(const char *serviceName, const char *featureName) +{ + DemoApi *demoApi = NULL; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(serviceName, featureName); + if (iUnknown == NULL) { + printf("[hctest]failed to GetFeatureApi.\n"); + return NULL; + } + int result = iUnknown->QueryInterface(iUnknown, 0, (void **)&demoApi); + if (result == 0 && demoApi != NULL) { + return demoApi; + } else { + printf("[hctest]failed to QueryInterface.\n"); + return NULL; + } +} + +static DefaultFeatureApi *GetDefaultIUnknown(const char *serviceName) +{ + DefaultFeatureApi *defaultApi = NULL; + IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(serviceName); + if (iUnknown == NULL) { + printf("[hctest]failed to GetFeatureApi.\n"); + return NULL; + } + int result = iUnknown->QueryInterface(iUnknown, 0, (void **)&defaultApi); + if (result == 0 && defaultApi != NULL) { + return defaultApi; + } else { + printf("[hctest]failed to QueryInterface.\n"); + return NULL; + } +} + +LITE_TEST_SUIT(distributedschedule, samgr, SingleTaskFuncTestSuite); + +static BOOL SingleTaskFuncTestSuiteSetUp(void) +{ + LOS_Msleep(OPER_INTERVAL); + return TRUE; +} + +static BOOL SingleTaskFuncTestSuiteTearDown(void) +{ + return TRUE; +} + +/* * + * @tc.number : DMSLite_SAMGR_Taskpool_SingleTask_0010 + * @tc.name : Service with PRI_LOW priority function is ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SingleTaskFuncTestSuite, testSingleTask0010, LEVEL2) +{ + // test featureApi function + DemoApi *demoApi = GetIUnknown("SingleTS01", "featureName501"); + if (demoApi == NULL) { + TEST_FAIL(); + } + BOOL result = demoApi->FeatureApi001((IUnknown *)demoApi, "xxxx"); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + g_createFeature.featureCalledCount = 0; + Request request = { + .msgId = 0, + .msgValue = 0 + }; + char *body = "I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + int32 result2 = demoApi->SendRequestProxyF(&(g_createFeature.identity), &request, NULL); + TEST_ASSERT_EQUAL_INT(result2 == 0, TRUE); + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(g_createFeature.featureCalledCount == 1, TRUE); + + // test defaultFeatureApi function + DefaultFeatureApi *defaultApi = GetDefaultIUnknown("SingleTS01"); + if (defaultApi == NULL) { + TEST_FAIL(); + } + result = defaultApi->DefaultApi001((IUnknown *)defaultApi, "yyyy"); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + Request request2 = { + .msgId = 0, + .msgValue = 0 + }; + char *body2 = "I want to call defaultFeature!"; + request2.len = (int16)(strlen(body2) + 1); + request2.data = malloc(request2.len); + if (request2.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request2.data, request2.len, body2); + result2 = defaultApi->SendRequestProxyDF(&(g_service[0].identity), &request2, NULL); + TEST_ASSERT_EQUAL_INT(result2 == 0, TRUE); + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(g_service[0].serviceCalledCount == 1, TRUE); +}; + +/* * + * @tc.number : DMSLite_SAMGR_Taskpool_SingleTask_0020 + * @tc.name : Service with PRI_BELOW_NORMAL priority function is ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SingleTaskFuncTestSuite, testSingleTask0020, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("SingleTS02", "featureName501"); + if (demoApi == NULL) { + TEST_FAIL(); + } + BOOL result = demoApi->FeatureApi001((IUnknown *)demoApi, "xxxx"); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + g_createFeature.featureCalledCount = 0; + Request request = { + .msgId = 0, + .msgValue = 0 + }; + char *body = "I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + int32 result2 = demoApi->SendRequestProxyF(&(g_createFeature.identity), &request, NULL); + TEST_ASSERT_EQUAL_INT(result2 == 0, TRUE); + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(g_createFeature.featureCalledCount == 1, TRUE); + + DefaultFeatureApi *defaultApi = GetDefaultIUnknown("SingleTS02"); + if (defaultApi == NULL) { + TEST_FAIL(); + } + result = defaultApi->DefaultApi001((IUnknown *)defaultApi, "yyyy"); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + Request request2 = { + .msgId = 0, + .msgValue = 0 + }; + char *body2 = "I want to call defaultFeature!"; + request2.len = (int16)(strlen(body2) + 1); + request2.data = malloc(request2.len); + if (request2.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request2.data, request2.len, body2); + result2 = defaultApi->SendRequestProxyDF(&(g_service[1].identity), &request2, NULL); + TEST_ASSERT_EQUAL_INT(result2 == 0, TRUE); + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(g_service[1].serviceCalledCount == 1, TRUE); +}; + +/* * + * @tc.number : DMSLite_SAMGR_Taskpool_SingleTask_0030 + * @tc.name : Service with PRI_NORMAL priority function is ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SingleTaskFuncTestSuite, testSingleTask0030, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("SingleTS03", "featureName501"); + if (demoApi == NULL) { + TEST_FAIL(); + } + BOOL result = demoApi->FeatureApi001((IUnknown *)demoApi, "xxxx"); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + g_createFeature.featureCalledCount = 0; + Request request = { + .msgId = 0, + .msgValue = 0 + }; + char *body = "I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + int32 result2 = demoApi->SendRequestProxyF(&(g_createFeature.identity), &request, NULL); + TEST_ASSERT_EQUAL_INT(result2 == 0, TRUE); + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(g_createFeature.featureCalledCount == 1, TRUE); + + DefaultFeatureApi *defaultApi = GetDefaultIUnknown("SingleTS03"); + if (defaultApi == NULL) { + TEST_FAIL(); + } + result = defaultApi->DefaultApi001((IUnknown *)defaultApi, "yyyy"); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + Request request2 = { + .msgId = 0, + .msgValue = 0 + }; + char *body2 = "I want to call defaultFeature!"; + request2.len = (int16)(strlen(body2) + 1); + request2.data = malloc(request2.len); + if (request2.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request2.data, request2.len, body2); + result2 = defaultApi->SendRequestProxyDF(&(g_service[INDEX2].identity), &request2, NULL); + TEST_ASSERT_EQUAL_INT(result2 == 0, TRUE); + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(g_service[INDEX2].serviceCalledCount == 1, TRUE); +}; + +/* * + * @tc.number : DMSLite_SAMGR_Taskpool_SingleTask_0040 + * @tc.name : Service with PRI_ABOVE_NORMAL priority function is ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SingleTaskFuncTestSuite, testSingleTask0040, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("SingleTS04", "featureName501"); + if (demoApi == NULL) { + TEST_FAIL(); + } + BOOL result = demoApi->FeatureApi001((IUnknown *)demoApi, "xxxx"); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + g_createFeature.featureCalledCount = 0; + Request request = { + .msgId = 0, + .msgValue = 0 + }; + char *body = "I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + int32 result2 = demoApi->SendRequestProxyF(&(g_createFeature.identity), &request, NULL); + TEST_ASSERT_EQUAL_INT(result2 == 0, TRUE); + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(g_createFeature.featureCalledCount == 1, TRUE); + + DefaultFeatureApi *defaultApi = GetDefaultIUnknown("SingleTS04"); + if (defaultApi == NULL) { + TEST_FAIL(); + } + result = defaultApi->DefaultApi001((IUnknown *)defaultApi, "yyyy"); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + Request request2 = { + .msgId = 0, + .msgValue = 0 + }; + char *body2 = "I want to call defaultFeature!"; + request2.len = (int16)(strlen(body2) + 1); + request2.data = malloc(request2.len); + if (request2.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request2.data, request2.len, body2); + result2 = defaultApi->SendRequestProxyDF(&(g_service[INDEX3].identity), &request2, NULL); + TEST_ASSERT_EQUAL_INT(result2 == 0, TRUE); + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(g_service[INDEX3].serviceCalledCount == 1, TRUE); +}; + +/* * + * @tc.number : DMSLite_SAMGR_Taskpool_SingleTask_0050 + * @tc.name : Service initialization order depends on service priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SingleTaskFuncTestSuite, testSingleTask0050, LEVEL2) +{ + for (int i = 0; i < VECTOR_Num(&g_nodeVector); i++) { + Node *vectorAt = (Node *)VECTOR_At(&g_nodeVector, i); + if (vectorAt == NULL) { + continue; + } + TEST_ASSERT_EQUAL_INT(vectorAt->id, i + 1); + TEST_ASSERT_EQUAL_INT(strcmp(vectorAt->name, g_serviceNameArray[SERVICE_NUM - (i + 1)]), 0); + } +}; + +RUN_TEST_SUITE(SingleTaskFuncTestSuite); \ No newline at end of file diff --git a/distributedschedule_lite/samgr_hal/src/taskpool_specifiedtask_func_test.c b/distributedschedule_lite/samgr_hal/src/taskpool_specifiedtask_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..14dd0a93b4e875513615cb5fb182e32c0c416913 --- /dev/null +++ b/distributedschedule_lite/samgr_hal/src/taskpool_specifiedtask_func_test.c @@ -0,0 +1,412 @@ +/** + * Copyright (c) 2020 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. + * + * Description : testcases for distributedschedule_lite subsystem + * Create : 2020/05/16 + */ + +#include +#include +#include "securec.h" +#include "cmsis_os2.h" +#include "hctest.h" +#include "samgr_lite.h" + +#define OPER_INTERVAL 200 // 200 ms +#define TARGET_NUM 2 + +static const char *GetName(Service *service); +static BOOL Initialize(Service *service, Identity identity); +static BOOL MessageHandle(Service *service, Request *msg); +static TaskConfig GetTaskConfig(Service *service); + +static void *g_servicePoint1; +static void *g_servicePoint2; + +typedef struct DemoApi { + INHERIT_IUNKNOWN; + BOOL(*FeatureApi001) + (IUnknown *iUnknown, char *para1); + int32 (*SendRequestProxyF)(const Identity *identity, const Request *request, Handler handler); +} DemoApi; + +typedef struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoApi); + Identity identity; + int featureCalledCount; +} DemoFeature; + +typedef struct DefaultFeatureApi { + INHERIT_IUNKNOWN; + BOOL(*DefaultApi001) + (IUnknown *iUnknown, char *para1); + int32 (*SendRequestProxyDF)(const Identity *identity, const Request *request, Handler handler); +} DefaultFeatureApi; + +typedef struct DemoService { + INHERIT_SERVICE; + INHERIT_IUNKNOWNENTRY(DefaultFeatureApi); + Identity identity; + int serviceCalledCount; +} DemoService; + +static BOOL DefaultApi001(IUnknown *iUnknown, char *para1) +{ + (void)iUnknown; + (void)para1; + return TRUE; +} +static int32 SendRequestProxyDF(const Identity *identity, const Request *request, Handler handler) +{ + return SAMGR_SendRequest(identity, request, handler); +} + +static BOOL FeatureApi001(IUnknown *iUnknown, char *para1) +{ + (void)iUnknown; + (void)para1; + return TRUE; +} +static int32 SendRequestProxyF(const Identity *identity, const Request *request, Handler handler) +{ + return SAMGR_SendRequest(identity, request, handler); +} + +static DemoService g_service[] = { + { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .DefaultApi001 = DefaultApi001, + .SendRequestProxyDF = SendRequestProxyDF, + }, + .serviceCalledCount = 0, + }, + { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .DefaultApi001 = DefaultApi001, + .SendRequestProxyDF = SendRequestProxyDF, + }, + .serviceCalledCount = 0, + } +}; + +static const char *GetName(Service *service) +{ + if (service == (Service *)&g_service[0]) { + return "SpecifiedT01"; + } else { + return "SpecifiedT02"; + } +} + +static BOOL Initialize(Service *service, Identity identity) +{ + DemoService *demoService = (DemoService *)service; + demoService->identity = identity; + + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)msg; + DemoService *demoService = (DemoService *)service; + demoService->serviceCalledCount++; + + if (service == (Service *)&g_service[0]) { + g_servicePoint1 = osThreadGetId(); + } else { + g_servicePoint2 = osThreadGetId(); + } + + return TRUE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + (void)service; + TaskConfig config = {LEVEL_HIGH, PRI_NORMAL, 1600, 20, SPECIFIED_TASK}; + return config; +} + +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return "featureName501"; +} + +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + (void)parent; + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; +} + +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *request) +{ + (void)request; + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + + return TRUE; +} + +static DemoFeature g_createFeature = { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .FeatureApi001 = FeatureApi001, + .SendRequestProxyF = SendRequestProxyF, + }, + .identity = {-1, -1, NULL}, + .featureCalledCount = 0, +}; + +static void ServiceInit(void) +{ + for (int i = 0; i < TARGET_NUM; i++) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service[i]); + } +} +SYS_SERVICE_INIT(ServiceInit); + +static void FeatureInit(void) +{ + for (int i = 0; i < TARGET_NUM; i++) { + SAMGR_GetInstance()->RegisterDefaultFeatureApi(g_service[i].GetName((Service *)&g_service[i]), + GET_IUNKNOWN(g_service[i])); + + SAMGR_GetInstance()->RegisterFeature(g_service[i].GetName((Service *)&g_service[i]), + (Feature *)&g_createFeature); + SAMGR_GetInstance()->RegisterFeatureApi(g_service[i].GetName((Service *)&g_service[i]), + "featureName501", GET_IUNKNOWN(g_createFeature)); + } +} +SYS_FEATURE_INIT(FeatureInit); + +static DemoApi *GetIUnknown(const char *serviceName, const char *featureName) +{ + DemoApi *demoApi = NULL; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(serviceName, featureName); + if (iUnknown == NULL) { + return NULL; + } + int result = iUnknown->QueryInterface(iUnknown, 0, (void **)&demoApi); + if (result == 0 && demoApi != NULL) { + return demoApi; + } else { + return NULL; + } +} + +static DefaultFeatureApi *GetDefaultIUnknown(const char *serviceName) +{ + DefaultFeatureApi *defaultApi = NULL; + IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(serviceName); + if (iUnknown == NULL) { + return NULL; + } + int result = iUnknown->QueryInterface(iUnknown, 0, (void **)&defaultApi); + if (result == 0 && defaultApi != NULL) { + return defaultApi; + } else { + return NULL; + } +} + +LITE_TEST_SUIT(distributedschedule, taskpool, SpecifiedTaskFuncTestSuite); + +static BOOL SpecifiedTaskFuncTestSuiteSetUp(void) +{ + LOS_Msleep(OPER_INTERVAL); + return TRUE; +} + +static BOOL SpecifiedTaskFuncTestSuiteTearDown(void) +{ + return TRUE; +} + +/** + * @tc.number : SUB_DSS_samgrLite_specifiedtask_0010 + * @tc.name : the first task function is ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SpecifiedTaskFuncTestSuite, testSpecifiedTask0010, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("SpecifiedT01", "featureName501"); + if (demoApi == NULL) { + TEST_FAIL(); + } + BOOL result = demoApi->FeatureApi001((IUnknown *)demoApi, "xxxx"); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + g_createFeature.featureCalledCount = 0; + Request request = {.msgId = 0, .msgValue = 0}; + char *body = "I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + int32 result2 = demoApi->SendRequestProxyF(&(g_createFeature.identity), &request, NULL); + TEST_ASSERT_EQUAL_INT(result2 == 0, TRUE); + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(g_createFeature.featureCalledCount == 1, TRUE); + + // *************************** // + DefaultFeatureApi *defaultApi = GetDefaultIUnknown("SpecifiedT01"); + if (defaultApi == NULL) { + TEST_FAIL(); + } + result = defaultApi->DefaultApi001((IUnknown *)defaultApi, "yyyy"); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + g_service[0].serviceCalledCount = 0; + Request request2 = {.msgId = 0, .msgValue = 0}; + char *body2 = "I want to call defaultFeature!"; + request2.len = (int16)(strlen(body2) + 1); + request2.data = malloc(request2.len); + if (request2.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request2.data, request2.len, body2); + result2 = defaultApi->SendRequestProxyDF(&(g_service[0].identity), &request2, NULL); + TEST_ASSERT_EQUAL_INT(result2 == 0, TRUE); + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(g_service[0].serviceCalledCount == 1, TRUE); +}; + +/** + * @tc.number : SUB_DSS_samgrLite_specifiedtask_0020 + * @tc.name : PRI_LOW function is ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SpecifiedTaskFuncTestSuite, testSpecifiedTask0020, LEVEL2) +{ + DemoApi *demoApi = GetIUnknown("SpecifiedT02", "featureName501"); + if (demoApi == NULL) { + TEST_FAIL(); + } + BOOL result = demoApi->FeatureApi001((IUnknown *)demoApi, "xxxx"); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + g_createFeature.featureCalledCount = 0; + Request request = {.msgId = 0, .msgValue = 0}; + char *body = "I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + int32 result2 = demoApi->SendRequestProxyF(&(g_createFeature.identity), &request, NULL); + TEST_ASSERT_EQUAL_INT(result2 == 0, TRUE); + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(g_createFeature.featureCalledCount == 1, TRUE); + + // *************************** // + DefaultFeatureApi *defaultApi = GetDefaultIUnknown("SpecifiedT02"); + if (defaultApi == NULL) { + TEST_FAIL(); + } + result = defaultApi->DefaultApi001((IUnknown *)defaultApi, "yyyy"); + TEST_ASSERT_EQUAL_INT(result, TRUE); + + g_service[0].serviceCalledCount = 0; + Request request2 = {.msgId = 0, .msgValue = 0}; + char *body2 = "I want to call defaultFeature!"; + request2.len = (int16)(strlen(body2) + 1); + request2.data = malloc(request2.len); + if (request2.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request2.data, request2.len, body2); + result2 = defaultApi->SendRequestProxyDF(&(g_service[0].identity), &request2, NULL); + TEST_ASSERT_EQUAL_INT(result2 == 0, TRUE); + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(g_service[0].serviceCalledCount == 1, TRUE); +}; + +/** + * @tc.number : SUB_DSS_samgrLite_specifiedtask_0030 + * @tc.name : The threadId is the same as the specified task + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(SpecifiedTaskFuncTestSuite, testSpecifiedTask0030, LEVEL2) +{ + DefaultFeatureApi *defaultApi = GetDefaultIUnknown("SpecifiedT01"); + if (defaultApi == NULL) { + TEST_FAIL(); + } + Request request = {.msgId = 0, .msgValue = 0}; + char *body = "I want to call defaultFeature!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request.data, request.len, body); + defaultApi->SendRequestProxyDF(&(g_service[0].identity), &request, NULL); + + DefaultFeatureApi *defaultApi2 = GetDefaultIUnknown("SpecifiedT01"); + if (defaultApi2 == NULL) { + TEST_FAIL(); + } + Request request2 = {.msgId = 0, .msgValue = 0}; + char *body2 = "I want to call defaultFeature!"; + request2.len = (int16)(strlen(body2) + 1); + request2.data = malloc(request2.len); + if (request2.data == NULL) { + TEST_FAIL(); + } + strcpy_s(request2.data, request2.len, body2); + defaultApi2->SendRequestProxyDF(&(g_service[1].identity), &request2, NULL); + + LOS_Msleep(OPER_INTERVAL); + TEST_ASSERT_EQUAL_INT(g_servicePoint1 == g_servicePoint2, TRUE); +}; +RUN_TEST_SUITE(SpecifiedTaskFuncTestSuite); \ No newline at end of file diff --git a/distributedschedule_lite/samgr_hal/utils/samgr_maintenance.c b/distributedschedule_lite/samgr_hal/utils/samgr_maintenance.c new file mode 100755 index 0000000000000000000000000000000000000000..8ec156c194b152eda568c9c742089d647685ed8f --- /dev/null +++ b/distributedschedule_lite/samgr_hal/utils/samgr_maintenance.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2020 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 "samgr_maintenance.h" +#include +#include "service_impl.h" +#include "samgr_lite_inner.h" + +void SAMGR_PrintServices(void) +{ + SamgrLiteImpl *samgr = GET_OBJECT(SAMGR_GetInstance(), SamgrLiteImpl, vtbl); + int16 num = VECTOR_Num(&samgr->services); + printf("[hctest][Maintenance]Print Services(%d) Information:\n", num); + if (num == 0) { + return; + } + + MUTEX_Lock(samgr->mutex); + int16 size = VECTOR_Size(&(samgr->services)); + int i; + for (i = 0; i < size; ++i) { + ServiceImpl *impl = VECTOR_At(&(samgr->services), i); + if (impl == NULL) { + continue; + } + + MUTEX_Unlock(samgr->mutex); + const char *name = impl->service->GetName(impl->service); + printf("[hctest][Service:%d]\n", + impl->serviceId, impl->inited, name, impl->defaultApi, VECTOR_Num(&impl->features), impl->taskPool); + + TaskPool *pool = impl->taskPool; + if (pool != NULL) { + printf("[hctest][TaskPool:%p]\n", + pool, pool->tasks[0], pool->queueId, pool->ref, pool->priority, pool->stackSize); + } + + int16 featureSize = VECTOR_Size(&impl->features); + int j; + for (j = 0; j < featureSize; ++j) { + FeatureImpl *feature = VECTOR_At(&impl->features, j); + if (feature == NULL) { + continue; + } + name = feature->feature->GetName(feature->feature); + printf("[hctest][Feature:%d]\n", j, name, feature->iUnknown); + } + MUTEX_Lock(samgr->mutex); + } + MUTEX_Unlock(samgr->mutex); +} \ No newline at end of file diff --git a/distributedschedule_lite/samgr_hal/utils/samgr_maintenance.h b/distributedschedule_lite/samgr_hal/utils/samgr_maintenance.h new file mode 100755 index 0000000000000000000000000000000000000000..2131c135fc0cf7e2e8e0fd0e4d8bdf8e96df247b --- /dev/null +++ b/distributedschedule_lite/samgr_hal/utils/samgr_maintenance.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2020 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 OHOS_LITE_SAMGR_MAINTENANCE_H +#define OHOS_LITE_SAMGR_MAINTENANCE_H +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif +void SAMGR_PrintServices(void); +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif +#endif // OHOS_LITE_SAMGR_MAINTENANCE_H diff --git a/distributedschedule_lite/samgr_posix/BUILD.gn b/distributedschedule_lite/samgr_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..8ae62076a2a197f4b21744a321739f46a92b70b3 --- /dev/null +++ b/distributedschedule_lite/samgr_posix/BUILD.gn @@ -0,0 +1,91 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsSamgrTest") { + suite_name = "acts" + sources = [ ] + if (ohos_kernel_type == "liteos_a") { + sources += [ + "src/utils/SamgrTestBase.cpp", + + "src/ServiceTest.cpp", + "src/FeatureTest.cpp", + "src/DefaultFeatureApiTest.cpp", + "src/FeatureApiTest.cpp", + "src/IUnknownTest.cpp", + "src/SendRequestTest.cpp", + "src/SendResponseTest.cpp", + "src/SendShareRequestTest.cpp", + "src/BroadcastSubscribeTest.cpp", + "src/BroadcastPublishTest.cpp", + "src/TaskpoolNoTaskTest.cpp", + "src/TaskpoolSingleTaskTest.cpp", + "src/TaskpoolSpecifiedTaskTest.cpp", + "src/TaskpoolSharedTaskTest.cpp", + "src/CommonTest.cpp", + "src/LiteIPCClientTest.cpp", + "src/LiteIPCFeatureTest.cpp", + "src/LiteIPCServiceTest.cpp", + ] + } else if (ohos_kernel_type == "linux") { + sources += [ + "src/utils/SamgrTestBase.cpp", + + "src/ServiceTest.cpp", + "src/FeatureTest.cpp", + "src/DefaultFeatureApiTest.cpp", + "src/FeatureApiTest.cpp", + "src/IUnknownTest.cpp", + "src/SendRequestTest.cpp", + "src/SendResponseTest.cpp", + "src/SendShareRequestTest.cpp", + "src/BroadcastSubscribeTest.cpp", + "src/BroadcastPublishTest.cpp", + "src/TaskpoolNoTaskTest.cpp", + "src/TaskpoolSingleTaskTest.cpp", + "src/TaskpoolSpecifiedTaskTest.cpp", + "src/TaskpoolSharedTaskTest.cpp", + "src/CommonTest.cpp", + # "src/LiteIPCClientTest.cpp", + "src/LiteIPCFeatureTest.cpp", + "src/LiteIPCServiceTest.cpp", + ] + } else { } + + include_dirs = [ + "src", + "src/utils", + "include", + "//utils/native/liteos/include", + "//third_party/bounds_checking_function/include", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/registry", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/samgr", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/communication/broadcast", + ] + deps = [ + "//foundation/distributedschedule/services/samgr_lite/samgr:samgr", + "//foundation/distributedschedule/services/samgr_lite/communication/broadcast:broadcast", + "//foundation/communication/frameworks/ipc_lite:liteipc_adapter", + "//base/hiviewdfx/frameworks/hilog_lite/featured:hilog_shared", + "//third_party/bounds_checking_function:libsec_shared", + ] + cflags = [ "-Wno-error" ] + + ldflags = [ + "-lstdc++", + "-lm", + "-lpthread" + ] +} diff --git a/distributedschedule_lite/samgr_posix/Test.json b/distributedschedule_lite/samgr_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..d10da60b4df17cd01f3b125c66c4e8f5eaea66b2 --- /dev/null +++ b/distributedschedule_lite/samgr_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for hcpptest demo test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/distributedschedule", + "target": "/test_root/distributedschedule" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/distributedschedule/ActsSamgrTest.bin" + } +} \ No newline at end of file diff --git a/distributedschedule_lite/samgr_posix/src/BroadcastPublishTest.cpp b/distributedschedule_lite/samgr_posix/src/BroadcastPublishTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..8929323a969d49a0652e50f2349931861fcb2074 --- /dev/null +++ b/distributedschedule_lite/samgr_posix/src/BroadcastPublishTest.cpp @@ -0,0 +1,367 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "broadcast_interface.h" +#include "utils/SamgrTestBase.h" + +using namespace testing::ext; + +static const int16 TEST_LEN = 10; +static const char *BROADCASR_TEST_SERVICE = "S_broadcast2"; + +static void C1Callback(Consumer *consumer, const Topic *topic, const Request *request) +{ + (void)consumer; + (void)topic; +} +static void C2Callback(Consumer *consumer, const Topic *topic, const Request *request) +{ + (void)consumer; + (void)topic; +} + +static BOOL Equal(const Consumer *current, const Consumer *other) +{ + if (current->Notify == other->Notify) { + return TRUE; + } else { + return FALSE; + } +} + +static const char *GetName(Service *service) +{ + (void)service; + return BROADCASR_TEST_SERVICE; +}; + +static Identity g_identity = { -1, -1, nullptr}; + +static BOOL Initialize(Service *service, Identity identity) +{ + g_identity = identity; + (void)service; + return TRUE; +}; + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)service; + return FALSE; +}; + +static TaskConfig GetTaskConfig(Service *service) +{ + TaskConfig config = {LEVEL_HIGH, PRI_NORMAL, 0x800, 20, SHARED_TASK}; // share with broadcast + (void)service; + return config; +}; + +static Service g_service = {GetName, Initialize, MessageHandle, GetTaskConfig}; +static void GInit(void) +{ + SAMGR_GetInstance()->RegisterService(&g_service); +} +SYSEX_SERVICE_INIT(GInit); + +static PubSubInterface *CASE_GetIUnknown(void) +{ + PubSubInterface *fapi = nullptr; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(BROADCAST_SERVICE, PUB_SUB_FEATURE); + if (iUnknown == nullptr) { + printf("[hctest]CASE_GetIUnknown error "); + return nullptr; + } + + int result = iUnknown->QueryInterface(iUnknown, 0x20, (void **)&fapi); + if (result != 0 || fapi == nullptr) { + printf("[hctest]CASE_GetIUnknown error "); + } + return fapi; +} + +static void CASE_ReleaseIUnknown(PubSubInterface *fapi) +{ + fapi->Release((IUnknown *)fapi); +} + +class BroadcastPublishTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + printf("[hcpptest]SetUpTestCase ! \n"); + SystemInitProxy(); + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** + * @tc.number : DMSLite_SAMGR_Publish_0010 + * @tc.name : Provider can publish a broadcast message + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(BroadcastPublishTest, testPublish0010, TestSize.Level1) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == nullptr) { + ADD_FAILURE(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == nullptr) { + ADD_FAILURE(); + } + + Provider *provider = &fapi->provider; + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + static Consumer c2 = {.identity = &g_identity, .Notify = C2Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c2); + + BOOL result = provider->Publish((IUnknown *)fapi, &topic0, (uint8_t *) "==>111<==", TEST_LEN); + ASSERT_EQ(result, 1); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_Publish_0020 + * @tc.name : Provider failed to publish broadcast for the specified topic not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(BroadcastPublishTest, testPublish0020, TestSize.Level2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == nullptr) { + ADD_FAILURE(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == nullptr) { + ADD_FAILURE(); + } + + Provider *provider = &fapi->provider; + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + static Consumer c2 = {.identity = &g_identity, .Notify = C2Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c2); + + Topic noExisttopic = 99; + BOOL result = provider->Publish((IUnknown *)fapi, &noExisttopic, (uint8_t *) "==>111<==", TEST_LEN); + ASSERT_EQ(result, 0); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_Publish_0030 + * @tc.name : Provider failed to publish broadcast for len and data not match + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(BroadcastPublishTest, testPublish0030, TestSize.Level2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == nullptr) { + ADD_FAILURE(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == nullptr) { + ADD_FAILURE(); + } + + Provider *provider = &fapi->provider; + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + static Consumer c2 = {.identity = &g_identity, .Notify = C2Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c2); + + BOOL result = provider->Publish((IUnknown *)fapi, &topic0, (uint8_t *) "==>111<==", TEST_LEN - 1); + ASSERT_EQ(result, TRUE); + + result = provider->Publish((IUnknown *)fapi, &topic0, (uint8_t *) "==>111<==", TEST_LEN + 1); + ASSERT_EQ(result, TRUE); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_Publish_0040 + * @tc.name : Provider publish broadcast successfully for 0 and max lenth message + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(BroadcastPublishTest, testPublish0040, TestSize.Level2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == nullptr) { + ADD_FAILURE(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == nullptr) { + ADD_FAILURE(); + } + + Provider *provider = &fapi->provider; + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + static Consumer c2 = {.identity = &g_identity, .Notify = C2Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c2); + + BOOL result = provider->Publish((IUnknown *)fapi, &topic0, (uint8_t *) "", 0); + ASSERT_EQ(result, 0); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_Publish_0050 + * @tc.name : Provider publish broadcast successfully for no consumer + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(BroadcastPublishTest, testPublish0050, TestSize.Level2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == nullptr) { + ADD_FAILURE(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == nullptr) { + ADD_FAILURE(); + } + + Provider *provider = &fapi->provider; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + + BOOL result = provider->Publish((IUnknown *)fapi, &topic0, (uint8_t *) "==>111<==", TEST_LEN); + ASSERT_EQ(result, 1); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_Publish_0060 + * @tc.name : Provider publish broadcast successfully for multi consumers + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(BroadcastPublishTest, testPublish0060, TestSize.Level2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == nullptr) { + ADD_FAILURE(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == nullptr) { + ADD_FAILURE(); + } + + Provider *provider = &fapi->provider; + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + static Consumer c2 = {.identity = &g_identity, .Notify = C2Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c2); + + BOOL result = provider->Publish((IUnknown *)fapi, &topic0, (uint8_t *) "==>111<==", TEST_LEN); + ASSERT_EQ(result, TRUE); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_Publish_0070 + * @tc.name : Provider send broadcast repeatedly, no memory leak + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(BroadcastPublishTest, testPublish0070, TestSize.Level2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == nullptr) { + ADD_FAILURE(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == nullptr) { + ADD_FAILURE(); + } + + Provider *provider = &fapi->provider; + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + static Consumer c2 = {.identity = &g_identity, .Notify = C2Callback, .Equal = Equal}; + + Topic topic0 = 70; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c2); + + for (int i = 0; i < PRESSURE_BASE; i++) { + // after this pressure, some operation will fail. + provider->Publish((IUnknown *)fapi, &topic0, (uint8_t *) "==>111<==", TEST_LEN); + } + + usleep(OPER_INTERVAL * MS2US); + BOOL result = provider->Publish((IUnknown *)fapi, &topic0, (uint8_t *) "==>111<==", TEST_LEN); + ASSERT_EQ(result, TRUE); + + CASE_ReleaseIUnknown(fapi); +} \ No newline at end of file diff --git a/distributedschedule_lite/samgr_posix/src/BroadcastSubscribeTest.cpp b/distributedschedule_lite/samgr_posix/src/BroadcastSubscribeTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..21d85fe72f370bf8eaaa6640132b2a728df639ec --- /dev/null +++ b/distributedschedule_lite/samgr_posix/src/BroadcastSubscribeTest.cpp @@ -0,0 +1,601 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "broadcast_interface.h" +#include "utils/SamgrTestBase.h" + +using namespace testing::ext; + +static const int16 TEST_LEN = 10; +static const char *BROADCASR_TEST_SERVICE = "S_broadcast1"; + +static void C1Callback(Consumer *consumer, const Topic *topic, const Request *request) +{ + (void)consumer; + (void)topic; +} +static void C2Callback(Consumer *consumer, const Topic *topic, const Request *request) +{ + (void)consumer; + (void)topic; +} + +static BOOL Equal(const Consumer *current, const Consumer *other) +{ + if (current->Notify == other->Notify) { + return TRUE; + } else { + return FALSE; + } +} + +static const char *GetName(Service *service) +{ + (void)service; + return BROADCASR_TEST_SERVICE; +}; + +static Identity g_identity = { -1, -1, nullptr}; +static BOOL Initialize(Service *service, Identity identity) +{ + g_identity = identity; + (void)service; + return TRUE; +}; + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)service; + return FALSE; +}; + +static TaskConfig GetTaskConfig(Service *service) +{ + TaskConfig config = {LEVEL_HIGH, PRI_NORMAL, 0x800, 20, SHARED_TASK}; // share with broadcast + (void)service; + return config; +}; + +static Service g_service = {GetName, Initialize, MessageHandle, GetTaskConfig}; +static void GInit(void) +{ + SAMGR_GetInstance()->RegisterService(&g_service); +} +SYSEX_SERVICE_INIT(GInit); + +static PubSubInterface *CASE_GetIUnknown(void) +{ + PubSubInterface *fapi = nullptr; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(BROADCAST_SERVICE, PUB_SUB_FEATURE); + if (iUnknown == nullptr) { + printf("[hctest]CASE_GetIUnknown error "); + return nullptr; + } + + int result = iUnknown->QueryInterface(iUnknown, 0x20, (void **)&fapi); + if (result != 0 || fapi == nullptr) { + printf("[hctest]CASE_GetIUnknown error "); + } + return fapi; +} + +static void CASE_ReleaseIUnknown(PubSubInterface *fapi) +{ + fapi->Release((IUnknown *)fapi); +} + +class BroadcastSubscribeTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + SystemInitProxy(); + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** + * @tc.number : DMSLite_SAMGR_AddTopic_0010 + * @tc.name : Valid topic can be added successfully + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(BroadcastSubscribeTest, testAddTopic0010, TestSize.Level1) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == nullptr) { + ADD_FAILURE(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == nullptr) { + ADD_FAILURE(); + } + + Topic topic0 = 11; + int result = subscriber->AddTopic((IUnknown *)fapi, &topic0); + ASSERT_EQ(result == 0, TRUE); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_AddTopic_0020 + * @tc.name : Topic which is nullptr or already existing can not be added + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(BroadcastSubscribeTest, testAddTopic0020, TestSize.Level2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == nullptr) { + ADD_FAILURE(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == nullptr) { + ADD_FAILURE(); + } + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + + int result = subscriber->AddTopic((IUnknown *)fapi, nullptr); + ASSERT_EQ(result != 0, TRUE); + + result = subscriber->AddTopic((IUnknown *)fapi, &topic0); + ASSERT_EQ(result != 0, TRUE); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_Subscribe_0010 + * @tc.name : Consumer can subscribe to a topic + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(BroadcastSubscribeTest, testSubscribe0010, TestSize.Level1) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == nullptr) { + ADD_FAILURE(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == nullptr) { + ADD_FAILURE(); + } + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + + Topic topic0 = 9; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + int result = subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + ASSERT_EQ(result == 0, TRUE); + + subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_Subscribe_0020 + * @tc.name : Consumer can not subscribe to the topic which is nullptr or does not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(BroadcastSubscribeTest, testSubscribe0020, TestSize.Level2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == nullptr) { + ADD_FAILURE(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == nullptr) { + ADD_FAILURE(); + } + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + int result = subscriber->Subscribe((IUnknown *)fapi, nullptr, &c1); + ASSERT_EQ(result != 0, TRUE); + + Topic noExistTopic = -200; + result = subscriber->Subscribe((IUnknown *)fapi, &noExistTopic, &c1); + ASSERT_EQ(result != 0, TRUE); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_Subscribe_0030 + * @tc.name : Consumer which is nullptr can not subscribe to a topic + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(BroadcastSubscribeTest, testSubscribe0030, TestSize.Level2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == nullptr) { + ADD_FAILURE(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == nullptr) { + ADD_FAILURE(); + } + Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + int result = subscriber->Subscribe((IUnknown *)fapi, &topic0, nullptr); + ASSERT_EQ(result != 0, TRUE); + + subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_Subscribe_0040 + * @tc.name : Consumer can not subscribe to the same topic twice + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(BroadcastSubscribeTest, testSubscribe0040, TestSize.Level2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == nullptr) { + ADD_FAILURE(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == nullptr) { + ADD_FAILURE(); + } + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + int result = subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + ASSERT_EQ(result != 0, TRUE); + + subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_UnSubscribe_0010 + * @tc.name : Consumer can unsubscribe a topic + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(BroadcastSubscribeTest, testUnsubscribe0010, TestSize.Level1) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == nullptr) { + ADD_FAILURE(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == nullptr) { + ADD_FAILURE(); + } + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + + Consumer *result = subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + ASSERT_EQ(result != nullptr, TRUE); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_UnSubscribe_0020 + * @tc.name : Consumer can not unsubscribe a topic if the specified topic-comsumer relationship is nullptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(BroadcastSubscribeTest, testUnsubscribe0020, TestSize.Level2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == nullptr) { + ADD_FAILURE(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == nullptr) { + ADD_FAILURE(); + } + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + + Consumer *result = subscriber->Unsubscribe((IUnknown *)fapi, nullptr, &c1); + ASSERT_EQ(result==NULL, TRUE); // failed + + result = subscriber->Unsubscribe((IUnknown *)fapi, &topic0, nullptr); + ASSERT_EQ(result==NULL, TRUE); + + subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_UnSubscribe_0030 + * @tc.name : Consumer can not unsubscribe a topic if the specified topic-comsumer relationship not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(BroadcastSubscribeTest, testUnsubscribe0030, TestSize.Level2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == nullptr) { + ADD_FAILURE(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == nullptr) { + ADD_FAILURE(); + } + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + static Consumer c2 = {.identity = &g_identity, .Notify = C2Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + + Consumer *result = subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c2); + ASSERT_EQ(result==NULL, TRUE); + + subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_UnSubscribe_0040 + * @tc.name : Consumer subscribe and unsubscribe a topic repeatedly, no memory leak. + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(BroadcastSubscribeTest, testUnsubscribe0040, TestSize.Level2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == nullptr) { + ADD_FAILURE(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == nullptr) { + ADD_FAILURE(); + } + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + + for (int i = 0; i < PRESSURE_BASE; i++) { + int result = subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + ASSERT_EQ(result == 0, TRUE); + + Consumer *resultConsumer = subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + ASSERT_EQ(resultConsumer != nullptr, TRUE); + } + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_ModifyConsumer_0010 + * @tc.name : Consumer can modify subscription relationship + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(BroadcastSubscribeTest, testModifyConsumer0010, TestSize.Level2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == nullptr) { + ADD_FAILURE(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == nullptr) { + ADD_FAILURE(); + } + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + static Consumer c2 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + + Consumer *result = subscriber->ModifyConsumer((IUnknown *)fapi, &topic0, &c1, &c2); + ASSERT_EQ(result != nullptr, TRUE); + + subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_ModifyConsumer_0020 + * @tc.name : Consumer can not modify subscription relationship if the input parameter is nullptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(BroadcastSubscribeTest, testModifyConsumer0020, TestSize.Level2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == nullptr) { + ADD_FAILURE(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == nullptr) { + ADD_FAILURE(); + } + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + static Consumer c2 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + + Consumer *result = subscriber->ModifyConsumer((IUnknown *)fapi, nullptr, &c1, &c2); + ASSERT_EQ(result!=NULL, 0); + + result = subscriber->ModifyConsumer((IUnknown *)fapi, &topic0, nullptr, &c2); + ASSERT_EQ(result!=NULL, 0); + + result = subscriber->ModifyConsumer((IUnknown *)fapi, &topic0, &c1, nullptr); + ASSERT_EQ(result!=NULL, 0); + + subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_ModifyConsumer_0030 + * @tc.name : Consumer can not modify subscription relationship if the specified topic not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(BroadcastSubscribeTest, testModifyConsumer0030, TestSize.Level2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == nullptr) { + ADD_FAILURE(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == nullptr) { + ADD_FAILURE(); + } + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + static Consumer c2 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + + Topic noExistTopic = 99; + Consumer *result = subscriber->ModifyConsumer((IUnknown *)fapi, &noExistTopic, &c1, &c2); + ASSERT_EQ(result==NULL, 1); + + subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_ModifyConsumer_0040 + * @tc.name : Consumer can not modify subscription relationship if the specified old consumer not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(BroadcastSubscribeTest, testModifyConsumer0040, TestSize.Level2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == nullptr) { + ADD_FAILURE(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == nullptr) { + ADD_FAILURE(); + } + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + static Consumer c2 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + + Topic noExistTopic = 99; + Consumer *result = subscriber->ModifyConsumer((IUnknown *)fapi, &noExistTopic, &c2, &c2); + ASSERT_EQ(result==NULL, 1); + + subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + + CASE_ReleaseIUnknown(fapi); +} + +/** + * @tc.number : DMSLite_SAMGR_ModifyConsumer_0050 + * @tc.name : Consumer can modify subscription relationship if the new consumer is the same as old consumer + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(BroadcastSubscribeTest, testModifyConsumer0050, TestSize.Level2) +{ + PubSubInterface *fapi = CASE_GetIUnknown(); + if (fapi == nullptr) { + ADD_FAILURE(); + } + Subscriber *subscriber = &fapi->subscriber; + if (subscriber == nullptr) { + ADD_FAILURE(); + } + static Consumer c1 = {.identity = &g_identity, .Notify = C1Callback, .Equal = Equal}; + + Topic topic0 = 0; + subscriber->AddTopic((IUnknown *)fapi, &topic0); + subscriber->Subscribe((IUnknown *)fapi, &topic0, &c1); + + Consumer *result = subscriber->ModifyConsumer((IUnknown *)fapi, &topic0, &c1, &c1); + ASSERT_EQ(result != nullptr, TRUE); + + subscriber->Unsubscribe((IUnknown *)fapi, &topic0, &c1); + + CASE_ReleaseIUnknown(fapi); +} diff --git a/distributedschedule_lite/samgr_posix/src/CommonTest.cpp b/distributedschedule_lite/samgr_posix/src/CommonTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..778dabf99fb56b7c6a09f33ae602d6b8e1d54db5 --- /dev/null +++ b/distributedschedule_lite/samgr_posix/src/CommonTest.cpp @@ -0,0 +1,400 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "utils/SamgrTestBase.h" + +const int RUN_TIMES = 10; +const int THREAD_NUM = 2; + +using namespace testing::ext; + +struct Node { + int id; + char *name; + int value; +}; + +static const Node *GetNode(const Node *node1) +{ + return node1; +} + +static MutexId g_mutex; + +static int CompareNode(const Node *node1, const Node *node2) +{ + if (node1->id < node2->id) { + return -1; + } else if (node1->id == node2->id) { + return 0; + } else { + return 1; + } +} + +class CommonTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + printf("[hcpptest]SetUpTestCase ! \n"); + SystemInitProxy(); + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + usleep(OPER_INTERVAL * MS2US); + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** + * @tc.number : DMSLite_SAMGR_Common_0010 + * @tc.name : The vector operation after initialization is correct + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(CommonTest, testCommon0010, TestSize.Level2) +{ + Vector nodeVector = VECTOR_Make((VECTOR_Key)GetNode, (VECTOR_Compare)CompareNode); + + int16 vectorSize = VECTOR_Size(&nodeVector); + ASSERT_EQ(vectorSize == 0, TRUE); + + int16 vectorNum = VECTOR_Num(&nodeVector); + ASSERT_EQ(vectorNum == 0, TRUE); + + Node *vectorAt = (Node *)VECTOR_At(&nodeVector, (int16)0); + ASSERT_EQ(vectorAt == nullptr, TRUE); + + Node node = {1, (char*)"node1", 1}; + Node *vectorSwap = (Node *)VECTOR_Swap(&nodeVector, (int16)0, &node); + ASSERT_EQ(vectorSwap == nullptr, TRUE); + + int16 indexFind = VECTOR_Find(&nodeVector, &node); + ASSERT_EQ(INVALID_INDEX, indexFind); + + int16 indexFindByKey = VECTOR_FindByKey(&nodeVector, &node); + ASSERT_EQ(INVALID_INDEX, indexFindByKey); + + VECTOR_Clear(&nodeVector); +} + +/** + * @tc.number : DMSLite_SAMGR_Common_0020 + * @tc.name : The vector operation is correct when only 1 element + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(CommonTest, testCommon0020, TestSize.Level2) +{ + Vector nodeVector = VECTOR_Make((VECTOR_Key)GetNode, (VECTOR_Compare)CompareNode); + + Node node = {1, (char*)"node1", 1}; + int16 resultAdd = VECTOR_Add(&nodeVector, &node); + ASSERT_EQ(resultAdd, 0); + + int16 vectorSize = VECTOR_Size(&nodeVector); + ASSERT_EQ(vectorSize, 1); + + int16 vectorNum = VECTOR_Num(&nodeVector); + ASSERT_EQ(vectorNum, 1); + + Node *vectorAt = (Node *)VECTOR_At(&nodeVector, (int16)0); + ASSERT_EQ(vectorAt != nullptr, TRUE); + + Node node2 = {2, (char*)"node2", 2}; + Node *resultNode = (Node *)VECTOR_Swap(&nodeVector, (int16)0, &node2); + ASSERT_EQ(resultNode != nullptr, TRUE); + + int16 indexFind = VECTOR_Find(&nodeVector, &node2); + ASSERT_EQ(indexFind, 0); + + int16 indexFindByKey = VECTOR_FindByKey(&nodeVector, &node2); + ASSERT_EQ(indexFindByKey, 0); + + VECTOR_Clear(&nodeVector); +} + +/** + * @tc.number : DMSLite_SAMGR_Common_0030 + * @tc.name : The vector operation is correct when multi elements + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(CommonTest, testCommon0030, TestSize.Level2) +{ + Vector nodeVector = VECTOR_Make((VECTOR_Key)GetNode, (VECTOR_Compare)CompareNode); + + Node node[] = { + {0, (char*)"node", 0}, + {1, (char*)"node", 1}, + {2, (char*)"node", 2}, + {3, (char*)"node", 3}, + {4, (char*)"node", 4}, + {5, (char*)"node", 5}, + {6, (char*)"node", 6}, + {7, (char*)"node", 7}, + {8, (char*)"node", 8}, + {9, (char*)"node", 9}, + }; + + for (int i = 0; i < RUN_TIMES; i++) { + int16 resultAdd = VECTOR_Add(&nodeVector, &(node[i])); + ASSERT_EQ(i, resultAdd); + } + + int16 vectorSize = VECTOR_Size(&nodeVector); + ASSERT_EQ(vectorSize, RUN_TIMES); + + int16 vectorNum = VECTOR_Num(&nodeVector); + ASSERT_EQ(vectorNum, RUN_TIMES); + + for (int i = 0; i < RUN_TIMES; i++) { + Node *vectorAt = (Node *)VECTOR_At(&nodeVector, (int16)i); + ASSERT_EQ(vectorAt != nullptr, TRUE); + ASSERT_EQ(vectorAt->id, i); + + int16 indexFind = VECTOR_Find(&nodeVector, &node[i]); + ASSERT_EQ(indexFind, i); + + int16 indexFindByKey = VECTOR_FindByKey(&nodeVector, &node[i]); + ASSERT_EQ(indexFindByKey, i); + } + + Node nodeX = {99, (char*)"node", 99}; + Node *resultNode = (Node *)VECTOR_Swap(&nodeVector, (int16)0, &nodeX); + ASSERT_EQ(resultNode != nullptr, TRUE); + ASSERT_EQ(resultNode->id, 0); + + VECTOR_Clear(&nodeVector); +} + +/** + * @tc.number : DMSLite_SAMGR_Common_0040 + * @tc.name : The vector operation is correct after delete some elements + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(CommonTest, testCommon0040, TestSize.Level2) +{ + Vector nodeVector = VECTOR_Make((VECTOR_Key)GetNode, (VECTOR_Compare)CompareNode); + Node node[] = { + {0, (char*)"node", 0}, + {1, (char*)"node", 1}, + {2, (char*)"node", 2}, + {3, (char*)"node", 3}, + {4, (char*)"node", 4}, + {5, (char*)"node", 5}, + {6, (char*)"node", 6}, + {7, (char*)"node", 7}, + {8, (char*)"node", 8}, + {9, (char*)"node", 9}, + }; + for (int i = 0; i < RUN_TIMES; i++) { + VECTOR_Add(&nodeVector, &(node[i])); + } + + for (int i = 0; i < RUN_TIMES; i++) { + Node *resultNode = (Node *)VECTOR_Swap(&nodeVector, (int16)i, nullptr); + ASSERT_EQ(resultNode != nullptr, TRUE); + ASSERT_EQ(i, resultNode->id); + + int16 vectorSize = VECTOR_Size(&nodeVector); + ASSERT_EQ(RUN_TIMES, vectorSize); + + int16 vectorNum = VECTOR_Num(&nodeVector); + ASSERT_EQ(RUN_TIMES - (i + 1), vectorNum); + + Node *vectorAt = (Node *)VECTOR_At(&nodeVector, (int16)i); + ASSERT_EQ(TRUE, vectorAt == nullptr); + + int16 indexFind = VECTOR_Find(&nodeVector, &node[i]); + ASSERT_EQ(INVALID_INDEX, indexFind); + + int16 indexFindByKey = VECTOR_FindByKey(&nodeVector, &node[i]); + ASSERT_EQ(INVALID_INDEX, indexFindByKey); + } + + VECTOR_Clear(&nodeVector); +} + +/** + * @tc.number : DMSLite_SAMGR_Common_0050 + * @tc.name : The vector operation is correct after add and delete some elements + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(CommonTest, testCommon0050, TestSize.Level2) +{ + Vector nodeVector = VECTOR_Make((VECTOR_Key)GetNode, (VECTOR_Compare)CompareNode); + Node node[] = { + {0, (char*)"node", 0}, + {1, (char*)"node", 1}, + {2, (char*)"node", 2}, + {3, (char*)"node", 3}, + {4, (char*)"node", 4}, + {5, (char*)"node", 5}, + {6, (char*)"node", 6}, + {7, (char*)"node", 7}, + {8, (char*)"node", 8}, + {9, (char*)"node", 9}, + }; + for (int i = 0; i < RUN_TIMES * RUN_TIMES; i++) { + for (int j = 0; j < RUN_TIMES; j++) { + VECTOR_Add(&nodeVector, &(node[j])); + } + for (int j = 0; j < RUN_TIMES; j++) { + VECTOR_Swap(&nodeVector, (int16)j, nullptr); + } + } + + for (int i = 0; i < RUN_TIMES; i++) { + VECTOR_Add(&nodeVector, &(node[i])); + } + printf("[hctest]test start \n"); + for (int i = 0; i < RUN_TIMES; i++) { + int16 indexFind = VECTOR_Find(&nodeVector, &node[i]); + ASSERT_EQ(indexFind >= 0, TRUE); + + int16 indexFindByKey = VECTOR_FindByKey(&nodeVector, &node[i]); + ASSERT_EQ(indexFindByKey >= 0, TRUE); + + Node *resultNode = (Node *)VECTOR_Swap(&nodeVector, indexFind, nullptr); + ASSERT_EQ(resultNode != nullptr, TRUE); + ASSERT_EQ(i, resultNode->id); + + int16 vectorSize = VECTOR_Size(&nodeVector); + ASSERT_EQ(vectorSize > (RUN_TIMES - (i + 1)), TRUE); + + int16 vectorNum = VECTOR_Num(&nodeVector); + ASSERT_EQ(RUN_TIMES - (i + 1), vectorNum); + + Node *vectorAt = (Node *)VECTOR_At(&nodeVector, indexFind); + ASSERT_EQ(TRUE, vectorAt == nullptr); + } + + VECTOR_Clear(&nodeVector); +} + +/** + * @tc.number : DMSLite_SAMGR_Common_0060 + * @tc.name : If vector or element is nullptr adding element fails + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(CommonTest, testCommon0060, TestSize.Level2) +{ + Vector nodeVector = VECTOR_Make((VECTOR_Key)GetNode, (VECTOR_Compare)CompareNode); + + Node node = {1, (char*)"node1", 1}; + int16 resultAdd = VECTOR_Add(NULL, &node); + ASSERT_EQ(INVALID_INDEX, resultAdd); + + resultAdd = VECTOR_Add(&nodeVector, nullptr); + ASSERT_EQ(INVALID_INDEX, resultAdd); + + VECTOR_Clear(&nodeVector); +} + +/** + * @tc.number : DMSLite_SAMGR_Common_0070 + * @tc.name : If vector is nullptr deleting element fails + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(CommonTest, testCommon0070, TestSize.Level2) +{ + Vector nodeVector = VECTOR_Make((VECTOR_Key)GetNode, (VECTOR_Compare)CompareNode); + Node node = {1, (char*)"node1", 1}; + VECTOR_Add(&nodeVector, &node); + + Node *vectorSwap = (Node *)VECTOR_Swap(NULL, (int16)0, nullptr); + ASSERT_EQ(TRUE, vectorSwap == nullptr); + + VECTOR_Clear(&nodeVector); +} + +/** + * @tc.number : DMSLite_SAMGR_Common_0080 + * @tc.name : If vector is nullptr getting information from vector fails + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(CommonTest, testCommon0080, TestSize.Level2) +{ + Vector nodeVector = VECTOR_Make((VECTOR_Key)GetNode, (VECTOR_Compare)CompareNode); + Node node = {1, (char*)"node1", 1}; + VECTOR_Add(&nodeVector, &node); + + int16 vectorSize = VECTOR_Size(NULL); + ASSERT_EQ(INVALID_INDEX, vectorSize); + + int16 vectorNum = VECTOR_Num(NULL); + ASSERT_EQ(INVALID_INDEX, vectorNum); + + Node *vectorAt = (Node *)VECTOR_At(NULL, (int16)0); + ASSERT_EQ(TRUE, vectorAt == nullptr); + + VECTOR_Clear(&nodeVector); +} + +/** + * @tc.number : DMSLite_SAMGR_Common_0090 + * @tc.name : If vector is nullptr searching from vector fails + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(CommonTest, testCommon0090, TestSize.Level2) +{ + Vector nodeVector = VECTOR_Make((VECTOR_Key)GetNode, (VECTOR_Compare)CompareNode); + Node node = {1, (char*)"node1", 1}; + VECTOR_Add(&nodeVector, &node); + + int16 indexFind = VECTOR_Find(NULL, &node); + ASSERT_EQ(INVALID_INDEX, indexFind); + + int16 indexFindByKey = VECTOR_FindByKey(NULL, &node); + ASSERT_EQ(INVALID_INDEX, indexFindByKey); + + VECTOR_Clear(&nodeVector); +} \ No newline at end of file diff --git a/distributedschedule_lite/samgr_posix/src/DefaultFeatureApiTest.cpp b/distributedschedule_lite/samgr_posix/src/DefaultFeatureApiTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..17a902d8b67ef9d34a19f906a758e6799d96d7c0 --- /dev/null +++ b/distributedschedule_lite/samgr_posix/src/DefaultFeatureApiTest.cpp @@ -0,0 +1,305 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include "utils/SamgrTestBase.h" + +using namespace testing::ext; + +struct DemoApi { + INHERIT_IUNKNOWN; +}; + +struct ExampleService { + INHERIT_SERVICE; + Identity identity; +}; + +static DemoApi g_api = { + DEFAULT_IUNKNOWN_IMPL, +}; + +static const char *GetName(Service *service) +{ + (void)service; + return "serviceName301"; +} + +static BOOL Initialize(Service *service, Identity identity) +{ + ExampleService *example = (ExampleService *)service; + example->identity = identity; + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)service; + (void)msg; + return FALSE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + (void)service; + TaskConfig config = {LEVEL_HIGH, PRI_ABOVE_NORMAL, 0x800, 20, SHARED_TASK}; + return config; +} + +static ExampleService g_service = { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .identity = {-1, -1, nullptr}, +}; + +class DefaultFeatureApiTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + SystemInitProxy(); + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + BOOL result = SAMGR_GetInstance()->RegisterService((Service *)&g_service); + if (result != TRUE) { + printf("[hcpptest]E failed to register service. \n"); + } + } + // Testcase teardown + virtual void TearDown() + { + SAMGR_GetInstance()->UnregisterService("serviceName301"); + } +}; + +/** + * @tc.number : DMSLite_SAMGR_RegisterDefaultFeatureApi_0010 + * @tc.name : Valid API can be registered under default feature + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(DefaultFeatureApiTest, testRegisterDefaultFeatureApi0010, TestSize.Level1) { + BOOL result = SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName301", (IUnknown *)&g_api); + ASSERT_EQ(result, TRUE); + + SAMGR_GetInstance()->UnregisterDefaultFeatureApi("serviceName301"); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterDefaultFeatureApi_0020 + * @tc.name : API failed to register if the specified service is null + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(DefaultFeatureApiTest, testRegisterDefaultFeatureApi0020, TestSize.Level2) { + BOOL result = SAMGR_GetInstance()->RegisterDefaultFeatureApi(NULL, (IUnknown *)&g_api); + ASSERT_EQ(result, FALSE); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterDefaultFeatureApi_0030 + * @tc.name : API failed to register if the specified service does not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(DefaultFeatureApiTest, testRegisterDefaultFeatureApi0030, TestSize.Level2) { + BOOL result = SAMGR_GetInstance()->RegisterDefaultFeatureApi("noExistService", (IUnknown *)&g_api); + ASSERT_EQ(result, FALSE); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterDefaultFeatureApi_0040 + * @tc.name : API failed to register if the target API is nullptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(DefaultFeatureApiTest, testRegisterDefaultFeatureApi0040, TestSize.Level2) { + BOOL result = SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName301", nullptr); + ASSERT_EQ(result, FALSE); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterDefaultFeatureApi_0050 + * @tc.name : API failed to register for the target API already exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(DefaultFeatureApiTest, testRegisterDefaultFeatureApi0050, TestSize.Level2) { + SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName301", (IUnknown *)&g_api); + BOOL result = SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName301", (IUnknown *)&g_api); + ASSERT_EQ(result, FALSE); + + SAMGR_GetInstance()->UnregisterDefaultFeatureApi("serviceName301"); +} + +/** + * @tc.number : DMSLite_SAMGR_GetDefaultFeatureApi_0010 + * @tc.name : API can be queried out from service + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(DefaultFeatureApiTest, testGetDefaultFeatureApi0010, TestSize.Level2) { + SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName301", (IUnknown *)&g_api); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi("serviceName301"); + ASSERT_EQ(resultIUnknown != nullptr, TRUE); + + SAMGR_GetInstance()->UnregisterDefaultFeatureApi("serviceName301"); +} + +/** + * @tc.number : DMSLite_SAMGR_GetDefaultFeatureApi_0020 + * @tc.name : It's nullptr result for nullptr service + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(DefaultFeatureApiTest, testGetDefaultFeatureApi0020, TestSize.Level2) { + SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName301", (IUnknown *)&g_api); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(NULL); + ASSERT_EQ(resultIUnknown == nullptr, TRUE); + + SAMGR_GetInstance()->UnregisterDefaultFeatureApi("serviceName301"); +} + +/** + * @tc.number : DMSLite_SAMGR_GetDefaultFeatureApi_0030 + * @tc.name : The query result is nullptr for the specified service not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(DefaultFeatureApiTest, testGetDefaultFeatureApi0030, TestSize.Level2) { + SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName301", (IUnknown *)&g_api); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi("noExistService"); + ASSERT_EQ(resultIUnknown == nullptr, TRUE); + + SAMGR_GetInstance()->UnregisterDefaultFeatureApi("serviceName301"); +} + +/** + * @tc.number : DMSLite_SAMGR_GetDefaultFeatureApi_0040 + * @tc.name : The query result is the same for multi query operations + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(DefaultFeatureApiTest, testGetDefaultFeatureApi0040, TestSize.Level2) { + SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName301", (IUnknown *)&g_api); + + IUnknown *resultIUnknown1 = SAMGR_GetInstance()->GetDefaultFeatureApi("serviceName301"); + IUnknown *resultIUnknown2 = SAMGR_GetInstance()->GetDefaultFeatureApi("serviceName301"); + ASSERT_EQ(resultIUnknown1 == resultIUnknown2, TRUE); + + SAMGR_GetInstance()->UnregisterDefaultFeatureApi("serviceName301"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterDefaultFeatureApi_0010 + * @tc.name : Default feature API can be unregistered + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(DefaultFeatureApiTest, testUnregisterDefaultFeatureApi0010, TestSize.Level2) { + SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName301", (IUnknown *)&g_api); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterDefaultFeatureApi("serviceName301"); + ASSERT_EQ(resultIUnknown != nullptr, TRUE); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterDefaultFeatureApi_0020 + * @tc.name : The unregister operation failed if serviceName is nullptr or empty + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(DefaultFeatureApiTest, testUnregisterDefaultFeatureApi0020, TestSize.Level2) { + SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName301", (IUnknown *)&g_api); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterDefaultFeatureApi(NULL); + ASSERT_EQ(resultIUnknown == nullptr, TRUE); + + resultIUnknown = SAMGR_GetInstance()->UnregisterDefaultFeatureApi(""); + ASSERT_EQ(resultIUnknown == nullptr, TRUE); + + SAMGR_GetInstance()->UnregisterDefaultFeatureApi("serviceName301"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterDefaultFeatureApi_0030 + * @tc.name : The unregister operation failed if the specified service does not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(DefaultFeatureApiTest, testUnregisterDefaultFeatureApi0030, TestSize.Level2) { + IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterDefaultFeatureApi("noExistService"); + ASSERT_EQ(resultIUnknown == nullptr, TRUE); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterDefaultFeatureApi_0040 + * @tc.name : Register and unregister default api repeatedly, no memory leak + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(DefaultFeatureApiTest, testUnregisterDefaultFeatureApi0040, TestSize.Level2) { + // RegisterService and unregister default api over and over again, if there is memory leak samgr will crash + for (int i = 0; i < PRESSURE_BASE; i++) { + BOOL result = SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName301", (IUnknown *)&g_api); + ASSERT_EQ(result, TRUE); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi("serviceName301"); + ASSERT_EQ(resultIUnknown != nullptr, TRUE); + + resultIUnknown = SAMGR_GetInstance()->UnregisterDefaultFeatureApi("serviceName301"); + ASSERT_EQ(resultIUnknown != nullptr, TRUE); + + resultIUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi("serviceName301"); + ASSERT_EQ(resultIUnknown == nullptr, TRUE); + } +} \ No newline at end of file diff --git a/distributedschedule_lite/samgr_posix/src/FeatureApiTest.cpp b/distributedschedule_lite/samgr_posix/src/FeatureApiTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..f624587d01cee3f506e2468348f11590352fd19d --- /dev/null +++ b/distributedschedule_lite/samgr_posix/src/FeatureApiTest.cpp @@ -0,0 +1,554 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include "utils/SamgrTestBase.h" + +using namespace testing::ext; + +struct DemoApi { + INHERIT_IUNKNOWN; +}; + +struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoApi); + Identity identity; +}; + +static const char *GetName(Service *service) +{ + (void)service; + return "serviceName401"; +} + +struct ExampleService { + INHERIT_SERVICE; + Identity identity; +}; + +static BOOL Initialize(Service *service, Identity identity) +{ + ExampleService *example = (ExampleService *)service; + example->identity = identity; + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)service; + (void)msg; + return FALSE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + (void)service; + TaskConfig config = { + LEVEL_HIGH, + PRI_ABOVE_NORMAL, + 0x800, + 20, + SHARED_TASK + }; + return config; +} + +static ExampleService g_service = { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .identity = {-1, -1, nullptr}, +}; + +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return "featureName401"; +} +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; +} +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *request) +{ + (void)feature; + (void)request; + return TRUE; +} + +static DemoFeature g_feature = { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ver = 1, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + }, + .identity = {-1, -1, nullptr}, +}; + +class FeatureApiTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + SystemInitProxy(); + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0010 + * @tc.name : Valid api can be registered under a feature + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureApiTest, testRegisterFeatureApi0010, TestSize.Level1) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + + BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", + GET_IUNKNOWN(g_feature)); + ASSERT_EQ(result, TRUE); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0020 + * @tc.name : API failed to register if the specified service name is null or space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureApiTest, testRegisterFeatureApi0020, TestSize.Level2) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + + BOOL result = SAMGR_GetInstance()->RegisterFeatureApi(NULL, "featureName401", GET_IUNKNOWN(g_feature)); + ASSERT_EQ(result, FALSE); + + result = SAMGR_GetInstance()->RegisterFeatureApi("", "featureName401", GET_IUNKNOWN(g_feature)); + ASSERT_EQ(result, FALSE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0030 + * @tc.name : API failed to register if the specified feature is space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureApiTest, testRegisterFeatureApi0030, TestSize.Level2) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + + BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "", GET_IUNKNOWN(g_feature)); + ASSERT_EQ(result, FALSE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0040 + * @tc.name : API failed to register if the api is null + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureApiTest, testRegisterFeatureApi0040, TestSize.Level2) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + + BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", nullptr); + ASSERT_EQ(result, FALSE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0050 + * @tc.name : If the specified feature is null api will be registered as default feature api + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureApiTest, testRegisterFeatureApi0050, TestSize.Level2) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + + // feature is null, handle as default feature api + BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", nullptr, GET_IUNKNOWN(g_feature)); + ASSERT_EQ(result, TRUE); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", nullptr); + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0060 + * @tc.name : API failed to register if the specified service name does not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureApiTest, testRegisterFeatureApi0060, TestSize.Level2) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + + BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("noExistService", "featureName401", GET_IUNKNOWN(g_feature)); + ASSERT_EQ(result, FALSE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0070 + * @tc.name : API failed to register if the specified feature name does not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureApiTest, testRegisterFeatureApi0070, TestSize.Level2) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + + BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "noExistFeature", GET_IUNKNOWN(g_feature)); + ASSERT_EQ(result, FALSE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0080 + * @tc.name : feature api can not be registered twice + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureApiTest, testRegisterFeatureApi0080, TestSize.Level2) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", + GET_IUNKNOWN(g_feature)); + + BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", + GET_IUNKNOWN(g_feature)); + ASSERT_EQ(result, FALSE); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_GetFeatureApi_0010 + * @tc.name : Service can query API by serverName-featureName + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureApiTest, testGetFeatureApi0010, TestSize.Level1) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature)); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName401", "featureName401"); + ASSERT_EQ(resultIUnknown != nullptr, TRUE); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_GetFeatureApi_0020 + * @tc.name : If the specified serviceName is NULL or space GetFeatureApi return NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureApiTest, testGetFeatureApi0020, TestSize.Level2) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature)); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->GetFeatureApi(NULL, "featureName401"); + ASSERT_EQ(resultIUnknown == nullptr, TRUE); + resultIUnknown = SAMGR_GetInstance()->GetFeatureApi("", "featureName401"); + ASSERT_EQ(resultIUnknown == nullptr, TRUE); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_GetFeatureApi_0030 + * @tc.name : If the specified featureName is NULL or space GetFeatureApi return NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureApiTest, testGetFeatureApi0030, TestSize.Level2) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature)); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName401", nullptr); + ASSERT_EQ(resultIUnknown == nullptr, TRUE); + resultIUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName401", ""); + ASSERT_EQ(resultIUnknown == nullptr, TRUE); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_GetFeatureApi_0040 + * @tc.name : If the specified featureName does not exist GetFeatureApi return NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureApiTest, testGetFeatureApi0040, TestSize.Level2) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->GetFeatureApi("noExistService", "featureName401"); + ASSERT_EQ(resultIUnknown == nullptr, TRUE); + resultIUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName401", "noExistFeature"); + ASSERT_EQ(resultIUnknown == nullptr, TRUE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_GetFeatureApi_0050 + * @tc.name : If no API under the specified feature GetFeatureApi return NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureApiTest, testGetFeatureApi0050, TestSize.Level2) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName401", "featureName401"); + ASSERT_EQ(resultIUnknown == nullptr, TRUE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_GetFeatureApi_0060 + * @tc.name : The results of multiple queries are the same for GetFeatureApi + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureApiTest, testGetFeatureApi0060, TestSize.Level2) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature)); + + IUnknown *resultIUnknown1 = SAMGR_GetInstance()->GetFeatureApi("serviceName401", "featureName401"); + IUnknown *resultIUnknown2 = SAMGR_GetInstance()->GetFeatureApi("serviceName401", "featureName401"); + ASSERT_EQ(resultIUnknown1 == resultIUnknown2, TRUE); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeatureApi_0010 + * @tc.name : FeatureApi can be unregistered + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureApiTest, testUnregisterFeatureApi0010, TestSize.Level2) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature)); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + ASSERT_EQ(resultIUnknown != nullptr, TRUE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeatureApi_0020 + * @tc.name : FeatureApi failed to unregister if the specified serviceName is NULL or space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureApiTest, testUnregisterFeatureApi0020, TestSize.Level2) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature)); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterFeatureApi(NULL, "featureName401"); + ASSERT_EQ(resultIUnknown == nullptr, TRUE); + resultIUnknown = SAMGR_GetInstance()->UnregisterFeatureApi("", "featureName401"); + ASSERT_EQ(resultIUnknown == nullptr, TRUE); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeatureApi_0030 + * @tc.name : FeatureApi failed to unregister if the specified featureName is space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureApiTest, testUnregisterFeatureApi0030, TestSize.Level2) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature)); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", ""); + ASSERT_EQ(resultIUnknown == nullptr, TRUE); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeatureApi_0040 + * @tc.name : FeatureApi failed to unregister if the specified serviceName does not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureApiTest, testUnregisterFeatureApi0040, TestSize.Level2) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature)); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterFeatureApi("noExistService", "featureName401"); + ASSERT_EQ(resultIUnknown == nullptr, TRUE); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeatureApi_0050 + * @tc.name : FeatureApi failed to unregister if the specified featureName does not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureApiTest, testUnregisterFeatureApi0050, TestSize.Level2) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature)); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "noExistFeature"); + ASSERT_EQ(resultIUnknown == nullptr, TRUE); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeatureApi_0060 + * @tc.name : Register feature api and unregister repeatedly, no memory leak + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureApiTest, testUnregisterFeatureApi0060, TestSize.Level2) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature); + + for (int i = 0; i < PRESSURE_BASE; i++) { + BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", + GET_IUNKNOWN(g_feature)); + ASSERT_EQ(result, TRUE); + + IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401"); + ASSERT_EQ(resultIUnknown != nullptr, TRUE); + } + SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401"); + SAMGR_GetInstance()->UnregisterService("serviceName401"); +} \ No newline at end of file diff --git a/distributedschedule_lite/samgr_posix/src/FeatureTest.cpp b/distributedschedule_lite/samgr_posix/src/FeatureTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..f63c8a086361f52be4932d95f0c96db8e206e61a --- /dev/null +++ b/distributedschedule_lite/samgr_posix/src/FeatureTest.cpp @@ -0,0 +1,372 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include "utils/SamgrTestBase.h" + +using namespace testing::ext; + +struct DemoApi { + INHERIT_IUNKNOWN; +}; + +struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoApi); + Identity identity; +}; + +struct ExampleService { + INHERIT_SERVICE; + Identity identity; +}; + +static const char *GetName(Service *service) +{ + (void)service; + return "serviceName201"; +} + +static BOOL Initialize(Service *service, Identity identity) +{ + ExampleService *example = (ExampleService *)service; + example->identity = identity; + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)msg; + (void)service; + return FALSE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + (void)service; + TaskConfig config = { + LEVEL_HIGH, + PRI_ABOVE_NORMAL, + 0x800, + 20, + SHARED_TASK + }; + return config; +} + +static ExampleService g_service = { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .identity = {-1, -1, nullptr}, +}; + +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return "featureName201"; +} +static const char *FEATURE_GetName2(Feature *feature) +{ + (void)feature; + return "featureName202"; +} +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; + (void)parent; +} +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *request) +{ + (void)feature; + (void)request; + return TRUE; +} + +static DemoFeature g_feature = { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ver = 0, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + }, + .identity = {-1, -1, nullptr}, +}; + +static DemoFeature g_feature2 = { + .GetName = FEATURE_GetName2, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ver = 0, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + }, + .identity = {-1, -1, nullptr}, +}; + +class FeatureTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + SystemInitProxy(); + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + BOOL result = SAMGR_GetInstance()->RegisterService((Service *)&g_service); + if (result != TRUE) { + printf("[hcpptest]E failed to register service. \n"); + } + } + // Testcase teardown + virtual void TearDown() + { + SAMGR_GetInstance()->UnregisterService("serviceName201"); + } +}; + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeature_0010 + * @tc.name : Valid feature can be registered + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureTest, testRegisterFeature0010, TestSize.Level1) { + BOOL result = SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature); + ASSERT_EQ(result, TRUE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName201"); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeature_0020 + * @tc.name : If the specified service is null feature can not be registered + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureTest, testRegisterFeature0020, TestSize.Level2) { + BOOL result = SAMGR_GetInstance()->RegisterFeature(NULL, (Feature *)&g_feature); + ASSERT_EQ(result, FALSE); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeature_0030 + * @tc.name : If the specified feature is null feature can not be registered + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureTest, testRegisterFeature0030, TestSize.Level2) { + BOOL result = SAMGR_GetInstance()->RegisterFeature("serviceName201", nullptr); + ASSERT_EQ(result, FALSE); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeature_0040 + * @tc.name : Feature can not be registered if the specified service does not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureTest, testRegisterFeature0040, TestSize.Level2) { + BOOL result = SAMGR_GetInstance()->RegisterFeature("noExistServiceName", (Feature *)&g_feature); + ASSERT_EQ(result, FALSE); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeature_0050 + * @tc.name : Feature failed to register if the same feature name already exist in samgr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureTest, testRegisterFeature0050, TestSize.Level2) { + SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature); + + BOOL result = SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature); + ASSERT_EQ(result, FALSE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName201"); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterFeature_0060 + * @tc.name : Multi features can be registered under one service + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureTest, testRegisterFeature0060, TestSize.Level2) { + BOOL result1 = SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature); + ASSERT_EQ(result1, TRUE); + BOOL result2 = SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature2); + ASSERT_EQ(result2, TRUE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName201"); + SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName202"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeature_0010 + * @tc.name : Feature can be unregistered + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureTest, testUnregisterFeature0010, TestSize.Level2) { + SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature); + + Feature *resultFeature = SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName201"); + ASSERT_EQ(strcmp(resultFeature->GetName(resultFeature), "featureName201"), 0); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeature_0020 + * @tc.name : Feature can not be unregistered if the specified service is null or space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureTest, testUnregisterFeature0020, TestSize.Level2) { + SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature); + + Feature *resultFeature = SAMGR_GetInstance()->UnregisterFeature(NULL, "featureName201"); + ASSERT_EQ(resultFeature == nullptr, TRUE); + + resultFeature = SAMGR_GetInstance()->UnregisterFeature("", "featureName201"); + ASSERT_EQ(resultFeature == nullptr, TRUE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName201"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeature_0030 + * @tc.name : Feature can not be unregistered if the specified feature is null or space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureTest, testUnregisterFeature0030, TestSize.Level2) { + SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature); + + Feature *resultFeature = SAMGR_GetInstance()->UnregisterFeature("serviceName201", nullptr); + ASSERT_EQ(resultFeature == nullptr, TRUE); + + resultFeature = SAMGR_GetInstance()->UnregisterFeature("serviceName201", ""); + ASSERT_EQ(resultFeature == nullptr, TRUE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName201"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeature_0040 + * @tc.name : Feature failed to unregister if the specified service not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureTest, testUnregisterFeature0040, TestSize.Level2) { + SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature); + + Feature *resultFeature = SAMGR_GetInstance()->UnregisterFeature("noExistService", "featureName201"); + ASSERT_EQ(resultFeature == nullptr, TRUE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName201"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeature_0050 + * @tc.name : Feature failed to unregister if the specified feature not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureTest, testUnregisterFeature0050, TestSize.Level2) { + SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature); + + Feature *resultFeature = SAMGR_GetInstance()->UnregisterFeature("serviceName201", "noExistFeature"); + ASSERT_EQ(resultFeature == nullptr, TRUE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName201"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeature_0060 + * @tc.name : Feature failed to unregister if there is api under the feature + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureTest, testUnregisterFeature0060, TestSize.Level2) { + SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName201", "featureName201", GET_IUNKNOWN(g_feature)); + + Feature *result = SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName201"); + ASSERT_EQ(result == nullptr, TRUE); + + SAMGR_GetInstance()->UnregisterFeatureApi("serviceName201", "featureName201"); + SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName201"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterFeature_0070 + * @tc.name : Register and unregister feature repeatedly, no memory leak + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(FeatureTest, testUnregisterFeature0070, TestSize.Level2) { + // RegisterService and unregister feature over and over again, if there is memory leak samgr will crash + for (int i = 0; i < PRESSURE_BASE; i++) { + BOOL result = SAMGR_GetInstance()->RegisterFeature("serviceName201", (Feature *)&g_feature); + ASSERT_EQ(result, TRUE); + + Feature *resultFeature = SAMGR_GetInstance()->UnregisterFeature("serviceName201", "featureName201"); + ASSERT_EQ(resultFeature != nullptr, TRUE); + } +} \ No newline at end of file diff --git a/distributedschedule_lite/samgr_posix/src/IUnknownTest.cpp b/distributedschedule_lite/samgr_posix/src/IUnknownTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..28dc19bcae1453fa69edf5de2d91a01b947d1030 --- /dev/null +++ b/distributedschedule_lite/samgr_posix/src/IUnknownTest.cpp @@ -0,0 +1,245 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "utils/SamgrTestBase.h" + +using namespace testing::ext; + +static const char *SERVICE_NAME = "S_iunknown"; +static const char *FEATURE_NAME = "F_iunknown"; + +struct DemoApi { + INHERIT_IUNKNOWN; +}; + +struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoApi); + Identity identity; +}; + +static const char *GetName(Service *service) +{ + (void)service; + return SERVICE_NAME; +} + +struct ExampleService { + INHERIT_SERVICE; + Identity identity; +}; + +static BOOL Initialize(Service *service, Identity identity) +{ + ExampleService *example = (ExampleService *)service; + example->identity = identity; + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)service; + (void)msg; + return FALSE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + (void)service; + TaskConfig config = { + LEVEL_HIGH, + PRI_ABOVE_NORMAL, + 0x800, + 20, + SHARED_TASK + }; + return config; +} + +static ExampleService g_service = { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .identity = {-1, -1, nullptr}, +}; + +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return FEATURE_NAME; +} +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; +} +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *request) +{ + (void)feature; + (void)request; + return TRUE; +} + +static DemoFeature g_feature = { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ver = DEFAULT_VERSION, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + }, + .identity = {-1, -1, nullptr}, +}; + +static DemoApi g_api = { + .QueryInterface = IUNKNOWN_QueryInterface, + .AddRef = IUNKNOWN_AddRef, + .Release = IUNKNOWN_Release, +}; + +class IUnknownTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + SystemInitProxy(); + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + BOOL result1 = SAMGR_GetInstance()->RegisterService((Service *)&g_service); + BOOL result2 = SAMGR_GetInstance()->RegisterFeature(SERVICE_NAME, (Feature *)&g_feature); + if (result1 == FALSE && result2 == FALSE) { + printf("[hctest]E failed to register service or feature \n"); + } + } + // Testcase teardown + virtual void TearDown() + { + Feature *feature = SAMGR_GetInstance()->UnregisterFeature(SERVICE_NAME, FEATURE_NAME); + if (feature == nullptr) { + printf("[hctest]E failed to unregister feature \n"); + } + Service *service = SAMGR_GetInstance()->UnregisterService(SERVICE_NAME); + if (service == nullptr) { + printf("[hctest]E failed to unregister service \n"); + } + } +}; + +/** + * @tc.number : DMSLite_SAMGR_GetIUnknown_0010 + * @tc.name : Use this macro GET_IUNKNOWN user can obtain the IUnknown interface from the subclass object. + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(IUnknownTest, testGetIUnknown0010, TestSize.Level2) { + IUnknown *iUnknown = GET_IUNKNOWN(g_feature); + ASSERT_EQ(iUnknown != nullptr, TRUE); +} + +/** + * @tc.number : DMSLite_SAMGR_GetObject_0010 + * @tc.name : Use this macro GET_OBJECT user can obtain a outside object. + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(IUnknownTest, testGetObject0010, TestSize.Level2) { + IUnknown *iUnknown = GET_IUNKNOWN(g_feature); + IUnknownEntry *entry = GET_OBJECT(iUnknown, IUnknownEntry, iUnknown); + ASSERT_EQ(entry->ver == DEFAULT_VERSION, TRUE); + ASSERT_EQ(entry->ref, 1); +} + +/** + * @tc.number : DMSLite_SAMGR_QueryInterface_0010 + * @tc.name : Use this api QueryInterface user can convert the object to the required subclass type. + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(IUnknownTest, testQueryInterface0010, TestSize.Level2) { + SAMGR_GetInstance()->RegisterFeatureApi(SERVICE_NAME, FEATURE_NAME, GET_IUNKNOWN(g_feature)); + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(SERVICE_NAME, FEATURE_NAME); + DemoApi *demoApi = NULL; + int resultQuery = iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void **)&demoApi); + ASSERT_EQ(EC_SUCCESS, resultQuery); + ASSERT_EQ(TRUE, demoApi != NULL); + + int resultAdd = iUnknown->AddRef(iUnknown); + int resultRelease = iUnknown->Release(iUnknown); + ASSERT_EQ(1, resultAdd - resultRelease); + + SAMGR_GetInstance()->UnregisterFeatureApi(SERVICE_NAME, FEATURE_NAME); +} + +/** + * @tc.number : DMSLite_SAMGR_QueryInterface_0020 + * @tc.name : User can not get the required subclass type if the version does not have permission. + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(IUnknownTest, testQueryInterface0020, TestSize.Level2) { + SAMGR_GetInstance()->RegisterFeatureApi(SERVICE_NAME, FEATURE_NAME, GET_IUNKNOWN(g_feature)); + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(SERVICE_NAME, FEATURE_NAME); + DemoApi *demoApi = NULL; + int resultQuery = iUnknown->QueryInterface(iUnknown, 0x30, (void **)&demoApi); + ASSERT_EQ(EC_INVALID, resultQuery); + + SAMGR_GetInstance()->UnregisterFeatureApi(SERVICE_NAME, FEATURE_NAME); +} + +/** + * @tc.number : DMSLite_SAMGR_QueryInterface_0030 + * @tc.name : User can rewrite this api QueryInterface. + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(IUnknownTest, testQueryInterface0030, TestSize.Level2) { + SAMGR_GetInstance()->RegisterFeatureApi(SERVICE_NAME, FEATURE_NAME, (IUnknown *)&g_api); + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(SERVICE_NAME, FEATURE_NAME); + DemoApi *demoApi = NULL; + int resultQuery = iUnknown->QueryInterface(iUnknown, 0, (void **)&demoApi); + ASSERT_EQ(EC_SUCCESS, resultQuery); + ASSERT_EQ(TRUE, demoApi != NULL); + + SAMGR_GetInstance()->UnregisterFeatureApi(SERVICE_NAME, FEATURE_NAME); +} \ No newline at end of file diff --git a/distributedschedule_lite/samgr_posix/src/LiteIPCClientTest.cpp b/distributedschedule_lite/samgr_posix/src/LiteIPCClientTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..48281c00f129cc30176a04377b229089a9d8d8d9 --- /dev/null +++ b/distributedschedule_lite/samgr_posix/src/LiteIPCClientTest.cpp @@ -0,0 +1,293 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "iproxy_client.h" +#include "utils/SamgrTestBase.h" + +using namespace testing::ext; + +static IClientProxy *GetRemoteIUnknown(const char *serviceName, const char *featureName) +{ + IClientProxy *demoApi = NULL; + IUnknown *iUnknown = NULL; + if (featureName == nullptr) { + iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(serviceName); + } else { + iUnknown = SAMGR_GetInstance()->GetFeatureApi(serviceName, featureName); + } + + if (iUnknown == nullptr) { + printf("[hcpptest][TID:0x%lx][GetDefaultFeatureApi S:%s]: error is NULL", pthread_self(), serviceName); + return nullptr; + } + (void)iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void **)&demoApi); + + return demoApi; +} + +static int CurrentCallback(IOwner owner, int code, IpcIo *reply) +{ + printf("[hcpptest]CurrentCallback run \n"); + size_t len = 0; + char *response = (char *)IpcIoPopString(reply, &len); + printf("[hcpptest]response %s \n", response); + return 0; +} + +static void ReleaseIUnknown(IUnknown *demoApi) +{ + if (demoApi != NULL) { + demoApi->Release((IUnknown *)demoApi); + } +} + +class LiteIPCClientTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + printf("[hcpptest]SetUpTestCase! \n"); + SystemInitProxy(); + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + } + // Testcase teardown + virtual void TearDown() + { + } +}; + + +/** + * @tc.number : DMSLite_SAMGR_IPCClient_0010 + * @tc.name : Client can get api of other process + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 +*/ +HWTEST_F(LiteIPCClientTest, testIPCClient0010, TestSize.Level1) +{ + IClientProxy *demoApi = NULL; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("abilityms", "AmsFeature"); + ASSERT_EQ(iUnknown != NULL, TRUE); + + int result = iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void **)&demoApi); + ASSERT_EQ(result, 0); + ASSERT_EQ(demoApi != nullptr, TRUE); +}; + +/** + * @tc.number : DMSLite_SAMGR_IPCClient_0020 + * @tc.name : Client can not get api if service name or feature name not exist in the system + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(LiteIPCClientTest, testIPCClient0020, TestSize.Level2) +{ + IClientProxy *demoApi = NULL; + + IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi("notExistService"); + ASSERT_EQ(iUnknown == NULL, TRUE); + + iUnknown = SAMGR_GetInstance()->GetFeatureApi("notExistService", ""); + ASSERT_EQ(iUnknown == NULL, TRUE); + + iUnknown = SAMGR_GetInstance()->GetFeatureApi("samgr", "notExistFeature"); + ASSERT_EQ(iUnknown == NULL, TRUE); +}; + +/** + * @tc.number : DMSLite_SAMGR_IPCClient_0030 + * @tc.name : Client can not get api if the api version does not match + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(LiteIPCClientTest, testIPCClient0030, TestSize.Level2) +{ + IClientProxy *demoApi = NULL; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("abilityms", "AmsFeature"); + ASSERT_EQ(iUnknown != NULL, TRUE); + + int result = iUnknown->QueryInterface(iUnknown, 0x00, (void **)&demoApi); + ASSERT_EQ(result != 0, TRUE); + ASSERT_EQ(demoApi == nullptr, TRUE); +}; + +/** + * @tc.number : DMSLite_SAMGR_IPCClient_0040 + * @tc.name : Client can send request to other process + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 +*/ +HWTEST_F(LiteIPCClientTest, testIPCClient0040, TestSize.Level1) +{ + IClientProxy *remoteApi = GetRemoteIUnknown("abilityms", "AmsFeature"); + ASSERT_EQ(remoteApi != nullptr, TRUE); + + IpcIo request; + char data[250]; + IpcIoInit(&request, data, sizeof(data), 0); + char *buff = (char*)"test xxxx"; + IpcIoPushString(&request, buff); + + char data2[250]; + int funcId = 0; + int result = remoteApi->Invoke(remoteApi, funcId, &request, data2, CurrentCallback); + ASSERT_EQ(result, EC_SUCCESS); + + ReleaseIUnknown((IUnknown *)remoteApi); +}; + +/** + * @tc.number : DMSLite_SAMGR_IPCClient_0050 + * @tc.name : Client can send request to ams + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(LiteIPCClientTest, testIPCClient0050, TestSize.Level2) +{ + IClientProxy *remoteApi = GetRemoteIUnknown("abilityms", "AmsFeature"); + printf("[hcpptest]remoteApi is null: %d \n", remoteApi == nullptr); + + IpcIo request; + char data[250]; + IpcIoInit(&request, data, sizeof(data), 0); + char *buff = (char*)"test xxxx"; + IpcIoPushString(&request, buff); + + char data2[250]; + int funcId = 0; + int result = remoteApi->Invoke(remoteApi, funcId, &request, data2, CurrentCallback); + printf("[hcpptest]result is: %d \n", result); + ASSERT_EQ(result, EC_SUCCESS); + + ReleaseIUnknown((IUnknown *)remoteApi); +}; + +/** + * @tc.number : DMSLite_SAMGR_IPCClient_0060 + * @tc.name : Client can send request to ams + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(LiteIPCClientTest, testIPCClient0060, TestSize.Level2) +{ + IClientProxy *remoteApi = GetRemoteIUnknown("abilityms", "AmsInnerFeature"); + printf("[hcpptest]remoteApi is null: %d \n", remoteApi == nullptr); + + IpcIo request; + char data[250]; + IpcIoInit(&request, data, sizeof(data), 0); + char *buff = (char*)"test xxxx"; + IpcIoPushString(&request, buff); + + char data2[250]; + int funcId = 0; + int result = remoteApi->Invoke(remoteApi, funcId, &request, data2, CurrentCallback); + printf("[hcpptest]result is: %d \n", result); + ASSERT_EQ(result, EC_SUCCESS); + + ReleaseIUnknown((IUnknown *)remoteApi); +}; + +/** + * @tc.number : DMSLite_SAMGR_IPCClient_0100 + * @tc.name : User can get IPC address of remote service + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(LiteIPCClientTest, testIPCClient0100, TestSize.Level2) +{ + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("abilityms", "AmsFeature"); + ASSERT_EQ(iUnknown != nullptr, TRUE); + + SvcIdentity svcIdentity = SAMGR_GetRemoteIdentity("abilityms", "AmsFeature"); + printf("[hcpptest]handle:%lx token:%lx \n", svcIdentity.handle, svcIdentity.token); + ASSERT_EQ(svcIdentity.handle != 0xffffffff, TRUE); +}; + +/** + * @tc.number : DMSLite_SAMGR_IPCClient_0110 + * @tc.name : User can get an invalid IPC address if input para is nullptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(LiteIPCClientTest, testIPCClient0110, TestSize.Level2) +{ + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("abilityms", "AmsFeature"); + + SvcIdentity svcIdentity = SAMGR_GetRemoteIdentity(nullptr, "AmsFeature"); + printf("[hcpptest]handle:%lx token:%lx \n", svcIdentity.handle, svcIdentity.token); + ASSERT_EQ(svcIdentity.handle == 0xffffffff, TRUE); + + svcIdentity = SAMGR_GetRemoteIdentity("abilityms", nullptr); + printf("[hcpptest]handle:%lx token:%lx \n", svcIdentity.handle, svcIdentity.token); + ASSERT_EQ(svcIdentity.handle == 0xffffffff, TRUE); +}; + +/** + * @tc.number : DMSLite_SAMGR_IPCClient_0120 + * @tc.name : User can get an invalid IPC address if has not called GetFeatureApi first + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(LiteIPCClientTest, testIPCClient0120, TestSize.Level2) +{ + SvcIdentity svcIdentity = SAMGR_GetRemoteIdentity("samgr", nullptr); + printf("[hcpptest]handle:%lx token:%lx \n", svcIdentity.handle, svcIdentity.token); + ASSERT_EQ(svcIdentity.handle == 0xffffffff, TRUE); +}; + +/** + * @tc.number : DMSLite_SAMGR_IPCClient_0130 + * @tc.name : User get an invalid IPC address if service not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(LiteIPCClientTest, testIPCClient0130, TestSize.Level2) +{ + SvcIdentity svcIdentity = SAMGR_GetRemoteIdentity("noExistService", "noExistFeature"); + printf("[hcpptest]handle:0x%lx token:%lx \n", svcIdentity.handle, svcIdentity.token); + ASSERT_EQ(svcIdentity.handle == 0xffffffff, TRUE); + ASSERT_EQ(svcIdentity.token == 0xffffffff, TRUE); +}; \ No newline at end of file diff --git a/distributedschedule_lite/samgr_posix/src/LiteIPCFeatureTest.cpp b/distributedschedule_lite/samgr_posix/src/LiteIPCFeatureTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..ec62819f272638d8c1ac3da8fdcd81acf2bb5b04 --- /dev/null +++ b/distributedschedule_lite/samgr_posix/src/LiteIPCFeatureTest.cpp @@ -0,0 +1,265 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "utils/SamgrTestBase.h" +#include "iproxy_client.h" +#include "iproxy_server.h" + +using namespace testing::ext; + +static const char *SERVICE_NAME = {"ipcService02"}; +static const char *FEATURE_NAME = {"ipcFeature"}; + +struct DemoService { + INHERIT_SERVICE; + Identity identity; + BOOL serviceStatus; +}; + +static const char *GetName(Service *service) +{ + (void)service; + return SERVICE_NAME; +} + +static BOOL Initialize(Service *service, Identity identity) +{ + DemoService *demoService = (DemoService *)service; + demoService->identity = identity; + demoService->serviceStatus = TRUE; + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)service; + (void)msg; + return FALSE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + (void)service; + TaskConfig config = {LEVEL_HIGH, PRI_BELOW_NORMAL, 0x800, 20, SHARED_TASK}; + return config; +} + +static DemoService g_service = { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .identity = {-1, -1, nullptr}, + .serviceStatus = FALSE, +}; + +static int calledCount = 0; +struct DemoFeatureApi { + INHERIT_SERVER_IPROXY; + void (*SyncCall)(IUnknown *iUnknown); +}; + +struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoFeatureApi); + Identity identity; + BOOL featureStatus; +}; + +static const char *FEATURE_GetName(Feature *feature); +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity); +static void FEATURE_OnStop(Feature *feature, Identity identity); +static BOOL FEATURE_OnMessage(Feature *feature, Request *request); +static int32 Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, IpcIo *reply); +static void SyncCall(IUnknown *iUnknown); + +static DemoFeature g_feature = { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + SERVER_IPROXY_IMPL_BEGIN, + .Invoke = Invoke, + .SyncCall = SyncCall, + IPROXY_END, + .identity = {-1, -1, NULL}, + .featureStatus = FALSE, +}; +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return FEATURE_NAME; +} + +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; + demoFeature->featureStatus = TRUE; +} + +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *msg) +{ + printf("[hcpptest][TID:0x%lx]OnMessage(%s)! Request<%d, %d, %p>", + pthread_self(), feature->GetName(feature), msg->msgId, msg->msgValue, msg->data); + return TRUE; +} + +static int32 Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, IpcIo *reply) +{ + printf("[hcpptest][TID:0x%lx]Feature Remote Invoke is called! <%p, %d, %p, %p, %p>", + pthread_self(), iProxy, funcId, origin, req, reply); + IpcIoPushBool(reply, TRUE); + return EC_SUCCESS; +} + +static void SyncCall(IUnknown *iUnknown) +{ + calledCount++; +} + +static void ServiceInit(void) +{ + BOOL result = SAMGR_GetInstance()->RegisterService((Service *)&g_service); + if (result == FALSE) { + printf("[hcpptest][error]RegisterService fail \n"); + (&g_service)->serviceStatus = FALSE; + } +} +SYSEX_SERVICE_INIT(ServiceInit); + +static void FeatureInit(void) +{ + BOOL result = SAMGR_GetInstance()->RegisterFeature(SERVICE_NAME, (Feature *)&g_feature); + if (result == FALSE) { + printf("[hcpptest][error]RegisterFeature fail \n"); + (&g_feature)->featureStatus = FALSE; + } + result = SAMGR_GetInstance()->RegisterFeatureApi(SERVICE_NAME, FEATURE_NAME, GET_IUNKNOWN(g_feature)); + if (result == FALSE) { + printf("[hcpptest][error]RegisterFeatureApi fail \n"); + (&g_feature)->featureStatus = FALSE; + } +} +SYSEX_FEATURE_INIT(FeatureInit); + +class LiteIPCFeatureTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + SystemInitProxy(); + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + usleep(OPER_INTERVAL * MS2US); + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** + * @tc.number : DMSLite_SAMGR_IPCFeature_0010 + * @tc.name : Feature which cross process should be inited ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(LiteIPCFeatureTest, testIPCFeature0010, TestSize.Level2) +{ + ASSERT_EQ((&g_service)->serviceStatus, TRUE); + ASSERT_EQ((&g_feature)->featureStatus, TRUE); +}; + +/** + * @tc.number : DMSLite_SAMGR_IPCFeature_0020 + * @tc.name : Feature which cross process also can be accessed as LPC + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(LiteIPCFeatureTest, testIPCFeature0020, TestSize.Level2) +{ + DemoFeatureApi *demoApi = nullptr; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(SERVICE_NAME, FEATURE_NAME); + ASSERT_EQ(iUnknown != nullptr, TRUE); + + // DEFAULT_VERSION: means access inside service + int resultCode = iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void **)&demoApi); + ASSERT_EQ(resultCode == EC_SUCCESS, TRUE); + + int countBefore = calledCount; + demoApi->SyncCall((IUnknown *)demoApi); + int countAfter = calledCount; + + ASSERT_EQ(countAfter - countBefore, 1); +}; + +/** + * @tc.number : DMSLite_SAMGR_IPCFeature_0030 + * @tc.name : For inside caller, Feature which cross process can not be accessed as IPC + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(LiteIPCFeatureTest, testIPCFeature0030, TestSize.Level2) +{ + IClientProxy *demoApi = nullptr; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(SERVICE_NAME, FEATURE_NAME); + ASSERT_EQ(iUnknown != nullptr, TRUE); + + // CLIENT_PROXY_VER: means access cross process + int resultCode = iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void **)&demoApi); + ASSERT_EQ(resultCode != EC_SUCCESS, TRUE); +}; + +/** + * @tc.number : DMSLite_SAMGR_IPCFeature_0040 + * @tc.name : Feature which cross process can be unregistered + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(LiteIPCFeatureTest, testIPCFeature0040, TestSize.Level2) +{ + IUnknown *iUnknown = SAMGR_GetInstance()->UnregisterFeatureApi(SERVICE_NAME, FEATURE_NAME); + ASSERT_EQ(iUnknown != nullptr, TRUE); + + Feature *feature = SAMGR_GetInstance()->UnregisterFeature(SERVICE_NAME, FEATURE_NAME); + ASSERT_EQ(feature != nullptr, TRUE); + + Service *service = SAMGR_GetInstance()->UnregisterService(SERVICE_NAME); + ASSERT_EQ(service != nullptr, TRUE); +}; \ No newline at end of file diff --git a/distributedschedule_lite/samgr_posix/src/LiteIPCServiceTest.cpp b/distributedschedule_lite/samgr_posix/src/LiteIPCServiceTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..ea011c46e6d8dc5cf4c7ce4914a9592def4f24b0 --- /dev/null +++ b/distributedschedule_lite/samgr_posix/src/LiteIPCServiceTest.cpp @@ -0,0 +1,271 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "utils/SamgrTestBase.h" +#include "iproxy_client.h" +#include "iproxy_server.h" + +using namespace testing::ext; + +static const char *SERVICE_NAME = {"ipcService01"}; + +static int calledCount = 0; +struct DefaultFeatureApi { + INHERIT_SERVER_IPROXY; + void (*SyncCall)(IUnknown *iUnknown); +}; + +struct DemoService { + INHERIT_SERVICE; + INHERIT_IUNKNOWNENTRY(DefaultFeatureApi); + Identity identity; + BOOL serviceStatus; +}; + +static const char *GetName(Service *service) +{ + (void)service; + return SERVICE_NAME; +} +static const char *GetName2(Service *service) +{ + (void)service; + return "samgr"; +} +static BOOL Initialize(Service *service, Identity identity) +{ + DemoService *demoService = (DemoService *)service; + demoService->identity = identity; + + demoService->serviceStatus = TRUE; + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + printf("[hcpptest][TID:0x%lx]MessageHandle(%s)! Request<%d, %d, %p>", + pthread_self(), service->GetName(service), msg->msgId, msg->msgValue, msg->data); + return FALSE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + (void)service; + TaskConfig config = {LEVEL_HIGH, PRI_BELOW_NORMAL, 0x800, 20, SHARED_TASK}; + return config; +} +static void SyncCall(IUnknown *iUnknown) +{ + calledCount++; +} +static int32 Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, IpcIo *reply) +{ + printf("[hcpptest][TID:0x%lx]Service Remote Invoke is called! <%p, %d, %p, %p, %p>", + pthread_self(), iProxy, funcId, origin, req, reply); + + size_t len = 0; + char *requestStr = (char *)IpcIoPopString(req, &len); + if (requestStr != nullptr) { + printf("[hcpptest]requestStr is %s", requestStr); + } else { + printf("[hcpptest]requestStr is NULL"); + } + + DefaultFeatureApi *defaultApi = (DefaultFeatureApi *)iProxy; + if (funcId == 0) { + defaultApi->SyncCall((IUnknown *)iProxy); + } + + IpcIoPushString(reply, "Yes, you did!"); + return EC_SUCCESS; +} +static DemoService g_service = { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + SERVER_IPROXY_IMPL_BEGIN, + .Invoke = Invoke, + .SyncCall = SyncCall, + IPROXY_END, + .identity = {-1, -1, nullptr}, + .serviceStatus = FALSE, +}; + +static DemoService g_service2 = { + .GetName = GetName2, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + SERVER_IPROXY_IMPL_BEGIN, + .Invoke = Invoke, + .SyncCall = SyncCall, + IPROXY_END, + .identity = {-1, -1, nullptr}, + .serviceStatus = FALSE, +}; + +static void ServiceInit(void) +{ + BOOL result1 = SAMGR_GetInstance()->RegisterService((Service *)&g_service); + BOOL result2 = SAMGR_GetInstance()->RegisterDefaultFeatureApi(SERVICE_NAME, GET_IUNKNOWN(g_service)); + if (result1 == FALSE || result2 == FALSE) { + printf("[hcpptest][error]RegisterService or register api fail \n"); + (&g_service)->serviceStatus = FALSE; + } +} +SYSEX_SERVICE_INIT(ServiceInit); + +static IClientProxy *getRemoteIUnknown(const char *serviceName, const char *featureName) +{ + IClientProxy *demoApi = nullptr; + IUnknown *iUnknown = nullptr; + if (featureName == nullptr) { + iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(serviceName); + } else { + iUnknown = SAMGR_GetInstance()->GetFeatureApi(serviceName, featureName); + } + + if (iUnknown == nullptr) { + printf("[hcpptest]failed to get api\n"); + } + int resultCode = iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void **)&demoApi); + if (resultCode != EC_SUCCESS) { + printf("[hcpptest][error]fail to QueryInterface and returnCode: %d\n", resultCode); + } + return demoApi; +} + +static void ReleaseIUnknown(IUnknown *demoApi) +{ + if (demoApi != NULL) { + demoApi->Release((IUnknown *)demoApi); + } +} + +class LiteIPCServiceTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + SystemInitProxy(); + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + usleep(OPER_INTERVAL * MS2US); + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** + * @tc.number : DMSLite_SAMGR_IPCService_0010 + * @tc.name : Service which cross processes is registered ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 +*/ +HWTEST_F(LiteIPCServiceTest, testIPCService0010, TestSize.Level1) +{ + ASSERT_EQ((&g_service)->serviceStatus, TRUE); + ASSERT_EQ((&g_service)->identity.serviceId != -1, TRUE); +}; + +/** + * @tc.number : DMSLite_SAMGR_IPCService_0020 + * @tc.name : Service which cross process also can be accessed as LPC + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(LiteIPCServiceTest, testIPCService0020, TestSize.Level2) +{ + DefaultFeatureApi *demoApi = nullptr; + IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(SERVICE_NAME); + ASSERT_EQ(iUnknown != nullptr, TRUE); + + // DEFAULT_VERSION: means access inside service + int resultCode = iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void **)&demoApi); + ASSERT_EQ(resultCode == EC_SUCCESS, TRUE); + + int countBefore = calledCount; + demoApi->SyncCall((IUnknown *)demoApi); + int countAfter = calledCount; + + ASSERT_EQ(countAfter - countBefore, 1); +}; + +/** + * @tc.number : DMSLite_SAMGR_IPCService_0030 + * @tc.name : For inside caller, Service which cross process can not be accessed as IPC + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(LiteIPCServiceTest, testIPCService0030, TestSize.Level2) +{ + IClientProxy *demoApi = nullptr; + IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(SERVICE_NAME); + ASSERT_EQ(iUnknown != nullptr, TRUE); + + // CLIENT_PROXY_VER: means access other process + int resultCode = iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void **)&demoApi); + ASSERT_EQ(resultCode != EC_SUCCESS, TRUE); +}; + +/** + * @tc.number : DMSLite_SAMGR_IPCService_0040 + * @tc.name : Service which cross process can be unregistered + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(LiteIPCServiceTest, testIPCService0040, TestSize.Level2) +{ + IUnknown *iUnknown = SAMGR_GetInstance()->UnregisterDefaultFeatureApi(SERVICE_NAME); + ASSERT_EQ(iUnknown != nullptr, TRUE); + + Service *service = SAMGR_GetInstance()->UnregisterService(SERVICE_NAME); + ASSERT_EQ(service != nullptr, TRUE); +}; + +/** + * @tc.number : DMSLite_SAMGR_IPCService_0050 + * @tc.name : User can not unregister service belong to other process + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(LiteIPCServiceTest, testIPCService0050, TestSize.Level2) +{ + // samgr belong foundation process + IUnknown *iUnknown = SAMGR_GetInstance()->UnregisterDefaultFeatureApi("samgr"); + ASSERT_EQ(iUnknown == nullptr, TRUE); +}; \ No newline at end of file diff --git a/distributedschedule_lite/samgr_posix/src/SendRequestTest.cpp b/distributedschedule_lite/samgr_posix/src/SendRequestTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..e34e7e9989f891a00a845613064e4f3e43858c6b --- /dev/null +++ b/distributedschedule_lite/samgr_posix/src/SendRequestTest.cpp @@ -0,0 +1,796 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "utils/SamgrTestBase.h" + +using namespace testing::ext; + +enum MessageId { + MSG_NO, // receiver does not send response + MSG_RT, // receiver send response + MSG_FW, // receiver forward message +}; + +struct Payload { + int id; + const char *name; + int value; +}; + +struct DemoApi { + INHERIT_IUNKNOWN; + BOOL(*SyncCall)(IUnknown *iUnknown, struct Payload *payload); + int32 (*SAMGR_SendRequestProxy)(const Identity *identity, const Request *request, Handler handler); +}; + +struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoApi); + Identity identity; + int featureCalledCount; + BOOL featureStatus; + char *latestRequest; +}; + +struct DefaultFeatureApi { + INHERIT_IUNKNOWN; +}; + +struct ExampleService { + INHERIT_SERVICE; + INHERIT_IUNKNOWNENTRY(DefaultFeatureApi); + Identity identity; +}; + +static BOOL SyncCall(IUnknown *iUnknown, struct Payload *payload) +{ + (void)iUnknown; + if (payload != nullptr && payload->id >= 0 && payload->name != nullptr) { + return TRUE; + } else { + return FALSE; + } +} + +static int32 SAMGR_SendRequestProxy(const Identity *identity, const Request *request, Handler handler) +{ + return SAMGR_SendRequest(identity, request, handler); +} + +static const char *GetName(Service *service) +{ + (void)service; + return "serviceName501"; +} + +static BOOL Initialize(Service *service, Identity identity) +{ + ExampleService *example = (ExampleService *)service; + example->identity = identity; + + printf("[hcpptest]serviceName %s Initialize \n", service->GetName(service)); + + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)service; + return FALSE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + (void)service; + TaskConfig config = {LEVEL_HIGH, PRI_ABOVE_NORMAL, 0x800, 20, SHARED_TASK}; + return config; +} + +static ExampleService g_service = { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ver = 0x20, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + } +}; + +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return "featureName501"; +} + +static const char *FEATURE_GetName02(Feature *feature) +{ + (void)feature; + return "featureName502"; +} + +static const char *FEATURE_GetName03(Feature *feature) +{ + (void)feature; + return "featureName503"; +} + +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; + + printf("[hcpptest]featureName %s Initialize \n", feature->GetName(feature)); + (void)parent; +} + +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *request) +{ + int32 returnCode; + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + demoFeature->latestRequest = (char *)request->data; + demoFeature->featureStatus = ((returnCode == 0) ? TRUE : FALSE); + + return demoFeature->featureStatus; +} + +static BOOL FEATURE_OnMessage02(Feature *feature, Request *request) +{ + int32 returnCode; + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + + if (demoFeature->latestRequest != nullptr) { + free(demoFeature->latestRequest); + } + + int requestLen = 0; + if (request->len > 0) { + requestLen = request->len; + } else { + requestLen = strlen((char *)request->data) + 1; + } + demoFeature->latestRequest = (char *)malloc(requestLen * sizeof(char)); + if (demoFeature->latestRequest == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s(demoFeature->latestRequest, requestLen, (char *)request->data); + if (error != EOK) { + ADD_FAILURE(); + } + + switch (request->msgId) { + case MSG_NO: + returnCode = 0; + break; + case MSG_RT: + { + char *dataR = (char*)"Yes, you did!"; + Response response = { + .data = dataR, + .len = 0, + }; + returnCode = SAMGR_SendResponse(request, &response); + }; + break; + case MSG_FW: + { + returnCode = 0; + }; + break; + } + demoFeature->featureStatus = ((returnCode == 0) ? TRUE : FALSE); + return demoFeature->featureStatus; +} + +static BOOL FEATURE_OnMessage03(Feature *feature, Request *request) +{ + int32 returnCode; + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + + int requestLen = 0; + if (request->len > 0) { + requestLen = request->len; + } else { + requestLen = strlen((char *)request->data) + 1; + } + demoFeature->latestRequest = (char *)malloc(requestLen * sizeof(char)); + if (demoFeature->latestRequest == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s(demoFeature->latestRequest, requestLen, (char *)request->data); + if (error != EOK) { + ADD_FAILURE(); + } + + switch (request->msgId) { + case MSG_NO: + returnCode = 0; + break; + case MSG_RT: + { + char *dataR = (char*)"Yes, you did!"; + Response response = { + .data = dataR, + .len = 0, + }; + returnCode = SAMGR_SendResponse(request, &response); + }; + break; + case MSG_FW: + { + returnCode = 0; + }; + break; + } + demoFeature->featureStatus = ((returnCode == 0) ? TRUE : FALSE); + + return demoFeature->featureStatus; +} + +static DemoFeature g_feature = { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ver = 0x20, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .SyncCall = SyncCall, + .SAMGR_SendRequestProxy = SAMGR_SendRequestProxy, + }, + .identity = {-1, -1, nullptr}, + .featureCalledCount = 0, + .featureStatus = TRUE, + .latestRequest = nullptr, +}; +static DemoFeature g_feature02 = { + .GetName = FEATURE_GetName02, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage02, + .ver = 0x20, + .ref = 0, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .SyncCall = SyncCall, + .SAMGR_SendRequestProxy = SAMGR_SendRequestProxy, + }, + .identity = {-1, 1, nullptr}, + .featureCalledCount = 0, + .featureStatus = TRUE, + .latestRequest = nullptr, +}; +static DemoFeature g_feature03 = { + .GetName = FEATURE_GetName03, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage03, + .ver = 0x20, + .ref = 0, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .SyncCall = SyncCall, + .SAMGR_SendRequestProxy = SAMGR_SendRequestProxy, + }, + .identity = {-1, 2, nullptr}, + .featureCalledCount = 0, + .featureStatus = TRUE, + .latestRequest = nullptr, +}; + +static void GServiceInit(void) +{ + printf("[hcpptest]GServiceInit start! \n"); + BOOL result = SAMGR_GetInstance()->RegisterService((Service *)&g_service); + if (result == FALSE) { + printf("[hcpptest]E RegisterService failed! \n"); + } +} +SYSEX_SERVICE_INIT(GServiceInit); + +static void GFeatureInit(void) +{ + printf("[hcpptest]GFeatureInit start! \n"); + + BOOL result1 = SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName501", GET_IUNKNOWN(g_feature)); + + BOOL result2 = SAMGR_GetInstance()->RegisterFeature("serviceName501", (Feature *)&g_feature02); + BOOL result3 = SAMGR_GetInstance()->RegisterFeatureApi("serviceName501", "featureName502", + GET_IUNKNOWN(g_feature02)); + + BOOL result4 = SAMGR_GetInstance()->RegisterFeature("serviceName501", (Feature *)&g_feature03); + BOOL result5 = SAMGR_GetInstance()->RegisterFeatureApi("serviceName501", "featureName503", + GET_IUNKNOWN(g_feature03)); + if (result1 == FALSE || result2 == FALSE || result3 == FALSE || result4 == FALSE || result5 == FALSE) { + printf("[hcpptest]E failed to register feature or api! \n"); + } +} +SYSEX_FEATURE_INIT(GFeatureInit); + +static DemoApi *GetIUnknown(const char *serviceName, const char *featureName) +{ + DemoApi *demoApi = nullptr; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(serviceName, featureName); + if (iUnknown == nullptr) { + return nullptr; + } + int result = iUnknown->QueryInterface(iUnknown, 0x20, (void **)&demoApi); + if (result == 0 && demoApi != nullptr) { + return demoApi; + } else { + return nullptr; + } +} + +static void ReleaseIUnknown(DemoApi *demoApi) +{ + demoApi->Release((IUnknown *)demoApi); +} + +static void DemoHandler(const Request *request, const Response *response) +{ + (void)request; + (void)response; +} + +static void DemoHandlerAndCheck(const Request *request, const Response *response) +{ + char *requestData = (char*)"I wanna async call good result!"; + ASSERT_EQ(strcmp((char *)request->data, requestData), 0); + + char *responseData = (char*)"Yes, you did!"; + ASSERT_EQ(strcmp((char *)response->data, responseData), 0); +} + +class SendRequestTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + printf("[hcpptest]SetUpTestCase! \n"); + SystemInitProxy(); + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + usleep(OPER_INTERVAL * MS2US); + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** + * @tc.number : DMSLite_SAMGR_SyncCall_0010 + * @tc.name : Service support synchronous call + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(SendRequestTest, testSyncCall0010, TestSize.Level1) { + DemoApi *demoApi = GetIUnknown("serviceName501", "featureName502"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + char *nameR = (char*)"I wanna sync call good result!"; + struct Payload payload = { + .id = 0, // api will return true + .name = nameR, + .value = 1}; + BOOL result = demoApi->SyncCall((IUnknown *)demoApi, &payload); + ASSERT_EQ(result, TRUE); + + struct Payload payloadX = { + .id = -1, // api will return false + .name = nameR, + .value = 1}; + result = demoApi->SyncCall((IUnknown *)demoApi, &payloadX); + ASSERT_EQ(result, FALSE); + + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendRequest_0010 + * @tc.name : Service support asynchronous call + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(SendRequestTest, testSendRequest0010, TestSize.Level1) { + DemoApi *demoApi = GetIUnknown("serviceName501", "featureName502"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + Request request = {.msgId = MSG_NO, + .len = 0, + .data = nullptr, + .msgValue = 0}; + char *body = (char*)"I wanna async call good result!"; + request.len = (uint32_t)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + printf("[hcpptest]error failed to strcpy_s \n"); + } + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName501", "featureName503"); + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + + feature->featureCalledCount = 0; + int32 result = demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, nullptr); + ASSERT_EQ(result == 0, TRUE); + + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(feature->featureCalledCount == 1, TRUE); + ASSERT_EQ(strcmp(feature->latestRequest, body), 0); + + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendRequest_0020 + * @tc.name : Feature can send an asynchronous message to itself + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(SendRequestTest, testSendRequest0020, TestSize.Level2) { + DemoApi *demoApi = GetIUnknown("serviceName501", "featureName502"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + Request request = {.msgId = MSG_RT, + .len = 0, + .data = nullptr, + .msgValue = 0}; + char *body = (char*)"I wanna async call good result!"; + request.len = (uint32_t)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + printf("[hcpptest]error failed to strcpy_s \n"); + } + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName501", "featureName502"); + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + + feature->featureCalledCount = 0; + int32 result = demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, nullptr); + ASSERT_EQ(result == 0, TRUE); + + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(feature->featureCalledCount == 1, TRUE); + ASSERT_EQ(strcmp(feature->latestRequest, body), 0); + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendRequest_0030 + * @tc.name : Feature failed to send an asynchronous message if the specified identity does not exist + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(SendRequestTest, testSendRequest0030, TestSize.Level2) { + DemoApi *demoApi = GetIUnknown("serviceName501", "featureName502"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + Request request = {.msgId = MSG_RT, + .len = 0, + .data = nullptr, + .msgValue = 0}; + char *body = (char*)"I wanna async call good result!"; + request.len = (uint32_t)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + + Identity identityX = {-1, -200, nullptr}; + int32 result = demoApi->SAMGR_SendRequestProxy(&identityX, &request, nullptr); + free(request.data); + ASSERT_EQ(result != 0, TRUE); + + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendRequest_0040 + * @tc.name : Feature can send an asynchronous message which length is 0 + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(SendRequestTest, testSendRequest0040, TestSize.Level2) { + DemoApi *demoApi = GetIUnknown("serviceName501", "featureName502"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + Request request = {.msgId = MSG_RT, + .len = 0, + .data = nullptr, + .msgValue = 0}; + char *body = (char*)""; + request.len = (uint32_t)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName501", "featureName503"); + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + + feature->featureCalledCount = 0; + int32 result = demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, nullptr); + ASSERT_EQ(result == 0, TRUE); + + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(feature->featureCalledCount == 1, TRUE); + ASSERT_EQ(strcmp(feature->latestRequest, body), 0); + + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendRequest_0050 + * @tc.name : Feature failed to send an asynchronous message if id or request is nullptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(SendRequestTest, testSendRequest0050, TestSize.Level2) { + DemoApi *demoApi = GetIUnknown("serviceName501", "featureName502"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + Request request = {.msgId = MSG_RT, + .len = 0, + .data = nullptr, + .msgValue = 0}; + char *body = (char*)"xxxx"; + request.len = strlen(body) + 1; + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName501", "featureName503"); + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + + int32 result = demoApi->SAMGR_SendRequestProxy(NULL, &request, nullptr); + ASSERT_EQ(result != 0, TRUE); + + result = demoApi->SAMGR_SendRequestProxy(&feature->identity, nullptr, nullptr); + ASSERT_EQ(result != 0, TRUE); + + free(request.data); + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendRequest_0060 + * @tc.name : Samgr will not check the matching relationship between len and data + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(SendRequestTest, testSendRequest0060, TestSize.Level2) { + DemoApi *demoApi = GetIUnknown("serviceName501", "featureName502"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + Request request = {.msgId = MSG_NO, + .len = 0, + .data = nullptr, + .msgValue = 0}; + char *body = (char*)"I wanna async call good result!"; + request.len = 0; + request.data = malloc(strlen(body) + 1); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, strlen(body) + 1, body); + if (error != EOK) { + ADD_FAILURE(); + } + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName501", "featureName503"); + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + + int32 result = demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, nullptr); + free(request.data); + ASSERT_EQ(result == 0, TRUE); + + Request request2 = {.msgId = MSG_NO, + .len = 0, + .data = nullptr, + .msgValue = 0}; + request2.len = (uint32_t)(strlen(body) + 1); + request2.data = malloc(request2.len); + if (request2.data == nullptr) { + ADD_FAILURE(); + } + error = strcpy_s((char *)request2.data, request2.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + + result = demoApi->SAMGR_SendRequestProxy(&feature->identity, &request2, nullptr); + ASSERT_EQ(result == 0, TRUE); + + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendRequest_0070 + * @tc.name : Feature send an asynchronous message and register handler then can receive response + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(SendRequestTest, testSendRequest0070, TestSize.Level2) { + DemoApi *demoApi = GetIUnknown("serviceName501", "featureName502"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + Request request = {.msgId = MSG_RT, + .len = 0, + .data = nullptr, + .msgValue = 0}; + char *body = (char*)"I wanna async call good result!"; + request.len = strlen(body) + 1; + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName501", "featureName503"); + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + + int32 result = demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, DemoHandlerAndCheck); + + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(result, 0); + ASSERT_EQ(strcmp(feature->latestRequest, body), 0); + + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendRequest_0080 + * @tc.name : Feature send an asynchronous message repeatedly, no memory leak + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(SendRequestTest, testSendRequest0080, TestSize.Level2) { + for (int i = 0; i < PRESSURE_L0; i++) { + DemoApi *demoApi = GetIUnknown("serviceName501", "featureName502"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + Request request = {.msgId = MSG_RT, + .len = 0, + .data = nullptr, + .msgValue = 0}; + char *body = (char*)"I wanna async call good result!"; + request.len = strlen(body) + 1; + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName501", "featureName503"); + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + + int32 result = demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, DemoHandlerAndCheck); + ASSERT_EQ(result, 0); + + usleep(OPER_INTERVAL); + ASSERT_EQ(strcmp(feature->latestRequest, body), 0); + + ReleaseIUnknown(demoApi); + } +} + +/** + * @tc.number : DMSLite_SAMGR_SendRequest_0090 + * @tc.name : Feature send an asynchronous message with 0 len repeatedly, no memory leak + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(SendRequestTest, testSendRequest0090, TestSize.Level2) { + for (int i = 0; i < PRESSURE_L0; i++) { + DemoApi *demoApi = GetIUnknown("serviceName501", "featureName502"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + Request request = {.msgId = MSG_RT, + .len = 0, + .data = nullptr, + .msgValue = 0}; + char body[]= "I wanna async call good result!"; + request.len = 0; + request.data = body; + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName501", "featureName503"); + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + + int32 result = demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, DemoHandlerAndCheck); + ASSERT_EQ(result, 0); + + usleep(OPER_INTERVAL); + ASSERT_EQ(strcmp(feature->latestRequest, body), 0); + + ReleaseIUnknown(demoApi); + } +} \ No newline at end of file diff --git a/distributedschedule_lite/samgr_posix/src/SendResponseTest.cpp b/distributedschedule_lite/samgr_posix/src/SendResponseTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..98548cf542db2e9c5873c3e8f096817eabad0c63 --- /dev/null +++ b/distributedschedule_lite/samgr_posix/src/SendResponseTest.cpp @@ -0,0 +1,548 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "utils/SamgrTestBase.h" + +using namespace testing::ext; + +enum MessageId { + MSG_NO = 1, // receiver does not send response + MSG_RT = 2, // receiver send response + MSG_FW = 3, // receiver forward message + MSG_RT_MULTI = 4, // receiver send response +}; + +struct Payload { + int id; + const char *name; + int value; +}; + +struct DemoApi { + INHERIT_IUNKNOWN; + int32 (*SAMGR_SendRequestProxy)(const Identity *identity, const Request *request, Handler handler); +}; + +struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoApi); + Identity identity; + int featureCalledCount; + BOOL featureStatus; +}; + +struct DefaultFeatureApi { + INHERIT_IUNKNOWN; +}; + +struct ExampleService { + INHERIT_SERVICE; + INHERIT_IUNKNOWNENTRY(DefaultFeatureApi); + Identity identity; +}; + +static int32 SAMGR_SendRequestProxy(const Identity *identity, const Request *request, Handler handler) +{ + return SAMGR_SendRequest(identity, request, handler); +} + +static const char *GetName(Service *service) +{ + (void)service; + return "serviceName601"; +} + +static BOOL Initialize(Service *service, Identity identity) +{ + ExampleService *example = (ExampleService *)service; + example->identity = identity; + + printf("[hcpptest]serviceName %s Initialize \n", service->GetName(service)); + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)service; + (void)msg; + return FALSE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + (void)service; + TaskConfig config = {LEVEL_HIGH, PRI_ABOVE_NORMAL, 0x800, 20, SHARED_TASK}; // share with broadcast + return config; +} + +static ExampleService g_service = { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ver = 0x20, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + } +}; + +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return "featureName601"; +} + +static const char *FEATURE_GetName02(Feature *feature) +{ + (void)feature; + return "featureName602"; +} + +static const char *FEATURE_GetName03(Feature *feature) +{ + (void)feature; + return "featureName603"; +} + +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; + + (void)parent; +} + +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *request) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + demoFeature->featureStatus = TRUE; + + return TRUE; +} + +static BOOL FEATURE_OnMessage02(Feature *feature, Request *request) +{ + int32 returnCode; + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + + switch (request->msgId) { + case MSG_NO: + returnCode = 0; + break; + case MSG_RT: + { + char *dataR = (char*)"Yes, you did!"; + Response response = { + .data = dataR, + .len = 0, + }; + returnCode = SAMGR_SendResponse(request, &response); + }; + break; + case MSG_FW: + { + char *dataR = (char*)"Yes, you did!"; + Response response = { + .data = dataR, + .len = 0, + }; + request->msgId = MSG_NO; + IUnknown *iUnknownX = SAMGR_GetInstance()->GetFeatureApi("serviceName601", "featureName602"); + DemoFeature *featureX = GET_OBJECT(iUnknownX, DemoFeature, iUnknown); + returnCode = SAMGR_SendResponseByIdentity(&featureX->identity, request, &response); + }; + break; + } + demoFeature->featureStatus = ((returnCode == 0) ? TRUE : FALSE); + return demoFeature->featureStatus; +} + +static BOOL FEATURE_OnMessage03(Feature *feature, Request *request) +{ + int32 returnCode = 0; + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + + switch (request->msgId) { + case MSG_NO: + returnCode = 0; + break; + case MSG_RT: + { + char *dataR = (char*)"Yes, you did!"; + Response response = { + .data = dataR, + .len = 0, + }; + returnCode = SAMGR_SendResponse(request, &response); + }; + break; + case MSG_FW: + { + char *dataR = (char*)"Yes, you did!"; + Response response = { + .data = dataR, + .len = 0, + }; + request->msgId = MSG_NO; + IUnknown *iUnknownX = SAMGR_GetInstance()->GetFeatureApi("serviceName601", "featureName602"); + DemoFeature *featureX = GET_OBJECT(iUnknownX, DemoFeature, iUnknown); + returnCode = SAMGR_SendResponseByIdentity(&featureX->identity, request, &response); + }; + break; + case MSG_RT_MULTI: + { + Response response = { + .data = (char*)"Yes, you did!", + .len = 0, + }; + for (int i = 0; i < PRESSURE_L0; i++) { + int tempCode = SAMGR_SendResponse(request, &response); + if (tempCode != 0) { + printf("[hctest]E failed to SendResponse occurs: %d rt: %d \n", i, tempCode); + returnCode++; + } + } + } + } + demoFeature->featureStatus = ((returnCode == 0) ? TRUE : FALSE); + return demoFeature->featureStatus; +} + +static DemoFeature g_feature = { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ver = 0x20, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .SAMGR_SendRequestProxy = SAMGR_SendRequestProxy, + }, + .identity = {-1, -1, nullptr}, + .featureCalledCount = 0, + .featureStatus = TRUE, +}; +static DemoFeature g_feature02 = { + .GetName = FEATURE_GetName02, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage02, + .ver = 0x20, + .ref = 0, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .SAMGR_SendRequestProxy = SAMGR_SendRequestProxy, + }, + .identity = {-1, 1, nullptr}, + .featureCalledCount = 0, + .featureStatus = TRUE, +}; +static DemoFeature g_feature03 = { + .GetName = FEATURE_GetName03, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage03, + .ver = 0x20, + .ref = 0, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .SAMGR_SendRequestProxy = SAMGR_SendRequestProxy, + }, + .identity = {-1, 2, nullptr}, + .featureCalledCount = 0, + .featureStatus = TRUE, +}; + +static void GServiceInit(void) +{ + printf("[hcpptest]ServiceInit! \n"); + SAMGR_GetInstance()->RegisterService((Service *)&g_service); +} +SYSEX_SERVICE_INIT(GServiceInit); + +static void GFeatureInit(void) +{ + printf("[hcpptest]FeatureInit! \n"); + SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName601", GET_IUNKNOWN(g_feature)); + + SAMGR_GetInstance()->RegisterFeature("serviceName601", (Feature *)&g_feature02); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName601", "featureName602", GET_IUNKNOWN(g_feature02)); + + SAMGR_GetInstance()->RegisterFeature("serviceName601", (Feature *)&g_feature03); + SAMGR_GetInstance()->RegisterFeatureApi("serviceName601", "featureName603", GET_IUNKNOWN(g_feature03)); +} +SYSEX_FEATURE_INIT(GFeatureInit); + +static DemoApi *GetIUnknown(const char *serviceName, const char *featureName) +{ + DemoApi *demoApi = nullptr; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(serviceName, featureName); + if (iUnknown == nullptr) { + return nullptr; + } + int result = iUnknown->QueryInterface(iUnknown, 0x20, (void **)&demoApi); + if (result == 0 && demoApi != nullptr) { + return demoApi; + } else { + return nullptr; + } +} + +static void ReleaseIUnknown(DemoApi *demoApi) +{ + demoApi->Release((IUnknown *)demoApi); +} + +static void DemoHandler(const Request *request, const Response *response) +{ + (void)request; + (void)response; +} + +static void DemoHandlerAndCheck(const Request *request, const Response *response) +{ + char *requestData = (char*)"I wanna async call good result!"; + ASSERT_EQ(strcmp((char *)request->data, requestData), 0); + + char *responseData = (char*)"Yes, you did!"; + ASSERT_EQ(strcmp((char *)response->data, responseData), 0); +} + +static void DemoHandlerAndCheck2(const Request *request, const Response *response) +{ + ASSERT_EQ(request->data != nullptr, TRUE); + ASSERT_EQ(response->data != nullptr, TRUE); +} + +class SendResponseTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** + * @tc.number : DMSLite_SAMGR_SendResponse_0010 + * @tc.name : Receiver send response successfully + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(SendResponseTest, testSendResponse0010, TestSize.Level2) { + DemoApi *demoApi = GetIUnknown("serviceName601", "featureName602"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + Request request = {.msgId = MSG_RT, + .len = 0, + .data = nullptr, + .msgValue = 0}; + char *body = (char*)"I wanna async call good result!"; + request.len = strlen(body) + 1; + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName601", "featureName603"); + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, DemoHandlerAndCheck); + + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(feature->featureStatus, TRUE); + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendResponse_0020 + * @tc.name : Receiver can not send response if sender has not register callback + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(SendResponseTest, testSendResponse0020, TestSize.Level2) { + DemoApi *demoApi = GetIUnknown("serviceName601", "featureName602"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + Request request = {.msgId = MSG_RT, + .len = 0, + .data = nullptr, + .msgValue = 0}; + char *body = (char*)"I wanna async call good result!"; + request.len = strlen(body) + 1; + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName601", "featureName603"); + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, nullptr); + + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(feature->featureStatus == FALSE, TRUE); + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendResponse_0030 + * @tc.name : Receiver send response to itself successfully + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(SendResponseTest, testSendResponse0030, TestSize.Level2) { + DemoApi *demoApi = GetIUnknown("serviceName601", "featureName603"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + Request request = {.msgId = MSG_RT, + .len = 0, + .data = nullptr, + .msgValue = 0}; + char *body = (char*)"I wanna async call good result!"; + request.len = strlen(body) + 1; + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName601", "featureName603"); + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, DemoHandler); + + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(feature->featureStatus == TRUE, TRUE); + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendResponse_0040 + * @tc.name : Receiver send response to the origin feature repeatedly + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(SendResponseTest, testSendResponse0040, TestSize.Level2) { + DemoApi *demoApi = GetIUnknown("serviceName601", "featureName602"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + Request request = {.msgId = MSG_RT_MULTI, + .len = 0, + .data = nullptr, + .msgValue = 0}; + char *body = (char*)"I wanna async call good result!"; + request.len = strlen(body) + 1; + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName601", "featureName603"); + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, DemoHandler); + + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(feature->featureStatus == TRUE, TRUE); + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendResponseByIdentity_0020 + * @tc.name : Receiver can not forward message if the sender has not registered handler + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(SendResponseTest, testSendResponseByIdentity0020, TestSize.Level2) { + DemoApi *demoApi = GetIUnknown("serviceName601", "featureName602"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + Request request = {.msgId = MSG_FW, + .len = 0, + .data = nullptr, + .msgValue = 0}; + char *body = (char*)"I wanna async call good result!"; + request.len = strlen(body) + 1; + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName601", "featureName603"); + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + + demoApi->SAMGR_SendRequestProxy(&feature->identity, &request, nullptr); + + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(feature->featureStatus == FALSE, TRUE); + + ReleaseIUnknown(demoApi); +} \ No newline at end of file diff --git a/distributedschedule_lite/samgr_posix/src/SendShareRequestTest.cpp b/distributedschedule_lite/samgr_posix/src/SendShareRequestTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..278e8bc3876137b6e95d60d497260f40cc8b2a92 --- /dev/null +++ b/distributedschedule_lite/samgr_posix/src/SendShareRequestTest.cpp @@ -0,0 +1,445 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "utils/SamgrTestBase.h" + +using namespace testing::ext; + +enum MessageId { + MSG_NO, // receiver does not send response + MSG_RT, // receiver send response + MSG_FW, // receiver forward message +}; + +struct Payload { + int id; + const char *name; + int value; +}; + +struct DemoApi { + INHERIT_IUNKNOWN; + uint32 *(*SAMGR_SendSharedRequestProxy)(const Identity *identity, const Request *request, uint32 *token, + Handler handler); + int32 (*SAMGR_SendSharedDirectRequestProxy)(const Identity *id, const Request *req, const Response *resp, + uint32 **ref, Handler handler); +}; + +struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoApi); + Identity identity; + int featureCalledCount; + BOOL featureStatus; + char *latestRequest; +}; + +struct DefaultFeatureApi { + INHERIT_IUNKNOWN; +}; + +struct ExampleService { + INHERIT_SERVICE; + INHERIT_IUNKNOWNENTRY(DefaultFeatureApi); + Identity identity; +}; + +static uint32 *SAMGR_SendSharedRequestProxy(const Identity *identity, const Request *request, uint32 *token, + Handler handler) +{ + return SAMGR_SendSharedRequest(identity, request, token, handler); +} + +static int32 SAMGR_SendSharedDirectRequestProxy(const Identity *id, const Request *req, const Response *resp, + uint32 **ref, Handler handler) +{ + return SAMGR_SendSharedDirectRequest(id, req, resp, ref, handler); +} + +static const char *GetName(Service *service) +{ + (void)service; + return "S_sendShareReq"; +} + +static BOOL Initialize(Service *service, Identity identity) +{ + ExampleService *example = (ExampleService *)service; + example->identity = identity; + + printf("[hcpptest]serviceName %s Initialize \n", service->GetName(service)); + + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)service; + return FALSE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + (void)service; + TaskConfig config = {LEVEL_HIGH, PRI_ABOVE_NORMAL, 0x800, 20, SHARED_TASK}; + return config; +} + +static ExampleService g_service = { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ver = 0x20, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + } +}; + +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return "feature01"; +} + +static const char *FEATURE_GetName02(Feature *feature) +{ + (void)feature; + return "feature02"; +} + +static const char *FEATURE_GetName03(Feature *feature) +{ + (void)feature; + return "feature03"; +} + +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; + + printf("[hcpptest]featureName %s Initialize \n", feature->GetName(feature)); + (void)parent; +} + +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *request) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + demoFeature->latestRequest = (char *)request->data; + + demoFeature->featureStatus = TRUE; + return TRUE; +} + +static BOOL FEATURE_OnMessage02(Feature *feature, Request *request) +{ + int32 returnCode; + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + demoFeature->latestRequest = (char *)request->data; + + switch (request->msgId) { + case MSG_NO: + returnCode = 0; + break; + case MSG_RT: + { + Response response = { + .data = (char*)"Yes, you did!", + .len = 0, + }; + returnCode = SAMGR_SendResponse(request, &response); + }; + break; + case MSG_FW: + { + returnCode = 0; + }; + break; + } + demoFeature->featureStatus = ((returnCode == 0) ? TRUE : FALSE); + return demoFeature->featureStatus; +} + +static BOOL FEATURE_OnMessage03(Feature *feature, Request *request) +{ + int32 returnCode; + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + demoFeature->latestRequest = (char *)request->data; + + switch (request->msgId) { + case MSG_NO: + returnCode = 0; + break; + case MSG_RT: + { + Response response = { + .data = (char*)"Yes, you did!", + .len = 0, + }; + returnCode = SAMGR_SendResponse(request, &response); + }; + break; + case MSG_FW: + { + returnCode = 0; + }; + break; + } + demoFeature->featureStatus = ((returnCode == 0) ? TRUE : FALSE); + return demoFeature->featureStatus; +} + +static DemoFeature g_feature = { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ver = 0x20, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .SAMGR_SendSharedRequestProxy = SAMGR_SendSharedRequestProxy, + .SAMGR_SendSharedDirectRequestProxy = SAMGR_SendSharedDirectRequestProxy, + }, + .identity = {-1, -1, nullptr}, + .featureCalledCount = 0, + .featureStatus = TRUE, + .latestRequest = nullptr, +}; +static DemoFeature g_feature02 = { + .GetName = FEATURE_GetName02, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage02, + .ver = 0x20, + .ref = 0, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .SAMGR_SendSharedRequestProxy = SAMGR_SendSharedRequestProxy, + .SAMGR_SendSharedDirectRequestProxy = SAMGR_SendSharedDirectRequestProxy, + }, + .identity = {-1, 1, nullptr}, + .featureCalledCount = 0, + .featureStatus = TRUE, + .latestRequest = nullptr, +}; +static DemoFeature g_feature03 = { + .GetName = FEATURE_GetName03, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage03, + .ver = 0x20, + .ref = 0, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .SAMGR_SendSharedRequestProxy = SAMGR_SendSharedRequestProxy, + .SAMGR_SendSharedDirectRequestProxy = SAMGR_SendSharedDirectRequestProxy, + }, + .identity = {-1, 2, nullptr}, + .featureCalledCount = 0, + .featureStatus = TRUE, + .latestRequest = nullptr, +}; + +static void GServiceInit(void) +{ + printf("[hcpptest]GServiceInit start! \n"); + BOOL result = SAMGR_GetInstance()->RegisterService((Service *)&g_service); + if (result == FALSE) { + printf("[hcpptest]E RegisterService failed! \n"); + } +} +SYSEX_SERVICE_INIT(GServiceInit); + +static void GFeatureInit(void) +{ + printf("[hcpptest]GFeatureInit start! \n"); + + BOOL result1 = SAMGR_GetInstance()->RegisterDefaultFeatureApi("S_sendShareReq", GET_IUNKNOWN(g_feature)); + + BOOL result2 = SAMGR_GetInstance()->RegisterFeature("S_sendShareReq", (Feature *)&g_feature02); + BOOL result3 = SAMGR_GetInstance()->RegisterFeatureApi("S_sendShareReq", "feature02", + GET_IUNKNOWN(g_feature02)); + + BOOL result4 = SAMGR_GetInstance()->RegisterFeature("S_sendShareReq", (Feature *)&g_feature03); + BOOL result5 = SAMGR_GetInstance()->RegisterFeatureApi("S_sendShareReq", "feature03", + GET_IUNKNOWN(g_feature03)); + if (result1 == FALSE || result2 == FALSE || result3 == FALSE || result4 == FALSE || result5 == FALSE) { + printf("[hcpptest]E failed to register feature or api! \n"); + } +} +SYSEX_FEATURE_INIT(GFeatureInit); + +static DemoApi *GetIUnknown(const char *serviceName, const char *featureName) +{ + DemoApi *demoApi = nullptr; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(serviceName, featureName); + if (iUnknown == nullptr) { + printf("[hcpptest]failed to GetFeatureApi.\n"); + return nullptr; + } + int result = iUnknown->QueryInterface(iUnknown, 0x20, (void **)&demoApi); + if (result == 0 && demoApi != nullptr) { + return demoApi; + } else { + printf("[hcpptest]failed to QueryInterface.\n"); + return nullptr; + } +} + +static void ReleaseIUnknown(DemoApi *demoApi) +{ + demoApi->Release((IUnknown *)demoApi); +} + +static void DemoHandler(const Request *request, const Response *response) +{ + (void)request; + (void)response; +} + +static void DemoHandlerAndCheck(const Request *request, const Response *response) +{ + char *requestData = (char*)"I wanna async call good result!"; + ASSERT_EQ(strcmp((char *)request->data, requestData), 0); + + char *responseData = (char*)"Yes, you did!"; + ASSERT_EQ(strcmp((char *)response->data, responseData), 0); +} + +class SendShareRequestTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + printf("[hcpptest]SetUpTestCase! \n"); + SystemInitProxy(); + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + usleep(OPER_INTERVAL * MS2US); + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** + * @tc.number : DMSLite_SAMGR_SendSharedRequest_0010 + * @tc.name : Feature sends a response to a specified feature after processing the original request. + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(SendShareRequestTest, testSendSharedRequest0010, TestSize.Level2) { + DemoApi *demoApi = GetIUnknown("S_sendShareReq", "feature02"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + Request request = {.msgId = MSG_RT, + .len = 0, + .data = nullptr, + .msgValue = 0}; + char *body = (char*)"I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + printf("[hcpptest]error failed to strcpy_s \n"); + } + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("S_sendShareReq", "feature03"); + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + + feature->featureCalledCount = 0; + uint32 *token = NULL; + token = demoApi->SAMGR_SendSharedRequestProxy(&feature->identity, &request, token, DemoHandlerAndCheck); + + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(feature->featureCalledCount, 1); + + ReleaseIUnknown(demoApi); +} + +/** + * @tc.number : DMSLite_SAMGR_SendSharedDirectRequest_0010 + * @tc.name : Sends a request and response of a caller to the feature thread + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(SendShareRequestTest, testSendSharedDirectRequest0010, TestSize.Level2) { + DemoApi *demoApi = GetIUnknown("S_sendShareReq", "feature02"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + Request request = {.msgId = MSG_RT, + .len = 0, + .data = nullptr, + .msgValue = 0}; + char *body = (char*)"I wanna async call good result!"; + request.len = (int16)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + printf("[hcpptest]error failed to strcpy_s \n"); + } + + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi("S_sendShareReq", "feature03"); + DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown); + + feature->featureCalledCount = 0; + Response response = { + .data = (char*)"Yes, you did!", + .len = 0, + }; + uint32 *token = NULL; + int32 result = demoApi->SAMGR_SendSharedDirectRequestProxy(&feature->identity, &request, &response, + &token, DemoHandlerAndCheck); + ASSERT_EQ(result, 0); + + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(feature->featureCalledCount, 0); + + ReleaseIUnknown(demoApi); +} \ No newline at end of file diff --git a/distributedschedule_lite/samgr_posix/src/ServiceTest.cpp b/distributedschedule_lite/samgr_posix/src/ServiceTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..2729d3929d7343eb0369b8f482c44573f59e3779 --- /dev/null +++ b/distributedschedule_lite/samgr_posix/src/ServiceTest.cpp @@ -0,0 +1,295 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include "utils/SamgrTestBase.h" + +using namespace testing::ext; + +struct DefaultFeatureApi { + INHERIT_IUNKNOWN; +}; + +struct ExampleService { + INHERIT_SERVICE; + INHERIT_IUNKNOWNENTRY(DefaultFeatureApi); + Identity identity; +}; + +struct DemoApi { + INHERIT_IUNKNOWN; +}; + +struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoApi); + Identity identity; +}; + +static const char *GetName(Service *service) +{ + (void)service; + return "serviceName101"; +} + +static BOOL Initialize(Service *service, Identity identity) +{ + printf("[hcpptest]Initialize. \n"); + ExampleService *example = (ExampleService *)service; + example->identity = identity; + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)service; + return FALSE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + (void)service; + TaskConfig config = {LEVEL_HIGH, PRI_ABOVE_NORMAL, 0x800, 20, SHARED_TASK}; + return config; +} + +static ExampleService g_service = { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ver = 1, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + }, +}; + +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return "featureName101"; +} +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; + (void)parent; +} +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *request) +{ + (void)feature; + (void)request; + return TRUE; +} + +static DemoFeature g_feature = { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ver = DEFAULT_VERSION, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + }, + .identity = {-1, -1, NULL}, +}; + +class ServiceTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + SystemInitProxy(); + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** + * @tc.number : DMSLite_SAMGR_RegisterService_0010 + * @tc.name : Valid service can be registered + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 +*/ +HWTEST_F(ServiceTest, testRegisterService0010, TestSize.Level1) { + BOOL result = SAMGR_GetInstance()->RegisterService((Service *)&g_service); + ASSERT_EQ(result, TRUE); + + SAMGR_GetInstance()->UnregisterService("serviceName101"); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterService_0020 + * @tc.name : Service which is nullptr failed to register + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(ServiceTest, testRegisterService0020, TestSize.Level2) { + BOOL result = SAMGR_GetInstance()->RegisterService(NULL); + ASSERT_EQ(result, FALSE); +} + +/** + * @tc.number : DMSLite_SAMGR_RegisterService_0030 + * @tc.name : Service which already exist in samgr failed to register + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(ServiceTest, testRegisterService0030, TestSize.Level2) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + BOOL result = SAMGR_GetInstance()->RegisterService((Service *)&g_service); + ASSERT_EQ(result, FALSE); + SAMGR_GetInstance()->UnregisterService("serviceName101"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterService_0010 + * @tc.name : Service can be unregistered + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(ServiceTest, testUnregisterService0010, TestSize.Level2) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + Service *resultService = SAMGR_GetInstance()->UnregisterService("serviceName101"); + ASSERT_EQ(strcmp(resultService->GetName(resultService), "serviceName101"), 0); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterService_0020 + * @tc.name : Service which contains NULL failed to unregister + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(ServiceTest, testUnregisterService0020, TestSize.Level2) { + Service *resultService = SAMGR_GetInstance()->UnregisterService(NULL); + ASSERT_EQ(resultService == nullptr, TRUE); + + resultService = SAMGR_GetInstance()->UnregisterService(""); + ASSERT_EQ(resultService == nullptr, TRUE); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterService_0030 + * @tc.name : Service which does not exist in samgr failed to unregister + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(ServiceTest, testUnregisterService0030, TestSize.Level2) { + Service *resultService = SAMGR_GetInstance()->UnregisterService("noExistServiceName"); + ASSERT_EQ(resultService == nullptr, TRUE); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterService_0040 + * @tc.name : Service which contains api failed to unregister + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(ServiceTest, testUnregisterService0040, TestSize.Level2) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterDefaultFeatureApi("serviceName101", GET_IUNKNOWN(g_service)); + + Service *resultService = SAMGR_GetInstance()->UnregisterService("serviceName101"); + ASSERT_EQ(resultService == nullptr, TRUE); + + SAMGR_GetInstance()->UnregisterDefaultFeatureApi("serviceName101"); + SAMGR_GetInstance()->UnregisterService("serviceName101"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterService_0050 + * @tc.name : Service which contains feature failed to unregister + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(ServiceTest, testUnregisterService0050, TestSize.Level2) { + SAMGR_GetInstance()->RegisterService((Service *)&g_service); + SAMGR_GetInstance()->RegisterFeature("serviceName101", (Feature *)&g_feature); + + Service *resultService = SAMGR_GetInstance()->UnregisterService("serviceName101"); + ASSERT_EQ(resultService == nullptr, TRUE); + + SAMGR_GetInstance()->UnregisterFeature("serviceName101", "featureName101"); + SAMGR_GetInstance()->UnregisterService("serviceName101"); +} + +/** + * @tc.number : DMSLite_SAMGR_UnregisterService_0060 + * @tc.name : Register and unregister service repeatedly, no memory leak + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(ServiceTest, testUnregisterService0060, TestSize.Level2) { + // RegisterService and unregister service over and over again, if there is memory leak samgr will crash + for (int i = 0; i < PRESSURE_BASE; i++) { + BOOL result = SAMGR_GetInstance()->RegisterService((Service *)&g_service); + ASSERT_EQ(result, TRUE); + + Service *resultService = SAMGR_GetInstance()->UnregisterService("serviceName101"); + ASSERT_EQ(resultService != nullptr, TRUE); + } +} + +/** + * @tc.number : DMSLite_SAMGR_Bootstrap_0010 + * @tc.name : Restart SAMGR service function is normal. + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(ServiceTest, testBootstrap0010, TestSize.Level2) { + SAMGR_Bootstrap(); + usleep(OPER_INTERVAL); + + SamgrLite *samgrLite = SAMGR_GetInstance(); + ASSERT_EQ(samgrLite != nullptr, TRUE); +} \ No newline at end of file diff --git a/distributedschedule_lite/samgr_posix/src/TaskpoolNoTaskTest.cpp b/distributedschedule_lite/samgr_posix/src/TaskpoolNoTaskTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..13d8a4c364f807069e47364ea24df39d215ef0fc --- /dev/null +++ b/distributedschedule_lite/samgr_posix/src/TaskpoolNoTaskTest.cpp @@ -0,0 +1,248 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "utils/SamgrTestBase.h" + + +using namespace testing::ext; + +struct DemoApi { + INHERIT_IUNKNOWN; + BOOL (*FeatureApi001)(IUnknown *iUnknown, char *para1); +}; + +struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoApi); + Identity identity; +}; + +struct DefaultFeatureApi { + INHERIT_IUNKNOWN; + BOOL (*DefaultApi001)(IUnknown *iUnknown, char *para1); +}; + +struct DemoService { + INHERIT_SERVICE; + INHERIT_IUNKNOWNENTRY(DefaultFeatureApi); + Identity identity; +}; + +static BOOL DefaultApi001(IUnknown *iUnknown, char *para1) +{ + (void)iUnknown; + return TRUE; +} + +static BOOL FeatureApi001(IUnknown *iUnknown, char *para1) +{ + (void)iUnknown; + return TRUE; +} + +static const char *GetName(Service *service) +{ + (void)service; + return "Service_NoTask"; +} + +static BOOL Initialize(Service *service, Identity identity) +{ + DemoService *demoService = (DemoService *)service; + demoService->identity = identity; + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + (void)service; + (void)msg; + return FALSE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + (void)service; + TaskConfig config = {LEVEL_HIGH, PRI_ABOVE_NORMAL, 0x800, 20, NO_TASK}; + return config; +} + +static DemoService g_createService = { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ver = 0x20, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .DefaultApi001 = DefaultApi001, + } +}; + +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return "featureName501"; +} + +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; + (void)parent; +} + +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *request) +{ + (void)feature; + char *dataR = (char*)"Yes, you did!"; + Response response = { + .data = dataR, + .len = 0, + }; + SAMGR_SendResponse(request, &response); + return TRUE; +} + +static DemoFeature g_createFeature = { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ver = 0x20, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .FeatureApi001 = FeatureApi001, + }, + .identity = {-1, -1, nullptr}, +}; + +static void GServiceInit(void) +{ + BOOL result = SAMGR_GetInstance()->RegisterService((Service *)&g_createService); + if (result != TRUE) { + printf("[hcpptest]error RegisterService failed"); + } +} +SYSEX_SERVICE_INIT(GServiceInit); + +static void GFeatureInit(void) +{ + BOOL result1 = SAMGR_GetInstance()->RegisterDefaultFeatureApi("Service_NoTask", + GET_IUNKNOWN(g_createService)); + BOOL result2 = SAMGR_GetInstance()->RegisterFeature("Service_NoTask", (Feature *)&g_createFeature); + BOOL result3 = SAMGR_GetInstance()->RegisterFeatureApi("Service_NoTask", "featureName501", + GET_IUNKNOWN(g_createFeature)); + if (result1 != TRUE || result2 != TRUE || result3 != TRUE) { + printf("[hcpptest]error register feature or api fail <%d, %d, %d> \n", result1, result2, result3); + } +} +SYSEX_FEATURE_INIT(GFeatureInit); + +static DemoApi *GetIUnknown(const char *serviceName, const char *featureName) +{ + DemoApi *demoApi = nullptr; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(serviceName, featureName); + if (iUnknown == nullptr) { + return nullptr; + } + int result = iUnknown->QueryInterface(iUnknown, 0x20, (void **)&demoApi); + if (result == 0 && demoApi != nullptr) { + return demoApi; + } else { + return nullptr; + } +} + +static DefaultFeatureApi *GetDefaultIUnknown(const char *serviceName) +{ + DefaultFeatureApi *defaultApi = nullptr; + IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(serviceName); + if (iUnknown == nullptr) { + return nullptr; + } + int result = iUnknown->QueryInterface(iUnknown, 0x20, (void **)&defaultApi); + if (result == 0 && defaultApi != nullptr) { + return defaultApi; + } else { + return nullptr; + } +} + +static void ReleaseIUnknown(DemoApi *demoApi) +{ + demoApi->Release((IUnknown *)demoApi); +} + +class TaskpoolNoTaskTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + printf("[hcpptest]SetUpTestCase ! \n"); + SystemInitProxy(); + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + usleep(OPER_INTERVAL * MS2US); + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** + * @tc.number : DMSLite_SAMGR_Taskpool_NoTask_0010 + * @tc.name : Service without task can handle direct calls + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(TaskpoolNoTaskTest, testNoTask0010, TestSize.Level2) +{ + DemoApi *demoApi = GetIUnknown("Service_NoTask", "featureName501"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + + BOOL result = demoApi->FeatureApi001((IUnknown *)demoApi, (char*)"xxxx"); + ASSERT_EQ(result, TRUE); + ReleaseIUnknown(demoApi); + + DefaultFeatureApi *defaultApi = GetDefaultIUnknown("Service_NoTask"); + if (defaultApi == nullptr) { + ADD_FAILURE(); + } + result = defaultApi->DefaultApi001((IUnknown *)defaultApi, (char*)"yyyy"); + ASSERT_EQ(result, TRUE); +}; \ No newline at end of file diff --git a/distributedschedule_lite/samgr_posix/src/TaskpoolSharedTaskTest.cpp b/distributedschedule_lite/samgr_posix/src/TaskpoolSharedTaskTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..7d6ca9aa33a9da84f73477ec90b2efc060dcbd01 --- /dev/null +++ b/distributedschedule_lite/samgr_posix/src/TaskpoolSharedTaskTest.cpp @@ -0,0 +1,516 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "utils/SamgrTestBase.h" + +const int MS1000 = 1000; // 1000ms +const int TARGET_NUM = 2; + +using namespace testing::ext; + +static const char *GetName(Service *service); +static BOOL Initialize(Service *service, Identity identity); +static BOOL MessageHandle(Service *service, Request *msg); +static TaskConfig GetTaskConfig(Service *service); + +static const char *FEATURE_GetName(Feature *feature); +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity); +static void FEATURE_OnStop(Feature *feature, Identity identity); +static BOOL FEATURE_OnMessage(Feature *feature, Request *request); + +static pthread_t g_threadID11; // for the first service threadID +static pthread_t g_threadID12; // for the first feature threadID +static pthread_t g_threadID21; // for the second service threadID +static pthread_t g_threadID22; // for the second feature threadID + +struct DemoApi { + INHERIT_IUNKNOWN; + BOOL(*FeatureApi001) + (IUnknown *iUnknown, char *para1); + int32 (*SendRequestProxyF)(const Identity *identity, const Request *request, Handler handler); +}; + +struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoApi); + Identity identity; + int featureCalledCount; +}; + +struct DefaultFeatureApi { + INHERIT_IUNKNOWN; + BOOL(*DefaultApi001) + (IUnknown *iUnknown, char *para1); + int32 (*SendRequestProxyDF)(const Identity *identity, const Request *request, Handler handler); +}; + +struct DemoService { + INHERIT_SERVICE; + INHERIT_IUNKNOWNENTRY(DefaultFeatureApi); + Identity identity; + int serviceCalledCount; +}; + +static BOOL DefaultApi001(IUnknown *iUnknown, char *para1) +{ + (void)iUnknown; + return TRUE; +} +static int32 SendRequestProxyDF(const Identity *identity, const Request *request, Handler handler) +{ + return SAMGR_SendRequest(identity, request, handler); +} + +static BOOL FeatureApi001(IUnknown *iUnknown, char *para1) +{ + (void)iUnknown; + return TRUE; +} +static int32 SendRequestProxyF(const Identity *identity, const Request *request, Handler handler) +{ + return SAMGR_SendRequest(identity, request, handler); +} + +static DemoService g_createService[] = { + { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ver = 0x20, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .DefaultApi001 = DefaultApi001, + .SendRequestProxyDF = SendRequestProxyDF, + }, + .identity = {-1, -1, nullptr}, + .serviceCalledCount = 0, + }, + { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ver = 0x20, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .DefaultApi001 = DefaultApi001, + .SendRequestProxyDF = SendRequestProxyDF, + }, + .identity = {-1, -1, nullptr}, + .serviceCalledCount = 0, + } +}; + +static const char *GetName(Service *service) +{ + if (service == (Service *)&g_createService[0]) { + return "SharedTask01"; + } else { + return "SharedTask02"; + } +} + +static BOOL Initialize(Service *service, Identity identity) +{ + DemoService *demoService = (DemoService *)service; + demoService->identity = identity; + + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + DemoService *demoService = (DemoService *)service; + demoService->serviceCalledCount++; + if (service == (Service *)&g_createService[0]) { + g_threadID11 = pthread_self(); + } else { + g_threadID21 = pthread_self(); + } + return TRUE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + TaskConfig config = {LEVEL_HIGH, PRI_NORMAL, 1600, 20, SHARED_TASK}; + if (service == (Service *)&g_createService[0]) { + config.priority = PRI_NORMAL; + } else { + config.priority = PRI_NORMAL + 1; + } + return config; +} + +static DemoFeature g_createFeature[] = { + { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ver = 0x20, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .FeatureApi001 = FeatureApi001, + .SendRequestProxyF = SendRequestProxyF, + }, + .identity = {-1, -1, nullptr}, + .featureCalledCount = 0, + }, + { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ver = 0x20, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .FeatureApi001 = FeatureApi001, + .SendRequestProxyF = SendRequestProxyF, + }, + .identity = {-1, -1, nullptr}, + .featureCalledCount = 0, + }, +}; + +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return "featureName501"; +} + +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; +} + +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *request) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + + printf("[hctest]FEATURE_OnMessage request msgId is %d \n", request->msgId); + if (feature == (Feature *)&g_createFeature[0]) { + g_threadID12 = pthread_self(); + } else { + g_threadID22 = pthread_self(); + } + return TRUE; +} + +static void GServiceInit(void) +{ + for (int i = 0; i < TARGET_NUM; i++) { + SAMGR_GetInstance()->RegisterService((Service *)&g_createService[i]); + } +} +SYS_SERVICE_INIT(GServiceInit); + +static void GFeatureInit(void) +{ + for (int i = 0; i < TARGET_NUM; i++) { + SAMGR_GetInstance()->RegisterDefaultFeatureApi(g_createService[i].GetName((Service *)&g_createService[i]), + GET_IUNKNOWN(g_createService[i])); + + SAMGR_GetInstance()->RegisterFeature(g_createService[i].GetName((Service *)&g_createService[i]), + (Feature *)&g_createFeature[i]); + SAMGR_GetInstance()->RegisterFeatureApi(g_createService[i].GetName((Service *)&g_createService[i]), + "featureName501", GET_IUNKNOWN(g_createFeature[i])); + } +} +SYS_FEATURE_INIT(GFeatureInit); + +static DemoApi *GetIUnknown(const char *serviceName, const char *featureName) +{ + DemoApi *demoApi = nullptr; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(serviceName, featureName); + if (iUnknown == nullptr) { + return nullptr; + } + int result = iUnknown->QueryInterface(iUnknown, 0x20, (void **)&demoApi); + if (result == 0 && demoApi != nullptr) { + return demoApi; + } else { + return nullptr; + } +} + +static DefaultFeatureApi *GetDefaultIUnknown(const char *serviceName) +{ + DefaultFeatureApi *defaultApi = nullptr; + IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(serviceName); + if (iUnknown == nullptr) { + return nullptr; + } + int result = iUnknown->QueryInterface(iUnknown, 0x20, (void **)&defaultApi); + if (result == 0 && defaultApi != nullptr) { + return defaultApi; + } else { + return nullptr; + } +} + +static void ReleaseIUnknown(DemoApi *demoApi) +{ + demoApi->Release((IUnknown *)demoApi); +} + +class TaskpoolSharedTaskTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + printf("[hcpptest]SetUpTestCase ! \n"); + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + usleep(OPER_INTERVAL * MS2US); + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** + * @tc.number : SUB_DSS_samgrLite_taskpool_0010 + * @tc.name : the first task function is ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(TaskpoolSharedTaskTest, testTaskPool0010, TestSize.Level2) +{ + DemoApi *demoApi = GetIUnknown("SharedTask01", "featureName501"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + BOOL result = demoApi->FeatureApi001((IUnknown *)demoApi, (char*)"xxxx"); + ASSERT_EQ(result, TRUE); + + g_createFeature[0].featureCalledCount = 0; + Request request = {.msgId = 0, .len = 0, .data = nullptr, .msgValue = 0}; + char *body = (char*)"I wanna async call good result!"; + request.len = (uint32_t)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + int32 result2 = demoApi->SendRequestProxyF(&(g_createFeature[0].identity), &request, nullptr); + ASSERT_EQ(result2 == 0, TRUE); + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(g_createFeature[0].featureCalledCount == 1, TRUE); + + DefaultFeatureApi *defaultApi = GetDefaultIUnknown("SharedTask01"); + if (defaultApi == nullptr) { + ADD_FAILURE(); + } + result = defaultApi->DefaultApi001((IUnknown *)defaultApi, (char*)"yyyy"); + ASSERT_EQ(result, TRUE); + + g_createService[0].serviceCalledCount = 0; + Request request2 = {.msgId = 0, .len = 0, .data = nullptr, .msgValue = 0}; + char *body2 = (char*)"I want to call defaultFeature!"; + request2.len = (uint32_t)(strlen(body2) + 1); + request2.data = malloc(request2.len); + if (request2.data == nullptr) { + ADD_FAILURE(); + } + error = strcpy_s((char *)request2.data, request2.len, body2); + if (error != EOK) { + ADD_FAILURE(); + } + result2 = defaultApi->SendRequestProxyDF(&(g_createService[0].identity), &request2, nullptr); + ASSERT_EQ(result2 == 0, TRUE); + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(g_createService[0].serviceCalledCount == 1, TRUE); +}; + +/** + * @tc.number : SUB_DSS_samgrLite_taskpool_0020 + * @tc.name : the second task function is ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(TaskpoolSharedTaskTest, testTaskPool0020, TestSize.Level2) +{ + DemoApi *demoApi = GetIUnknown("SharedTask02", "featureName501"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + BOOL result = demoApi->FeatureApi001((IUnknown *)demoApi, (char*)"xxxx"); + ASSERT_EQ(result, TRUE); + + g_createFeature[1].featureCalledCount = 0; + Request request = {.msgId = 0, .len = 0, .data = nullptr, .msgValue = 0}; + char *body = (char*)"I wanna async call good result!"; + request.len = (uint32_t)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + int32 result2 = demoApi->SendRequestProxyF(&(g_createFeature[1].identity), &request, nullptr); + ASSERT_EQ(result2 == 0, TRUE); + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(g_createFeature[1].featureCalledCount == 1, TRUE); + + DefaultFeatureApi *defaultApi = GetDefaultIUnknown("SharedTask02"); + if (defaultApi == nullptr) { + ADD_FAILURE(); + } + result = defaultApi->DefaultApi001((IUnknown *)defaultApi, (char*)"yyyy"); + ASSERT_EQ(result, TRUE); + + g_createService[1].serviceCalledCount = 0; + Request request2 = {.msgId = 0, .len = 0, .data = nullptr, .msgValue = 0}; + char *body2 = (char*)"I want to call defaultFeature!"; + request2.len = (uint32_t)(strlen(body2) + 1); + request2.data = malloc(request2.len); + if (request2.data == nullptr) { + ADD_FAILURE(); + } + error = strcpy_s((char *)request2.data, request2.len, body2); + if (error != EOK) { + ADD_FAILURE(); + } + result2 = defaultApi->SendRequestProxyDF(&(g_createService[1].identity), &request2, nullptr); + ASSERT_EQ(result2 == 0, TRUE); + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(g_createService[1].serviceCalledCount == 1, TRUE); +}; + +/** + * @tc.number : SUB_DSS_samgrLite_taskpool_0030 + * @tc.name : PRI_LOW function is ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(TaskpoolSharedTaskTest, testTaskPool0030, TestSize.Level2) +{ + DefaultFeatureApi *defaultApi = GetDefaultIUnknown("SharedTask01"); + if (defaultApi == nullptr) { + ADD_FAILURE(); + } + Request request = {.msgId = 0, .len = 0, .data = nullptr, .msgValue = 0}; + char *body = (char*)"I want to call defaultFeature!"; + request.len = (uint32_t)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + defaultApi->SendRequestProxyDF(&(g_createService[0].identity), &request, nullptr); + + DefaultFeatureApi *defaultApi2 = GetDefaultIUnknown("SharedTask01"); + if (defaultApi2 == nullptr) { + ADD_FAILURE(); + } + Request request2 = {.msgId = 0, .len = 0, .data = nullptr, .msgValue = 0}; + request2.len = (uint32_t)(strlen(body) + 1); + request2.data = malloc(request2.len); + if (request2.data == nullptr) { + ADD_FAILURE(); + } + error = strcpy_s((char *)request2.data, request2.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + defaultApi2->SendRequestProxyDF(&(g_createService[1].identity), &request2, nullptr); + + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(g_threadID11 == g_threadID21, TRUE); +}; + +/** + * @tc.number : SUB_DSS_samgrLite_taskpool_0040 + * @tc.name : PRI_LOW function is ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(TaskpoolSharedTaskTest, testTaskPool0040, TestSize.Level2) +{ + DemoApi *demoApi = GetIUnknown("SharedTask01", "featureName501"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + Request request1 = {.msgId = 1, .len = 0, .data = nullptr, .msgValue = 0}; + char *body = (char*)"I wanna async call good result!"; + request1.len = (uint32_t)(strlen(body) + 1); + request1.data = malloc(request1.len); + if (request1.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request1.data, request1.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + demoApi->SendRequestProxyF(&(g_createFeature[0].identity), &request1, nullptr); + + DemoApi *demoApi2 = GetIUnknown("SharedTask02", "featureName501"); + if (demoApi2 == nullptr) { + ADD_FAILURE(); + } + Request request2 = {.msgId = 1 + 1, .len = 0, .data = nullptr, .msgValue = 0}; + request2.len = (uint32_t)(strlen(body) + 1); + request2.data = malloc(request2.len); + if (request2.data == nullptr) { + ADD_FAILURE(); + } + error = strcpy_s((char *)request2.data, request2.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + demoApi2->SendRequestProxyF(&(g_createFeature[1].identity), &request2, nullptr); + + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(g_threadID12 == g_threadID22, TRUE); +}; \ No newline at end of file diff --git a/distributedschedule_lite/samgr_posix/src/TaskpoolSingleTaskTest.cpp b/distributedschedule_lite/samgr_posix/src/TaskpoolSingleTaskTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..b539cb19a104d52819d8770f4ee0a4c27238a9e3 --- /dev/null +++ b/distributedschedule_lite/samgr_posix/src/TaskpoolSingleTaskTest.cpp @@ -0,0 +1,618 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "utils/SamgrTestBase.h" + +using namespace testing::ext; + +const int SERVICE_NUM = 4; + +const int INDEX0 = 0; +const int INDEX1 = 1; +const int INDEX2 = 2; +const int INDEX3 = 3; + +static char *g_serviceNameArray[] = { + (char*)"SingleTS01", + (char*)"SingleTS02", + (char*)"SingleTS03", + (char*)"SingleTS04" +}; + +static const char *GetName(Service *service); +static BOOL Initialize(Service *service, Identity identity); +static BOOL MessageHandle(Service *service, Request *msg); +static TaskConfig GetTaskConfig(Service *service); + +static Vector g_nodeVector; +struct Node { + int id; + char *name; +}; +static Node *GetNode(const Node *node) +{ + return const_cast(node); +} +static int CompareNode(const Node *node1, const Node *node2) +{ + if (node1->id < node2->id) { + return -1; + } else if (node1->id == node2->id) { + return 0; + } else { + return 1; + } +} + +struct DemoApi { + INHERIT_IUNKNOWN; + BOOL(*FeatureApi001) + (IUnknown *iUnknown, char *para1); + int32 (*SendRequestProxyF)(const Identity *identity, const Request *request, Handler handler); +}; + +struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoApi); + Identity identity; + int featureCalledCount; +}; + +struct DefaultFeatureApi { + INHERIT_IUNKNOWN; + BOOL(*DefaultApi001) + (IUnknown *iUnknown, char *para1); + int32 (*SendRequestProxyDF)(const Identity *identity, const Request *request, Handler handler); +}; + +struct DemoService { + INHERIT_SERVICE; + INHERIT_IUNKNOWNENTRY(DefaultFeatureApi); + Identity identity; + int serviceCalledCount; +}; + +static BOOL DefaultApi001(IUnknown *iUnknown, char *para1) +{ + (void)iUnknown; + return TRUE; +} +static int32 SendRequestProxyDF(const Identity *identity, const Request *request, Handler handler) +{ + return SAMGR_SendRequest(identity, request, handler); +} + +static BOOL FeatureApi001(IUnknown *iUnknown, char *para1) +{ + (void)iUnknown; + return TRUE; +} +static int32 SendRequestProxyF(const Identity *identity, const Request *request, Handler handler) +{ + return SAMGR_SendRequest(identity, request, handler); +} + +static DemoService g_service[] = { + { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ver = 0x20, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .DefaultApi001 = DefaultApi001, + .SendRequestProxyDF = SendRequestProxyDF, + }, + .identity = {-1, -1, nullptr}, + .serviceCalledCount = 0, + }, + { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ver = 0x20, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .DefaultApi001 = DefaultApi001, + .SendRequestProxyDF = SendRequestProxyDF, + }, + .identity = {-1, -1, nullptr}, + .serviceCalledCount = 0, + }, + { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ver = 0x20, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .DefaultApi001 = DefaultApi001, + .SendRequestProxyDF = SendRequestProxyDF, + }, + .identity = {-1, -1, nullptr}, + .serviceCalledCount = 0, + }, + { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ver = 0x20, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .DefaultApi001 = DefaultApi001, + .SendRequestProxyDF = SendRequestProxyDF, + }, + .identity = {-1, -1, nullptr}, + .serviceCalledCount = 0, + } +}; + +static const char *GetName(Service *service) +{ + if (service == (Service *)&g_service[INDEX0]) { + return g_serviceNameArray[INDEX0]; + } else if (service == (Service *)&g_service[INDEX1]) { + return g_serviceNameArray[INDEX1]; + } else if (service == (Service *)&g_service[INDEX2]) { + return g_serviceNameArray[INDEX2]; + } else { + return g_serviceNameArray[INDEX3]; + } +} + +static int g_initlizationOrder = 0; +static BOOL Initialize(Service *service, Identity identity) +{ + DemoService *demoService = (DemoService *)service; + demoService->identity = identity; + + g_initlizationOrder++; + Node *node = (Node *)malloc(sizeof(Node)); + if (node == nullptr) { + ADD_FAILURE(); + } + node->id = g_initlizationOrder; + node->name = (char *)service->GetName(service); + VECTOR_Add(&g_nodeVector, node); + + printf("[hcpptest]serviceName %s priority %d Initialize \n", service->GetName(service), + service->GetTaskConfig(service).priority); + + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + DemoService *demoService = (DemoService *)service; + demoService->serviceCalledCount++; + return TRUE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + // stackSize: valid stackSize is [1600, 342000), the L0 RAM size is 342000, if stackSize = 800, system will crash + // queueSize: [0, system upper limit), 0: will not create taskpool, the max value depends on RAM size + // priority: PRI_ABOVE_NORMAL PRI_NORMAL PRI_BELOW_NORMAL PRI_LOW + + TaskConfig config = {LEVEL_HIGH, PRI_NORMAL, 1600, 2, SINGLE_TASK}; + if (service == (Service *)&g_service[INDEX0]) { + config.priority = PRI_LOW + 1; + } else if (service == (Service *)&g_service[INDEX1]) { + config.priority = PRI_BELOW_NORMAL; + } else if (service == (Service *)&g_service[INDEX2]) { + config.priority = PRI_NORMAL; + } else { + config.priority = PRI_ABOVE_NORMAL; + } + return config; +} + +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return "featureName501"; +} + +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; +} + +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *request) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + + return TRUE; +} + +static DemoFeature g_feature = { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ver = 0x20, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .FeatureApi001 = FeatureApi001, + .SendRequestProxyF = SendRequestProxyF, + }, + .identity = {-1, -1, nullptr}, + .featureCalledCount = 0, +}; + +static void GServiceInit(void) +{ + for (int i = 0; i < SERVICE_NUM; i++) { + BOOL result = SAMGR_GetInstance()->RegisterService((Service *)&g_service[i]); + if (result == FALSE) { + printf("[hcpptest]E RegisterService failed, occurs: %d\n", i); + } + } +} +SYS_SERVICE_INIT(GServiceInit); + +static void GFeatureInit(void) +{ + for (int i = 0; i < SERVICE_NUM; i++) { + BOOL result1 = SAMGR_GetInstance()->RegisterDefaultFeatureApi(g_service[i].GetName((Service *)&g_service[i]), + GET_IUNKNOWN(g_service[i])); + BOOL result2 = SAMGR_GetInstance()->RegisterFeature(g_service[i].GetName((Service *)&g_service[i]), + (Feature *)&g_feature); + BOOL result3 = SAMGR_GetInstance()->RegisterFeatureApi(g_service[i].GetName((Service *)&g_service[i]), + "featureName501", GET_IUNKNOWN(g_feature)); + if (result1 == FALSE || result2 == FALSE || result3 == FALSE) { + printf("[hcpptest]E failed to register feature or api.\n"); + } + } +} +SYS_FEATURE_INIT(GFeatureInit); + +static DemoApi *GetIUnknown(const char *serviceName, const char *featureName) +{ + DemoApi *demoApi = nullptr; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(serviceName, featureName); + if (iUnknown == nullptr) { + return nullptr; + } + int result = iUnknown->QueryInterface(iUnknown, 0x20, (void **)&demoApi); + if (result == 0 && demoApi != nullptr) { + return demoApi; + } else { + return nullptr; + } +} + +static DefaultFeatureApi *GetDefaultIUnknown(const char *serviceName) +{ + DefaultFeatureApi *defaultApi = nullptr; + IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(serviceName); + if (iUnknown == nullptr) { + return nullptr; + } + int result = iUnknown->QueryInterface(iUnknown, 0x20, (void **)&defaultApi); + if (result == 0 && defaultApi != nullptr) { + return defaultApi; + } else { + return nullptr; + } +} + +static void ReleaseIUnknown(DemoApi *demoApi) +{ + demoApi->Release((IUnknown *)demoApi); +} + +class TaskpoolSingleTaskTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + printf("[hcpptest]SetUpTestCase ! \n"); + SystemInitProxy(); + usleep(OPER_INTERVAL * MS2US); + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** + * @tc.number : DMSLite_SAMGR_Taskpool_SingleTask_0010 + * @tc.name : Service with PRI_LOW priority function is ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(TaskpoolSingleTaskTest, testSingleTask0010, TestSize.Level2) +{ + // test featureApi function + DemoApi *demoApi = GetIUnknown("SingleTS01", "featureName501"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + char *para = (char*)"xxxx"; + BOOL result = demoApi->FeatureApi001((IUnknown *)demoApi, para); + ASSERT_EQ(result, TRUE); + + g_feature.featureCalledCount = 0; + Request request = {.msgId = 0, + .len = 0, + .data = nullptr, + .msgValue = 0}; + char *body = (char*)"I wanna async call good result!"; + request.len = (uint32_t)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + int32 result2 = demoApi->SendRequestProxyF(&(g_feature.identity), &request, nullptr); + ASSERT_EQ(result2 == 0, TRUE); + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(g_feature.featureCalledCount == 1, TRUE); + + // test defaultFeatureApi function + DefaultFeatureApi *defaultApi = GetDefaultIUnknown("SingleTS01"); + if (defaultApi == nullptr) { + ADD_FAILURE(); + } + result = defaultApi->DefaultApi001((IUnknown *)defaultApi, (char*)"yyyy"); + ASSERT_EQ(result, TRUE); + + Request request2 = {.msgId = 0, .len = 0, .data = nullptr, .msgValue = 0}; + char *body2 = (char*)"I want to call defaultFeature!"; + request2.len = (uint32_t)(strlen(body2) + 1); + request2.data = malloc(request2.len); + if (request2.data == nullptr) { + ADD_FAILURE(); + } + error = strcpy_s((char *)request2.data, request2.len, body2); + if (error != EOK) { + ADD_FAILURE(); + } + result2 = defaultApi->SendRequestProxyDF(&(g_service[0].identity), &request2, nullptr); + ASSERT_EQ(result2 == 0, TRUE); + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(g_service[0].serviceCalledCount == 1, TRUE); +}; + +/** + * @tc.number : DMSLite_SAMGR_Taskpool_SingleTask_0020 + * @tc.name : Service with PRI_BELOW_NORMAL priority function is ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(TaskpoolSingleTaskTest, testSingleTask0020, TestSize.Level2) +{ + DemoApi *demoApi = GetIUnknown("SingleTS02", "featureName501"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + BOOL result = demoApi->FeatureApi001((IUnknown *)demoApi, (char*)"xxxx"); + ASSERT_EQ(result, TRUE); + + g_feature.featureCalledCount = 0; + Request request = {.msgId = 0, .len = 0, .data = nullptr, .msgValue = 0}; + char *body = (char*)"I wanna async call good result!"; + request.len = (uint32_t)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + int32 result2 = demoApi->SendRequestProxyF(&(g_feature.identity), &request, nullptr); + ASSERT_EQ(result2 == 0, TRUE); + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(g_feature.featureCalledCount == 1, TRUE); + + DefaultFeatureApi *defaultApi = GetDefaultIUnknown("SingleTS02"); + if (defaultApi == nullptr) { + ADD_FAILURE(); + } + result = defaultApi->DefaultApi001((IUnknown *)defaultApi, (char*)"yyyy"); + ASSERT_EQ(result, TRUE); + + Request request2 = {.msgId = 0, .len = 0, .data = nullptr, .msgValue = 0}; + char *body2 = (char*)"I want to call defaultFeature!"; + request2.len = (uint32_t)(strlen(body2) + 1); + request2.data = malloc(request2.len); + if (request2.data == nullptr) { + ADD_FAILURE(); + } + error = strcpy_s((char *)request2.data, request2.len, body2); + if (error != EOK) { + ADD_FAILURE(); + } + result2 = defaultApi->SendRequestProxyDF(&(g_service[1].identity), &request2, nullptr); + ASSERT_EQ(result2 == 0, TRUE); + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(g_service[1].serviceCalledCount == 1, TRUE); +}; + +/** + * @tc.number : DMSLite_SAMGR_Taskpool_SingleTask_0030 + * @tc.name : Service with PRI_NORMAL priority function is ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(TaskpoolSingleTaskTest, testSingleTask0030, TestSize.Level2) +{ + DemoApi *demoApi = GetIUnknown("SingleTS03", "featureName501"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + BOOL result = demoApi->FeatureApi001((IUnknown *)demoApi, (char*)"xxxx"); + ASSERT_EQ(result, TRUE); + + g_feature.featureCalledCount = 0; + Request request = {.msgId = 0, .len = 0, .data = nullptr, .msgValue = 0}; + char *body = (char*)"I wanna async call good result!"; + request.len = (uint32_t)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + int32 result2 = demoApi->SendRequestProxyF(&(g_feature.identity), &request, nullptr); + ASSERT_EQ(result2 == 0, TRUE); + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(g_feature.featureCalledCount == 1, TRUE); + + DefaultFeatureApi *defaultApi = GetDefaultIUnknown("SingleTS03"); + if (defaultApi == nullptr) { + ADD_FAILURE(); + } + result = defaultApi->DefaultApi001((IUnknown *)defaultApi, (char*)"yyyy"); + ASSERT_EQ(result, TRUE); + + Request request2 = {.msgId = 0, .len = 0, .data = nullptr, .msgValue = 0}; + char *body2 = (char*)"I want to call defaultFeature!"; + request2.len = (uint32_t)(strlen(body2) + 1); + request2.data = malloc(request2.len); + if (request2.data == nullptr) { + ADD_FAILURE(); + } + error = strcpy_s((char *)request2.data, request2.len, body2); + if (error != EOK) { + ADD_FAILURE(); + } + result2 = defaultApi->SendRequestProxyDF(&(g_service[INDEX2].identity), &request2, nullptr); + ASSERT_EQ(result2 == 0, TRUE); + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(g_service[INDEX2].serviceCalledCount == 1, TRUE); +}; + +/** + * @tc.number : DMSLite_SAMGR_Taskpool_SingleTask_0040 + * @tc.name : Service with PRI_ABOVE_NORMAL priority function is ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(TaskpoolSingleTaskTest, testSingleTask0040, TestSize.Level2) +{ + DemoApi *demoApi = GetIUnknown("SingleTS04", "featureName501"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + BOOL result = demoApi->FeatureApi001((IUnknown *)demoApi, (char*)"xxxx"); + ASSERT_EQ(result, TRUE); + + g_feature.featureCalledCount = 0; + Request request = {.msgId = 0, .len = 0, .data = nullptr, .msgValue = 0}; + char *body = (char*)"I wanna async call good result!"; + request.len = (uint32_t)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + int32 result2 = demoApi->SendRequestProxyF(&(g_feature.identity), &request, nullptr); + ASSERT_EQ(result2 == 0, TRUE); + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(g_feature.featureCalledCount == 1, TRUE); + + DefaultFeatureApi *defaultApi = GetDefaultIUnknown("SingleTS04"); + if (defaultApi == nullptr) { + ADD_FAILURE(); + } + result = defaultApi->DefaultApi001((IUnknown *)defaultApi, (char*)"yyyy"); + ASSERT_EQ(result, TRUE); + + Request request2 = {.msgId = 0, .len = 0, .data = nullptr, .msgValue = 0}; + char *body2 = (char*)"I want to call defaultFeature!"; + request2.len = (uint32_t)(strlen(body2) + 1); + request2.data = malloc(request2.len); + if (request2.data == nullptr) { + ADD_FAILURE(); + } + error = strcpy_s((char *)request2.data, request2.len, body2); + if (error != EOK) { + ADD_FAILURE(); + } + result2 = defaultApi->SendRequestProxyDF(&(g_service[INDEX3].identity), &request2, nullptr); + ASSERT_EQ(result2 == 0, TRUE); + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(g_service[INDEX3].serviceCalledCount == 1, TRUE); +}; + +/** + * @tc.number : DMSLite_SAMGR_Taskpool_SingleTask_0050 + * @tc.name : Service initialization order depends on service priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(TaskpoolSingleTaskTest, testSingleTask0050, TestSize.Level2) +{ + for (int i = 0; i < VECTOR_Num(&g_nodeVector); i++) { + Node *node = (Node *)VECTOR_At(&g_nodeVector, i); + if (node == NULL) { + continue; + } + printf("[hcpptest]vector: service %s, serviceArray: %s \n", node->name, + g_serviceNameArray[SERVICE_NUM - (i + 1)]); + ASSERT_EQ(node->id, i + 1); + ASSERT_EQ(strcmp(node->name, g_serviceNameArray[SERVICE_NUM - (i + 1)]), 0); + } +}; \ No newline at end of file diff --git a/distributedschedule_lite/samgr_posix/src/TaskpoolSpecifiedTaskTest.cpp b/distributedschedule_lite/samgr_posix/src/TaskpoolSpecifiedTaskTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..72cff8d7d3922b64b67dd2c3be2c358923198d93 --- /dev/null +++ b/distributedschedule_lite/samgr_posix/src/TaskpoolSpecifiedTaskTest.cpp @@ -0,0 +1,437 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "utils/SamgrTestBase.h" + +const int TARGET_NUM = 2; + +using namespace testing::ext; + +static const char *GetName(Service *service); +static BOOL Initialize(Service *service, Identity identity); +static BOOL MessageHandle(Service *service, Request *msg); +static TaskConfig GetTaskConfig(Service *service); + +static pthread_t g_servicePoint1; +static pthread_t g_servicePoint2; + +struct DemoApi { + INHERIT_IUNKNOWN; + BOOL(*FeatureApi001) + (IUnknown *iUnknown, char *para1); + int32 (*SendRequestProxyF)(const Identity *identity, const Request *request, Handler handler); +}; + +struct DemoFeature { + INHERIT_FEATURE; + INHERIT_IUNKNOWNENTRY(DemoApi); + Identity identity; + int featureCalledCount; +}; + +struct DefaultFeatureApi { + INHERIT_IUNKNOWN; + BOOL(*DefaultApi001) + (IUnknown *iUnknown, char *para1); + int32 (*SendRequestProxyDF)(const Identity *identity, const Request *request, Handler handler); +}; + +struct DemoService { + INHERIT_SERVICE; + INHERIT_IUNKNOWNENTRY(DefaultFeatureApi); + Identity identity; + int serviceCalledCount; +}; + +static BOOL DefaultApi001(IUnknown *iUnknown, char *para1) +{ + (void)iUnknown; + return TRUE; +} +static int32 SendRequestProxyDF(const Identity *identity, const Request *request, Handler handler) +{ + return SAMGR_SendRequest(identity, request, handler); +} + +static BOOL FeatureApi001(IUnknown *iUnknown, char *para1) +{ + (void)iUnknown; + return TRUE; +} +static int32 SendRequestProxyF(const Identity *identity, const Request *request, Handler handler) +{ + return SAMGR_SendRequest(identity, request, handler); +} + +static DemoService g_createService[] = { + { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ver = 0x20, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .DefaultApi001 = DefaultApi001, + .SendRequestProxyDF = SendRequestProxyDF, + }, + .identity = {-1, -1, nullptr}, + .serviceCalledCount = 0, + }, + { + .GetName = GetName, + .Initialize = Initialize, + .MessageHandle = MessageHandle, + .GetTaskConfig = GetTaskConfig, + .ver = 0x20, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .DefaultApi001 = DefaultApi001, + .SendRequestProxyDF = SendRequestProxyDF, + }, + .identity = {-1, -1, nullptr}, + .serviceCalledCount = 0, + } +}; + +static const char *GetName(Service *service) +{ + if (service == (Service *)&g_createService[0]) { + return "SpecifiedT01"; + } else { + return "SpecifiedT02"; + } +} + +static BOOL Initialize(Service *service, Identity identity) +{ + DemoService *demoService = (DemoService *)service; + demoService->identity = identity; + + return TRUE; +} + +static BOOL MessageHandle(Service *service, Request *msg) +{ + DemoService *demoService = (DemoService *)service; + demoService->serviceCalledCount++; + + if (service == (Service *)&g_createService[0]) { + g_servicePoint1 = pthread_self(); + } else { + g_servicePoint2 = pthread_self(); + } + + return TRUE; +} + +static TaskConfig GetTaskConfig(Service *service) +{ + TaskConfig config = {LEVEL_HIGH, PRI_NORMAL, 1600, 20, SPECIFIED_TASK}; + return config; +} + +static const char *FEATURE_GetName(Feature *feature) +{ + (void)feature; + return "featureName501"; +} + +static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->identity = identity; +} + +static void FEATURE_OnStop(Feature *feature, Identity identity) +{ + (void)feature; + (void)identity; +} + +static BOOL FEATURE_OnMessage(Feature *feature, Request *request) +{ + DemoFeature *demoFeature = (DemoFeature *)feature; + demoFeature->featureCalledCount++; + + return TRUE; +} + +static DemoFeature g_createFeature = { + .GetName = FEATURE_GetName, + .OnInitialize = FEATURE_OnInitialize, + .OnStop = FEATURE_OnStop, + .OnMessage = FEATURE_OnMessage, + .ver = 0x20, + .ref = 1, + .iUnknown = { + DEFAULT_IUNKNOWN_IMPL, + .FeatureApi001 = FeatureApi001, + .SendRequestProxyF = SendRequestProxyF, + }, + .identity = {-1, -1, nullptr}, + .featureCalledCount = 0, +}; + +static void GServiceInit(void) +{ + for (int i = 0; i < TARGET_NUM; i++) { + SAMGR_GetInstance()->RegisterService((Service *)&g_createService[i]); + } +} +SYS_SERVICE_INIT(GServiceInit); + +static void GFeatureInit(void) +{ + for (int i = 0; i < TARGET_NUM; i++) { + SAMGR_GetInstance()->RegisterDefaultFeatureApi(g_createService[i].GetName((Service *)&g_createService[i]), + GET_IUNKNOWN(g_createService[i])); + + SAMGR_GetInstance()->RegisterFeature(g_createService[i].GetName((Service *)&g_createService[i]), + (Feature *)&g_createFeature); + SAMGR_GetInstance()->RegisterFeatureApi(g_createService[i].GetName((Service *)&g_createService[i]), + "featureName501", GET_IUNKNOWN(g_createFeature)); + } +} +SYS_FEATURE_INIT(GFeatureInit); + +static DemoApi *GetIUnknown(const char *serviceName, const char *featureName) +{ + DemoApi *demoApi = nullptr; + IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(serviceName, featureName); + if (iUnknown == nullptr) { + return nullptr; + } + int result = iUnknown->QueryInterface(iUnknown, 0x20, (void **)&demoApi); + if (result == 0 && demoApi != nullptr) { + return demoApi; + } else { + return nullptr; + } +} + +static DefaultFeatureApi *GetDefaultIUnknown(const char *serviceName) +{ + DefaultFeatureApi *defaultApi = nullptr; + IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(serviceName); + if (iUnknown == nullptr) { + return nullptr; + } + int result = iUnknown->QueryInterface(iUnknown, 0x20, (void **)&defaultApi); + if (result == 0 && defaultApi != nullptr) { + return defaultApi; + } else { + return nullptr; + } +} + +static void ReleaseIUnknown(DemoApi *demoApi) +{ + demoApi->Release((IUnknown *)demoApi); +} + +class TaskpoolSpecifiedTaskTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + printf("[hcpptest]SetUpTestCase ! \n"); + SystemInitProxy(); + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + usleep(OPER_INTERVAL * MS2US); + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** + * @tc.number : SUB_DSS_samgrLite_taskpool_0010 + * @tc.name : the first task function is ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(TaskpoolSpecifiedTaskTest, testTaskPool0010, TestSize.Level2) +{ + DemoApi *demoApi = GetIUnknown("SpecifiedT01", "featureName501"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + BOOL result = demoApi->FeatureApi001((IUnknown *)demoApi, (char*)"xxxx"); + ASSERT_EQ(result, TRUE); + + g_createFeature.featureCalledCount = 0; + Request request = {.msgId = 0, .len = 0, .data = nullptr, .msgValue = 0}; + char *body = (char*)"I wanna async call good result!"; + request.len = (uint32_t)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + int32 result2 = demoApi->SendRequestProxyF(&(g_createFeature.identity), &request, nullptr); + ASSERT_EQ(result2 == 0, TRUE); + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(g_createFeature.featureCalledCount == 1, TRUE); + + DefaultFeatureApi *defaultApi = GetDefaultIUnknown("SpecifiedT01"); + if (defaultApi == nullptr) { + ADD_FAILURE(); + } + result = defaultApi->DefaultApi001((IUnknown *)defaultApi, (char*)"yyyy"); + ASSERT_EQ(result, TRUE); + + g_createService[0].serviceCalledCount = 0; + Request request2 = {.msgId = 0, .len = 0, .data = nullptr, .msgValue = 0}; + char *body2 = (char*)"I want to call defaultFeature!"; + request2.len = (uint32_t)(strlen(body2) + 1); + request2.data = malloc(request2.len); + if (request2.data == nullptr) { + ADD_FAILURE(); + } + error = strcpy_s((char *)request2.data, request2.len, body2); + if (error != EOK) { + ADD_FAILURE(); + } + result2 = defaultApi->SendRequestProxyDF(&(g_createService[0].identity), &request2, nullptr); + ASSERT_EQ(result2 == 0, TRUE); + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(g_createService[0].serviceCalledCount == 1, TRUE); +}; + +/** + * @tc.number : SUB_DSS_samgrLite_taskpool_0020 + * @tc.name : PRI_LOW function is ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(TaskpoolSpecifiedTaskTest, testTaskPool0020, TestSize.Level2) +{ + DemoApi *demoApi = GetIUnknown("SpecifiedT02", "featureName501"); + if (demoApi == nullptr) { + ADD_FAILURE(); + } + BOOL result = demoApi->FeatureApi001((IUnknown *)demoApi, (char*)"xxxx"); + ASSERT_EQ(result, TRUE); + + g_createFeature.featureCalledCount = 0; + Request request = {.msgId = 0, .len = 0, .data = nullptr, .msgValue = 0}; + char *body = (char*)"I wanna async call good result!"; + request.len = (uint32_t)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + int32 result2 = demoApi->SendRequestProxyF(&(g_createFeature.identity), &request, nullptr); + ASSERT_EQ(result2 == 0, TRUE); + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(g_createFeature.featureCalledCount == 1, TRUE); + + DefaultFeatureApi *defaultApi = GetDefaultIUnknown("SpecifiedT02"); + if (defaultApi == nullptr) { + ADD_FAILURE(); + } + result = defaultApi->DefaultApi001((IUnknown *)defaultApi, (char*)"yyyy"); + ASSERT_EQ(result, TRUE); + + g_createService[0].serviceCalledCount = 0; + Request request2 = {.msgId = 0, .len = 0, .data = nullptr, .msgValue = 0}; + char *body2 = (char*)"I want to call defaultFeature!"; + request2.len = (uint32_t)(strlen(body2) + 1); + request2.data = malloc(request2.len); + if (request2.data == nullptr) { + ADD_FAILURE(); + } + error = strcpy_s((char *)request2.data, request2.len, body2); + if (error != EOK) { + ADD_FAILURE(); + } + result2 = defaultApi->SendRequestProxyDF(&(g_createService[0].identity), &request2, nullptr); + ASSERT_EQ(result2 == 0, TRUE); + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(g_createService[0].serviceCalledCount == 1, TRUE); +}; + +/** + * @tc.number : SUB_DSS_samgrLite_taskpool_0030 + * @tc.name : PRI_LOW function is ok + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 +*/ +HWTEST_F(TaskpoolSpecifiedTaskTest, testTaskPool0030, TestSize.Level2) +{ + DefaultFeatureApi *defaultApi = GetDefaultIUnknown("SpecifiedT01"); + if (defaultApi == nullptr) { + ADD_FAILURE(); + } + Request request = {.msgId = 0, .len = 0, .data = nullptr, .msgValue = 0}; + char *body = (char*)"I want to call defaultFeature!"; + request.len = (uint32_t)(strlen(body) + 1); + request.data = malloc(request.len); + if (request.data == nullptr) { + ADD_FAILURE(); + } + errno_t error = strcpy_s((char *)request.data, request.len, body); + if (error != EOK) { + ADD_FAILURE(); + } + defaultApi->SendRequestProxyDF(&(g_createService[0].identity), &request, nullptr); + + DefaultFeatureApi *defaultApi2 = GetDefaultIUnknown("SpecifiedT01"); + if (defaultApi2 == nullptr) { + ADD_FAILURE(); + } + Request request2 = {.msgId = 0, .len = 0, .data = nullptr, .msgValue = 0}; + char *body2 = (char*)"I want to call defaultFeature!"; + request2.len = (uint32_t)(strlen(body2) + 1); + request2.data = malloc(request2.len); + if (request2.data == nullptr) { + ADD_FAILURE(); + } + error = strcpy_s((char *)request2.data, request2.len, body2); + if (error != EOK) { + ADD_FAILURE(); + } + defaultApi2->SendRequestProxyDF(&(g_createService[1].identity), &request2, nullptr); + + usleep(OPER_INTERVAL * MS2US); + ASSERT_EQ(g_servicePoint1 == g_servicePoint2, TRUE); +}; \ No newline at end of file diff --git a/distributedschedule_lite/samgr_posix/src/utils/SamgrTestBase.cpp b/distributedschedule_lite/samgr_posix/src/utils/SamgrTestBase.cpp new file mode 100755 index 0000000000000000000000000000000000000000..e540fab034caccee0a12800ef56bf0ccf9ebb9f3 --- /dev/null +++ b/distributedschedule_lite/samgr_posix/src/utils/SamgrTestBase.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 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 "SamgrTestBase.h" + +extern "C" void __attribute__((weak)) HOS_SystemInit(void) +{ + SAMGR_Bootstrap(); +}; + +static const int INIT_TIME = 1000; +static BOOL isInited = FALSE; +void SystemInitProxy() +{ + if (isInited == FALSE) { + printf("[hcpptest]samgr start init.\n"); + HOS_SystemInit(); + + usleep(OPER_INTERVAL * INIT_TIME); + isInited = TRUE; + } else { + printf("[hcpptest]samgr already init. \n"); + } +} \ No newline at end of file diff --git a/distributedschedule_lite/samgr_posix/src/utils/SamgrTestBase.h b/distributedschedule_lite/samgr_posix/src/utils/SamgrTestBase.h new file mode 100755 index 0000000000000000000000000000000000000000..fa4b248b995759defdebf88347c0fa20f8994c33 --- /dev/null +++ b/distributedschedule_lite/samgr_posix/src/utils/SamgrTestBase.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 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 SAMGR_TEST_UTILS +#define SAMGR_TEST_UTILS + +#include +#include +#include "samgr_lite.h" + +const int MS2US = 1000; +const int OPER_INTERVAL = 200; + +const int PRESSURE_BASE = 1024 * 10; +const int PRESSURE_L0 = 1024; + +void SystemInitProxy(); + +#endif \ No newline at end of file diff --git a/hiviewdfx_lite/dfx_hal/BUILD.gn b/hiviewdfx_lite/dfx_hal/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..5628d6c74359864d188b106c009582f42acad2ee --- /dev/null +++ b/hiviewdfx_lite/dfx_hal/BUILD.gn @@ -0,0 +1,34 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") +hctest_suite("ActsDfxFuncTest") { + suite_name = "acts" + sources = [ + "src/dfx_hilog.c", + ] + + include_dirs = [ + "src", + "//base/hiviewdfx/interfaces/kits/hilog_lite", + "//base/hiviewdfx/interfaces/innerkits/hievent_lite", + "//base/hiviewdfx/utils/lite", + "//base/hiviewdfx/frameworks/hievent_lite", + "//base/hiviewdfx/frameworks/hilog_lite/mini", + "//base/hiviewdfx/services/hilogcat_lite/commond", + "//vendor/hisi/hi3861/hi3861/include", + "//vendor/hisi/hi3861/hi3861/components/lwip_sack/include" + ] + + cflags = [ "-Wno-error" ] +} diff --git a/hiviewdfx_lite/dfx_hal/Test.tmpl b/hiviewdfx_lite/dfx_hal/Test.tmpl new file mode 100755 index 0000000000000000000000000000000000000000..be8407e1286041a5af2bdc75a15633337376eb9d --- /dev/null +++ b/hiviewdfx_lite/dfx_hal/Test.tmpl @@ -0,0 +1,19 @@ +{ + "description": "Config for $module test cases", + "environment": [ + { + "type": "device", + "label": "wifiiot" + } + ], + "kits": [ + { + "type": "DeployKit", + "timeout": "20000", + "burn_file": "$subsystem/$module.bin" + } + ], + "driver": { + "type": "CTestLite" + } +} \ No newline at end of file diff --git a/hiviewdfx_lite/dfx_hal/src/dfx_hilog.c b/hiviewdfx_lite/dfx_hal/src/dfx_hilog.c new file mode 100755 index 0000000000000000000000000000000000000000..24f0424f9c4491857374a8ef32f4ecb8c02d85b9 --- /dev/null +++ b/hiviewdfx_lite/dfx_hal/src/dfx_hilog.c @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2020 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 "hos_init.h" +#include "hiview_output_log.h" +#include "log.h" +#include "hctest.h" + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is dfx + * @param : module name is dfxlite + * @param : test suit name is DfxFuncTestSuite + */ +LITE_TEST_SUIT(dfx, dfxlite, DfxFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL DfxFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL DfxFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number : SUB_DFX_DFT_Hilog_0100 + * @tc.name : DebugLog print test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 0 + */ +LITE_TEST_CASE(DfxFuncTestSuite, subDfxDftHilog0100, LEVEL0) +{ + bool ret = TRUE; + HILOG_DEBUG(HILOG_MODULE_HIVIEW, "debuglog test pass"); + TEST_ASSERT_TRUE (ret); +}; + + +/** + * @tc.number : SUB_DFX_DFT_Hilog_0200 + * @tc.name : InfoLog print test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(DfxFuncTestSuite, subDfxDftHilog0200, LEVEL1) +{ + bool ret = TRUE; + HILOG_INFO(HILOG_MODULE_HIVIEW, "infolog test pass"); + TEST_ASSERT_TRUE (ret); +}; + +/** + * @tc.number : SUB_DFX_DFT_Hilog_0300 + * @tc.name : DebugLog print test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(DfxFuncTestSuite, subDfxDftHilog0300, LEVEL1) +{ + bool ret = TRUE; + HILOG_WARN(HILOG_MODULE_HIVIEW, "warnlog test pass"); + TEST_ASSERT_TRUE (ret); +}; + +/** + * @tc.number : SUB_DFX_DFT_Hilog_0400 + * @tc.name : ErrorLog print test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(DfxFuncTestSuite, subDfxDftHilog0400, LEVEL1) +{ + bool ret = TRUE; + HILOG_ERROR(HILOG_MODULE_HIVIEW, "errorlog test pass"); + TEST_ASSERT_TRUE (ret); +}; + +/** + * @tc.number : SUB_DFX_DFT_Hilog_0500 + * @tc.name : FatalLog print test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(DfxFuncTestSuite, subDfxDftHilog0500, LEVEL1) +{ + bool ret = TRUE; + HILOG_FATAL(HILOG_MODULE_HIVIEW, "fatallog test pass"); + TEST_ASSERT_TRUE (ret); +}; + +/** + * @tc.number : SUB_DFX_DFT_Hilog_0600 + * @tc.name : HiLogRegisterModule test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 0 + */ +LITE_TEST_CASE(DfxFuncTestSuite, subDfxDftHilog0600, LEVEL0) +{ + bool ret = TRUE; + ret = HiLogRegisterModule(HILOG_MODULE_HIVIEW, "HIVIEW"); + TEST_ASSERT_FALSE (ret); +}; + +/** + * @tc.number : SUB_DFX_DFT_Hilog_0700 + * @tc.name : HiLogGetModuleName test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 0 + */ +LITE_TEST_CASE(DfxFuncTestSuite, subDfxDftHilog0700, LEVEL0) +{ + const char * ret = HiLogGetModuleName(HILOG_MODULE_HIVIEW); + TEST_ASSERT_EQUAL_STRING (ret, "HIVIEW"); +}; + +RUN_TEST_SUITE(DfxFuncTestSuite); diff --git a/iot_hardware_lite/wifiiot_hal/BUILD.gn b/iot_hardware_lite/wifiiot_hal/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..b109181cb83c6504decbeeec3cc9a82c2c041ca2 --- /dev/null +++ b/iot_hardware_lite/wifiiot_hal/BUILD.gn @@ -0,0 +1,44 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") +hctest_suite("ActsWifiIotTest") { + suite_name = "acts" + sources = [ + "src/wifiiot_func_test.c", + "src/wifiiot_flash_func_test.c", + "src/wifiiot_gpio_func_test.c", + "src/wifiiot_i2c_func_test.c", + "src/wifiiot_uart_func_test.c", + "src/wifiiot_adc_func_test.c", + "src/wifiiot_spi_hdx_func_test.c", + "src/wifiiot_spi_slave_func_test.c", + "src/wifiiot_spi_fdx_func_test.c", + "src/wifiiot_sdio_func_test.c", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "//third_party/unity/src", + "src", + "//kernel/liteos_m/components/cmsis", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/samgr", + "//base/iot_hardware/interfaces/kits/wifiiot_lite", + ] + + deps = [ + "//test/xts/tools/hctest:hctest", + ] + + cflags = [ "-Wno-error" ] +} diff --git a/iot_hardware_lite/wifiiot_hal/Test.tmpl b/iot_hardware_lite/wifiiot_hal/Test.tmpl new file mode 100755 index 0000000000000000000000000000000000000000..be8407e1286041a5af2bdc75a15633337376eb9d --- /dev/null +++ b/iot_hardware_lite/wifiiot_hal/Test.tmpl @@ -0,0 +1,19 @@ +{ + "description": "Config for $module test cases", + "environment": [ + { + "type": "device", + "label": "wifiiot" + } + ], + "kits": [ + { + "type": "DeployKit", + "timeout": "20000", + "burn_file": "$subsystem/$module.bin" + } + ], + "driver": { + "type": "CTestLite" + } +} \ No newline at end of file diff --git a/iot_hardware_lite/wifiiot_hal/src/wifiiot_adc_func_test.c b/iot_hardware_lite/wifiiot_hal/src/wifiiot_adc_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..b1ec0c256d1f10e8b4e3210ce29fce02cc731c3f --- /dev/null +++ b/iot_hardware_lite/wifiiot_hal/src/wifiiot_adc_func_test.c @@ -0,0 +1,568 @@ +/* + * Copyright (c) 2020 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 "hos_types.h" +#include +#include +#include +#include "hctest.h" +#include "hi_task.h" +#include "hi_time.h" + +#include "samgr_lite.h" +#include "wifiiot_adc.h" +#include "wifiiot_errno.h" + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is wifiiot + * @param : module name is wifiiotlite + * @param : test suit name is UtilsFileFuncTestSuite + */ +LITE_TEST_SUIT(wifiiot, wifiiotlite, WifiIotAdcFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL WifiIotAdcFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL WifiIotAdcFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc001, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_0, &data, WIFI_IOT_ADC_EQU_MODEL_1, WIFI_IOT_ADC_CUR_BAIS_AUTO, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc002, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_0, &data, WIFI_IOT_ADC_EQU_MODEL_1, WIFI_IOT_ADC_CUR_BAIS_3P3V, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc003, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_0, &data, WIFI_IOT_ADC_EQU_MODEL_1, WIFI_IOT_ADC_CUR_BAIS_BUTT, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc004, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_0, &data, WIFI_IOT_ADC_EQU_MODEL_8, WIFI_IOT_ADC_CUR_BAIS_AUTO, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc005, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_0, &data, WIFI_IOT_ADC_EQU_MODEL_8, WIFI_IOT_ADC_CUR_BAIS_3P3V, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc006, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_0, &data, WIFI_IOT_ADC_EQU_MODEL_8, WIFI_IOT_ADC_CUR_BAIS_BUTT, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc007, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_0, &data, WIFI_IOT_ADC_EQU_MODEL_BUTT, WIFI_IOT_ADC_CUR_BAIS_AUTO, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc008, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_0, &data, WIFI_IOT_ADC_EQU_MODEL_BUTT, WIFI_IOT_ADC_CUR_BAIS_3P3V, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc009, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_0, &data, WIFI_IOT_ADC_EQU_MODEL_BUTT, WIFI_IOT_ADC_CUR_BAIS_BUTT, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc010, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_7, &data, WIFI_IOT_ADC_EQU_MODEL_1, WIFI_IOT_ADC_CUR_BAIS_AUTO, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc011, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_7, &data, WIFI_IOT_ADC_EQU_MODEL_1, WIFI_IOT_ADC_CUR_BAIS_3P3V, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc012, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_7, &data, WIFI_IOT_ADC_EQU_MODEL_1, WIFI_IOT_ADC_CUR_BAIS_BUTT, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc013, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_7, &data, WIFI_IOT_ADC_EQU_MODEL_8, WIFI_IOT_ADC_CUR_BAIS_AUTO, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc014, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_7, &data, WIFI_IOT_ADC_EQU_MODEL_8, WIFI_IOT_ADC_CUR_BAIS_3P3V, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc015, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_7, &data, WIFI_IOT_ADC_EQU_MODEL_8, WIFI_IOT_ADC_CUR_BAIS_BUTT, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc016, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_7, &data, WIFI_IOT_ADC_EQU_MODEL_BUTT, WIFI_IOT_ADC_CUR_BAIS_AUTO, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc017, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_7, &data, WIFI_IOT_ADC_EQU_MODEL_BUTT, WIFI_IOT_ADC_CUR_BAIS_3P3V, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc018, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_7, &data, WIFI_IOT_ADC_EQU_MODEL_BUTT, WIFI_IOT_ADC_CUR_BAIS_BUTT, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc019, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_BUTT, &data, WIFI_IOT_ADC_EQU_MODEL_1, WIFI_IOT_ADC_CUR_BAIS_AUTO, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc020, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_BUTT, &data, WIFI_IOT_ADC_EQU_MODEL_1, WIFI_IOT_ADC_CUR_BAIS_3P3V, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc021, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_BUTT, &data, WIFI_IOT_ADC_EQU_MODEL_1, WIFI_IOT_ADC_CUR_BAIS_BUTT, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc022, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_BUTT, &data, WIFI_IOT_ADC_EQU_MODEL_8, WIFI_IOT_ADC_CUR_BAIS_AUTO, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc023, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_BUTT, &data, WIFI_IOT_ADC_EQU_MODEL_8, WIFI_IOT_ADC_CUR_BAIS_3P3V, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc024, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_BUTT, &data, WIFI_IOT_ADC_EQU_MODEL_8, WIFI_IOT_ADC_CUR_BAIS_BUTT, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc025, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_BUTT, &data, WIFI_IOT_ADC_EQU_MODEL_BUTT, WIFI_IOT_ADC_CUR_BAIS_AUTO, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc026, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_BUTT, &data, WIFI_IOT_ADC_EQU_MODEL_BUTT, WIFI_IOT_ADC_CUR_BAIS_3P3V, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1500 + * @tc.name : Adc operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotAdcFuncTestSuite, testWifiIotAdc027, LEVEL1) +{ + unsigned int ret; + unsigned short data = 0; + ret = AdcRead(WIFI_IOT_ADC_CHANNEL_BUTT, &data, WIFI_IOT_ADC_EQU_MODEL_BUTT, WIFI_IOT_ADC_CUR_BAIS_BUTT, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_ADC_PARAMETER_WRONG) && (ret <= WIFI_IOT_ERR_ADC_NOT_INIT)))) + { + TEST_FAIL(); + } +}; + +RUN_TEST_SUITE(WifiIotAdcFuncTestSuite); diff --git a/iot_hardware_lite/wifiiot_hal/src/wifiiot_flash_func_test.c b/iot_hardware_lite/wifiiot_hal/src/wifiiot_flash_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..2cd39b5e6a7dc0974f9452f7765bf0c1364b65b9 --- /dev/null +++ b/iot_hardware_lite/wifiiot_hal/src/wifiiot_flash_func_test.c @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2020 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 "hos_types.h" +#include +#include +#include +#include "hctest.h" +#include "hi_task.h" +#include "hi_time.h" + +#include "samgr_lite.h" +#include "wifiiot_errno.h" +#include "wifiiot_flash.h" +#include "wifiiot_flash_ex.h" + +#define TEST_FLASH_SIZE 8 +#define TEST_FLASH_SIZE_4K 4096 +#define TEST_FLASH_OFFSET 0x1FF000 + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is wifiiot + * @param : module name is wifiiotlite + * @param : test suit name is UtilsFileFuncTestSuite + */ +LITE_TEST_SUIT(wifiiot, wifiiotlite, WifiIotFlashFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL WifiIotFlashFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL WifiIotFlashFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number : SUB_UTILS_IOT_API_100 + * @tc.name : Flash operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotFlashFuncTestSuite, testWifiIotFlashEx, LEVEL1) +{ + unsigned int ret; + char readtmp[TEST_FLASH_SIZE+1] = {0}; + ret = FlashDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = FlashInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + (void)memset_s(readtmp, TEST_FLASH_SIZE, 0x0, TEST_FLASH_SIZE); + ret = FlashIoctl(0, readtmp); + if (!(ret == 0 || (((ret >= WIFI_IOT_ERR_FLASH_NOT_INIT) && (ret <= WIFI_IOT_ERR_FLASH_PROTECT_NOT_FIND_CHIP)) + ||((ret >= WIFI_IOT_ERR_FLASH_CRYPTO_INVALID_PARAM) && (ret <= WIFI_IOT_ERR_FLASH_CRYPTO_KERNEL_ADDR_ERR))))) + { + TEST_FAIL(); + } +}; + + +/** + * @tc.number : SUB_UTILS_IOT_API_100 + * @tc.name : Flash operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotFlashFuncTestSuite, testWifiIotFlash001, LEVEL1) +{ + unsigned int ret; + char writetmp[TEST_FLASH_SIZE+1] = {0}; + ret = FlashDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = FlashInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + (void)sprintf_s(writetmp, sizeof(writetmp), "test"); + ret = FlashWrite(TEST_FLASH_OFFSET, TEST_FLASH_SIZE, (const uint8 *)writetmp, 1); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_200 + * @tc.name : Flash operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotFlashFuncTestSuite, testWifiIotFlash002, LEVEL1) +{ + unsigned int ret; + char readtmp[TEST_FLASH_SIZE+1] = {0}; + ret = FlashDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = FlashInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + (void)memset_s(readtmp, TEST_FLASH_SIZE, 0x0, TEST_FLASH_SIZE); + ret = FlashRead(TEST_FLASH_OFFSET, TEST_FLASH_SIZE, (uint8 *)readtmp); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_200 + * @tc.name : Flash operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotFlashFuncTestSuite, testWifiIotFlash003, LEVEL1) +{ + unsigned int ret; + ret = FlashDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = FlashInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = FlashErase(TEST_FLASH_OFFSET, TEST_FLASH_SIZE_4K); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_200 + * @tc.name : Flash operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotFlashFuncTestSuite, testWifiIotFlash004, LEVEL1) +{ + unsigned int ret; + char writetmp[TEST_FLASH_SIZE+1] = {0}; + char readtmp[TEST_FLASH_SIZE+1] = {0}; + ret = FlashDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = FlashInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + (void)sprintf_s(writetmp, sizeof(writetmp), "test"); + ret = FlashWrite(TEST_FLASH_OFFSET, TEST_FLASH_SIZE, (const uint8 *)writetmp, 1); + TEST_ASSERT_EQUAL_INT(0, ret); + + (void)memset_s(readtmp, TEST_FLASH_SIZE, 0x0, TEST_FLASH_SIZE); + ret = FlashRead(TEST_FLASH_OFFSET, TEST_FLASH_SIZE, (uint8 *)readtmp); + TEST_ASSERT_EQUAL_INT(0, ret); + + if (strcmp(readtmp, writetmp) != 0) { + TEST_FAIL(); + } + + ret = FlashErase(TEST_FLASH_OFFSET, TEST_FLASH_SIZE_4K); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +RUN_TEST_SUITE(WifiIotFlashFuncTestSuite); diff --git a/iot_hardware_lite/wifiiot_hal/src/wifiiot_func_test.c b/iot_hardware_lite/wifiiot_hal/src/wifiiot_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..e74acb0698a52dee6824af695e8ec85daef216ca --- /dev/null +++ b/iot_hardware_lite/wifiiot_hal/src/wifiiot_func_test.c @@ -0,0 +1,489 @@ +/* + * Copyright (c) 2020 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 "hos_types.h" +#include +#include +#include +#include "hctest.h" +#include "hi_task.h" +#include "hi_time.h" + +#include "samgr_lite.h" +#include "wifiiot_errno.h" +#include "wifiiot_watchdog.h" +#include "wifiiot_partition.h" +#include "wifiiot_at.h" +#include "wifiiot_kal.h" +#ifdef CONFIG_I2S_SUPPORT +#include "wifiiot_i2s.h" +#endif +#ifdef CONFIG_PWM_SUPPORT +#include "wifiiot_pwm.h" +#endif + +#define TEST_REGISTER_CMD 2 +#define TEST_PWM_PORT 1200 +#define TEST_PWM_DUTY 1500 +#define TEST_I2S_SIZE 8 +#define TEST_I2S_TIMEOUT 1000 + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is wifiiot + * @param : module name is wifiiotlite + * @param : test suit name is UtilsFileFuncTestSuite + */ +LITE_TEST_SUIT(wifiiot, wifiiotlite, WifiIotFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL WifiIotFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL WifiIotFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number : SUB_UTILS_IOT_API_1200 + * @tc.name : Watchdog operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotFuncTestSuite, testWifiIotWatchdog, LEVEL1) +{ + WatchDogEnable(); + WatchDogKick(); + WatchDogDisable(); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1300 + * @tc.name : Partition operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotFuncTestSuite, testWifiIotPartition, LEVEL1) +{ + unsigned int ret; + char *table = 0; + + ret = FlashPartitionInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + + table = (char *)GetPartitionTable(); + if (table == 0) { + TEST_FAIL(); + } +}; + +int DemoAtExeTest1Cmd(void) +{ + int ret = AtPrintf("DemoAtExeTest1Cmd!\n"); + TEST_ASSERT_GREATER_OR_EQUAL_INT(0, ret); + return 0; +} + +int DemoAtExeTest2Cmd(void) +{ + int ret = AtPrintf("DemoAtExeTest2Cmd!\n"); + TEST_ASSERT_GREATER_OR_EQUAL_INT(0, ret); + return 0; +} + +AtCmdTbl g_regatcmdtbl[] = { + {"+TEST1", 6, 0, 0, 0, (AtCallbackFunc)DemoAtExeTest1Cmd}, + {"+TEST2", 6, 0, 0, 0, (AtCallbackFunc)DemoAtExeTest2Cmd}, +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1600 + * @tc.name : Partition operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotFuncTestSuite, testWifiIotAt001, LEVEL1) +{ + unsigned int ret; + ret = AtInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + AtSysCmdRegister(); + AtCheckUartBusy(1); + ret = AtRegisterCmd(g_regatcmdtbl, TEST_REGISTER_CMD); + if (!(((ret >= WIFI_IOT_ERR_AT_NAME_OR_FUNC_REPEAT_REGISTERED) && (ret <= WIFI_IOT_ERR_AT_INVALID_PARAMETER)) + || ret == 0)) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1700 + * @tc.name : Partition operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotFuncTestSuite, testWifiIotAt002, LEVEL1) +{ + unsigned int ret; + ret = AtInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + AtSysCmdRegister(); + AtCheckUartBusy(0); + ret = AtRegisterCmd(g_regatcmdtbl, TEST_REGISTER_CMD); + if (!(((ret >= WIFI_IOT_ERR_AT_NAME_OR_FUNC_REPEAT_REGISTERED) && (ret <= WIFI_IOT_ERR_AT_INVALID_PARAMETER)) + || ret == 0)) + { + TEST_FAIL(); + } +}; + +#ifdef CONFIG_PWM_SUPPORT +/** + * @tc.number : SUB_UTILS_IOT_API_1400 + * @tc.name : Pwm operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotFuncTestSuite, testWifiIotPwm001, LEVEL1) +{ + unsigned int ret; + ret = PwmDeinit(WIFI_IOT_PWM_PORT_PWM0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_PWM_NO_INIT) && (ret <= WIFI_IOT_ERR_PWM_INVALID_PARAMETER)))) + { + TEST_FAIL(); + } + ret =PwmInit(WIFI_IOT_PWM_PORT_PWM0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_PWM_NO_INIT) && (ret <= WIFI_IOT_ERR_PWM_INVALID_PARAMETER)))) + { + TEST_FAIL(); + } + ret =PwmStart(WIFI_IOT_PWM_PORT_PWM0, TEST_PWM_PORT, TEST_PWM_DUTY); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_PWM_NO_INIT) && (ret <= WIFI_IOT_ERR_PWM_INVALID_PARAMETER)))) + { + TEST_FAIL(); + } + ret = PwmStop(WIFI_IOT_PWM_PORT_PWM0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_PWM_NO_INIT) && (ret <= WIFI_IOT_ERR_PWM_INVALID_PARAMETER)))) + { + TEST_FAIL(); + } + ret = PwmDeinit(WIFI_IOT_PWM_PORT_PWM0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_PWM_NO_INIT) && (ret <= WIFI_IOT_ERR_PWM_INVALID_PARAMETER)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1400 + * @tc.name : Pwm operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotFuncTestSuite, testWifiIotPwm002, LEVEL1) +{ + unsigned int ret; + ret = PwmDeinit(WIFI_IOT_PWM_PORT_PWM5); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_PWM_NO_INIT) && (ret <= WIFI_IOT_ERR_PWM_INVALID_PARAMETER)))) + { + TEST_FAIL(); + } + ret =PwmInit(WIFI_IOT_PWM_PORT_PWM5); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_PWM_NO_INIT) && (ret <= WIFI_IOT_ERR_PWM_INVALID_PARAMETER)))) + { + TEST_FAIL(); + } + ret =PwmStart(WIFI_IOT_PWM_PORT_PWM5, TEST_PWM_PORT, TEST_PWM_DUTY); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_PWM_NO_INIT) && (ret <= WIFI_IOT_ERR_PWM_INVALID_PARAMETER)))) + { + TEST_FAIL(); + } + ret = PwmStop(WIFI_IOT_PWM_PORT_PWM5); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_PWM_NO_INIT) && (ret <= WIFI_IOT_ERR_PWM_INVALID_PARAMETER)))) + { + TEST_FAIL(); + } + ret = PwmDeinit(WIFI_IOT_PWM_PORT_PWM5); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_PWM_NO_INIT) && (ret <= WIFI_IOT_ERR_PWM_INVALID_PARAMETER)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1400 + * @tc.name : Pwm operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotFuncTestSuite, testWifiIotPwm003, LEVEL1) +{ + unsigned int ret; + ret = PwmDeinit(WIFI_IOT_PWM_PORT_MAX); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_PWM_NO_INIT) && (ret <= WIFI_IOT_ERR_PWM_INVALID_PARAMETER)))) + { + TEST_FAIL(); + } + ret =PwmInit(WIFI_IOT_PWM_PORT_MAX); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_PWM_NO_INIT) && (ret <= WIFI_IOT_ERR_PWM_INVALID_PARAMETER)))) + { + TEST_FAIL(); + } + ret =PwmStart(WIFI_IOT_PWM_PORT_MAX, TEST_PWM_PORT, TEST_PWM_DUTY); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_PWM_NO_INIT) && (ret <= WIFI_IOT_ERR_PWM_INVALID_PARAMETER)))) + { + TEST_FAIL(); + } + ret = PwmStop(WIFI_IOT_PWM_PORT_MAX); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_PWM_NO_INIT) && (ret <= WIFI_IOT_ERR_PWM_INVALID_PARAMETER)))) + { + TEST_FAIL(); + } +}; +#endif + +#ifdef CONFIG_I2S_SUPPORT +/** + * @tc.number : SUB_UTILS_IOT_API_2500 + * @tc.name : I2s operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotFuncTestSuite, testWifiIotI2s001, LEVEL1) +{ + unsigned int ret; + unsigned char writeBuf[] = "I2sDemoTest"; + unsigned char readBuf[TEST_I2S_SIZE] = ""; + + WifiIotI2sAttribute i2s_cfg; + i2s_cfg.sampleRate = WIFI_IOT_I2S_SAMPLE_RATE_8K; + i2s_cfg.resolution = WIFI_IOT_I2S_RESOLUTION_16BIT; + + ret = I2sDeinit(); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2S_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_I2S_WRITE_TIMEOUT)))) + { + TEST_FAIL(); + } + ret = I2sInit(&i2s_cfg); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2S_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_I2S_WRITE_TIMEOUT)))) + { + TEST_FAIL(); + } + ret = I2sWrite(writeBuf, sizeof(writeBuf), TEST_I2S_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2S_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_I2S_WRITE_TIMEOUT)))) + { + TEST_FAIL(); + } + + ret = I2sRead(readBuf, sizeof(readBuf), TEST_I2S_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2S_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_I2S_WRITE_TIMEOUT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2500 + * @tc.name : I2s operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotFuncTestSuite, testWifiIotI2s002, LEVEL1) +{ + unsigned int ret; + unsigned char writeBuf[] = "I2sDemoTest"; + unsigned char readBuf[TEST_I2S_SIZE] = ""; + + WifiIotI2sAttribute i2s_cfg; + i2s_cfg.sampleRate = WIFI_IOT_I2S_SAMPLE_RATE_8K; + i2s_cfg.resolution = WIFI_IOT_I2S_RESOLUTION_24BIT; + + ret = I2sDeinit(); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2S_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_I2S_WRITE_TIMEOUT)))) + { + TEST_FAIL(); + } + ret = I2sInit(&i2s_cfg); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2S_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_I2S_WRITE_TIMEOUT)))) + { + TEST_FAIL(); + } + ret = I2sWrite(writeBuf, sizeof(writeBuf), TEST_I2S_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2S_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_I2S_WRITE_TIMEOUT)))) + { + TEST_FAIL(); + } + + ret = I2sRead(readBuf, sizeof(readBuf), TEST_I2S_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2S_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_I2S_WRITE_TIMEOUT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2500 + * @tc.name : I2s operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotFuncTestSuite, testWifiIotI2s003, LEVEL1) +{ + unsigned int ret; + unsigned char writeBuf[] = "I2sDemoTest"; + unsigned char readBuf[TEST_I2S_SIZE] = ""; + + WifiIotI2sAttribute i2s_cfg; + i2s_cfg.sampleRate = WIFI_IOT_I2S_SAMPLE_RATE_48K; + i2s_cfg.resolution = WIFI_IOT_I2S_RESOLUTION_16BIT; + + ret = I2sDeinit(); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2S_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_I2S_WRITE_TIMEOUT)))) + { + TEST_FAIL(); + } + ret = I2sInit(&i2s_cfg); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2S_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_I2S_WRITE_TIMEOUT)))) + { + TEST_FAIL(); + } + ret = I2sWrite(writeBuf, sizeof(writeBuf), TEST_I2S_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2S_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_I2S_WRITE_TIMEOUT)))) + { + TEST_FAIL(); + } + + ret = I2sRead(readBuf, sizeof(readBuf), TEST_I2S_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2S_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_I2S_WRITE_TIMEOUT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2500 + * @tc.name : I2s operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotFuncTestSuite, testWifiIotI2s004, LEVEL1) +{ + unsigned int ret; + unsigned char writeBuf[] = "I2sDemoTest"; + unsigned char readBuf[TEST_I2S_SIZE] = ""; + + WifiIotI2sAttribute i2s_cfg; + i2s_cfg.sampleRate = WIFI_IOT_I2S_SAMPLE_RATE_48K; + i2s_cfg.resolution = WIFI_IOT_I2S_RESOLUTION_24BIT; + + ret = I2sDeinit(); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2S_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_I2S_WRITE_TIMEOUT)))) + { + TEST_FAIL(); + } + ret = I2sInit(&i2s_cfg); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2S_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_I2S_WRITE_TIMEOUT)))) + { + TEST_FAIL(); + } + ret = I2sWrite(writeBuf, sizeof(writeBuf), TEST_I2S_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2S_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_I2S_WRITE_TIMEOUT)))) + { + TEST_FAIL(); + } + + ret = I2sRead(readBuf, sizeof(readBuf), TEST_I2S_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2S_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_I2S_WRITE_TIMEOUT)))) + { + TEST_FAIL(); + } +}; +#endif + +void TickCB(void) +{ + printf("Tick callback function\n"); + KalTickRegisterCallback(0); +} +void IdleCB(void) +{ + printf("Idle task callback function\n"); + KalThreadRegisterIdleCallback(0); +} + +/** + * @tc.number : SUB_UTILS_IOT_API_2600 + * @tc.name : Kal operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotFuncTestSuite, testWifiIotKal001, LEVEL1) +{ + KalTickRegisterCallback(TickCB); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2700 + * @tc.name : Kal operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotFuncTestSuite, testWifiIotKal002, LEVEL1) +{ + KalThreadRegisterIdleCallback(IdleCB); +}; + +RUN_TEST_SUITE(WifiIotFuncTestSuite); diff --git a/iot_hardware_lite/wifiiot_hal/src/wifiiot_gpio_func_test.c b/iot_hardware_lite/wifiiot_hal/src/wifiiot_gpio_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..bf8f4ff339ea291e511d506e8716fb55643e4005 --- /dev/null +++ b/iot_hardware_lite/wifiiot_hal/src/wifiiot_gpio_func_test.c @@ -0,0 +1,2607 @@ +/* + * Copyright (c) 2020 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 "hos_types.h" +#include +#include +#include +#include "hctest.h" +#include "hi_task.h" +#include "hi_time.h" + +#include "samgr_lite.h" +#include "wifiiot_errno.h" +#include "wifiiot_gpio.h" +#include "wifiiot_gpio_ex.h" + +#define TEST_GPIO_SIZE 8 + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is wifiiot + * @param : module name is wifiiotlite + * @param : test suit name is UtilsFileFuncTestSuite + */ +LITE_TEST_SUIT(wifiiot, wifiiotlite, WifiIotGpioFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL WifiIotGpioFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL WifiIotGpioFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO001, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_GPIO_IDX_0; + WifiIotGpioDir val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetDir(gpioOutNum, WIFI_IOT_GPIO_DIR_OUT); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioGetDir(gpioOutNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO002, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_GPIO_IDX_7; + WifiIotGpioDir val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetDir(gpioOutNum, WIFI_IOT_GPIO_DIR_OUT); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioGetDir(gpioOutNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO003, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_GPIO_IDX_14; + WifiIotGpioDir val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetDir(gpioOutNum, WIFI_IOT_GPIO_DIR_OUT); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioGetDir(gpioOutNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO004, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_GPIO_IDX_MAX; + WifiIotGpioDir val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetDir(gpioOutNum, WIFI_IOT_GPIO_DIR_OUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = GpioGetDir(gpioOutNum, &val); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO005, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_GPIO_IDX_0; + WifiIotGpioDir val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetDir(gpioOutNum, WIFI_IOT_GPIO_DIR_IN); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioGetDir(gpioOutNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO006, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_GPIO_IDX_7; + WifiIotGpioDir val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetDir(gpioOutNum, WIFI_IOT_GPIO_DIR_IN); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioGetDir(gpioOutNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO007, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_GPIO_IDX_14; + WifiIotGpioDir val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetDir(gpioOutNum, WIFI_IOT_GPIO_DIR_IN); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioGetDir(gpioOutNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO008, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_GPIO_IDX_MAX; + WifiIotGpioDir val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetDir(gpioOutNum, WIFI_IOT_GPIO_DIR_IN); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = GpioGetDir(gpioOutNum, &val); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO009, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_GPIO_IDX_0; + WifiIotGpioValue val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetOutputVal(gpioOutNum, WIFI_IOT_GPIO_VALUE0); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioGetOutputVal(gpioOutNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO010, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_GPIO_IDX_7; + WifiIotGpioValue val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetOutputVal(gpioOutNum, WIFI_IOT_GPIO_VALUE0); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioGetOutputVal(gpioOutNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO011, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_GPIO_IDX_14; + WifiIotGpioValue val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetOutputVal(gpioOutNum, WIFI_IOT_GPIO_VALUE0); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioGetOutputVal(gpioOutNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO012, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_GPIO_IDX_MAX; + WifiIotGpioValue val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetOutputVal(gpioOutNum, WIFI_IOT_GPIO_VALUE0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = GpioGetOutputVal(gpioOutNum, &val); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO0013, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_GPIO_IDX_0; + WifiIotGpioValue val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetOutputVal(gpioOutNum, WIFI_IOT_GPIO_VALUE1); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioGetOutputVal(gpioOutNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO0014, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_GPIO_IDX_7; + WifiIotGpioValue val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetOutputVal(gpioOutNum, WIFI_IOT_GPIO_VALUE1); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioGetOutputVal(gpioOutNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO015, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_GPIO_IDX_14; + WifiIotGpioValue val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetOutputVal(gpioOutNum, WIFI_IOT_GPIO_VALUE1); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioGetOutputVal(gpioOutNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO016, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_GPIO_IDX_MAX; + WifiIotGpioValue val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetOutputVal(gpioOutNum, WIFI_IOT_GPIO_VALUE1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = GpioGetOutputVal(gpioOutNum, &val); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO017, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_0; + WifiIotGpioValue val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioGetInputVal(gpioInNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO018, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_7; + WifiIotGpioValue val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioGetInputVal(gpioInNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO019, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_14; + WifiIotGpioValue val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioGetInputVal(gpioInNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO020, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_MAX; + WifiIotGpioValue val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioGetInputVal(gpioInNum, &val); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +void IOT_IsrFunc(char *arg) +{ + int gpioInNum = (intptr_t)arg; + unsigned int ret = GpioUnregisterIsrFunc(gpioInNum); + TEST_ASSERT_EQUAL_INT(0, ret); + printf("GpioIsrFunc callback successfully\n"); +} + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO021, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_0; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioRegisterIsrFunc(gpioInNum, WIFI_IOT_INT_TYPE_LEVEL, + WIFI_IOT_GPIO_EDGE_FALL_LEVEL_LOW, IOT_IsrFunc, (char *)(intptr_t)gpioInNum); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = GpioUnregisterIsrFunc(gpioInNum); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO022, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_7; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioRegisterIsrFunc(gpioInNum, WIFI_IOT_INT_TYPE_LEVEL, + WIFI_IOT_GPIO_EDGE_FALL_LEVEL_LOW, IOT_IsrFunc, (char *)(intptr_t)gpioInNum); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = GpioUnregisterIsrFunc(gpioInNum); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO023, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_14; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioRegisterIsrFunc(gpioInNum, WIFI_IOT_INT_TYPE_LEVEL, + WIFI_IOT_GPIO_EDGE_FALL_LEVEL_LOW, IOT_IsrFunc, (char *)(intptr_t)gpioInNum); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = GpioUnregisterIsrFunc(gpioInNum); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO024, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_MAX; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioRegisterIsrFunc(gpioInNum, WIFI_IOT_INT_TYPE_LEVEL, + WIFI_IOT_GPIO_EDGE_FALL_LEVEL_LOW, IOT_IsrFunc, (char *)(intptr_t)gpioInNum); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = GpioUnregisterIsrFunc(gpioInNum); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO025, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_0; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioRegisterIsrFunc(gpioInNum, WIFI_IOT_INT_TYPE_LEVEL, + WIFI_IOT_GPIO_EDGE_RISE_LEVEL_HIGH, IOT_IsrFunc, (char *)(intptr_t)gpioInNum); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = GpioUnregisterIsrFunc(gpioInNum); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO026, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_7; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioRegisterIsrFunc(gpioInNum, WIFI_IOT_INT_TYPE_LEVEL, + WIFI_IOT_GPIO_EDGE_RISE_LEVEL_HIGH, IOT_IsrFunc, (char *)(intptr_t)gpioInNum); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = GpioUnregisterIsrFunc(gpioInNum); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO027, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_14; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioRegisterIsrFunc(gpioInNum, WIFI_IOT_INT_TYPE_LEVEL, + WIFI_IOT_GPIO_EDGE_RISE_LEVEL_HIGH, IOT_IsrFunc, (char *)(intptr_t)gpioInNum); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = GpioUnregisterIsrFunc(gpioInNum); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO028, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_MAX; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioRegisterIsrFunc(gpioInNum, WIFI_IOT_INT_TYPE_LEVEL, + WIFI_IOT_GPIO_EDGE_RISE_LEVEL_HIGH, IOT_IsrFunc, (char *)(intptr_t)gpioInNum); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = GpioUnregisterIsrFunc(gpioInNum); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO029, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_0; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioRegisterIsrFunc(gpioInNum, WIFI_IOT_INT_TYPE_EDGE, + WIFI_IOT_GPIO_EDGE_FALL_LEVEL_LOW, IOT_IsrFunc, (char *)(intptr_t)gpioInNum); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = GpioUnregisterIsrFunc(gpioInNum); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO030, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_7; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioRegisterIsrFunc(gpioInNum, WIFI_IOT_INT_TYPE_EDGE, + WIFI_IOT_GPIO_EDGE_FALL_LEVEL_LOW, IOT_IsrFunc, (char *)(intptr_t)gpioInNum); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = GpioUnregisterIsrFunc(gpioInNum); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO031, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_14; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioRegisterIsrFunc(gpioInNum, WIFI_IOT_INT_TYPE_EDGE, + WIFI_IOT_GPIO_EDGE_FALL_LEVEL_LOW, IOT_IsrFunc, (char *)(intptr_t)gpioInNum); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = GpioUnregisterIsrFunc(gpioInNum); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO032, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_MAX; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioRegisterIsrFunc(gpioInNum, WIFI_IOT_INT_TYPE_EDGE, + WIFI_IOT_GPIO_EDGE_FALL_LEVEL_LOW, IOT_IsrFunc, (char *)(intptr_t)gpioInNum); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = GpioUnregisterIsrFunc(gpioInNum); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO033, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_0; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioRegisterIsrFunc(gpioInNum, WIFI_IOT_INT_TYPE_EDGE, + WIFI_IOT_GPIO_EDGE_RISE_LEVEL_HIGH, IOT_IsrFunc, (char *)(intptr_t)gpioInNum); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = GpioUnregisterIsrFunc(gpioInNum); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO034, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_7; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioRegisterIsrFunc(gpioInNum, WIFI_IOT_INT_TYPE_EDGE, + WIFI_IOT_GPIO_EDGE_RISE_LEVEL_HIGH, IOT_IsrFunc, (char *)(intptr_t)gpioInNum); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = GpioUnregisterIsrFunc(gpioInNum); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO035, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_14; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioRegisterIsrFunc(gpioInNum, WIFI_IOT_INT_TYPE_EDGE, + WIFI_IOT_GPIO_EDGE_RISE_LEVEL_HIGH, IOT_IsrFunc, (char *)(intptr_t)gpioInNum); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = GpioUnregisterIsrFunc(gpioInNum); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO036, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_MAX; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioRegisterIsrFunc(gpioInNum, WIFI_IOT_INT_TYPE_EDGE, + WIFI_IOT_GPIO_EDGE_RISE_LEVEL_HIGH, IOT_IsrFunc, (char *)(intptr_t)gpioInNum); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = GpioUnregisterIsrFunc(gpioInNum); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO037, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_0; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMask(gpioInNum, 1); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMask(gpioInNum, 0); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO038, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_7; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMask(gpioInNum, 1); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMask(gpioInNum, 0); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO039, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_14; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMask(gpioInNum, 1); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMask(gpioInNum, 0); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO040, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_MAX; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMask(gpioInNum, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = GpioSetIsrMask(gpioInNum, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO041, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_0; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMode(gpioInNum, + WIFI_IOT_INT_TYPE_LEVEL, WIFI_IOT_GPIO_EDGE_FALL_LEVEL_LOW); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO042, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_7; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMode(gpioInNum, + WIFI_IOT_INT_TYPE_LEVEL, WIFI_IOT_GPIO_EDGE_FALL_LEVEL_LOW); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO043, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_14; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMode(gpioInNum, + WIFI_IOT_INT_TYPE_LEVEL, WIFI_IOT_GPIO_EDGE_FALL_LEVEL_LOW); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO044, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_MAX; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMode(gpioInNum, + WIFI_IOT_INT_TYPE_LEVEL, WIFI_IOT_GPIO_EDGE_FALL_LEVEL_LOW); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO045, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_0; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMode(gpioInNum, + WIFI_IOT_INT_TYPE_LEVEL, WIFI_IOT_GPIO_EDGE_RISE_LEVEL_HIGH); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO046, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_7; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMode(gpioInNum, + WIFI_IOT_INT_TYPE_LEVEL, WIFI_IOT_GPIO_EDGE_RISE_LEVEL_HIGH); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO047, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_14; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMode(gpioInNum, + WIFI_IOT_INT_TYPE_LEVEL, WIFI_IOT_GPIO_EDGE_RISE_LEVEL_HIGH); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_300 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO048, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_MAX; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMode(gpioInNum, + WIFI_IOT_INT_TYPE_LEVEL, WIFI_IOT_GPIO_EDGE_RISE_LEVEL_HIGH); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO0849, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_0; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMode(gpioInNum, + WIFI_IOT_INT_TYPE_EDGE, WIFI_IOT_GPIO_EDGE_FALL_LEVEL_LOW); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO050, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_7; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMode(gpioInNum, + WIFI_IOT_INT_TYPE_EDGE, WIFI_IOT_GPIO_EDGE_FALL_LEVEL_LOW); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO051, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_14; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMode(gpioInNum, + WIFI_IOT_INT_TYPE_EDGE, WIFI_IOT_GPIO_EDGE_FALL_LEVEL_LOW); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO052, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_MAX; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMode(gpioInNum, + WIFI_IOT_INT_TYPE_EDGE, WIFI_IOT_GPIO_EDGE_FALL_LEVEL_LOW); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO053, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_0; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMode(gpioInNum, + WIFI_IOT_INT_TYPE_EDGE, WIFI_IOT_GPIO_EDGE_RISE_LEVEL_HIGH); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO054, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_7; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMode(gpioInNum, + WIFI_IOT_INT_TYPE_EDGE, WIFI_IOT_GPIO_EDGE_RISE_LEVEL_HIGH); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO055, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_14; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMode(gpioInNum, + WIFI_IOT_INT_TYPE_EDGE, WIFI_IOT_GPIO_EDGE_RISE_LEVEL_HIGH); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_400 + * @tc.name : GPIO operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO056, LEVEL1) +{ + unsigned int ret; + int gpioInNum = WIFI_IOT_GPIO_IDX_MAX; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioSetIsrMode(gpioInNum, + WIFI_IOT_INT_TYPE_EDGE, WIFI_IOT_GPIO_EDGE_RISE_LEVEL_HIGH); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_500 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO057, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_0; + WifiIotIoPull val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoSetPull(gpioOutNum, WIFI_IOT_IO_PULL_UP); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoGetPull(gpioOutNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_500 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO058, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_0; + WifiIotIoPull val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoSetPull(gpioOutNum, WIFI_IOT_IO_PULL_DOWN); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoGetPull(gpioOutNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_500 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO059, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_0; + WifiIotIoPull val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoSetPull(gpioOutNum, WIFI_IOT_IO_PULL_MAX); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = IoGetPull(gpioOutNum, &val); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_500 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO060, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_0; + WifiIotIoPull val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoSetPull(gpioOutNum, WIFI_IOT_IO_PULL_NONE); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoGetPull(gpioOutNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_500 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO061, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_7; + WifiIotIoPull val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoSetPull(gpioOutNum, WIFI_IOT_IO_PULL_UP); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoGetPull(gpioOutNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_500 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO062, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_7; + WifiIotIoPull val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoSetPull(gpioOutNum, WIFI_IOT_IO_PULL_DOWN); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoGetPull(gpioOutNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_500 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO063, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_7; + WifiIotIoPull val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoSetPull(gpioOutNum, WIFI_IOT_IO_PULL_MAX); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = IoGetPull(gpioOutNum, &val); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_500 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO064, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_7; + WifiIotIoPull val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoSetPull(gpioOutNum, WIFI_IOT_IO_PULL_NONE); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoGetPull(gpioOutNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_600 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO065, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_14; + WifiIotIoPull val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoSetPull(gpioOutNum, WIFI_IOT_IO_PULL_UP); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoGetPull(gpioOutNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_600 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO066, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_14; + WifiIotIoPull val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoSetPull(gpioOutNum, WIFI_IOT_IO_PULL_DOWN); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoGetPull(gpioOutNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_600 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO067, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_14; + WifiIotIoPull val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoSetPull(gpioOutNum, WIFI_IOT_IO_PULL_MAX); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = IoGetPull(gpioOutNum, &val); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_600 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO068, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_14; + WifiIotIoPull val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoSetPull(gpioOutNum, WIFI_IOT_IO_PULL_NONE); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoGetPull(gpioOutNum, &val); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_600 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO069, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_MAX; + WifiIotIoPull val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoSetPull(gpioOutNum, WIFI_IOT_IO_PULL_UP); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = IoGetPull(gpioOutNum, &val); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_600 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO070, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_MAX; + WifiIotIoPull val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoSetPull(gpioOutNum, WIFI_IOT_IO_PULL_DOWN); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = IoGetPull(gpioOutNum, &val); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_600 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO071, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_MAX; + WifiIotIoPull val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoSetPull(gpioOutNum, WIFI_IOT_IO_PULL_MAX); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = IoGetPull(gpioOutNum, &val); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_600 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO072, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_MAX; + WifiIotIoPull val = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoSetPull(gpioOutNum, WIFI_IOT_IO_PULL_NONE); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = IoGetPull(gpioOutNum, &val); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_500 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO073, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_0; + char gpioOutNumFunc = WIFI_IOT_IO_FUNC_GPIO_0_GPIO; + unsigned char gpioGetFunc[TEST_GPIO_SIZE+1] = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoSetFunc(gpioOutNum, gpioOutNumFunc); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoGetFunc(gpioOutNum, gpioGetFunc); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_500 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO074, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_7; + char gpioOutNumFunc = WIFI_IOT_IO_FUNC_GPIO_7_SPI0_RXD; + unsigned char gpioGetFunc[TEST_GPIO_SIZE+1] = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoSetFunc(gpioOutNum, gpioOutNumFunc); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoGetFunc(gpioOutNum, gpioGetFunc); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_600 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO075, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_14; + char gpioOutNumFunc = WIFI_IOT_IO_FUNC_GPIO_14_I2C0_SCL; + unsigned char gpioGetFunc[TEST_GPIO_SIZE+1] = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoSetFunc(gpioOutNum, gpioOutNumFunc); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoGetFunc(gpioOutNum, gpioGetFunc); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_600 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO076, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_MAX; + char gpioOutNumFunc = WIFI_IOT_IO_FUNC_GPIO_9_I2S0_MCLK; + unsigned char gpioGetFunc[TEST_GPIO_SIZE+1] = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IoSetFunc(gpioOutNum, gpioOutNumFunc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = IoGetFunc(gpioOutNum, gpioGetFunc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_500 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO077, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_0; + WifiIotIoDriverStrength gpioGetDriverStrength = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IOSetDriverStrength(gpioOutNum, WIFI_IOT_IO_DRIVER_STRENGTH_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = IOGetDriverStrength(gpioOutNum, &gpioGetDriverStrength); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_500 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO078, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_0; + WifiIotIoDriverStrength gpioGetDriverStrength = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IOSetDriverStrength(gpioOutNum, WIFI_IOT_IO_DRIVER_STRENGTH_7); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = IOGetDriverStrength(gpioOutNum, &gpioGetDriverStrength); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_500 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO079, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_0; + WifiIotIoDriverStrength gpioGetDriverStrength = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IOSetDriverStrength(gpioOutNum, WIFI_IOT_IO_DRIVER_STRENGTH_MAX); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = IOGetDriverStrength(gpioOutNum, &gpioGetDriverStrength); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_500 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO080, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_7; + WifiIotIoDriverStrength gpioGetDriverStrength = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IOSetDriverStrength(gpioOutNum, WIFI_IOT_IO_DRIVER_STRENGTH_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = IOGetDriverStrength(gpioOutNum, &gpioGetDriverStrength); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_500 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO081, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_7; + WifiIotIoDriverStrength gpioGetDriverStrength = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IOSetDriverStrength(gpioOutNum, WIFI_IOT_IO_DRIVER_STRENGTH_7); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = IOGetDriverStrength(gpioOutNum, &gpioGetDriverStrength); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_500 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO082, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_7; + WifiIotIoDriverStrength gpioGetDriverStrength = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IOSetDriverStrength(gpioOutNum, WIFI_IOT_IO_DRIVER_STRENGTH_MAX); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = IOGetDriverStrength(gpioOutNum, &gpioGetDriverStrength); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_600 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO083, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_14; + WifiIotIoDriverStrength gpioGetDriverStrength = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IOSetDriverStrength(gpioOutNum, WIFI_IOT_IO_DRIVER_STRENGTH_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = IOGetDriverStrength(gpioOutNum, &gpioGetDriverStrength); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_600 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO084, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_14; + WifiIotIoDriverStrength gpioGetDriverStrength = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IOSetDriverStrength(gpioOutNum, WIFI_IOT_IO_DRIVER_STRENGTH_7); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = IOGetDriverStrength(gpioOutNum, &gpioGetDriverStrength); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_600 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO085, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_GPIO_14; + WifiIotIoDriverStrength gpioGetDriverStrength = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IOSetDriverStrength(gpioOutNum, WIFI_IOT_IO_DRIVER_STRENGTH_MAX); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = IOGetDriverStrength(gpioOutNum, &gpioGetDriverStrength); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_600 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO086, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_MAX; + WifiIotIoDriverStrength gpioGetDriverStrength = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IOSetDriverStrength(gpioOutNum, WIFI_IOT_IO_DRIVER_STRENGTH_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = IOGetDriverStrength(gpioOutNum, &gpioGetDriverStrength); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_600 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO087, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_MAX; + WifiIotIoDriverStrength gpioGetDriverStrength = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IOSetDriverStrength(gpioOutNum, WIFI_IOT_IO_DRIVER_STRENGTH_7); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = IOGetDriverStrength(gpioOutNum, &gpioGetDriverStrength); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_600 + * @tc.name : GPIO_EX operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotGpioFuncTestSuite, testWifiIotGPIO088, LEVEL1) +{ + unsigned int ret; + int gpioOutNum = WIFI_IOT_IO_NAME_MAX; + WifiIotIoDriverStrength gpioGetDriverStrength = {0}; + + ret = GpioDeinit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = GpioInit(); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = IOSetDriverStrength(gpioOutNum, WIFI_IOT_IO_DRIVER_STRENGTH_MAX); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } + + ret = IOGetDriverStrength(gpioOutNum, &gpioGetDriverStrength); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_GPIO_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_GPIO_NOT_SUPPORT)))) + { + TEST_FAIL(); + } +}; + +RUN_TEST_SUITE(WifiIotGpioFuncTestSuite); diff --git a/iot_hardware_lite/wifiiot_hal/src/wifiiot_i2c_func_test.c b/iot_hardware_lite/wifiiot_hal/src/wifiiot_i2c_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..2ea5fe8f9ea6689e4138ff858b93fdb210c62768 --- /dev/null +++ b/iot_hardware_lite/wifiiot_hal/src/wifiiot_i2c_func_test.c @@ -0,0 +1,474 @@ +/* + * Copyright (c) 2020 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 "hos_types.h" +#include +#include +#include +#include "hctest.h" +#include "hi_task.h" +#include "hi_time.h" + +#include "samgr_lite.h" +#include "wifiiot_errno.h" +#ifdef CONFIG_I2C_SUPPORT +#include "wifiiot_i2c.h" +#include "wifiiot_i2c_ex.h" +#endif + +#define SEND_RECV_LEN 3 +#define AT24C02_1K 0xa0 +#define INIT_BAUD_RATE 10000 +#define SET_BAUD_RATE 19200 + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is wifiiot + * @param : module name is wifiiotlite + * @param : test suit name is UtilsFileFuncTestSuite + */ +LITE_TEST_SUIT(wifiiot, wifiiotlite, WifiIotI2cFuncTestSuite); + +#ifdef CONFIG_I2C_SUPPORT +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL WifiIotI2cFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL WifiIotI2cFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +void IOT_ResetFunc(void) +{ + printf("Abnormal callback function\n"); +} + +/** + * @tc.number : SUB_UTILS_IOT_API_900 + * @tc.name : I2C operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotI2cFuncTestSuite, testWifiIotI2C001, LEVEL1) +{ + unsigned int ret; + WifiIotI2cFunc callbackType = {0}; + + ret = I2cDeinit(WIFI_IOT_I2C_IDX_0); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = I2cInit(WIFI_IOT_I2C_IDX_0, INIT_BAUD_RATE); + TEST_ASSERT_EQUAL_INT(0, ret); + + callbackType.resetFunc = IOT_ResetFunc; + (void)I2cRegisterResetBusFunc(WIFI_IOT_I2C_IDX_0, callbackType); + + ret = I2cDeinit(WIFI_IOT_I2C_IDX_0); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_900 + * @tc.name : I2C operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotI2cFuncTestSuite, testWifiIotI2C02, LEVEL1) +{ + unsigned int ret; + WifiIotI2cFunc callbackType = {0}; + + ret = I2cDeinit(WIFI_IOT_I2C_IDX_1); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = I2cInit(WIFI_IOT_I2C_IDX_1, INIT_BAUD_RATE); + TEST_ASSERT_EQUAL_INT(0, ret); + + callbackType.resetFunc = IOT_ResetFunc; + (void)I2cRegisterResetBusFunc(WIFI_IOT_I2C_IDX_1, callbackType); + + ret = I2cDeinit(WIFI_IOT_I2C_IDX_1); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_700 + * @tc.name : I2C operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotI2cFuncTestSuite, testWifiIotI2C003, LEVEL1) +{ + unsigned int ret; + ret = I2cDeinit(WIFI_IOT_I2C_IDX_0); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = I2cInit(WIFI_IOT_I2C_IDX_0, INIT_BAUD_RATE); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = I2cSetBaudrate(WIFI_IOT_I2C_IDX_0, SET_BAUD_RATE); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2C_NOT_INIT) && (ret <= WIFI_IOT_ERR_I2C_WAIT_ACK_ERR)))) + { + TEST_FAIL(); + } + + ret = I2cDeinit(WIFI_IOT_I2C_IDX_0); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_700 + * @tc.name : I2C operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotI2cFuncTestSuite, testWifiIotI2C004, LEVEL1) +{ + unsigned int ret; + ret = I2cDeinit(WIFI_IOT_I2C_IDX_1); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = I2cInit(WIFI_IOT_I2C_IDX_1, INIT_BAUD_RATE); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = I2cSetBaudrate(WIFI_IOT_I2C_IDX_1, SET_BAUD_RATE); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2C_NOT_INIT) && (ret <= WIFI_IOT_ERR_I2C_WAIT_ACK_ERR)))) + { + TEST_FAIL(); + } + + ret = I2cDeinit(WIFI_IOT_I2C_IDX_1); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_700 + * @tc.name : I2C operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotI2cFuncTestSuite, testWifiIotI2C005, LEVEL1) +{ + unsigned int ret; + char senddata[SEND_RECV_LEN] = {0}; + WifiIotI2cData stdata = {0}; + + ret = I2cDeinit(WIFI_IOT_I2C_IDX_0); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = I2cInit(WIFI_IOT_I2C_IDX_0, INIT_BAUD_RATE); + TEST_ASSERT_EQUAL_INT(0, ret); + + senddata[0] = 0x0; + senddata[1] = 0x3; + stdata.sendBuf = (uint8 *)senddata; + stdata.sendLen = SEND_RECV_LEN; + ret= I2cWrite(WIFI_IOT_I2C_IDX_0, AT24C02_1K, &stdata); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2C_NOT_INIT) && (ret <= WIFI_IOT_ERR_I2C_WAIT_ACK_ERR)))) + { + TEST_FAIL(); + } + + ret = I2cDeinit(WIFI_IOT_I2C_IDX_0); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_700 + * @tc.name : I2C operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotI2cFuncTestSuite, testWifiIotI2C006, LEVEL1) +{ + unsigned int ret; + char senddata[SEND_RECV_LEN] = {0}; + WifiIotI2cData stdata = {0}; + + ret = I2cDeinit(WIFI_IOT_I2C_IDX_1); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = I2cInit(WIFI_IOT_I2C_IDX_1, INIT_BAUD_RATE); + TEST_ASSERT_EQUAL_INT(0, ret); + + senddata[0] = 0x0; + senddata[1] = 0x3; + stdata.sendBuf = (uint8 *)senddata; + stdata.sendLen = SEND_RECV_LEN; + ret= I2cWrite(WIFI_IOT_I2C_IDX_1, AT24C02_1K, &stdata); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2C_NOT_INIT) && (ret <= WIFI_IOT_ERR_I2C_WAIT_ACK_ERR)))) + { + TEST_FAIL(); + } + + ret = I2cDeinit(WIFI_IOT_I2C_IDX_1); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_800 + * @tc.name : I2C operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotI2cFuncTestSuite, testWifiIotI2C007, LEVEL1) +{ + unsigned int ret; + char recvdata[SEND_RECV_LEN] = {0}; + WifiIotI2cData stdata = {0}; + + ret = I2cDeinit(WIFI_IOT_I2C_IDX_0); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = I2cInit(WIFI_IOT_I2C_IDX_0, INIT_BAUD_RATE); + TEST_ASSERT_EQUAL_INT(0, ret); + + stdata.receiveBuf = (uint8 *)recvdata; + stdata.receiveLen = SEND_RECV_LEN; + ret = I2cRead(WIFI_IOT_I2C_IDX_0, AT24C02_1K, &stdata); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2C_NOT_INIT) && (ret <= WIFI_IOT_ERR_I2C_WAIT_ACK_ERR)))) + { + TEST_FAIL(); + } + + ret = I2cDeinit(WIFI_IOT_I2C_IDX_0); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_800 + * @tc.name : I2C operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotI2cFuncTestSuite, testWifiIotI2C008, LEVEL1) +{ + unsigned int ret; + char recvdata[SEND_RECV_LEN] = {0}; + WifiIotI2cData stdata = {0}; + + ret = I2cDeinit(WIFI_IOT_I2C_IDX_1); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = I2cInit(WIFI_IOT_I2C_IDX_1, INIT_BAUD_RATE); + TEST_ASSERT_EQUAL_INT(0, ret); + + stdata.receiveBuf = (uint8 *)recvdata; + stdata.receiveLen = SEND_RECV_LEN; + ret = I2cRead(WIFI_IOT_I2C_IDX_1, AT24C02_1K, &stdata); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2C_NOT_INIT) && (ret <= WIFI_IOT_ERR_I2C_WAIT_ACK_ERR)))) + { + TEST_FAIL(); + } + + ret = I2cDeinit(WIFI_IOT_I2C_IDX_1); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_800 + * @tc.name : I2C operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotI2cFuncTestSuite, testWifiIotI2C009, LEVEL1) +{ + unsigned int ret; + char senddata[SEND_RECV_LEN] = {0}; + char recvdata[SEND_RECV_LEN] = {0}; + WifiIotI2cData stdata = {0}; + + ret = I2cDeinit(WIFI_IOT_I2C_IDX_0); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = I2cInit(WIFI_IOT_I2C_IDX_0, INIT_BAUD_RATE); + TEST_ASSERT_EQUAL_INT(0, ret); + + senddata[0] = 0x0; + senddata[1] = 0x3; + stdata.sendBuf = (uint8 *)senddata; + stdata.sendLen = SEND_RECV_LEN; + stdata.receiveBuf = (uint8 *)recvdata; + stdata.receiveLen = SEND_RECV_LEN; + ret = I2cWriteread(WIFI_IOT_I2C_IDX_0, AT24C02_1K, &stdata); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2C_NOT_INIT) && (ret <= WIFI_IOT_ERR_I2C_WAIT_ACK_ERR)))) + { + TEST_FAIL(); + } + + ret = I2cDeinit(WIFI_IOT_I2C_IDX_0); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_800 + * @tc.name : I2C operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotI2cFuncTestSuite, testWifiIotI2C0010, LEVEL1) +{ + unsigned int ret; + char senddata[SEND_RECV_LEN] = {0}; + char recvdata[SEND_RECV_LEN] = {0}; + WifiIotI2cData stdata = {0}; + + ret = I2cDeinit(WIFI_IOT_I2C_IDX_1); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = I2cInit(WIFI_IOT_I2C_IDX_1, INIT_BAUD_RATE); + TEST_ASSERT_EQUAL_INT(0, ret); + + senddata[0] = 0x0; + senddata[1] = 0x3; + stdata.sendBuf = (uint8 *)senddata; + stdata.sendLen = SEND_RECV_LEN; + stdata.receiveBuf = (uint8 *)recvdata; + stdata.receiveLen = SEND_RECV_LEN; + ret = I2cWriteread(WIFI_IOT_I2C_IDX_1, AT24C02_1K, &stdata); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2C_NOT_INIT) && (ret <= WIFI_IOT_ERR_I2C_WAIT_ACK_ERR)))) + { + TEST_FAIL(); + } + + ret = I2cDeinit(WIFI_IOT_I2C_IDX_1); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_800 + * @tc.name : I2C operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotI2cFuncTestSuite, testWifiIotI2C011, LEVEL1) +{ + unsigned int ret; + char senddata[SEND_RECV_LEN] = {0}; + char recvdata[SEND_RECV_LEN] = {0}; + WifiIotI2cData stdata = {0}; + + ret = I2cDeinit(WIFI_IOT_I2C_IDX_0); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = I2cInit(WIFI_IOT_I2C_IDX_0, INIT_BAUD_RATE); + TEST_ASSERT_EQUAL_INT(0, ret); + + senddata[0] = 0x0; + senddata[1] = 0x3; + stdata.sendBuf = (uint8 *)senddata; + stdata.sendLen = SEND_RECV_LEN; + ret= I2cWrite(WIFI_IOT_I2C_IDX_0, AT24C02_1K, &stdata); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2C_NOT_INIT) && (ret <= WIFI_IOT_ERR_I2C_WAIT_ACK_ERR)))) + { + TEST_FAIL(); + } + stdata.receiveBuf = (uint8 *)recvdata; + stdata.receiveLen = SEND_RECV_LEN; + ret = I2cRead(WIFI_IOT_I2C_IDX_0, AT24C02_1K, &stdata); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2C_NOT_INIT) && (ret <= WIFI_IOT_ERR_I2C_WAIT_ACK_ERR)))) + { + TEST_FAIL(); + } + + if (strcmp(stdata.receiveBuf, stdata.sendBuf) != 0) { + TEST_FAIL(); + } + + ret = I2cDeinit(WIFI_IOT_I2C_IDX_0); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_800 + * @tc.name : I2C operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotI2cFuncTestSuite, testWifiIotI2C012, LEVEL1) +{ + unsigned int ret; + char senddata[SEND_RECV_LEN] = {0}; + char recvdata[SEND_RECV_LEN] = {0}; + WifiIotI2cData stdata = {0}; + + ret = I2cDeinit(WIFI_IOT_I2C_IDX_1); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = I2cInit(WIFI_IOT_I2C_IDX_1, INIT_BAUD_RATE); + TEST_ASSERT_EQUAL_INT(0, ret); + + senddata[0] = 0x0; + senddata[1] = 0x3; + stdata.sendBuf = (uint8 *)senddata; + stdata.sendLen = SEND_RECV_LEN; + ret= I2cWrite(WIFI_IOT_I2C_IDX_1, AT24C02_1K, &stdata); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2C_NOT_INIT) && (ret <= WIFI_IOT_ERR_I2C_WAIT_ACK_ERR)))) + { + TEST_FAIL(); + } + stdata.receiveBuf = (uint8 *)recvdata; + stdata.receiveLen = SEND_RECV_LEN; + ret = I2cRead(WIFI_IOT_I2C_IDX_1, AT24C02_1K, &stdata); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_I2C_NOT_INIT) && (ret <= WIFI_IOT_ERR_I2C_WAIT_ACK_ERR)))) + { + TEST_FAIL(); + } + + if (strcmp(stdata.receiveBuf, stdata.sendBuf) != 0) { + TEST_FAIL(); + } + + ret = I2cDeinit(WIFI_IOT_I2C_IDX_1); + TEST_ASSERT_EQUAL_INT(0, ret); +}; +#endif + +RUN_TEST_SUITE(WifiIotI2cFuncTestSuite); diff --git a/iot_hardware_lite/wifiiot_hal/src/wifiiot_sdio_func_test.c b/iot_hardware_lite/wifiiot_hal/src/wifiiot_sdio_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..975e1bbd2a82faefb1d26e88bfad010b42bf7b72 --- /dev/null +++ b/iot_hardware_lite/wifiiot_hal/src/wifiiot_sdio_func_test.c @@ -0,0 +1,434 @@ +/* + * Copyright (c) 2020 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 "hos_types.h" +#include +#include +#include +#include "hctest.h" +#include "hi_task.h" +#include "hi_time.h" + +#include "samgr_lite.h" +#include "wifiiot_errno.h" +#include "wifiiot_sdio.h" + +#define TEST_SDIO_LENGTH 8 +#define TEST_REG_NUM 10 +#define TEST_BYTE_NUM 100 +#define MAX_ADMA_INDEX 130 +#define MAX_MSG_VALUE 31 +#define ADMA_TABLE_PARAM 666 + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is wifiiot + * @param : module name is wifiiotlite + * @param : test suit name is UtilsFileFuncTestSuite + */ +LITE_TEST_SUIT(wifiiot, wifiiotlite, WifiIotSdioFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL WifiIotSdioFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL WifiIotSdioFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +int ReadStartCallbackFunc(unsigned int len, unsigned char *admaTable) +{ + (void)admaTable; + printf("ReadStartCallbackFunc\n"); + return sizeof(len); +} + +int ReadOverCallbackFunc(void) +{ + printf("ReadOverCallbackFunc\n"); + return 0; +} + +void ReadErrCallbackFunc(void) +{ + printf("ReadErrCallbackFunc\n"); +} + +int WriteStartCallbackFunc(unsigned int len, unsigned char *admaTable) +{ + (void)admaTable; + printf("WriteStartCallbackFunc\n"); + return sizeof(len); +} + +int WriteOverCallbackFunc(void) +{ + printf("WriteOverCallbackFunc\n"); + return 0; +} + +void ProcessMsgCallbackFunc(unsigned int msg) +{ + (void)msg; + printf("ProcessMsgCallbackFunc\n"); +} + +void SoftRstCallbackFunc(void) +{ + printf("SoftRstCallbackFunc\n"); +} + +void NotifyHostMessageEventFunc(void) +{ + printf("NotifyHostMessageEventFunc\n"); +} + +/** + * @tc.number : SUB_UTILS_IOT_API_1800 + * @tc.name : Sdio operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSdioFuncTestSuite, testWifiIotSdio001, LEVEL1) +{ + unsigned int ret; + + WifiIotSdioIntcallback callback; + callback.RdstartCallback = ReadStartCallbackFunc; + callback.RdoverCallback = ReadOverCallbackFunc; + callback.RderrCallback = ReadErrCallbackFunc; + callback.WrstartCallback = WriteStartCallbackFunc; + callback.WroverCallback = WriteOverCallbackFunc; + callback.ProcessmsgCallback = ProcessMsgCallbackFunc; + callback.SoftRstCallback = SoftRstCallbackFunc; + + ret = SdioInit(); + if (ret == 0xffffffff){ + printf("SDIO is absent\n"); + TEST_IGNORE(); + return; + } + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = SdioRegisterCallback(&callback); + if (!(ret == 0 || ret == WIFI_IOT_ERR_SDIO_INVALID_PARAMETER)) + { + TEST_FAIL(); + } + + SdioRegisterNotifyMessageCallback(NotifyHostMessageEventFunc); + SdioSoftReset(); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1900 + * @tc.name : Sdio operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSdioFuncTestSuite, testWifiIotSdio002, LEVEL1) +{ + unsigned int ret; + WifiIotSdioAdmatable admaTable; + admaTable.param = ADMA_TABLE_PARAM; + admaTable.len = TEST_SDIO_LENGTH; + admaTable.address = 0x11; + + ret = SdioReinit(); + if (ret == 0xffffffff){ + printf("SDIO is absent\n"); + TEST_IGNORE(); + return; + } + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = SdioIsPendingMsg(0); + if (!(ret == 0 || ret == 1)) + { + TEST_FAIL(); + } + + ret = SdioIsSendingMsg(0); + if (!(ret == 0 || ret == 1)) + { + TEST_FAIL(); + } + + ret = SdioSetAdmatable((unsigned char*)&admaTable, 0, (const unsigned int *)0x11, TEST_SDIO_LENGTH); + if (!(ret == 0 || ret == WIFI_IOT_ERR_SDIO_INVALID_PARAMETER)) + { + TEST_FAIL(); + } + + ret = SdioSetPadAdmatab(TEST_SDIO_LENGTH, (unsigned char*)&admaTable, 0); + if (!(ret == 0 || ret == WIFI_IOT_ERR_SDIO_INVALID_PARAMETER)) + { + TEST_FAIL(); + } + + SdioSetPowerdownWhenDeepSleep(1); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1900 + * @tc.name : Sdio operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSdioFuncTestSuite, testWifiIotSdio003, LEVEL1) +{ + unsigned int ret; + WifiIotSdioAdmatable admaTable; + admaTable.param = ADMA_TABLE_PARAM; + admaTable.len = TEST_SDIO_LENGTH; + admaTable.address = 0x11; + + ret = SdioReinit(); + if (ret == 0xffffffff){ + printf("SDIO is absent\n"); + TEST_IGNORE(); + return; + } + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = SdioIsPendingMsg(MAX_MSG_VALUE); + if (!(ret == 0 || ret == 1)) + { + TEST_FAIL(); + } + + ret = SdioIsSendingMsg(MAX_MSG_VALUE); + if (!(ret == 0 || ret == 1)) + { + TEST_FAIL(); + } + + ret = SdioSetAdmatable((unsigned char*)&admaTable, MAX_ADMA_INDEX, (const unsigned int *)0x11, TEST_SDIO_LENGTH); + if (!(ret == 0 || ret == WIFI_IOT_ERR_SDIO_INVALID_PARAMETER)) + { + TEST_FAIL(); + } + + ret = SdioSetPadAdmatab(TEST_SDIO_LENGTH, (unsigned char*)&admaTable, MAX_ADMA_INDEX); + if (!(ret == 0 || ret == WIFI_IOT_ERR_SDIO_INVALID_PARAMETER)) + { + TEST_FAIL(); + } + + SdioSetPowerdownWhenDeepSleep(0); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2000 + * @tc.name : Sdio operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSdioFuncTestSuite, testWifiIotSdio004, LEVEL1) +{ + unsigned int ret; + WifiIotSdioAdmatable admaTable; + admaTable.param = ADMA_TABLE_PARAM; + admaTable.len = TEST_SDIO_LENGTH; + admaTable.address = 0x11; + + WifiIotSdioExtendFunc extendInfo; + extendInfo.intStat = 0; + extendInfo.msgStat = 1; + extendInfo.xferCount = TEST_BYTE_NUM; + extendInfo.creditInfo = 1; + extendInfo.creditIsvalid = 1; + extendInfo.commReg[WIFI_IOT_SDIO_EXTENDREG_COUNT-1] = (uintptr_t)"CommonRegister"; + extendInfo.commregIsvalid = 1; + extendInfo.validCommregCnt = TEST_REG_NUM; + + ret = SdioReinit(); + if (ret == 0xffffffff){ + printf("SDIO is absent\n"); + TEST_IGNORE(); + return; + } + TEST_ASSERT_EQUAL_INT(0, ret); + + WifiIotSdioExtendFunc *getExtendInfo; + getExtendInfo = SdioGetExtendInfo(); + if (0 == getExtendInfo) + { + TEST_FAIL(); + } + + ret = SdioWriteExtinfo(&extendInfo); + if (!(ret == 0 || ret == WIFI_IOT_ERR_SDIO_INVALID_PARAMETER)) + { + TEST_FAIL(); + } + + SdioSendData(TEST_BYTE_NUM); + + ret = SdioSendMsgAck(0); + TEST_ASSERT_EQUAL_INT(1, ret); + + ret = SdioCompleteSend((unsigned char*)&admaTable, 0); + if (!(ret == 0 || ret == WIFI_IOT_ERR_SDIO_INVALID_PARAMETER)) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2000 + * @tc.name : Sdio operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSdioFuncTestSuite, testWifiIotSdio005, LEVEL1) +{ + unsigned int ret; + WifiIotSdioAdmatable admaTable; + admaTable.param = ADMA_TABLE_PARAM; + admaTable.len = TEST_SDIO_LENGTH; + admaTable.address = 0x11; + + WifiIotSdioExtendFunc extendInfo; + extendInfo.intStat = 0; + extendInfo.msgStat = 1; + extendInfo.xferCount = TEST_BYTE_NUM; + extendInfo.creditInfo = 1; + extendInfo.creditIsvalid = 1; + extendInfo.commReg[WIFI_IOT_SDIO_EXTENDREG_COUNT-1] = (uintptr_t)"CommonRegister"; + extendInfo.commregIsvalid = 1; + extendInfo.validCommregCnt = TEST_REG_NUM; + + ret = SdioReinit(); + if (ret == 0xffffffff){ + printf("SDIO is absent\n"); + TEST_IGNORE(); + return; + } + TEST_ASSERT_EQUAL_INT(0, ret); + + WifiIotSdioExtendFunc *getExtendInfo; + getExtendInfo = SdioGetExtendInfo(); + if (0 == getExtendInfo) + { + TEST_FAIL(); + } + + ret = SdioWriteExtinfo(&extendInfo); + if (!(ret == 0 || ret == WIFI_IOT_ERR_SDIO_INVALID_PARAMETER)) + { + TEST_FAIL(); + } + + SdioSendData(TEST_BYTE_NUM); + + ret = SdioSendMsgAck(MAX_MSG_VALUE); + TEST_ASSERT_EQUAL_INT(1, ret); + + ret = SdioCompleteSend((unsigned char*)&admaTable, MAX_ADMA_INDEX); + if (!(ret == 0 || ret == WIFI_IOT_ERR_SDIO_INVALID_PARAMETER)) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2100 + * @tc.name : Sdio operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSdioFuncTestSuite, testWifiIotSdio006, LEVEL1) +{ + unsigned int ret; + + ret = SdioReinit(); + if (ret == 0xffffffff){ + printf("SDIO is absent\n"); + TEST_IGNORE(); + return; + } + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = SdioSendSyncMsg(0); + TEST_ASSERT_EQUAL_INT(1, ret); + + ret = SdioProcessMsg(0, MAX_MSG_VALUE); + TEST_ASSERT_EQUAL_INT(1, ret); + + ret = SdioSchedMsg(); + if (!(ret == 0 || ret == 1)) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2100 + * @tc.name : Sdio operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSdioFuncTestSuite, testWifiIotSdio007, LEVEL1) +{ + unsigned int ret; + + ret = SdioReinit(); + if (ret == 0xffffffff){ + printf("SDIO is absent\n"); + TEST_IGNORE(); + return; + } + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = SdioSendSyncMsg(MAX_MSG_VALUE); + TEST_ASSERT_EQUAL_INT(1, ret); + + ret = SdioProcessMsg(MAX_MSG_VALUE, 0); + TEST_ASSERT_EQUAL_INT(1, ret); + + ret = SdioSchedMsg(); + if (!(ret == 0 || ret == 1)) + { + TEST_FAIL(); + } +}; + +RUN_TEST_SUITE(WifiIotSdioFuncTestSuite); diff --git a/iot_hardware_lite/wifiiot_hal/src/wifiiot_spi_fdx_func_test.c b/iot_hardware_lite/wifiiot_hal/src/wifiiot_spi_fdx_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..76ed99123c6bb3c811911f042adc41496a4abd14 --- /dev/null +++ b/iot_hardware_lite/wifiiot_hal/src/wifiiot_spi_fdx_func_test.c @@ -0,0 +1,2556 @@ +/* + * Copyright (c) 2020 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 "hos_types.h" +#include +#include +#include +#include "hctest.h" +#include "hi_task.h" +#include "hi_time.h" + +#include "samgr_lite.h" +#include "wifiiot_errno.h" +#ifdef CONFIG_SPI_SUPPORT +#include "wifiiot_spi.h" +#endif + +#define TEST_SPI_SIZE 20 +#define TEST_FREQ_SIZE 2000000 + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is wifiiot + * @param : module name is wifiiotlite + * @param : test suit name is UtilsFileFuncTestSuite + */ +LITE_TEST_SUIT(wifiiot, wifiiotlite, WifiIotSpiFdxFuncTestSuite); + +#ifdef CONFIG_SPI_SUPPORT +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL WifiIotSpiFdxFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL WifiIotSpiFdxFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +void SpiIsrFuncPrepareProc(void) +{ + printf("SpiIsrFuncPrepareProc \n"); +} + +void SpiIsrFuncRestoreProc(void) +{ + printf("SpiIsrFuncRestoreProc \n"); +} + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi073, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_0, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_0, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi074, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_0, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_0, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi075, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_0, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_0, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi076, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_0, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_0, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi077, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_0, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_0, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi078, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_0, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_0, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi079, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_0, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_0, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi080, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_0, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_0, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi081, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_0, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_0, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi082, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_1, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_1, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi083, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_1, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_1, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi084, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_1, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_1, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi085, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_1, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_1, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi086, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_1, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_1, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi087, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_1, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_1, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi088, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_1, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_1, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi089, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_1, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_1, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi090, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_1, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_1, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi091, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_0, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_0, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi092, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_0, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_0, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi093, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_0, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_0, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi094, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_0, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_0, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi095, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_0, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_0, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi096, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_0, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_0, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi097, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_0, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_0, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi098, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_0, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_0, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi099, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_0, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_0, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi100, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_1, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_1, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi101, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_1, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_1, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi102, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_1, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_1, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi103, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_1, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_1, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi104, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_1, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_1, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi105, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_1, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_1, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi106, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_1, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_1, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi107, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_1, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_1, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2400 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiFdxFuncTestSuite, testWifiIotSpi108, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiRegisterUsrFunc(WIFI_IOT_SPI_ID_1, SpiIsrFuncPrepareProc, SpiIsrFuncRestoreProc); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetLoopBackMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetIrqMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWriteread(WIFI_IOT_SPI_ID_1, send_buf, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; +#endif + +RUN_TEST_SUITE(WifiIotSpiFdxFuncTestSuite); diff --git a/iot_hardware_lite/wifiiot_hal/src/wifiiot_spi_hdx_func_test.c b/iot_hardware_lite/wifiiot_hal/src/wifiiot_spi_hdx_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..786ce275337ecd089fcd3e225e73f0e614486d80 --- /dev/null +++ b/iot_hardware_lite/wifiiot_hal/src/wifiiot_spi_hdx_func_test.c @@ -0,0 +1,2330 @@ +/* + * Copyright (c) 2020 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 "hos_types.h" +#include +#include +#include +#include "hctest.h" +#include "hi_task.h" +#include "hi_time.h" + +#include "samgr_lite.h" +#include "wifiiot_errno.h" +#ifdef CONFIG_SPI_SUPPORT +#include "wifiiot_spi.h" +#endif + +#define TEST_SPI_SIZE 20 +#define TEST_FREQ_SIZE 2000000 + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is wifiiot + * @param : module name is wifiiotlite + * @param : test suit name is UtilsFileFuncTestSuite + */ +LITE_TEST_SUIT(wifiiot, wifiiotlite, WifiIotSpiHdxFuncTestSuite); + +#ifdef CONFIG_SPI_SUPPORT +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL WifiIotSpiHdxFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL WifiIotSpiHdxFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi001, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_0, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi002, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_0, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi003, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_0, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi004, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_0, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi005, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_0, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi006, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_0, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi007, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_0, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi008, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_0, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi009, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_0, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi010, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_1, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi011, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_1, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi012, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_1, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi013, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_1, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi014, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_1, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi015, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_1, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi016, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_1, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi017, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_1, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi018, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_1, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi019, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_0, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi020, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_0, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi021, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_0, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi022, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_0, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi023, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_0, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi024, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_0, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi025, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_0, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi026, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_0, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi027, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_0, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi028, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_1, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi029, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_1, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi030, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_1, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi031, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_1, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi032, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_1, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi033, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_1, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi034, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_1, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi035, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_1, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2300 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiHdxFuncTestSuite, testWifiIotSpi036, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetBasicInfo(WIFI_IOT_SPI_ID_1, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiHostRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf)); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; +#endif + +RUN_TEST_SUITE(WifiIotSpiHdxFuncTestSuite); diff --git a/iot_hardware_lite/wifiiot_hal/src/wifiiot_spi_slave_func_test.c b/iot_hardware_lite/wifiiot_hal/src/wifiiot_spi_slave_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..549cd4c38e0e50546f245cb739d3134101ffb23a --- /dev/null +++ b/iot_hardware_lite/wifiiot_hal/src/wifiiot_spi_slave_func_test.c @@ -0,0 +1,2331 @@ +/* + * Copyright (c) 2020 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 "hos_types.h" +#include +#include +#include +#include "hctest.h" +#include "hi_task.h" +#include "hi_time.h" + +#include "samgr_lite.h" +#include "wifiiot_errno.h" +#ifdef CONFIG_SPI_SUPPORT +#include "wifiiot_spi.h" +#endif + +#define TEST_SPI_SIZE 20 +#define TEST_FREQ_SIZE 2000000 +#define TEST_SPI_TIMEOUT 1000 + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is wifiiot + * @param : module name is wifiiotlite + * @param : test suit name is UtilsFileFuncTestSuite + */ +LITE_TEST_SUIT(wifiiot, wifiiotlite, WifiIotSpiSlaveFuncTestSuite); + +#ifdef CONFIG_SPI_SUPPORT +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL WifiIotSpiSlaveFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL WifiIotSpiSlaveFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi037, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi038, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi039, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi040, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi041, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi042, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi043, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi044, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi045, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_0, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi046, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi047, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi048, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi049, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi050, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi051, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi052, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi053, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi054, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 1; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_1, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi055, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi056, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi057, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi058, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi059, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi060, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi061, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi062, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi063, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_0; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_0; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_LITTLE; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_0, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_0, 1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_0, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_0, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi064, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi065, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi066, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MOTOROLA; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi067, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi068, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi069, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_TI; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi070, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_4BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi071, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_10BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_2200 + * @tc.name : Spi operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotSpiSlaveFuncTestSuite, testWifiIotSpi072, LEVEL1) +{ + unsigned int ret; + char send_buf[] = "SpiDemoTest"; + char recv_buf[TEST_SPI_SIZE] = {0}; + WifiIotSpiCfgBasicInfo spi_para; + spi_para.cpol = WIFI_IOT_SPI_CFG_CLOCK_CPOL_1; + spi_para.cpha = WIFI_IOT_SPI_CFG_CLOCK_CPHA_1; + spi_para.framMode = WIFI_IOT_SPI_CFG_FRAM_MODE_MICROWIRE; + spi_para.dataWidth = WIFI_IOT_SPI_CFG_DATA_WIDTH_E_16BIT; + spi_para.endian = WIFI_IOT_SPI_CFG_ENDIAN_BIG; + spi_para.pad = 0; + spi_para.freq = TEST_FREQ_SIZE; + + WifiIotSpiCfgInitParam init_param; + init_param.isSlave = 0; + init_param.pad = 0; + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiInit(WIFI_IOT_SPI_ID_1, init_param, &spi_para); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSetDmaMode(WIFI_IOT_SPI_ID_1, 0); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveWrite(WIFI_IOT_SPI_ID_1, send_buf, sizeof(send_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiSlaveRead(WIFI_IOT_SPI_ID_1, recv_buf, sizeof(recv_buf), TEST_SPI_TIMEOUT); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } + + ret = SpiDeinit(WIFI_IOT_SPI_ID_1); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_SPI_NOT_INIT) && (ret <= WIFI_IOT_ERR_SPI_NOT_SUPPORT_DMA)))) + { + TEST_FAIL(); + } +}; +#endif + +RUN_TEST_SUITE(WifiIotSpiSlaveFuncTestSuite); diff --git a/iot_hardware_lite/wifiiot_hal/src/wifiiot_uart_func_test.c b/iot_hardware_lite/wifiiot_hal/src/wifiiot_uart_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..803d48d8151cd2cfd3daf2fdee289f0d0a56fd48 --- /dev/null +++ b/iot_hardware_lite/wifiiot_hal/src/wifiiot_uart_func_test.c @@ -0,0 +1,1004 @@ +/* + * Copyright (c) 2020 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 "hos_types.h" +#include +#include +#include +#include "hctest.h" +#include "hi_task.h" +#include "hi_time.h" + +#include "samgr_lite.h" +#include "wifiiot_errno.h" +#include "wifiiot_uart.h" +#include "wifiiot_uart_ex.h" + +#define TEST_UART_SIZE 8 +#define INIT_BAUD_RATE 115200 +#define TEST_BUF_SIZE 10000 + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is wifiiot + * @param : module name is wifiiotlite + * @param : test suit name is UtilsFileFuncTestSuite + */ +LITE_TEST_SUIT(wifiiot, wifiiotlite, WifiIotUartFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL WifiIotUartFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL WifiIotUartFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number : SUB_UTILS_IOT_API_1100 + * @tc.name : Uart operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotUartFuncTestSuite, testWifiIotUart007, LEVEL1) +{ + unsigned int ret; + WifiIotUartAttribute uartAttr; + uartAttr.baudRate = INIT_BAUD_RATE, + uartAttr.dataBits = WIFI_IOT_UART_DATA_BIT_8; + uartAttr.stopBits = WIFI_IOT_UART_STOP_BIT_1; + uartAttr.parity = WIFI_IOT_UART_PARITY_NONE; + uartAttr.pad ='M'; + + WifiIotUartExtraAttr extraAttr; + (void)memset_s(&extraAttr, sizeof(WifiIotUartExtraAttr), 0, sizeof(WifiIotUartExtraAttr)); + extraAttr.txFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.rxFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.flowFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.txBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.rxBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.txBufSize = TEST_BUF_SIZE; + extraAttr.rxBufSize = TEST_BUF_SIZE; + extraAttr.txUseDma = WIFI_IOT_UART_NONE_DMA; + extraAttr.rxUseDma = WIFI_IOT_UART_NONE_DMA; + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartInit(WIFI_IOT_UART_IDX_2, &uartAttr, &extraAttr); + TEST_ASSERT_EQUAL_INT(0, ret); + + WifiIotUartAttribute getUartAttr = {0}; + WifiIotUartExtraAttr getExtraAttr = {0}; + ret = UartGetAttribute(WIFI_IOT_UART_IDX_2, &getUartAttr, &getExtraAttr); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1100 + * @tc.name : Uart operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotUartFuncTestSuite, testWifiIotUart008, LEVEL1) +{ + unsigned int ret; + WifiIotUartAttribute uartAttr; + uartAttr.baudRate = INIT_BAUD_RATE, + uartAttr.dataBits = WIFI_IOT_UART_DATA_BIT_8; + uartAttr.stopBits = WIFI_IOT_UART_STOP_BIT_1; + uartAttr.parity = WIFI_IOT_UART_PARITY_ODD; + uartAttr.pad ='M'; + + WifiIotUartExtraAttr extraAttr; + (void)memset_s(&extraAttr, sizeof(WifiIotUartExtraAttr), 0, sizeof(WifiIotUartExtraAttr)); + extraAttr.txFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.rxFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.flowFifoLine = WIFI_IOT_FIFO_LINE_SEVEN_EIGHTS; + extraAttr.txBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.rxBlock = WIFI_IOT_UART_BLOCK_STATE_BLOCK; + extraAttr.txBufSize = TEST_BUF_SIZE; + extraAttr.rxBufSize = TEST_BUF_SIZE; + extraAttr.txUseDma = WIFI_IOT_UART_NONE_DMA; + extraAttr.rxUseDma = WIFI_IOT_UART_NONE_DMA; + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartInit(WIFI_IOT_UART_IDX_2, &uartAttr, &extraAttr); + TEST_ASSERT_EQUAL_INT(0, ret); + + WifiIotUartAttribute getUartAttr = {0}; + WifiIotUartExtraAttr getExtraAttr = {0}; + ret = UartGetAttribute(WIFI_IOT_UART_IDX_2, &getUartAttr, &getExtraAttr); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1100 + * @tc.name : Uart operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotUartFuncTestSuite, testWifiIotUart009, LEVEL1) +{ + unsigned int ret; + WifiIotUartAttribute uartAttr; + uartAttr.baudRate = INIT_BAUD_RATE, + uartAttr.dataBits = WIFI_IOT_UART_DATA_BIT_8; + uartAttr.stopBits = WIFI_IOT_UART_STOP_BIT_1; + uartAttr.parity = WIFI_IOT_UART_PARITY_EVEN; + uartAttr.pad ='M'; + + WifiIotUartExtraAttr extraAttr; + (void)memset_s(&extraAttr, sizeof(WifiIotUartExtraAttr), 0, sizeof(WifiIotUartExtraAttr)); + extraAttr.txFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.rxFifoLine = WIFI_IOT_FIFO_LINE_SEVEN_EIGHTS; + extraAttr.flowFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.txBlock = WIFI_IOT_UART_BLOCK_STATE_BLOCK; + extraAttr.rxBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.txBufSize = TEST_BUF_SIZE; + extraAttr.rxBufSize = TEST_BUF_SIZE; + extraAttr.txUseDma = WIFI_IOT_UART_NONE_DMA; + extraAttr.rxUseDma = WIFI_IOT_UART_NONE_DMA; + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartInit(WIFI_IOT_UART_IDX_2, &uartAttr, &extraAttr); + TEST_ASSERT_EQUAL_INT(0, ret); + + WifiIotUartAttribute getUartAttr = {0}; + WifiIotUartExtraAttr getExtraAttr = {0}; + ret = UartGetAttribute(WIFI_IOT_UART_IDX_2, &getUartAttr, &getExtraAttr); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1100 + * @tc.name : Uart operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotUartFuncTestSuite, testWifiIotUart010, LEVEL1) +{ + unsigned int ret; + WifiIotUartAttribute uartAttr; + uartAttr.baudRate = INIT_BAUD_RATE, + uartAttr.dataBits = WIFI_IOT_UART_DATA_BIT_8; + uartAttr.stopBits = WIFI_IOT_UART_STOP_BIT_2; + uartAttr.parity = WIFI_IOT_UART_PARITY_NONE; + uartAttr.pad ='M'; + + WifiIotUartExtraAttr extraAttr; + (void)memset_s(&extraAttr, sizeof(WifiIotUartExtraAttr), 0, sizeof(WifiIotUartExtraAttr)); + extraAttr.txFifoLine = WIFI_IOT_FIFO_LINE_SEVEN_EIGHTS; + extraAttr.rxFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.flowFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.txBlock = WIFI_IOT_UART_BLOCK_STATE_BLOCK; + extraAttr.rxBlock = WIFI_IOT_UART_BLOCK_STATE_BLOCK; + extraAttr.txBufSize = TEST_BUF_SIZE; + extraAttr.rxBufSize = TEST_BUF_SIZE; + extraAttr.txUseDma = WIFI_IOT_UART_NONE_DMA; + extraAttr.rxUseDma = WIFI_IOT_UART_USE_DMA; + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartInit(WIFI_IOT_UART_IDX_2, &uartAttr, &extraAttr); + if (ret == 0) + { + TEST_ASSERT_EQUAL_INT(0, ret); + }else if ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + return; + }else + { + TEST_FAIL(); + return; + } + + WifiIotUartAttribute getUartAttr = {0}; + WifiIotUartExtraAttr getExtraAttr = {0}; + ret = UartGetAttribute(WIFI_IOT_UART_IDX_2, &getUartAttr, &getExtraAttr); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1100 + * @tc.name : Uart operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotUartFuncTestSuite, testWifiIotUart011, LEVEL1) +{ + unsigned int ret; + WifiIotUartAttribute uartAttr; + uartAttr.baudRate = INIT_BAUD_RATE, + uartAttr.dataBits = WIFI_IOT_UART_DATA_BIT_8; + uartAttr.stopBits = WIFI_IOT_UART_STOP_BIT_2; + uartAttr.parity = WIFI_IOT_UART_PARITY_ODD; + uartAttr.pad ='M'; + + WifiIotUartExtraAttr extraAttr; + (void)memset_s(&extraAttr, sizeof(WifiIotUartExtraAttr), 0, sizeof(WifiIotUartExtraAttr)); + extraAttr.txFifoLine = WIFI_IOT_FIFO_LINE_SEVEN_EIGHTS; + extraAttr.rxFifoLine = WIFI_IOT_FIFO_LINE_SEVEN_EIGHTS; + extraAttr.flowFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.txBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.rxBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.txBufSize = TEST_BUF_SIZE; + extraAttr.rxBufSize = TEST_BUF_SIZE; + extraAttr.txUseDma = WIFI_IOT_UART_USE_DMA; + extraAttr.rxUseDma = WIFI_IOT_UART_NONE_DMA; + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartInit(WIFI_IOT_UART_IDX_2, &uartAttr, &extraAttr); + if (ret == 0) + { + TEST_ASSERT_EQUAL_INT(0, ret); + }else if ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + return; + }else + { + TEST_FAIL(); + return; + } + + WifiIotUartAttribute getUartAttr = {0}; + WifiIotUartExtraAttr getExtraAttr = {0}; + ret = UartGetAttribute(WIFI_IOT_UART_IDX_2, &getUartAttr, &getExtraAttr); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1100 + * @tc.name : Uart operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotUartFuncTestSuite, testWifiIotUart012, LEVEL1) +{ + unsigned int ret; + WifiIotUartAttribute uartAttr; + uartAttr.baudRate = INIT_BAUD_RATE, + uartAttr.dataBits = WIFI_IOT_UART_DATA_BIT_8; + uartAttr.stopBits = WIFI_IOT_UART_STOP_BIT_2; + uartAttr.parity = WIFI_IOT_UART_PARITY_EVEN; + uartAttr.pad ='M'; + + WifiIotUartExtraAttr extraAttr; + (void)memset_s(&extraAttr, sizeof(WifiIotUartExtraAttr), 0, sizeof(WifiIotUartExtraAttr)); + extraAttr.txFifoLine = WIFI_IOT_FIFO_LINE_SEVEN_EIGHTS; + extraAttr.rxFifoLine = WIFI_IOT_FIFO_LINE_SEVEN_EIGHTS; + extraAttr.flowFifoLine = WIFI_IOT_FIFO_LINE_SEVEN_EIGHTS; + extraAttr.txBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.rxBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.txBufSize = TEST_BUF_SIZE; + extraAttr.rxBufSize = TEST_BUF_SIZE; + extraAttr.txUseDma = WIFI_IOT_UART_USE_DMA; + extraAttr.rxUseDma = WIFI_IOT_UART_USE_DMA; + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartInit(WIFI_IOT_UART_IDX_2, &uartAttr, &extraAttr); + if (ret == 0) + { + TEST_ASSERT_EQUAL_INT(0, ret); + }else if ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + return; + }else + { + TEST_FAIL(); + return; + } + + WifiIotUartAttribute getUartAttr = {0}; + WifiIotUartExtraAttr getExtraAttr = {0}; + ret = UartGetAttribute(WIFI_IOT_UART_IDX_2, &getUartAttr, &getExtraAttr); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1100 + * @tc.name : Uart operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotUartFuncTestSuite, testWifiIotUart013, LEVEL1) +{ + unsigned int ret; + WifiIotUartAttribute uartAttr; + uartAttr.baudRate = INIT_BAUD_RATE, + uartAttr.dataBits = WIFI_IOT_UART_DATA_BIT_8; + uartAttr.stopBits = WIFI_IOT_UART_STOP_BIT_1; + uartAttr.parity = WIFI_IOT_UART_PARITY_NONE; + uartAttr.pad ='M'; + + WifiIotUartExtraAttr extraAttr; + (void)memset_s(&extraAttr, sizeof(WifiIotUartExtraAttr), 0, sizeof(WifiIotUartExtraAttr)); + extraAttr.txFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.rxFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.flowFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.txBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.rxBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.txBufSize = TEST_BUF_SIZE; + extraAttr.rxBufSize = TEST_BUF_SIZE; + extraAttr.txUseDma = WIFI_IOT_UART_NONE_DMA; + extraAttr.rxUseDma = WIFI_IOT_UART_NONE_DMA; + + ret = UartDeinit(WIFI_IOT_UART_IDX_MAX); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)))) + { + TEST_FAIL(); + } + + ret = UartInit(WIFI_IOT_UART_IDX_MAX, &uartAttr, &extraAttr); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)))) + { + TEST_FAIL(); + } + + WifiIotUartAttribute getUartAttr = {0}; + WifiIotUartExtraAttr getExtraAttr = {0}; + ret = UartGetAttribute(WIFI_IOT_UART_IDX_MAX, &getUartAttr, &getExtraAttr); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1000 + * @tc.name : Uart operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotUartFuncTestSuite, testWifiIotUart015, LEVEL1) +{ + unsigned int ret; + unsigned char busy = 0; + WifiIotUartAttribute uartAttr; + uartAttr.baudRate = INIT_BAUD_RATE, + uartAttr.dataBits = WIFI_IOT_UART_DATA_BIT_8; + uartAttr.stopBits = WIFI_IOT_UART_STOP_BIT_1; + uartAttr.parity = WIFI_IOT_UART_PARITY_NONE; + uartAttr.pad ='M'; + + WifiIotUartExtraAttr extraAttr; + (void)memset_s(&extraAttr, sizeof(WifiIotUartExtraAttr), 0, sizeof(WifiIotUartExtraAttr)); + extraAttr.txFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.rxFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.flowFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.txBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.rxBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.txBufSize = TEST_BUF_SIZE; + extraAttr.rxBufSize = TEST_BUF_SIZE; + extraAttr.txUseDma = WIFI_IOT_UART_NONE_DMA; + extraAttr.rxUseDma = WIFI_IOT_UART_NONE_DMA; + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartInit(WIFI_IOT_UART_IDX_2, &uartAttr, &extraAttr); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartIsBusy(WIFI_IOT_UART_IDX_2, &busy); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1000 + * @tc.name : Uart operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotUartFuncTestSuite, testWifiIotUart016, LEVEL1) +{ + unsigned int ret; + unsigned char busy = 0; + WifiIotUartAttribute uartAttr; + uartAttr.baudRate = INIT_BAUD_RATE, + uartAttr.dataBits = WIFI_IOT_UART_DATA_BIT_8; + uartAttr.stopBits = WIFI_IOT_UART_STOP_BIT_1; + uartAttr.parity = WIFI_IOT_UART_PARITY_NONE; + uartAttr.pad ='M'; + + WifiIotUartExtraAttr extraAttr; + (void)memset_s(&extraAttr, sizeof(WifiIotUartExtraAttr), 0, sizeof(WifiIotUartExtraAttr)); + extraAttr.txFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.rxFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.flowFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.txBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.rxBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.txBufSize = TEST_BUF_SIZE; + extraAttr.rxBufSize = TEST_BUF_SIZE; + extraAttr.txUseDma = WIFI_IOT_UART_NONE_DMA; + extraAttr.rxUseDma = WIFI_IOT_UART_NONE_DMA; + + ret = UartDeinit(WIFI_IOT_UART_IDX_MAX); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)))) + { + TEST_FAIL(); + } + + ret = UartInit(WIFI_IOT_UART_IDX_MAX, &uartAttr, &extraAttr); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)))) + { + TEST_FAIL(); + } + + ret = UartIsBusy(WIFI_IOT_UART_IDX_MAX, &busy); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1000 + * @tc.name : Uart operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotUartFuncTestSuite, testWifiIotUart018, LEVEL1) +{ + unsigned int ret; + unsigned char empty = 0; + WifiIotUartAttribute uartAttr; + uartAttr.baudRate = INIT_BAUD_RATE, + uartAttr.dataBits = WIFI_IOT_UART_DATA_BIT_8; + uartAttr.stopBits = WIFI_IOT_UART_STOP_BIT_1; + uartAttr.parity = WIFI_IOT_UART_PARITY_ODD; + uartAttr.pad ='M'; + + WifiIotUartExtraAttr extraAttr; + (void)memset_s(&extraAttr, sizeof(WifiIotUartExtraAttr), 0, sizeof(WifiIotUartExtraAttr)); + extraAttr.txFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.rxFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.flowFifoLine = WIFI_IOT_FIFO_LINE_SEVEN_EIGHTS; + extraAttr.txBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.rxBlock = WIFI_IOT_UART_BLOCK_STATE_BLOCK; + extraAttr.txBufSize = TEST_BUF_SIZE; + extraAttr.rxBufSize = TEST_BUF_SIZE; + extraAttr.txUseDma = WIFI_IOT_UART_NONE_DMA; + extraAttr.rxUseDma = WIFI_IOT_UART_NONE_DMA; + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartInit(WIFI_IOT_UART_IDX_2, &uartAttr, &extraAttr); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartIsBufEmpty(WIFI_IOT_UART_IDX_2, &empty); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1000 + * @tc.name : Uart operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotUartFuncTestSuite, testWifiIotUart019, LEVEL1) +{ + unsigned int ret; + unsigned char empty = 0; + WifiIotUartAttribute uartAttr; + uartAttr.baudRate = INIT_BAUD_RATE, + uartAttr.dataBits = WIFI_IOT_UART_DATA_BIT_8; + uartAttr.stopBits = WIFI_IOT_UART_STOP_BIT_1; + uartAttr.parity = WIFI_IOT_UART_PARITY_ODD; + uartAttr.pad ='M'; + + WifiIotUartExtraAttr extraAttr; + (void)memset_s(&extraAttr, sizeof(WifiIotUartExtraAttr), 0, sizeof(WifiIotUartExtraAttr)); + extraAttr.txFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.rxFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.flowFifoLine = WIFI_IOT_FIFO_LINE_SEVEN_EIGHTS; + extraAttr.txBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.rxBlock = WIFI_IOT_UART_BLOCK_STATE_BLOCK; + extraAttr.txBufSize = TEST_BUF_SIZE; + extraAttr.rxBufSize = TEST_BUF_SIZE; + extraAttr.txUseDma = WIFI_IOT_UART_NONE_DMA; + extraAttr.rxUseDma = WIFI_IOT_UART_NONE_DMA; + + ret = UartDeinit(WIFI_IOT_UART_IDX_MAX); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)))) + { + TEST_FAIL(); + } + + ret = UartInit(WIFI_IOT_UART_IDX_MAX, &uartAttr, &extraAttr); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)))) + { + TEST_FAIL(); + } + + ret = UartIsBufEmpty(WIFI_IOT_UART_IDX_MAX, &empty); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1000 + * @tc.name : Uart operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotUartFuncTestSuite, testWifiIotUart021, LEVEL1) +{ + unsigned int ret; + int len; + unsigned char uartWriteBuff[] = "hello uart!"; + WifiIotUartAttribute uartAttr; + uartAttr.baudRate = INIT_BAUD_RATE, + uartAttr.dataBits = WIFI_IOT_UART_DATA_BIT_8; + uartAttr.stopBits = WIFI_IOT_UART_STOP_BIT_1; + uartAttr.parity = WIFI_IOT_UART_PARITY_EVEN; + uartAttr.pad ='M'; + + WifiIotUartExtraAttr extraAttr; + (void)memset_s(&extraAttr, sizeof(WifiIotUartExtraAttr), 0, sizeof(WifiIotUartExtraAttr)); + extraAttr.txFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.rxFifoLine = WIFI_IOT_FIFO_LINE_SEVEN_EIGHTS; + extraAttr.flowFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.txBlock = WIFI_IOT_UART_BLOCK_STATE_BLOCK; + extraAttr.rxBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.txBufSize = TEST_BUF_SIZE; + extraAttr.rxBufSize = TEST_BUF_SIZE; + extraAttr.txUseDma = WIFI_IOT_UART_NONE_DMA; + extraAttr.rxUseDma = WIFI_IOT_UART_NONE_DMA; + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartInit(WIFI_IOT_UART_IDX_2, &uartAttr, &extraAttr); + TEST_ASSERT_EQUAL_INT(0, ret); + + len = UartWrite(WIFI_IOT_UART_IDX_2, uartWriteBuff, sizeof(uartWriteBuff)); + TEST_ASSERT_GREATER_OR_EQUAL_INT(0, len); + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1000 + * @tc.name : Uart operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotUartFuncTestSuite, testWifiIotUart022, LEVEL1) +{ + unsigned int ret; + int len; + unsigned char uartWriteBuff[] = "hello uart!"; + WifiIotUartAttribute uartAttr; + uartAttr.baudRate = INIT_BAUD_RATE, + uartAttr.dataBits = WIFI_IOT_UART_DATA_BIT_8; + uartAttr.stopBits = WIFI_IOT_UART_STOP_BIT_1; + uartAttr.parity = WIFI_IOT_UART_PARITY_EVEN; + uartAttr.pad ='M'; + + WifiIotUartExtraAttr extraAttr; + (void)memset_s(&extraAttr, sizeof(WifiIotUartExtraAttr), 0, sizeof(WifiIotUartExtraAttr)); + extraAttr.txFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.rxFifoLine = WIFI_IOT_FIFO_LINE_SEVEN_EIGHTS; + extraAttr.flowFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.txBlock = WIFI_IOT_UART_BLOCK_STATE_BLOCK; + extraAttr.rxBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.txBufSize = TEST_BUF_SIZE; + extraAttr.rxBufSize = TEST_BUF_SIZE; + extraAttr.txUseDma = WIFI_IOT_UART_NONE_DMA; + extraAttr.rxUseDma = WIFI_IOT_UART_NONE_DMA; + + ret = UartDeinit(WIFI_IOT_UART_IDX_MAX); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)))) + { + TEST_FAIL(); + } + + ret = UartInit(WIFI_IOT_UART_IDX_MAX, &uartAttr, &extraAttr); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)))) + { + TEST_FAIL(); + } + + len = UartWrite(WIFI_IOT_UART_IDX_MAX, uartWriteBuff, sizeof(uartWriteBuff)); + TEST_ASSERT_EQUAL_INT(-1, len); + +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1000 + * @tc.name : Uart operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotUartFuncTestSuite, testWifiIotUart024, LEVEL1) +{ + unsigned int ret; + WifiIotUartAttribute uartAttr; + uartAttr.baudRate = INIT_BAUD_RATE, + uartAttr.dataBits = WIFI_IOT_UART_DATA_BIT_8; + uartAttr.stopBits = WIFI_IOT_UART_STOP_BIT_1; + uartAttr.parity = WIFI_IOT_UART_PARITY_ODD; + uartAttr.pad ='M'; + + WifiIotUartExtraAttr extraAttr; + (void)memset_s(&extraAttr, sizeof(WifiIotUartExtraAttr), 0, sizeof(WifiIotUartExtraAttr)); + extraAttr.txFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.rxFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.flowFifoLine = WIFI_IOT_FIFO_LINE_SEVEN_EIGHTS; + extraAttr.txBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.rxBlock = WIFI_IOT_UART_BLOCK_STATE_BLOCK; + extraAttr.txBufSize = TEST_BUF_SIZE; + extraAttr.rxBufSize = TEST_BUF_SIZE; + extraAttr.txUseDma = WIFI_IOT_UART_NONE_DMA; + extraAttr.rxUseDma = WIFI_IOT_UART_NONE_DMA; + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartInit(WIFI_IOT_UART_IDX_2, &uartAttr, &extraAttr); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartSetFlowCtrl(WIFI_IOT_UART_IDX_2, WIFI_IOT_FLOW_CTRL_RTS_CTS); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartSetFlowCtrl(WIFI_IOT_UART_IDX_2, WIFI_IOT_FLOW_CTRL_RTS_ONLY); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartSetFlowCtrl(WIFI_IOT_UART_IDX_2, WIFI_IOT_FLOW_CTRL_CTS_ONLY); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartSetFlowCtrl(WIFI_IOT_UART_IDX_2, WIFI_IOT_FLOW_CTRL_NONE); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1000 + * @tc.name : Uart operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotUartFuncTestSuite, testWifiIotUart025, LEVEL1) +{ + unsigned int ret; + WifiIotUartAttribute uartAttr; + uartAttr.baudRate = INIT_BAUD_RATE, + uartAttr.dataBits = WIFI_IOT_UART_DATA_BIT_8; + uartAttr.stopBits = WIFI_IOT_UART_STOP_BIT_1; + uartAttr.parity = WIFI_IOT_UART_PARITY_ODD; + uartAttr.pad ='M'; + + WifiIotUartExtraAttr extraAttr; + (void)memset_s(&extraAttr, sizeof(WifiIotUartExtraAttr), 0, sizeof(WifiIotUartExtraAttr)); + extraAttr.txFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.rxFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.flowFifoLine = WIFI_IOT_FIFO_LINE_SEVEN_EIGHTS; + extraAttr.txBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.rxBlock = WIFI_IOT_UART_BLOCK_STATE_BLOCK; + extraAttr.txBufSize = TEST_BUF_SIZE; + extraAttr.rxBufSize = TEST_BUF_SIZE; + extraAttr.txUseDma = WIFI_IOT_UART_NONE_DMA; + extraAttr.rxUseDma = WIFI_IOT_UART_NONE_DMA; + + ret = UartDeinit(WIFI_IOT_UART_IDX_MAX); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)))) + { + TEST_FAIL(); + } + + ret = UartInit(WIFI_IOT_UART_IDX_MAX, &uartAttr, &extraAttr); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)))) + { + TEST_FAIL(); + } + + ret = UartSetFlowCtrl(WIFI_IOT_UART_IDX_MAX, WIFI_IOT_FLOW_CTRL_RTS_CTS); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)))) + { + TEST_FAIL(); + } + + ret = UartSetFlowCtrl(WIFI_IOT_UART_IDX_MAX, WIFI_IOT_FLOW_CTRL_RTS_ONLY); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)))) + { + TEST_FAIL(); + } + + ret = UartSetFlowCtrl(WIFI_IOT_UART_IDX_MAX, WIFI_IOT_FLOW_CTRL_CTS_ONLY); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)))) + { + TEST_FAIL(); + } + + ret = UartSetFlowCtrl(WIFI_IOT_UART_IDX_MAX, WIFI_IOT_FLOW_CTRL_NONE); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)))) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1100 + * @tc.name : Uart operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotUartFuncTestSuite, testWifiIotUart027, LEVEL1) +{ + unsigned int ret; + int len; + unsigned char uartWriteBuff[] = "hello uart!"; + WifiIotUartAttribute uartAttr; + uartAttr.baudRate = INIT_BAUD_RATE, + uartAttr.dataBits = WIFI_IOT_UART_DATA_BIT_8; + uartAttr.stopBits = WIFI_IOT_UART_STOP_BIT_1; + uartAttr.parity = WIFI_IOT_UART_PARITY_EVEN; + uartAttr.pad ='M'; + + WifiIotUartExtraAttr extraAttr; + (void)memset_s(&extraAttr, sizeof(WifiIotUartExtraAttr), 0, sizeof(WifiIotUartExtraAttr)); + extraAttr.txFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.rxFifoLine = WIFI_IOT_FIFO_LINE_SEVEN_EIGHTS; + extraAttr.flowFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.txBlock = WIFI_IOT_UART_BLOCK_STATE_BLOCK; + extraAttr.rxBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.txBufSize = TEST_BUF_SIZE; + extraAttr.rxBufSize = TEST_BUF_SIZE; + extraAttr.txUseDma = WIFI_IOT_UART_NONE_DMA; + extraAttr.rxUseDma = WIFI_IOT_UART_NONE_DMA; + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartInit(WIFI_IOT_UART_IDX_2, &uartAttr, &extraAttr); + TEST_ASSERT_EQUAL_INT(0, ret); + + len = UartWriteImmediately(WIFI_IOT_UART_IDX_2, uartWriteBuff, sizeof(uartWriteBuff)); + TEST_ASSERT_GREATER_OR_EQUAL_INT(0, len); + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1100 + * @tc.name : Uart operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotUartFuncTestSuite, testWifiIotUart028, LEVEL1) +{ + unsigned int ret; + int len; + unsigned char uartWriteBuff[] = "hello uart!"; + WifiIotUartAttribute uartAttr; + uartAttr.baudRate = INIT_BAUD_RATE, + uartAttr.dataBits = WIFI_IOT_UART_DATA_BIT_8; + uartAttr.stopBits = WIFI_IOT_UART_STOP_BIT_1; + uartAttr.parity = WIFI_IOT_UART_PARITY_EVEN; + uartAttr.pad ='M'; + + WifiIotUartExtraAttr extraAttr; + (void)memset_s(&extraAttr, sizeof(WifiIotUartExtraAttr), 0, sizeof(WifiIotUartExtraAttr)); + extraAttr.txFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.rxFifoLine = WIFI_IOT_FIFO_LINE_SEVEN_EIGHTS; + extraAttr.flowFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.txBlock = WIFI_IOT_UART_BLOCK_STATE_BLOCK; + extraAttr.rxBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.txBufSize = TEST_BUF_SIZE; + extraAttr.rxBufSize = TEST_BUF_SIZE; + extraAttr.txUseDma = WIFI_IOT_UART_NONE_DMA; + extraAttr.rxUseDma = WIFI_IOT_UART_NONE_DMA; + + ret = UartDeinit(WIFI_IOT_UART_IDX_MAX); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)))) + { + TEST_FAIL(); + } + + ret = UartInit(WIFI_IOT_UART_IDX_MAX, &uartAttr, &extraAttr); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)))) + { + TEST_FAIL(); + } + + len = UartWriteImmediately(WIFI_IOT_UART_IDX_MAX, uartWriteBuff, sizeof(uartWriteBuff)); + TEST_ASSERT_EQUAL_INT(-1, len); + +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1100 + * @tc.name : Uart operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotUartFuncTestSuite, testWifiIotUart030, LEVEL1) +{ + unsigned int ret; + int len; + unsigned char uartReadBuff[TEST_UART_SIZE] = {0}; + unsigned char uartWriteBuff[] = "hello uart!"; + WifiIotUartAttribute uartAttr; + uartAttr.baudRate = INIT_BAUD_RATE, + uartAttr.dataBits = WIFI_IOT_UART_DATA_BIT_8; + uartAttr.stopBits = WIFI_IOT_UART_STOP_BIT_1; + uartAttr.parity = WIFI_IOT_UART_PARITY_ODD; + uartAttr.pad ='M'; + + WifiIotUartExtraAttr extraAttr; + (void)memset_s(&extraAttr, sizeof(WifiIotUartExtraAttr), 0, sizeof(WifiIotUartExtraAttr)); + extraAttr.txFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.rxFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.flowFifoLine = WIFI_IOT_FIFO_LINE_SEVEN_EIGHTS; + extraAttr.txBlock = WIFI_IOT_UART_BLOCK_STATE_BLOCK; + extraAttr.rxBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.txBufSize = TEST_BUF_SIZE; + extraAttr.rxBufSize = TEST_BUF_SIZE; + extraAttr.txUseDma = WIFI_IOT_UART_NONE_DMA; + extraAttr.rxUseDma = WIFI_IOT_UART_NONE_DMA; + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UartInit(WIFI_IOT_UART_IDX_2, &uartAttr, &extraAttr); + TEST_ASSERT_EQUAL_INT(0, ret); + + UartWrite(WIFI_IOT_UART_IDX_2, uartWriteBuff, sizeof(uartWriteBuff)); + len = UartRead(WIFI_IOT_UART_IDX_2, uartReadBuff, sizeof(uartReadBuff)); + TEST_ASSERT_GREATER_OR_EQUAL_INT(0, len); + + ret = UartDeinit(WIFI_IOT_UART_IDX_2); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_IOT_API_1100 + * @tc.name : Uart operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(WifiIotUartFuncTestSuite, testWifiIotUart031, LEVEL1) +{ + unsigned int ret; + int len; + unsigned char uartReadBuff[TEST_UART_SIZE] = {0}; + WifiIotUartAttribute uartAttr; + uartAttr.baudRate = INIT_BAUD_RATE, + uartAttr.dataBits = WIFI_IOT_UART_DATA_BIT_8; + uartAttr.stopBits = WIFI_IOT_UART_STOP_BIT_1; + uartAttr.parity = WIFI_IOT_UART_PARITY_ODD; + uartAttr.pad ='M'; + + WifiIotUartExtraAttr extraAttr; + (void)memset_s(&extraAttr, sizeof(WifiIotUartExtraAttr), 0, sizeof(WifiIotUartExtraAttr)); + extraAttr.txFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.rxFifoLine = WIFI_IOT_FIFO_LINE_ONE_EIGHT; + extraAttr.flowFifoLine = WIFI_IOT_FIFO_LINE_SEVEN_EIGHTS; + extraAttr.txBlock = WIFI_IOT_UART_BLOCK_STATE_BLOCK; + extraAttr.rxBlock = WIFI_IOT_UART_BLOCK_STATE_NONE_BLOCK; + extraAttr.txBufSize = TEST_BUF_SIZE; + extraAttr.rxBufSize = TEST_BUF_SIZE; + extraAttr.txUseDma = WIFI_IOT_UART_NONE_DMA; + extraAttr.rxUseDma = WIFI_IOT_UART_NONE_DMA; + + ret = UartDeinit(WIFI_IOT_UART_IDX_MAX); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)))) + { + TEST_FAIL(); + } + + ret = UartInit(WIFI_IOT_UART_IDX_MAX, &uartAttr, &extraAttr); + if (!(ret == 0 || ((ret >= WIFI_IOT_ERR_UART_INVALID_PARAMETER) && (ret <= WIFI_IOT_ERR_UART_NOT_BLOCK_MODE)))) + { + TEST_FAIL(); + } + + len = UartRead(WIFI_IOT_UART_IDX_MAX, uartReadBuff, sizeof(uartReadBuff)); + TEST_ASSERT_EQUAL_INT(-1, len); +}; + +RUN_TEST_SUITE(WifiIotUartFuncTestSuite); diff --git a/kernel_lite/BUILD.gn b/kernel_lite/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..62267782503335a83db491d320d450d354614e79 --- /dev/null +++ b/kernel_lite/BUILD.gn @@ -0,0 +1,34 @@ + # Copyright (c) 2020 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. + +group("ActsKernelTest") { + deps = [ + "//test/xts/acts/kernel_lite/ipc_posix:ActsKernelIPCTest", + "//test/xts/acts/kernel_lite/process_posix:ActsProcessApiTest", + "//test/xts/acts/kernel_lite/sched_posix:ActsSchedApiTest", + "//test/xts/acts/kernel_lite/mem_posix:ActsMemApiTest", + "//test/xts/acts/kernel_lite/math_posix:ActsMathApiTest", + "//test/xts/acts/kernel_lite/sys_posix:ActsSysApiTest", + "//test/xts/acts/kernel_lite/time_posix:ActsTimeApiTest", + "//test/xts/acts/kernel_lite/util_check_posix:ActsUtilCheckApiTest", + "//test/xts/acts/kernel_lite/util_convert_posix:ActsUtilConvertApiTest", + "//test/xts/acts/kernel_lite/util_datastruct_posix:ActsUtilDatastructApiTest", + "//test/xts/acts/kernel_lite/util_math_posix:ActsUtilMathApiTest", + "//test/xts/acts/kernel_lite/util_msg_posix:ActsUtilMsgApiTest", + "//test/xts/acts/kernel_lite/util_string_posix:ActsUtilStringApiTest", + "//test/xts/acts/kernel_lite/util_widecheck_posix:ActsUtilWideCheckApiTest", + "//test/xts/acts/kernel_lite/futex_posix:ActsFutexApiTest", + "//test/xts/acts/kernel_lite/dyload_posix:ActsDyloadTest", + "//test/xts/acts/kernel_lite/fs_posix:ActsFSTest", + ] +} \ No newline at end of file diff --git a/kernel_lite/dyload_posix/BUILD.gn b/kernel_lite/dyload_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..ff44eb03fce631745bb0256c5d29255c551f37fc --- /dev/null +++ b/kernel_lite/dyload_posix/BUILD.gn @@ -0,0 +1,35 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsDyloadTest") { + suite_name = "acts" + + sources = [ + "DlopenTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "../utils" + ] + + deps = [ + "//test/xts/acts/kernel_lite/utils:libutils", + "//test/xts/acts/kernel_lite/utils:libfs" + + ] + ldflags = [ "-ldl" ] + cflags_cc = ["-Wno-write-strings" ] +} \ No newline at end of file diff --git a/kernel_lite/dyload_posix/DlopenTest.cpp b/kernel_lite/dyload_posix/DlopenTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..713f1c0bd855dd7cf3befd40fa950548e5d602b9 --- /dev/null +++ b/kernel_lite/dyload_posix/DlopenTest.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2020 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 "log.h" +#include "utils.h" +#include "libfs.h" +#include "KernelConstants.h" + +using namespace testing::ext; + +class DlopenTest : public testing::Test { +}; + +#define RES_DIR_DYLOAD RES_DIR_KERNEL "dyload/" +#define DYLOAD_TEST_DIR "/storage/data/" + +/** + * @tc.number SUB_KERNEL_DL_SO_0400 + * @tc.name the elf doesn't depend on any user-so. dlopen a not exist so. + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(DlopenTest, testDlopenNotExistSo, TestSize.Level3) +{ + dlerror(); // clear any old error message + char* errMsg = dlerror(); + if (errMsg) { + LOG("dlerror should return NULL when called twice."); + FAIL(); + } + + void* h = dlopen("not_exist_dso1.so", RTLD_NOW); + if (h) { + LOG("dlopen a non-exist-so should return NULL!"); + FAIL(); + } + errMsg = dlerror(); + if (!errMsg) { + LOG("dlerror return NULL!"); + FAIL(); + } + char* p = strcasestr(errMsg, "No such file"); + if (!p) { + LOG("dlerror msg invalid, should include 'No such file', actual msg=%s", errMsg); + FAIL(); + } +} diff --git a/kernel_lite/dyload_posix/Test.json b/kernel_lite/dyload_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..b5e5e8b5fab42d16c7faa6c3cf471bb8edbc9604 --- /dev/null +++ b/kernel_lite/dyload_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsDyloadTest.bin" + } +} \ No newline at end of file diff --git a/kernel_lite/fs_posix/BUILD.gn b/kernel_lite/fs_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..e59cdb31dab796cc9d5f8418d38d866e2f555705 --- /dev/null +++ b/kernel_lite/fs_posix/BUILD.gn @@ -0,0 +1,20 @@ + # Copyright (c) 2020 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. + +group("ActsFSTest") { + deps = [ + "./jffs:ActsJFFS2Test", + "./nfs:ActsNFSTest", + "./vfat:ActsVFATTest", + ] +} diff --git a/kernel_lite/fs_posix/jffs/BUILD.gn b/kernel_lite/fs_posix/jffs/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..2669dc4db48736117ee619b67dcdaa97fbb4f6f3 --- /dev/null +++ b/kernel_lite/fs_posix/jffs/BUILD.gn @@ -0,0 +1,36 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsJFFS2Test") { + suite_name = "acts" + sources = [ + "../src/FileSystemTest.cpp", + "../src/FsFcntlTest.cpp", + "../src/FsStdioTest.cpp", + "../src/FsStdlibTest.cpp", + "../src/FsUnistdTest.cpp", + "../src/FsOtherTest.cpp", + ] + include_dirs = [ + "//test/xts/tools/hctest/include", + "//test/xts/acts/kernel_lite/utils" + ] + deps = [ + "//test/xts/acts/kernel_lite/utils:libutils", + "//test/xts/acts/kernel_lite/utils:libfs" + ] + cflags_cc = [ "-Wno-write-strings" ] + defines = [ "LITE_FS_JFFS2", "TOP_DIR=\"/storage\"" ] +} diff --git a/kernel_lite/fs_posix/jffs/Test.json b/kernel_lite/fs_posix/jffs/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..57477d6b4cfb859bb27856e323fbe8393e6051ce --- /dev/null +++ b/kernel_lite/fs_posix/jffs/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsJFFS2Test.bin" + } +} \ No newline at end of file diff --git a/kernel_lite/fs_posix/nfs/BUILD.gn b/kernel_lite/fs_posix/nfs/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..74cc30de1de624fb39612afd93eb9cf5371a6d58 --- /dev/null +++ b/kernel_lite/fs_posix/nfs/BUILD.gn @@ -0,0 +1,36 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsNFSTest") { + suite_name = "acts" + sources = [ + "../src/FileSystemTest.cpp", + "../src/FsFcntlTest.cpp", + "../src/FsStdioTest.cpp", + "../src/FsStdlibTest.cpp", + "../src/FsUnistdTest.cpp", + "../src/FsOtherTest.cpp", + ] + include_dirs = [ + "//test/xts/tools/hctest/include", + "//test/xts/acts/kernel_lite/utils" + ] + deps = [ + "//test/xts/acts/kernel_lite/utils:libutils", + "//test/xts/acts/kernel_lite/utils:libfs" + ] + cflags_cc = [ "-Wno-write-strings" ] + defines = [ "LITE_FS_NFS", "TOP_DIR=\"/test_root/kernel\"" ] +} diff --git a/kernel_lite/fs_posix/nfs/Test.json b/kernel_lite/fs_posix/nfs/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..1359d4d02cb348c50b572194892d3efd92311187 --- /dev/null +++ b/kernel_lite/fs_posix/nfs/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsNFSTest.bin" + } +} \ No newline at end of file diff --git a/kernel_lite/fs_posix/src/FileSystemTest.cpp b/kernel_lite/fs_posix/src/FileSystemTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..df14afcb7685173946a39d3a9824dcb2d4faa6ab --- /dev/null +++ b/kernel_lite/fs_posix/src/FileSystemTest.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2020 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 "FileSystemTest.h" +#include +#include "utils.h" + +using namespace testing::ext; + +// before testCase +void FileSystemTest::SetUp() +{ + LOG("------- case start"); + mCurPath = GetCurrentPath(); + int rt = chdir(TOP_DIR); + if (rt == -1) { + LOG("== chdir to %s failed! rt=%d, errno=%d", TOP_DIR, rt, errno); + } else { + LOG("== chdir to %s OK!", TOP_DIR); + } +} + +// after testCase +void FileSystemTest::TearDown() +{ + RemoveDir(TOP_DIR "/" DIR0); + remove(TOP_DIR "/" FILE0); + int rt = chdir(mCurPath); + if (rt == -1) { + LOG("== chdir to %s failed! rt=%d, errno=%d", mCurPath, rt, errno); + } else { + LOG("== chdir to %s OK!", mCurPath); + } + LOG("------- case end\n"); +} + +int main(int argc, char *argv[]) +{ + testing::GTEST_FLAG(output) = "xml:"; + testing::InitGoogleTest(&argc, argv); + if (access(TOP_DIR, F_OK) == 0) { + RemoveDir(TOP_DIR "/" DIR0); + remove(TOP_DIR "/" FILE0); + return RUN_ALL_TESTS(); + } else { + LOG("======= %s dose not exist. Test Stop.", TOP_DIR); + return 0; + } +} \ No newline at end of file diff --git a/kernel_lite/fs_posix/src/FileSystemTest.h b/kernel_lite/fs_posix/src/FileSystemTest.h new file mode 100755 index 0000000000000000000000000000000000000000..61f4ee47021c138460650d3518b551fbd8f19a34 --- /dev/null +++ b/kernel_lite/fs_posix/src/FileSystemTest.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2020 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 KERNEL_LITE_FILESYSTEMTEST +#define KERNEL_LITE_FILESYSTEMTEST + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "utils.h" +#include "log.h" +#include "KernelConstants.h" +#include "libfs.h" + +class FileSystemTest : public::testing::Test { +protected: + char *mCurPath; + void SetUp(); + void TearDown(); +}; + +// Creating Folders and Files for the Test +#define FILE0 "FILE0" // FILE0 +#define DIR0 "DIR0" // DIR0/ +#define DIR0_FILE0 "DIR0_FILE0" // ├── DIR0_FILE0 +#define DIR0_DIR0 "DIR0_DIR0" // ├── DIR0_DIR0/ +#define DIR0_DIR1 "DIR0_DIR1" // └── DIR0_DIR1/ +#define DIR0_DIR1_FILE0 "DIR0_DIR1_FILE0" // ├── DIR0_DIR1_FILE0 +#define DIR0_DIR1_DIR0 "DIR0_DIR1_DIR0" // └── DIR0_DIR1_DIR0/ + +// Creating Folders and Files for the Test +#define CreateTestFolder() do { \ + int thisFd; \ + ASSERT_NE(mkdir(DIR0, 0777), -1) << "> mkdir errno = " << errno; \ + ASSERT_NE((thisFd = creat((DIR0 "/" DIR0_FILE0), 0777)), -1) << "> creat errno = " << errno; \ + ASSERT_NE(close(thisFd), -1) << "> close errno = " << errno; \ + ASSERT_NE(mkdir((DIR0 "/" DIR0_DIR0), 0777), -1) << "> mkdir errno = " << errno; \ + ASSERT_NE(mkdir((DIR0 "/" DIR0_DIR1), 0777), -1) << "> mkdir errno = " << errno; \ + ASSERT_NE((thisFd = creat((DIR0 "/" DIR0_DIR1"/" DIR0_DIR1_FILE0), 0777)), -1) << "> creat errno = " << errno; \ + ASSERT_NE(close(thisFd), -1) << "> close errno = " << errno; \ + ASSERT_NE(mkdir((DIR0 "/" DIR0_DIR1"/" DIR0_DIR1_DIR0), 0777), -1) << "> mkdir errno = " << errno; \ + } while (0) + +// write and close +#define WriteCloseTest(fd) do { \ + char writeBuf[] = "this is a file"; \ + EXPECT_NE(write(fd, writeBuf, sizeof(writeBuf)), -1) << "> write errno = " << errno; \ + EXPECT_NE(close(fd), -1) << "> close errno = " << errno; \ + } while (0) \ + +// read and close +#define ReadCloseTest(fd) do { \ + char writeBuf[] = "this is a file"; \ + char readBuf[100]; \ + EXPECT_NE(read(fd, readBuf, 20), -1) << "> read errno = " << errno; \ + EXPECT_STREQ(writeBuf, readBuf) << "> writeBuf = " << writeBuf \ + << "\n> readBuf = " << readBuf; \ + EXPECT_NE(close(fd), -1) << "> close errno = " << errno; \ + } while (0) \ + +#endif diff --git a/kernel_lite/fs_posix/src/FsFcntlTest.cpp b/kernel_lite/fs_posix/src/FsFcntlTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..cfa83bf8654ff65322dee4732c9c0da072360706 --- /dev/null +++ b/kernel_lite/fs_posix/src/FsFcntlTest.cpp @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2020 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 "FileSystemTest.h" +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "utils.h" +#include "log.h" +#include "KernelConstants.h" +#include "libfs.h" + +using namespace testing::ext; + +#if defined(LITE_FS_JFFS2) || defined(LITE_FS_VFAT) || defined(LITE_FS_NFS) +/** + * @tc.number SUB_KERNEL_FS_FCNTL_0100 + * @tc.name basic function test : {fcntl} Test of three basic functions + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(FileSystemTest, testFcntl, TestSize.Level3) +{ + int fd = 0; + EXPECT_NE((fd = open(FILE0, O_CREAT | O_RDWR, 0777)), -1) << "> open faild errno = " << errno; + WriteCloseTest(fd); + +#if defined(LITE_FS_NFS) + // F_DUPFD + int fdNew = 0; + EXPECT_NE((fd = open(FILE0, O_RDONLY, 0777)), -1) << "> open faild errno = " << errno; + EXPECT_NE((fdNew = fcntl(fd, F_DUPFD)), -1) << "> fcntl errno = " << errno; + ReadCloseTest(fdNew); +#endif + int flagReadWrite = GetRandom(3) - 1; // 0 is O_RDONLY, 1 is O_WRONLY, 2 is O_RDWR + EXPECT_NE((fd = open(FILE0, flagReadWrite, 0777)), -1) << "> open faild errno = " << errno; + + // F_GETFL + int flagGet = 0; + EXPECT_NE((flagGet = fcntl(fd, F_GETFL)), -1) << "> fcntl errno = " << errno; + EXPECT_EQ(flagReadWrite, (flagGet & O_ACCMODE)) << "> flagReadWrite != (flagGet & O_ACCMODE)"; + + // F_SETFL + int flagSet = flagGet | O_APPEND | O_NONBLOCK; + EXPECT_NE(fcntl(fd, F_SETFL, flagSet), -1) << "> fcntl errno = " << errno; + + // F_GETFL + EXPECT_NE((flagGet = fcntl(fd, F_GETFL)), -1) << "> fcntl errno = " << errno; + EXPECT_EQ(flagGet & O_APPEND, O_APPEND) << "> O_APPEND faild"; + EXPECT_EQ(flagGet & O_NONBLOCK, O_NONBLOCK) << "> O_NONBLOCK faild"; + + EXPECT_NE(close(fd), -1) << "> close errno = " << errno; +} +#endif + +#if defined(LITE_FS_JFFS2) || defined(LITE_FS_VFAT) || defined(LITE_FS_NFS) +/** + * @tc.number SUB_KERNEL_FS_FCNTL_0200 + * @tc.name basic function test : Setting the read and write positions by running the {lseek} function + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(FileSystemTest, testLseek, TestSize.Level3) +{ + int reLseek; + int fd = 0; + char writeBuf[100]; + memset(writeBuf, '1', 100); + char readBuf[100]; + memset(writeBuf, '0', 100); + + // reLseek 0 -> 20 + fd = open(FILE0, O_CREAT | O_RDWR, 0777); + EXPECT_NE(fd, -1) << "> open faild errno = " << errno; + EXPECT_NE(write(fd, writeBuf, 20), -1) << "> write errno = " << errno; + reLseek = lseek(fd, 0, SEEK_CUR); + EXPECT_NE(reLseek, -1) << "> lseek errno = " << errno; + EXPECT_EQ(reLseek, 20) << "> reLseek = " << reLseek; + + // reLseek 20 -> 10 + reLseek = lseek(fd, 10, SEEK_SET); + EXPECT_NE(reLseek, -1) << "> lseek errno = " << errno; + EXPECT_EQ(reLseek, 10) << "> reLseek = " << reLseek; + + // reLseek 10 -> 20 + EXPECT_NE(write(fd, writeBuf, 10), -1) << "> write errno = " << errno; + EXPECT_NE((reLseek = lseek(fd, 0, SEEK_CUR)), -1) << "> lseek errno = " << errno; + EXPECT_EQ(reLseek, 20) << "> reLseek = " << reLseek; + + // reLseek 20 -> 10 + reLseek = lseek(fd, -10, SEEK_END); + EXPECT_NE(reLseek, -1) << "> lseek errno = " << errno; + EXPECT_EQ(reLseek, 10) << "> reLseek = " << reLseek; + + // reLseek 10 -> 30 + EXPECT_NE(write(fd, writeBuf, 20), -1) << "> write errno = " << errno; + reLseek = lseek(fd, 0, SEEK_CUR); + EXPECT_NE(reLseek, -1) << "> lseek errno = " << errno; + EXPECT_EQ(reLseek, 30) << "> reLseek = " << reLseek; + + // reLseek 30 -> 0 + reLseek = lseek(fd, 0, SEEK_SET); + EXPECT_NE(reLseek, -1) << "> lseek errno = " << errno; + EXPECT_EQ(reLseek, 0) << "> reLseek = " << reLseek; + + // reLseek 0 -> 30 + EXPECT_EQ(read(fd, readBuf, 50), 30) << "> read errno = " << errno; + EXPECT_EQ(strncmp(readBuf, writeBuf, 30), 0) << "readBuf = " << readBuf; + reLseek = lseek(fd, 0, SEEK_CUR); + EXPECT_NE(reLseek, -1) << "> lseek errno = " << errno; + EXPECT_EQ(reLseek, 30) << "> reLseek = " << reLseek; + + EXPECT_NE(close(fd), -1) << "> close errno = " << errno; +} +#endif diff --git a/kernel_lite/fs_posix/src/FsOtherTest.cpp b/kernel_lite/fs_posix/src/FsOtherTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..c7f4c7a2e48edd842734ee84ba3da5a49832662f --- /dev/null +++ b/kernel_lite/fs_posix/src/FsOtherTest.cpp @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2020 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 "FileSystemTest.h" +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "utils.h" +#include "log.h" +#include "KernelConstants.h" +#include "libfs.h" + +using namespace testing::ext; + +/** + * @tc.number SUB_KERNEL_FS_OTHER_0100 + * @tc.name basic function test : get dirname, get current dir name, and get basename + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +#if defined(LITE_FS_JFFS2) || defined(LITE_FS_VFAT) +HWTEST_F(FileSystemTest, testPath, TestSize.Level1) +{ + int fd = 0; + fd = creat(FILE0, 0777); + EXPECT_NE(fd, -1) << "> creat faild errno = " << errno; + EXPECT_NE(close(fd), -1) << "> close errno = " << errno; + + // get dir + char *workDir = dirname((char*)FILE0); + EXPECT_NE(workDir, nullptr) << "> dirname errno = " << errno; + EXPECT_STREQ(".", workDir); + LOG("> workDir = %s", workDir); + + // get current dir name + const char *currentDirStandard = TOP_DIR; + char *currentDir = get_current_dir_name(); + EXPECT_NE(currentDir, nullptr); + EXPECT_STREQ(currentDir, currentDirStandard); + LOG("> currentDir = %s", currentDir); + + // get file name + char *desName = basename((char*)FILE0); + EXPECT_NE(desName, nullptr) << "> basename errno = " << errno; + EXPECT_STREQ(desName, FILE0); + LOG("> desName = %s", desName); +} +#endif + +// check file or directory for ftw +#if defined(LITE_FS_JFFS2) || defined(LITE_FS_VFAT) || defined(LITE_FS_NFS) +int ftwCheckDirTree(const char *path, const struct stat *sb, int flag) +{ + const char file0[] = DIR0 "/" DIR0_FILE0; + const char file1[] = DIR0 "/" DIR0_DIR1 "/" DIR0_DIR1_FILE0; + const char dir0[] = DIR0; + const char dir1[] = DIR0 "/" DIR0_DIR0; + const char dir2[] = DIR0 "/" DIR0_DIR1; + const char dir3[] = DIR0 "/" DIR0_DIR1"/" DIR0_DIR1_DIR0; + if (flag == FTW_F) { + if (strncmp(path, file0, sizeof(file0)) == 0) { + LOG("> File %s", file0); + } else if (strncmp(path, file1, sizeof(file1)) == 0) { + LOG("> File %s", file1); + } else { + LOG("> File error %s", path); + return -1; + } + } else if (flag == FTW_D) { + if (strncmp(path, dir0, sizeof(dir0)) == 0) { + LOG("> Dir %s", DIR0); + } else if (strncmp(path, dir1, sizeof(dir1)) == 0) { + LOG("> Dir %s", dir1); + } else if (strncmp(path, dir2, sizeof(dir2)) == 0) { + LOG("> Dir %s", dir2); + } else if (strncmp(path, dir3, sizeof(dir3)) == 0) { + LOG("> Dir %s", dir3); + } else { + LOG("> File error %s", path); + return -1; + } + } + return 0; +} + +// check file or directory for nftw +int nftwCheckDirTree(const char *path, const struct stat *sb, int flag, struct FTW *s) +{ + const char file0[] = DIR0 "/" DIR0_FILE0; + const char file1[] = DIR0 "/" DIR0_DIR1 "/" DIR0_DIR1_FILE0; + const char dir0[] = DIR0; + const char dir1[] = DIR0 "/" DIR0_DIR0; + const char dir2[] = DIR0 "/" DIR0_DIR1; + const char dir3[] = DIR0 "/" DIR0_DIR1"/" DIR0_DIR1_DIR0; + if (flag == FTW_F) { + if (strncmp(path, file0, sizeof(file0)) == 0) { + LOG("> File %s", file0); + } else if (strncmp(path, file1, sizeof(file1)) == 0) { + LOG("> File %s", file1); + } else { + LOG("> File %s", path); + return -1; + } + } else if (flag == FTW_D) { + if (strncmp(path, dir0, sizeof(dir0)) == 0) { + LOG("> Dir %s", DIR0); + } else if (strncmp(path, dir1, sizeof(dir1)) == 0) { + LOG("> Dir %s", dir1); + } else if (strncmp(path, dir2, sizeof(dir2)) == 0) { + LOG("> Dir %s", dir2); + } else if (strncmp(path, dir3, sizeof(dir3)) == 0) { + LOG("> Dir %s", dir3); + } else { + LOG("> File %s", path); + return -1; + } + } + return 0; +} + +/** + * @tc.number SUB_KERNEL_FS_OTHER_0200 + * @tc.name basic function test : use ftw and nftw check file tree + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(FileSystemTest, testFtw, TestSize.Level3) +{ + CreateTestFolder(); + + LOG("> to check ftw"); + EXPECT_EQ(ftw(DIR0, ftwCheckDirTree, 100), 0) << "> ftw error"; + + LOG("> to check nftw"); + EXPECT_EQ(nftw(DIR0, nftwCheckDirTree, 100, 0), 0) << "> ftw error"; +} +#endif + +#if defined(LITE_FS_JFFS2) || defined(LITE_FS_VFAT) || defined(LITE_FS_NFS) +/** + * @tc.number SUB_KERNEL_FS_OTHER_0300 + * @tc.name basic function test : use statvfs and statfs check file system information. + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(FileSystemTest, test, TestSize.Level2) +{ + struct statvfs vfsBuf; + struct statfs fsBuf; + + statvfs(".", &vfsBuf); + LOG("vfsBuf.f_bsise = %lu", vfsBuf.f_bsize); // File system block size. + LOG("vfsBuf.f_frsize = %lu", vfsBuf.f_frsize); // Fundamental file system block size. + LOG("vfsBuf.f_blocks = %lu", vfsBuf.f_blocks); // Total number of blocks on file system in units of f_frsize. + LOG("vfsBuf.f_bfree = %lu", vfsBuf.f_bfree); // Total number of free blocks. + LOG("vfsBuf.f_bavail = %lu", vfsBuf.f_bavail); // Number of free blocks available to non-privileged process. + LOG("vfsBuf.f_files = %lu", vfsBuf.f_files); // Total number of file serial numbers. + LOG("vfsBuf.f_ffree = %lu", vfsBuf.f_ffree); // Total number of free file serial numbers. + LOG("vfsBuf.f_favail = %lu", vfsBuf.f_favail); // Number of i-nodes available to unprivileged process. + LOG("vfsBuf.f_fsid = %lu", vfsBuf.f_fsid); // File system ID. + LOG("vfsBuf.f_flag = %lu", vfsBuf.f_flag); // Bit mask of f_flag values. + LOG("vfsBuf.f_namemax = %lu", vfsBuf.f_namemax); // Maximum filename length. + + statfs(".", &fsBuf); + LOG("fsBuf.f_type = %lu", fsBuf.f_type); // Type of filesystem. + LOG("fsBuf.f_bsize = %lu", fsBuf.f_bsize); // Optimal transfer block size. + LOG("fsBuf.f_blocks = %lu", fsBuf.f_blocks); // Total data blocks in filesystem. + LOG("fsBuf.f_bfree = %lu", fsBuf.f_bfree); // Total data blocks in filesystem. + LOG("fsBuf.f_bavail = %lu", fsBuf.f_bavail); // Free blocks available to unprivileged user. + LOG("fsBuf.f_files = %lu", fsBuf.f_files); // Total file nodes in filesystem. + LOG("fsBuf.f_ffree = %lu", fsBuf.f_ffree); // Free file nodes in filesystem. + LOG("fsBuf.f_fsid.__val[0] = %d", fsBuf.f_fsid.__val[0]); // Filesystem ID. + LOG("fsBuf.f_fsid.__val[1] = %d", fsBuf.f_fsid.__val[1]); // Filesystem ID. + LOG("fsBuf.f_namelen = %ld", fsBuf.f_namelen); // Maximum length of filenames. + + EXPECT_EQ(vfsBuf.f_bsize, fsBuf.f_bsize); + EXPECT_EQ(vfsBuf.f_blocks, fsBuf.f_blocks); + EXPECT_EQ(vfsBuf.f_bfree, fsBuf.f_bfree); + EXPECT_EQ(vfsBuf.f_bavail, fsBuf.f_bavail); + EXPECT_EQ(vfsBuf.f_files, fsBuf.f_files); + EXPECT_EQ(vfsBuf.f_ffree, fsBuf.f_ffree); + EXPECT_EQ(vfsBuf.f_namemax, fsBuf.f_namelen); +} +#endif diff --git a/kernel_lite/fs_posix/src/FsStdioTest.cpp b/kernel_lite/fs_posix/src/FsStdioTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..3ed8c14d714e73be632f2afd8c418eb3a4fa3e2c --- /dev/null +++ b/kernel_lite/fs_posix/src/FsStdioTest.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2020 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 "FileSystemTest.h" +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "utils.h" +#include "log.h" +#include "KernelConstants.h" +#include "libfs.h" + +using namespace testing::ext; + +/** + * @tc.number SUB_KERNEL_FS_STDIO_0100 + * @tc.name basic function test : SUB_KERNEL_FS_1100 read and write with stream + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +#if defined(LITE_FS_JFFS2) || defined(LITE_FS_VFAT) +HWTEST_F(FileSystemTest, testFILE, TestSize.Level2) +{ + FILE *fp; + int fd = 0; + char writeBuf[] = "this is a file"; + char readBuf[20]; + memset(readBuf, 0, sizeof(readBuf)); + + // write + fd = creat(FILE0, 0777); + EXPECT_NE(fd, -1) << "> creat faild errno = " << errno; + EXPECT_NE(close(fd), -1) << "> close errno = " << errno; + fp = fopen(FILE0, "w+"); + EXPECT_NE(fp, nullptr) << "> fopen errno = " << errno; + fwrite(writeBuf, sizeof(writeBuf), 1, fp); + EXPECT_NE(fclose(fp), -1) << "> fclose errno =" < fopen errno = " << errno; + EXPECT_NE(fread(readBuf, sizeof(writeBuf), 1, fp), 0) << "> fread errno = " < writeBuf = " << writeBuf\ + << "\n> readBuf = " << readBuf; + EXPECT_NE(fclose(fp), -1) << "> fclose errno =" < +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "utils.h" +#include "log.h" +#include "KernelConstants.h" +#include "libfs.h" + +using namespace testing::ext; + +/** + * @tc.number SUB_KERNEL_FS_STDLIB_0100 + * @tc.name basic function test : mkstemp create a temporary file + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +#if defined(LITE_FS_JFFS2) || defined(LITE_FS_VFAT) +HWTEST_F(FileSystemTest, testMkstemp, TestSize.Level2) +{ + int fd = 0; + char tmpFileName[]= "tmpFile_XXXXXX"; + fd = mkstemp(tmpFileName); + EXPECT_NE(fd, -1) << "> mkstemp errno = " < open errno = " << errno; + ReadCloseTest(fd); + EXPECT_NE(unlink(tmpFileName), -1) << "> unlink errno = " << errno; +} +#endif + +/** + * @tc.number SUB_KERNEL_FS_STDLIB_0200 + * @tc.name basic function test : mkstemps create a temporary file + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +#if defined(LITE_FS_JFFS2) || defined(LITE_FS_VFAT) +HWTEST_F(FileSystemTest, testMkstemps, TestSize.Level2) +{ + int fd = 0; + char tmpFileName[] = "tmpFile_XXXXXX"; + fd = mkstemps(tmpFileName, 0); + EXPECT_NE(fd, -1) << "> mkstemp errno = " < open errno = " << errno; + ReadCloseTest(fd); + EXPECT_NE(unlink(tmpFileName), -1) << "> unlink errno = " << errno; +} +#endif + +/** + * @tc.number SUB_KERNEL_FS_STDLIB_0300 + * @tc.name basic function test : mkostemp create a temporary file with read and write + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +#if defined(LITE_FS_JFFS2) || defined(LITE_FS_VFAT) +HWTEST_F(FileSystemTest, testMkostemp, TestSize.Level2) +{ + int fd = 0; + char tmpFileName[] = "tmpFile_XXXXXX"; + fd = mkostemp(tmpFileName, O_RDWR); + EXPECT_NE(fd, -1) << "> mkstemp errno = " < open errno = " << errno; + ReadCloseTest(fd); + EXPECT_NE(unlink(tmpFileName), -1) << "> unlink errno = " << errno; +} +#endif + +/** + * @tc.number SUB_KERNEL_FS_STDLIB_0400 + * @tc.name basic function test : mktemp create a temporary file name, mkdtemp create a directory + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +#if defined(LITE_FS_JFFS2) || defined(LITE_FS_VFAT) +HWTEST_F(FileSystemTest, testMktempMkdtemp, TestSize.Level2) +{ + char tmpFileNamePre[] = "tmpFile_XXXXXX"; + char tmpFileName[] = "tmpFile_XXXXXX"; + EXPECT_NE(mktemp(tmpFileName), nullptr) << "> mktemp errno = " << errno; + EXPECT_STRNE(tmpFileName, tmpFileNamePre) << "> tmpFileName no change"; + + char tmpDirName[] = "tmpDir_XXXXXXX"; + EXPECT_NE(mkdtemp(tmpDirName), nullptr) << "> mktemp errno = " << errno; + EXPECT_NE(remove(tmpDirName), -1) << "> remove errno = " << errno; +} +#endif + +/** + * @tc.number SUB_KERNEL_FS_STDLIB_0500 + * @tc.name basic function test : Use the realpath function to obtain the path. + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +#if defined(LITE_FS_JFFS2) || defined(LITE_FS_VFAT) || defined(LITE_FS_NFS) +HWTEST_F(FileSystemTest, testRealpath, TestSize.Level3) +{ + int fd = 0; + fd = creat(FILE0, 0777); + EXPECT_NE(fd, -1) << "> creat faild errno = " << errno; + EXPECT_NE(close(fd), -1) << "> close errno = " << errno; + + // get Absolute Path + const char *realPathStandard = TOP_DIR "/" FILE0; + char *realPath = (char*)malloc(256); + EXPECT_NE(realpath(FILE0, realPath), nullptr) << "> realpath errno = " << errno; + EXPECT_STREQ(realPath, realPathStandard); + LOG("> realPath = %s", realPath); + free(realPath); +} +#endif + +/** + * @tc.number SUB_KERNEL_FS_STDLIB_0600 + * @tc.name basic function test : Use the rename function to rename directories and files. + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +#if defined(LITE_FS_JFFS2) || defined(LITE_FS_VFAT) || defined(LITE_FS_NFS) +HWTEST_F(FileSystemTest, testRename, TestSize.Level3) +{ + int fd = 0; + const char *newFileName = "FILE_NEW"; + const char *newDirName = "DIR_NEW"; + fd = creat(FILE0, 0777); + EXPECT_NE(fd, -1) << "> creat faild errno = " << errno; + EXPECT_NE(close(fd), -1) << "> close errno = " << errno; + EXPECT_NE(mkdir(DIR0, 0777), -1) << "> mkdir errno = " << errno; + EXPECT_NE(rename(FILE0, newFileName), -1) << "> rename errno = " << errno; + EXPECT_NE(rename(DIR0, newDirName), -1) << "> rename errno = " << errno; + + EXPECT_NE(unlink(newFileName), -1) << "> unlink errno = " << errno; + EXPECT_NE(rmdir(newDirName), -1) << "> rmdir errno = " << errno; +} +#endif diff --git a/kernel_lite/fs_posix/src/FsUnistdTest.cpp b/kernel_lite/fs_posix/src/FsUnistdTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..51f4806389446d0bea874dd1e1e9295558c7caaa --- /dev/null +++ b/kernel_lite/fs_posix/src/FsUnistdTest.cpp @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2020 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 "FileSystemTest.h" +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "utils.h" +#include "log.h" +#include "KernelConstants.h" +#include "libfs.h" + +using namespace testing::ext; + +#if defined(LITE_FS_JFFS2) || defined(LITE_FS_VFAT) || defined(LITE_FS_NFS) +/** + * @tc.number SUB_KERNEL_FS_UNISTD_0100 + * @tc.name basic function test : access check whether the file exists. + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(FileSystemTest, testAccess, TestSize.Level0) +{ + int fd = 0; + fd = creat(FILE0, 0777); + EXPECT_NE(fd, -1) << "> creat faild errno = " << errno; + EXPECT_NE(close(fd), -1) << "> close errno = " << errno; + EXPECT_EQ(access(FILE0, F_OK), 0) << "> access F_OK errno = " << errno; + EXPECT_EQ(unlink(FILE0), 0) << "> remove errno = " << errno; + EXPECT_NE(access(FILE0, F_OK), 0) << "> access F_OK expect faild but success"; +} +#endif + +#if defined(LITE_FS_JFFS2) || defined(LITE_FS_VFAT) +/** + * @tc.number SUB_KERNEL_FS_UNISTD_0200 + * @tc.name basic function test : switch to the current working directory. + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(FileSystemTest, testChdir, TestSize.Level1) +{ + char testDir[MAX_PATH_SIZE]; + const char *expectDirStandard = TOP_DIR "/" DIR0; + EXPECT_NE(mkdir(DIR0, 0777), -1) << "> mkdir errno = " << errno; + EXPECT_NE(chdir(DIR0), -1) << "> chdir errno = " << errno; + EXPECT_NE(getcwd(testDir, sizeof(testDir)), nullptr) << "> getcwd errno = " << errno; + EXPECT_NE(chdir(TOP_DIR), -1) << "> chdir errno = " << errno; + + EXPECT_STREQ(testDir, expectDirStandard); + LOG("> expectDirStandard = %s", expectDirStandard); + LOG("> testDir = %s", testDir); +} +#endif + +/** + * @tc.number SUB_KERNEL_FS_UNISTD_0300 + * @tc.name basic function test : dup copy file description, then write and read + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +#if defined(LITE_FS_NFS) +HWTEST_F(FileSystemTest, testDup, TestSize.Level3) +{ + int fd = 0; + int fdNew = 0; + fd = open(FILE0, O_CREAT | O_RDWR, 0777); + EXPECT_NE(fd, -1) << "> open faild errno = " << errno; + WriteCloseTest(fd); + fd = open(FILE0, O_RDONLY, 0777); + EXPECT_NE(fd, -1) << "> open faild errno = " << errno; + fdNew = dup(fd); + EXPECT_NE(fdNew, -1) << "> dup errno = " << errno; + ReadCloseTest(fdNew); +} +#endif + +#if defined(LITE_FS_JFFS2) || defined(LITE_FS_VFAT) || defined(LITE_FS_NFS) +/** + * @tc.number SUB_KERNEL_FS_UNISTD_0400 + * @tc.name basic function test : dup2 copy file description, then write and read + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(FileSystemTest, testDup2, TestSize.Level3) +{ + int fd = 0; + int fdNew = 0; + fd = open(FILE0, O_CREAT | O_RDWR, 0777); + EXPECT_NE(fd, -1) << "> open faild errno = " << errno; + WriteCloseTest(fd); + fd = open(FILE0, O_RDONLY, 0777); + EXPECT_NE(fd, -1) << "> open faild errno = " << errno; + EXPECT_NE(dup2(fd, fdNew), -1) << "> dup2 errno = " << errno; + ReadCloseTest(fdNew); + EXPECT_NE(close(fd), -1) << "> close errno = " << errno; +} +#endif + +#if defined(LITE_FS_VFAT) +/** + * @tc.number SUB_KERNEL_FS_UNISTD_0500 + * @tc.name basic function test : using ftruncate and truncate functions to change the file size + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(FileSystemTest, testFtruncate, TestSize.Level1) +{ + struct stat statbuf; + char writeBuf[] = "this is a file"; + int fd = 0; + + fd = open(FILE0, O_CREAT | O_RDWR, 0777); + EXPECT_NE(fd, -1) << "> open faild errno = " << errno; + EXPECT_NE(write(fd, "writeBuf", sizeof(writeBuf)), -1) << "> write errno = " << errno; + + EXPECT_NE(ftruncate(fd, 1000), -1) << "truncate errno = " << errno; + EXPECT_NE(close(fd), -1) << "> close errno = " << errno; + + stat(FILE0, &statbuf); + EXPECT_EQ(statbuf.st_size, 1000); + + EXPECT_NE(truncate(FILE0, 100), -1) << "truncate errno = " << errno; + stat(FILE0, &statbuf); + EXPECT_EQ(statbuf.st_size, 100); +} +#endif diff --git a/kernel_lite/fs_posix/vfat/BUILD.gn b/kernel_lite/fs_posix/vfat/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..fe386e5820905e3123df00b51609e516137ae4b6 --- /dev/null +++ b/kernel_lite/fs_posix/vfat/BUILD.gn @@ -0,0 +1,36 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsVFATTest") { + suite_name = "acts" + sources = [ + "../src/FileSystemTest.cpp", + "../src/FsFcntlTest.cpp", + "../src/FsStdioTest.cpp", + "../src/FsStdlibTest.cpp", + "../src/FsUnistdTest.cpp", + "../src/FsOtherTest.cpp", + ] + include_dirs = [ + "//test/xts/tools/hctest/include", + "//test/xts/acts/kernel_lite/utils" + ] + deps = [ + "//test/xts/acts/kernel_lite/utils:libutils", + "//test/xts/acts/kernel_lite/utils:libfs" + ] + cflags_cc = [ "-Wno-write-strings" ] + defines = [ "LITE_FS_VFAT", "TOP_DIR=\"/sdcard\"" ] +} diff --git a/kernel_lite/fs_posix/vfat/Test.json b/kernel_lite/fs_posix/vfat/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..ddf8aafefefe199a10d82160db31191dc4e88e2c --- /dev/null +++ b/kernel_lite/fs_posix/vfat/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsVFATTest.bin" + } +} \ No newline at end of file diff --git a/kernel_lite/futex_posix/BUILD.gn b/kernel_lite/futex_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..ce554928a9d59dd219f93df216204f7a0c1a3e46 --- /dev/null +++ b/kernel_lite/futex_posix/BUILD.gn @@ -0,0 +1,34 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsFutexApiTest") { + suite_name = "acts" + sources = [ + "src/ActsFutexApiTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "../utils/", + "src", + ] + + deps = [ + "//test/xts/tools/hcpptest:hcpptest", + "//test/xts/acts/kernel_lite/utils:libutils" + ] + + cflags = [ "-Wno-error" ] +} diff --git a/kernel_lite/futex_posix/Test.json b/kernel_lite/futex_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..8de09ad42aba14365b6d70ecc941e7710ffbfc5b --- /dev/null +++ b/kernel_lite/futex_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite posix futex api test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsFutexApiTest.bin" + } +} \ No newline at end of file diff --git a/kernel_lite/futex_posix/src/ActsFutexApiTest.cpp b/kernel_lite/futex_posix/src/ActsFutexApiTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..17abd52978758df66f6d634c55de58687dfd1bd2 --- /dev/null +++ b/kernel_lite/futex_posix/src/ActsFutexApiTest.cpp @@ -0,0 +1,452 @@ +/* + * Copyright (c) 2020 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 +#include +#include +#include "gtest/gtest.h" +#include "utils.h" +#define MAX 5 + +using namespace testing::ext; + +static int g_count = 0; +static int g_cancel = 0; +static pthread_mutex_t g_mutex_lock; +static pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_cond_t g_notfull = PTHREAD_COND_INITIALIZER; +static pthread_cond_t g_notempty = PTHREAD_COND_INITIALIZER; +static pthread_rwlock_t g_rwlock; +static pthread_spinlock_t g_spinlock; +static int g_testvalue = 0; +static int g_index = 0; +static int g_retvalue[25] = {2}; +static int g_wcount; +static int g_top = 0; +static int g_bottom = 0; +static int g_rwindex = 0; +static int g_rwresult[15] = {0}; +static int g_fifteen = 15; +static int g_fourty = 40; +static int g_fivehundred = 520; +std::ostringstream s1; +std::ostringstream s2; +class ActsFutexApiTest : public testing::Test { +protected: + static void *thread_fun_1(void *data) + { + pthread_mutex_lock(&g_mutex_lock); + g_count++; + printf("%s g_count: %d\n", __func__, g_count); + pthread_mutex_unlock(&g_mutex_lock); + return NULL; + } + + static void *thread_fun_2(void *data) + { + pthread_mutex_lock(&g_mutex_lock); + g_count++; + printf("%s g_count: %d\n", __func__, g_count); + pthread_mutex_unlock(&g_mutex_lock); + return NULL; + } + + static void *thread_fun_3(void *data) + { + pthread_mutex_lock(&g_mutex_lock); + g_count++; + printf("%s g_count: %d\n", __func__, g_count); + pthread_mutex_unlock(&g_mutex_lock); + return NULL; + } + + static void *thread_fun_4(void *data) + { + pthread_mutex_lock(&g_mutex_lock); + int i = 0; + while (i < 10) { + s1 << "1" ; + i++; + } + pthread_mutex_unlock(&g_mutex_lock); + return NULL; + } + + static void *thread_fun_5(void *data) + { + pthread_mutex_lock(&g_mutex_lock); + int i = 0; + while (i < 10) { + s1 << "2" ; + i++; + } + pthread_mutex_unlock(&g_mutex_lock); + return NULL; + } + + static void *thread_fun_6(void *data) + { + if (pthread_mutex_trylock(&g_mutex_lock) != 0) { + g_cancel = 1; + return 0; + } + int i = 0; + g_cancel = 0; + + while (i < 10) { + if (g_cancel) break; + s2 << "1" ; + i++; + Msleep(10); + } + + pthread_mutex_unlock(&g_mutex_lock); + return NULL; + } + + static void *thread_fun_7(void *data) + { + if (pthread_mutex_trylock(&g_mutex_lock) != 0) { + g_cancel = 1; + return 0; + } + int i = 0; + g_cancel = 0; + + while (i < 10) { + if (g_cancel) break; + s2 << "2" ; + i++; + Msleep(10); + } + pthread_mutex_unlock(&g_mutex_lock); + return NULL; + } + + static void *produce(void* arg) + { + int i; + for ( i = 0; i < MAX*2; i++) + { + pthread_mutex_lock(&g_mutex); + while ((g_top + 1)%MAX == g_bottom) + { + printf("full! producer is waiting\n"); + pthread_cond_wait(&g_notfull, &g_mutex); + } + Msleep(10); + g_top = (g_top + 1) % MAX; + pthread_cond_signal(&g_notempty); + pthread_mutex_unlock(&g_mutex); + } + return (void*)1; + } + static void *consume(void* arg) + { + int i; + for ( i = 0; i < MAX*2; i++) + { + pthread_mutex_lock(&g_mutex); + while (g_top%MAX == g_bottom) + { + printf("empty! consumer is waiting\n"); + g_count++; + pthread_cond_wait(&g_notempty, &g_mutex); + } + Msleep(1); + g_bottom = (g_bottom + 1) % MAX; + pthread_cond_signal(&g_notfull); + pthread_mutex_unlock(&g_mutex); + } + return (void*)2; + } + + static void *pth_wr(void *arg) + { + int i = (int)arg; + while (g_wcount <= g_fivehundred) + { + pthread_rwlock_wrlock(&g_rwlock); + printf("write================w_count = %ld, %d thread\n", g_wcount += g_fourty, i + 1); + if (g_rwindex < g_fifteen) + { + g_rwresult[g_rwindex] = g_wcount; + g_rwindex++; + } + pthread_rwlock_unlock(&g_rwlock); + Msleep(10); + } + return NULL; + } + + static void *pth_rd(void *arg) + { + int i = (int)arg; + while (g_wcount <= g_fivehundred) + { + pthread_rwlock_rdlock(&g_rwlock); + printf("read================w_count = %ld, %d thread\n", g_wcount, i + 1); + pthread_rwlock_unlock(&g_rwlock); + Msleep(10); + } + return NULL; + } + + static void *UDP_first_thread(void *arg) + { + int i ,ret; + printf("UDP_first_thread begin\n"); + for(i =0 ;i<10 ;i++ ) { + pthread_spin_lock(&g_spinlock); + g_testvalue++; + g_retvalue[g_index] = g_testvalue; + g_index++; + printf("test_value %d\n", g_testvalue); + Msleep(10); + pthread_spin_unlock(&g_spinlock); + Msleep(5); + } + printf("UDP_first_thread end\n"); + return NULL; + } + + static void *UDP_second_thread(void *arg) + { + int i ,ret; + printf("UDP_second_thread begin\n"); + for(i =0 ;i<10 ;i++ ) { + pthread_spin_lock(&g_spinlock); + g_testvalue--; + g_retvalue[g_index] = g_testvalue; + g_index++; + printf("test_value %d\n", g_testvalue); + Msleep(10); + pthread_spin_unlock(&g_spinlock); + Msleep(5); + } + printf("UDP_second_thread end\n"); + return NULL; + } +}; + +/** +* @tc.number SUB_KERNEL_NDKAPI_FUTEX_LOCK_0100 +* @tc.name testpthreadmutexlock api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsFutexApiTest, testpthreadmutexlock, TestSize.Level1) { + int ret; + pthread_t pid[3]; + + ret = pthread_mutex_init(&g_mutex_lock, NULL); + if (ret != 0) { + printf("mutex init failed\n"); + EXPECT_EQ(ret, 0); + } + + pthread_create(&pid[0], NULL, thread_fun_1, NULL); + pthread_create(&pid[1], NULL, thread_fun_2, NULL); + pthread_create(&pid[2], NULL, thread_fun_3, NULL); + + pthread_join(pid[0], NULL); + pthread_join(pid[1], NULL); + pthread_join(pid[2], NULL); + + pthread_mutex_destroy(&g_mutex_lock); + EXPECT_EQ(g_count, 3) << "ErrInfo: g_count, --> g_count:='" << g_count << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_FUTEX_LOCK_0200 +* @tc.name testpthreadmutexlock1 api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsFutexApiTest, testpthreadmutexlock1, TestSize.Level1) { + int ret; + pthread_t pid[3]; + + ret = pthread_mutex_init(&g_mutex_lock, NULL); + if (ret != 0) { + printf("mutex init failed\n"); + EXPECT_EQ(ret, 0); + } + + pthread_create(&pid[0], NULL, thread_fun_4, NULL); + Msleep(5); + pthread_create(&pid[1], NULL, thread_fun_5, NULL); + + pthread_join(pid[0], NULL); + pthread_join(pid[1], NULL); + + pthread_mutex_destroy(&g_mutex_lock); + EXPECT_EQ(s1.str(), "11111111112222222222"); +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_FUTEX_LOCK_0300 +* @tc.name testpthreadmutextrylock api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsFutexApiTest, testpthreadmutextrylock, TestSize.Level1) { + int ret; + pthread_t pid[3]; + + ret = pthread_mutex_init(&g_mutex_lock, NULL); + if (ret != 0) { + printf("mutex init failed\n"); + EXPECT_EQ(ret, 0); + } + + pthread_create(&pid[0], NULL, thread_fun_6, NULL); + pthread_create(&pid[1], NULL, thread_fun_7, NULL); + + pthread_join(pid[0], NULL); + pthread_join(pid[1], NULL); + + pthread_mutex_destroy(&g_mutex_lock); + string s = s2.str(); + EXPECT_NE(s, "11111111112222222222"); + EXPECT_NE(s, "22222222221111111111"); + printf("s2.str = %s", s.c_str()); +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_FUTEX_LOCK_0400 +* @tc.name testpthread_cond_wait api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsFutexApiTest, testpthread_cond_wait, TestSize.Level1) { + pthread_t thid1; + pthread_t thid2; + pthread_t thid3; + pthread_t thid4; + + int ret1; + int ret2; + int ret3; + int ret4; + g_count = 0; + pthread_create(&thid1, NULL, produce, NULL); + pthread_create(&thid2, NULL, consume, NULL); + pthread_create(&thid3, NULL, produce, NULL); + pthread_create(&thid4, NULL, consume, NULL); + + pthread_join(thid1, (void**)&ret1); + pthread_join(thid2, (void**)&ret2); + pthread_join(thid3, (void**)&ret3); + pthread_join(thid4, (void**)&ret4); + EXPECT_NE(g_count, 0); + printf("testpthread_cond_wait g_count = %d", g_count); +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_FUTEX_LOCK_0500 +* @tc.name testpthread_rwlock api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsFutexApiTest, testpthread_rwlock, TestSize.Level1) { + pthread_t pth[10]; + int i; + pthread_rwlock_init(&g_rwlock, nullptr); + for (i = 0; i < 5; i++) + { + pthread_create(&pth[i], NULL, pth_wr, (void *)i); + } + for (i = 0; i < 5; i++) + { + pthread_create(&pth[5 + i], NULL, pth_rd, (void *)i); + } + + while (1) + { + if (g_wcount >= 520) + { + for (int j = 0; j < 10; j++) + { + pthread_cancel(pth[j]); + pthread_join(pth[j], nullptr); + } + break; + } + Msleep(200); + } + EXPECT_EQ(g_rwresult[0], 40); + EXPECT_EQ(g_rwresult[1], 80); + EXPECT_EQ(g_rwresult[2], 120); + EXPECT_EQ(g_rwresult[3], 160); + EXPECT_EQ(g_rwresult[4], 200); + EXPECT_EQ(g_rwresult[5], 240); + EXPECT_EQ(g_rwresult[6], 280); + EXPECT_EQ(g_rwresult[7], 320); + EXPECT_EQ(g_rwresult[8], 360); + EXPECT_EQ(g_rwresult[9], 400); + EXPECT_EQ(g_rwresult[10], 440); + EXPECT_EQ(g_rwresult[11], 480); + EXPECT_EQ(g_rwresult[12], 520); + EXPECT_EQ(g_rwresult[13], 560); +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_FUTEX_LOCK_0600 +* @tc.name testpthread_spin_lock api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsFutexApiTest, testpthread_spin_lock, TestSize.Level1) { + int err; + pthread_t tid1, tid2; + + pthread_spin_init(&g_spinlock, 0); + err = pthread_create(&tid1, NULL, UDP_first_thread, NULL); + if (err != 0) { + perror(" fail to create thread "); + } + err = pthread_create(&tid2, NULL, UDP_second_thread, NULL); + if (err != 0) { + perror(" fail to create thread "); + } + pthread_join(tid1, NULL); + pthread_join(tid2, NULL); + for (int i = 0; i < 20; i++) + { + if (i%2 == 0) + { + EXPECT_EQ(g_retvalue[i], 1); + } + else + { + EXPECT_EQ(g_retvalue[i], 0); + } + } +} \ No newline at end of file diff --git a/kernel_lite/ipc_posix/BUILD.gn b/kernel_lite/ipc_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..7bdd2fd990a0111592fc2b0b6f3764a755315d23 --- /dev/null +++ b/kernel_lite/ipc_posix/BUILD.gn @@ -0,0 +1,36 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsKernelIPCTest") { + suite_name = "acts" + sources = [ + "src/SignalTest.cpp", + "src/SignalTestUtils.cpp", + "src/ShmTest.cpp", + "src/FifoTest.cpp", + "src/PipeTest.cpp", + "src/IpcMqExceptionTest.cpp", + "src/IpcMqTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "../utils/" + ] + + deps = [ + "//test/xts/acts/kernel_lite/utils:libutils" + ] +} diff --git a/kernel_lite/ipc_posix/Test.json b/kernel_lite/ipc_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..e41aaf307655503add8ae46c2069e4cfa36cecfd --- /dev/null +++ b/kernel_lite/ipc_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsKernelIPCTest.bin" + } +} \ No newline at end of file diff --git a/kernel_lite/ipc_posix/src/FifoTest.cpp b/kernel_lite/ipc_posix/src/FifoTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..1dcc3e7fa785229f3baf190ebadb11d5ac9ca846 --- /dev/null +++ b/kernel_lite/ipc_posix/src/FifoTest.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2020 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 "log.h" +#include "utils.h" +#include "KernelConstants.h" + +using namespace testing::ext; + +class FifoTest : public::testing::Test { +}; + +/** + * @tc.number SUB_KERNEL_IPC_FIFO_0100 + * @tc.name basic function test : hello world + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(FifoTest, testHelloWorld, TestSize.Level0) +{ + const char fifoPath[] = "/dev/xtsTestFifo"; + char buffer[80]; + int fd; + char sentence[] = "Hello World"; + unlink(fifoPath); + + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "> parent: fork : error"; + if (pid == 0) { + Msleep(20); + fd = open(fifoPath, O_WRONLY); + write(fd, sentence, sizeof(sentence)); + LOG("> child: write: %s", sentence); + close(fd); + exit(0); + } + // parent + int ret = mkfifo(fifoPath, 0666); + EXPECT_EQ(ret, 0) << "> parent: mkfifo errno = " << errno; + fd = open(fifoPath, O_RDONLY); + EXPECT_NE(fd, -1) << "> open faild errno = " << errno; + EXPECT_NE(read(fd, buffer, sizeof(buffer)), -1) << "> read errno = " << errno; + EXPECT_STREQ(sentence, buffer) << "> parent: read = " << buffer; + LOG("> parent: read: %s", buffer); + close(fd); + + Msleep(100); + EXPECT_NE(remove(fifoPath), -1) << "> remove errno = " << errno; + AssertProcExitedOK(pid); +} + +/** + * @tc.number SUB_KERNEL_IPC_FIFO_0700 + * @tc.name mkfifo() Duplicate creation and delete + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(FifoTest, testFifoAddDelete, TestSize.Level0) +{ + char fifoPath[50]; + const int loopNum = 32; + + for (int i = 0; i < loopNum; i++) { + sprintf(fifoPath, "/dev/xtsTestFifo_%d", i); + unlink(fifoPath); + + LOG("> Create fifo %d", i); + ASSERT_EQ(mkfifo(fifoPath, 0666), 0) << "> mkfifo errno = " << errno; + + LOG("> Delete fifo %d", i); + EXPECT_NE(remove(fifoPath), -1) << "> remove errno = " << errno; + } +} + +/** + * @tc.number SUB_KERNEL_IPC_FIFO_0800 + * @tc.name test O_NONBLOCK + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(FifoTest, testFifoNonblack, TestSize.Level1) +{ + const int arrSize = MAX_PIPE_BUFFER + 1000; + const char fifoPath[] = "/dev/xtsTestFifo"; + int fd; + int tmpInt; + char buffer[80]; + char testBuffer[arrSize]; + memset(testBuffer, '1', sizeof(testBuffer)); + + unlink(fifoPath); + int ret = mkfifo(fifoPath, 0666); + EXPECT_EQ(ret, 0) << "> parent: mkfifo errno = " << errno; + + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "> parent : fork : error"; + if (pid == 0) { + char readBuffer[arrSize]; + memset(readBuffer, 0, sizeof(readBuffer)); + fd = open(fifoPath, O_RDONLY); + if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) { + LOG("> fcntl errno = %d", errno); + } + Msleep(60); + tmpInt = read(fd, readBuffer, arrSize); + if (tmpInt != MAX_PIPE_BUFFER) { + LOG("> child: tmpInt = %d", tmpInt); + LOG("> child: errno = %d", errno); + close(fd); + exit(1); + } + if (strncmp(testBuffer, readBuffer, MAX_PIPE_BUFFER) != 0) { + close(fd); + exit(1); + } + close(fd); + exit(0); + } + // parent + char writeBuffer[arrSize]; + memset(writeBuffer, '1', sizeof(writeBuffer)); + fd = open(fifoPath, O_WRONLY); + EXPECT_NE(fd, -1) << "> open faild errno = " << errno; + EXPECT_NE(fcntl(fd, F_SETFL, O_NONBLOCK), -1) << "> fcntl errno = " << errno; + Msleep(30); + tmpInt = write(fd, writeBuffer, arrSize); + EXPECT_EQ(tmpInt, MAX_PIPE_BUFFER) << "> parent: errno = " < parent: write num = %d", tmpInt); + close(fd); + + Msleep(100); + EXPECT_NE(remove(fifoPath), -1) << "> remove errno = " << errno; + AssertProcExitedOK(pid); +} diff --git a/kernel_lite/ipc_posix/src/IpcMqExceptionTest.cpp b/kernel_lite/ipc_posix/src/IpcMqExceptionTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..a74fccb615fce3988b647c0474b5fd33e7d090b2 --- /dev/null +++ b/kernel_lite/ipc_posix/src/IpcMqExceptionTest.cpp @@ -0,0 +1,922 @@ +/* + * Copyright (c) 2020 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 "IpcMqTest.h" +#include +#include +#include +#include +#include +#include "log.h" +#include "utils.h" +#include "KernelConstants.h" + +using namespace testing::ext; + +/** + * @tc.number SUB_KERNEL_IPC_MQ_OPEN_0100 + * @tc.name mq_open function errno for EEXIST test + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(IpcMqTest, testMqOpenEEXIST, TestSize.Level2) +{ + char qName[MQ_NAME_LEN]; + mqd_t queue, queueOther; + + sprintf(qName, "testMqOpenEEXIST_%d", GetRandom(10000)); + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL); + ASSERT_TRUE(queue != (mqd_t)-1) << "ERROR: mq_open() == (mqd_t)-1"; + + queueOther = mq_open(qName, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR, NULL); + EXPECT_TRUE(queueOther == (mqd_t)-1) << "ERROR: mq_open() != (mqd_t)-1, queueOther = " << queueOther; + EXPECT_TRUE(errno == EEXIST) << "ERROR: errno != EEXIST" << \ + " errno = " << errno << " strerror(errno) = " << strerror(errno); + EXPECT_TRUE(mq_close(queue) == 0) << "ERROR: mq_close() != 0"; + ASSERT_TRUE(mq_unlink(qName) == 0) << "ERROR: mq_unlink() != 0"; +} + +/** + * @tc.number SUB_KERNEL_IPC_MQ_OPEN_0200 + * @tc.name mq_open function errno for EINVAL test + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(IpcMqTest, testMqOpenEINVAL, TestSize.Level2) +{ + int i; + mqd_t queue; + struct mq_attr attr; + char qName[MQ_NAME_LEN]; + const int max = 65535; + + sprintf(qName, "testMqOpenEINVAL_%d", GetRandom(10000)); + + for (i = 0; i<6; i++) { + switch (i) { + case 0: + attr.mq_msgsize = -1; + attr.mq_maxmsg = max; + break; + case 1: + /* attr.mq_msgsize > USHRT_MAX - 4 */ + attr.mq_msgsize = max; + attr.mq_maxmsg = max; + break; + case 2: + attr.mq_msgsize = 10; + attr.mq_maxmsg = -1; + break; + case 3: + attr.mq_msgsize = 10; + attr.mq_maxmsg = max + 1; + break; + + case 4: + attr.mq_msgsize = 0; + attr.mq_maxmsg = 16; + break; + + case 5: + attr.mq_msgsize = 64; + attr.mq_maxmsg = 0; + break; + } + + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + EXPECT_TRUE(queue == (mqd_t)-1) << "ERROR: mq_open() != (mqd_t)-1, i = " << i; + + if (queue != (mqd_t)-1) { + mq_close(queue); + mq_unlink(qName); + } + + /* if NOT call mq_close & mq_unlink then errno == ENOENT */ + EXPECT_TRUE(errno == EINVAL) << "errno != EINVAL, errno = " << errno << " i = " << i << " qName = " << qName; + } + + for (i=0; i +#include +#include +#include +#include +#include "log.h" +#include "utils.h" +#include "KernelConstants.h" + +using namespace testing::ext; + +/** + * @tc.number SUB_KERNEL_IPC_MQ_0100 + * @tc.name mq_send and mq_receive function test + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(IpcMqTest, testMqOneLevelCom, TestSize.Level0) +{ + mqd_t queue; + unsigned int prio; + struct mq_attr attr; + struct mq_attr getAttr, setAttr; + char qName[MQ_NAME_LEN], rMsg[MQ_RX_LEN]; + + sprintf(qName, "testMqOneLevelCom_%d", GetRandom(10000)); + setAttr.mq_msgsize = MQ_MSG_SIZE; + setAttr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &setAttr); + ASSERT_TRUE(queue != (mqd_t)-1) << "ERROR: mq_open() == (mqd_t)-1"; + EXPECT_TRUE(mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO) == 0) << "ERROR: mq_send() != 0"; + + EXPECT_TRUE(mq_getattr(queue, &getAttr) == 0) << "ERROR: mq_getattr() != 0"; + EXPECT_TRUE(getAttr.mq_msgsize == MQ_MSG_SIZE) << "getAttr.mq_msgsize != MQ_MSG_SIZE, " << \ + "getAttr.mq_msgsize = " << getAttr.mq_msgsize; + EXPECT_TRUE(getAttr.mq_maxmsg == MQ_MAX_MSG) << "getAttr.mq_maxmsg != MQ_MAX_MSG, " << \ + "getAttr.mq_maxmsg = " << getAttr.mq_maxmsg; + + EXPECT_TRUE(mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio) != -1) << "ERROR: mq_receive() == -1"; + EXPECT_TRUE(prio == 0) << "ERROR: prio != 0, prio = " << prio; + EXPECT_TRUE(strncmp(MQ_MSG, rMsg, MQ_MSG_LEN) == 0) << "sent != received: sent = " << \ + MQ_MSG << ", received = " << rMsg; + EXPECT_TRUE(mq_close(queue) == 0) << "ERROR: mq_close() != 0"; + ASSERT_TRUE(mq_unlink(qName) == 0) << "ERROR: mq_unlink() != 0"; +} + +/** + * @tc.number SUB_KERNEL_IPC_MQ_0200 + * @tc.name mq_timedsend and mq_timedreceive function test + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(IpcMqTest, testMqTimedOneLevelCom, TestSize.Level1) +{ + mqd_t queue; + unsigned int prio; + struct timespec tts, rts; + struct mq_attr getAttr, setAttr; + char qName[MQ_NAME_LEN], rMsg[MQ_RX_LEN]; + + sprintf(qName, "testMqTimedOneLevelCom_%d", GetRandom(10000)); + setAttr.mq_msgsize = MQ_MSG_SIZE; + setAttr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &setAttr); + ASSERT_TRUE(queue != (mqd_t)-1) << "ERROR: mq_open() == (mqd_t)-1"; + + tts.tv_sec = time(NULL) + 1; + tts.tv_nsec = 0; + EXPECT_TRUE(mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &tts) == 0) << "ERROR: mq_timedsend() != 0"; + + EXPECT_TRUE(mq_getattr(queue, &getAttr) == 0) << "ERROR: mq_getattr() != 0"; + EXPECT_TRUE(getAttr.mq_msgsize == MQ_MSG_SIZE) << "getAttr.mq_msgsize != MQ_MSG_SIZE, " << \ + "getAttr.mq_msgsize = " << getAttr.mq_msgsize; + EXPECT_TRUE(getAttr.mq_maxmsg == MQ_MAX_MSG) << "getAttr.mq_maxmsg != MQ_MAX_MSG, " << \ + "getAttr.mq_maxmsg = " << getAttr.mq_maxmsg; + rts.tv_sec = time(NULL) + 1; + rts.tv_nsec = 0; + EXPECT_TRUE(mq_timedreceive(queue, rMsg, getAttr.mq_msgsize, &prio, &rts) != -1) << \ + "ERROR: mq_timedreceive() == -1"; + EXPECT_TRUE(prio == 0) << "ERROR: prio != 0, prio = " << prio; + EXPECT_TRUE(strncmp(MQ_MSG, rMsg, MQ_MSG_LEN) == 0) << "sent != received: sent = " << \ + MQ_MSG << ", received = " << rMsg; + EXPECT_TRUE(mq_close(queue) == 0) << "ERROR: mq_close() != 0"; + ASSERT_TRUE(mq_unlink(qName) == 0) << "ERROR: mq_unlink() != 0"; +} + +/** + * @tc.number SUB_KERNEL_IPC_MQ_0300 + * @tc.name all send and all receive function test + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ + HWTEST_F(IpcMqTest, testMqAllOneLevelCom, TestSize.Level2) +{ + mqd_t queue; + unsigned int prio; + struct timespec tts, rts; + struct mq_attr getAttr, setAttr; + char qName[MQ_NAME_LEN], rMsg[MQ_RX_LEN]; + + sprintf(qName, "testMqAllOneLevelCom_%d", GetRandom(10000)); + + memset(&getAttr, 0, sizeof(getAttr)); + memset(&setAttr, 0, sizeof(setAttr)); + setAttr.mq_msgsize = MQ_MSG_SIZE; + setAttr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &setAttr); + ASSERT_TRUE(queue != (mqd_t)-1) << "ERROR: mq_open() == (mqd_t)-1"; + + EXPECT_TRUE(mq_getattr(queue, &setAttr) == 0) << "ERROR: mq_getattr() != 0"; + setAttr.mq_msgsize = MQ_MSG_SIZE; + setAttr.mq_maxmsg = MQ_MAX_MSG; + EXPECT_TRUE(mq_setattr(queue, &setAttr, NULL) == 0) << "ERROR: mq_setattr() != 0"; + EXPECT_TRUE(mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO) == 0) << "ERROR: mq_send() != 0"; + + EXPECT_TRUE(mq_getattr(queue, &getAttr) == 0) << "ERROR: mq_getattr() != 0"; + EXPECT_TRUE(getAttr.mq_msgsize == setAttr.mq_msgsize) << "ERROR: getAttr.mq_msgsize != setAttr.mq_msgsize," \ + " getAttr.mq_msgsize = " << getAttr.mq_msgsize << " setAttr.mq_msgsize = " << setAttr.mq_msgsize; + EXPECT_TRUE(getAttr.mq_maxmsg == setAttr.mq_maxmsg) << "ERROR: getAttr.mq_maxmsg != setAttr.mq_maxmsg," \ + " getAttr.mq_maxmsg = " << getAttr.mq_maxmsg << " setAttr.mq_maxmsg = " << setAttr.mq_maxmsg; + EXPECT_TRUE(getAttr.mq_curmsgs == 1) << \ + "ERROR: getAttr.mq_curmsgs != 1, getAttr.mq_curmsgs = " << getAttr.mq_curmsgs; + + EXPECT_TRUE(mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio) != -1) << \ + "ERROR: mq_receive() == -1"; + EXPECT_TRUE(strncmp(MQ_MSG, rMsg, MQ_MSG_LEN) == 0) << \ + "sent != received: sent = " << MQ_MSG << ", received = " << rMsg; + + tts.tv_sec = time(NULL) + 1; + tts.tv_nsec = 0; + EXPECT_TRUE(mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &tts) == 0) << "ERROR: mq_timedsend() != 0"; + + EXPECT_TRUE(mq_getattr(queue, &getAttr) == 0) << "ERROR: mq_getattr() != 0"; + EXPECT_TRUE(getAttr.mq_msgsize == setAttr.mq_msgsize) << "ERROR: getAttr.mq_msgsize != setAttr.mq_msgsize"; + EXPECT_TRUE(getAttr.mq_maxmsg == setAttr.mq_maxmsg) << "ERROR: getAttr.mq_maxmsg != setAttr.mq_maxmsg"; + EXPECT_TRUE(getAttr.mq_curmsgs == 1) << "ERROR: getAttr.mq_curmsgs != 1"; + + rts.tv_sec = time(NULL) + 1; + rts.tv_nsec = 0; + EXPECT_TRUE(mq_timedreceive(queue, rMsg, getAttr.mq_msgsize, &prio, &rts) != -1) << \ + "ERROR: mq_timedreceive() == -1"; + EXPECT_TRUE(strncmp(MQ_MSG, rMsg, MQ_MSG_LEN) == 0) << \ + "sent != received: sent = " << MQ_MSG << ", received = " << rMsg; + + EXPECT_TRUE(mq_close(queue) == 0) << "ERROR: mq_close() != 0"; + ASSERT_TRUE(mq_unlink(qName) == 0) << "ERROR: mq_unlink() != 0" << \ + " errno = " << errno << " strerror(errno) = " << strerror(errno); +} + +/** + * @tc.number SUB_KERNEL_IPC_MQ_0400 + * @tc.name mq_send and mq_receive function test in child and parent process + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(IpcMqTest, testMqTwoLevelCom, TestSize.Level1) +{ + mqd_t queue; + pid_t pid; + unsigned int prio; + struct mq_attr getAttr, setAttr; + char qName[MQ_NAME_LEN], rMsg[MAX_MQ_MSG_SIZE], sMsg[MAX_MQ_MSG_SIZE]; + + for (int i=0; i +#include +#include +#include +#include +#include + +const int MQ_NAME_LEN = 64; // mqueue name len +const int MQ_TX_LEN = 64; // mqueue send buffer len +const int MQ_RX_LEN = 64; // mqueue receive buffer len +const int MQ_MSG_SIZE = 64; // mqueue message size +const int MQ_MSG_PRIO = 0; // mqueue message priority +const int MQ_MAX_MSG = 16; // mqueue message number + +const char MQ_MSG[] = "MessageToSend"; // mqueue message to send +const int MQ_MSG_LEN = sizeof(MQ_MSG); // mqueue message len to send + +class IpcMqTest : public::testing::Test { +}; + +#endif \ No newline at end of file diff --git a/kernel_lite/ipc_posix/src/PipeTest.cpp b/kernel_lite/ipc_posix/src/PipeTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..a5ec53b3addc70e8356888a9bf03b21632609e1a --- /dev/null +++ b/kernel_lite/ipc_posix/src/PipeTest.cpp @@ -0,0 +1,208 @@ +/* + * Copyright (c) 2020 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 "utils.h" +#include "log.h" +#include "KernelConstants.h" + +using namespace testing::ext; + +class PipeTest : public::testing::Test { +}; + +/** + * @tc.number SUB_KERNEL_IPC_PIPE_0100 + * @tc.name basic function test + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(PipeTest, testHelloWorld, TestSize.Level0) +{ + int fd[2]; + char readBuffer[100]; + int ret; + + ret = pipe(fd); + ASSERT_EQ(ret, 0) << "> parent: pipe errno = " << errno; + + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "> parent: fork errno = " << errno; + if (pid == 0) { + close(fd[1]); + if (read(fd[0], readBuffer, 20) == -1) { + close(fd[0]); + exit(1); + } + if (strncmp(readBuffer, "hello world", sizeof("hello world")) != 0) { + close(fd[0]); + exit(1); + } + close(fd[0]); + exit(0); + } + + // parent + close(fd[0]); + ret = write(fd[1], "hello world", sizeof("hello world")); + EXPECT_NE(ret, -1) << "> write errno = " << errno; + close(fd[1]); + + Msleep(100); + AssertProcExitedOK(pid); +} + +/** + * @tc.number SUB_KERNEL_IPC_PIPE_0300 + * @tc.name pipe buffer teset + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(PipeTest, testPipeBuf, TestSize.Level3) +{ + const int arrSize = MAX_PIPE_BUFFER + 1000; + int fd[2]; + int tmpInt; + char testBuffer[arrSize]; + memset(testBuffer, '1', sizeof(testBuffer)); + + tmpInt = pipe(fd); + ASSERT_EQ(tmpInt, 0) << "> parent: Create Pipe Error! "; + + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "> parent: error : fork"; + if (pid == 0) { + char readBuffer[arrSize]; + memset(readBuffer, 0, sizeof(readBuffer)); + close(fd[1]); + + Msleep(60); + if (fcntl(fd[0], F_SETFL, O_NONBLOCK) == -1) { + LOG("> child fcntl errno = %d", errno); + } + tmpInt = read(fd[0], readBuffer, arrSize); + if (tmpInt != MAX_PIPE_BUFFER) { + LOG("> child: error : read MAX_PIPE_BUFFER = %d, not %d", tmpInt, MAX_PIPE_BUFFER); + close(fd[0]); + exit(1); + } + if (strncmp(testBuffer, readBuffer, MAX_PIPE_BUFFER) != 0) { + close(fd[0]); + exit(1); + } + close(fd[0]); + exit(0); + } + + // parent + char writeBuffer[arrSize]; + memset(writeBuffer, '1', sizeof(writeBuffer)); + close(fd[0]); + + Msleep(30); + EXPECT_NE(fcntl(fd[1], F_SETFL, O_NONBLOCK), -1) << "> fcntl errno = " << errno; + tmpInt = write(fd[1], writeBuffer, arrSize); + LOG("> parent: write num = %d", tmpInt); + EXPECT_NE(tmpInt, -1) << "> parent: error : write num = "<< tmpInt; + close(fd[1]); + + Msleep(100); + AssertProcExitedOK(pid); +} + +/** + * @tc.number SUB_KERNEL_IPC_PIPE_0500 + * @tc.name teset max pipe number + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(PipeTest, testMaxPipeNum, TestSize.Level2) +{ + int fd[MAX_PIPE_NUMBER * 2]; // two file descriptor + int tmpInt; + for (int i = 0; i < MAX_PIPE_NUMBER; i++) { + tmpInt = pipe(&fd[i * 2]); + ASSERT_EQ(tmpInt, 0) << "> Create Pipe Error! " << errno; + LOG("> Create Pipe %d", i); + } + tmpInt = pipe(fd); + EXPECT_TRUE((tmpInt == -1) && (errno == ENFILE)) << "> tmpInt = "<< tmpInt << "\n" \ + << "> errno = " << errno; + for (int i = 0; i < MAX_PIPE_NUMBER * 2; i++) { + close(fd[i]); + } +} + +/** + * @tc.number SUB_KERNEL_IPC_PIPE_0600 + * @tc.name test pipe-ipc between brother + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(PipeTest, testBrotherHelloWorld, TestSize.Level1) +{ + int fd[2]; + char readBuffer[100]; + int ret; + + ret = pipe(fd); + ASSERT_EQ(ret, 0) << "> parent: pipe errno = " << errno; + + pid_t pidChild1 = fork(); + ASSERT_TRUE(pidChild1 >= 0) << "> parent: fork errno = " << errno; + if (pidChild1 == 0) { + close(fd[1]); + if (read(fd[0], readBuffer, 20) == -1) { + close(fd[0]); + exit(1); + } + if (strncmp(readBuffer, "hello world", sizeof("hello world")) != 0) { + close(fd[0]); + exit(1); + } + close(fd[0]); + exit(0); + } + + pid_t pidChild2 = fork(); + ASSERT_TRUE(pidChild2 >= 0) << "> parent: fork errno = " << errno; + if (pidChild2 == 0) { + close(fd[0]); + ret = write(fd[1], "hello world", sizeof("hello world")); + if (ret == -1) { + LOG("> child write errno = %d", errno); + } + close(fd[1]); + exit(0); + } + + close(fd[0]); + close(fd[1]); + + Msleep(100); + AssertProcExitedOK(pidChild1); + AssertProcExitedOK(pidChild2); +} diff --git a/kernel_lite/ipc_posix/src/ShmTest.cpp b/kernel_lite/ipc_posix/src/ShmTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..a564ba3f9a2746e2243117098552355be96fd7d7 --- /dev/null +++ b/kernel_lite/ipc_posix/src/ShmTest.cpp @@ -0,0 +1,342 @@ +/* + * Copyright (c) 2020 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 "utils.h" +#include "log.h" + +using namespace testing::ext; + +class ShmTest : public::testing::Test { +public: + static const char SHM_TEST_STR[]; + static const int SHM_TEST_STR_LEN; +}; + +const char ShmTest::SHM_TEST_STR[] = "hello shmem"; +const int ShmTest::SHM_TEST_STR_LEN = sizeof(SHM_TEST_STR); + +/** + * @tc.number SUB_KERNEL_IPC_SHM_ALL_0100 + * @tc.name basic function test : hello world + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(ShmTest, testShmBasic, TestSize.Level0) +{ + const int memSize = 1024; + int shmid; + char *shared = nullptr; + + shmid = shmget(static_cast IPC_PRIVATE, memSize, 0666 | IPC_CREAT); + ASSERT_NE(shmid, -1) << "> parent: shmid errno = " << errno; + + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "> parent: fork errno = " << errno; + if (pid == 0) { + int exitCode = 0; + Msleep(40); + shared = static_cast(shmat(shmid, nullptr, 0)); + if (shared == reinterpret_cast(-1)) { + LOG("> child: shmat errno = %d", errno); + exit(1); + } + if (strncmp(shared, SHM_TEST_STR, SHM_TEST_STR_LEN) != 0) { + LOG("> child: error strncmp() shared = %s", shared); + exitCode = 1; + } + if ((shmdt(shared)) == -1) { + LOG("> child: shmdt errno = %d", errno); + exit(1); + } + if (shmctl(shmid, IPC_RMID, nullptr) == -1) { + LOG("> child: shmctl errno = %d", errno); + exit(1); + } + exit(exitCode); + } + // parent + shared = static_cast(shmat(shmid, nullptr, 0)); + ASSERT_NE(shared, (void*)-1) << "> parent : error: shmat"; + strncpy(shared, SHM_TEST_STR, SHM_TEST_STR_LEN); + ASSERT_NE(shmdt(shared), -1) << "> parent: error : shmdt"; + + Msleep(100); + AssertProcExitedOK(pid); +} + +/** + * @tc.number SUB_KERNEL_IPC_SHM_ALL_0300 + * @tc.name Single-process test + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(ShmTest, testShmSingleProcess, TestSize.Level1) +{ + const int memSize = 1024; + char *shared = nullptr; + + int shmid = shmget(static_cast IPC_PRIVATE, memSize, 0666 | IPC_CREAT); + ASSERT_NE(shmid, -1) << "> shmget errno = " << errno; + + shared = static_cast(shmat(shmid, nullptr, 0)); + ASSERT_NE(shared, (void*)-1) << "> shmat errno = " << errno; + strncpy(shared, SHM_TEST_STR, SHM_TEST_STR_LEN); + + int re = shmdt(shared); + ASSERT_NE(re, -1) << "> shmdt errno = " << errno; + + re = shmctl(shmid, IPC_RMID, nullptr); + ASSERT_NE(re, -1) << "> shmctl errno = " << errno; +} + +/** + * @tc.number SUB_KERNEL_IPC_SHM_SHMGET_0100 + * @tc.name shmat basic function test + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(ShmTest, testShmget, TestSize.Level0) +{ + const int memSize = 1024; + int tmp; + int shmid; + int shmidTmp; + int tmpKey = GetRandom(2147483647); + LOG("> tmpKey = %d", tmpKey); + + shmid = shmget(IPC_PRIVATE, memSize, 0666 | IPC_CREAT); + ASSERT_NE(shmid, -1) << "> shmget : errno = " << errno; + tmp = shmctl(shmid, IPC_RMID, nullptr); + ASSERT_NE(tmp, -1) << "shmctl : error : IPC_RMID "; + + // make sure tmpKey free + shmid = shmget(key_t(tmpKey), memSize, 0666 | IPC_CREAT); + ASSERT_NE(shmid, -1) << "> shmget : errno = " << errno; + tmp = shmctl(shmid, IPC_RMID, nullptr); + ASSERT_NE(tmp, -1) << "shmctl : error : IPC_RMID "; + + shmid = shmget(key_t(tmpKey), memSize, IPC_EXCL | IPC_CREAT); + ASSERT_NE(shmid, -1) << "> shmget : errno = " << errno; + + shmidTmp = shmid; + shmidTmp = shmget(key_t(tmpKey), memSize, IPC_EXCL | IPC_CREAT); + ASSERT_EQ(shmidTmp, -1) << "> shmget : errno = " << errno; + + tmp = shmctl(shmid, IPC_RMID, nullptr); + ASSERT_NE(tmp, -1) << "> shmctl : error : IPC_RMID "; + + shmid = shmget(key_t(tmpKey), memSize, 0); + ASSERT_EQ(shmid, -1) << "> shmget : errno = " << errno; + + shmid = shmget(IPC_PRIVATE, 0, 0666 | IPC_CREAT); + ASSERT_EQ(shmid, -1) << "> shmget : errno = " << errno; + + shmid = shmget(IPC_PRIVATE, memSize, 0666 | IPC_CREAT); + ASSERT_NE(shmid, -1) << "> shmget : errno = " << errno; + + tmp = shmctl(shmid, IPC_RMID, nullptr); + ASSERT_NE(tmp, -1) << "> shmctl : error : IPC_RMID"; +} + +/** + * @tc.number SUB_KERNEL_IPC_SHM_SHMAT_0100 + * @tc.name shmat: SHM_REMAP function test + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(ShmTest, testShmatSHM_REMAP, TestSize.Level1) +{ + const int memSize = 1024; + int shmid; + char *shared = nullptr; + + shmid = shmget(static_cast IPC_PRIVATE, memSize, 0666 | IPC_CREAT); + ASSERT_NE(shmid, -1) << "> parent: error : shmget"; + + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "> parent: error : fork"; + if (pid == 0) { + Msleep(10); + int exitCode = 0; + shared = static_cast(shmat(shmid, nullptr, 0)); + if (shared == reinterpret_cast(-1)) { + LOG("> child: shmat 1 : errno = %d", errno); + exit(1); + } + if (shmdt(shared) == -1) { + LOG("> child: shmdt: errno = %d", errno); + exit(1); + } + shared = static_cast(shmat(shmid, shared, SHM_REMAP)); + if (shared == reinterpret_cast(-1)) { + LOG("> child: shmat 2 : errno = %d", errno); + exit(1); + } + if (strncmp(shared, SHM_TEST_STR, SHM_TEST_STR_LEN) != 0) { + LOG("> child: error strncmp() shared = %s", shared); + exitCode = 1; + } + if ((shmdt(shared)) == -1) { + LOG("> child: shmdt : errno = %d", errno); + exit(1); + } + exit(exitCode); + } + // parent + shared = static_cast(shmat(shmid, nullptr, 0)); + ASSERT_NE(shared, (void*)-1) << "> shmat 1 : errno = " << errno; + ASSERT_NE(shmdt(shared), -1) << "> shmdt 1 : errno = " << errno; + shared = static_cast(shmat(shmid, shared, SHM_REMAP)); + ASSERT_NE(shared, (void*)-1) << "> parent: shmat 2 : errno = " << errno; + strncpy(shared, SHM_TEST_STR, SHM_TEST_STR_LEN); + ASSERT_NE(shmdt(shared), -1) << "> parent: shmdt 2 : errno = " << errno; + Msleep(20); + ASSERT_NE(shmctl(shmid, IPC_RMID, nullptr), -1) << "> parent: shmctl : errno = " << errno; + + Msleep(50); + AssertProcExitedOK(pid); +} + +/** + * @tc.number SUB_KERNEL_IPC_SHM_SHMAT_0300 + * @tc.name shmat: SHM_RND function test + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(ShmTest, testShmatSHM_RND, TestSize.Level0) +{ + const int memSize = 1024; + int tmp; + int shmid; + void *shared = nullptr; + + Msleep(10); + shmid = shmget(IPC_PRIVATE, memSize, 0666 | IPC_CREAT); + EXPECT_NE(shmid, -1) << "shmget : errno = " << errno; + + shared = shmat(shmid, nullptr, 0); + EXPECT_NE(shared, (void*)-1) << "> shmat : errno = " << errno; + int re = shmdt(shared); + EXPECT_NE(re, -1) << "> shmdt : errno = " << errno; + + void *sharedTmp = shared; + sharedTmp = shmat(shmid, sharedTmp, SHM_RND); + EXPECT_NE(sharedTmp, (void*)-1) << "> shmat : error : sharedTmp = " << sharedTmp << "shared = " << shared; + strncpy(static_cast(sharedTmp), SHM_TEST_STR, SHM_TEST_STR_LEN); + re = shmdt(sharedTmp); + EXPECT_NE(re, -1) << "> shmdt : errno = " << errno; + + tmp = shmctl(shmid, IPC_RMID, nullptr); + EXPECT_NE(tmp, -1) << "> shmctl : IPC_RMID errno = " << errno; +} + +/** + * @tc.number SUB_KERNEL_IPC_SHM_SHMCTL_0100 + * @tc.name shmctl: IPC_STAT and IPC_SET function test + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(ShmTest, testShmctl, TestSize.Level1) +{ + const int memSize = 4096; + struct shmid_ds shmPerm; + int tmp; + int shmid; + + LOG("> getuid = %d", getuid()); + LOG("> getgid = %d", getgid()); + LOG("> getpid = %d", getpid()); + + Msleep(10); + shmid = shmget(IPC_PRIVATE, memSize, 0666 | IPC_CREAT); + ASSERT_NE(shmid, -1) << "> shmget : errno = " << errno; + + tmp = shmctl(shmid, IPC_STAT, &shmPerm); + EXPECT_NE(tmp, -1) << "> shmctl : IPC_STAT1 :erron = " << errno; + EXPECT_EQ(shmPerm.shm_lpid, 0); // PID of last shmat/shmdt + EXPECT_EQ(shmPerm.shm_nattch, 0); // No. of current attaches + + char *shared = static_cast(shmat(shmid, nullptr, 0)); + EXPECT_NE(shared, (void*)-1) << "> shmat : errno = " << errno; + + tmp = shmctl(shmid, IPC_STAT, &shmPerm); + ASSERT_NE(tmp, -1) << "> shmctl : IPC_STAT2 :erron = " << errno; + EXPECT_EQ(shmPerm.shm_perm.__key, 0); // Key supplied to shmget + EXPECT_EQ(shmPerm.shm_perm.cuid, geteuid()); // Effective UID of creator + EXPECT_EQ(shmPerm.shm_perm.uid, geteuid()); // Effective UID of owne + EXPECT_EQ(shmPerm.shm_perm.cgid, getegid()); // Effective GID of creator + EXPECT_EQ(shmPerm.shm_perm.gid, getegid()); // Effective GID of owner + EXPECT_EQ(shmPerm.shm_perm.mode, 0666); // Permissions + SHM_DEST and SHM_LOCKED flags + LOG("> last shmat() time %lld", shmPerm.shm_atime); // Last attach time + LOG("> last shmdt() time %lld", shmPerm.shm_dtime); // Last detach time + EXPECT_EQ(shmPerm.shm_segsz, memSize); // Size of segment (bytes) + EXPECT_EQ(shmPerm.shm_cpid, getpid()); // PID of creator + EXPECT_EQ(shmPerm.shm_lpid, getpid()); // PID of last shmat/shmdt + EXPECT_EQ(shmPerm.shm_nattch, 1); // No. of current attaches + + tmp = shmctl(shmid, IPC_SET, &shmPerm); + EXPECT_NE(shared, (void*)-1) << "> shmat : errno = " << errno; + + tmp = shmdt(shared); + ASSERT_NE(tmp, -1) << "> shmdt : errno = " << errno; + + tmp = shmctl(shmid, IPC_RMID, nullptr); + ASSERT_NE(tmp, -1) << "> shmctl : IPC_RMID : errno = " << errno; +} + +/** + * @tc.number SUB_KERNEL_IPC_SHM_SHMCTL_0200 + * @tc.name shmctl: IPC_INFO and SHM_INFO function test + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(ShmTest, testShmctlINFO, TestSize.Level0) +{ + int tmp; + struct shminfo buf; + tmp = shmctl(0, IPC_INFO, (struct shmid_ds *) &buf); + EXPECT_NE(tmp, -1) << "shmctl : IPC_INFO errno = " << errno; + LOG("> shminfo.shmmax = %lu", buf.shmmax); // Maximum segment size 42428800 + EXPECT_EQ(buf.shmmin, 1) << "> shminfo.shmmin = " << buf.shmmin; // Minimum segment size 1 + LOG("> shminfo.shmmni = %lu", buf.shmmni); // Maximum number of segments 192 + LOG("> shminfo.shmseg = %lu", buf.shmseg); // Maximum number of segments that a process can attach 128 + LOG("> shminfo.shmall = %lu", buf.shmall); // Maximum number of pages of shared memory, system-wide 12800 + + // Describes the system resource information for Shared memory + struct shm_info info; + tmp = shmctl(0, SHM_INFO, (struct shmid_ds *) &info); + EXPECT_NE(tmp, -1) << "shmctl : SHM_INFO errno = " << errno; + LOG("> shm_info.used_ids = %d", info.used_ids); // Currently existing segments + LOG("> shm_info.shm_tot = %lu", info.shm_tot); // Total number of shared memory pages + LOG("> shm_info.shm_rss = %lu", info.shm_rss); // Resident shared memory pages + LOG("> shm_info.shm_swp = %lu", info.shm_swp); // Swapped shared memory pages + LOG("> shm_info.__swap_attempts = %ld", info.__swap_attempts); // Number of exchange attempts + LOG("> shm_info.__swap_successes = %ld", info.__swap_successes); // Number of successful exchanges +} diff --git a/kernel_lite/ipc_posix/src/SignalTest.cpp b/kernel_lite/ipc_posix/src/SignalTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..00406277e3cce45e69eeb8d4852dfa927f88e127 --- /dev/null +++ b/kernel_lite/ipc_posix/src/SignalTest.cpp @@ -0,0 +1,829 @@ +/* + * Copyright (c) 2020 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 "SignalTest.h" +#include +#include +#include +#include +#include +#include +#include "log.h" +#include "utils.h" + +using namespace testing::ext; + +/** + * @tc.number SUB_KERNEL_IPC_SIGNAL_0100 + * @tc.name test SIGKILL and SIGSTOP's action can not changed by signal + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(IpcSignalTest, testSignalFailSig, TestSize.Level2) +{ + int rt, status; + SignalFailTest(SIGKILL, SignalHandler); + SignalFailTest(SIGKILL, SIG_IGN); + SignalFailTest(SIGSTOP, SignalHandler); + SignalFailTest(SIGSTOP, SIG_IGN); +} + +/** + * @tc.number SUB_KERNEL_IPC_SIGTIMEDWAIT_0100 + * @tc.name sigtimedwait still work even blocked by sigprocmask + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(IpcSignalTest, testSigtimedwaitBlock, TestSize.Level1) +{ + int rt, status; + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + if (pid == 0) { // child + int exitCode = 0; + signal(SIGSEGV, SignalHandler); + struct timespec time1 = {0, 100*1000000}; + sigset_t sigmask, timeset; + sigemptyset(&sigmask); + sigaddset(&sigmask, SIGINT); + sigaddset(&sigmask, SIGSEGV); + sigemptyset(×et); + sigaddset(×et, SIGSEGV); + + sigprocmask(SIG_BLOCK, &sigmask, 0); + Msleep(80); + + rt = sigtimedwait(×et, 0, &time1); + if (rt != SIGSEGV) { + LOG("sigtimedwait return fail, expected:%d, actual:%d", SIGSEGV, rt); + exitCode = 1; + } + + // check the sigprocmask set not changed + sigemptyset(&sigmask); + sigprocmask(SIG_UNBLOCK, NULL, &sigmask); + if (sigismember(&sigmask, SIGINT) != 1) { + LOG("SIGINT should still in block set!"); + exitCode = 1; + } + if (sigismember(&sigmask, SIGSEGV) != 1) { + LOG("SIGSEGV should still in block set!"); + exitCode = 1; + } + exit(exitCode); + } else { // parent + Msleep(40); + kill(pid, SIGSEGV); + Msleep(200); + AssertProcExitedOK(pid); + } + sigset_t pending; + sigemptyset(&pending); + sigpending(&pending); + if (sigisemptyset(&pending)) { + LOG("pending set empty"); + return; + } + LOG("========pending set not empty========="); + if (sigismember(&pending, SIGCHLD)) { + LOG("pending set is SIGCHLD"); + return; + } else { + LOG("pending set is not SIGCHLD!"); + } +} + +/** + * @tc.number SUB_KERNEL_IPC_SIGTIMEDWAIT_0200 + * @tc.name sigtimedwait error test: timeout or interupted. + * by now, liteos sigtimedwait cannot interupted + * so the interupte-check-code will run only when 'POSIX_TEST' is set + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(IpcSignalTest, testSigtimedwaitTimeout, TestSize.Level2) +{ + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + if (pid == 0) { // child + int rt; + int exitCode = 0; + sigset_t set; + siginfo_t si; + struct timespec ts = {0, 500*1000000}; + sigemptyset(&set); + sigaddset(&set, SIGUSR1); + + struct timespec time1 = {0, 0}; + struct timespec time2 = {0, 0}; + errno = 0; + clock_gettime(CLOCK_MONOTONIC, &time1); + rt = sigtimedwait(&set, &si, &ts); + clock_gettime(CLOCK_MONOTONIC, &time2); + LOG("sigtimedwait returned: %d", rt); + if (rt != -1 || errno != EAGAIN) { + LOG("sigtimedwait error check fail, expected errno=%d(EAGAIN), actual=%d", EAGAIN, errno); + exitCode = 1; + } + double duration = (time2.tv_sec - time1.tv_sec)*1000.0 + (time2.tv_nsec - time1.tv_nsec)/1000000.0; + LOG("clock_gettime1 : tv_sec=%ld, tv_nsec=%ld", time1.tv_sec, time1.tv_nsec); + LOG("clock_gettime2 : tv_sec=%ld, tv_nsec=%ld", time2.tv_sec, time2.tv_nsec); + LOG("duration : %f ms", duration); + if (CheckValueClose(1000, duration)) { + LOG("Timeout value accuracy check fail, expected=1000, actual=%f", duration); + exitCode = 1; + } + + LOG("child exited with code=%d", exitCode); + exit(exitCode); + } else { // parent + sleep(1); + AssertProcExitedOK(pid); + } +} + + +/** + * @tc.number SUB_KERNEL_IPC_SIGTIMEDWAIT_0300 + * @tc.name sigtimedwait siginfo_t test + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(IpcSignalTest, testSigtimedwaitSiginfo, TestSize.Level2) +{ + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + if (pid == 0) { // child + int exitCode = 0; + signal(SIGINT, SignalHandler); + struct timespec time1 = {0, 100*1000000}; + sigset_t set; + siginfo_t si; + sigemptyset(&set); + sigaddset(&set, SIGINT); + int rt = sigtimedwait(&set, &si, &time1); + if (rt != SIGINT) { + LOG("sigtimedwait should return the signal, expected:%d, actual:%d", SIGINT, rt); + exitCode = 1; + } + LOGD("si: %d,%d,%d,%p", si.si_signo, si.si_code, si.si_value.slval_int, si.si_value.slval_int); + if (si.si_signo != SIGINT) { + LOG("sigtimedwait set siginfo_t fail, si_signo=%d", si.si_signo); + exitCode = 1; + } + // other area of siginfo_t is not supported yet, test code deleted + LOG("child exited with code=%d", exitCode); + exit(exitCode); + } else { // parent + Msleep(20); + kill(pid, SIGINT); + Msleep(100); + AssertProcExitedOK(pid); + } +} + +/** + * @tc.number SUB_KERNEL_IPC_SIGWAITINFO_0100 + * @tc.name test sigwaitinfo basic test: a pending signal should cause sigwaitinfo return immediately + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(IpcSignalTest, testSigwaitinfoBasic, TestSize.Level1) +{ + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + if (pid == 0) { // child + int exitCode = 0; + sigset_t set, pending; + sigemptyset(&pending); + sigemptyset(&set); + sigaddset(&set, SIGALRM); + signal(SIGALRM, SignalHandler); + if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) { + LOG("sigprocmask failed"); + exit(1); + } + LOG("raise SIGALRM"); + raise(SIGALRM); + + sigpending(&pending); + if (!sigismember(&pending, SIGALRM)) { + LOG("SIGALRM is not in pending set"); + exit(1); + } + + LOGD("before sigwaitinfo"); + struct timespec time1 = {0, 0}; + struct timespec time2 = {0, 0}; + clock_gettime(CLOCK_MONOTONIC, &time1); + int rt = sigwaitinfo(&set, NULL); + clock_gettime(CLOCK_MONOTONIC, &time2); + + LOGD("after sigwaitinfo"); + double duration = (time2.tv_sec - time1.tv_sec)*1000.0 + (time2.tv_nsec - time1.tv_nsec)/1000000.0; + LOG("duration: %f ms", duration); + if (CheckValueClose(0.1, duration)) { + LOG("sigwaitinfo should return immediately, but %f ms used", duration); + exitCode = 1; + } + if (rt != SIGALRM) { + LOG("sigwaitinfo should return the signal, expected:%d, actual:%d", SIGALRM, rt); + exitCode = 1; + } + LOG("child exited with code=%d", exitCode); + exit(exitCode); + } else { // parent + sleep(1); + AssertProcExitedOK(pid); + } +} + +/** + * @tc.number SUB_KERNEL_IPC_SIG_PAUSE_0100 + * @tc.name pause basic function test + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(IpcSignalTest, testPauseBasic, TestSize.Level1) +{ + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + if (pid == 0) { // child + struct timespec time1, time2; + int exitCode = 0; + signal(SIGQUIT, SignalHandler); + Msleep(100); + + clock_gettime(CLOCK_MONOTONIC, &time1); + int rt = pause(); + clock_gettime(CLOCK_MONOTONIC, &time2); + if (rt != -1) { + LOG("pause should return -1, but rt=%d", rt); + exitCode = 1; + } + if (errno != EINTR) { + LOG("pause should set errno to 4(EINTR),but get %d", errno); + exitCode = 1; + } + + long duration = (time2.tv_sec - time1.tv_sec)*1000 + (time2.tv_nsec - time1.tv_nsec)/1000000; + LOG("paused time: %ld ms", duration); + if (! CheckValueClose(100, duration, 0.2)) { + LOG("paused time check error."); + exitCode = 1; + } + if (mReceivedSignal != SIGQUIT) { + LOG("Received signal check fail, expected signal=%d", SIGQUIT); + exitCode = 1; + } + exit(exitCode); + } else { // parent + Msleep(200); + kill(pid, SIGQUIT); + Msleep(20); + AssertProcExitedOK(pid); + } +} +/** + * @tc.number SUB_KERNEL_IPC_SIG_PAUSE_0200 + * @tc.name pause basic function test + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(IpcSignalTest, testPauseAndMask, TestSize.Level1) +{ + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + if (pid == 0) { // child + int exitCode = 0; + signal(SIGINT, SignalHandler); + signal(SIGTRAP, SignalHandler); + + sigset_t sigmask; + sigemptyset(&sigmask); + sigaddset(&sigmask, SIGINT); + int rt = sigprocmask(SIG_BLOCK, &sigmask, NULL); + if (rt != 0) { + LOG("sigprocmask fail, rt=%d, errno=%d", rt, errno); + exit(1); + } + LOG("before pause"); + rt = pause(); + if (rt != -1) { + LOG("pause should return -1, but rt=%d", rt); + exitCode = 1; + } + if (errno != EINTR) { + LOG("pause should set errno to 4(EINTR),but get %d", errno); + exitCode = 1; + } + LOG("after pause"); + if (mReceivedSignal != SIGTRAP) { + LOG("Received signal check fail, expected %d,but get %d", SIGINT, mReceivedSignal); + exitCode = 1; + } + exit(exitCode); + } else { // parent + Msleep(20); + kill(pid, SIGINT); + Msleep(20); + AssertProcAlive(pid); + kill(pid, SIGTRAP); + Msleep(20); + AssertProcExitedOK(pid); + } + sigset_t pending; + sigemptyset(&pending); + sigpending(&pending); + if (sigisemptyset(&pending)) { + LOG("pending set empty"); + } else { + LOG("========pending set not empty========="); + } +} + +/** + * @tc.number SUB_KERNEL_IPC_SIGPENDING_0100 + * @tc.name sigpending basic function test, also test pending-signal-set should not inherited after fork, + but signal mask set should inherited, and the change of child's pending set should not effect parent's. + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(IpcSignalTest, testSigpendingBasic, TestSize.Level1) +{ + int status, rt; + sigset_t sigmask, oldmask; + sigset_t pending; + sigemptyset(&sigmask); + sigemptyset(&oldmask); + sigemptyset(&pending); + sigpending(&pending); + EXPECT_EQ(1, sigisemptyset(&pending)) << "initial pending set should empty"; + + signal(SIGALRM, SignalHandler); + + sigaddset(&sigmask, SIGALRM); + sigaddset(&sigmask, SIGUSR1); + sigprocmask(SIG_BLOCK, &sigmask, &oldmask); + EXPECT_EQ(1, sigisemptyset(&oldmask)) << "initial sig mask set should empty"; + rt = sigpending(&pending); + EXPECT_EQ(rt, 0); + EXPECT_EQ(1, sigisemptyset(&pending)) << "SIG_BLOCK set should not effect on pending set"; + + LOGD("raise SIGALRM"); + raise(SIGALRM); + sigpending(&pending); + EXPECT_EQ(1, sigismember(&pending, SIGALRM)); + + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + if (pid == 0) { // child + int exitCode = 0; + sigemptyset(&pending); + sigpending(&pending); + if (sigisemptyset(&pending) != 1) { + LOG("pending signal set should not reserved via fork"); + exitCode = 1; + } + + sigemptyset(&oldmask); + sigprocmask(SIG_BLOCK, NULL, &oldmask); // read mask + if ((sigismember(&oldmask, SIGALRM) != 1) || (sigismember(&oldmask, SIGUSR1) != 1)) { + LOG("signal mask set should reserved via fork"); + exitCode = 1; + } + + LOG("unblock SIGALRM."); + rt = sigprocmask(SIG_UNBLOCK, &sigmask, NULL); + sigemptyset(&pending); + sigpending(&pending); + if (sigisemptyset(&pending) != 1) { + LOG("pending signal set is not empty after unblock"); + exitCode = 1; + } + + LOG("child exit(%d).", exitCode); + exit(exitCode); + } else { // parent + Msleep(50); + AssertProcExitedOK(pid); + // check child's pending set should not effect parent's + sigemptyset(&pending); + sigpending(&pending); + EXPECT_EQ(1, sigismember(&pending, SIGALRM)) << "parent's pending set is changed!"; + } +} + +/** + * @tc.number SUB_KERNEL_IPC_SIGPROCMASK_0100 + * @tc.name sigprocmask function test: use raise and kill to send signal + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(IpcSignalTest, testSigprocmaskBasic, TestSize.Level1) +{ + int status, rt; + sigset_t sigmask, oldmask; + sigset_t pending; + sigemptyset(&sigmask); + sigemptyset(&oldmask); + sigemptyset(&pending); + sigaddset(&sigmask, SIGINT); + sigaddset(&sigmask, SIGUSR1); + rt = sigprocmask(SIG_BLOCK, &sigmask, &oldmask); + EXPECT_EQ(rt, 0); + + signal(SIGINT, SignalHandler); + signal(SIGUSR1, SignalHandler); + ASSERT_EQ(mReceivedSignal, 0); + + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + if (pid == 0) { // child + int exitCode = 0; + raise(SIGINT); + if (mReceivedSignal != 0) { + LOG("SignalHandler check fail, expected=%d, actual=%d", 0, mReceivedSignal); + LOG("SIGINT(%d) should has blocked!", SIGINT); + exit(1); + } + + LOG("unblock SIGINT"); + sigemptyset(&sigmask); + sigaddset(&sigmask, SIGINT); + rt = sigprocmask(SIG_UNBLOCK, &sigmask, NULL); + EXPECT_EQ(rt, 0); + + // check the new block set + sigemptyset(&oldmask); + sigprocmask(SIG_UNBLOCK, NULL, &oldmask); + if (sigismember(&oldmask, SIGINT) == 1) { + LOG("SIGINT should has deleted from block set!"); + exitCode = 1; + } + if (sigismember(&oldmask, SIGUSR1) != 1) { + LOG("SIGUSR1 should still in block set!"); + exitCode = 1; + } + if (mReceivedSignal != SIGINT) { + LOG("SignalHandler check fail, expected=%d, actual=%d", SIGINT, mReceivedSignal); + LOG("SIGALRM should deliver after unblock!"); + exitCode = 1; + } + + // test kill + mReceivedSignal = 0; + Msleep(80); + sigpending(&pending); + if (!sigismember(&pending, SIGUSR1)) { + LOG("SIGUSR1 is not in pending set!"); + exitCode = 1; + } else { + LOG("SIGUSR1 is in pending set."); + } + + if (mReceivedSignal != 0) { + LOG("SignalHandler check fail, expected=%d, actual=%d", 0, mReceivedSignal); + LOG("SIGUSR1(%d) should has blocked!", SIGUSR1); + exit(1); + } + + LOG("unblock SIGUSR1"); + sigemptyset(&sigmask); + sigaddset(&sigmask, SIGUSR1); + sigprocmask(SIG_UNBLOCK, &sigmask, NULL); + + if (mReceivedSignal != SIGUSR1) { + LOG("SignalHandler check fail, expected=%d, actual=%d", SIGUSR1, mReceivedSignal); + LOG("SIGUSR1 should deliver after unblock!"); + exitCode = 1; + } + + LOG("child exit(%d).", exitCode); + exit(exitCode); + } else { // parent + Msleep(50); + kill(pid, SIGUSR1); + Msleep(50); + ExpectProcExitedOK(pid); + } + // restore default config + signal(SIGINT, SIG_DFL); + signal(SIGUSR1, SIG_DFL); + rt = sigprocmask(SIG_UNBLOCK, &sigmask, NULL); + EXPECT_EQ(rt, 0); +} + +/** + * @tc.number SUB_KERNEL_IPC_SIGPROCMASK_0200 + * @tc.name sigprocmask function test: use alarm to send the signal + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(IpcSignalTest, testSigprocmaskAlarm, TestSize.Level2) +{ + int status, rt; + sigset_t sigmask, oldmask; + sigset_t pending; + sigemptyset(&sigmask); + sigemptyset(&oldmask); + sigemptyset(&pending); + sigaddset(&sigmask, SIGALRM); + rt = sigprocmask(SIG_BLOCK, &sigmask, &oldmask); + ASSERT_EQ(rt, 0); + + signal(SIGALRM, SignalHandler); + ASSERT_EQ(mReceivedSignal, 0); + alarm(1); + Msleep(1100); + + sigpending(&pending); + EXPECT_EQ(1, sigismember(&pending, SIGALRM)); + EXPECT_EQ(mReceivedSignal, 0); + + LOG("unblock SIGALRM."); + rt = sigprocmask(SIG_UNBLOCK, &sigmask, NULL); + EXPECT_EQ(rt, 0); + ASSERT_EQ(mReceivedSignal, SIGALRM); + + signal(SIGALRM, SIG_DFL); +} + +/** + * @tc.number SUB_KERNEL_IPC_SIGPROCMASK_0300 + * @tc.name sigprocmask function test: mask operation + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(IpcSignalTest, testSigprocmaskSetMask, TestSize.Level2) +{ + int rt; + sigset_t sigmask, oldmask, pending; + sigemptyset(&sigmask); + sigemptyset(&oldmask); + sigemptyset(&pending); + sigaddset(&sigmask, SIGALRM); + rt = sigprocmask(SIG_BLOCK, &sigmask, NULL); + ASSERT_EQ(rt, 0); + sigemptyset(&sigmask); + sigaddset(&sigmask, SIGINT); + rt = sigprocmask(SIG_BLOCK, &sigmask, NULL); + ASSERT_EQ(rt, 0); + + LOG("add a new sig to block set"); + rt = sigprocmask(SIG_BLOCK, NULL, &oldmask); // check + ASSERT_EQ(rt, 0); + EXPECT_EQ(1, sigismember(&oldmask, SIGALRM)); + EXPECT_EQ(1, sigismember(&oldmask, SIGINT)); + + LOG("unblock a not-in-set sig"); + sigemptyset(&sigmask); + sigaddset(&sigmask, SIGTRAP); + rt = sigprocmask(SIG_UNBLOCK, &sigmask, NULL); + ASSERT_EQ(rt, 0); + rt = sigprocmask(SIG_UNBLOCK, NULL, &oldmask); // check + EXPECT_EQ(1, sigismember(&oldmask, SIGALRM)); + EXPECT_EQ(1, sigismember(&oldmask, SIGINT)); + EXPECT_EQ(0, sigismember(&oldmask, SIGTRAP)); + + LOG("set new block set, clear old one"); + rt = sigprocmask(SIG_SETMASK, &sigmask, NULL); + ASSERT_EQ(rt, 0); + rt = sigprocmask(10, NULL, &oldmask); // check + ASSERT_EQ(rt, 0); + EXPECT_EQ(0, sigismember(&oldmask, SIGALRM)); + EXPECT_EQ(0, sigismember(&oldmask, SIGINT)); + EXPECT_EQ(1, sigismember(&oldmask, SIGTRAP)); + + LOG("unblock git, clear the block set"); + rt = sigprocmask(SIG_UNBLOCK, &sigmask, NULL); + ASSERT_EQ(rt, 0); + rt = sigprocmask(100, NULL, &oldmask); // check + ASSERT_EQ(rt, 0); + EXPECT_EQ(1, sigisemptyset(&oldmask)); +} +/** + * @tc.number SUB_KERNEL_IPC_SIGPROCMASK_0400 + * @tc.name sigprocmask function test: don't block signal that not in block-set + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(IpcSignalTest, testSigprocmaskNotinSet, TestSize.Level2) +{ + LOG("Test1: not-in-set signal could be caught."); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + if (pid == 0) { // child + int exitCode = 0; + sigset_t sigmask; + sigemptyset(&sigmask); + sigaddset(&sigmask, SIGTRAP); + int rt = sigprocmask(SIG_BLOCK, &sigmask, NULL); + if (rt != 0) { + LOG("sigprocmask fail, rt=%d, errno=%d", rt, errno); + exit(1); + } + signal(SIGINT, SignalHandler); + signal(SIGTRAP, SignalHandler); + + Msleep(80); + if (mReceivedSignal != SIGINT) { + LOG("SignalHandler check fail, expected=SIGINT, actual=%d", mReceivedSignal); + exit(1); + } + exit(0); + } else { // parent + Msleep(30); + kill(pid, SIGINT); + Msleep(100); + AssertProcExitedOK(pid); + } + + LOG("Test2: not-in-set signal could terminate the process."); + pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + if (pid == 0) { // child + int exitCode = 0; + sigset_t sigmask; + sigemptyset(&sigmask); + sigaddset(&sigmask, SIGTRAP); + int rt = sigprocmask(SIG_BLOCK, &sigmask, NULL); + if (rt != 0) { + LOG("sigprocmask fail, rt=%d, errno=%d", rt, errno); + exit(1); + } + Msleep(60); + exit(0); + } else { // parent + Msleep(30); + kill(pid, SIGINT); + Msleep(80); + AssertProcKilled(pid, SIGINT); + } +} + +/** + * @tc.number SUB_KERNEL_IPC_SIGSUSPEND_0100 + * @tc.name sigsuspend basic function test1: the sigsuspend-signal terminates the process + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(IpcSignalTest, testSigsuspendTerminate, TestSize.Level1) +{ + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + if (pid == 0) { // child + signal(SIGTRAP, SignalHandler); + sigset_t set; + sigemptyset(&set); + sigaddset(&set, SIGHUP); + int rt = sigsuspend(&set); + // should not get here: + LOG("sigsuspend rt = %d, errno=%d", rt, errno); + exit(1); + } else { // parent + Msleep(20); + + kill(pid, SIGHUP); // this should blocked by sigsuspend + Msleep(20); + AssertProcAlive(pid); + + kill(pid, SIGTRAP); // this should interupt sigsuspend + Msleep(20); + AssertProcKilled(pid, SIGHUP); + } +} +/** + * @tc.number SUB_KERNEL_IPC_SIGSUSPEND_0200 + * @tc.name sigsuspend basic function test2: the sigsuspend-signal caught, and process continue run + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(IpcSignalTest, testSigsuspendContinue, TestSize.Level2) +{ + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + if (pid == 0) { // child + int exitCode = 0; + signal(SIGTRAP, SignalHandler); + signal(SIGHUP, SignalHandler); + sigset_t set; + sigemptyset(&set); + sigaddset(&set, SIGHUP); + int rt = sigsuspend(&set); + if (rt != -1) { + LOG("sigsuspend should return -1, but rt=%d", rt); + exitCode = 1; + } + if (errno != EINTR) { + LOG("sigsuspend should set errno to 4(EINTR),but get %d", errno); + exitCode = 1; + } + if (mReceivedSignal != SIGHUP) { + LOG("Received signal check fail, expected signal=%d", SIGHUP); + exitCode = 1; + } + exit(exitCode); + } else { // parent + Msleep(20); + + kill(pid, SIGHUP); + Msleep(20); + AssertProcAlive(pid); + + kill(pid, SIGTRAP); + Msleep(20); + AssertProcExitedOK(pid); + } +} + +/** + * @tc.number SUB_KERNEL_IPC_SIGSUSPEND_0300 + * @tc.name sigsuspend test with sigprocmask + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(IpcSignalTest, testSigsuspendAndMask, TestSize.Level1) +{ + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + if (pid == 0) { // child + int exitCode = 0; + sigset_t procMask, suspendMask, pending; + sigemptyset(&suspendMask); + sigemptyset(&procMask); + sigaddset(&suspendMask, SIGQUIT); + sigaddset(&procMask, SIGINT); + + signal(SIGINT, SignalHandler); + signal(SIGQUIT, SignalHandler); + + LOG("Block SIGINT..."); + int rt = sigprocmask(SIG_SETMASK, &procMask, NULL); + if (rt != 0) { + LOG("sigprocmask fail, rt=%d, errno=%d", rt, errno); + exit(1); + } + LOG("Suspend SIGQUIT..."); + rt = sigsuspend(&suspendMask); + if (rt != -1) { + LOG("sigsuspend should return -1, but rt=%d", rt); + exitCode = 1; + } + // signal in procmask should received 1st + // need change to check SIGQUIT only if multi-signal issue fixed + if ((mReceivedSignal != SIGQUIT) && (mReceivedSignal != SIGINT)) { + LOG("Received signal check fail, get %d", mReceivedSignal); + exitCode = 1; + } + + LOG("Check current mask..."); + sigemptyset(&procMask); + sigprocmask(10, NULL, &procMask); + if (!sigismember(&procMask, SIGINT)) { + LOG("SIGINT should in block set!"); + exitCode = 1; + } + if (sigismember(&procMask, SIGQUIT)) { + LOG("SIGQUIT should not in block set!"); + exitCode = 1; + } + exit(exitCode); + } else { // parent + Msleep(20); + kill(pid, SIGQUIT); + Msleep(20); + AssertProcAlive(pid); + + kill(pid, SIGINT); // this should interupt sigsuspend + Msleep(20); + AssertProcExitedOK(pid); + } +} diff --git a/kernel_lite/ipc_posix/src/SignalTest.h b/kernel_lite/ipc_posix/src/SignalTest.h new file mode 100755 index 0000000000000000000000000000000000000000..e058e4b1d86cc21a651cbe658f369eaacc27ffa7 --- /dev/null +++ b/kernel_lite/ipc_posix/src/SignalTest.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2020 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 SIGNAL_TEST +#define SIGNAL_TEST + +#include +#include + +const int MAX_SIGNAL = 30; +enum SignalAction {TERMINATE, COREDUMP, IGNORE, STOP, CONTINUE}; +struct SignalNameAction { + char signame[12]; + SignalAction action; +}; +extern SignalNameAction const ALL_SIGNALS[MAX_SIGNAL + 1]; + +using handler_type = void (*) (int); + +class IpcSignalTest : public::testing::TestWithParam { +public: + void SetUp() + { + mReceivedSignal = 0; + }; + // fail test util-func for sig api + void SignalFailTest(int signum, handler_type h, int expectErrno = EINVAL); + void SigpendingFailTest(sigset_t* pset); + void SigtimedwaitFailTest(const sigset_t *set, siginfo_t* info, + const struct timespec* timeout, int expectErrno = EINVAL); + + // utils for all signal test + void DefaultActionTest(int signum, bool expectStop, bool coredump = false); + void SendAndRecvTest(int signum); + + // general signal handler + static void SignalHandler(int signum); + // special signal handler for function 'abort' + static void SigAbortHandler(int signum); + // special signal handler for function 'sigaction' + static void SigactionHandler(int signum, siginfo_t* si, void* ucontext); + +protected: + static int mReceivedSignal; + static const char* mAbortPipeName; + static siginfo_t mSiginfo; +}; + + +#endif \ No newline at end of file diff --git a/kernel_lite/ipc_posix/src/SignalTestUtils.cpp b/kernel_lite/ipc_posix/src/SignalTestUtils.cpp new file mode 100755 index 0000000000000000000000000000000000000000..b36bc1fa6721c87a96e367c79afe4fd5a34db113 --- /dev/null +++ b/kernel_lite/ipc_posix/src/SignalTestUtils.cpp @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2020 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 "log.h" +#include "utils.h" +#include "SignalTest.h" + +using namespace testing::ext; + +// static membor must init before use. +int IpcSignalTest::mReceivedSignal = 0; +siginfo_t IpcSignalTest::mSiginfo; +const char* IpcSignalTest::mAbortPipeName = "/dev/AbortPipe001"; + +// special signal hander for function 'abort' +void IpcSignalTest::SigAbortHandler(int signum) +{ + LOG("hander: recv a signal: %d", signum); + int fd = open(mAbortPipeName, O_WRONLY); + // use mAbortPipeName as message + int rt = write(fd, mAbortPipeName, strlen(mAbortPipeName)); + LOG("hander: pipe write rt=%d, errno=%d", rt, errno); + close(fd); +} + +// special signal handler for function 'sigaction' +void IpcSignalTest::SigactionHandler(int signum, siginfo_t* si, void* ucontext) +{ + LOG("hander recv a signal: %s(%d)", ALL_SIGNALS[signum].signame, signum); + mReceivedSignal = signum; + // siginfo_t para is not supported yet +} + +// general signal hander +void IpcSignalTest::SignalHandler(int signum) +{ + LOG("hander recv a signal: %s(%d)", ALL_SIGNALS[signum].signame, signum); + mReceivedSignal = signum; +} + +SignalNameAction const ALL_SIGNALS[MAX_SIGNAL + 1] = { + {"NA", TERMINATE}, + {"SIGHUP", TERMINATE}, // 1 + {"SIGINT", TERMINATE}, + {"SIGQUIT", COREDUMP}, + {"SIGILL", COREDUMP}, + {"SIGTRAP", COREDUMP}, + {"SIGABRT", COREDUMP}, // alias: SIGIOT + {"SIGBUS", COREDUMP}, + {"SIGFPE", COREDUMP}, + {"SIGKILL", TERMINATE}, + {"SIGUSR1", TERMINATE}, + {"SIGSEGV", COREDUMP}, + {"SIGUSR2", TERMINATE}, + {"SIGPIPE", TERMINATE}, + {"SIGALRM", TERMINATE}, + {"SIGTERM", TERMINATE}, + {"SIGSTKFLT", TERMINATE}, + {"SIGCHLD", IGNORE}, // alias: SIGCLD + {"SIGCONT", CONTINUE}, + {"SIGSTOP", STOP}, + {"SIGTSTP", STOP}, + {"SIGTTIN", STOP}, + {"SIGTTOU", STOP}, + {"SIGURG", IGNORE}, + {"SIGXCPU", COREDUMP}, + {"SIGXFSZ", COREDUMP}, + {"SIGVTALRM", TERMINATE}, + {"SIGPROF", TERMINATE}, + {"SIGWINCH", IGNORE}, + {"SIGIO", TERMINATE}, // alias: SIGPOLL + {"SIGPWR", TERMINATE} // alias: SIGINFO, 30 +}; + +void IpcSignalTest::DefaultActionTest(int signum, bool expectStop, bool coredump) +{ + int status, rt; + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + if (pid > 0) { // parent + Msleep(20); + kill(pid, signum); + if (!expectStop) { + Msleep(20); + AssertProcAlive(pid); + Msleep(100); + AssertProcExitedOK(pid); + } else { + Msleep(20); + AssertProcKilled(pid, signum); + if (coredump) { + // todo: check codedump, liteos not support yet + } + } + } else { // child + KeepRun(100); + if (expectStop) { + LOG("Child should has been Terminated, but still alive."); + exit(1); + } + exit(0); + } +} + +void IpcSignalTest::SendAndRecvTest(int signum) +{ + pid_t pid1, pid2; + int status, rt; + bool useBrother = GetRandom(100) % 2; // if use brother to send the signal + pid1 = fork(); + ASSERT_TRUE(pid1 >= 0) << "======== Fork1 Error! ========="; + if (pid1 > 0) { // parent + LOGD("in parent..."); + if (useBrother) { + pid2 = fork(); + ASSERT_TRUE(pid2 >= 0) << "======== Fork2 Error! ========="; + if (pid2 == 0) { // child 2 + Msleep(50); + kill(pid1, signum); + exit(0); + } + // parent + Msleep(100); + LOG("check if child2 exited OK"); + AssertProcExitedOK(pid2); + } else { + Msleep(100); + kill(pid1, signum); + } + AssertProcAlive(pid1); + + Msleep(200); // child should exited now + LOG("check if child exited OK"); + AssertProcExitedOK(pid1); + } else { // child 1, the receiver + LOGD("in child, pid=%d", getpid()); + signal(signum, SignalHandler); + Msleep(150); + if (mReceivedSignal != signum) { + LOG("SignalHandler check fail, expected=%d, received=%d", signum, mReceivedSignal); + exit(1); + } + LOGD("child sleeping...."); + Msleep(20); + LOGD("child exit 0...."); + exit(0); + } +} + +void IpcSignalTest::SignalFailTest(int signum, handler_type h, int expectErrno) +{ + errno = 0; + handler_type rt = signal(signum, h); + ASSERT_EQ(rt, SIG_ERR); + ASSERT_EQ(errno, expectErrno); +} +void IpcSignalTest::SigpendingFailTest(sigset_t* pset) +{ + errno = 0; + int rt = sigpending(pset); + ASSERT_EQ(rt, -1); + ASSERT_EQ(errno, EFAULT); +} +void IpcSignalTest::SigtimedwaitFailTest(const sigset_t *set, siginfo_t* info, const timespec* timeout, int expectErrno) +{ + errno = 0; + int rt = sigtimedwait(set, info, timeout); + ASSERT_EQ(rt, -1); + ASSERT_EQ(errno, expectErrno); +} diff --git a/kernel_lite/kernelcmsis_hal/BUILD.gn b/kernel_lite/kernelcmsis_hal/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..7fea3589cf989595bac55ecfd085cdf978faad16 --- /dev/null +++ b/kernel_lite/kernelcmsis_hal/BUILD.gn @@ -0,0 +1,36 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hctest_suite("ActsCMSISTest") { + suite_name = "acts" + sources = [ + "src/cmsis_task_func_test.c", + "src/cmsis_task_pri_func_test.c", + "src/cmsis_timer_func_test.c", + "src/cmsis_event_func_test.c", + "src/cmsis_mutex_func_test.c", + "src/cmsis_msg_func_test.c", + "src/cmsis_sem_func_test.c", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "//third_party/unity/src", + "src", + "//kernel/liteos_m/components/cmsis", + "//kernel/liteos_m/components/cmsis/2.0", + ] + cflags = [ "-Wno-error" ] +} \ No newline at end of file diff --git a/kernel_lite/kernelcmsis_hal/Test.tmpl b/kernel_lite/kernelcmsis_hal/Test.tmpl new file mode 100755 index 0000000000000000000000000000000000000000..be8407e1286041a5af2bdc75a15633337376eb9d --- /dev/null +++ b/kernel_lite/kernelcmsis_hal/Test.tmpl @@ -0,0 +1,19 @@ +{ + "description": "Config for $module test cases", + "environment": [ + { + "type": "device", + "label": "wifiiot" + } + ], + "kits": [ + { + "type": "DeployKit", + "timeout": "20000", + "burn_file": "$subsystem/$module.bin" + } + ], + "driver": { + "type": "CTestLite" + } +} \ No newline at end of file diff --git a/kernel_lite/kernelcmsis_hal/src/cmsis_event_func_test.c b/kernel_lite/kernelcmsis_hal/src/cmsis_event_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..bd9fe44fbaa6f4d02649f5b28ff4fd8155171555 --- /dev/null +++ b/kernel_lite/kernelcmsis_hal/src/cmsis_event_func_test.c @@ -0,0 +1,398 @@ +/** + * Copyright (c) 2020 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 "hos_types.h" +#include +#include "hctest.h" +#include "los_config.h" +#include "cmsis_os2.h" +#include "kernel_test.h" + +osEventFlagsId_t g_eventId; +UINT16 g_cmsisTestEventCount; +#define EVENT_MASK_HEX_1 0x01 +#define EVENT_MASK_HEX_2 0x02 +#define EVENT_MASK_HEX_4 0x04 +#define EVENT_MASK_HEX_10 0x10 +#define EVENT_MASK_HEX_11 0x11 +#define TIMEOUT_NUM_3 3 +#define TIMEOUT_NUM_10 10 +#define INVALID_FLAG_OPTION 0x00000004U + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is utils + * @param : module name is utilsFile + * @param : test suit name is CmsisEventFuncTestSuite + */ +LITE_TEST_SUIT(Cmsis, Cmsisevent, CmsisEventFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL CmsisEventFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL CmsisEventFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +static void CmsisEventFlagsWaitFunc001(void const *argument) +{ + (void)argument; + UINT32 uwRet; + g_cmsisTestEventCount++; + uwRet = osEventFlagsWait(g_eventId, EVENT_MASK_HEX_11, (osFlagsWaitAll | osFlagsNoClear), osWaitForever); + TEST_ASSERT_EQUAL_INT(EVENT_MASK_HEX_11, uwRet); + g_cmsisTestEventCount++; + osThreadExit(); +} + +static void CmsisEventFlagsSetFunc002(void const *argument) +{ + (void)argument; + UINT32 uwRet; + g_cmsisTestEventCount++; + uwRet = osEventFlagsWait(g_eventId, EVENT_MASK_HEX_11, (osFlagsWaitAll | osFlagsNoClear), TIMEOUT_NUM_3); + TEST_ASSERT_EQUAL_INT(osErrorTimeout, uwRet); + g_cmsisTestEventCount++; + + uwRet = osEventFlagsWait(g_eventId, EVENT_MASK_HEX_4, (osFlagsWaitAll | osFlagsNoClear), osWaitForever); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_4, uwRet); + g_cmsisTestEventCount++; + osThreadExit(); +} + +static void CmsisEventFlagsClearFunc001(void const *argument) +{ + (void)argument; + UINT32 uwRet; + g_cmsisTestEventCount++; + uwRet = osEventFlagsWait(g_eventId, EVENT_MASK_HEX_1, osFlagsWaitAll, osWaitForever); + TEST_ASSERT_EQUAL_INT(EVENT_MASK_HEX_1, uwRet); + g_cmsisTestEventCount++; + osThreadExit(); +} + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_100 + * @tc.name : event operation for creat + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsNew001, LEVEL1) +{ + g_eventId = osEventFlagsNew(NULL); + TEST_ASSERT_NOT_NULL(g_eventId); + (void)osEventFlagsDelete(g_eventId); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_100 + * @tc.name : event operation for delete + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsDelete001, LEVEL1) +{ + UINT32 uwRet; + g_eventId = osEventFlagsNew(NULL); + TEST_ASSERT_NOT_NULL(g_eventId); + + uwRet = osEventFlagsDelete(g_eventId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_100 + * @tc.name : event delete operation with EventFlagsId = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsDelete002, LEVEL1) +{ + UINT32 uwRet; + + uwRet = osEventFlagsDelete(NULL); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_100 + * @tc.name : event operation for flags set + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsSet001, LEVEL1) +{ + UINT32 uwRet; + g_eventId = osEventFlagsNew(NULL); + uwRet = osEventFlagsSet(g_eventId, EVENT_MASK_HEX_10); + TEST_ASSERT_EQUAL_INT(EVENT_MASK_HEX_10, uwRet); + uwRet = osEventFlagsDelete(g_eventId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_100 + * @tc.name : event operation for flags set + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsSet002, LEVEL1) +{ + UINT32 uwRet; + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + + g_cmsisTestEventCount = 0; + g_eventId = osEventFlagsNew(NULL); + TEST_ASSERT_NOT_NULL(g_eventId); + id = osThreadNew((osThreadFunc_t)CmsisEventFlagsSetFunc002, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestEventCount); + g_cmsisTestEventCount++; + uwRet=osEventFlagsSet(g_eventId, EVENT_MASK_HEX_2); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_3, g_cmsisTestEventCount); + + g_cmsisTestEventCount++; + uwRet=osEventFlagsSet(g_eventId, EVENT_MASK_HEX_11); + osDelay(DELAY_TICKS_5); + + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_4, g_cmsisTestEventCount); + uwRet=osEventFlagsSet(g_eventId, EVENT_MASK_HEX_4); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_5, g_cmsisTestEventCount); + uwRet = osEventFlagsDelete(g_eventId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_100 + * @tc.name : event flags set operation with EventFlagsId = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsSet003, LEVEL1) +{ + UINT32 uwRet; + uwRet = osEventFlagsSet(NULL, EVENT_MASK_HEX_10); + TEST_ASSERT_EQUAL_INT(osFlagsErrorParameter, uwRet); + +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_100 + * @tc.name : event operation for wait + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsWait001, LEVEL1) +{ + UINT32 uwRet; + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + + g_cmsisTestEventCount = 0; + g_eventId = osEventFlagsNew(NULL); + TEST_ASSERT_NOT_NULL(g_eventId); + id = osThreadNew((osThreadFunc_t)CmsisEventFlagsWaitFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + + uwRet = osEventFlagsSet(g_eventId, EVENT_MASK_HEX_10); + TEST_ASSERT_EQUAL_INT(EVENT_MASK_HEX_10, uwRet); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestEventCount); + + uwRet = osEventFlagsSet(g_eventId, EVENT_MASK_HEX_1); + TEST_ASSERT_EQUAL_INT(EVENT_MASK_HEX_11, uwRet); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestEventCount); + + uwRet = osEventFlagsDelete(g_eventId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_100 + * @tc.name : event operation for invalid option + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsWait002, LEVEL1) +{ + UINT32 uwRet; + g_eventId = osEventFlagsNew(NULL); + TEST_ASSERT_NOT_NULL(g_eventId); + + uwRet = osEventFlagsWait(g_eventId, EVENT_MASK_HEX_11, INVALID_FLAG_OPTION, osWaitForever); + TEST_ASSERT_EQUAL_INT(osFlagsErrorParameter, uwRet); + + uwRet = osEventFlagsDelete(g_eventId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_100 + * @tc.name : event wait operation with EventFlagsId = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsWait003, LEVEL1) +{ + UINT32 uwRet; + uwRet = osEventFlagsWait(NULL, EVENT_MASK_HEX_11, (osFlagsWaitAll | osFlagsNoClear), osWaitForever); + TEST_ASSERT_EQUAL_INT(osFlagsErrorParameter, uwRet); + +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_100 + * @tc.name : event operation for flags get + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsGet001, LEVEL1) +{ + UINT32 uwRet; + g_eventId = osEventFlagsNew(NULL); + uwRet = osEventFlagsSet(g_eventId, EVENT_MASK_HEX_10); + TEST_ASSERT_EQUAL_INT(EVENT_MASK_HEX_10, uwRet); + uwRet = 0; + uwRet = osEventFlagsGet(g_eventId); + TEST_ASSERT_EQUAL_INT(EVENT_MASK_HEX_10, uwRet); + + uwRet = osEventFlagsDelete(g_eventId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_100 + * @tc.name : event flags get operation with EventFlagsId = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsGet002, LEVEL1) +{ + UINT32 uwRet; + uwRet = osEventFlagsGet(NULL); + TEST_ASSERT_EQUAL_INT(osFlagsErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_100 + * @tc.name : event operation for flags clear + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsClear001, LEVEL1) +{ + UINT32 uwRet; + osThreadId_t id; + + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + + g_cmsisTestEventCount = 0; + g_eventId = osEventFlagsNew(NULL); + id = osThreadNew((osThreadFunc_t)CmsisEventFlagsClearFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + uwRet = osEventFlagsSet(g_eventId, EVENT_MASK_HEX_10); + TEST_ASSERT_EQUAL_INT(EVENT_MASK_HEX_10, uwRet); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestEventCount); + + uwRet = osEventFlagsClear(g_eventId, 0xffff); + TEST_ASSERT_EQUAL_INT(EVENT_MASK_HEX_10, uwRet); + uwRet = osEventFlagsGet(g_eventId); + TEST_ASSERT_EQUAL_INT(0, uwRet); + uwRet = osEventFlagsSet(g_eventId, EVENT_MASK_HEX_1); + // after the event is triggered, the flag is reset to be zero + TEST_ASSERT_EQUAL_INT(0, uwRet); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestEventCount); + uwRet = osEventFlagsDelete(g_eventId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_100 + * @tc.name : event flags clear operation with EventFlagsId = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsClear002, LEVEL1) +{ + UINT32 uwRet; + uwRet = osEventFlagsClear(NULL, 0xffff); + TEST_ASSERT_EQUAL_INT(osFlagsErrorParameter, uwRet); +}; + +RUN_TEST_SUITE(CmsisEventFuncTestSuite); diff --git a/kernel_lite/kernelcmsis_hal/src/cmsis_msg_func_test.c b/kernel_lite/kernelcmsis_hal/src/cmsis_msg_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..84bf83bc9abeb846cacb64e5e4f819d9a68356f7 --- /dev/null +++ b/kernel_lite/kernelcmsis_hal/src/cmsis_msg_func_test.c @@ -0,0 +1,446 @@ +/** + * Copyright (c) 2020 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 "hos_types.h" +#include +#include "hctest.h" +#include "los_config.h" +#include "cmsis_os2.h" +#include "kernel_test.h" + +osMessageQueueId_t g_cmsisMessageQId; +#define MSGQUEUE_COUNT 16 +#define MSGQUEUE_SPACE_COUNT 13 +#define MSGQUEUE_PUT_COUNT 3 +#define MSG_SIZE 4 +#define MSGINFO_LEN 4 +#define TIMEOUT_COUNT 1000 +#define BUF_LEN 32 +#define MSGQUEUE_COUNT_INDEX_0 0 +#define MSGQUEUE_COUNT_INDEX_1 1 +#define MSGQUEUE_COUNT_INDEX_2 2 +static char *g_cmsisMessageInfo[] = {"msg1", "msg2", "msg3", "msg4", "msg5", "msg6", "msg7", "msg8"}; + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is utils + * @param : module name is utilsFile + * @param : test suit name is CmsisMsgFuncTestSuite + */ +LITE_TEST_SUIT(Cmsis, Cmsismsg, CmsisMsgFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL CmsisMsgFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL CmsisMsgFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +static void CmsisMessageQueueGetFunc001(void const *argument) +{ + (void)argument; + osStatus_t uwRet; + UINT8 msg_prio = 0; + CHAR uctemp[MSGINFO_LEN] = ""; + UINT32 uwCmp; + uwRet = osMessageQueueGet(g_cmsisMessageQId, uctemp, &msg_prio, TIMEOUT_COUNT); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + uwCmp = memcmp(uctemp, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0], MSGINFO_LEN); + TEST_ASSERT_EQUAL_INT(0, uwCmp); + + uwRet = osMessageQueueDelete(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + osThreadExit(); +} + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_100 + * @tc.name : message queue operation for creat + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueNew001, LEVEL1) +{ + g_cmsisMessageQId = osMessageQueueNew(MSGQUEUE_COUNT, MSG_SIZE, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMessageQId); + (void)osMessageQueueDelete(g_cmsisMessageQId); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_100 + * @tc.name : message queue operation for creat when msg_count = 0 + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueNew002, LEVEL1) +{ + g_cmsisMessageQId = osMessageQueueNew(0, MSG_SIZE, NULL); + TEST_ASSERT_NULL(g_cmsisMessageQId); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_100 + * @tc.name : message queue operation for creat when msg_size = 0 + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueNew003, LEVEL1) +{ + g_cmsisMessageQId = osMessageQueueNew(MSGQUEUE_COUNT, 0, NULL); + TEST_ASSERT_NULL(g_cmsisMessageQId); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_100 + * @tc.name : message queue operation for delete + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueDelete001, LEVEL1) +{ + osStatus_t uwRet; + g_cmsisMessageQId = osMessageQueueNew(MSGQUEUE_COUNT, MSG_SIZE, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMessageQId); + uwRet = osMessageQueueDelete(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_100 + * @tc.name : message queue delete operation with mq_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueDelete002, LEVEL1) +{ + osStatus_t uwRet; + uwRet = osMessageQueueDelete(NULL); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_100 + * @tc.name : message queue operation for put + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueuePut001, LEVEL1) +{ + osStatus_t uwRet; + g_cmsisMessageQId = osMessageQueueNew(MSGQUEUE_COUNT, MSG_SIZE, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMessageQId); + + uwRet = osMessageQueuePut(g_cmsisMessageQId, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0], 0, 0); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMessageQueueDelete(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_100 + * @tc.name : message queue put operation with mq_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueuePut002, LEVEL1) +{ + osStatus_t uwRet; + uwRet = osMessageQueuePut(NULL, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0], 0, 0); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_100 + * @tc.name : message queue operation for put when msg_ptr = 0 + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueuePut003, LEVEL1) +{ + osStatus_t uwRet; + g_cmsisMessageQId = osMessageQueueNew(MSGQUEUE_COUNT, MSG_SIZE, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMessageQId); + + uwRet = osMessageQueuePut(g_cmsisMessageQId, NULL, 0, 0); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); + + uwRet = osMessageQueueDelete(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_100 + * @tc.name : message queue operation for get + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueGet001, LEVEL1) +{ + osStatus_t uwRet; + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + osKernelLock(); + g_cmsisMessageQId = osMessageQueueNew(MSGQUEUE_COUNT, MSG_SIZE, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMessageQId); + + id = osThreadNew((osThreadFunc_t)CmsisMessageQueueGetFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + uwRet = osMessageQueuePut(g_cmsisMessageQId, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0], 0, 0); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + osKernelUnlock(); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_100 + * @tc.name : message queue get operation with mq_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueGet002, LEVEL1) +{ + osStatus_t uwRet; + UINT8 msg_prio = 0; + CHAR uctemp[MSGINFO_LEN] = ""; + uwRet = osMessageQueueGet(NULL, uctemp, &msg_prio, TIMEOUT_COUNT); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_100 + * @tc.name : message queue operation for get when msg_ptr = 0 + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueGet003, LEVEL1) +{ + osStatus_t uwRet; + UINT8 msg_prio = 0; + g_cmsisMessageQId = osMessageQueueNew(MSGQUEUE_COUNT, MSG_SIZE, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMessageQId); + + uwRet = osMessageQueueGet(g_cmsisMessageQId, NULL, &msg_prio, TIMEOUT_COUNT); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); + + uwRet = osMessageQueueDelete(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_100 + * @tc.name : message queue operation for get msg size + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueGetMsgSize001, LEVEL1) +{ + UINT32 uwRet; + g_cmsisMessageQId = osMessageQueueNew(MSGQUEUE_COUNT, MSG_SIZE, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMessageQId); + + uwRet = osMessageQueueGetMsgSize(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(MSG_SIZE, uwRet); + + uwRet = osMessageQueueDelete(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_100 + * @tc.name : message queue get msg size with mq_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueGetMsgSize002, LEVEL1) +{ + UINT32 uwRet; + uwRet = osMessageQueueGetMsgSize(NULL); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_100 + * @tc.name : message queue operation for get capacity + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueGetCapacity001, LEVEL1) +{ + UINT32 uwRet; + g_cmsisMessageQId = osMessageQueueNew(MSGQUEUE_COUNT, MSG_SIZE, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMessageQId); + uwRet = osMessageQueueGetCapacity(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(MSGQUEUE_COUNT, uwRet); + + uwRet = osMessageQueueDelete(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_100 + * @tc.name : message queue get capacity with mq_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueGetCapacity002, LEVEL1) +{ + UINT32 uwRet; + uwRet = osMessageQueueGetCapacity(NULL); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_100 + * @tc.name : message queue operation for get count + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueGetCount001, LEVEL1) +{ + UINT32 uwRet; + g_cmsisMessageQId = osMessageQueueNew(MSGQUEUE_COUNT, MSG_SIZE, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMessageQId); + + uwRet = osMessageQueuePut(g_cmsisMessageQId, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0], 0, 0); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMessageQueuePut(g_cmsisMessageQId, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_1], 0, 0); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMessageQueuePut(g_cmsisMessageQId, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_2], 0, 0); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMessageQueueGetCount(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(MSGQUEUE_PUT_COUNT, uwRet); + + uwRet = osMessageQueueDelete(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_100 + * @tc.name : message queue get count with mq_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueGetCount002, LEVEL1) +{ + UINT32 uwRet; + uwRet = osMessageQueueGetCount(NULL); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_100 + * @tc.name : message queue operation for get space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueGetSpace001, LEVEL1) +{ + UINT32 uwRet; + g_cmsisMessageQId = osMessageQueueNew(MSGQUEUE_COUNT, MSG_SIZE, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMessageQId); + + uwRet = osMessageQueuePut(g_cmsisMessageQId, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0], 0, 0); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMessageQueuePut(g_cmsisMessageQId, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_1], 0, 0); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMessageQueuePut(g_cmsisMessageQId, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_2], 0, 0); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMessageQueueGetSpace(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(MSGQUEUE_SPACE_COUNT, uwRet); + + uwRet = osMessageQueueDelete(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_100 + * @tc.name : message queue get space with mq_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueGetSpace002, LEVEL1) +{ + UINT32 uwRet; + uwRet = osMessageQueueGetSpace(NULL); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +RUN_TEST_SUITE(CmsisMsgFuncTestSuite); diff --git a/kernel_lite/kernelcmsis_hal/src/cmsis_mutex_func_test.c b/kernel_lite/kernelcmsis_hal/src/cmsis_mutex_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..35ec7de045610b698c2602ae328f28eb0566926a --- /dev/null +++ b/kernel_lite/kernelcmsis_hal/src/cmsis_mutex_func_test.c @@ -0,0 +1,311 @@ +/** + * Copyright (c) 2020 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 "hos_types.h" +#include +#include "hctest.h" +#include "los_config.h" +#include "cmsis_os2.h" +#include "kernel_test.h" + +#define LOS_WAIT_FOREVER 0xFFFFFFFF + +UINT16 g_cmsisTestMutexCount; +osMutexId_t g_cmsisMutexId; +osMutexAttr_t g_cmsisMutexAttr; + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is utils + * @param : module name is utilsFile + * @param : test suit name is CmsisMutexFuncTestSuite + */ +LITE_TEST_SUIT(Cmsis, Cmsismutex, CmsisMutexFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL CmsisMutexFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL CmsisMutexFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +static void CmsisMutexGetOwnerFunc001(void const *argument) +{ + (void)argument; + osStatus_t uwRet; + osThreadId_t id1; + osThreadId_t id2; + osThreadAttr_t attr; + g_cmsisMutexId = osMutexNew(&g_cmsisMutexAttr); + TEST_ASSERT_NOT_NULL(g_cmsisMutexId); + + uwRet = osMutexAcquire(g_cmsisMutexId, LOS_WAIT_FOREVER); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + id1 = osMutexGetOwner(g_cmsisMutexId); + id2 = osThreadGetId(); + TEST_ASSERT_EQUAL_STRING(id1, id2); + + attr.name = osThreadGetName(id1); + TEST_ASSERT_EQUAL_STRING("testMutexGetOwner001", attr.name); + + uwRet = osMutexRelease(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMutexDelete(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + osThreadExit(); +} + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100 + * @tc.name : mutex operation for creat + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexNew001, LEVEL1) +{ + g_cmsisMutexId = osMutexNew(NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMutexId); + (void)osMutexDelete(g_cmsisMutexId); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100 + * @tc.name : mutex operation for creat + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexNew002, LEVEL1) +{ + g_cmsisMutexId = osMutexNew(&g_cmsisMutexAttr); + TEST_ASSERT_NOT_NULL(g_cmsisMutexId); + (void)osMutexDelete(g_cmsisMutexId); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100 + * @tc.name : mutex operation for delete + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexDelete001, LEVEL1) +{ + osStatus_t uwRet; + g_cmsisMutexId = osMutexNew(NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMutexId); + uwRet = osMutexDelete(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMutexDelete(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100 + * @tc.name : mutex operation for delete + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexDelete002, LEVEL1) +{ + osStatus_t uwRet; + g_cmsisMutexId = osMutexNew(&g_cmsisMutexAttr); + TEST_ASSERT_NOT_NULL(g_cmsisMutexId); + uwRet = osMutexDelete(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMutexDelete(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100 + * @tc.name : mutex operation for acquire + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexDelete003, LEVEL1) +{ + osStatus_t uwRet; + g_cmsisMutexId = osMutexNew(NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMutexId); + + osMutexAcquire(g_cmsisMutexId, LOS_WAIT_FOREVER); + uwRet = osMutexDelete(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet); + + osMutexRelease(g_cmsisMutexId); + uwRet = osMutexDelete(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100 + * @tc.name : mutex delete operation with mutex_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexDelete004, LEVEL1) +{ + osStatus_t uwRet; + uwRet = osMutexDelete(NULL); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100 + * @tc.name : mutex acquire operation with mutex_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexAcquire001, LEVEL1) +{ + osStatus_t uwRet; + uwRet = osMutexAcquire(NULL, LOS_WAIT_FOREVER); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100 + * @tc.name : mutex operation for acquire + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexAcquire002, LEVEL1) +{ + osStatus_t uwRet; + g_cmsisMutexId = osMutexNew(&g_cmsisMutexAttr); + TEST_ASSERT_NOT_NULL(g_cmsisMutexId); + + uwRet = osMutexAcquire(g_cmsisMutexId, LOS_WAIT_FOREVER); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + (void)osMutexRelease(g_cmsisMutexId); + uwRet = osMutexDelete(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100 + * @tc.name : mutex operation for release + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexRelease001, LEVEL1) +{ + osStatus_t uwRet; + g_cmsisMutexId = osMutexNew(&g_cmsisMutexAttr); + TEST_ASSERT_NOT_NULL(g_cmsisMutexId); + + uwRet = osMutexAcquire(g_cmsisMutexId, LOS_WAIT_FOREVER); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMutexDelete(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet); + + uwRet = osMutexRelease(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMutexDelete(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100 + * @tc.name : mutex release operation with mutex_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexRelease002, LEVEL1) +{ + osStatus_t uwRet; + uwRet = osMutexRelease(NULL); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100 + * @tc.name : mutex operation for get owner + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexGetOwner001, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "testMutexGetOwner001"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + id = osThreadNew((osThreadFunc_t)CmsisMutexGetOwnerFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100 + * @tc.name : mutex get owner operation with mutex_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexGetOwner002, LEVEL1) +{ + osThreadId_t id; + id = osMutexGetOwner(NULL); + TEST_ASSERT_NULL(id); +}; + +RUN_TEST_SUITE(CmsisMutexFuncTestSuite); diff --git a/kernel_lite/kernelcmsis_hal/src/cmsis_sem_func_test.c b/kernel_lite/kernelcmsis_hal/src/cmsis_sem_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..a026a3268a11fec95c3589f91d2060957dbff061 --- /dev/null +++ b/kernel_lite/kernelcmsis_hal/src/cmsis_sem_func_test.c @@ -0,0 +1,498 @@ +/** + * Copyright (c) 2020 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 "hos_types.h" +#include +#include "hctest.h" +#include "los_config.h" +#include "cmsis_os2.h" +#include "kernel_test.h" + +osSemaphoreId_t g_cmsisSemSema; +#define SEMAPHHORE_COUNT_HEX_MAX 0xFE +#define SEMAPHHORE_COUNT_INT0 0 +#define SEMAPHHORE_COUNT_INT1 1 +#define SEMAPHHORE_COUNT_INT10 10 + + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is utils + * @param : module name is utilsFile + * @param : test suit name is CmsisTaskFuncTestSuite + */ +LITE_TEST_SUIT(Cmsis, CmsisSem, CmsisSemFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL CmsisSemFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL CmsisSemFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore operation for creat + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew001, LEVEL1) +{ + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT0, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + (void)osSemaphoreDelete(g_cmsisSemSema); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore operation for creat + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew002, LEVEL1) +{ + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT10, SEMAPHHORE_COUNT_INT1, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + (void)osSemaphoreDelete(g_cmsisSemSema); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore operation for creat + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew003, LEVEL1) +{ + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT0, SEMAPHHORE_COUNT_INT10, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + (void)osSemaphoreDelete(g_cmsisSemSema); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore operation for creat + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew004, LEVEL1) +{ + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT0, SEMAPHHORE_COUNT_INT0, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + osSemaphoreDelete(g_cmsisSemSema); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore operation for creat + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew005, LEVEL1) +{ + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT1, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + osSemaphoreDelete(g_cmsisSemSema); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore operation for creat + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew006, LEVEL1) +{ + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT10, SEMAPHHORE_COUNT_INT10, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + osSemaphoreDelete(g_cmsisSemSema); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore operation for creat + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew007, LEVEL1) +{ + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_HEX_MAX, SEMAPHHORE_COUNT_INT0, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + osSemaphoreDelete(g_cmsisSemSema); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore operation for creat + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew008, LEVEL1) +{ + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT0, SEMAPHHORE_COUNT_HEX_MAX, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + osSemaphoreDelete(g_cmsisSemSema); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore operation for delete + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreDelete001, LEVEL1) +{ + osStatus_t uwRet; + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT10, SEMAPHHORE_COUNT_INT0, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore operation for delete + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreDelete002, LEVEL1) +{ + osStatus_t uwRet; + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT10, SEMAPHHORE_COUNT_INT0, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore delete operation with semaphore_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreDelete003, LEVEL1) +{ + osStatus_t uwRet; + uwRet = osSemaphoreDelete(NULL); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); + +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore operation for acquire + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreAcquire001, LEVEL1) +{ + osStatus_t uwRet; + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT1, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + uwRet = osSemaphoreAcquire(g_cmsisSemSema, 0); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore operation for acquire + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreAcquire002, LEVEL1) +{ + osStatus_t uwRet; + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT0, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + uwRet = osSemaphoreAcquire(g_cmsisSemSema, 0); + TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet); + + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore operation for acquire + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreAcquire003, LEVEL1) +{ + osStatus_t uwRet; + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT0, SEMAPHHORE_COUNT_INT1, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + uwRet = osSemaphoreAcquire(g_cmsisSemSema, 0); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore acquire operation with semaphore_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreAcquire004, LEVEL1) +{ + osStatus_t uwRet; + uwRet = osSemaphoreAcquire(NULL, 0); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); + +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore operation for release + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreRelease001, LEVEL1) +{ + osStatus_t uwRet; + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT0, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + + uwRet = osSemaphoreAcquire(g_cmsisSemSema, 0); + TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet); + + uwRet = osSemaphoreRelease(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore operation for release + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreRelease002, LEVEL1) +{ + osStatus_t uwRet; + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT0, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + + uwRet = osSemaphoreRelease(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + uwRet = osSemaphoreRelease(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet); + + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore operation for release + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreRelease003, LEVEL1) +{ + osStatus_t uwRet; + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT1, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + + uwRet = osSemaphoreRelease(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet); + + uwRet = osSemaphoreAcquire(g_cmsisSemSema, 0); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osSemaphoreRelease(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + uwRet = osSemaphoreRelease(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet); + + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore release operation with semaphore_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreRelease004, LEVEL1) +{ + osStatus_t uwRet; + uwRet = osSemaphoreRelease(NULL); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); + +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore operation for get count + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreGetCount001, LEVEL1) +{ + osStatus_t uwRet; + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT1, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + uwRet = osSemaphoreGetCount(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(1, uwRet); + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_HEX_MAX, SEMAPHHORE_COUNT_HEX_MAX, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + uwRet = osSemaphoreGetCount(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(SEMAPHHORE_COUNT_HEX_MAX, uwRet); + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore operation for get count + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreGetCount002, LEVEL1) +{ + osStatus_t uwRet; + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT0, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + uwRet = osSemaphoreGetCount(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(0, uwRet); + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT0, SEMAPHHORE_COUNT_INT1, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + uwRet = osSemaphoreGetCount(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(1, uwRet); + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore operation for get count + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreGetCount003, LEVEL1) +{ + osStatus_t uwRet; + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_HEX_MAX, SEMAPHHORE_COUNT_HEX_MAX, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + uwRet = osSemaphoreAcquire(g_cmsisSemSema, osWaitForever); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osSemaphoreGetCount(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(SEMAPHHORE_COUNT_HEX_MAX - 1, uwRet); + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_100 + * @tc.name : semaphore get count operation with semaphore_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreGetCount004, LEVEL1) +{ + osStatus_t uwRet; + uwRet = osSemaphoreGetCount(NULL); + TEST_ASSERT_EQUAL_INT(0, uwRet); + +}; + +RUN_TEST_SUITE(CmsisSemFuncTestSuite); diff --git a/kernel_lite/kernelcmsis_hal/src/cmsis_task_func_test.c b/kernel_lite/kernelcmsis_hal/src/cmsis_task_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..26b9bc6e015dc481a26125f6f3c6f705cd65a3ed --- /dev/null +++ b/kernel_lite/kernelcmsis_hal/src/cmsis_task_func_test.c @@ -0,0 +1,3481 @@ +/** + * Copyright (c) 2020 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 "hos_types.h" +#include +#include "hctest.h" +#include "los_config.h" +#include "cmsis_os2.h" +#include "kernel_test.h" + +UINT32 g_threadCount; +UINT16 g_cmsisTestTaskCount; +osThreadId_t g_puwTaskID01; +osThreadId_t g_puwTaskID02; +osPriority_t g_threadPriority; + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is utils + * @param : module name is utilsFile + * @param : test suit name is CmsisTaskFuncTestSuite + */ +LITE_TEST_SUIT(Cmsis, Cmsistask, CmsisTaskFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL CmsisTaskFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL CmsisTaskFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +static void CmsisThreadCreatFunc(void const *argument) +{ + (void)argument; + osThreadExit(); +} + +static void CmsisThreadCreat002Func001(void const *argument) +{ + (void)argument; + g_cmsisTestTaskCount++; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_3, g_cmsisTestTaskCount); + osThreadExit(); +} + +static void CmsisThreadCreat002Func002(void const *argument) +{ + (void)argument; + g_cmsisTestTaskCount++; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + osThreadExit(); +} + +static void CmsisThreadCreat003Func001(void const *argument) +{ + (void)argument; + TEST_ASSERT_EQUAL_INT(0, g_cmsisTestTaskCount); + g_cmsisTestTaskCount++; + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_3, g_cmsisTestTaskCount); + g_cmsisTestTaskCount++; + osThreadExit(); +} + +static void CmsisThreadCreat003Func002(void const *argument) +{ + (void)argument; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + g_cmsisTestTaskCount++; + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_4, g_cmsisTestTaskCount); + g_cmsisTestTaskCount++; + osThreadExit(); +} + +static void CmsisThreadCreat004Func002(void const *argument) +{ + (void)argument; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); + g_cmsisTestTaskCount++; + osThreadExit(); +} + +static void CmsisThreadCreat004Func001(void const *argument) +{ + (void)argument; + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + TEST_ASSERT_EQUAL_INT(0, g_cmsisTestTaskCount); + g_cmsisTestTaskCount++; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreat004Func002, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + g_cmsisTestTaskCount++; + osThreadExit(); +} + +static void CmsisThreadCreat005Func001(void const *argument) +{ + (void)argument; + UINT32 uwIndex; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); + for (uwIndex = 0; uwIndex < TEST_TIME; uwIndex++) { + printf("test the thread running delay:%d \t\n", uwIndex); + } + g_cmsisTestTaskCount++; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_3, g_cmsisTestTaskCount); + osThreadExit(); +} + +static void CmsisThreadGetIDFunc001(void const *argument) +{ + (void)argument; + g_puwTaskID01 = osThreadGetId(); + TEST_ASSERT_NOT_NULL(g_puwTaskID01); + osThreadExit(); +} + +static void CmsisThreadGetNameFunc001(void const *argument) +{ + (void)argument; + osThreadAttr_t attr; + g_puwTaskID01 = osThreadGetId(); + attr.name = osThreadGetName(g_puwTaskID01); + TEST_ASSERT_EQUAL_STRING("testThreadGetName", attr.name); + osThreadExit(); +} + +static void CmsisThreadGetStateFunc001(void const *argument) +{ + (void)argument; + osThreadState_t state; + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadBlocked, state); + + g_puwTaskID02 = osThreadGetId(); + state = osThreadGetState(g_puwTaskID02); + TEST_ASSERT_EQUAL_INT(osThreadRunning, state); + osThreadExit(); +} + +static void CmsisThreadGetStateFunc002(void const *argument) +{ + (void)argument; + osThreadState_t state; + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadReady, state); + + g_puwTaskID02 = osThreadGetId(); + state = osThreadGetState(g_puwTaskID02); + TEST_ASSERT_EQUAL_INT(osThreadRunning, state); + osThreadExit(); +} + +static void CmsisThreadSuspendFunc001(void const *argument) +{ + (void)argument; + osStatus_t uwRet; + g_puwTaskID01 = osThreadGetId(); + uwRet = osThreadSuspend(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + osThreadExit(); +} + +static void CmsisThreadGetStackSizeFunc001(void const *argument) +{ + (void)argument; + osThreadAttr_t attr; + g_puwTaskID01 = osThreadGetId(); + attr.stack_size = osThreadGetStackSize(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(TEST_TASK_STACK_SIZE, attr.stack_size); + osThreadExit(); +} + +static void CmsisThreadGetStackSpaceFunc001(void const *argument) +{ + (void)argument; + UINT32 uwCount; + g_puwTaskID01 = osThreadGetId(); + uwCount = osThreadGetStackSpace(g_puwTaskID01); + TEST_ASSERT_GREATER_THAN_INT32(0, uwCount); + osThreadExit(); +} + +static void CmsisThreadYieldFunc002(void const *argument) +{ + (void)argument; + osThreadState_t state; + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadReady, state); + g_cmsisTestTaskCount++; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + osThreadExit(); +} + +static void CmsisThreadYieldFunc001(void const *argument) +{ + (void)argument; + osStatus_t uwRet; + osThreadId_t id; + osThreadState_t state; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_threadPriority; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); + g_puwTaskID01 = osThreadGetId(); + id = osThreadNew((osThreadFunc_t)CmsisThreadYieldFunc002, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadRunning, state); + uwRet = osThreadYield(); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + osThreadExit(); +} + +static void CmsisThreadYieldFunc003(void const *argument) +{ + (void)argument; + osStatus_t uwRet; + osThreadId_t id; + osThreadState_t state; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal7; + g_puwTaskID01 = osThreadGetId(); + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadRunning, state); + uwRet = osThreadYield(); + TEST_ASSERT_EQUAL_INT(osError, uwRet); + osThreadExit(); +} + +static void CmsisThreadResumeFunc002(void const *argument) +{ + (void)argument; + osStatus_t uwRet; + g_cmsisTestTaskCount++; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + uwRet = osThreadResume(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + osDelay(DELAY_TICKS_5); + osThreadExit(); +} + +static void CmsisThreadResumeFunc001(void const *argument) +{ + (void)argument; + osStatus_t uwRet; + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + g_puwTaskID01 = osThreadGetId(); + id = osThreadNew((osThreadFunc_t)CmsisThreadResumeFunc002, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + uwRet = osThreadSuspend(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + g_cmsisTestTaskCount++; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_3, g_cmsisTestTaskCount); + osThreadExit(); +} + +static void CmsisThreadTerminateFunc001(void const *argument) +{ + (void)argument; + osStatus_t uwRet; + g_puwTaskID01 = osThreadGetId(); + uwRet = osThreadTerminate(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + g_cmsisTestTaskCount++; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); + osThreadExit(); +} + +static void CmsisThreadGetCountFunc002(void const *argument) +{ + (void)argument; + UINT32 uwRet; + uwRet = osThreadGetCount(); + TEST_ASSERT_GREATER_THAN_INT32(1, uwRet); + osThreadExit(); +} + +static void CmsisThreadGetCountFunc001(void const *argument) +{ + (void)argument; + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetCountFunc002, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osThreadExit(); +} + +static void CmsisThreadGetCountFunc003(void const *argument) +{ + (void)argument; + UINT32 uwRet; + uwRet = osThreadGetCount(); + TEST_ASSERT_EQUAL_INT(g_threadCount + 1, uwRet); + osThreadExit(); +} + +static void CmsisOSKernelLockFunc002(void const *argument) +{ + (void)argument; + g_cmsisTestTaskCount++; + osThreadExit(); +} + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for creat fail + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew001, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + + osDelay(DELAY_TICKS_5); + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, NULL); + TEST_ASSERT_NULL(id); + id = osThreadNew(NULL, NULL, NULL); + TEST_ASSERT_NULL(id); + id = osThreadNew(NULL, NULL, &attr); + TEST_ASSERT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for creat success + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew002, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_cmsisTestTaskCount = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreat002Func001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + TEST_ASSERT_EQUAL_INT(0, g_cmsisTestTaskCount); + + g_cmsisTestTaskCount++; + attr.priority = osPriorityAboveNormal; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreat002Func002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_3, g_cmsisTestTaskCount); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for delay scheduler + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew003, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + osThreadAttr_t attr1; + g_cmsisTestTaskCount = 0; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + id = osThreadNew ((osThreadFunc_t)CmsisThreadCreat003Func001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); + g_cmsisTestTaskCount++; + attr1.name = "test1"; + attr1.attr_bits = 0U; + attr1.cb_mem = NULL; + attr1.cb_size = 0U; + attr1.stack_mem = NULL; + attr1.stack_size = TEST_TASK_STACK_SIZE; + attr1.priority = osPriorityAboveNormal; + id = osThreadNew ((osThreadFunc_t)CmsisThreadCreat003Func002, NULL, &attr1); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_5, g_cmsisTestTaskCount); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for nesting schedule + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew004, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + g_cmsisTestTaskCount = 0; + attr.priority = osPriorityAboveNormal; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreat004Func001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_3, g_cmsisTestTaskCount); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for cycle schdule + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew005, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreat005Func001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_1); + g_cmsisTestTaskCount++; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for creat fail + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew006, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNone; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for creat fail + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew007, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityIdle; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for creat fail + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew008, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for creat success + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew009, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for creat success + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew0010, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow7; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for creat success + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew011, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for creat success + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew012, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal7; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for creat success + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew013, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for creat success + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew014, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal7; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for creat success + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew015, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for creat success + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew016, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for creat fail + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew017, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal7; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for creat fail + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew018, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityHigh; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for creat fail + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew019, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityHigh7; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for creat fail + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew020, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityRealtime; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for creat fail + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew021, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityRealtime7; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for creat fail + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew022, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityISR; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for creat fail + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew023, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityError; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for creat fail + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew024, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityReserved; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread creat operation with func = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew025, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + + id = osThreadNew(NULL, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread creat operation with attr = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew026, LEVEL1) +{ + osThreadId_t id; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, NULL); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get name + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetName001, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "testThreadGetName"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + + g_cmsisTestTaskCount = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetNameFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get state + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetState001, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + g_puwTaskID01 = osThreadGetId(); + id = osThreadNew ((osThreadFunc_t)CmsisThreadGetStateFunc002, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for suspend + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadSuspend001, LEVEL1) +{ + osThreadId_t id; + osStatus_t uwRet; + osThreadAttr_t attr; + osThreadState_t state; + g_cmsisTestTaskCount = 0; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + id = osThreadNew ((osThreadFunc_t)CmsisThreadSuspendFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadBlocked, state); + uwRet = osThreadResume(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get ID + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetId001, LEVEL1) +{ + g_puwTaskID01 = osThreadGetId(); + TEST_ASSERT_NOT_NULL(g_puwTaskID01); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get ID + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetId002, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetIDFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT((uintptr_t)id, (uintptr_t)g_puwTaskID01); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get ID + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetId003, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow7; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetIDFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT((uintptr_t)id, (uintptr_t)g_puwTaskID01); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get ID + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetId004, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetIDFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT((uintptr_t)id, (uintptr_t)g_puwTaskID01); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get ID + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetId005, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal7; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetIDFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT((uintptr_t)id, (uintptr_t)g_puwTaskID01); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get ID + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetId006, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetIDFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT((uintptr_t)id, (uintptr_t)g_puwTaskID01); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get ID + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetId007, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal7; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetIDFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + TEST_ASSERT_EQUAL_INT((uintptr_t)id, (uintptr_t)g_puwTaskID01); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get ID + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetId008, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetIDFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + TEST_ASSERT_EQUAL_INT((uintptr_t)id, (uintptr_t)g_puwTaskID01); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get ID + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetId009, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetIDFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + TEST_ASSERT_EQUAL_INT((uintptr_t)id, (uintptr_t)g_puwTaskID01); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get ID + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetId010, LEVEL1) +{ + g_puwTaskID01 = osThreadGetId(); + TEST_ASSERT_NOT_NULL(g_puwTaskID01); + osThreadExit(); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get stack size + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSize001, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_cmsisTestTaskCount = 0; + g_puwTaskID01 = 0; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSizeFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get stack space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSpace001, LEVEL1) +{ + UINT32 uwCount; + g_cmsisTestTaskCount = 0; + g_puwTaskID01 = osThreadGetId(); + uwCount = osThreadGetStackSpace(g_puwTaskID01); + TEST_ASSERT_GREATER_THAN_INT32(0, uwCount); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for yield + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadYield001, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_threadPriority = osPriorityLow1; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_threadPriority; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + id = osThreadNew((osThreadFunc_t)CmsisThreadYieldFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for yield + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadYield002, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_threadPriority = osPriorityLow7; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_threadPriority; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + id = osThreadNew((osThreadFunc_t)CmsisThreadYieldFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for yield + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadYield003, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_threadPriority = osPriorityBelowNormal; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_threadPriority; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + id = osThreadNew((osThreadFunc_t)CmsisThreadYieldFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for yield + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadYield004, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_threadPriority = osPriorityBelowNormal7; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_threadPriority; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + id = osThreadNew((osThreadFunc_t)CmsisThreadYieldFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for yield + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadYield005, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_threadPriority = osPriorityNormal; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_threadPriority; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + id = osThreadNew((osThreadFunc_t)CmsisThreadYieldFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for yield + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadYield006, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_threadPriority = osPriorityNormal7; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_threadPriority; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + id = osThreadNew((osThreadFunc_t)CmsisThreadYieldFunc001, NULL, &attr); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for yield + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadYield007, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_threadPriority = osPriorityAboveNormal; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_threadPriority; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + id = osThreadNew((osThreadFunc_t)CmsisThreadYieldFunc001, NULL, &attr); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for yield + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadYield008, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_threadPriority = osPriorityAboveNormal6; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_threadPriority; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + id = osThreadNew((osThreadFunc_t)CmsisThreadYieldFunc001, NULL, &attr); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread yield operation for thread with different priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadYield009, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + id = osThreadNew((osThreadFunc_t)CmsisThreadYieldFunc003, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for resume + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadResume001, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + id = osThreadNew((osThreadFunc_t)CmsisThreadResumeFunc001, NULL, &attr); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_3, g_cmsisTestTaskCount); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for terminate + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadTerminate001, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + id = osThreadNew((osThreadFunc_t)CmsisThreadTerminateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for count + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetCount001, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetCountFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for count + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetCount002, LEVEL1) +{ + UINT32 uwRet; + uwRet = osThreadGetCount(); + TEST_ASSERT_GREATER_THAN_INT32(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for count + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetCount003, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_threadCount = osThreadGetCount(); + TEST_ASSERT_GREATER_THAN_INT32(0, g_threadCount); + id = osThreadNew((osThreadFunc_t)CmsisThreadGetCountFunc003, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for count + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetCount004, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow7; + g_threadCount = osThreadGetCount(); + TEST_ASSERT_GREATER_THAN_INT32(0, g_threadCount); + id = osThreadNew((osThreadFunc_t)CmsisThreadGetCountFunc003, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for count + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetCount005, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal; + g_threadCount = osThreadGetCount(); + TEST_ASSERT_GREATER_THAN_INT32(0, g_threadCount); + id = osThreadNew((osThreadFunc_t)CmsisThreadGetCountFunc003, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for count + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetCount006, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal7; + g_threadCount = osThreadGetCount(); + TEST_ASSERT_GREATER_THAN_INT32(0, g_threadCount); + id = osThreadNew((osThreadFunc_t)CmsisThreadGetCountFunc003, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for count + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetCount007, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_threadCount = osThreadGetCount(); + TEST_ASSERT_GREATER_THAN_INT32(0, g_threadCount); + id = osThreadNew((osThreadFunc_t)CmsisThreadGetCountFunc003, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for count + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetCount008, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal7; + g_threadCount = osThreadGetCount(); + TEST_ASSERT_GREATER_THAN_INT32(0, g_threadCount); + id = osThreadNew((osThreadFunc_t)CmsisThreadGetCountFunc003, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for count + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetCount009, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + g_threadCount = osThreadGetCount(); + TEST_ASSERT_GREATER_THAN_INT32(0, g_threadCount); + id = osThreadNew((osThreadFunc_t)CmsisThreadGetCountFunc003, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for count + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetCount010, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_threadCount = osThreadGetCount(); + TEST_ASSERT_GREATER_THAN_INT32(0, g_threadCount); + id = osThreadNew((osThreadFunc_t)CmsisThreadGetCountFunc003, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get name input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetName002, LEVEL1) +{ + osThreadAttr_t attr; + attr.name = osThreadGetName(NULL); + TEST_ASSERT_NULL(attr.name); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get name + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetName003, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "testThreadGetName"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetNameFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get name + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetName004, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "testThreadGetName"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow7; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetNameFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get name + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetName005, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "testThreadGetName"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetNameFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get name + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetName006, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "testThreadGetName"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal7; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetNameFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get name + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetName007, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "testThreadGetName"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal7; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetNameFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get name + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetName008, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "testThreadGetName"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetNameFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get name + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetName009, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "testThreadGetName"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetNameFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get name + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetName010, LEVEL1) +{ + osThreadAttr_t attr; + g_puwTaskID01 = osThreadGetId(); + attr.name = osThreadGetName(g_puwTaskID01); + TEST_ASSERT_NOT_NULL(attr.name); + osThreadExit(); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get state input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetState002, LEVEL1) +{ + osStatus_t uwRet; + uwRet = osThreadGetState(NULL); + TEST_ASSERT_EQUAL_INT(osThreadError, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get state + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetState003, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + + g_puwTaskID01 = osThreadGetId(); + id = osThreadNew ((osThreadFunc_t)CmsisThreadGetStateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get state + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetState004, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow7; + + g_puwTaskID01 = osThreadGetId(); + id = osThreadNew ((osThreadFunc_t)CmsisThreadGetStateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get state + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetState005, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal; + + g_puwTaskID01 = osThreadGetId(); + id = osThreadNew ((osThreadFunc_t)CmsisThreadGetStateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get state + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetState006, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal7; + + g_puwTaskID01 = osThreadGetId(); + id = osThreadNew ((osThreadFunc_t)CmsisThreadGetStateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get state + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetState007, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + + g_puwTaskID01 = osThreadGetId(); + id = osThreadNew ((osThreadFunc_t)CmsisThreadGetStateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get state + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetState008, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal7; + + g_puwTaskID01 = osThreadGetId(); + id = osThreadNew ((osThreadFunc_t)CmsisThreadGetStateFunc002, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get state + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetState009, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + + g_puwTaskID01 = osThreadGetId(); + id = osThreadNew ((osThreadFunc_t)CmsisThreadGetStateFunc002, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get state + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetState010, LEVEL1) +{ + osThreadState_t state; + g_puwTaskID01 = osThreadGetId(); + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadRunning, state); + osThreadExit(); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for suspend input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadSuspend002, LEVEL1) +{ + osStatus_t uwRet; + uwRet = osThreadSuspend(NULL); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for suspend + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadSuspend003, LEVEL1) +{ + osThreadId_t id; + osStatus_t uwRet; + osThreadAttr_t attr; + osThreadState_t state; + g_cmsisTestTaskCount = 0; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow7; + id = osThreadNew ((osThreadFunc_t)CmsisThreadSuspendFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadBlocked, state); + uwRet = osThreadResume(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for suspend + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadSuspend004, LEVEL1) +{ + osThreadId_t id; + osStatus_t uwRet; + osThreadAttr_t attr; + osThreadState_t state; + g_cmsisTestTaskCount = 0; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal; + id = osThreadNew ((osThreadFunc_t)CmsisThreadSuspendFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadBlocked, state); + uwRet = osThreadResume(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for suspend + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadSuspend005, LEVEL1) +{ + osThreadId_t id; + osStatus_t uwRet; + osThreadAttr_t attr; + osThreadState_t state; + g_cmsisTestTaskCount = 0; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal7; + id = osThreadNew ((osThreadFunc_t)CmsisThreadSuspendFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadBlocked, state); + uwRet = osThreadResume(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for suspend + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadSuspend006, LEVEL1) +{ + osThreadId_t id; + osStatus_t uwRet; + osThreadAttr_t attr; + osThreadState_t state; + g_cmsisTestTaskCount = 0; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + id = osThreadNew ((osThreadFunc_t)CmsisThreadSuspendFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadBlocked, state); + uwRet = osThreadResume(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for suspend + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadSuspend007, LEVEL1) +{ + osThreadId_t id; + osStatus_t uwRet; + osThreadAttr_t attr; + osThreadState_t state; + g_cmsisTestTaskCount = 0; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal7; + id = osThreadNew ((osThreadFunc_t)CmsisThreadSuspendFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadBlocked, state); + uwRet = osThreadResume(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for suspend + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadSuspend008, LEVEL1) +{ + osThreadId_t id; + osStatus_t uwRet; + osThreadAttr_t attr; + osThreadState_t state; + g_cmsisTestTaskCount = 0; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + id = osThreadNew ((osThreadFunc_t)CmsisThreadSuspendFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadBlocked, state); + uwRet = osThreadResume(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for suspend + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadSuspend009, LEVEL1) +{ + osThreadId_t id; + osStatus_t uwRet; + osThreadAttr_t attr; + osThreadState_t state; + g_cmsisTestTaskCount = 0; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + id = osThreadNew ((osThreadFunc_t)CmsisThreadSuspendFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadBlocked, state); + uwRet = osThreadResume(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get stack size input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSize002, LEVEL1) +{ + UINT32 uwRet; + uwRet = osThreadGetStackSize(NULL); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get stack size + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSize003, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSizeFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get stack size + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSize004, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow7; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSizeFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get stack size + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSize005, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSizeFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get stack size + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSize006, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal7; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSizeFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get stack size + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSize007, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSizeFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get stack size + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSize008, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal7; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSizeFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get stack size + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSize009, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSizeFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get stack size + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSize010, LEVEL1) +{ + osThreadAttr_t attr; + g_puwTaskID01 = osThreadGetId(); + attr.stack_size = osThreadGetStackSize(g_puwTaskID01); + TEST_ASSERT_GREATER_THAN_INT32(0, attr.stack_size); + osThreadExit(); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get stack space input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSpace002, LEVEL1) +{ + UINT32 uwRet; + uwRet = osThreadGetStackSpace(NULL); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get stack space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSpace003, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSpaceFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get stack space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSpace004, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow7; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSpaceFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get stack space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSpace005, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSpaceFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get stack space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSpace006, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal7; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSpaceFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get stack space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSpace007, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSpaceFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get stack space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSpace008, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal7; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSpaceFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get stack space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSpace009, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSpaceFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get stack space + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSpace010, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSpaceFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for resume input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadResume002, LEVEL1) +{ + UINT32 uwRet; + uwRet = osThreadResume(NULL); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for resume input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadResume003, LEVEL1) +{ + UINT32 uwRet; + g_puwTaskID01 = osThreadGetId(); + uwRet = osThreadResume(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for terminate input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadTerminate002, LEVEL1) +{ + UINT32 uwRet; + uwRet = osThreadTerminate(NULL); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for terminate + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadTerminate003, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow7; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + id = osThreadNew((osThreadFunc_t)CmsisThreadTerminateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for terminate + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadTerminate004, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + id = osThreadNew((osThreadFunc_t)CmsisThreadTerminateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for terminate + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadTerminate005, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal7; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + id = osThreadNew((osThreadFunc_t)CmsisThreadTerminateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for terminate + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadTerminate006, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + id = osThreadNew((osThreadFunc_t)CmsisThreadTerminateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for terminate + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadTerminate007, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal7; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + id = osThreadNew((osThreadFunc_t)CmsisThreadTerminateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for terminate + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadTerminate008, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + id = osThreadNew((osThreadFunc_t)CmsisThreadTerminateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for terminate + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadTerminate009, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + id = osThreadNew((osThreadFunc_t)CmsisThreadTerminateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : kernel operation for get info + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsKernelGetInfo001, LEVEL1) +{ + CHAR infobuf[100]; + osVersion_t osv; + osStatus_t status; + status = osKernelGetInfo(&osv, infobuf, sizeof(infobuf)); + TEST_ASSERT_EQUAL_INT(osOK, status); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : kernel operation for get state + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsKernelGetState001, LEVEL1) +{ + osKernelState_t uwRet; + uwRet = osKernelGetState(); + TEST_ASSERT_EQUAL_INT(osKernelRunning, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_Cmsis_TASK_OPERATION_100 + * @tc.name : kernel operation for get state + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsKernelGetState002, LEVEL1) +{ + osKernelLock (); + osKernelState_t uwRet; + uwRet = osKernelGetState(); + TEST_ASSERT_EQUAL_INT(osKernelLocked, uwRet); + osKernelUnlock (); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : kernel operation for lock + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsKernelLock001, LEVEL1) +{ + UINT32 uwRet; + uwRet = osKernelLock(); + TEST_ASSERT_EQUAL_INT(0, uwRet); + uwRet = osKernelLock(); + TEST_ASSERT_EQUAL_INT(1, uwRet); + osKernelUnlock(); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : kernel operation for lock + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsKernelLock002, LEVEL1) +{ + UINT32 uwRet; + osThreadId_t id; + osThreadAttr_t attr; + g_cmsisTestTaskCount = 0; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + + uwRet = osKernelLock(); + TEST_ASSERT_EQUAL_INT(0, uwRet); + id = osThreadNew((osThreadFunc_t)CmsisOSKernelLockFunc002, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + TEST_ASSERT_EQUAL_INT(0, g_cmsisTestTaskCount); + uwRet = osKernelUnlock(); + TEST_ASSERT_EQUAL_INT(1, uwRet); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : kernel operation for unlock + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsKernelUnLock001, LEVEL1) +{ + UINT32 uwRet; + uwRet = osKernelUnlock(); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : kernel operation for unlock + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsKernelUnLock002, LEVEL1) +{ + UINT32 uwRet; + (void)osKernelLock(); + uwRet = osKernelUnlock(); + TEST_ASSERT_EQUAL_INT(1, uwRet); + uwRet = osKernelUnlock(); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : kernel operation for unlock + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsKernelUnLock003, LEVEL1) +{ + UINT32 uwRet; + (void)osKernelLock(); + (void)osKernelLock(); + uwRet = osKernelUnlock(); + TEST_ASSERT_EQUAL_INT(1, uwRet); + uwRet = osKernelUnlock(); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : kernel operation for restore lock + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsKernelRestoreLock001, LEVEL1) +{ + UINT32 uwRet; + (void)osKernelLock(); + uwRet = osKernelRestoreLock(0); + TEST_ASSERT_EQUAL_INT(0, uwRet); + uwRet = osKernelUnlock(); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : kernel operation for restore lock + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsKernelRestoreLock002, LEVEL1) +{ + UINT32 uwRet; + (void)osKernelLock(); + (void)osKernelLock(); + uwRet = osKernelRestoreLock(0); + TEST_ASSERT_EQUAL_INT(0, uwRet); + uwRet = osKernelUnlock(); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : kernel operation for restore lock + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsKernelRestoreLock003, LEVEL1) +{ + UINT32 uwRet; + uwRet = osKernelUnlock(); + TEST_ASSERT_EQUAL_INT(0, uwRet); + uwRet = osKernelRestoreLock(1); + TEST_ASSERT_EQUAL_INT(1, uwRet); + uwRet = osKernelUnlock(); + TEST_ASSERT_EQUAL_INT(1, uwRet); +}; + +RUN_TEST_SUITE(CmsisTaskFuncTestSuite); diff --git a/kernel_lite/kernelcmsis_hal/src/cmsis_task_pri_func_test.c b/kernel_lite/kernelcmsis_hal/src/cmsis_task_pri_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..b58a03847467dca9fb770bc546b330b3b9487b78 --- /dev/null +++ b/kernel_lite/kernelcmsis_hal/src/cmsis_task_pri_func_test.c @@ -0,0 +1,1857 @@ +/** + * Copyright (c) 2020 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 "hos_types.h" +#include +#include "hctest.h" +#include "los_config.h" +#include "cmsis_os2.h" +#include "kernel_test.h" + +osThreadId_t g_priTaskID01; +osPriority_t g_setPriority; + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is utils + * @param : module name is utilsFile + * @param : test suit name is CmsisTaskPriFuncTestSuite + */ +LITE_TEST_SUIT(Cmsis, Cmsistask, CmsisTaskPriFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL CmsisTaskPriFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL CmsisTaskPriFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +static void CmsisThreadGetPriorityFunc001(void const *argument) +{ + (void)argument; + osThreadAttr_t attr; + g_priTaskID01 = osThreadGetId(); + attr.priority = osThreadGetPriority(g_priTaskID01); + TEST_ASSERT_EQUAL_INT(g_setPriority, attr.priority); + osThreadExit(); +} + +static void CmsisThreadSetPriorityFunc001(void const *argument) +{ + (void)argument; + osThreadAttr_t attr; + UINT32 uwRet; + g_priTaskID01 = osThreadGetId(); + uwRet = osThreadSetPriority(g_priTaskID01, g_setPriority); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + attr.priority = osThreadGetPriority(g_priTaskID01); + TEST_ASSERT_EQUAL_INT(g_setPriority, attr.priority); + osThreadExit(); +} + +static void CmsisThreadSetPriorityFunc002(void const *argument) +{ + (void)argument; + UINT32 uwRet; + g_priTaskID01 = osThreadGetId(); + uwRet = osThreadSetPriority(g_priTaskID01, g_setPriority); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); + osThreadExit(); +} + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadGetPriority001, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_setPriority = osPriorityLow1; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_setPriority; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadGetPriority002, LEVEL1) +{ + UINT32 uwRet; + uwRet = osThreadGetPriority(NULL); + TEST_ASSERT_EQUAL_INT(osPriorityError, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadGetPriority003, LEVEL1) +{ + UINT32 uwRet; + g_priTaskID01 = osThreadGetId(); + uwRet = osThreadGetPriority(g_priTaskID01); + TEST_ASSERT_EQUAL_INT(osPriorityNormal, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadGetPriority004, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_setPriority = osPriorityLow7; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_setPriority; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadGetPriority005, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_setPriority = osPriorityBelowNormal; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_setPriority; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadGetPriority006, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_setPriority = osPriorityBelowNormal7; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_setPriority; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadGetPriority007, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_setPriority = osPriorityNormal; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_setPriority; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadGetPriority008, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_setPriority = osPriorityNormal7; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_setPriority; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetPriorityFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadGetPriority009, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_setPriority = osPriorityAboveNormal; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_setPriority; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetPriorityFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for get priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadGetPriority010, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_setPriority = osPriorityAboveNormal6; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_setPriority; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetPriorityFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input1 exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority001, LEVEL1) +{ + UINT32 uwRet; + uwRet = osThreadSetPriority(NULL, osPriorityNormal); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input2 exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority002, LEVEL1) +{ + UINT32 uwRet; + g_priTaskID01 = osThreadGetId(); + uwRet = osThreadSetPriority(g_priTaskID01, osPriorityNone); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority003, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityNone; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority004, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityIdle; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority005, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityLow; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority006, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityLow1; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority007, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityLow7; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority008, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityBelowNormal; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority009, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityBelowNormal7; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority010, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityNormal; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority011, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityNormal7; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority012, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityAboveNormal; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority013, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityAboveNormal6; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority014, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityAboveNormal7; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority015, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityHigh; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority016, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityHigh7; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority017, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityRealtime; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority018, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityRealtime7; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority019, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityISR; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority020, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityError; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority021, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityReserved; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority022, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityNone; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority023, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityIdle; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority024, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityLow; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority025, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityLow1; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority026, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityLow7; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority027, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityBelowNormal; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority028, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityBelowNormal7; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority029, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityNormal; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority030, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityNormal7; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority031, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityAboveNormal; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority032, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityAboveNormal6; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority033, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityAboveNormal7; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority034, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityHigh; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority035, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityHigh7; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority036, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityRealtime; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority037, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityRealtime7; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority038, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityISR; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority039, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityError; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority040, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityReserved; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority041, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityNone; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority042, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityIdle; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority043, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityLow; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority044, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityLow1; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority045, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityLow7; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority046, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityBelowNormal; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority047, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityBelowNormal7; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority048, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityNormal; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority049, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityNormal7; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority050, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityAboveNormal; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority051, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityAboveNormal6; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority052, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityAboveNormal7; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority053, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityHigh; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority054, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityHigh7; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority055, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityRealtime; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority056, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityRealtime7; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority057, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityISR; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority058, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityError; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : thread operation for set priority input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority059, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityReserved; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : delay operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsDelay001, LEVEL1) +{ + UINT32 uwRet; + uwRet = osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : delay operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsDelay002, LEVEL1) +{ + UINT32 uwRet; + uwRet = osDelay(0); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : delay until operation + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsDelayUntil001, LEVEL1) +{ + UINT32 uwRet; + UINT32 uwTickCnt; + UINT32 uwUntilTickCnt; + uwTickCnt = osKernelGetTickCount(); + uwUntilTickCnt = uwTickCnt + DELAY_TICKS_10; + uwRet = osDelayUntil(uwUntilTickCnt); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : delay until operation input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsDelayUntil002, LEVEL1) +{ + UINT32 uwRet; + uwRet = osDelayUntil(DELAY_TICKS_1); + TEST_ASSERT_EQUAL_INT(osError, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_100 + * @tc.name : delay until operation input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsDelayUntil003, LEVEL1) +{ + UINT32 uwRet; + UINT32 uwTickCnt; + UINT32 uwUntilTickCnt; + uwTickCnt = osKernelGetTickCount(); + uwUntilTickCnt = uwTickCnt - DELAY_TICKS_10; + uwRet = osDelayUntil(uwUntilTickCnt); + TEST_ASSERT_EQUAL_INT(osError, uwRet); +}; + +RUN_TEST_SUITE(CmsisTaskPriFuncTestSuite); diff --git a/kernel_lite/kernelcmsis_hal/src/cmsis_timer_func_test.c b/kernel_lite/kernelcmsis_hal/src/cmsis_timer_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..8922b735cf94c722f08c35bd0b10806f67acf40b --- /dev/null +++ b/kernel_lite/kernelcmsis_hal/src/cmsis_timer_func_test.c @@ -0,0 +1,759 @@ +/** + * Copyright (c) 2020 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 "hos_types.h" +#include +#include "hctest.h" +#include "los_config.h" +#include "cmsis_os2.h" +#include "kernel_test.h" + +UINT16 g_cmsisTestTimeCount; +#define MILLISEC_NUM_INT10 10 +#define MILLISEC_NUM_INT4 4 +#define INVALID_TIMER_TYPE 10 +#define TIMER_PERIODIC_COUNT 2 + + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is utils + * @param : module name is utilsFile + * @param : test suit name is CmsisTaskFuncTestSuite + */ +LITE_TEST_SUIT(Cmsis, Cmsistimer, CmsisTimerFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL CmsisTimerFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL CmsisTimerFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +static void CmsisTimerFunc001(void const *argument) +{ + (void)argument; + return; +} + +static void CmsisTimerFunc002(void const *argument) +{ + (void)argument; + g_cmsisTestTimeCount++; + return; +} + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for creat + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerNew001, LEVEL1) +{ + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + (void)osTimerDelete(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for creat + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerNew002, LEVEL1) +{ + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + (void)osTimerDelete(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer creat operation with NULL func + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerNew003, LEVEL1) +{ + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew(NULL, osTimerOnce, &value, NULL); + TEST_ASSERT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer creat operation with NULL func + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerNew004, LEVEL1) +{ + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew(NULL, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for invalid timer type + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerNew005, LEVEL1) +{ + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, INVALID_TIMER_TYPE, &value, NULL); + TEST_ASSERT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for start + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStart001, LEVEL1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT4; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + uwRet = osTimerStart(id, millisec); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for start + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStart002, LEVEL1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT4; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + uwRet = osTimerStart(id, millisec); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for start + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStart003, LEVEL1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT4; + g_cmsisTestTimeCount = 0; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc002, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + uwRet = osTimerStart(id, millisec); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + osDelay(DELAY_TICKS_10); + TEST_ASSERT_EQUAL_INT(1, g_cmsisTestTimeCount); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for start + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStart004, LEVEL1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT4; + g_cmsisTestTimeCount = 0; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc002, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + uwRet = osTimerStart(id, millisec); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + osDelay(DELAY_TICKS_10); + TEST_ASSERT_EQUAL_INT(TIMER_PERIODIC_COUNT, g_cmsisTestTimeCount); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer start operation with ticks = 0 + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStart005, LEVEL1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + uwRet = osTimerStart(id, 0); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer start operation with ticks = 0 + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStart006, LEVEL1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + uwRet = osTimerStart(id, 0); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer start operation with timer_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStart007, LEVEL1) +{ + UINT32 uwRet; + UINT32 millisec = MILLISEC_NUM_INT4; + uwRet = osTimerStart(NULL, millisec); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for delete + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerDelete001, LEVEL1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osDelay(1); + uwRet = osTimerDelete(id); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for delete + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerDelete002, LEVEL1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osDelay(1); + uwRet = osTimerDelete(id); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for delete + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerDelete003, LEVEL1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osTimerStart(id, millisec); + osDelay(1); + uwRet = osTimerDelete(id); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for delete + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerDelete004, LEVEL1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osTimerStart(id, millisec); + osDelay(1); + uwRet = osTimerDelete(id); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer delete operation with timer_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerDelete005, LEVEL1) +{ + UINT32 uwRet; + uwRet = osTimerDelete(NULL); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for stop + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStop001, LEVEL1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osTimerStart(id, millisec); + osDelay(1); + uwRet = osTimerStop(id); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for stop + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStop002, LEVEL1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osTimerStart(id, millisec); + osDelay(1); + uwRet = osTimerStop(id); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for stop + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStop003, LEVEL1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osDelay(1); + uwRet = osTimerStop(id); + TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for stop + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStop004, LEVEL1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osDelay(1); + uwRet = osTimerStop(id); + TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer stop operation with timer_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStop005, LEVEL1) +{ + UINT32 uwRet; + uwRet = osTimerStop(NULL); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for running + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerIsRunning001, LEVEL1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew ((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + uwRet = osTimerIsRunning(id); + TEST_ASSERT_EQUAL_INT(0, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for running + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerIsRunning002, LEVEL1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osTimerStart(id, millisec); + uwRet = osTimerIsRunning(id); + TEST_ASSERT_EQUAL_INT(1, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for running + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerIsRunning003, LEVEL1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew ((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osTimerStart(id, millisec); + osTimerStop(id); + + uwRet = osTimerIsRunning(id); + TEST_ASSERT_EQUAL_INT(0, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for running + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerIsRunning004, LEVEL1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew ((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osTimerStart(id, millisec); + osTimerDelete(id); + uwRet = osTimerIsRunning(id); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for running + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerIsRunning005, LEVEL1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew ((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + uwRet = osTimerIsRunning(id); + TEST_ASSERT_EQUAL_INT(0, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for running + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerIsRunning006, LEVEL1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osTimerStart(id, millisec); + uwRet = osTimerIsRunning(id); + TEST_ASSERT_EQUAL_INT(1, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for running + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerIsRunning007, LEVEL1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew ((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osTimerStart(id, millisec); + osTimerStop(id); + + uwRet = osTimerIsRunning(id); + TEST_ASSERT_EQUAL_INT(0, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer operation for running + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerIsRunning008, LEVEL1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew ((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osTimerStart(id, millisec); + osTimerDelete(id); + uwRet = osTimerIsRunning(id); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : timer running inquiry with timer_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerIsRunning009, LEVEL1) +{ + UINT32 uwRet; + uwRet = osTimerIsRunning(NULL); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : os operation for get tick freq + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsKernelGetTickFreq001, LEVEL1) +{ + UINT32 uwRet; + uwRet = osKernelGetTickFreq(); + TEST_ASSERT_EQUAL_INT(LOSCFG_BASE_CORE_TICK_PER_SECOND, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : os operation for get sys time freq + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsKernelGetSysTimerFreq001, LEVEL1) +{ + UINT32 uwRet; + uwRet = osKernelGetSysTimerFreq(); + TEST_ASSERT_EQUAL_INT(OS_SYS_CLOCK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_100 + * @tc.name : os operation for get sys time count + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsKernelGetSysTimerCount001, LEVEL1) +{ + UINT32 uwRet; + uwRet = osKernelGetSysTimerCount(); + TEST_ASSERT_GREATER_THAN_UINT32(0, uwRet); +}; + +RUN_TEST_SUITE(CmsisTimerFuncTestSuite); diff --git a/kernel_lite/kernelcmsis_hal/src/kernel_test.h b/kernel_lite/kernelcmsis_hal/src/kernel_test.h new file mode 100755 index 0000000000000000000000000000000000000000..664150f7fd0fe156d2b41ebddda77210590671f1 --- /dev/null +++ b/kernel_lite/kernelcmsis_hal/src/kernel_test.h @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2020 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 KERNEL_TEST_H +#define KERNEL_TEST_H + +#define TESTCOUNT_NUM_1 1 +#define TESTCOUNT_NUM_2 2 +#define TESTCOUNT_NUM_3 3 +#define TESTCOUNT_NUM_4 4 +#define TESTCOUNT_NUM_5 5 + +#define DELAY_TICKS_1 1 +#define DELAY_TICKS_5 5 +#define DELAY_TICKS_10 10 + +#define TEST_TASK_STACK_SIZE 0x600 +#define TASK_LOOP_NUM 0x10000000 +#define TEST_TIME 10 +#define THREAD_COUNT_MIN 3 +#define THREAD_COUNT_MAX 30 +#define THREAD_STACK_SPACE_MAX 4096 + +#ifdef __cplusplus +#if __cplusplus +#endif +#endif /* __cplusplus */ +#endif diff --git a/kernel_lite/kernelkal_hal/BUILD.gn b/kernel_lite/kernelkal_hal/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..8f81e25ee48cc9821a5887971b41559df4f5f33a --- /dev/null +++ b/kernel_lite/kernelkal_hal/BUILD.gn @@ -0,0 +1,32 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hctest_suite("ActsKalTest") { + suite_name = "acts" + sources = [ + "src/kal_func_test.c", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "//third_party/unity/src", + "src", + "//kernel/liteos_m/components/cmsis", + "//kernel/liteos_m/components/cmsis/2.0", + "//kernel/liteos_m/components/kal/include", + "//kernel/liteos_m/kernel/base/include", + ] + cflags = [ "-Wno-error" ] +} \ No newline at end of file diff --git a/kernel_lite/kernelkal_hal/Test.tmpl b/kernel_lite/kernelkal_hal/Test.tmpl new file mode 100755 index 0000000000000000000000000000000000000000..be8407e1286041a5af2bdc75a15633337376eb9d --- /dev/null +++ b/kernel_lite/kernelkal_hal/Test.tmpl @@ -0,0 +1,19 @@ +{ + "description": "Config for $module test cases", + "environment": [ + { + "type": "device", + "label": "wifiiot" + } + ], + "kits": [ + { + "type": "DeployKit", + "timeout": "20000", + "burn_file": "$subsystem/$module.bin" + } + ], + "driver": { + "type": "CTestLite" + } +} \ No newline at end of file diff --git a/kernel_lite/kernelkal_hal/src/kal_func_test.c b/kernel_lite/kernelkal_hal/src/kal_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..1573dcc144d480b9e5299ebfce21bc5072e81147 --- /dev/null +++ b/kernel_lite/kernelkal_hal/src/kal_func_test.c @@ -0,0 +1,597 @@ +/** + * Copyright (c) 2020 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 "hos_types.h" +#include +#include "hctest.h" +#include "los_config.h" +#include "kal.h" +#include "cmsis_os2.h" +#include "los_task_pri.h" + + +UINT16 g_kalTestCount; +#define MILLISEC_NUM_10 10 +#define MILLISEC_NUM_1000 1000 +#define TICK_NUM_10 10 +#define TICK_NUM_20 20 +#define TICK_NUM_30 30 +#define TICK_NUM_40 40 +#define TICK_NUM_1000 1000 +#define TESTCOUNT_NUM_1 1 +#define TESTCOUNT_NUM_2 2 +#define TESTCOUNT_NUM_3 3 +#define TESTCOUNT_NUM_4 4 +#define TESTCOUNT_NUM_5 5 +#define TEST_TASK_STACK_SIZE 0x600 +#define TEST_TASK_PRIORITY_LOW osPriorityBelowNormal // tskIDLE_PRIORITY + 10 +#define TEST_TASK_PRIORITY_NORMAL osPriorityNormal // tskIDLE_PRIORITY + 11 +#define TEST_TASK_PRIORITY_HIGH osPriorityAboveNormal // tskIDLE_PRIORITY + 12 +#define PRIORITY_TRANSFORM_NUM 39 + + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is utils + * @param : module name is utilsFile + * @param : test suit name is CmsisTaskFuncTestSuite + */ +LITE_TEST_SUIT(Kal, KalApi, KalFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL KalFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL KalFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +static void KalTimerProc001Func001(void *argument) +{ + (void)argument; + g_kalTestCount++; + return; +} + +static void KalThreadGetInfo001Func001(void const *argument) +{ + (void)argument; + int ret; + LosTaskCB *pid; + ThreadInfo info; + pid = (LosTaskCB*)osThreadGetId(); + ret = KalThreadGetInfo(pid->taskID, &info); + TEST_ASSERT_EQUAL_INT(0, ret); + TEST_ASSERT_EQUAL_STRING("testThreadGetInfo001", info.name); + TEST_ASSERT_EQUAL_INT(TEST_TASK_STACK_SIZE, info.stackSize); + // Priorities defined in KAL are different in CMSIS,need to transform + TEST_ASSERT_EQUAL_INT(TEST_TASK_PRIORITY_HIGH, PRIORITY_TRANSFORM_NUM - info.priority); + osThreadExit(); +} + +static void KalDelayUs001Func001(void const *argument) +{ + (void)argument; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_kalTestCount); + g_kalTestCount++; + osThreadExit(); +} + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal api for delay us + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalDelayUs001, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = TEST_TASK_PRIORITY_NORMAL; + g_kalTestCount = 0; + g_kalTestCount++; + id = osThreadNew((osThreadFunc_t)KalDelayUs001Func001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + KalDelayUs(MILLISEC_NUM_10); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_kalTestCount); + +}; + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal get thread Info + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalThreadGetInfo001, LEVEL1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "testThreadGetInfo001"; + attr.attr_bits = 1U; + attr.cb_mem = NULL; + attr.cb_size = 2U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = TEST_TASK_PRIORITY_HIGH; + printf("KalThreadGetInfo ThreadAttr Name = %s \r\n", attr.name); + printf("KalThreadGetInfo ThreadAttr StackSize = %x \r\n", attr.stack_size); + printf("KalThreadGetInfo ThreadAttr Priority = %d \r\n", attr.priority); + id = osThreadNew((osThreadFunc_t)KalThreadGetInfo001Func001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal get thread Info when info = NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalThreadGetInfo002, LEVEL1) +{ + int ret; + LosTaskCB *pid; + pid = (LosTaskCB*)osThreadGetId(); + ret = KalThreadGetInfo(pid->taskID, NULL); + TEST_ASSERT_EQUAL_INT(-1, ret); +}; + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal timer create + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalTimerCreate001, LEVEL1) +{ + KalTimerId id; + id = KalTimerCreate(KalTimerProc001Func001, KAL_TIMER_ONCE, NULL, TICK_NUM_20); + TEST_ASSERT_NOT_NULL(id); + (void)KalTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal timer create input kalTimerproc exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalTimerCreate002, LEVEL1) +{ + g_kalTestCount = 0; + KalTimerId id; + id = KalTimerCreate(NULL, KAL_TIMER_ONCE, NULL, TICK_NUM_20); + TEST_ASSERT_NULL(id); + (void)KalTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal timer create repeat + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalTimerCreate003, LEVEL1) +{ + g_kalTestCount = 0; + KalTimerId id; + KalErrCode kRet; + id = KalTimerCreate(KalTimerProc001Func001, KAL_TIMER_PERIODIC, NULL, TICK_NUM_20); + TEST_ASSERT_NOT_NULL(id); + kRet = KalTimerStart(id); + TEST_ASSERT_EQUAL_INT(KAL_OK, kRet); + osDelay(TICK_NUM_30); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_kalTestCount); + osDelay(TICK_NUM_20); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_kalTestCount); + (void)KalTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal timer start + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalTimerStart001, LEVEL1) +{ + KalTimerId id; + KalErrCode kRet; + id = KalTimerCreate(KalTimerProc001Func001, KAL_TIMER_ONCE, NULL, TICK_NUM_20); + TEST_ASSERT_NOT_NULL(id); + kRet = KalTimerStart(id); + TEST_ASSERT_EQUAL_INT(KAL_OK, kRet); + (void)KalTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal timer start input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalTimerStart002, LEVEL1) +{ + KalErrCode kRet; + kRet = KalTimerStart(NULL); + TEST_ASSERT_EQUAL_INT(KAL_ERR_PARA, kRet); +}; + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal timer is running + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalTimerIsRunning001, LEVEL1) +{ + KalTimerId id; + UINT32 uwRet; + KalErrCode kRet; + id = KalTimerCreate(KalTimerProc001Func001, KAL_TIMER_ONCE, NULL, TICK_NUM_20); + TEST_ASSERT_NOT_NULL(id); + kRet = KalTimerStart(id); + TEST_ASSERT_EQUAL_INT(KAL_OK, kRet); + uwRet = KalTimerIsRunning(id); + TEST_ASSERT_EQUAL_INT(TRUE, uwRet); + (void)KalTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal timer is running input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalTimerIsRunning002, LEVEL1) +{ + UINT32 uwRet; + uwRet = KalTimerIsRunning(NULL); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal timer is running deal + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalTimerIsRunning003, LEVEL1) +{ + g_kalTestCount = 0; + KalTimerId id; + KalErrCode kRet; + UINT32 uwRet; + id = KalTimerCreate(KalTimerProc001Func001, KAL_TIMER_ONCE, NULL, TICK_NUM_20); + TEST_ASSERT_NOT_NULL(id); + kRet = KalTimerStart(id); + TEST_ASSERT_EQUAL_INT(KAL_OK, kRet); + uwRet = KalTimerIsRunning(id); + TEST_ASSERT_EQUAL_INT(TRUE, uwRet); + osDelay(TICK_NUM_10); + TEST_ASSERT_EQUAL_INT(0, g_kalTestCount); + osDelay(TICK_NUM_10); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_kalTestCount); + (void)KalTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal timer is stop + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalTimerStop001, LEVEL1) +{ + g_kalTestCount = 0; + KalTimerId id; + KalErrCode kRet; + id = KalTimerCreate(KalTimerProc001Func001, KAL_TIMER_ONCE, NULL, TICK_NUM_20); + TEST_ASSERT_NOT_NULL(id); + kRet = KalTimerStart(id); + TEST_ASSERT_EQUAL_INT(KAL_OK, kRet); + kRet = KalTimerStop(id); + TEST_ASSERT_EQUAL_INT(KAL_OK, kRet); + (void)KalTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal timer is stop input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalTimerStop002, LEVEL1) +{ + KalErrCode kRet; + KalTimerId id = NULL; + kRet = KalTimerStop(id); + TEST_ASSERT_EQUAL_INT(KAL_ERR_PARA, kRet); + (void)KalTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal timer is stop deal + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalTimerStop003, LEVEL1) +{ + g_kalTestCount = 0; + KalTimerId id; + KalErrCode kRet; + id = KalTimerCreate(KalTimerProc001Func001, KAL_TIMER_ONCE, NULL, TICK_NUM_20); + TEST_ASSERT_NOT_NULL(id); + kRet = KalTimerStart(id); + TEST_ASSERT_EQUAL_INT(KAL_OK, kRet); + osDelay(TICK_NUM_10); + TEST_ASSERT_EQUAL_INT(0, g_kalTestCount); + kRet = KalTimerStop(id); + TEST_ASSERT_EQUAL_INT(KAL_OK, kRet); + osDelay(TICK_NUM_20); + kRet = KalTimerStart(id); + TEST_ASSERT_EQUAL_INT(KAL_OK, kRet); + TEST_ASSERT_EQUAL_INT(0, g_kalTestCount); + osDelay(TICK_NUM_20); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_kalTestCount); + (void)KalTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal timer change + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalTimerChange001, LEVEL1) +{ + g_kalTestCount = 0; + KalTimerId id; + KalErrCode kRet; + id = KalTimerCreate(KalTimerProc001Func001, KAL_TIMER_ONCE, NULL, TICK_NUM_20); + TEST_ASSERT_NOT_NULL(id); + kRet = KalTimerChange(id, TICK_NUM_40); + TEST_ASSERT_EQUAL_INT(KAL_OK, kRet); + (void)KalTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal timer change start exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalTimerChange002, LEVEL1) +{ + g_kalTestCount = 0; + KalTimerId id; + KalErrCode kRet; + id = KalTimerCreate(KalTimerProc001Func001, KAL_TIMER_ONCE, NULL, TICK_NUM_20); + TEST_ASSERT_NOT_NULL(id); + kRet = KalTimerStart(id); + TEST_ASSERT_EQUAL_INT(KAL_OK, kRet); + kRet = KalTimerChange(id, TICK_NUM_40); + TEST_ASSERT_EQUAL_INT(KAL_ERR_TIMER_STATE, kRet); + (void)KalTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal timer is stop input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalTimerChange003, LEVEL1) +{ + KalErrCode kRet; + KalTimerId id = NULL; + kRet = KalTimerChange(id, TICK_NUM_20); + TEST_ASSERT_EQUAL_INT(KAL_ERR_PARA, kRet); +}; + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal timer is stop deal + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalTimerChange004, LEVEL1) +{ + g_kalTestCount = 0; + KalTimerId id; + KalErrCode kRet; + id = KalTimerCreate(KalTimerProc001Func001, KAL_TIMER_ONCE, NULL, TICK_NUM_20); + TEST_ASSERT_NOT_NULL(id); + kRet = KalTimerChange(id, TICK_NUM_40); + TEST_ASSERT_EQUAL_INT(KAL_OK, kRet); + kRet = KalTimerStart(id); + TEST_ASSERT_EQUAL_INT(KAL_OK, kRet); + osDelay(TICK_NUM_30); + TEST_ASSERT_EQUAL_INT(0, g_kalTestCount); + osDelay(TICK_NUM_20); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_kalTestCount); + (void)KalTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal timer delete + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalTimerDelete001, LEVEL1) +{ + g_kalTestCount = 0; + KalTimerId id; + KalErrCode kRet; + id = KalTimerCreate(KalTimerProc001Func001, KAL_TIMER_ONCE, NULL, TICK_NUM_20); + TEST_ASSERT_NOT_NULL(id); + kRet = KalTimerStart(id); + TEST_ASSERT_EQUAL_INT(KAL_OK, kRet); + kRet = KalTimerDelete(id); + TEST_ASSERT_EQUAL_INT(KAL_OK, kRet); +}; + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal timer is stop input exception + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalTimerDelete002, LEVEL1) +{ + KalErrCode kRet; + KalTimerId id = NULL; + kRet = KalTimerDelete(id); + TEST_ASSERT_EQUAL_INT(KAL_ERR_PARA, kRet); +}; + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal get mem info + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalGetMemInfo001, LEVEL1) +{ + g_kalTestCount = 0; + KalErrCode kRet; + MemInfo *pmemInfo; + pmemInfo = malloc(sizeof(MemInfo)); + if (pmemInfo == NULL) { + TEST_ASSERT_EQUAL_INT(0, 1); + } + kRet = KalGetMemInfo(pmemInfo); + TEST_ASSERT_EQUAL_INT(KAL_OK, kRet); + printf("KalGetMemInfo: pmemInfo total [%d] \r\n", pmemInfo->total); + printf("KalGetMemInfo: pmemInfo used[%d] \r\n", pmemInfo->used); + printf("KalGetMemInfo: pmemInfo free[%d] \r\n", pmemInfo->free); + printf("KalGetMemInfo: pmemInfo freeNodeNum[%d] \r\n", pmemInfo->freeNodeNum); + printf("KalGetMemInfo: pmemInfo usedNodeNum[%d] \r\n", pmemInfo->usedNodeNum); + printf("KalGetMemInfo: pmemInfo maxFreeNodeSize[%d] \r\n", pmemInfo->maxFreeNodeSize); + printf("KalGetMemInfo: pmemInfo mallocFailCount[%d] \r\n", pmemInfo->mallocFailCount); + printf("KalGetMemInfo: pmemInfo peekSize[%d] \r\n", pmemInfo->peekSize); + printf("KalGetMemInfo: pmemInfo totalLmp[%d] \r\n", pmemInfo->totalLmp); + printf("KalGetMemInfo: pmemInfo usedLmp[%d] \r\n", pmemInfo->usedLmp); + printf("KalGetMemInfo: pmemInfo freeLmp[%d] \r\n", pmemInfo->freeLmp); + free(pmemInfo); + pmemInfo = NULL; + +}; + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal ms to tick + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalMsToTick001, LEVEL1) +{ + UINT32 tick = 0; + UINT32 ms = 1; + while (tick < TICK_NUM_10) { + ms = ms * TICK_NUM_10; + tick = KalMsToTick(ms); + printf("KalMsToTick: ms[%d] to tick[%d] \r\n", ms, tick); + } + TEST_ASSERT_GREATER_OR_EQUAL(TICK_NUM_10, tick); + TEST_ASSERT_LESS_THAN_INT(TICK_NUM_1000, tick); +}; + +/** + * @tc.number : SUB_KERNEL_Kal_OPERATION_100 + * @tc.name : kal tick to ms + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KalFuncTestSuite, testKalTickToMs001, LEVEL1) +{ + UINT32 tick = 1; + UINT32 ms = 0; + while (ms < MILLISEC_NUM_10) { + tick = tick * MILLISEC_NUM_10; + ms = KalTickToMs(tick); + printf("KalTickToMs: tick[%d] to ms[%d] \r\n", tick, ms); + } + TEST_ASSERT_GREATER_OR_EQUAL(MILLISEC_NUM_10, ms); + TEST_ASSERT_LESS_THAN_INT(MILLISEC_NUM_1000, ms); +}; + +RUN_TEST_SUITE(KalFuncTestSuite); diff --git a/kernel_lite/math_posix/BUILD.gn b/kernel_lite/math_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..d04a64080506abe59894b07e87a6ce87c7377d20 --- /dev/null +++ b/kernel_lite/math_posix/BUILD.gn @@ -0,0 +1,34 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsMathApiTest") { + suite_name = "acts" + sources = [ + "src/ActsMathApiTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "../utils/", + "../util_datastruct_posix/src", + "src", + ] + + deps = [ + "//test/xts/tools/hcpptest:hcpptest", + ] + + cflags = [ "-Wno-error" ] +} diff --git a/kernel_lite/math_posix/Test.json b/kernel_lite/math_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..1ffe9051cc1693c512e5add9a9c35401ce54fce1 --- /dev/null +++ b/kernel_lite/math_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite posix math api test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsMathApiTest.bin" + } +} \ No newline at end of file diff --git a/kernel_lite/math_posix/src/ActsMathApiTest.cpp b/kernel_lite/math_posix/src/ActsMathApiTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..21acd23b19f8284d0ba0563174b820f78aba4401 --- /dev/null +++ b/kernel_lite/math_posix/src/ActsMathApiTest.cpp @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2020 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 +#include + +#include "gtest/gtest.h" +#include "XtsActsUtil.h" +#include "XtsActsMathApiExpect.h" + +using namespace testing::ext; + +class ActsMathApiTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** +* @tc.number SUB_KERNEL_NDKAPI_MATH_ABS_0100 +* @tc.name test abs api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsMathApiTest, testAbs, TestSize.Level1) { + int returnVal, paraVal; + + paraVal = 3; + returnVal = abs(paraVal); + LogPrint(" abs i:='%d', --> returnVal:='%d'\n", paraVal, returnVal); + EXPECT_EQ(3, returnVal) << "ErrInfo: abs i:='" << paraVal << "', --> returnVal:='" << returnVal << "'"; + + paraVal = -3; + returnVal = abs(paraVal); + LogPrint(" abs i:='%d', --> returnVal:='%d'\n", paraVal, returnVal); + EXPECT_EQ(3, returnVal) << "ErrInfo: abs i:='" << paraVal << "', --> returnVal:='" << returnVal << "'"; + + paraVal = 0; + returnVal = abs(paraVal); + LogPrint(" abs i:='%d', --> returnVal:='%d'\n", paraVal, returnVal); + EXPECT_EQ(0, returnVal) << "ErrInfo: abs i:='" << paraVal << "', --> returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_MATH_DOUBLE_CEIL_0100 +* @tc.name test double ceil api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsMathApiTest, testCeil01, TestSize.Level1) { + double returnVal, paraVal; + + paraVal = 123.45; + returnVal = ceil(paraVal); + EXPECT_EQ(124, returnVal) << "ErrInfo: ceil i:='" << paraVal << "', returnVal:='" << returnVal << "'"; + + paraVal = -5.9; + returnVal = ceil(paraVal); + EXPECT_EQ(-5, returnVal) << "ErrInfo: ceil i:='" << paraVal << "', returnVal:='" << returnVal << "'"; + + paraVal = 0; + returnVal = ceil(paraVal); + EXPECT_EQ(0, returnVal) << "ErrInfo: ceil i:='" << paraVal << "', returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_MATH_FLOAT_CEIL_0100 +* @tc.name test double ceil api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsMathApiTest, testCeil02, TestSize.Level1) { + float returnVal, paraVal; + + paraVal = 123.45; + returnVal = ceilf(paraVal); + EXPECT_EQ(124, returnVal) << "ErrInfo: ceilf paraVal:='" << paraVal << "', returnVal:='" << returnVal << "'"; + + paraVal = -5.9; + returnVal = ceilf(paraVal); + EXPECT_EQ(-5, returnVal) << "ErrInfo: ceilf paraVal:='" << paraVal << "', returnVal:='" << returnVal << "'"; + + paraVal = 0; + returnVal = ceilf(paraVal); + EXPECT_EQ(0, returnVal) << "ErrInfo: ceilf paraVal:='" << paraVal << "', returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_MATH_DOUBLE_CBRT_0100 +* @tc.name test double ceil api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsMathApiTest, testCbrt01, TestSize.Level1) { + double returnVal, paraVal; + + paraVal = 64; + returnVal = cbrt(paraVal); + EXPECT_EQ(4, returnVal) << "ErrInfo: cbrt paraVal:='" << paraVal << "', returnVal:='" << returnVal << "'"; + + paraVal = -125; + returnVal = cbrt(paraVal); + EXPECT_EQ(-5, returnVal) << "ErrInfo: cbrt paraVal:='" << paraVal << "', returnVal:='" << returnVal << "'"; + + paraVal = 0; + returnVal = cbrt(paraVal); + EXPECT_EQ(0, returnVal) << "ErrInfo: cbrt paraVal:='" << paraVal << "', returnVal:='" << returnVal << "'"; + + paraVal = 91.125; + returnVal = cbrt(paraVal); + EXPECT_EQ(4.5, returnVal) << "ErrInfo: cbrt paraVal:='" << paraVal << "', returnVal:='" << returnVal << "'"; +} diff --git a/kernel_lite/math_posix/src/XtsActsMathApiExpect.h b/kernel_lite/math_posix/src/XtsActsMathApiExpect.h new file mode 100755 index 0000000000000000000000000000000000000000..30714cdf0c739f4b67cb2006b4ed1c2554d1692f --- /dev/null +++ b/kernel_lite/math_posix/src/XtsActsMathApiExpect.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2020 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 XTS_ACTS_MATH_API_EXPECT_H +#define XTS_ACTS_MATH_API_EXPECT_H + +#endif \ No newline at end of file diff --git a/kernel_lite/mem_posix/BUILD.gn b/kernel_lite/mem_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..ca51c1a70b96008b32b3bc4e2c8785d1743185a0 --- /dev/null +++ b/kernel_lite/mem_posix/BUILD.gn @@ -0,0 +1,34 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsMemApiTest") { + suite_name = "acts" + sources = [ + "src/ActsMemApiTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "../utils/", + "../util_datastruct_posix/src", + "src", + ] + + deps = [ + "//test/xts/tools/hcpptest:hcpptest", + ] + + cflags = [ "-Wno-error" ] +} diff --git a/kernel_lite/mem_posix/Test.json b/kernel_lite/mem_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..4de6d76c4febb01daaafb76abe4b10eda608fe03 --- /dev/null +++ b/kernel_lite/mem_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite posix mem api test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsMemApiTest.bin" + } +} \ No newline at end of file diff --git a/kernel_lite/mem_posix/src/ActsMemApiTest.cpp b/kernel_lite/mem_posix/src/ActsMemApiTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..c4ef1ee2c0e89d93945cdcfbad127ea256dcd1b9 --- /dev/null +++ b/kernel_lite/mem_posix/src/ActsMemApiTest.cpp @@ -0,0 +1,375 @@ +/* + * Copyright (c) 2020 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 + +#include "gtest/gtest.h" +#include "XtsActsUtil.h" +#include "XtsActsMemApiExpect.h" + +using namespace testing::ext; + +class ActsMemApiTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + errno = 0; + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** +* @tc.number SUB_KERNEL_NDKAPI_MEM_BCMP_0100 +* @tc.name test bcmp api +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsMemApiTest, testMemBcmp_0100, TestSize.Level1) { + char str1[] = "this is string1"; + char str2[] = "this is string2"; + int returnVal; + + returnVal = bcmp(str1, str2, 7); + LogPrint(" bcmp *s1:='%s' *s2:='%s' size:='7', --> returnVal:='%d'\n", str1, str2, returnVal); + EXPECT_EQ(0, returnVal) + << "ErrInfo: bcmp *s1:='" << str1 << "' *s2:='" << str2 + << "' size:='7', --> returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_MEM_BCMP_1000 +* @tc.name test bcmp api NE +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsMemApiTest, testMemBcmp_1000, TestSize.Level1) { + char str1[] = "this is string1"; + char str2[] = "this is string2"; + int returnVal; + + returnVal = bcmp(str1, str2, 15); + LogPrint(" bcmp *s1:='%s' *s2:='%s' size:='15', --> returnVal:='%d'\n", str1, str2, returnVal); + EXPECT_NE(0, returnVal) + << "ErrInfo: bcmp *s1:='" << str1 << "' *s2:='" << str2 + << "' size:='15', --> returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_MEM_BCOPY_0100 +* @tc.name test bcopy api +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsMemApiTest, testMemBcopy_0100, TestSize.Level1) { + char srcStr[] = "this"; + char destStr[] = "00000000"; + int iRtn = 1; + + LogPrint(" bcopy *src:='%s' *dest:='%s', size:='4', \n", srcStr, destStr); + bcopy(srcStr, destStr, 4); + LogPrint(" --> *dest:='%s'\n", destStr); + + for (int iLoop = 0; iLoop < 4; iLoop++) + { + if (srcStr[iLoop] != destStr[iLoop]) { + iRtn = 0; + break; + } + } + + EXPECT_EQ(1, iRtn) + << "ErrInfo: bcopy *src:='" << srcStr << "' *dest:='" + << "' size:='4', --> *dest:='" << destStr << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_MEM_BZERO_0100 +* @tc.name test bzero api +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsMemApiTest, testMemBzero_0100, TestSize.Level1) { + char srcStr[] = "this is string1"; + char destStr[] = "this is string1"; + int iFlag = 1; + + LogPrint(" bzero *s:='%s' size:='4', ", srcStr); + bzero(destStr, 4); + LogPrint("--> afterrun s:='%s', ", destStr); + + for(int iLoop = 0; iLoop < 4; iLoop++) + { + if (destStr[iLoop] != '\0') { + iFlag = 0; + break; + } else { + destStr[iLoop] = '0'; + } + } + LogPrint(" for_print s:='%s'\n", destStr); + + EXPECT_EQ(1, iFlag) + << "ErrInfo: bzero *:='" << srcStr << "' size:='4', --> afterrun s:='" << destStr << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_MEM_MALLOC_USABLE_SIZE_0100 +* @tc.name test malloc_usable_size api +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsMemApiTest, testMallocUsableSize_0100, TestSize.Level1) { + char *pt = nullptr; + size_t size; + + pt = (char *)malloc(128); + if (pt) { + LogPrint(" Mem allocated at: %x\n", pt); + } else { + LogPrint(" No enough Mem!\n"); + } + + size = malloc_usable_size(pt); + LogPrint(" malloc_usable_size *ptr:='%x', --> return size:='%d'\n", pt, size); + + EXPECT_GT(size, 1) + << "ErrInfo: malloc_usable_size *ptr:='" << pt << "', --> return size:='" << size << "'"; + free(pt); +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_MEM_MALLOC_USABLE_SIZE_1000 +* @tc.name test malloc_usable_size api exception null +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsMemApiTest, testMallocUsableSize_1000, TestSize.Level1) { + char *pt = nullptr; + size_t size; + + size = malloc_usable_size(NULL); + LogPrint(" malloc_usable_size *ptr:='NULL', --> return size:='%d'\n", size); + + EXPECT_EQ(size, 0) + << "ErrInfo: malloc_usable_size *ptr:='NULL', --> return size:='" << size << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_MEM_MEMCCPY_0100 +* @tc.name test memccpy api +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsMemApiTest, testMemCcpy_0100, TestSize.Level1) { + char srcStr[] = "this is str1:stop here"; + char destStr[] = "000000000000000000000000"; + char *pt = nullptr; + + LogPrint(" bcopy *dest:='%s' *src:='%s' c:=':' size:='18', \n", destStr, srcStr); + pt = (char *)memccpy(destStr, srcStr, ':', 18); + LogPrint(" --> return pt:='%x', dest:='%s'\n", pt, destStr); + ASSERT_TRUE(pt) + << "ErrInfo: bcopy *dest:='destStr' *src:='" + << srcStr << "' c:=':' size:='18', --> afterrun dest:='" << destStr << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_MEM_MEMCCPY_0200 +* @tc.name test memccpy api not find c +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsMemApiTest, testMemCcpy_0200, TestSize.Level1) { + char srcStr[] = "this is str1:stop here"; + char destStr[] = "000000000000000000000000"; + char *pt = nullptr; + + LogPrint(" bcopy *dest:='%s' *src:='%s' c:=';' size:='18', \n", destStr, srcStr); + pt = (char *)memccpy(destStr, srcStr, ';', 18); + LogPrint(" --> return pt:='%x', *dest:='%s'\n", pt, destStr); + ASSERT_FALSE(pt) + << "ErrInfo: bcopy *dest:='destStr' *src:='" + << srcStr << "' c:=':' size:='18', --> return pt:='" << pt << "', dest:='" << destStr << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_MEM_MEMPCPY_0100 +* @tc.name test mempcpy api +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsMemApiTest, testMempcpy_0100, TestSize.Level1) { + char srcStr[] = "this is str1"; + char destStr[] = "00000000000000000000"; + size_t size; + char *pt = nullptr; + + LogPrint(" mempcpy *dest:='%s' *src:='%s' size:='16',", destStr, srcStr); + pt = (char *)mempcpy(destStr, srcStr, 16); + LogPrint(" --> return pt:='%x', *dest:='%s'\n", pt, destStr); + ASSERT_TRUE(pt) + << "ErrInfo: mempcpy *dest:='destStr' *src:='" + << srcStr << "' size:='16', --> return pt:='" << pt << "', dest:='" << destStr << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_MEM_MEMCHR_0100 +* @tc.name test memchr api +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsMemApiTest, testMemchr_0100, TestSize.Level1) { + char srcStr[] = "this is str a;"; + char *pos = nullptr; + + LogPrint(" memchr *s:='%s' c:='a' size:='14',", srcStr); + pos = (char *)memchr(srcStr, 'a', 14); + LogPrint(" --> return pos:='%x'\n", pos); + + ASSERT_TRUE(pos) + << "ErrInfo: memchr *s:='" << srcStr << "' c:='a' size:='14'," + << " --> return pos:='" << pos << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_MEM_MEMCHR_1000 +* @tc.name test memchr api para len not enough +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsMemApiTest, testMemchr_1000, TestSize.Level1) { + char srcStr[] = "this is str a;"; + char *pos = nullptr; + + LogPrint(" memchr *s:='%s' c:='a' size:='4',", srcStr); + pos = (char *)memchr(srcStr, 'a', 4); + LogPrint(" --> return pos:='%x'\n", pos); + ASSERT_FALSE(pos) + << "ErrInfo: memchr *s:='" << srcStr << "' c:='a' size:='4'," + << " --> return pos:='" << pos << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_MEM_MEMCHR_1100 +* @tc.name test memchr api para c not found +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsMemApiTest, testMemchr_1100, TestSize.Level1) { + char srcStr[] = "this is str a;"; + char *pos = nullptr; + + LogPrint(" memchr *s:='%s' c:='b' size:='14',", srcStr); + pos = (char *)memchr(srcStr, 'b', 14); + LogPrint(" --> return pos:='%x'\n", pos); + ASSERT_FALSE(pos) + << "ErrInfo: memchr *s:='" << srcStr << "' c:='b' size:='14'," + << " --> return pos:='" << pos << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_MEM_MEMMEM_0100 +* @tc.name test memmem api +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsMemApiTest, testMemmem_0100, TestSize.Level1) { + char srcStr[] = "this is str a;"; + char srcSubStr[] = "str"; + char *pos = nullptr; + + LogPrint(" memmem *haystack:='%s' size_haystack:='%d' ", srcStr, strlen(srcStr)); + LogPrint("*needle:='%s' size_needle:='%d',\n", srcSubStr, strlen(srcSubStr)); + pos = (char *)memmem(srcStr, strlen(srcStr), srcSubStr, strlen(srcSubStr)); + LogPrint(" --> return pos:='%x'\n", pos); + + ASSERT_TRUE(pos) + << "ErrInfo: memmem *haystack:='" << srcStr << " size_haystack:='" + << strlen(srcStr) << "' *needle:='" << srcSubStr << "' size_needle:='" << strlen(srcSubStr) + << " --> return pos:='" << pos << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_MEM_MEMMEM_1000 +* @tc.name test memmem api para not found +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsMemApiTest, testMemmem_1000, TestSize.Level1) { + char srcStr[] = "this is str a;"; + char srcSubStr[] = "strb"; + char *pos = nullptr; + + pos = (char *)memmem(srcStr, strlen(srcStr), srcSubStr, strlen(srcSubStr)); + LogPrint(" memmem *haystack:='%s' size_haystack:='%d' ", srcStr, strlen(srcStr)); + LogPrint("*needle:='%s' size_needle:='%d',\n", srcSubStr, strlen(srcSubStr)); + LogPrint(" --> return pos:='%x'\n", pos); + + ASSERT_FALSE(pos) + << "ErrInfo: memmem *haystack:='" << srcStr << " size_haystack:='" + << strlen(srcStr) << "' *needle:='" << srcSubStr << "' size_needle:='" << strlen(srcSubStr) + << " --> return pos:='" << pos << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_MEM_OPEN_MEMSTREAM_0100 +* @tc.name test open_memstream api +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsMemApiTest, testOpenMemStream_0100, TestSize.Level1) { + FILE *memStream; + char *ptr = nullptr; + size_t sizeLoc; + + memStream = open_memstream(&ptr, &sizeLoc); + LogPrint(" open_memstream **ptr:='*ptr' *sizeloc:='*sizeLoc', "); + LogPrint(" --> return memStream:='%x'\n", memStream); + LogPrint(" ptr:='%x', sizeLoc:='%d'\n", ptr, sizeLoc); + + ASSERT_TRUE(memStream) + << "ErrInfo: open_memstream **ptr:='*ptr' *sizeloc:='*sizeLoc', " + << " --> return memStream:='" << memStream << "'"; + + LogPrint(" fprintf(memStream, 'Hello!');\n"); + fprintf(memStream, "Hello!"); + fflush(memStream); + LogPrint(" ptr:='%s', sizeloc:='%zu'\n", ptr, sizeLoc); + + LogPrint(" fclose(memStream);\n"); + fclose(memStream); + LogPrint(" ptr:='%s', sizeloc:='%zu'\n", ptr, sizeLoc); + free(ptr); +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_MEM_GETPAGESIZE_0100 +* @tc.name test getpagesize api +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsMemApiTest, testMemGetpagesize_0100, TestSize.Level1) { + int returnVal; + + returnVal = getpagesize(); + LogPrint(" getpagesize, --> returnVal:='%d'\n", returnVal); + EXPECT_GE(returnVal, 0); + EXPECT_EQ(returnVal, XTS_ACTS_MEM_API_EXPECT_PAGESIZE) + << "ErrInfo: getpagesize, --> returnVal:='" << returnVal << "'"; +} diff --git a/kernel_lite/mem_posix/src/XtsActsMemApiExpect.h b/kernel_lite/mem_posix/src/XtsActsMemApiExpect.h new file mode 100755 index 0000000000000000000000000000000000000000..d3bc78e4f53e819db3fa8e25765053b747cae1ad --- /dev/null +++ b/kernel_lite/mem_posix/src/XtsActsMemApiExpect.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2020 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 XTS_ACTS_MEM_API_EXPECT_H +#define XTS_ACTS_MEM_API_EXPECT_H + +static const int XTS_ACTS_MEM_API_EXPECT_PAGESIZE = 4096; + +#endif \ No newline at end of file diff --git a/kernel_lite/process_posix/BUILD.gn b/kernel_lite/process_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..085c06909b8596a6bd72f558529a6434818f545e --- /dev/null +++ b/kernel_lite/process_posix/BUILD.gn @@ -0,0 +1,40 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsProcessApiTest") { + suite_name = "acts" + sources = [ + "src/ActsProcessApiTest.cpp", + "src/PidTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "../utils/", + "../util_datastruct_posix/src", + "src", + ] + + deps = [ + "//test/xts/tools/hcpptest:hcpptest", + "//test/xts/acts/kernel_lite/utils:libutils" + ] + + cflags = [ "-Wno-error" ] + + defines = [ + "DEBUG", + ] +} diff --git a/kernel_lite/process_posix/Test.json b/kernel_lite/process_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..b86b99ad8fdeae9f052b0c611c6d6c3e5468a6e1 --- /dev/null +++ b/kernel_lite/process_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite posix process api test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsProcessApiTest.bin" + } +} \ No newline at end of file diff --git a/kernel_lite/process_posix/src/ActsProcessApiTest.cpp b/kernel_lite/process_posix/src/ActsProcessApiTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..2bece11178b2374b725f8ca5bbb80c746a152aa9 --- /dev/null +++ b/kernel_lite/process_posix/src/ActsProcessApiTest.cpp @@ -0,0 +1,257 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "XtsActsUtil.h" +#include "XtsActsProcessApiExpect.h" + +using namespace testing::ext; + +class ActsProcessApiTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + errno = 0; + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +jmp_buf g_buf; +void TestLongjmp01(void) +{ + LogPrint(" TestLongjmp() Start\n"); + _longjmp(g_buf, 1); + LogPrint(" TestLongjmp() End\n"); +} + +void TestLongjmp02(void) +{ + LogPrint(" TestLongjmp() Start\n"); + longjmp(g_buf, 1); + LogPrint(" TestLongjmp() End\n"); +} + +static void *ThreadFunc(void* arg) +{ + LogPrint(" This is ThreadFunc()\n"); + return NULL; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_PROCESS_LONGJMP_0100 +* @tc.name test _longjmp api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsProcessApiTest, testLongjmp0100, TestSize.Level1) { + int flagVal = 1; + + if(setjmp(g_buf)) { + LogPrint(" back TestLongjmp()\n"); + flagVal = 0; + } else { + LogPrint(" first time to setjmp\n"); + flagVal = 1; + TestLongjmp01(); + } + + EXPECT_EQ(flagVal, 0) << "ErrInfo: _longjmp fail."; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_PROCESS_LONGJMP_0200 +* @tc.name test longjmp api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsProcessApiTest, testLongjmp0200, TestSize.Level1) { + int flagVal = 1; + + if (setjmp(g_buf)) { + LogPrint(" back TestLongjmp()\n"); + flagVal = 0; + } else { + LogPrint(" first time to setjmp\n"); + flagVal = 1; + TestLongjmp02(); + } + + EXPECT_EQ(flagVal, 0) << "ErrInfo: longjmp fail."; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_PROCESS_SETJMP_0100 +* @tc.name test _setjmp api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsProcessApiTest, testSetjmp0100, TestSize.Level1) { + int returnVal; + + returnVal = _setjmp(g_buf); + LogPrint(" _setjmp env:='struct jmp_buf', --> returnVal:='%d'\n", returnVal); + + if (returnVal != 0) { + LogPrint(" back testLongjmp()\n"); + ASSERT_NE(returnVal, 0) << "ErrInfo: second time _setjmp EQ 0, --> returnVal:='" << returnVal << "'"; + } else { + LogPrint(" first time to setjmp\n"); + ASSERT_EQ(returnVal, 0) << "ErrInfo: first time _setjmp not EQ 0, --> returnVal:='" << returnVal << "'"; + TestLongjmp01(); + } +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_PROCESS_SETJMP_0200 +* @tc.name test setjmp api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsProcessApiTest, testSetjmp0200, TestSize.Level1) { + int returnVal; + + returnVal = setjmp(g_buf); + LogPrint(" setjmp env:='struct jmp_buf', returnVal:='%d'\n", returnVal); + + if(returnVal != 0) { + LogPrint(" back testLongjmp()\n"); + ASSERT_NE(returnVal, 0) << "ErrInfo: second time setjmp EQ 0, --> returnVal:='" << returnVal << "'"; + } else { + LogPrint(" first time to setjmp\n"); + ASSERT_EQ(returnVal, 0) << "ErrInfo: first time setjmp not EQ 0, --> returnVal:='" << returnVal << "'"; + TestLongjmp02(); + } +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_PROCESS_PTHREAD_SETNAME_NP_0100 +* @tc.name test pthread_setname_np api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsProcessApiTest, testPthreadSetnameNp0100, TestSize.Level1) { + pthread_t thisThread; + int returnVal; + + thisThread = pthread_self(); + LogPrint(" pthread_self(), --> return pthread_t:='%u(0x%x)'\n", + (unsigned int)thisThread, (unsigned int)thisThread); + + returnVal = pthread_setname_np(thisThread, "funcThreadName"); + LogPrint(" pthread_setname_np thread:='%u(0x%x)' *name:='funcThreadName', " + "--> returnVal:='%d'\n", thisThread, thisThread, returnVal); + + EXPECT_EQ(returnVal, 0) + << "ErrInfo: pthread_setname_np thread:='" << thisThread + << "(0x" << thisThread << ")' *name:='funcThreadName', " + << "--> returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_PROCESS_PTHREAD_SETNAME_NP_1000 +* @tc.name test pthread_setname_np api para stringlong +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsProcessApiTest, testPthreadSetnameNp1000, TestSize.Level1) { + pthread_t thisThread; + int returnVal; + + thisThread = pthread_self(); + LogPrint(" pthread_self(), --> return pthread_t:='%u(0x%x)'\n", + (unsigned int)thisThread, (unsigned int)thisThread); + + returnVal = pthread_setname_np(thisThread, "funcThreadNamelongName"); + LogPrint(" pthread_setname_np thread:='%u(0x%x)' *name:='funcThreadNamelongName', " + "--> returnVal:='%d'\n", thisThread, thisThread, returnVal); + + EXPECT_NE(returnVal, 0) + << "ErrInfo: pthread_setname_np thread:='" << thisThread + << "(0x" << thisThread << ")' *name:='funcThreadNamelongName'," + << " --> returnVal:='" << returnVal << "'"; + EXPECT_EQ(returnVal, ERANGE) + << "ErrInfo: pthread_setname_np thread:='" << thisThread + << "(0x" << thisThread << ")' *name:='funcThreadNamelongName'," + << " --> returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_PROCESS_PTHREAD_ATTR_GETGUARDSIZE_0100 +* @tc.name test pthread_attr_getguardsize api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsProcessApiTest, testPthreadAttrGetguardsize0100, TestSize.Level1) { + pthread_t newThread; + pthread_attr_t threadAttr = {}; + int returnVal; + + returnVal = pthread_create(&newThread, &threadAttr, ThreadFunc, NULL); + LogPrint(" pthread_create *thread:='&newThread' *attr:='&threadAttr' " + "*start_routine:='ThreadFunc' arg:='NULL', \n"); + LogPrint(" --> returnVal:='%d',newThread:='%u(0x%x)'\n", returnVal, newThread, newThread); + + size_t guardsize; + returnVal = pthread_attr_getguardsize(&threadAttr, &guardsize); + LogPrint(" pthread_attr_getguardsize attr:='&threadAttr' guardsize:='&guardsize'," + " --> returnVal:='%d', guardsize:='%d'\n", returnVal, guardsize); + + EXPECT_EQ(returnVal, 0) + << "ErrInfo: pthread_attr_getguardsize attr:='&threadAttr' guardsize:='&guardsize'," + << " --> returnVal:='" << returnVal << "', guardsize:='" << guardsize << "'"; + + returnVal = pthread_attr_setguardsize(&threadAttr, 4096); + LogPrint(" pthread_attr_setguardsize attr:='&threadAttr' guardsize:='4096'," + " --> returnVal:='%d', guardsize:='%d'\n", returnVal, guardsize); + + returnVal = pthread_attr_getguardsize(&threadAttr, &guardsize); + LogPrint(" pthread_attr_getguardsize attr:='&threadAttr' guardsize:='&guardsize'," + " --> returnVal:='%d', guardsize:='%d'\n", returnVal, guardsize); + + EXPECT_EQ(returnVal, 0) + << "ErrInfo: pthread_attr_getguardsize attr:='&threadAttr' guardsize:='&guardsize'," + << " --> returnVal:='" << returnVal << "', guardsize:='" << guardsize << "'"; + EXPECT_EQ(guardsize, 4096) + << "ErrInfo: pthread_attr_getguardsize attr:='&threadAttr' guardsize:='&guardsize'," + << " --> returnVal:='" << returnVal << "', guardsize:='" << guardsize << "'"; +} diff --git a/kernel_lite/process_posix/src/PidTest.cpp b/kernel_lite/process_posix/src/PidTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..bc09422afd9c16937393138da12542592f2741aa --- /dev/null +++ b/kernel_lite/process_posix/src/PidTest.cpp @@ -0,0 +1,285 @@ +/* + * Copyright (c) 2020 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. + */ + +// tested api in this file: getpid getppid getpgrp setpgrp getpgid setpgid + +#include +#include +#include +#include "log.h" +#include "utils.h" +#include "KernelConstants.h" + +using namespace testing::ext; + +class PidTest : public testing::Test { +protected: + const char* mChildELF = RES_DIR_KERNEL "process/executor"; +}; + +/** + * @tc.number SUB_KERNEL_PM_PID_Getppid_0100 + * @tc.name getpid and getppid test + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(PidTest, testGetPpid, TestSize.Level1) +{ + pid_t parentPid = getpid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + if (pid == 0) { // child + pid_t pPid = getppid(); + if (pPid != parentPid) { + LOG("getppid fail, expect:%d, but get:%d", parentPid, pPid); + exit(1); + } + exit(0); + } else { // parent + Msleep(100); + AssertProcExitedOK(pid); + } +} + +/** + * @tc.number SUB_KERNEL_PM_PID_SetGetPgrp_0100 + * @tc.name setpgrp and getpgrp test + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(PidTest, testSetGetPgrp, TestSize.Level1) +{ + pid_t parentPid = getpid(); + int rt = setpgrp(); + ASSERT_EQ(rt, 0); + + pid_t pgid = getpgrp(); + ASSERT_EQ(pgid, parentPid); + + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + if (pid == 0) { // child + pid_t childPgid = getpgrp(); + if (childPgid != pgid) { + LOG("child getpgrp fail, expect:%d, but get:%d", pgid, childPgid); + exit(1); + } + exit(0); + } else { // parent + Msleep(30); + AssertProcExitedOK(pid); + } +} + +/** + * @tc.number SUB_KERNEL_PM_PID_SetGetPgid_0100 + * @tc.name setpgid and getpgid basic test + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(PidTest, testSetGetPgid, TestSize.Level1) +{ + pid_t parentPid = getpid(); + int rt = setpgid(0, parentPid); + ASSERT_EQ(rt, 0); + rt = setpgid(0, 0); + ASSERT_EQ(rt, 0); + + pid_t pgid = getpgid(0); + ASSERT_EQ(pgid, parentPid); + + pid_t pid1 = fork(); + ASSERT_TRUE(pid1 >= 0) << "======== Fork Error! ========="; + if (pid1 == 0) { // child + pid_t childPgid = getpgid(0); + if (childPgid != pgid) { + LOG("child getpgid fail, expect:%d, but get:%d", pgid, childPgid); + exit(1); + } + Msleep(40); + childPgid = getpgid(0); + pid_t childPid = getpid(); + if (childPgid != childPid) { + LOG("child new pgid check fail, pid=%d, pgid:%d", childPid, childPgid); + exit(1); + } + exit(0); + } else { // parent + Msleep(30); + rt = setpgid(pid1, pid1); + ASSERT_EQ(rt, 0); + pid_t pgid2 = getpgid(pid1); + ASSERT_EQ(pgid2, pid1); + Msleep(50); + AssertProcExitedOK(pid1); + } +} +/** + * @tc.number SUB_KERNEL_PM_PID_SetGetPgid_0200 + * @tc.name setpgid and getpgid test for sibling process + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(PidTest, testSetGetSiblingPgid, TestSize.Level1) +{ + pid_t parentPid = getpid(); + int rt = setpgid(0, parentPid); + ASSERT_EQ(rt, 0); + rt = setpgid(0, 0); + ASSERT_EQ(rt, 0); + pid_t pgid = getpgid(0); + ASSERT_EQ(pgid, parentPid); + + pid_t pid1 = fork(); + ASSERT_TRUE(pid1 >= 0) << "======== Fork Error! ========="; + if (pid1 == 0) { // child1 + Msleep(20); + exit(0); + } else { // parent + pid_t pid2 = fork(); + ASSERT_TRUE(pid2 >= 0) << "======== Fork Error! ========="; + if (pid2 == 0) { // child2 + int exitCode = 0; + pid_t siblingPgid = getpgid(pid1); + if (siblingPgid != parentPid) { + LOG("child2: get sibling pgid fail, rt=%d, errno=%d", siblingPgid, errno); + exitCode = 1; + } + rt = setpgid(pid1, pid1); + if (rt != -1) { + LOG("child2: setpgid for sibling should fail"); + exitCode = 1; + } + if (errno != ESRCH) { + LOG("child2: setpgid errno fail, expected %d, but get %d", ESRCH, errno); + exitCode = 1; + } + exit(exitCode); + } + // parent + Msleep(50); + AssertProcExitedOK(pid1); + AssertProcExitedOK(pid2); + } +} +/** + * @tc.number SUB_KERNEL_PM_PID_SetGetPgid_0300 + * @tc.name setpgid fail test + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(PidTest, testGetpgidFail, TestSize.Level3) +{ + pid_t pgid = getpgid(-1); + EXPECT_EQ(pgid, -1); + EXPECT_EQ(errno, EINVAL); + + pgid = getpgid(-1000001); + EXPECT_EQ(pgid, -1); + EXPECT_EQ(errno, EINVAL); + + pid_t nonExitPid = GetNonExistPid(); // valid but not exist pid + if (nonExitPid != -1) { + pgid = getpgid(nonExitPid); + EXPECT_EQ(pgid, -1); + EXPECT_EQ(errno, ESRCH); + } + + pgid = getpgid(MAX_PROCESS_NUMBER + 1); + EXPECT_EQ(pgid, -1); + EXPECT_EQ(errno, EINVAL); + + pgid = getpgid(100000); + EXPECT_EQ(pgid, -1); + EXPECT_EQ(errno, EINVAL); + + pgid = getpgid(1); + EXPECT_EQ(pgid, 1) << "get init process-groups-ID fail\n"; +} + +/** + * @tc.number SUB_KERNEL_PM_PID_SetGetPgid_0400 + * @tc.name setpgid fail test + * @tc.desc [C- SOFTWARE -0200] + * @tc.size SMALL + * @tc.type FUNC + */ +HWTEST_F(PidTest, testSetpgidFail, TestSize.Level3) +{ + pid_t pid = getpid(); + int rt = setpgrp(); + ASSERT_EQ(rt, 0); + + LOG("invalid pid test..."); + rt = setpgid(-1, 0); + EXPECT_EQ(rt, -1); + EXPECT_EQ(errno, EINVAL); + + rt = setpgid(-1000001, 0); + EXPECT_EQ(rt, -1); + EXPECT_EQ(errno, EINVAL); + + pid_t nonExitPid = GetNonExistPid(); // valid but not exist pid + if (nonExitPid != -1) { + rt = setpgid(nonExitPid, 0); + EXPECT_EQ(rt, -1); + EXPECT_EQ(errno, ESRCH); + } + + rt = setpgid(MAX_PROCESS_NUMBER + 1, 0); + EXPECT_EQ(rt, -1); + EXPECT_EQ(errno, EINVAL); + + rt = setpgid(100000, 0); + EXPECT_EQ(rt, -1); + EXPECT_EQ(errno, EINVAL); + + rt = setpgid(1, pid); // init + EXPECT_EQ(rt, -1); + EXPECT_EQ(errno, EPERM); + + rt = setpgid(2, pid); // kProcess + EXPECT_EQ(rt, -1); + EXPECT_EQ(errno, EPERM); + + LOG("invalid pgid test..."); + rt = setpgid(0, -1); + EXPECT_EQ(rt, -1); + EXPECT_EQ(errno, EINVAL); + + nonExitPid = GetNonExistPid(); // valid but not exist pid + if (nonExitPid != -1) { + rt = setpgid(0, nonExitPid); + EXPECT_EQ(rt, -1); + EXPECT_EQ(errno, EPERM); + } + + rt = setpgid(0, 10001); + EXPECT_EQ(rt, -1); + EXPECT_EQ(errno, EINVAL); + + rt = setpgid(0, 1); // init + EXPECT_EQ(rt, -1); + EXPECT_EQ(errno, EPERM); + + rt = setpgid(0, 2); // kProcess + EXPECT_EQ(rt, -1); + EXPECT_EQ(errno, EPERM); +} diff --git a/kernel_lite/process_posix/src/XtsActsProcessApiExpect.h b/kernel_lite/process_posix/src/XtsActsProcessApiExpect.h new file mode 100755 index 0000000000000000000000000000000000000000..cfe00938cf48c0258829bcfac4cc889beb22ca45 --- /dev/null +++ b/kernel_lite/process_posix/src/XtsActsProcessApiExpect.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2020 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 XTS_ACTS_PROCESS_API_EXPECT_H +#define XTS_ACTS_PROCESS_API_EXPECT_H + +#endif \ No newline at end of file diff --git a/kernel_lite/sched_posix/BUILD.gn b/kernel_lite/sched_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..03ebbc5660ada89db083158e8209435fa4e472e8 --- /dev/null +++ b/kernel_lite/sched_posix/BUILD.gn @@ -0,0 +1,35 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsSchedApiTest") { + suite_name = "acts" + sources = [ + "src/ActsSchedApiTest.cpp", + "src/FuncSchedTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "../utils/", + "../util_datastruct_posix/src", + "src", + ] + + deps = [ + "//test/xts/tools/hcpptest:hcpptest", + ] + + cflags = [ "-Wno-error" ] +} diff --git a/kernel_lite/sched_posix/Test.json b/kernel_lite/sched_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..52391502131ea6e28cbd5cbb1fda0091c6d079c8 --- /dev/null +++ b/kernel_lite/sched_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite posix sched api test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsSchedApiTest.bin" + } +} \ No newline at end of file diff --git a/kernel_lite/sched_posix/src/ActsSchedApiTest.cpp b/kernel_lite/sched_posix/src/ActsSchedApiTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..e84680a4b8998df347c8a3fbb4dcb33fe8a2034e --- /dev/null +++ b/kernel_lite/sched_posix/src/ActsSchedApiTest.cpp @@ -0,0 +1,313 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "XtsActsUtil.h" +#include "XtsActsSchedApiExpect.h" + +using namespace testing::ext; + +class ActsSchedApiTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + errno = 0; + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** +* @tc.number SUB_KERNEL_NDKAPI_SCHED_GETPRIORITY_0100 +* @tc.name test getpriority api +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsSchedApiTest, testGetpriority, TestSize.Level1) { + int which = PRIO_PROCESS; + id_t pid; + int returnPriority; + + pid = getpid(); + LogPrint(" getpid, --> pid:='%d'\n", pid); + + returnPriority = getpriority(which, pid); + LogPrint(" getpriority which:='PRIO_PROCESS' pid:='%d', " + "--> returnPriority:='%d'\n", pid, returnPriority); + EXPECT_GE(returnPriority, XTS_ACTS_SCHED_API_EXPECT_USER_PRIORITY_MIN) + << "ErrInfo: " << "getpriority which:='PRIO_PROCESS' pid:='" + << pid << "', --> returnPriority:='" << returnPriority << "'"; + EXPECT_LE(returnPriority, XTS_ACTS_SCHED_API_EXPECT_USER_PRIORITY_MAX) + << "ErrInfo: " << "getpriority which:='PRIO_PROCESS' pid:='" + << pid << "', --> returnPriority:='" << returnPriority << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_SCHED_SCHED_GET_PRIORITY_MAX_0100 +* @tc.name test sched_get_priority_max api +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsSchedApiTest, testSchedGetPriorityMax, TestSize.Level1) { + int returnPriority; + + returnPriority = sched_get_priority_max(SCHED_FIFO); + LogPrint(" sched_get_priority_max policy:='SCHED_FIFO', --> returnPriority:='%d'\n", returnPriority); + EXPECT_EQ(returnPriority, XTS_ACTS_SCHED_API_EXPECT_USER_PRIORITY_MAX) + << "ErrInfo:" << " sched_get_priority_max policy:='SCHED_FIFO', --> returnPriority:='" + << returnPriority << "'"; + + returnPriority = sched_get_priority_max(SCHED_RR); + LogPrint(" sched_get_priority_max policy:='SCHED_RR', --> returnPriority:='%d'\n", returnPriority); + EXPECT_EQ(returnPriority, XTS_ACTS_SCHED_API_EXPECT_USER_PRIORITY_MAX) + << "ErrInfo:" << " sched_get_priority_max policy:='SCHED_RR', --> returnPriority:='" + << returnPriority << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_SCHED_SCHED_GET_PRIORITY_MIN_0100 +* @tc.name test sched_get_priority_min api +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsSchedApiTest, testSchedGetPriorityMin, TestSize.Level1) { + int returnPriority; + + returnPriority = sched_get_priority_min(SCHED_FIFO); + LogPrint(" sched_get_priority_min policy:='SCHED_FIFO', --> returnPriority:='%d'\n", returnPriority); + EXPECT_EQ(returnPriority, XTS_ACTS_SCHED_API_EXPECT_USER_PRIORITY_MIN) << "ErrInfo: " + << "sched_get_priority_min policy:='SCHED_FIFO', --> returnPriority:='" << returnPriority << "'"; + + returnPriority = sched_get_priority_min(SCHED_RR); + LogPrint(" sched_get_priority_min policy:='SCHED_RR', --> returnPriority:='%d'\n", returnPriority); + EXPECT_EQ(returnPriority, XTS_ACTS_SCHED_API_EXPECT_USER_PRIORITY_MIN) << "ErrInfo: " + << "sched_get_priority_min policy:='SCHED_FIFO', --> returnPriority:='" << returnPriority << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_SCHED_SCHED_GETPARAM_0100 +* @tc.name test sched_getparam api +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsSchedApiTest, testSchedGetParam, TestSize.Level1) { + struct sched_param params; + id_t pid; + int returnVal; + + pid = getpid(); + LogPrint(" getpid, --> pid:='%d'\n", pid); + + returnVal = sched_getparam(pid, ¶ms); + LogPrint(" sched_getparam pid:='%d' ¶ms:='int sched_priority'," + " --> returnVal:='%d', params.sched_priority:='%d'\n", pid, returnVal, params.sched_priority); + EXPECT_EQ(returnVal, 0) + << "ErrInfo: sched_getparam pid:='" << pid + << "' ¶ms:='int sched_priority', --> returnVal:='" << returnVal << "', params.sched_priority:='" + << params.sched_priority <<"'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_SCHED_SCHED_GETSCHEDULER_0100 +* @tc.name test sched_getscheduler api +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsSchedApiTest, testSchedGetScheduler, TestSize.Level1) { + struct sched_param params; + id_t pid; + int returnVal; + + pid = getpid(); + LogPrint(" getpid, --> pid:='%d'\n", pid); + + returnVal = sched_getscheduler(pid); + LogPrint(" sched_getscheduler pid:='%d', --> returnVal:='%d'\n", pid, returnVal); + EXPECT_EQ(returnVal, SCHED_RR) + << "ErrInfo: sched_getscheduler pid:='" << pid + << "', --> returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_SCHED_RR_GET_INTERVAL_0100 +* @tc.name test sched_rr_get_interval api +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsSchedApiTest, testSchedRRGetInterval, TestSize.Level1) { + struct timespec intervalS1; + struct timespec intervalS2; + id_t pid; + int returnVal1 = -1; + int returnVal2 = -1; + intervalS1.tv_sec = -1; + intervalS1.tv_nsec = -1; + intervalS2.tv_sec = -1; + intervalS2.tv_nsec = -1; + + pid = getpid(); + LogPrint(" getpid, --> pid:='%d'\n", pid); + + returnVal1 = sched_rr_get_interval(pid, &intervalS1); + returnVal2 = sched_rr_get_interval(0, &intervalS2); + LogPrint(" sched_rr_get_interval pid:='%d' *ts:='&intervalS1', " + "--> returnVal1:='%d' intervalS1.tv_sec:='%lld', intervalS1.tv_nsec:='%ld'\n", + pid, returnVal1, intervalS1.tv_sec, intervalS1.tv_nsec); + LogPrint(" sched_rr_get_interval pid:='0' *ts:='&intervalS2', " + "--> returnVal2:='%d' intervalS2.tv_sec:='%lld', intervalS2.tv_nsec:='%ld'\n", + returnVal2, intervalS2.tv_sec, intervalS2.tv_nsec); + EXPECT_EQ(returnVal1, returnVal2) + << "ErrInfo: sched_rr_get_interval pid:='" << pid + << ",0' *ts:='&intervalS1,&intervalS2', --> returnVal1:='" << returnVal1 << "' returnVal2:='" + << returnVal2 << "'"; + EXPECT_EQ(intervalS1.tv_sec, intervalS2.tv_sec) + << "ErrInfo: sched_rr_get_interval pid:='" << pid + << ",0' *ts:='&intervalS1,&intervalS2', --> return intervalS1.tv_sec:='" << intervalS1.tv_sec + << "' intervalS2.tv_sec:='" << intervalS2.tv_sec << "'"; + EXPECT_EQ(intervalS1.tv_nsec, intervalS2.tv_nsec) + << "ErrInfo: sched_rr_get_interval pid:='" << pid + << ",0' *ts:='&intervalS1,&intervalS2', --> return intervalS1.tv_nsec:='" << intervalS1.tv_nsec + << "' intervalS2.tv_nsec:='" << intervalS2.tv_nsec << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_SCHED_SCHED_SETPARAM_0100 +* @tc.name test sched_setparam api +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsSchedApiTest, testSchedSetParam, TestSize.Level1) { + struct sched_param params; + id_t pid; + int policy, oldPriority, newPriority, tmpErrno; + int returnVal1, returnVal2, returnVal3; + + pid = getpid(); + LogPrint(" getpid, --> pid:='%d'\n", pid); + + returnVal1 = sched_getparam(pid, ¶ms); + LogPrint(" sched_getparam pid:='%d' ¶ms:='*param', " + "--> returnVal1:='%d', params.sched_priority:='%d'\n", pid, returnVal1, params.sched_priority); + oldPriority = params.sched_priority; + + newPriority = params.sched_priority == XTS_ACTS_SCHED_API_EXPECT_USER_PRIORITY_MIN ? + (params.sched_priority = XTS_ACTS_SCHED_API_EXPECT_USER_PRIORITY_MAX): + (params.sched_priority = XTS_ACTS_SCHED_API_EXPECT_USER_PRIORITY_MIN); + + LogPrint(" newPriority:='%d'\n", newPriority); + + returnVal2 = sched_setparam(pid, ¶ms); + tmpErrno = errno; + LogPrint(" sched_setparam pid:='%d' ¶ms:='*param', " + "--> returnVal2:='%d', params.sched_priority:='%d'\n", pid, returnVal2, params.sched_priority); + newPriority = params.sched_priority; + EXPECT_EQ(returnVal2, 0) << "ErrInfo: sched_setparam pid:='" << pid + << "' ¶ms:='int sched_priority', --> returnVal2:='" << returnVal2 << "', params.sched_priority:='" + << params.sched_priority <<"'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_SCHED_SCHED_SETSCHEDULER_0100 +* @tc.name test sched_setscheduler api +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsSchedApiTest, testSchedSetScheduler, TestSize.Level1) { + struct sched_param params; + int which = PRIO_PROCESS; + id_t pid; + int returnVal, oldPolicy, oldPriority, newPolicy, returnNewPolicy, tmpErrno; + + pid = getpid(); + LogPrint(" getpid, --> pid:='%d'\n", pid); + + oldPolicy = sched_getscheduler(pid); + LogPrint(" sched_getscheduler pid:='%d', --> return oldPolicy:='%d'\n", pid, oldPolicy); + oldPriority = getpriority(which, pid); + LogPrint(" getpriority which:='PRIO_PROCESS' pid:='%d', --> oldPriority:='%d'\n", pid, oldPriority); + + newPolicy = oldPolicy == SCHED_RR ? (newPolicy = SCHED_FIFO) : (newPolicy = SCHED_RR); + LogPrint(" newPolicy:='%d'\n", newPolicy); + + params.sched_priority = XTS_ACTS_SCHED_API_EXPECT_USER_PRIORITY_MIN; + + returnVal = sched_setscheduler(pid, newPolicy, ¶ms); + tmpErrno = errno; + LogPrint(" sched_setscheduler pid:='%d' policy:='%d' params.sched_priority:='%d', " + "--> returnVal:='%d'\n", pid, newPolicy, params.sched_priority, returnVal); + EXPECT_NE(returnVal, -1) + << "ErrInfo: sched_setscheduler pid:='" << pid << "' policy:='" << newPolicy + << "' params.sched_priority:='" << params.sched_priority << "', --> returnVal:='" << returnVal << "'"; + EXPECT_EQ(tmpErrno, 0) + << "ErrInfo: sched_setscheduler pid:='" << pid << "' policy:='" << newPolicy + << "' params.sched_priority:='" << params.sched_priority << "', --> returnVal:='" << returnVal + << "' errno:='" << errno << "'"; + + returnNewPolicy = sched_getscheduler(pid); + LogPrint(" sched_getscheduler pid:='%d', --> returnNewPolicy:='%d'\n", pid, returnNewPolicy); + EXPECT_EQ(returnNewPolicy, newPolicy) + << "ErrInfo: sched_setscheduler pid:='" << pid << "' policy:='" + << newPolicy << "' params.sched_priority:='" << params.sched_priority << "', --> returnNewPolicy:='" + << returnNewPolicy << "'"; + + // teardown + params.sched_priority = oldPriority; + sched_setscheduler(pid, oldPolicy, ¶ms); +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_SCHED_SETPRIORITY_0100 +* @tc.name test setpriority api +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_F(ActsSchedApiTest, testSetpriority, TestSize.Level1) { + int which = PRIO_PROCESS; + id_t pid; + int oldPriority, newPriority, returnVal, tmpErrno; + + pid = getpid(); + LogPrint(" getpid, --> pid:='%d'\n", pid); + + oldPriority = getpriority(which, pid); + LogPrint(" getpriority which:='PRIO_PROCESS' pid:='%d', --> oldPriority:='%d'\n", pid, oldPriority); + + newPriority = oldPriority == XTS_ACTS_SCHED_API_EXPECT_USER_PRIORITY_MAX ? + (newPriority = oldPriority - 1): + (newPriority = oldPriority + 1); + + returnVal = setpriority(which, pid, newPriority); + tmpErrno = errno; + LogPrint(" setpriority which:='PRIO_PROCESS' pid:='%d' priority:='%d', " + "--> returnVal:='%d', errno:='%d'\n", pid, newPriority, returnVal, tmpErrno); + + EXPECT_EQ(returnVal, 0) + << "ErrInfo: setpriority which:='PRIO_PROCESS' pid:='" << pid << "' priority:='" + << newPriority << "', --> returnVal:='" << returnVal << "'"; + EXPECT_EQ(tmpErrno, 0) + << "ErrInfo: setpriority which:='PRIO_PROCESS' pid:='" << pid << "' priority:='" + << newPriority << "', --> returnVal:='" << returnVal << "' errno:='" << tmpErrno << "'"; +} diff --git a/kernel_lite/sched_posix/src/FuncSchedTest.cpp b/kernel_lite/sched_posix/src/FuncSchedTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..3b22db21351991c55b4b1d1778312947355ee5e0 --- /dev/null +++ b/kernel_lite/sched_posix/src/FuncSchedTest.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "XtsActsUtil.h" +#include "XtsActsSchedApiExpect.h" + +using namespace testing::ext; + +class FuncSchedTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + errno = 0; + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +class FuncSchedParaTest : public testing::TestWithParam { +}; + +/** +* @tc.number SUB_KERNEL_PROCESS_PPRIORITY_0100 +* @tc.name test pthread_setschedprio api +* @tc.desc [C- SOFTWARE -0200] +*/ +HWTEST_P(FuncSchedParaTest, testPthreadSetschedprio_0100, TestSize.Level2) { + int newPriority = GetParam(); + int which = PRIO_PROCESS; + id_t pid; + int oldPriority, returnVal, tmpErrno, newPriorityReturn; + + pid = getpid(); + LogPrint(" getpid, --> pid:='%d'\n", pid); + + oldPriority = getpriority(which, pid); + LogPrint(" getpriority which:='PRIO_PROCESS' pid:='%d', --> oldPriority:='%d'\n", pid, oldPriority); + + returnVal = setpriority(which, pid, newPriority); + tmpErrno = errno; + LogPrint(" setpriority which:='PRIO_PROCESS' pid:='%d' priority:='%d', " + "--> returnVal:='%d', errno:='%d'\n", pid, newPriority, returnVal, tmpErrno); + + EXPECT_EQ(returnVal, 0) + << "ErrInfo: setpriority which:='PRIO_PROCESS' pid:='" << pid << "' priority:='" + << newPriority << "', --> returnVal:='" << returnVal << "'"; + EXPECT_EQ(tmpErrno, 0) + << "ErrInfo: setpriority which:='PRIO_PROCESS' pid:='" << pid << "' priority:='" + << newPriority << "', --> returnVal:='" << returnVal << "' errno:='" << tmpErrno << "'"; + + newPriorityReturn = getpriority(which, pid); + LogPrint(" getpriority which:='PRIO_PROCESS' pid:='%d'," + " --> newPriorityReturn:='%d'\n", pid, newPriorityReturn); + + usleep(10); +} + +INSTANTIATE_TEST_CASE_P(FuncSchedTest, FuncSchedParaTest, testing::Range(10, 32)); + diff --git a/kernel_lite/sched_posix/src/XtsActsSchedApiExpect.h b/kernel_lite/sched_posix/src/XtsActsSchedApiExpect.h new file mode 100755 index 0000000000000000000000000000000000000000..048da3c353f9fee522febe47c704dec127ed6408 --- /dev/null +++ b/kernel_lite/sched_posix/src/XtsActsSchedApiExpect.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2020 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 XTS_ACTS_SCHED_API_EXPECT_H +#define XTS_ACTS_SCHED_API_EXPECT_H + +static const int XTS_ACTS_SCHED_API_EXPECT_USER_PRIORITY_MAX = 31; +static const int XTS_ACTS_SCHED_API_EXPECT_USER_PRIORITY_MIN = 10; +static const int XTS_ACTS_SCHED_API_EXPECT_KERNEL_PRIORITY_MAX = 31; +static const int XTS_ACTS_SCHED_API_EXPECT_KERNEL_PRIORITY_MIN = 0; + +#endif \ No newline at end of file diff --git a/kernel_lite/sys_posix/BUILD.gn b/kernel_lite/sys_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..9e4c0a83d0adac3768826729b98fc0f751511db5 --- /dev/null +++ b/kernel_lite/sys_posix/BUILD.gn @@ -0,0 +1,34 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsSysApiTest") { + suite_name = "acts" + sources = [ + "src/ActsSysApiTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "../utils/", + "../util_datastruct_posix/src", + "src", + ] + + deps = [ + "//test/xts/tools/hcpptest:hcpptest", + ] + + cflags = [ "-Wno-error" ] +} diff --git a/kernel_lite/sys_posix/Test.json b/kernel_lite/sys_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..607a2c0406d7f452e5c2e359b1a768aacd1b850f --- /dev/null +++ b/kernel_lite/sys_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite posix sys api test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsSysApiTest.bin" + } +} \ No newline at end of file diff --git a/kernel_lite/sys_posix/src/ActsSysApiTest.cpp b/kernel_lite/sys_posix/src/ActsSysApiTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..1f49b8b085126c2547fa9e132616447ce90817bf --- /dev/null +++ b/kernel_lite/sys_posix/src/ActsSysApiTest.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2020 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 +#include + +#include "gtest/gtest.h" +#include "XtsActsUtil.h" +#include "XtsActsSysApiExpect.h" + +using namespace testing::ext; + +class ActsSysApiTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** +* @tc.number SUB_KERNEL_NDKAPI_SYS_SECUREGETENV_0100 +* @tc.name test secure_getenv api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsSysApiTest, testSecureGetenv_0100, TestSize.Level2) { + char* envPath; + + envPath = secure_getenv("HOME"); + LogPrint(" secure_getenv name:='HOME', --> return envPath:='%s'\n", envPath); + EXPECT_STREQ(envPath, NULL); + + envPath = secure_getenv("INCLUDE"); + LogPrint(" secure_getenv name:='INCLUDE', --> return envPath:='%s'\n", envPath); + EXPECT_STREQ(envPath, NULL); + + envPath = secure_getenv("ROOT"); + LogPrint(" secure_getenv name:='ROOT', --> return envPath:='%s'\n", envPath); + EXPECT_STREQ(envPath, NULL); + + envPath = secure_getenv("USER"); + LogPrint(" secure_getenv name:='USER', --> return envPath:='%s'\n", envPath); + EXPECT_STREQ(envPath, NULL); +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_SYS_SETENV_0100 +* @tc.name test setenv api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsSysApiTest, testSetenv_0100, TestSize.Level2) { + int returnVal; + char srcPara[] = "/bin"; + + char* envSrc; + envSrc = secure_getenv("PATH"); + LogPrint(" secure_getenv name:='PATH', --> return envSrc:='%s'\n", envSrc); + + returnVal = setenv("PATH", srcPara, 1); + LogPrint(" setenv name:='PATH' value:='%s' overwrite:='1', " + " --> returnVal:='%d'\n", srcPara, returnVal); + + char* envDst; + envDst = secure_getenv("PATH"); + LogPrint(" secure_getenv name:='PATH', --> return envDst:='%s'\n", envDst); + EXPECT_STREQ(envDst, srcPara); +} diff --git a/kernel_lite/sys_posix/src/XtsActsSysApiExpect.h b/kernel_lite/sys_posix/src/XtsActsSysApiExpect.h new file mode 100755 index 0000000000000000000000000000000000000000..eb6e6d92c7c9b3a8b936527e8527ff72bd0d584b --- /dev/null +++ b/kernel_lite/sys_posix/src/XtsActsSysApiExpect.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2020 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 XTS_ACTS_SYS_API_EXPECT_H +#define XTS_ACTS_SYS_API_EXPECT_H + +static const char XTS_ACTS_SYS_API_EXPECT_SYSNAME[] = "OHOS"; + +#endif \ No newline at end of file diff --git a/kernel_lite/time_posix/BUILD.gn b/kernel_lite/time_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..6e8e0621e64d9bd9eb4f9208268d397cf0eb5f4b --- /dev/null +++ b/kernel_lite/time_posix/BUILD.gn @@ -0,0 +1,33 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsTimeApiTest") { + suite_name = "acts" + sources = [ + "src/ActsTimeApiTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "../util_datastruct_posix/src", + "src", + ] + + deps = [ + "//test/xts/tools/hcpptest:hcpptest", + ] + + cflags = [ "-Wno-error" ] +} diff --git a/kernel_lite/time_posix/Test.json b/kernel_lite/time_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..28956cb729a9101118c57d8884de0fb4d20d86d2 --- /dev/null +++ b/kernel_lite/time_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite posix time api test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsTimeApiTest.bin" + } +} \ No newline at end of file diff --git a/kernel_lite/time_posix/src/ActsTimeApiTest.cpp b/kernel_lite/time_posix/src/ActsTimeApiTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..88bc083efbe3cad592e052d4f3129abdb3c5a0f4 --- /dev/null +++ b/kernel_lite/time_posix/src/ActsTimeApiTest.cpp @@ -0,0 +1,487 @@ +/* + * Copyright (c) 2020 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 +#include + +#include "gtest/gtest.h" +#include "XtsActsUtil.h" +#include "XtsActsTimeApiExpect.h" + +using namespace testing::ext; + +class ActsTimeApiTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + errno = 0; + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** +* @tc.number SUB_KERNEL_NDKAPI_TIME_CLOCK_GETRES_0100 +* @tc.name test clock_getres api para CLOCK_REALTIME +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsTimeApiTest, testClockGetRes0100, TestSize.Level1) { + struct timespec res; + int returnVal; + + returnVal = clock_getres(CLOCK_REALTIME, &res); + LogPrint(" clock_getres clock_id:='CLOCK_REALTIME=%d' &res:='&res', --> returnVal:='%d', " + "{res.tv_sec:='%lld' res.tv_nsec:='%ld'}\n", CLOCK_REALTIME, returnVal, res.tv_sec, res.tv_nsec); + + EXPECT_EQ(returnVal, 0) + << "ErrInfo: clock_getres clock_id:='CLOCK_REALTIME=" << CLOCK_REALTIME + << "', &res:='&res', --> returnVal:='" << returnVal << "', {res.tv_sec:='" + << res.tv_sec << "' res.tv_nsec:='" << res.tv_sec << "'}"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_TIME_CLOCK_GETRES_0200 +* @tc.name test clock_getres api para CLOCK_MONOTONIC +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsTimeApiTest, testClockGetRes0200, TestSize.Level1) { + struct timespec res; + int returnVal; + + returnVal = clock_getres(CLOCK_MONOTONIC, &res); + LogPrint(" clock_getres clock_id:='CLOCK_MONOTONIC=%d' &res:='&res', --> returnVal:='%d', " + "{res.tv_sec:='%lld' res.tv_nsec:='%ld'}\n", CLOCK_MONOTONIC, returnVal, res.tv_sec, res.tv_nsec); + + EXPECT_EQ(returnVal, 0) + << "ErrInfo: clock_getres clock_id:='CLOCK_MONOTONIC=" << CLOCK_MONOTONIC + << "', &res:='&res', --> returnVal:='" << returnVal << "', {res.tv_sec:='" + << res.tv_sec << "' res.tv_nsec:='" << res.tv_sec << "'}"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_TIME_CLOCK_GETRES_0400 +* @tc.name test clock_getres api para CLOCK_REALTIME_COARSE +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsTimeApiTest, testClockGetRes0400, TestSize.Level1) { + struct timespec res; + int returnVal; + + returnVal = clock_getres(CLOCK_REALTIME_COARSE, &res); + LogPrint(" clock_getres clock_id:='CLOCK_REALTIME_COARSE=%d' &res:='&res', --> returnVal:='%d', " + "{res.tv_sec:='%lld', res.tv_nsec:='%ld'}\n", CLOCK_REALTIME_COARSE, returnVal, res.tv_sec, res.tv_nsec); + + EXPECT_EQ(returnVal, 0) + << "ErrInfo: clock_getres clock_id:='CLOCK_REALTIME_COARSE=" << CLOCK_REALTIME_COARSE + << "', &res:='&res', --> returnVal:='" << returnVal << "', {res.tv_sec:='" + << res.tv_sec << "' res.tv_nsec:='" << res.tv_sec << "'}"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_TIME_CLOCK_GETRES_0500 +* @tc.name test clock_getres api para CLOCK_MONOTONIC_COARSE +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsTimeApiTest, testClockGetRes0500, TestSize.Level1) { + struct timespec res; + int returnVal; + + returnVal = clock_getres(CLOCK_MONOTONIC_COARSE, &res); + LogPrint(" clock_getres clock_id:='CLOCK_MONOTONIC_COARSE=%d' &res:='&res', --> returnVal:='%d', " + "{res.tv_sec:='%lld', res.tv_nsec:='%ld'}\n", CLOCK_MONOTONIC_COARSE, returnVal, res.tv_sec, res.tv_nsec); + + EXPECT_EQ(returnVal, 0) + << "ErrInfo: clock_getres clock_id:='CLOCK_MONOTONIC_COARSE=" << CLOCK_MONOTONIC_COARSE + << "', &res:='&res', --> returnVal:='" << returnVal << "', {res.tv_sec:='" + << res.tv_sec << "' res.tv_nsec:='" << res.tv_sec << "'}"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_TIME_CLOCK_GETRES_1000 +* @tc.name test clock_getres api para CLOCK_PROCESS_CPUTIME_ID not support +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsTimeApiTest, testClockGetRes1000, TestSize.Level1) { + struct timespec res; + int returnVal, thisErrno; + + returnVal = clock_getres(CLOCK_PROCESS_CPUTIME_ID, &res); + thisErrno = errno; + LogPrint(" clock_getres clock_id:='CLOCK_PROCESS_CPUTIME_ID=%d' &res:='&res', --> returnVal:='%d', " + "errno:='%d'\n", CLOCK_PROCESS_CPUTIME_ID, returnVal, thisErrno); + + EXPECT_NE(returnVal, 0) + << "ErrInfo: clock_getres clock_id:='CLOCK_PROCESS_CPUTIME_ID=" << CLOCK_PROCESS_CPUTIME_ID + << "', &res:='&res', --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'"; + EXPECT_EQ(thisErrno, EOPNOTSUPP) + << "ErrInfo: clock_getres clock_id:='" << CLOCK_PROCESS_CPUTIME_ID + << "', &res:='&res', --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'"; + + returnVal = clock_getres(CLOCK_PROCESS_CPUTIME_ID + 30, &res); + thisErrno = errno; + LogPrint(" clock_getres clock_id:='%d' &res:='&res', --> returnVal:='%d', " + "errno:='%d'\n", CLOCK_PROCESS_CPUTIME_ID + 30, returnVal, thisErrno); + + EXPECT_NE(returnVal, 0) + << "ErrInfo: clock_getres clock_id:='" << CLOCK_PROCESS_CPUTIME_ID + 30 + << "', &res:='&res', --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'"; + EXPECT_EQ(thisErrno, EINVAL) + << "ErrInfo: clock_getres clock_id:='" << CLOCK_PROCESS_CPUTIME_ID + 30 + << "', &res:='&res', --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_TIME_CLOCK_GETTIME_0100 +* @tc.name test clock_gettime api para CLOCK_REALTIME +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsTimeApiTest, testClockGetTime0100, TestSize.Level1) { + struct timespec tp; + int returnVal; + tp.tv_sec = 0; + tp.tv_nsec = 0; + + returnVal = clock_gettime(CLOCK_REALTIME, &tp); + LogPrint(" clock_gettime clock_id:='CLOCK_REALTIME=%d' &tp:='&tp', --> returnVal:='%d', " + "{tp.tv_sec:='%lld' tp.tv_nsec:='%ld'}\n", CLOCK_REALTIME, returnVal, tp.tv_sec, tp.tv_nsec); + LogPrint(" time is: %lld.%d\n", tp.tv_sec, tp.tv_nsec); + LogPrint(" sec : %lld, size:%d\n", tp.tv_sec, sizeof(tp.tv_sec)); + LogPrint(" nsec : %ld, size:%d\n", tp.tv_nsec, sizeof(tp.tv_nsec)); + EXPECT_EQ(returnVal, 0) + << "ErrInfo: clock_gettime clock_id:='CLOCK_REALTIME=" << CLOCK_REALTIME + << "', &tp:='&tp', --> returnVal:='" << returnVal << "', {tp.tv_sec:='" + << tp.tv_sec << "' tp.tv_nsec:='" << tp.tv_sec << "'}"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_TIME_CLOCK_GETTIME_0200 +* @tc.name test clock_gettime api para CLOCK_MONOTONIC +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsTimeApiTest, testClockGetTime0200, TestSize.Level1) { + struct timespec tp; + int returnVal; + + returnVal = clock_gettime(CLOCK_MONOTONIC, &tp); + LogPrint(" clock_gettime clock_id:='CLOCK_MONOTONIC=%d' &tp:='&tp', --> returnVal:='%d', " + "{tp.tv_sec:='%lld', tp.tv_nsec:='%ld'}\n", CLOCK_MONOTONIC, returnVal, tp.tv_sec, tp.tv_nsec); + LogPrint(" time is: %lld.%d\n", tp.tv_sec, tp.tv_nsec); + LogPrint(" sec : %lld, size:%d\n", tp.tv_sec, sizeof(tp.tv_sec)); + LogPrint(" nsec : %ld, size:%d\n", tp.tv_nsec, sizeof(tp.tv_nsec)); + EXPECT_EQ(returnVal, 0) + << "ErrInfo: clock_gettime clock_id:='CLOCK_MONOTONIC=" << CLOCK_MONOTONIC + << "', &tp:='&tp', --> returnVal:='" << returnVal << "', {tp.tv_sec:='" + << tp.tv_sec << "' tp.tv_nsec:='" << tp.tv_sec << "'}"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_TIME_CLOCK_GETTIME_0400 +* @tc.name test clock_gettime api para CLOCK_REALTIME_COARSE +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsTimeApiTest, testClockGetTime0400, TestSize.Level1) { + struct timespec tp; + int returnVal; + + returnVal = clock_gettime(CLOCK_REALTIME_COARSE, &tp); + LogPrint(" clock_gettime clock_id:='CLOCK_REALTIME_COARSE=%d' &tp:='&tp', --> returnVal:='%d', " + "{tp.tv_sec:='%lld', tp.tv_nsec:='%ld'}\n", CLOCK_REALTIME_COARSE, returnVal, tp.tv_sec, tp.tv_nsec); + EXPECT_EQ(returnVal, 0) + << "ErrInfo: clock_gettime clock_id:='CLOCK_REALTIME_COARSE=" << CLOCK_REALTIME_COARSE + << "', &tp:='&tp', --> returnVal:='" << returnVal << "', {tp.tv_sec:='" + << tp.tv_sec << "' tp.tv_nsec:='" << tp.tv_sec << "'}"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_TIME_CLOCK_GETTIME_0500 +* @tc.name test clock_gettime api para CLOCK_MONOTONIC_COARSE +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsTimeApiTest, testClockGetTime0500, TestSize.Level1) { + struct timespec tp; + int returnVal; + + returnVal = clock_gettime(CLOCK_MONOTONIC_COARSE, &tp); + LogPrint(" clock_gettime clock_id:='CLOCK_MONOTONIC_COARSE=%d' &tp:='&tp', --> returnVal:='%d', " + "{tp.tv_sec:='%lld', tp.tv_nsec:='%ld'}\n", CLOCK_MONOTONIC_COARSE, returnVal, tp.tv_sec, tp.tv_nsec); + EXPECT_EQ(returnVal, 0) + << "ErrInfo: clock_gettime clock_id:='CLOCK_MONOTONIC_COARSE=" << CLOCK_MONOTONIC_COARSE + << "', &tp:='&tp', --> returnVal:='" << returnVal << "', {tp.tv_sec:='" + << tp.tv_sec << "' tp.tv_nsec:='" << tp.tv_sec << "'}"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_TIME_CLOCK_GETTIME_1000 +* @tc.name test clock_gettime api para CLOCK_PROCESS_CPUTIME_ID not support +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsTimeApiTest, testClockGetTime1000, TestSize.Level1) { + struct timespec tp; + int returnVal, thisErrno; + + returnVal = clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp); + thisErrno = errno; + LogPrint(" clock_gettime clock_id:='CLOCK_PROCESS_CPUTIME_ID=%d' &tp:='&tp', --> returnVal:='%d', " + "errno:='%d'\n", CLOCK_PROCESS_CPUTIME_ID, returnVal, thisErrno); + EXPECT_NE(returnVal, 0) + << "ErrInfo: clock_gettime clock_id:='CLOCK_PROCESS_CPUTIME_ID=" << CLOCK_PROCESS_CPUTIME_ID + << "', &tp:='&tp', --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'"; + EXPECT_EQ(thisErrno, EOPNOTSUPP) + << "ErrInfo: clock_gettime clock_id:='CLOCK_PROCESS_CPUTIME_ID=" << CLOCK_PROCESS_CPUTIME_ID + << "', &tp:='&tp', --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'"; + + returnVal = clock_gettime(CLOCK_PROCESS_CPUTIME_ID + 30, &tp); + thisErrno = errno; + LogPrint(" clock_gettime clock_id:='%d' &tp:='&tp', --> returnVal:='%d', " + "errno:='%d'\n", CLOCK_PROCESS_CPUTIME_ID + 30, returnVal, thisErrno); + EXPECT_NE(returnVal, 0) + << "ErrInfo: clock_gettime clock_id:='" << CLOCK_PROCESS_CPUTIME_ID + 30 + << "', &tp:='&tp', --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'"; + EXPECT_EQ(thisErrno, EINVAL) + << "ErrInfo: clock_gettime clock_id:='" << CLOCK_PROCESS_CPUTIME_ID +30 + << "', &tp:='&tp', --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_TIME_CLOCK_SETTIME_1000 +* @tc.name test clock_settime api para CLOCK_MONOTONIC not support +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsTimeApiTest, testClockSetTime1000, TestSize.Level1) { + struct timespec tp; + int returnVal, thisErrno; + + tp.tv_sec = 1565308800; + tp.tv_nsec = 0; + + returnVal = clock_settime(CLOCK_MONOTONIC, &tp); + thisErrno = errno; + LogPrint(" clock_settime clock_id:='CLOCK_MONOTONIC=%d' {tp.tv_sec:='%lld' tp.tv_nsec:='%ld'} " + "--> returnVal:='%d', errno:='%d'\n", CLOCK_MONOTONIC, tp.tv_sec, tp.tv_nsec, returnVal, thisErrno); + EXPECT_NE(returnVal, 0) + << "ErrInfo: clock_settime clock_id:='CLOCK_MONOTONIC=" << CLOCK_MONOTONIC + << "', {tp.tv_sec:='" << tp.tv_sec << "' tp.tv_nsec:='" << tp.tv_nsec + << "'} --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'"; + EXPECT_EQ(thisErrno, EINVAL) + << "ErrInfo: clock_settime clock_id:='CLOCK_MONOTONIC=" << CLOCK_MONOTONIC + << "', {tp.tv_sec:='" << tp.tv_sec << "' tp.tv_nsec:='" << tp.tv_nsec + << "'} --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_TIME_CLOCK_SETTIME_1100 +* @tc.name test clock_settime api para CLOCK_PROCESS_CPUTIME_ID not support +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsTimeApiTest, testClockSetTime1100, TestSize.Level1) { + struct timespec tp; + int returnVal, thisErrno; + + tp.tv_sec = 1565308800; + tp.tv_nsec = 0; + + returnVal = clock_settime(CLOCK_PROCESS_CPUTIME_ID, &tp); + thisErrno = errno; + LogPrint(" clock_settime clock_id:='CLOCK_PROCESS_CPUTIME_ID=%d' {tp.tv_sec:='%lld' tp.tv_nsec:='%ld'} " + "--> returnVal:='%d', errno:='%d'\n", CLOCK_PROCESS_CPUTIME_ID, tp.tv_sec, tp.tv_nsec, returnVal, thisErrno); + EXPECT_NE(returnVal, 0) + << "ErrInfo: clock_settime clock_id:='CLOCK_PROCESS_CPUTIME_ID=" << CLOCK_PROCESS_CPUTIME_ID + << "', {tp.tv_sec:='" << tp.tv_sec << "' tp.tv_nsec:='" << tp.tv_nsec + << "'} --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'"; + EXPECT_EQ(thisErrno, EOPNOTSUPP) + << "ErrInfo: clock_settime clock_id:='CLOCK_PROCESS_CPUTIME_ID=" << CLOCK_PROCESS_CPUTIME_ID + << "', {tp.tv_sec:='" << tp.tv_sec << "' tp.tv_nsec:='" << tp.tv_nsec + << "'} --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_TIME_CLOCK_SETTIME_1200 +* @tc.name test clock_settime api para CLOCK_REALTIME nsec less than zero +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsTimeApiTest, testClockSetTime1200, TestSize.Level1) { + struct timespec tp; + int returnVal, thisErrno; + + tp.tv_sec = 1565308800; + tp.tv_nsec = -1000; + + returnVal = clock_settime(CLOCK_REALTIME, &tp); + thisErrno = errno; + LogPrint(" clock_settime clock_id:='CLOCK_REALTIME=%d' {tp.tv_sec:='%lld' tp.tv_nsec:='%ld'} " + "--> returnVal:='%d', errno:='%d'\n", CLOCK_REALTIME, tp.tv_sec, tp.tv_nsec, returnVal, thisErrno); + EXPECT_NE(returnVal, 0) + << "ErrInfo: clock_settime clock_id:='CLOCK_REALTIME=" << CLOCK_REALTIME + << "', {tp.tv_sec:='" << tp.tv_sec << "' tp.tv_nsec:='" << tp.tv_nsec + << "'} --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'"; + EXPECT_EQ(thisErrno, EINVAL) + << "ErrInfo: clock_settime clock_id:='CLOCK_REALTIME=" << CLOCK_REALTIME + << "', {tp.tv_sec:='" << tp.tv_sec << "' tp.tv_nsec:='" << tp.tv_nsec + << "'} --> returnVal:='" << returnVal << "', errno:='" << thisErrno << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_TIME_ASCTIME_0100 +* @tc.name test asctime api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsTimeApiTest, testAscTime0100, TestSize.Level1) { + struct tm timeptr; + char *returnStr; + int thisErrno; + + timeptr.tm_sec = 0; + timeptr.tm_min = 10; + timeptr.tm_hour = 10; + timeptr.tm_mday = 9; + timeptr.tm_mon = 7; + timeptr.tm_year = 119; + timeptr.tm_wday = 5; + + returnStr = asctime(&timeptr); + thisErrno = errno; + LogPrint(" asctime &timeptr:='{timeptr.tm_year=%d timeptr.tm_mon=%d timeptr.tm_mday=%d}' " + "--> returnStr:='%s'\n", timeptr.tm_year, timeptr.tm_mon, timeptr.tm_mday, returnStr); + EXPECT_STREQ("Fri Aug 9 10:10:00 2019\n", returnStr) + << "ErrInfo: asctime &timeptr:='{timeptr.tm_year=" << timeptr.tm_year + << " timeptr.tm_mon=" << timeptr.tm_mon << "' timeptr.tm_mday=" << timeptr.tm_mday + << "}' --> returnStr:='" << returnStr << "'"; + EXPECT_EQ(thisErrno, 0) + << "ErrInfo: asctime &timeptr:='{timeptr.tm_year=" << timeptr.tm_year + << " timeptr.tm_mon=" << timeptr.tm_mon << "' timeptr.tm_mday=" << timeptr.tm_mday + << "}' --> returnStr:='" << returnStr << "', errno:='" << thisErrno << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_TIME_CTIME_0100 +* @tc.name test ctime api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsTimeApiTest, testCtime0100, TestSize.Level1) { + time_t curClock; + char *returnStr; + + time(&curClock); + returnStr = ctime(&curClock); + LogPrint(" ctime &clock:='&clock' --> returnStr:='%s'\n", returnStr); + EXPECT_STRNE(NULL, returnStr) + << "ErrInfo: ctime &clock:='&clock' --> returnStr:='" << returnStr << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_TIME_DIFFTIME_0100 +* @tc.name test difftime api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsTimeApiTest, testDiffTime0100, TestSize.Level1) { + time_t timeStart, timeEnd; + double returnVal; + + time(&timeStart); + sleep(1); + time(&timeEnd); + + returnVal = difftime(timeEnd, timeStart); + LogPrint(" difftime timeEnd:='%lld' timeStart:='%lld' " + "--> returnVal:='%f'\n", timeEnd, timeStart, returnVal); + LogPrint(" sizeof timeEnd:='%d' sizeof timeStart:='%d'\n", sizeof(timeEnd), sizeof(timeStart)); + EXPECT_GE(returnVal, 0) + << "ErrInfo: difftime timeEnd:='" << timeEnd << "' timeStart:='" + << timeStart << "' --> returnVal:='" << returnVal << "'"; + EXPECT_LE(returnVal, 2) + << "ErrInfo: difftime timeEnd:='" << timeEnd << "' timeStart:='" + << timeStart << "' --> returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_TIME_TIMEGM_0100 +* @tc.name test timegm api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsTimeApiTest, testTimegm_0100, TestSize.Level1) { + struct tm timeptr; + time_t timeThis; + + timeptr.tm_sec = 0; + timeptr.tm_min = 10; + timeptr.tm_hour = 10; + timeptr.tm_mday = 9; + timeptr.tm_mon = 7; + timeptr.tm_year = 119; + timeptr.tm_wday = 5; + + timeThis = timegm(&timeptr); + LogPrint(" timegm &timeptr:='{timeptr.tm_year=%d timeptr.tm_mon=%d timeptr.tm_mday=%d}' " + "--> return timeThis:='%lld'\n", timeptr.tm_year, timeptr.tm_mon, timeptr.tm_mday, timeThis); + + EXPECT_GE(timeThis, 1) + << "ErrInfo: timegm &timeptr:='{timeptr.tm_year=" << timeptr.tm_year + << " timeptr.tm_mon=" << timeptr.tm_mon << " timeptr.tm_mday=" + << timeptr.tm_mday << "}' --> return timeThis:='" << timeThis << "'"; +} + diff --git a/kernel_lite/time_posix/src/ClockID.h b/kernel_lite/time_posix/src/ClockID.h new file mode 100755 index 0000000000000000000000000000000000000000..90389c0db5565f2d9b3f6a74522a582c5d44579a --- /dev/null +++ b/kernel_lite/time_posix/src/ClockID.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2020 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 TIMER_CLOCK_ID +#define TIMER_CLOCK_ID + +#include + +// defined in musl/include/time.h +static const char* ALL_CLOCKS[CLOCK_TAI + 1] = { + "CLOCK_REALTIME", + "CLOCK_MONOTONIC", + "CLOCK_PROCESS_CPUTIME_ID", + "CLOCK_THREAD_CPUTIME_ID", + "CLOCK_MONOTONIC_RAW", + "CLOCK_REALTIME_COARSE", + "CLOCK_MONOTONIC_COARSE", + "CLOCK_BOOTTIME", + "CLOCK_REALTIME_ALARM", + "CLOCK_BOOTTIME_ALARM", + "CLOCK_SGI_CYCLE", + "CLOCK_TAI", +}; + +static const auto ALL_CLOCK_IDS = testing::Values(CLOCK_REALTIME, CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID, + CLOCK_THREAD_CPUTIME_ID, CLOCK_MONOTONIC_RAW, CLOCK_REALTIME_COARSE, CLOCK_MONOTONIC_COARSE, + CLOCK_BOOTTIME, CLOCK_REALTIME_ALARM, CLOCK_BOOTTIME_ALARM, CLOCK_SGI_CYCLE, CLOCK_TAI); + +static const auto ALL_SUPPORTED_IDS = testing::Values(CLOCK_MONOTONIC, CLOCK_REALTIME, + CLOCK_MONOTONIC_COARSE, CLOCK_REALTIME_COARSE, CLOCK_MONOTONIC_RAW); + +class AllClockIDTest : public testing::TestWithParam { +}; +class SupportedClockIDTest : public testing::TestWithParam { +}; + +#endif \ No newline at end of file diff --git a/kernel_lite/time_posix/src/XtsActsTimeApiExpect.h b/kernel_lite/time_posix/src/XtsActsTimeApiExpect.h new file mode 100755 index 0000000000000000000000000000000000000000..f3957c361b9e5b9a0d98b9fabecca10cfd2b052d --- /dev/null +++ b/kernel_lite/time_posix/src/XtsActsTimeApiExpect.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2020 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 XTS_ACTS_TIME_API_EXPECT_H +#define XTS_ACTS_TIME_API_EXPECT_H + +#endif \ No newline at end of file diff --git a/kernel_lite/util_check_posix/BUILD.gn b/kernel_lite/util_check_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..86bf5acb4c304e0e911213f70d97171b7f50a991 --- /dev/null +++ b/kernel_lite/util_check_posix/BUILD.gn @@ -0,0 +1,33 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsUtilCheckApiTest") { + suite_name = "acts" + sources = [ + "src/ActsUtilCheckApiTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "src", + "../utils/" + ] + + deps = [ + "//test/xts/tools/hcpptest:hcpptest", + ] + + cflags = [ "-Wno-error" ] +} diff --git a/kernel_lite/util_check_posix/Test.json b/kernel_lite/util_check_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..084ab5f44091b47db29448f007928f942a14994d --- /dev/null +++ b/kernel_lite/util_check_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite posix util api test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsUtilCheckApiTest.bin" + } +} \ No newline at end of file diff --git a/kernel_lite/util_check_posix/src/ActsUtilCheckApiTest.cpp b/kernel_lite/util_check_posix/src/ActsUtilCheckApiTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..80446c1a6686c28a00c6e061a10281f5a40e9fc4 --- /dev/null +++ b/kernel_lite/util_check_posix/src/ActsUtilCheckApiTest.cpp @@ -0,0 +1,986 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "log.h" +#include "utils.h" + +using namespace testing::ext; + +class ActsUtilCheckApiTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISALNUM_0100 +* @tc.name test isalnum api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsalnum0100, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = '2'; + returnVal = isalnum(paraVal); + LOGD(" isalnum returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isalnum returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISALNUM_0200 +* @tc.name test isalnum api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsalnum0200, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = 'z'; + returnVal = isalnum(paraVal); + LOGD(" isalnum returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isalnum returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISALNUM_0300 +* @tc.name test isalnum api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsalnum0300, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = 'Z'; + returnVal = isalnum(paraVal); + LOGD(" isalnum returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isalnum returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISALNUM_0400 +* @tc.name test isalnum api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsalnum0400, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = ' '; + returnVal = isalnum(paraVal); + LOGD(" isalnum returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: isalnum returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISALNUM_0500 +* @tc.name test isalnum api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsalnum0500, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = '\n'; + returnVal = isalnum(paraVal); + LOGD(" isalnum returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: isalnum returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISALPHA_1100 +* @tc.name test isalpha api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsalpha1100, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = 'z'; + returnVal = isalpha(paraVal); + LOGD(" isalpha returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isalpha returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISALPHA_1200 +* @tc.name test isalpha api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsalpha1200, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = 'Z'; + returnVal = isalpha(paraVal); + LOGD(" isalpha returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isalpha returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISALPHA_1300 +* @tc.name test isalpha api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsalpha1300, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = ' '; + returnVal = isalpha(paraVal); + LOGD(" isalpha returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: isalpha returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISALPHA_1400 +* @tc.name test isalpha api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsalpha1400, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = '\n'; + returnVal = isalpha(paraVal); + LOGD(" isalpha returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: isalpha returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISASCII_1900 +* @tc.name test isascii api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsascii1900, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = 'z'; + returnVal = isascii(paraVal); + LOGD(" isascii returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isascii returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISASCII_2000 +* @tc.name test isascii api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsascii2000, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = 'Z'; + returnVal = isascii(paraVal); + LOGD(" isascii returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isascii returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISASCII_2100 +* @tc.name test isascii api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsascii2100, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = '~'; + returnVal = isascii(paraVal); + LOGD(" isascii returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isascii returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISASCII_2200 +* @tc.name test isascii api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsascii2200, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = 128; + returnVal = isascii(paraVal); + LOGD(" isascii returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: isascii returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISASTREAM_2300 +* @tc.name test isastream api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsastream2300, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = 128; + returnVal = isastream(paraVal); + LOGD(" isastream returnVal:='%d'\n", returnVal); + ASSERT_TRUE(-1 == returnVal) << "ErrInfo: isastream returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISATTY_2400 +* @tc.name test isatty api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsatty2400, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = 128; + returnVal = isatty(paraVal); + LOGD(" isatty returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: isatty returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISBLANK_2500 +* @tc.name test isblank api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsblank2500, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = ' '; + returnVal = isblank(paraVal); + LOGD(" isblank returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isblank returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISBLANK_2600 +* @tc.name test isblank api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsblank2600, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = 'A'; + returnVal = isblank(paraVal); + LOGD(" isblank returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: isblank returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISCNTRL_2900 +* @tc.name test iscntrl api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIscntrl2900, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = '\n'; + returnVal = iscntrl(paraVal); + LOGD(" iscntrl returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: iscntrl returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISCNTRL_3000 +* @tc.name test iscntrl api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIscntrl3000, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = 'A'; + returnVal = iscntrl(paraVal); + LOGD(" iscntrl returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: iscntrl returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISDIGIT_3300 +* @tc.name test isdigit api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsdigit3300, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = '3'; + returnVal = isdigit(paraVal); + LOGD(" isdigit returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isdigit returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISDIGIT_3400 +* @tc.name test isdigit api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsdigitl3400, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = 'a'; + returnVal = isdigit(paraVal); + LOGD(" isdigit returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: isdigit returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISDIGIT_3500 +* @tc.name test isdigit api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsdigitl3500, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = '\n'; + returnVal = isdigit(paraVal); + LOGD(" isdigit returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: isdigit returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISDIGIT_3600 +* @tc.name test isdigit api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsdigit3600, TestSize.Level1) { + int paraVal; + int returnVal; + + paraVal = ' '; + returnVal = isdigit(paraVal); + LOGD(" isdigit returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: isdigit returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISFINITE_4100 +* @tc.name test isfinite api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsfinite4100, TestSize.Level1) { + double paraVal; + int returnVal; + + paraVal = ' '; + returnVal = isfinite(paraVal); + LOGD(" isfinite returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isfinite returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISFINITE_4200 +* @tc.name test isfinite api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsfinite4200, TestSize.Level1) { + double paraVal; + int returnVal; + + paraVal = 3.1415926; + returnVal = isfinite(paraVal); + LOGD(" isfinite returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isfinite returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISFINITE_4300 +* @tc.name test isfinite api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsfinite4300, TestSize.Level1) { + double paraVal; + int returnVal; + + paraVal = 1.26e3; + returnVal = isfinite(paraVal); + LOGD(" isfinite returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isfinite returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISGRAPH_4400 +* @tc.name test isgraph api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsgraph4400, TestSize.Level1) { + double paraVal; + int returnVal; + + paraVal = 'A'; + returnVal = isgraph(paraVal); + LOGD(" isgraph returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isgraph returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISGRAPH_4500 +* @tc.name test isgraph api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsgraph4500, TestSize.Level1) { + double paraVal; + int returnVal; + + paraVal = 'z'; + returnVal = isgraph(paraVal); + LOGD(" isgraph returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isgraph returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISGRAPH_4600 +* @tc.name test isgraph api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsgraph4600, TestSize.Level1) { + double paraVal; + int returnVal; + + paraVal = '\n'; + returnVal = isgraph(paraVal); + LOGD(" isgraph returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: isgraph returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISGRAPH_4700 +* @tc.name test isgraph api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsgraph4700, TestSize.Level1) { + double paraVal; + int returnVal; + + paraVal = ' '; + returnVal = isgraph(paraVal); + LOGD(" isgraph returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: isgraph returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISGREATER_5200 +* @tc.name test isgreater api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsgreater5200, TestSize.Level1) { + double paraVal1; + double paraVal2; + int returnVal; + + paraVal1 = 1.1; + paraVal2 = 2.1; + returnVal = isgreater(paraVal1, paraVal2); + LOGD(" isgreater returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: isgreater returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISGREATER_5300 +* @tc.name test isgreater api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsgreater5300, TestSize.Level1) { + double paraVal1; + double paraVal2; + int returnVal; + + paraVal1 = 2.1; + paraVal2 = 1.1; + returnVal = isgreater(paraVal1, paraVal2); + LOGD(" isgreater returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isgreater returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISGREATER_5400 +* @tc.name test isgreater api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsgreater5400, TestSize.Level1) { + double paraVal1; + double paraVal2; + int returnVal; + + paraVal1 = 2.1; + paraVal2 = 2.1; + returnVal = isgreater(paraVal1, paraVal2); + LOGD(" isgreater returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: isgreater returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISGREATEREQUAL_5500 +* @tc.name test isgreaterequal api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsgreaterequal5500, TestSize.Level1) { + double paraVal1; + double paraVal2; + int returnVal; + + paraVal1 = 1.1; + paraVal2 = 2.1; + returnVal = isgreaterequal(paraVal1, paraVal2); + LOGD(" isgreaterequal returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: isgreaterequal returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISGREATEREQUAL_5600 +* @tc.name test isgreaterequal api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsgreaterequal5600, TestSize.Level1) { + double paraVal1; + double paraVal2; + int returnVal; + + paraVal1 = 2.1; + paraVal2 = 1.1; + returnVal = isgreaterequal(paraVal1, paraVal2); + LOGD(" isgreaterequal returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isgreaterequal returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISGREATEREQUAL_5700 +* @tc.name test isgreaterequal api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsgreaterequal5700, TestSize.Level1) { + double paraVal1; + double paraVal2; + int returnVal; + + paraVal1 = 2.1; + paraVal2 = 2.1; + returnVal = isgreaterequal(paraVal1, paraVal2); + LOGD(" isgreaterequal returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isgreaterequal returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISINF_5800 +* @tc.name test isinf api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsinf5800, TestSize.Level1) { + double paraVal; + int returnVal; + + paraVal = INFINITY; + returnVal = isinf(paraVal); + LOGD(" isinf returnVal:='%d'\n", returnVal); + ASSERT_TRUE(1 == returnVal) << "ErrInfo: isinf returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISLESSEQUAL_5900 +* @tc.name test islessequal api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIslessequal5900, TestSize.Level1) { + double paraVal1; + double paraVal2; + int returnVal; + + paraVal1 = 1.1; + paraVal2 = 2.1; + returnVal = islessequal(paraVal1, paraVal2); + LOGD(" islessequal returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 != returnVal) << "ErrInfo: islessequal returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISLESSEQUAL_6000 +* @tc.name test islessequal api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIslessequal6000, TestSize.Level1) { + double paraVal1; + double paraVal2; + int returnVal; + + paraVal1 = 2.1; + paraVal2 = 1.1; + returnVal = islessequal(paraVal1, paraVal2); + LOGD(" islessequal returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: islessequal returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISLESSEQUAL_6100 +* @tc.name test islessequal api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIslessequal6100, TestSize.Level1) { + double paraVal1; + double paraVal2; + int returnVal; + + paraVal1 = 2.1; + paraVal2 = 2.1; + returnVal = islessequal(paraVal1, paraVal2); + LOGD(" islessequal returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: islessequal returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISLESSGREATER_6200 +* @tc.name test islessgreater api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIslessgreater6200, TestSize.Level1) { + double paraVal1; + double paraVal2; + int returnVal; + + paraVal1 = 2.1; + paraVal2 = 2.1; + returnVal = islessgreater(paraVal1, paraVal2); + LOGD(" islessgreater returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: islessgreater returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISLESSGREATER_6300 +* @tc.name test islessgreater api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIslessgreater6300, TestSize.Level1) { + double paraVal1; + double paraVal2; + int returnVal; + + paraVal1 = 1.1; + paraVal2 = 2.1; + returnVal = islessgreater(paraVal1, paraVal2); + LOGD(" islessgreater returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: islessgreater returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISLESSGREATER_6400 +* @tc.name test islessgreater api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIslessgreater6400, TestSize.Level1) { + double paraVal1; + double paraVal2; + int returnVal; + + paraVal1 = 3.1; + paraVal2 = 2.1; + returnVal = islessgreater(paraVal1, paraVal2); + LOGD(" islessgreater returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: islessgreater returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISLOWER_6500 +* @tc.name test islower api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIslower6500, TestSize.Level1) { + char paraChar; + int returnVal; + + paraChar = 'A'; + returnVal = islower(paraChar); + LOGD(" islower c:='%c', returnVal:='%c'\n", paraChar, returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: islower c:='" << paraChar << "', returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISLOWER_6600 +* @tc.name test islower api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIslower6600, TestSize.Level1) { + char paraChar; + int returnVal; + + paraChar = 'a'; + returnVal = islower(paraChar); + LOGD(" islower c:='%c', returnVal:='%c'\n", paraChar, returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: islower c:='" << paraChar << "', returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISLOWER_6700 +* @tc.name test islower api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIslower6700, TestSize.Level1) { + char paraChar; + int returnVal; + + paraChar = '5'; + returnVal = islower(paraChar); + LOGD(" islower c:='%c', returnVal:='%c'\n", paraChar, returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: islower c:='" << paraChar << "', returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISLOWER_6800 +* @tc.name test islower api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIslower6800, TestSize.Level1) { + char paraChar; + int returnVal; + + paraChar = ' '; + returnVal = islower(paraChar); + LOGD(" islower c:='%c', returnVal:='%c'\n", paraChar, returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: islower c:='" << paraChar << "', returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISNAN_7300 +* @tc.name test isnan api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsnan7300, TestSize.Level1) { + double paraVal; + int returnVal; + + paraVal = NAN; + returnVal = isnan(paraVal); + LOGD(" isnan returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isnan returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISNORMAL_7400 +* @tc.name test isnormal api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsnormal7400, TestSize.Level1) { + double paraVal; + int returnVal; + + paraVal = FP_NORMAL; + returnVal = isnormal(paraVal); + LOGD(" isnormal returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isnormal returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISNORMAL_7500 +* @tc.name test isnormal api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsnormal7500, TestSize.Level1) { + double paraVal; + int returnVal; + + paraVal = NAN; + returnVal = isnormal(paraVal); + LOGD(" isnormal returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: isnormal returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISNORMAL_7600 +* @tc.name test isnormal api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsnormal7600, TestSize.Level1) { + double paraVal; + int returnVal; + + paraVal = 2.1; + returnVal = isnormal(paraVal); + LOGD(" isnormal returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isnormal returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISPRINT_7700 +* @tc.name test isprint api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsprint7700, TestSize.Level1) { + char paraVal; + int returnVal; + + paraVal = 'a'; + returnVal = isprint(paraVal); + LOGD(" isprint returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isprint returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISPRINT_7800 +* @tc.name test isprint api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsprint7800, TestSize.Level1) { + char paraVal; + int returnVal; + + paraVal = ' '; + returnVal = isprint(paraVal); + LOGD(" isprint returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: isprint returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CHECK_ISPRINT_7900 +* @tc.name test isprint api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilCheckApiTest, testIsprint7900, TestSize.Level1) { + char paraVal; + int returnVal; + + paraVal = '\n'; + returnVal = isprint(paraVal); + LOGD(" isprint returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: isprint returnVal:='" << returnVal << "'"; +} diff --git a/kernel_lite/util_convert_posix/BUILD.gn b/kernel_lite/util_convert_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..27b94b6b019277ca6c9d3f79c61234b30e66c274 --- /dev/null +++ b/kernel_lite/util_convert_posix/BUILD.gn @@ -0,0 +1,33 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsUtilConvertApiTest") { + suite_name = "acts" + sources = [ + "src/ActsUtilConvertApiTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "src", + "../utils/" + ] + + deps = [ + "//test/xts/tools/hcpptest:hcpptest", + ] + + cflags = [ "-Wno-error" ] +} diff --git a/kernel_lite/util_convert_posix/Test.json b/kernel_lite/util_convert_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..ba9154d2e9578f69feddd446ed05f96a00b8ba15 --- /dev/null +++ b/kernel_lite/util_convert_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite posix util api test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsUtilConvertApiTest.bin" + } +} \ No newline at end of file diff --git a/kernel_lite/util_convert_posix/src/ActsUtilConvertApiTest.cpp b/kernel_lite/util_convert_posix/src/ActsUtilConvertApiTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..4a057fc469c951002bfef16a2c97be5860a9f475 --- /dev/null +++ b/kernel_lite/util_convert_posix/src/ActsUtilConvertApiTest.cpp @@ -0,0 +1,687 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "log.h" +#include "utils.h" + +using namespace testing::ext; + +class ActsUtilConvertApiTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_TOLOWER_0100 +* @tc.name test _tolower api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testTolower0100, TestSize.Level1) { + char paraChar; + int returnVal; + + paraChar = 'A'; + returnVal = _tolower(paraChar); + LOGD(" _tolower c:='%c', returnVal:='%c'\n", paraChar, returnVal); + ASSERT_TRUE('a' == returnVal) << "ErrInfo: _tolower returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_TOLOWER_0200 +* @tc.name test _tolower api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testTolower0200, TestSize.Level1) { + char paraChar; + int returnVal; + + paraChar = '5'; + returnVal = _tolower(paraChar); + LOGD(" _tolower c:='%c', returnVal:='%c'\n", paraChar, returnVal); + ASSERT_TRUE('5' == returnVal) << "ErrInfo: _tolower returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_TOLOWER_0300 +* @tc.name test _tolower api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testTolower0300, TestSize.Level1) { + char paraChar; + int returnVal; + + paraChar = 'z'; + returnVal = _tolower(paraChar); + LOGD(" _tolower c:='%c', returnVal:='%c'\n", paraChar, returnVal); + ASSERT_TRUE('z' == returnVal) << "ErrInfo: _tolower returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_TOUPPER_0400 +* @tc.name test _toupper api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testToupper0400, TestSize.Level1) { + char paraChar; + int returnVal; + + paraChar = 'a'; + returnVal = _toupper(paraChar); + LOGD(" _toupper c:='%c', returnVal:='%c'\n", paraChar, returnVal); + ASSERT_TRUE('A' == returnVal) << "ErrInfo: _toupper returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_TOUPPER_0500 +* @tc.name test _toupper api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testToupper0500, TestSize.Level1) { + char paraChar; + int returnVal; + + paraChar = 'Z'; + returnVal = _toupper(paraChar); + LOGD(" _toupper c:='%c', returnVal:='%c'\n", paraChar, returnVal); + ASSERT_TRUE('Z' == returnVal) << "ErrInfo: _toupper returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_ATOF_0600 +* @tc.name test atof api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testAtof0600, TestSize.Level1) { + const char *paraChar = nullptr; + double returnVal; + + paraChar = "abcde"; + returnVal = atof(paraChar); + LOGD(" atof c:='%s', returnVal:='%f'\n", paraChar, returnVal); + ASSERT_TRUE(0.000000 == returnVal) << "ErrInfo: atof returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_ATOF_0700 +* @tc.name test atof api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testAtof0700, TestSize.Level1) { + const char *paraChar = nullptr; + double returnVal; + + paraChar = ""; + returnVal = atof(paraChar); + LOGD(" atof c:='%s', returnVal:='%f'\n", paraChar, returnVal); + ASSERT_TRUE(0.000000 == returnVal) << "ErrInfo: atof returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_ATOF_0800 +* @tc.name test atof api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testAtof0800, TestSize.Level1) { + const char *paraChar = nullptr; + double returnVal; + + paraChar = "12345"; + returnVal = atof(paraChar); + LOGD(" atof c:='%s', returnVal:='%f'\n", paraChar, returnVal); + ASSERT_TRUE(12345.000000 == returnVal) << "ErrInfo: atof returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_ATOL_0900 +* @tc.name test atol api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testAtol0900, TestSize.Level1) { + const char *paraChar = nullptr; + long int returnVal; + + paraChar = "abcde"; + returnVal = atol(paraChar); + LOGD(" atol c:='%s', returnVal:='%ld'\n", paraChar, returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: atol returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_ATOL_1000 +* @tc.name test atol api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testAtol1000, TestSize.Level1) { + const char *paraChar = nullptr; + long int returnVal; + + paraChar = ""; + returnVal = atol(paraChar); + LOGD(" atol c:='%s', returnVal:='%ld'\n", paraChar, returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: atol returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_ATOL_1100 +* @tc.name test atol api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testAtol1100, TestSize.Level1) { + const char *paraChar = nullptr; + long int returnVal; + + paraChar = "12345"; + returnVal = atol(paraChar); + LOGD(" atol c:='%s', returnVal:='%ld'\n", paraChar, returnVal); + ASSERT_TRUE(12345 == returnVal) << "ErrInfo: atol returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_ATOLL_1200 +* @tc.name test atoll api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testAtoll1200, TestSize.Level1) { + const char *paraChar = nullptr; + long long int returnVal; + + paraChar = "abcde"; + returnVal = atoll(paraChar); + LOGD(" atoll c:='%s', returnVal:='%lld'\n", paraChar, returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: atoll returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_ATOLL_1300 +* @tc.name test atoll api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testAtoll1300, TestSize.Level1) { + const char *paraChar = nullptr; + long long int returnVal; + + paraChar = ""; + returnVal = atoll(paraChar); + LOGD(" atoll c:='%s', returnVal:='%lld'\n", paraChar, returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: atoll returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_ATOLL_1400 +* @tc.name test atoll api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testAtoll1400, TestSize.Level1) { + const char *paraChar = nullptr; + long long int returnVal; + + paraChar = "1234567890"; + returnVal = atoll(paraChar); + LOGD(" atoll c:='%s', returnVal:='%lld'\n", paraChar, returnVal); + ASSERT_TRUE(1234567890 == returnVal) << "ErrInfo: atoll returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_ECVT_1500 +* @tc.name test ecvt api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testEcvt1500, TestSize.Level1) { + char *returnVal = nullptr; + double paraValue; + int digitCount; + int paraDec; + int paraSign; + + paraValue = 12345.6789; + digitCount = 10; + returnVal = ecvt(paraValue, digitCount, ¶Dec, ¶Sign); + LOGD(" ecvt paraValue:='%f', digitCount:='%d', paraDec = '%d', paraSign = '%d', returnVal:='%s'\n", + paraValue, digitCount, paraDec, paraSign, returnVal); + ASSERT_TRUE(strcmp(returnVal, "1234567890") == 0 && paraSign == 0 && paraDec == 5) << + "ErrInfo: ecvt returnVal:='" << returnVal << "', paraDec:='" << paraDec << "', paraSign:='" << paraSign << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_ECVT_1600 +* @tc.name test ecvt api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testEcvt1600, TestSize.Level1) { + char *returnVal = nullptr; + double paraValue; + int digitCount; + int paraDec; + int paraSign; + + paraValue = -0.123e4; + digitCount = 5; + returnVal = ecvt(paraValue, digitCount, ¶Dec, ¶Sign); + LOGD(" ecvt paraValue:='%d', digitCount:='%d', paraDec = '%d', paraSign = '%d', returnVal:='%s'\n", + paraValue, digitCount, returnVal, paraDec, paraSign); + ASSERT_TRUE(strcmp(returnVal, "12300") == 0 && paraSign == 1 && paraDec != 0) << + "ErrInfo: ecvt returnVal:='" << returnVal << "', paraDec:='" << paraDec << "', paraSign:='" << paraSign << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_TOASCII_1700 +* @tc.name test toascii api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testToascii1700, TestSize.Level1) { + char paraVal; + int returnVal; + + paraVal = 225; + returnVal = toascii(paraVal); + LOGD(" toascii returnVal:='%d'\n", returnVal); + ASSERT_TRUE(97 == returnVal) << "ErrInfo: toascii returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_TOLOWER_1800 +* @tc.name test tolower api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testTolower1800, TestSize.Level1) { + char paraVal; + int returnVal; + + paraVal = 'A'; + returnVal = tolower(paraVal); + LOGD(" tolower returnVal:='%d'\n", returnVal); + ASSERT_TRUE('a' == returnVal) << "ErrInfo: tolower returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_TOLOWER_1900 +* @tc.name test tolower api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testTolower1900, TestSize.Level1) { + char paraVal; + int returnVal; + + paraVal = 'a'; + returnVal = tolower(paraVal); + LOGD(" tolower returnVal:='%d'\n", returnVal); + ASSERT_TRUE('a' == returnVal) << "ErrInfo: tolower returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_TOUPPER_2200 +* @tc.name test toupper api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testToupper2200, TestSize.Level1) { + char paraVal; + int returnVal; + + paraVal = 'A'; + returnVal = toupper(paraVal); + LOGD(" toupper returnVal:='%d'\n", returnVal); + ASSERT_TRUE('A' == returnVal) << "ErrInfo: toupper returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_TOUPPER_2300 +* @tc.name test toupper api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testToupper2300, TestSize.Level1) { + char paraVal; + int returnVal; + + paraVal = 'a'; + returnVal = toupper(paraVal); + LOGD(" toupper returnVal:='%d'\n", returnVal); + ASSERT_TRUE('A' == returnVal) << "ErrInfo: toupper returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_L64A_2600 +* @tc.name test l64a api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testL64a2600, TestSize.Level1) { + long paraVal; + char *returnVal; + + paraVal = 0; + returnVal = l64a(paraVal); + LOGD(" l64a returnVal:='%s'\n", returnVal); + ASSERT_TRUE(strcmp("", returnVal) == 0) << "ErrInfo: l64a returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_L64A_2700 +* @tc.name test l64a api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testL64a2700, TestSize.Level1) { + long paraVal; + char *returnVal; + + paraVal = 12345; + returnVal = l64a(paraVal); + LOGD(" l64a returnVal:='%s'\n", returnVal); + ASSERT_TRUE(strcmp("t.1", returnVal) == 0) << "ErrInfo: l64a returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_TOWLOWER_2800 +* @tc.name test towlower api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testTowlower2800, TestSize.Level1) { + wint_t wideChar; + wint_t returnVal; + + wideChar = 'A'; + returnVal = towlower(wideChar); + LOGD(" towlower returnVal:='%c'\n", returnVal); + ASSERT_TRUE('a' == returnVal) << "ErrInfo: towlower returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_TOWLOWER_2900 +* @tc.name test towlower api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testTowlower2900, TestSize.Level1) { + wint_t wideChar; + wint_t returnVal; + + wideChar = 'a'; + returnVal = towlower(wideChar); + LOGD(" towlower returnVal:='%c'\n", returnVal); + ASSERT_TRUE('a' == returnVal) << "ErrInfo: towlower returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_TOWUPPER_3200 +* @tc.name test towupper api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testTowupper3200, TestSize.Level1) { + wint_t wideChar; + wint_t returnVal; + + wideChar = 'A'; + returnVal = towupper(wideChar); + LOGD(" towupper returnVal:='%c'\n", returnVal); + ASSERT_TRUE('A' == returnVal) << "ErrInfo: towupper returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_TOWUPPER_3300 +* @tc.name test towupper api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testTowupper3300, TestSize.Level1) { + wint_t wideChar; + wint_t returnVal; + + wideChar = 'a'; + returnVal = towupper(wideChar); + LOGD(" towupper returnVal:='%c'\n", returnVal); + ASSERT_TRUE('A' == returnVal) << "ErrInfo: towupper returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_MBTOWC_3600 +* @tc.name test mbtowc api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testMbtowc3600, TestSize.Level1) { + wchar_t wideChar; + const char *paraStr = "a"; + size_t sizeVal; + int returnVal; + + wideChar = 'a'; + sizeVal = 1; + returnVal = mbtowc(&wideChar, paraStr, sizeVal); + LOGD(" mbtowc returnVal:='%d'\n", returnVal); + ASSERT_TRUE(1 == returnVal && L'a' == wideChar) << "ErrInfo: mbtowc returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_TOWCTRANS_3700 +* @tc.name test towctrans api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testTowctrans3700, TestSize.Level1) { + wint_t wideChar; + wctrans_t paraDesc; + wint_t returnVal; + + wideChar = WEOF; + paraDesc = wctrans("tolower"); + returnVal = towctrans(wideChar, paraDesc); + LOGD(" towctrans returnVal:='%d'\n", returnVal); + ASSERT_TRUE(WEOF == returnVal) << "ErrInfo: towctrans returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_TOWCTRANS_3800 +* @tc.name test towctrans api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testTowctrans3800, TestSize.Level1) { + wint_t wideChar; + wctrans_t paraDesc; + wint_t returnVal; + + wideChar = L'A'; + paraDesc = wctrans("tolower"); + returnVal = towctrans(wideChar, paraDesc); + LOGD(" towctrans returnVal:='%d'\n", returnVal); + ASSERT_TRUE('a' == returnVal) << "ErrInfo: towctrans returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_TOWCTRANS_3900 +* @tc.name test towctrans api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testTowctrans3900, TestSize.Level1) { + wint_t wideChar; + wctrans_t paraDesc; + wint_t returnVal; + + wideChar = L'a'; + paraDesc = wctrans("toupper"); + returnVal = towctrans(wideChar, paraDesc); + LOGD(" towctrans returnVal:='%d'\n", returnVal); + ASSERT_TRUE('A' == returnVal) << "ErrInfo: towctrans returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_WCTOB_4300 +* @tc.name test wctob api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testWctob4300, TestSize.Level1) { + wint_t wideChar; + int returnVal; + + wideChar = L'a'; + returnVal = wctob(wideChar); + LOGD(" wctob returnVal:='%d'\n", returnVal); + ASSERT_TRUE('a' == returnVal) << "ErrInfo: wctob returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_WCTOMB_4400 +* @tc.name test wctomb api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testWctomb4400, TestSize.Level1) { + char paraStr[5]; + wint_t wideChar; + int returnVal; + + wideChar = L'a'; + returnVal = wctomb(paraStr, wideChar); + LOGD(" wctomb returnVal:='%d'\n", returnVal); + ASSERT_TRUE(1 == returnVal && 'a' == paraStr[0]) << "ErrInfo: wctomb returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_MBSTOWCS_4500 +* @tc.name test mbstowcs api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testMbstowcs4500, TestSize.Level1) { + wchar_t paraDest[10]; + const char *paraSrc = "abcde"; + size_t sizeVal = 6; + size_t returnVal; + + returnVal = mbstowcs(paraDest, paraSrc, sizeVal); + LOGD(" mbstowcs returnVal:='%d'\n", returnVal); + ASSERT_TRUE(5 == returnVal && (0 == wcscmp(paraDest, L"abcde"))) + << "ErrInfo: mbstowcs returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_WCSTOMBS_4600 +* @tc.name test wcstombs api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testWcstombs4600, TestSize.Level1) { + char paraDest[10]; + const wchar_t *paraSrc = L"abcde"; + size_t sizeVal = 6; + size_t returnVal; + + returnVal = wcstombs(paraDest, paraSrc, sizeVal); + LOGD(" wcstombs returnVal:='%d'\n", returnVal); + ASSERT_TRUE(5 == returnVal && (0 == strcmp(paraDest, "abcde"))) + << "ErrInfo: wcstombs returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_CONVERT_WCRTOMB_4700 +* @tc.name test wcrtomb api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilConvertApiTest, testWcrtomb4700, TestSize.Level1) { + char paraStr[2]; + wchar_t wideChar; + mbstate_t paraPs; + size_t returnVal; + + wideChar = L'a'; + + returnVal = wcrtomb(paraStr, wideChar, ¶Ps); + LOGD(" wcrtomb returnVal:='%d'\n", returnVal); + ASSERT_TRUE(1 == returnVal && 'a' == paraStr[0]) << "ErrInfo: wcrtomb returnVal:='" << returnVal << "'"; +} \ No newline at end of file diff --git a/kernel_lite/util_datastruct_posix/BUILD.gn b/kernel_lite/util_datastruct_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..0a15c9368e30cd4793508961836ae8c60c729f55 --- /dev/null +++ b/kernel_lite/util_datastruct_posix/BUILD.gn @@ -0,0 +1,33 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsUtilDatastructApiTest") { + suite_name = "acts" + sources = [ + "src/ActsUtilDataStructApiTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "src", + "../utils/" + ] + + deps = [ + "//test/xts/tools/hcpptest:hcpptest", + ] + + cflags = [ "-Wno-error" ] +} diff --git a/kernel_lite/util_datastruct_posix/Test.json b/kernel_lite/util_datastruct_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..17dce9518b02c48eb26cea849943aebd742e7bf7 --- /dev/null +++ b/kernel_lite/util_datastruct_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite posix util api test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsUtilDatastructApiTest.bin" + } +} \ No newline at end of file diff --git a/kernel_lite/util_datastruct_posix/src/ActsUtilDataStructApiTest.cpp b/kernel_lite/util_datastruct_posix/src/ActsUtilDataStructApiTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..c1cb420ab51bb64ade87dab5b12e947b15fb4e82 --- /dev/null +++ b/kernel_lite/util_datastruct_posix/src/ActsUtilDataStructApiTest.cpp @@ -0,0 +1,222 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "log.h" +#include "utils.h" +#include "XtsActsUtil.h" + +using namespace testing::ext; + +class ActsUtilDataStructApiTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** +* @tc.number SUB_KERNEL_UTIL_DATASTRUCT_BSEARCH_0100 +* @tc.name test bsearch api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilDataStructApiTest, testBsearch0100, TestSize.Level1) { + int numArray[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + int *itemPtr = nullptr; + int keyVal; + + keyVal = 5; + itemPtr = (int *)bsearch(&keyVal, numArray, sizeof(numArray) / sizeof(numArray[0]), + sizeof(int), (int (*)(const void *, const void *))NumCompare); + ASSERT_TRUE(&numArray[5] == itemPtr) << "ErrInfo: bsearch returnVal:='" << *itemPtr << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_DATASTRUCT_BSEARCH_0200 +* @tc.name test bsearch api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilDataStructApiTest, testBsearch0200, TestSize.Level1) { + int numArray[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + int *itemPtr = nullptr; + int keyVal; + + keyVal = 10; + itemPtr = (int *)bsearch(&keyVal, numArray, sizeof(numArray) / sizeof(numArray[0]), + sizeof(int), (int (*)(const void *, const void *))NumCompare); + ASSERT_TRUE(nullptr == itemPtr) << "ErrInfo: bsearch returnVal:='" << *itemPtr << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_DATASTRUCT_HCREATE_0300 +* @tc.name test hcreate api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilDataStructApiTest, testHcreate0300, TestSize.Level1) { + int createResult; + size_t netVal = 10; + ENTRY item; + ENTRY *searchResult = nullptr; + char hashKey[10] = "key1"; + char hashValue[10] = "value1"; + + createResult = hcreate(netVal); + LOGD(" hcreate createResult:='%d'\n", createResult); + ASSERT_TRUE(createResult != 0) << "ErrInfo: hcreate returnVal:='" << createResult << "'"; + + item.key = hashKey; + item.data = hashValue; + + searchResult = hsearch(item, ENTER); + ASSERT_TRUE(searchResult != nullptr) << "ErrInfo: hsearch searchResult:='" << searchResult << "'"; + + item.key = hashKey; + searchResult = hsearch(item, FIND); + LOGD(" hsearch searchResult->data:='%s'\n", searchResult->data); + ASSERT_TRUE(searchResult != nullptr && strcmp((const char *)searchResult->data, "value1") == 0) + << "ErrInfo: hsearch searchResult->data:='" << searchResult->data << "'"; + + hdestroy(); +} + +/** +* @tc.number SUB_KERNEL_UTIL_DATASTRUCT_HCREATE_0400 +* @tc.name test hcreate api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilDataStructApiTest, testHcreate0400, TestSize.Level1) { + int createResult; + size_t netVal = 10; + ENTRY item; + ENTRY *searchResult = nullptr; + char hashKey[10] = "key1"; + + createResult = hcreate(netVal); + LOGD(" hcreate createResult:='%d'\n", createResult); + ASSERT_TRUE(createResult != 0) << "ErrInfo: hcreate returnVal:='" << createResult << "'"; + + item.key = hashKey; + searchResult = hsearch(item, FIND); + ASSERT_TRUE(searchResult == nullptr) + << "ErrInfo: hsearch searchResult:='" << searchResult << "'"; + + hdestroy(); +} + +/** +* @tc.number SUB_KERNEL_UTIL_DATASTRUCT_HCREATE_R_0500 +* @tc.name test hcreate_r api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilDataStructApiTest, testHcreateR0500, TestSize.Level1) { + int createResult; + int returnVal = 0; + size_t netVal = 10; + ENTRY item; + ENTRY *searchResult = nullptr; + char hashKey[10] = "key1"; + char hashValue[10] = "value1"; + struct hsearch_data hTab; + + createResult = hcreate_r(netVal, &hTab); + LOGD(" hcreate_r createResult:='%d'\n", createResult); + ASSERT_TRUE(createResult != 0) << "ErrInfo: hcreate_r returnVal:='" << createResult << "'"; + + item.key = hashKey; + item.data = hashValue; + + returnVal = hsearch_r(item, ENTER, &searchResult, &hTab); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: hsearch_r searchResult:='" << searchResult << "'"; + + item.key = hashKey; + returnVal = hsearch_r(item, FIND, &searchResult, &hTab); + LOGD(" hsearch_r searchResult->data:='%s'\n", searchResult->data); + ASSERT_TRUE(returnVal != 0 && strcmp((const char *)searchResult->data, "value1") == 0) + << "ErrInfo: hsearch_r searchResult->data:='" << searchResult->data << "'"; + + hdestroy_r(&hTab); +} + +/** +* @tc.number SUB_KERNEL_UTIL_DATASTRUCT_HCREATE_R_0600 +* @tc.name test hcreate_r api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilDataStructApiTest, testHcreateR0600, TestSize.Level1) { + int createResult; + int returnVal = 0; + size_t netVal = 10; + ENTRY item; + ENTRY *searchResult = nullptr; + char hashKey[10] = "key1"; + struct hsearch_data hTab; + + createResult = hcreate_r(netVal, &hTab); + LOGD(" hcreate_r createResult:='%d'\n", createResult); + ASSERT_TRUE(createResult != 0) << "ErrInfo: hcreate_r returnVal:='" << createResult << "'"; + + item.key = hashKey; + returnVal = hsearch_r(item, FIND, &searchResult, &hTab); + LOGD(" hsearch_r searchResult='%s'\n", searchResult); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: hsearch_r searchResult:='" << searchResult << "'"; + + hdestroy_r(&hTab); +} + +/** +* @tc.number SUB_KERNEL_UTIL_DATASTRUCT_INITSTATE_0700 +* @tc.name test initstate api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilDataStructApiTest, testInitstate0700, TestSize.Level1) { + int seed = 8; + char *returnVal = nullptr; + char state[] = {'1', '2', '3', '4', '5', '6', '7', '8'}; + size_t num = 8; + + returnVal = initstate(seed, state, num); + LOGD(" initstate returnVal:='%x'\n", returnVal); + ASSERT_TRUE(returnVal != nullptr) << "ErrInfo: initstate returnVal:='" << returnVal << "'"; +} \ No newline at end of file diff --git a/kernel_lite/util_datastruct_posix/src/XtsActsUtil.h b/kernel_lite/util_datastruct_posix/src/XtsActsUtil.h new file mode 100755 index 0000000000000000000000000000000000000000..8541b50e2b051f789b48611672e81d378d5c89a7 --- /dev/null +++ b/kernel_lite/util_datastruct_posix/src/XtsActsUtil.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2020 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 XTS_ACTS_UTIL_H +#define XTS_ACTS_UTIL_H + +#include +#include + +// 0 not print, 1 print +static int g_xtsDebugLevel = 1; + +static int LogPrint(const char *format, ...) +{ + int ret = 0; + if (g_xtsDebugLevel == 0) { + } else { + va_list ap; + va_start(ap, format); + ret = vfprintf(stdout, format, ap); + va_end(ap); + } + return ret; +} + +static int NumCompare(const void *p1, const void *p2) +{ + return ((*(int *)p1) - (*(int *)p2)); +} + +#endif \ No newline at end of file diff --git a/kernel_lite/util_math_posix/BUILD.gn b/kernel_lite/util_math_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..a701ed76c77b75c15786001cf024fa2a1ed2dda6 --- /dev/null +++ b/kernel_lite/util_math_posix/BUILD.gn @@ -0,0 +1,33 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsUtilMathApiTest") { + suite_name = "acts" + sources = [ + "src/ActsUtilMathApiTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "src", + "../utils/" + ] + + deps = [ + "//test/xts/tools/hcpptest:hcpptest", + ] + + cflags = [ "-Wno-error" ] +} diff --git a/kernel_lite/util_math_posix/Test.json b/kernel_lite/util_math_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..b4be09ad7d472ecf1e5c348c8498fbc21f78b89c --- /dev/null +++ b/kernel_lite/util_math_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite posix util api test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsUtilMathApiTest.bin" + } +} \ No newline at end of file diff --git a/kernel_lite/util_math_posix/src/ActsUtilMathApiTest.cpp b/kernel_lite/util_math_posix/src/ActsUtilMathApiTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..502ba5e069ad2eecc25a3a319e7f94b7dda79b87 --- /dev/null +++ b/kernel_lite/util_math_posix/src/ActsUtilMathApiTest.cpp @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "log.h" +#include "utils.h" + +using namespace testing::ext; + +class ActsUtilMathApiTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** +* @tc.number SUB_KERNEL_UTIL_MATH_DRAND48_0100 +* @tc.name test drand48 api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilMathApiTest, testDrand480100, TestSize.Level1) { + double returnVal; + long seedVal; + + seedVal = 12345; + srand48(seedVal); + returnVal = drand48(); + LOGD(" drand48 returnVal:='%f'\n", returnVal); + ASSERT_TRUE(returnVal >= 0.0 && returnVal < 1.0) << "ErrInfo: drand48 returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_MATH_ERAND48_0200 +* @tc.name test erand48 api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilMathApiTest, testErand480200, TestSize.Level1) { + double returnVal; + unsigned short xsubi[3] = {0, 1, 2}; + + returnVal = erand48(xsubi); + LOGD(" erand48 returnVal:='%f'\n", returnVal); + ASSERT_TRUE(returnVal >= 0.0 && returnVal < 1.0) << "ErrInfo: erand48 returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_MATH_JRAND48_0300 +* @tc.name test jrand48 api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilMathApiTest, testJrand480300, TestSize.Level1) { + long returnVal; + unsigned short xsubi[3] = {0, 1, 2}; + + returnVal = jrand48(xsubi); + LOGD(" jrand48 returnVal:='%ld'\n", returnVal); + ASSERT_TRUE(returnVal >= -2147483648) + << "ErrInfo: jrand48 returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_MATH_MAND48_0400 +* @tc.name test mrand48 api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilMathApiTest, testMrand480400, TestSize.Level1) { + long returnVal; + unsigned short paraVal[7] = {0, 1, 2, 3, 4, 5, 6}; + + lcong48(paraVal); + returnVal = mrand48(); + LOGD(" mrand48 returnVal:='%ld'\n", returnVal); + ASSERT_TRUE(returnVal >= -2147483648) + << "ErrInfo: mrand48 returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_MATH_LAND48_0500 +* @tc.name test lrand48 api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilMathApiTest, testLrand480500, TestSize.Level1) { + long returnVal; + unsigned short paraVal[3] = {0, 1, 2}; + + seed48(paraVal); + returnVal = lrand48(); + LOGD(" lrand48 returnVal:='%ld'\n", returnVal); + ASSERT_TRUE(returnVal >= 0) << "ErrInfo: lrand48 returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_MATH_NRAND48_0700 +* @tc.name test nrand48 api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilMathApiTest, testNrand480700, TestSize.Level1) { + long returnVal; + unsigned short paraVal[3] = {0, 1, 2}; + + returnVal = nrand48(paraVal); + LOGD(" nrand48 returnVal:='%ld'\n", returnVal); + ASSERT_TRUE(returnVal >= 0) << "ErrInfo: nrand48 returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_MATH_RAND_R_0800 +* @tc.name test rand_r api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilMathApiTest, testNrand480800, TestSize.Level1) { + int returnVal; + unsigned int paraVal; + + returnVal = rand_r(¶Val); + LOGD(" rand_r returnVal:='%ld'\n", returnVal); + ASSERT_TRUE(returnVal >= 0 && returnVal <= RAND_MAX) << "ErrInfo: rand_r returnVal:='" << returnVal << "'"; +} \ No newline at end of file diff --git a/kernel_lite/util_msg_posix/BUILD.gn b/kernel_lite/util_msg_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..1bf837bec14b7e5e3073de03933756ecfa61cb1d --- /dev/null +++ b/kernel_lite/util_msg_posix/BUILD.gn @@ -0,0 +1,33 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsUtilMsgApiTest") { + suite_name = "acts" + sources = [ + "src/ActsUtilMsgApiTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "src", + "../utils/" + ] + + deps = [ + "//test/xts/tools/hcpptest:hcpptest", + ] + + cflags = [ "-Wno-error" ] +} diff --git a/kernel_lite/util_msg_posix/Test.json b/kernel_lite/util_msg_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..7b67c5d53dd864604b678c39955323e7cba62f18 --- /dev/null +++ b/kernel_lite/util_msg_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite posix util api test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsUtilMsgApiTest.bin" + } +} \ No newline at end of file diff --git a/kernel_lite/util_msg_posix/src/ActsUtilMsgApiTest.cpp b/kernel_lite/util_msg_posix/src/ActsUtilMsgApiTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..17b363e8b7df606b4e2244bee86291e0229292b6 --- /dev/null +++ b/kernel_lite/util_msg_posix/src/ActsUtilMsgApiTest.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "log.h" +#include "utils.h" + +using namespace testing::ext; + +class ActsUtilMsgApiTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** +* @tc.number SUB_KERNEL_UTIL_MSG_FMTMSG_0100 +* @tc.name test fmtmsg api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilMsgApiTest, testFmtmsg0100, TestSize.Level1) { + int returnVal = 0; + + returnVal = fmtmsg(MM_PRINT, "test fmtmsg:", MM_INFO, "hello fmtmsg", "call it", "fmtmsg"); + LOGD(" fmtmsg returnVal:='%d'\n", returnVal); + ASSERT_TRUE(MM_OK == returnVal) << "ErrInfo: fmtmsg returnVal:='" << returnVal << "'"; +} \ No newline at end of file diff --git a/kernel_lite/util_string_posix/BUILD.gn b/kernel_lite/util_string_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..40435a77dc990a60a058316b1aee026f9c3b6fb7 --- /dev/null +++ b/kernel_lite/util_string_posix/BUILD.gn @@ -0,0 +1,33 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsUtilStringApiTest") { + suite_name = "acts" + sources = [ + "src/ActsUtilStringOperApiTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "src", + "../utils/" + ] + + deps = [ + "//test/xts/tools/hcpptest:hcpptest", + ] + + cflags = [ "-Wno-error" ] +} diff --git a/kernel_lite/util_string_posix/Test.json b/kernel_lite/util_string_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..51d1029a58b62c33baa21cc83f422308729020a0 --- /dev/null +++ b/kernel_lite/util_string_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite posix util api test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsUtilStringApiTest.bin" + } +} \ No newline at end of file diff --git a/kernel_lite/util_string_posix/src/ActsUtilStringOperApiTest.cpp b/kernel_lite/util_string_posix/src/ActsUtilStringOperApiTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..f3e886b501f533e240d010672bb51cb43298ce3e --- /dev/null +++ b/kernel_lite/util_string_posix/src/ActsUtilStringOperApiTest.cpp @@ -0,0 +1,230 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "log.h" +#include "utils.h" + +using namespace testing::ext; + +class ActsUtilStringOperApiTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** +* @tc.number SUB_KERNEL_UTIL_STRINGOPER_FFS_0100 +* @tc.name test fss api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilStringOperApiTest, testFss0100, TestSize.Level1) { + int paraValue; + int returnVal; + + paraValue = 1; + returnVal = ffs(paraValue); + LOGD(" ffs returnVal:='%d'\n", returnVal); + ASSERT_TRUE(1 == returnVal) << "ErrInfo: ffs returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_STRINGOPER_FFS_0200 +* @tc.name test fss api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilStringOperApiTest, testFss0200, TestSize.Level1) { + int paraValue; + int returnVal; + + paraValue = 0; + returnVal = ffs(paraValue); + LOGD(" ffs returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: ffs returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_STRINGOPER_FFS_0300 +* @tc.name test fss api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilStringOperApiTest, testFss0300, TestSize.Level1) { + int paraValue; + int returnVal; + + paraValue = 0x8000; + returnVal = ffs(paraValue); + LOGD(" ffs returnVal:='%d'\n", returnVal); + ASSERT_TRUE(16 == returnVal) << "ErrInfo: ffs returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_STRINGOPER_FFSL_0400 +* @tc.name test fssl api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilStringOperApiTest, testFssl0400, TestSize.Level1) { + long int paraValue; + int returnVal; + + paraValue = 1; + returnVal = ffsl(paraValue); + LOGD(" ffsl returnVal:='%d'\n", returnVal); + ASSERT_TRUE(1 == returnVal) << "ErrInfo: ffsl returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UUTIL_STRINGOPER_FFSL_0500 +* @tc.name test fssl api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilStringOperApiTest, testFssl0500, TestSize.Level1) { + long int paraValue; + int returnVal; + + paraValue = 0; + returnVal = ffsl(paraValue); + LOGD(" ffsl returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: ffsl returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_STRINGOPER_FFSL_0600 +* @tc.name test fssl api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilStringOperApiTest, testFssl0600, TestSize.Level1) { + long int paraValue; + int returnVal; + + paraValue = 0x8000; + returnVal = ffsl(paraValue); + LOGD(" ffsl returnVal:='%d'\n", returnVal); + ASSERT_TRUE(16 == returnVal) << "ErrInfo: ffsl returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_STRINGOPER_FFSLL_0700 +* @tc.name test fssll api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilStringOperApiTest, testFssll0700, TestSize.Level1) { + long long int paraValue; + int returnVal; + + paraValue = 1; + returnVal = ffsll(paraValue); + LOGD(" ffsll returnVal:='%d'\n", returnVal); + ASSERT_TRUE(1 == returnVal) << "ErrInfo: ffsll returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_STRINGOPER_FFSLL_0800 +* @tc.name test fssll api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilStringOperApiTest, testFssll0800, TestSize.Level1) { + long long int paraValue; + int returnVal; + + paraValue = 0; + returnVal = ffsll(paraValue); + LOGD(" ffsll returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: ffsll returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_STRINGOPER_FFSLL_0900 +* @tc.name test fssll api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilStringOperApiTest, testFssll0900, TestSize.Level1) { + long long int paraValue; + int returnVal; + + paraValue = 0x800000000000; + returnVal = ffsll(paraValue); + LOGD(" ffsll returnVal:='%d'\n", returnVal); + ASSERT_TRUE(48 == returnVal) << "ErrInfo: ffsll returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCWIDTH_1100 +* @tc.name test wcwidth api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilStringOperApiTest, testWcwidth1100, TestSize.Level1) { + wchar_t wideChar; + int returnVal; + + wideChar = 'A'; + returnVal = wcwidth(wideChar); + LOGD(" wcwidth returnVal:='%d'\n", returnVal); + ASSERT_TRUE(1 == returnVal) << "ErrInfo: wcwidth returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCTYPE_1200 +* @tc.name test wctype api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilStringOperApiTest, testWctype1200, TestSize.Level1) { + const char *paraVal = "alnum"; + wctype_t returnVal; + + returnVal = wctype(paraVal); + LOGD(" wcwidth returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: wcwidth returnVal:='" << returnVal << "'"; +} \ No newline at end of file diff --git a/kernel_lite/util_widecheck_posix/BUILD.gn b/kernel_lite/util_widecheck_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..23804f431993d8e0908b203dad73dfa1f5079106 --- /dev/null +++ b/kernel_lite/util_widecheck_posix/BUILD.gn @@ -0,0 +1,33 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsUtilWideCheckApiTest") { + suite_name = "acts" + sources = [ + "src/ActsUtilWideCheckApiTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "src", + "../utils/" + ] + + deps = [ + "//test/xts/tools/hcpptest:hcpptest", + ] + + cflags = [ "-Wno-error" ] +} diff --git a/kernel_lite/util_widecheck_posix/Test.json b/kernel_lite/util_widecheck_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..4647b726d9c9ddb8e8e4938c1cfee0201fb70ec8 --- /dev/null +++ b/kernel_lite/util_widecheck_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite posix util api test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsUtilWideCheckApiTest.bin" + } +} \ No newline at end of file diff --git a/kernel_lite/util_widecheck_posix/src/ActsUtilWideCheckApiTest.cpp b/kernel_lite/util_widecheck_posix/src/ActsUtilWideCheckApiTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..dcbcc52443ae39bacec77e9dd869e3d1fa08ec05 --- /dev/null +++ b/kernel_lite/util_widecheck_posix/src/ActsUtilWideCheckApiTest.cpp @@ -0,0 +1,505 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "log.h" +#include "utils.h" + +using namespace testing::ext; + +class ActsUtilWideCheckApiTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) + { + } + // Testcase setup + virtual void SetUp() + { + } + // Testcase teardown + virtual void TearDown() + { + } +}; + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWALNUM_0100 +* @tc.name test iswalnum api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswalnum0100, TestSize.Level1) { + wint_t paraVal; + int returnVal; + + paraVal = '2'; + returnVal = iswalnum(paraVal); + LOGD(" iswalnum returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: iswalnum returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWALNUM_0200 +* @tc.name test iswalnum api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswalnum0200, TestSize.Level1) { + wint_t paraVal; + int returnVal; + + paraVal = 'Z'; + returnVal = iswalnum(paraVal); + LOGD(" iswalnum returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: iswalnum returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWALNUM_0300 +* @tc.name test iswalnum api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswalnum0300, TestSize.Level1) { + wint_t paraVal; + int returnVal; + + paraVal = 'z'; + returnVal = iswalnum(paraVal); + LOGD(" iswalnum returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: iswalnum returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWALNUM_0400 +* @tc.name test iswalnum api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswalnum0400, TestSize.Level1) { + wint_t paraVal; + int returnVal; + + paraVal = ' '; + returnVal = iswalnum(paraVal); + LOGD(" iswalnum returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: iswalnum returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWALNUM_0500 +* @tc.name test iswalnum api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswalnum0500, TestSize.Level1) { + wint_t paraVal; + int returnVal; + + paraVal = '\n'; + returnVal = iswalnum(paraVal); + LOGD(" iswalnum returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: iswalnum returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWALPHA_1100 +* @tc.name test iswalpha api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswalpha1100, TestSize.Level1) { + wint_t paraVal; + int returnVal; + + paraVal = 'z'; + returnVal = iswalpha(paraVal); + LOGD(" iswalpha returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: iswalpha returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWALPHA_1200 +* @tc.name test iswalpha api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswalpha1200, TestSize.Level1) { + wint_t paraVal; + int returnVal; + + paraVal = 'Z'; + returnVal = iswalpha(paraVal); + LOGD(" iswalpha returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: iswalpha returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWALPHA_1300 +* @tc.name test iswalpha api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswalpha1300, TestSize.Level1) { + wint_t paraVal; + int returnVal; + + paraVal = ' '; + returnVal = iswalpha(paraVal); + LOGD(" iswalpha returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: iswalpha returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWALPHA_1400 +* @tc.name test iswalpha api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswalpha1400, TestSize.Level1) { + wint_t paraVal; + int returnVal; + + paraVal = '\n'; + returnVal = iswalpha(paraVal); + LOGD(" iswalpha returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: iswalpha returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWBLANK_1900 +* @tc.name test iswblank api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswblank1900, TestSize.Level1) { + wint_t paraVal; + int returnVal; + + paraVal = ' '; + returnVal = iswblank(paraVal); + LOGD(" iswblank returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: iswblank returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWBLANK_2000 +* @tc.name test iswblank api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswblank2000, TestSize.Level1) { + wint_t paraVal; + int returnVal; + + paraVal = 'A'; + returnVal = iswblank(paraVal); + LOGD(" iswblank returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: iswblank returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWCNTRL_2400 +* @tc.name test iswcntrl api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswcntrl2400, TestSize.Level1) { + wint_t paraVal; + int returnVal; + + paraVal = 'A'; + returnVal = iswcntrl(paraVal); + LOGD(" iswcntrl returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: iswcntrl returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWCTYPE_2700 +* @tc.name test iswctype api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswctype2700, TestSize.Level1) { + wint_t wideChar; + wctype_t paraDesc; + int returnVal; + + wideChar = 'A'; + paraDesc = wctype("alnum"); + returnVal = iswctype(wideChar, paraDesc); + LOGD(" iswctype returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: iswctype returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWCTYPE_2800 +* @tc.name test iswctype api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswctype2800, TestSize.Level1) { + wint_t wideChar; + wctype_t paraDesc; + int returnVal; + + wideChar = '3'; + paraDesc = wctype("alnum"); + returnVal = iswctype(wideChar, paraDesc); + LOGD(" iswctype returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: iswctype returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWDIGIT_3100 +* @tc.name test iswdigit api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswdigit3100, TestSize.Level1) { + wint_t wideChar; + int returnVal; + + wideChar = '3'; + returnVal = iswdigit(wideChar); + LOGD(" iswdigit returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: iswdigit returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWDIGIT_3200 +* @tc.name test iswdigit api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswdigit3200, TestSize.Level1) { + wint_t wideChar; + int returnVal; + + wideChar = 'A'; + returnVal = iswdigit(wideChar); + LOGD(" iswdigit returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: iswdigit returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWGRAPH_3500 +* @tc.name test iswgraph api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswgraph3500, TestSize.Level1) { + wint_t wideChar; + int returnVal; + + wideChar = 'A'; + returnVal = iswgraph(wideChar); + LOGD(" iswgraph returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: iswgraph returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWGRAPH_3600 +* @tc.name test iswgraph api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswgraph3600, TestSize.Level1) { + wint_t wideChar; + int returnVal; + + wideChar = '\n'; + returnVal = iswgraph(wideChar); + LOGD(" iswgraph returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: iswgraph returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWLOWER_3900 +* @tc.name test iswlower api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswlower3900, TestSize.Level1) { + wint_t wideChar; + int returnVal; + + wideChar = 'A'; + returnVal = iswlower(wideChar); + LOGD(" iswlower c:='%c', returnVal:='%c'\n", wideChar, returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: iswlower c:='" << wideChar << "', returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWLOWER_4000 +* @tc.name test islower api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswlower4000, TestSize.Level1) { + wint_t wideChar; + int returnVal; + + wideChar = 'a'; + returnVal = iswlower(wideChar); + LOGD(" iswlower c:='%c', returnVal:='%c'\n", wideChar, returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: iswlower c:='" << wideChar << "', returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWLOWER_4100 +* @tc.name test islower api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswlower4100, TestSize.Level1) { + wint_t wideChar; + int returnVal; + + wideChar = '5'; + returnVal = iswlower(wideChar); + LOGD(" iswlower c:='%c', returnVal:='%c'\n", wideChar, returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: iswlower c:='" << wideChar << "', returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWPRINT_4500 +* @tc.name test iswprint api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswprint4500, TestSize.Level1) { + wint_t wideChar; + int returnVal; + + wideChar = 'a'; + returnVal = iswprint(wideChar); + LOGD(" iswprint returnVal:='%d'\n", returnVal); + ASSERT_TRUE(returnVal != 0) << "ErrInfo: iswprint returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWPRINT_4600 +* @tc.name test iswprint api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswprint4600, TestSize.Level1) { + wint_t wideChar; + int returnVal; + + wideChar = '\n'; + returnVal = iswprint(wideChar); + LOGD(" iswprint returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: iswprint returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWPUNCT_4900 +* @tc.name test iswpunct api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswpunct4900, TestSize.Level1) { + wint_t wideChar; + int returnVal; + + wideChar = ' '; + returnVal = iswpunct(wideChar); + LOGD(" iswpunct returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: iswpunct returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWPUNCT_5000 +* @tc.name test iswpunct api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswpunct5000, TestSize.Level1) { + wint_t wideChar; + int returnVal; + + wideChar = 'A'; + returnVal = iswpunct(wideChar); + LOGD(" iswpunct returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: iswpunct returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWPUNCT_5100 +* @tc.name test iswpunct api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswpunct5100, TestSize.Level1) { + wint_t wideChar; + int returnVal; + + wideChar = '3'; + returnVal = iswpunct(wideChar); + LOGD(" iswpunct returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: iswpunct returnVal:='" << returnVal << "'"; +} + +/** +* @tc.number SUB_KERNEL_UTIL_WIDECHECK_ISWPUNCT_5200 +* @tc.name test iswpunct api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ActsUtilWideCheckApiTest, testIswpunct5200, TestSize.Level1) { + wint_t wideChar; + int returnVal; + + wideChar = '\n'; + returnVal = iswpunct(wideChar); + LOGD(" iswpunct returnVal:='%d'\n", returnVal); + ASSERT_TRUE(0 == returnVal) << "ErrInfo: iswpunct returnVal:='" << returnVal << "'"; +} diff --git a/kernel_lite/utils/BUILD.gn b/kernel_lite/utils/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..936229d398ac18bc294590c39dfe09a811cd1a27 --- /dev/null +++ b/kernel_lite/utils/BUILD.gn @@ -0,0 +1,31 @@ + # Copyright (c) 2020 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. + +static_library("libutils") { + sources = [ + "utils.cpp" + ] + include_dirs = [ + "//test/xts/tools/hctest/include" + ] + deps = [ + "//test/xts/tools/hcpptest:hcpptest" + ] +} + +static_library("libfs") { + sources = [ + "libfs.cpp" + ] +} + diff --git a/kernel_lite/utils/KernelConstants.h b/kernel_lite/utils/KernelConstants.h new file mode 100755 index 0000000000000000000000000000000000000000..1b1e15e214e59a4ca82abd738134235add352b02 --- /dev/null +++ b/kernel_lite/utils/KernelConstants.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2020 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 KERNEL_CONSTANTS_H +#define KERNEL_CONSTANTS_H + +/** + * ================ DAC and Caps ================ + */ +const int SHELL_UID = 2; +const int SHELL_GID = 2; + + +/** + * ================ Process Manager ================ + */ +const int MAX_PROCESS_GROUPS = 255; // max number of groups a process can have +const int MAX_PROCESS_NUMBER = 63; // max allowd process [0,63] +const int MAX_TASK_NUMBER = 128; // max allowd task(process+thread) + + +/** + * ================ IPC ================ + */ +const int MAX_SIGNAL_NUMBER = 64; // max number of allowed signal, [1,64] +const int MAX_PIPE_BUFFER = 1023; // max size of a pipe buffer +const int MAX_PIPE_NUMBER = 32; // max pipe number + +const int MAX_MQ_NUMBER = 1024; // max mqueue number +const int MAX_MQ_NAME_LEN = 256; // max mqueue name length +const int MAX_MQ_MSG_SIZE = 65530; // max mqueue message size + + +/** + * ================ FS ================ + */ +const int MAX_PATH_SIZE = 256; // max size of path string + + +/** + * ================ XTS ================ + */ +// top dir of test resource of kernel +#define RES_DIR_KERNEL "/test_root/kernel/" + +#endif diff --git a/kernel_lite/utils/libfs.cpp b/kernel_lite/utils/libfs.cpp new file mode 100755 index 0000000000000000000000000000000000000000..beab0086ae5ea096df00eadf9018523390f16a36 --- /dev/null +++ b/kernel_lite/utils/libfs.cpp @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2020 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 "log.h" +#include "libfs.h" +#include "KernelConstants.h" + +int MakeDir(const char *dirname) +{ + if (access(dirname, F_OK) == 0) { + LOG("dir:%s exists", dirname); + return 1; + } else { + int rt = mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR | S_IRWXG | S_IXOTH); + if (rt) { + LOG("create dir failed! path=%s, errno=%d:%s", dirname, errno, strerror(errno)); + return -1; + } + } + return 0; +} + +int RemoveDir(const char *dirname) +{ + char subDir[MAX_PATH_SIZE]; + struct stat dirStat; + + if (stat(dirname, &dirStat) < 0) { + LOG("get directory stat error, errno=%d:%s", errno, strerror(errno)); + return -1; + } + + if (S_ISDIR(dirStat.st_mode)) { + DIR *pDir = opendir(dirname); + struct dirent *entry; + while ((entry = readdir(pDir))) { + char *fname = entry->d_name; + if (!strcmp(fname, ".") || !strcmp(fname, "..")) { + continue; // skip . and .. + } + // MAX_PATH_SIZE is the max length of allowed path string, so it safe to use sprintf here. + sprintf(subDir, "%s/%s", dirname, fname); + RemoveDir(subDir); // remove sub dir or file + } + closedir(pDir); + if (rmdir(dirname) == -1) { // delete empty dir + LOG("delete empty directory failed, path=%s, errno=%d:%s", dirname, errno, strerror(errno)); + return -1; + } + } else { + if (remove(dirname) == -1) { + LOG("remove regular file failed, path=%s, errno=%d:%s", dirname, errno, strerror(errno)); + return -1; + } + } + + return 0; +} + +int RemoveFile(const char *fpath) +{ + if (!remove(fpath)) { + LOG("remove file success"); + } else { + LOG("remove file failed! path=%s: errno=%d:%s", fpath, errno, strerror(errno)); + return -1; + } + return 0; +} + +int CopyFile(const char *srcFile, const char *dstFile) +{ + int rt = 0; + FILE *srcFp = fopen(srcFile, "rb"); + if (srcFp == NULL) { + LOG("Cannot open source file %s: errno=%d,%s \n", srcFile, errno, strerror(errno)); + return -1; + } + FILE *dstFp = fopen(dstFile, "wb"); + if (dstFp == NULL) { + LOG("Cannot create dest file %s: errno=%d,%s \n", dstFile, errno, strerror(errno)); + fclose(srcFp); + return -1; + } + + const int BUF_SIZE = 100 * 1024; + char buffer[BUF_SIZE]; + size_t bytes; + while ((bytes = fread(buffer, 1, sizeof(buffer), srcFp)) > 0) { + if (fwrite(buffer, 1, bytes, dstFp) != bytes) { + LOG("write to dest file failed: errno=%d,%s \n", errno, strerror(errno)); + rt = -1; + break; + } + } + fclose(srcFp); + fclose(dstFp); + return rt; +} + +char* GetCurrentPath() +{ + static char path1[MAX_PATH_SIZE]; + char *path = getcwd(path1, MAX_PATH_SIZE); + LOG("current Path = %s,path1=%s", path, path1); + return path1; +} diff --git a/kernel_lite/utils/libfs.h b/kernel_lite/utils/libfs.h new file mode 100755 index 0000000000000000000000000000000000000000..2d5bfde649fcd55d343bb25139a7a464a8626c0d --- /dev/null +++ b/kernel_lite/utils/libfs.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2020 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 KERNEL_LIBFS_H +#define KERNEL_LIBFS_H + +/** + * desc: make a new directory + * input: dirname + * output: -1 -- mkdir failed, detail info printed + * 0 -- mkdir ok, or dirname already exists + * 1 -- dirname already exists + */ +int MakeDir(const char *dirname); + +/** + * desc: remove a dir, even it's not empty + * input: dirname + * output: -1 -- rmdir failed, detail info printed + * 0 -- remove ok + */ +int RemoveDir(const char *dirname); + +/** + * desc: remove a file + * input: dirname + * output: -1 -- rmdir failed, detail info printed + * 0 -- remove ok + */ +int RemoveFile(const char *fpath); + +/** + * desc: copy srcFile to dstFile. if dstFile exist, it will be reflashed + * output: -1 -- copy failed, detail info printed + * 0 -- copy ok + */ +int CopyFile(const char *srcFile, const char *dstFile); + +/** + * desc: get current working directory + * output: NULL -- getcwd failed, detail info printed + * string -- the current working directory + */ +char* GetCurrentPath(); + +#endif // header diff --git a/kernel_lite/utils/log.h b/kernel_lite/utils/log.h new file mode 100755 index 0000000000000000000000000000000000000000..9b5a6fa952e95a2612ae2fa27488cedcd228a857 --- /dev/null +++ b/kernel_lite/utils/log.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2020 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 KERNEL_LITE_LOG +#define KERNEL_LITE_LOG + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +const int SYS_NS_PER_US = 1000; +// get current time, for logging only +static char* GetCurTime(void) +{ + static char buff[20]; + struct timespec time1 = {0, 0}; + clock_gettime(CLOCK_MONOTONIC, &time1); + snprintf(buff, sizeof(buff), "%ld:%06ld", time1.tv_sec, time1.tv_nsec / SYS_NS_PER_US); + return buff; +} + +#ifdef DEBUG +#define LOGD(format, ...) fprintf(stdout, "[%s] " format "\n", GetCurTime(), ##__VA_ARGS__) +#define LOG(format, ...) fprintf(stdout, "[%s] " format "\n", GetCurTime(), ##__VA_ARGS__) +#else +#define LOGD(...) +#define LOG(format, ...) fprintf(stdout, format "\n", ##__VA_ARGS__) +#endif + +#define T_LOC2(l) __FILE__ ":" #l +#define T_LOC1(l) T_LOC2(l) +#define LOGE(format, ...) fprintf(stdout, "\n" T_LOC1(__LINE__) ": " format "\n", ##__VA_ARGS__) + +#define PANIC(format, ...) do { \ + LOGE(format, ##__VA_ARGS__); \ + exit(1); \ + } while (0) + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/kernel_lite/utils/utils.cpp b/kernel_lite/utils/utils.cpp new file mode 100755 index 0000000000000000000000000000000000000000..1f2afbcf5ae740368b09089f995136d4bfdf0209 --- /dev/null +++ b/kernel_lite/utils/utils.cpp @@ -0,0 +1,221 @@ +/* + * Copyright (c) 2020 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 _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include "utils.h" +#include +#include "log.h" + +// init rand seed at startup +__attribute__((constructor)) static void Initialize(void) +{ + LOGD("srand(time(0)) is called."); + srand(time(0)); +} + +int CheckValueClose(double target, double actual, double accuracy) +{ + double diff = actual - target; + if (diff < 0) { + diff = -diff; + } + double pct = diff / actual; + LOGD("diff=%f, pct=%f\n", diff, pct); + return (pct <= accuracy); +} + +const int SYS_US_PER_MS = 1000; +void Msleep(int msec) +{ + usleep(msec * SYS_US_PER_MS); +} + +int KeepRun(int msec) +{ + struct timespec time1 = {0, 0}; + struct timespec time2 = {0, 0}; + clock_gettime(CLOCK_MONOTONIC, &time1); + LOGD("KeepRun start : tv_sec=%ld, tv_nsec=%ld\n", time1.tv_sec, time1.tv_nsec); + int loop = 0; + int runned = 0; + while (runned < msec) { + ++loop; + clock_gettime(CLOCK_MONOTONIC, &time2); + runned = (time2.tv_sec - time1.tv_sec) * 1000 + (time2.tv_nsec - time1.tv_nsec) / 1000000; + } + LOGD("KeepRun end : tv_sec=%ld, tv_nsec=%ld\n", time2.tv_sec, time2.tv_nsec); + return loop; +} + +// check process state use 'waitpid' +int CheckProcStatus(pid_t pid, int* code, int flag) +{ + int status; + int rt = waitpid(pid, &status, flag); + errno = 0; + if (rt == -1) { + LOGE("waitpid return -1, errno=%d:%s\n", errno, strerror(errno)); + return -1; + } else if (rt == 0) { + return 0; + } else if (rt != pid) { // waitpid return error + if (errno) { + LOGE("waitpid return error, rt=%d, errno=%d:%s\n", rt, errno, strerror(errno)); + } else { + LOGE("waitpid return error, errno is not set(no more info)\n"); + } + return -2; + } + + if (WIFEXITED(status)) { + *code = WEXITSTATUS(status); + return 1; + } else if (WIFSIGNALED(status)) { + *code = WTERMSIG(status); + return 2; + } else if (WIFSTOPPED(status)) { + *code = WSTOPSIG(status); + return 3; + } + return 4; +} + +// start a elf, only check if execve success or not +static int StartElf(const char* fname, char* const argv[], char* const envp[]) +{ + int pid = fork(); + if (pid == -1) { + LOGE("ERROR: Fork Error, errno=%d, err=%s\n", errno, strerror(errno)); + return -1; + } else if (pid == 0) { // child + errno = 0; + int rt = execve(fname, argv, envp); + if (rt == -1) { + LOGE("ERROR: execve return -1, errno=%d, err=%s\n", errno, strerror(errno)); + exit(EXECVE_RETURN_ERROR); + } + LOGE("ERROR: execve should never return on success. rt=%d, errno=%d, err=%s\n", rt, errno, strerror(errno)); + exit(EXECVE_RETURN_OK); + } + return pid; +} + +int RunElf(const char* fname, char* const argv[], char* const envp[], int timeoutSec) +{ + int isTimeout = 0; + int status; + int exitCode; + sigset_t set; + sigemptyset(&set); + sigaddset(&set, SIGCHLD); + + int pid = StartElf(fname, argv, envp); + if (pid == -1) { // fork error + return -1; + } + + if (timeoutSec > 0) { + struct timespec time1 = {timeoutSec, 0}; + if (sigtimedwait(&set, 0, &time1) == -1) { + if (errno == EAGAIN) { + isTimeout = 1; + } else { + LOGE("ERROR: sigtimedwait FAIL: %s\n", strerror(errno)); + return -1; + } + if (kill(pid, SIGKILL) == -1) { + LOGE("ERROR: kill child FAIL: %s\n", strerror(errno)); + return -1; + } + } + // else: sigtimedwait return ok, child has exited already, nothing else to do + } + int rt = CheckProcStatus(pid, &exitCode, 0); + if ((rt <= 0) || (exitCode == EXECVE_RETURN_OK) || (exitCode == EXECVE_RETURN_ERROR)) { + return -1; + } + if (isTimeout) { + LOGE("ERROR: child execute timed out!\n"); + return -2; + } + return exitCode; +} + +int StartExecveError(const char* fname, char* const argv[], char* const envp[]) +{ + pid_t pid = fork(); + if (pid == -1) { + LOGE("ERROR: Fork Error, errno=%d, err=%s\n", errno, strerror(errno)); + return -1; + } else if (pid == 0) { // child + int rt = execve(fname, argv, envp); + if (rt == -1) { + LOG("ERROR: execve return -1, errno=%d, err=%s\n", errno, strerror(errno)); + exit(errno); + } + LOGE("ERROR: execve should never return on success. rt=%d, errno=%d, err=%s\n", rt, errno, strerror(errno)); + exit(EXECVE_RETURN_OK); + } + // parent + Msleep(30); + int exitCode; + int procStat = CheckProcStatus(pid, &exitCode); + LOG("procStat=%d, exitCode=%d\n", procStat, exitCode); + if (procStat != 1) { + return -3; + } else if (exitCode == EXECVE_RETURN_OK) { + return -2; + } else { + return exitCode; + } +} + +// Get a pid number that currently not exist +// by creat a child process and exit. +pid_t GetNonExistPid() +{ + pid_t pid = fork(); + if (pid < 0) { + LOG("fork error, wait 5 seconds than try angain..."); + sleep(5); + pid = fork(); + if (pid < 0) { + LOG("still fork error!"); + return -1; + } + } + if (pid > 0) { // parent + Msleep(20); + if (waitpid(pid, NULL, 0) != pid) { + LOG("waitpid failed, errno = %d", errno); + return -1; + } + } else { // child + exit(0); + } + return pid; +} + +// return n: 0 < n <= max +uint32_t GetRandom(uint32_t max) +{ + if (max == 0 || max == 1) { + return 1; + } + return (rand() % max) + 1; +} diff --git a/kernel_lite/utils/utils.h b/kernel_lite/utils/utils.h new file mode 100755 index 0000000000000000000000000000000000000000..937507cec728ae656caab93cadc5fa60b120b27a --- /dev/null +++ b/kernel_lite/utils/utils.h @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2020 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 KERNEL_LITE_UTILS +#define KERNEL_LITE_UTILS + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +// check if 'actual' is close to 'target', within 5% in default +int CheckValueClose(double target, double actual, double accuracy = 0.05); + +// sleep n millisecond(1/1000 sec) +void Msleep(int n); + +/** + * desc: check process state use 'waitpid' + * input: pid -- target pid + * code -- store exit code or signal number + * flag -- flag for waitpid, default to WNOHANG + * output: -1 -- waitpid return -1 + * -2 -- waitpid return value error(not -1 and not pid) + * 0 -- target process still alive + * 1 -- target process existd, exist code is set in 'code' + * 2 -- target process killed by a signal, signal number is set in 'code' + * 3 -- target process is stopped, signal number is set in 'code' + * 4 -- get target process state error, due to waitpid error + */ +int CheckProcStatus(pid_t pid, int* code, int flag = WNOHANG); + +// make sure process is still alive +#define AssertProcAlive(pid) do { \ + int exitCode; \ + int procStat = CheckProcStatus(pid, &exitCode); \ + ASSERT_EQ(procStat, 0) << "target process should still alive.\n"; \ + } while (0) +#define ExpectProcAlive(pid) do { \ + int exitCode; \ + int procStat = CheckProcStatus(pid, &exitCode); \ + EXPECT_EQ(procStat, 0) << "target process should still alive.\n"; \ + } while (0) + +// make sure process exited with exitCode 0 +#define AssertProcExitedOK(pid) do { \ + int exitCode; \ + int procStat = CheckProcStatus(pid, &exitCode); \ + EXPECT_EQ(procStat, 1); \ + ASSERT_EQ(exitCode, 0) << "target process should exited 0.\n"; \ + } while (0) +#define ExpectProcExitedOK(pid) do { \ + int exitCode; \ + int procStat = CheckProcStatus(pid, &exitCode); \ + EXPECT_EQ(procStat, 1); \ + EXPECT_EQ(exitCode, 0) << "target process should exited 0.\n"; \ + } while (0) + +// make sure process killed by signal signum +#define AssertProcKilled(pid, signum) do { \ + int exitCode; \ + int procStat = CheckProcStatus(pid, &exitCode); \ + ASSERT_EQ(procStat, 2); \ + ASSERT_EQ(exitCode, signum) << "target process should killed by " << signum; \ + } while (0) +#define ExpectProcKilled(pid, signum) do { \ + int exitCode; \ + int procStat = CheckProcStatus(pid, &exitCode); \ + EXPECT_EQ(procStat, 2); \ + EXPECT_EQ(exitCode, signum) << "target process should killed by " << signum; \ + } while (0) + + +// keep current process run for a specific time, no sleep. +// msec is millisecond (1/1000 sec). +// return value is the loop count(generally you don't need to care about it) +int KeepRun(int msec); + +/** + * code to determain if execve is faild, may confic with actual sub program's exit code + */ +const int EXECVE_RETURN_ERROR = 190; // execve return -1 +const int EXECVE_RETURN_OK = 191; // execve return not -1: execve should never return on success + +/** + * desc: start a elf, check if execve success, and return child process exit code within timeout_sec + * input: fname, argv, envp -- parameters for execve + * timeout_sec -- timeout of the child executing, default: 5 seconds. + * timeout_sec<=0 means no timeout, wait forever until child exit. + * output: -1 -- something wrong for internal syscall, check log for detail + * -2 -- child does not finish in 'timeout_sec' + * n(>=0) -- child exit code + */ +int RunElf(const char* fname, char* const argv[], char* const envp[], int timeoutSec = 5); + +/** + * desc: call execve with error parameters(e.g. a non-exist file) + * input: fname, argv, envp -- parameters for execve + * output: 0 -- execve ok + * -1 -- unexpected fork error + * -2 -- unexpected execve error + * -3 -- unknow error + * n(>0) -- errno of execve + */ +int StartExecveError(const char* fname, char* const argv[], char* const envp[]); + +// Get a pid number that currently not exist +pid_t GetNonExistPid(); + +/** + * return random number n: 0 < n <= max + * we found in most case '0' is not expected. + */ +uint32_t GetRandom(uint32_t max); + +#endif \ No newline at end of file diff --git a/multimedia_lite/multimedia_posix/camera/BUILD.gn b/multimedia_lite/multimedia_posix/camera/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..fd7a5683c4a69869fe19961f56d0671c61d3652c --- /dev/null +++ b/multimedia_lite/multimedia_posix/camera/BUILD.gn @@ -0,0 +1,61 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsMediaCameraTest") { + suite_name = "acts" + sources = [ + "src/ActsMediaCameraTest.cpp", + ] + + include_dirs = [ + "src", + "//kernel/liteos_a/kernel/include", + "//kernel/liteos_a/kernel/common", + "//foundation/multimedia/services/media_lite/camera/src", + "//foundation/multimedia/services/media_lite/audio_capture/include", + "//foundation/multimedia/services/media_lite/common/include", + "//foundation/multimedia/services/media_lite/recorder/include", + "//third_party/bounds_checking_function/include", + "//third_party/bounds_checking_function/include", + ] + outdir = rebase_path("$root_out_dir") + ldflags = ["-L$outdir"] + ldflags += ["-Wl,-rpath-link,$outdir"] + ldflags += ["-Wl,-L$outdir"] + ldflags += ["-lc"] + ldflags += ["-lm"] + ldflags += ["-lpthread"] + ldflags += ["-ldl"] + ldflags += ["-lstdc++"] + ldflags += ["-lformat_muxer"] + ldflags += ["-live"] + ldflags += ["-lmp4"] + ldflags += ["-lrecorder_pro"] + ldflags += ["-lfileformat"] + ldflags += ["-ldtcf"] + ldflags += ["-lhitimer"] + ldflags += ["-lmedia_common"] + ldflags += ["-laudio_capturer"] + ldflags += ["-luproc"] + ldflags += ["-lcodec"] + ldflags += ["-laudio_hw"] + deps = [ + "//third_party/bounds_checking_function:libsec_shared", + "//foundation/multimedia/services/media_lite:recorder", + "//foundation/multimedia/services/media_lite:camera", + "//foundation/multimedia/services/media_lite:audio_capturer", + ] + cflags = [ "-Wno-error" ] +} diff --git a/multimedia_lite/multimedia_posix/camera/Test.json b/multimedia_lite/multimedia_posix/camera/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..97a7d725398d0c2dc1d0e4f00024b1f50e26f94f --- /dev/null +++ b/multimedia_lite/multimedia_posix/camera/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for hcpptest demo test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/multimedia", + "target": "/test_root/multimedia" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/multimedia/ActsMediaCameraTest.bin" + } +} \ No newline at end of file diff --git a/multimedia_lite/multimedia_posix/camera/src/ActsMediaCameraTest.cpp b/multimedia_lite/multimedia_posix/camera/src/ActsMediaCameraTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..b2867c0cb751fbc4a95be4d4f0c3d2e3bd0ad49e --- /dev/null +++ b/multimedia_lite/multimedia_posix/camera/src/ActsMediaCameraTest.cpp @@ -0,0 +1,698 @@ +/* + * Copyright (c) 2020 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 "ActsMediaCameraTest.h" +#include "camera_config.h" +#include "camera_device_callback.h" +#include "camera_kit.h" +#include "camera_state_callback.h" +#include "event_handler.h" +#include "frame_config.h" +#include "frame_state_callback.h" +#include "fstream" +#include "iostream" +#include "recorder.h" +#include "surface.h" +#include "thread" +#include "unistd.h" +#include "gtest/gtest.h" +#include + +using namespace std; +using namespace OHOS::Media; +using namespace testing::ext; + +const int FRAME_RATE_DEFAULT = 30; +EventHandler *g_hdl = nullptr; + +// SetUpTestCase:测试套预置动作,在第一个TestCase之前执行 +void ActsMediaCameraTest::SetUpTestCase(void) +{ + g_hdl = new EventHandler; + cout << "SetUpTestCase" << endl; +} +// TearDownTestCase:测试套清理动作,在最后一个TestCase之后执行 +void ActsMediaCameraTest::TearDownTestCase(void) +{ + if (g_hdl != nullptr) { + delete g_hdl; + g_hdl = NULL; + } + cout << "TearDownTestCase" << endl; +} +// 用例的预置动作 初始化回调Flag为 FLAG0 +void ActsMediaCameraTest::SetUp(void) +{ + // CameraDeviceCallBack + CameraFlag::g_onCameraAvailableFlag = FLAG0; + CameraFlag::g_onCameraUnavailableFlag = FLAG0; + CameraFlag::g_onCameraAccessPrioritiesChangedFlag = FLAG0; + CameraFlag::g_onTorchModeAvailableFlag = FLAG0; + CameraFlag::g_onTorchModeUnavailableFlag = FLAG0; + + // CameraStateCallback + CameraFlag::g_onCreatedFlag = FLAG0; + CameraFlag::g_onCreateFailedFlag = FLAG0; + CameraFlag::g_onReleasedFlag = FLAG0; + + // FrameStateCallback + CameraFlag::g_onCaptureTriggerAbortedFlag = FLAG0; + CameraFlag::g_onCaptureTriggerCompletedFlag = FLAG0; + CameraFlag::g_onCaptureTriggerStartedFlag = FLAG0; + CameraFlag::g_onFrameCompletedFlag = FLAG0; + CameraFlag::g_onFrameErrorFlag = FLAG0; + CameraFlag::g_onFrameProgressedFlag = FLAG0; + CameraFlag::g_onFrameStartedFlag = FLAG0; + cout << "SetUp" << endl; +} + +// 用例的清理动作 +void ActsMediaCameraTest::TearDown(void) +{ + cout << "TearDown.." << endl; +} + +namespace OHOS::Media { +// 设置保存拍照 +void TestSaveCapture(char *p, uint32_t size) +{ + cout << "Start saving picture" << endl; + struct timeval tv; + gettimeofday(&tv, NULL); + struct tm *ltm = localtime(&tv.tv_sec); + ostringstream ss("Capture_"); + ss << "Capture" << ltm->tm_hour << "-" << ltm->tm_min << "-" << ltm->tm_sec << ".jpg"; + + ofstream pic("/tmp/" + ss.str()); + cout << "write " << size << " bytes" << endl; + pic.write(p, size); + cout << "Saving picture end" << endl; +} +// 实现framestate callback +class TestFrameStateCallback : public FrameStateCallback { + void OnFrameCompleted(Camera &camera, FrameConfig &frameConfig, FrameResult frameResult) override + { + if (frameConfig.GetFrameConfigType() != CAPTURE) { + cout << "Test frame completed." << endl; + return; + } + // 写入文件 + cout << "Try to read picture." << endl; + auto surfaceList = frameConfig.GetSurfaceList(); + Surface *surface = nullptr; + if (surfaceList->empty()) { + delete &frameConfig; + cout << "Receive empty frame config" << endl; + return; + } + surface = surfaceList->front(); + SurfaceBuffer *buffer = surface->AcquireBuffer(); + if (buffer != nullptr) { + TestSaveCapture(static_cast(buffer->GetVirAddr()), buffer->GetSize()); + surface->ReleaseBuffer(buffer); + } + + delete surface; + delete &frameConfig; + } +}; + +// 实现IBufferConsumerListener回调 +class TestConsumer : public IBufferConsumerListener { + void OnBufferAvailable() override + { + return; + } +}; + +// 实现CameraStateCallback,进行预览相关操作 +class TestPreviewCameraStateCallback : public CameraStateCallback { +public: + TestPreviewCameraStateCallback() : camera_(nullptr), fsc_(nullptr), surface_(nullptr) {} + ~TestPreviewCameraStateCallback() + { + if (surface_ != nullptr) { + delete surface_; + } + if (fsc_ != nullptr) { + delete fsc_; + } + } + // 创建surface并注册 + void GenSurface() + { + surface_ = Surface::CreateSurface(); + auto consumer = new TestConsumer; + surface_->RegisterConsumerListener(*consumer); + } + // 相机创建成功,设置surface相关参数 + void OnCreated(Camera &c) override + { + fsc_ = new TestFrameStateCallback; + CameraConfig *cc = CameraConfig::CreateCameraConfig(); + cc->SetFrameStateCallback(fsc_, g_hdl); + c.Configure(cc); + GenSurface(); + surface_->SetUserData("region_position_x", "100"); + surface_->SetUserData("region_position_y", "100"); + surface_->SetUserData("region_width", "192"); + surface_->SetUserData("region_height", "108"); + surface_->SetQueueSize(2); + surface_->SetWidthAndHeight(1920, 1080); + camera_ = &c; + } + // 相机创建失败 + void OnCreateFailed(std::string cameraId, int32_t errorCode) override + { + CameraFlag::g_onCreateFailedFlag = FLAG1; + printf("OnCreateFailed\n"); + } + // 相机释放 + void OnReleased(Camera &c) override + { + CameraFlag::g_onReleasedFlag = FLAG1; + printf("OnReleased\n"); + } + Surface *surface_; + Camera *camera_; + FrameStateCallback *fsc_; +}; + +// 实现CameraStateCallback,进行录像相关操作 +class TestCameraStateCallback : public CameraStateCallback { +public: + TestCameraStateCallback() : camera_(nullptr), fsc_(nullptr), surface_(nullptr) + { + recorder_ = new Recorder(); + } + ~TestCameraStateCallback() + { + if (recorder_ != nullptr) { + delete recorder_; + } + if (fsc_ != nullptr) { + delete fsc_; + } + } + + void GenSurface(VideoEncodeParam *param) + { + std::cout << "recorder main " << std::endl; + int ret = 0; + int32_t sampleRate = 48000; + int32_t channelCount = 1; + AudioCodecFormat audioFormat = AAC_LC; + AudioSourceType inputSource = AUDIO_MIC; + int32_t audioEncodingBitRate = sampleRate; + VideoSourceType source = VIDEO_SOURCE_SURFACE_ES; + int32_t frameRate = 30; + float fps = 30; + int32_t rate = 4096; + int32_t sourceId = 0; + int32_t audioSourceId = 0; + int32_t width = 1920; + int32_t height = 1080; + VideoCodecFormat encoder; + if (param->enType == ENCODE_H265) { + encoder = HEVC; + } else { + encoder = H264; + } + if (param->picSize == PIC_1080P) { + width = 1920; + height = 1080; + } else { + width = 1280; + height = 720; + } + if ((ret = recorder_->SetVideoSource(source, sourceId)) != SUCCESS) { + printf("SetVideoSource fialed :0x%x\n", ret); + } + if ((ret = recorder_->SetVideoEncoder(sourceId, encoder)) != SUCCESS) { + printf("SetVideoEncoder fialed :0x%x\n", ret); + } + if ((ret = recorder_->SetVideoSize(sourceId, width, height)) != SUCCESS) { + printf("SetVideoSize fialed :0x%x\n", ret); + } + if ((ret = recorder_->SetVideoFrameRate(sourceId, frameRate)) != SUCCESS) { + printf("SetVideoFrameRate fialed :0x%x\n", ret); + } + if ((ret = recorder_->SetVideoEncodingBitRate(sourceId, rate)) != SUCCESS) { + printf("SetVideoEncodingBitRate fialed :0x%x\n", ret); + } + if ((ret = recorder_->SetCaptureRate(sourceId, frameRate)) != SUCCESS) { + printf("SetCaptureRate fialed :0x%x\n", ret); + } + if ((ret = recorder_->SetAudioSource(inputSource, audioSourceId)) != SUCCESS) { + printf("SetAudioSource fialed :0x%x\n", ret); + } + if ((ret = recorder_->SetAudioEncoder(audioSourceId, audioFormat)) != SUCCESS) { + printf("SetAudioEncoder fialed :0x%x\n", ret); + } + if ((ret = recorder_->SetAudioSampleRate(audioSourceId, sampleRate)) != SUCCESS) { + printf("SetAudioSampleRate fialed :0x%x\n", ret); + } + if ((ret = recorder_->SetAudioChannels(audioSourceId, channelCount)) != SUCCESS) { + printf("SetAudioChannels fialed :0x%x\n", ret); + } + if ((ret = recorder_->SetAudioEncodingBitRate(audioSourceId, audioEncodingBitRate)) != SUCCESS) { + printf("SetAudioEncodingBitRate fialed :0x%x\n", ret); + } + } + + void OnCreated(Camera &c) override + { + CameraFlag::g_onCreatedFlag = FLAG1; + printf("OnCreated\n"); + fsc_ = new TestFrameStateCallback; + CameraConfig *cc = CameraConfig::CreateCameraConfig(); + cc->SetFrameStateCallback(fsc_, g_hdl); + c.Configure(cc); + camera_ = &c; + } + // 相机创建失败 + void OnCreateFailed(std::string cameraId, int32_t errorCode) override + { + CameraFlag::g_onCreateFailedFlag = FLAG1; + printf("OnCreateFailed\n"); + } + // 相机释放 + void OnReleased(Camera &c) override + { + CameraFlag::g_onReleasedFlag = FLAG1; + printf("OnReleased\n"); + } + + Surface *surface_; + Recorder *recorder_; + Camera *camera_; + FrameStateCallback *fsc_; +}; +} // namespace OHOS::Media + +using namespace OHOS; +using namespace std; + +FrameConfig *TestCreatCaptureFrameConfig() +{ + FrameConfig *fc = new FrameConfig(CAPTURE); + Surface *surface = Surface::CreateSurface(); + surface->SetWidthAndHeight(1920, 1080); + fc->AddSurface(surface); + return fc; +} + +/* * + * @tc.number : SUB_MEDIA_CAMERA_DEV_00100 + * @tc.name : get cameraKit instance + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(ActsMediaCameraTest, TestCreatCamerakit, TestSize.Level1) +{ + CameraKit *cameraKit = new CameraKit(); + EXPECT_NE(nullptr, cameraKit); + delete cameraKit; +} + +/* * + * @tc.number : SUB_MEDIA_CAMERA_DEV_00200 + * @tc.name : get cameraKit device callback + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(ActsMediaCameraTest, TestCamera002, TestSize.Level1) +{ + CameraDeviceCallback *deviceCallback = new CameraDeviceCallback(); + EXPECT_NE(nullptr, deviceCallback); + delete deviceCallback; +} + +/* * + * @tc.number : SUB_MEDIA_CAMERA_DEV_00300 + * @tc.name : get cameraKit state callback + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(ActsMediaCameraTest, TestCamera003, TestSize.Level1) +{ + CameraStateCallback *stateCallback = new CameraStateCallback(); + EXPECT_NE(nullptr, stateCallback); + delete stateCallback; +} + +/* * + * @tc.number : SUB_MEDIA_CAMERA_DEV_00400 + * @tc.name : get cameraKit Envent Handle + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(ActsMediaCameraTest, TestCamera004, TestSize.Level1) +{ + EXPECT_NE(nullptr, g_hdl); +} + +/* * + * @tc.number : SUB_MEDIA_CAMERA_DEV_00500 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(ActsMediaCameraTest, Test_Camera005, TestSize.Level1) +{ + CameraKit *cameraKit = new CameraKit(); + CameraDeviceCallback *deviceCallback = new CameraDeviceCallback(); + TestCameraStateCallback *stateCallback = new TestCameraStateCallback(); + cameraKit->RegisterCameraDeviceCallback(deviceCallback, g_hdl); + EXPECT_EQ(FLAG1, CameraFlag::g_onCameraAvailableFlag); + delete cameraKit; + delete deviceCallback; + delete stateCallback; +} + +/* * + * @tc.number : SUB_MEDIA_CAMERA_DEV_00600 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(ActsMediaCameraTest, Test_Camera006, TestSize.Level1) +{ + CameraKit *cameraKit = new CameraKit(); + CameraDeviceCallback *deviceCallback = new CameraDeviceCallback(); + TestCameraStateCallback *stateCallback = new TestCameraStateCallback(); + cameraKit->RegisterCameraDeviceCallback(deviceCallback, g_hdl); + EXPECT_EQ(FLAG1, CameraFlag::g_onCameraAvailableFlag); + cameraKit->UnregisterCameraDeviceCallback(deviceCallback); + EXPECT_EQ(FLAG1, CameraFlag::g_onCameraUnavailableFlag); + delete cameraKit; + delete deviceCallback; + delete stateCallback; +} + +/* * + * @tc.number : SUB_MEDIA_CAMERA_DEV_00700 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(ActsMediaCameraTest, Test_Camera007, TestSize.Level1) +{ + CameraKit *cameraKit = new CameraKit(); + CameraDeviceCallback *deviceCallback = new CameraDeviceCallback(); + TestCameraStateCallback *stateCallback = new TestCameraStateCallback(); + cameraKit->RegisterCameraDeviceCallback(deviceCallback, g_hdl); + std::string cameraId = "camera001"; + cameraKit->CreateCamera(cameraId, stateCallback, g_hdl); + while (stateCallback->camera_ == nullptr) { + sleep(1); + } + EXPECT_EQ(FLAG1, CameraFlag::g_onCreatedFlag); + EXPECT_TRUE(stateCallback->camera_); + EXPECT_TRUE(stateCallback->surface_); + stateCallback->recorder_->Release(); + sleep(2); + delete cameraKit; + delete deviceCallback; + delete stateCallback; +} + +/* * + * @tc.number : SUB_MEDIA_CAMERA_DEV_00800 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(ActsMediaCameraTest, Test_Camera008, TestSize.Level0) +{ + CameraKit *cameraKit = new CameraKit(); + CameraDeviceCallback *deviceCallback = new CameraDeviceCallback(); + TestCameraStateCallback *stateCallback = new TestCameraStateCallback(); + cameraKit->RegisterCameraDeviceCallback(deviceCallback, g_hdl); + FrameConfig *fc = new FrameConfig(RECORD); // TODO: NEED TO FREE + std::string cameraId = "camera001"; + fc->AddSurface(stateCallback->surface_); + const CameraAbility *cameraAbility = cameraKit->GetCameraAbility(cameraId); + EXPECT_EQ(1920, cameraAbility->imageSize[0].u32Width); + EXPECT_EQ(1080, cameraAbility->imageSize[0].u32Height); + delete fc; + delete cameraKit; + delete deviceCallback; + delete stateCallback; +} + +/* * + * @tc.number : SUB_MEDIA_CAMERA_DEV_00900 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(ActsMediaCameraTest, Test_Camera009, TestSize.Level0) +{ + CameraKit *cameraKit = new CameraKit(); + CameraDeviceCallback *deviceCallback = new CameraDeviceCallback(); + TestCameraStateCallback *stateCallback = new TestCameraStateCallback(); + cameraKit->RegisterCameraDeviceCallback(deviceCallback, g_hdl); + std::string cameraId = "camera001"; + cameraKit->CreateCamera(cameraId, stateCallback, g_hdl); + FrameConfig *fc = new FrameConfig(RECORD); + VideoEncodeParam param; + param.enGopMode = VENCODE_GOPMODE_NORMALP; + param.enType = ENCODE_H265; + param.enRcMode = VENCODE_RC_CBR; + param.picSize = PIC_1080P; + param.u32Profile = 0; + stateCallback->GenSurface(¶m); + stateCallback->recorder_->Prepare(); + stateCallback->surface_ = stateCallback->recorder_->GetSurface(0).get(); + stateCallback->surface_->SetWidthAndHeight(1920, 1080); + stateCallback->surface_->SetQueueSize(3); + stateCallback->surface_->SetSize(512 * 1024); + fc->AddSurface(stateCallback->surface_); + fc->SetFrameFps(FRAME_RATE_DEFAULT); + fc->SetVencParam(¶m); + int32_t ret = stateCallback->recorder_->Start(); + stateCallback->camera_->StartLoopingCapture(*fc); + sleep(5); + stateCallback->recorder_->Stop(false); + stateCallback->camera_->StopLoopingCapture(); + stateCallback->recorder_->Release(); + delete fc; + delete stateCallback; + delete cameraKit; + delete deviceCallback; + sleep(10); +} + +/* * + * @tc.number : SUB_MEDIA_CAMERA_DEV_01000 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(ActsMediaCameraTest, Test_Camera010, TestSize.Level0) +{ + CameraKit *cameraKit = new CameraKit(); + CameraDeviceCallback *deviceCallback = new CameraDeviceCallback(); + TestCameraStateCallback *stateCallback = new TestCameraStateCallback(); + cameraKit->RegisterCameraDeviceCallback(deviceCallback, g_hdl); + std::string cameraId = "camera001"; + cameraKit->CreateCamera(cameraId, stateCallback, g_hdl); + while (stateCallback->camera_ == nullptr) { + sleep(1); + } + VideoEncodeParam param; + param.enGopMode = VENCODE_GOPMODE_NORMALP; + param.enType = ENCODE_H264; + param.enRcMode = VENCODE_RC_CBR; + param.picSize = PIC_1080P; + param.u32Profile = 0; + FrameConfig *fc = new FrameConfig(RECORD); + stateCallback->GenSurface(¶m); + stateCallback->recorder_->Prepare(); + stateCallback->surface_ = stateCallback->recorder_->GetSurface(0).get(); + stateCallback->surface_->SetWidthAndHeight(1920, 1080); + stateCallback->surface_->SetQueueSize(3); + stateCallback->surface_->SetSize(512 * 1024); + fc->AddSurface(stateCallback->surface_); + fc->SetFrameFps(FRAME_RATE_DEFAULT); + fc->SetVencParam(¶m); + int32_t ret = stateCallback->recorder_->Start(); + stateCallback->camera_->StartLoopingCapture(*fc); + sleep(5); + stateCallback->recorder_->Stop(false); + stateCallback->camera_->StopLoopingCapture(); + stateCallback->recorder_->Release(); + delete fc; + delete stateCallback; + delete cameraKit; + delete deviceCallback; +} + +/* * + * @tc.number : SUB_MEDIA_CAMERA_DEV_01100 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(ActsMediaCameraTest, Test_Camera011, TestSize.Level0) +{ + CameraKit *cameraKit = new CameraKit(); + CameraDeviceCallback *deviceCallback = new CameraDeviceCallback(); + TestCameraStateCallback *stateCallback = new TestCameraStateCallback(); + cameraKit->RegisterCameraDeviceCallback(deviceCallback, g_hdl); + std::string cameraId = "camera001"; + cameraKit->CreateCamera(cameraId, stateCallback, g_hdl); + while (stateCallback->camera_ == NULL) { + sleep(1); + } + FrameConfig *fc = new FrameConfig(RECORD); + VideoEncodeParam param; + param.enGopMode = VENCODE_GOPMODE_NORMALP; + param.enType = ENCODE_H265; + param.enRcMode = VENCODE_RC_CBR; + param.picSize = PIC_720P; + param.u32Profile = 0; + stateCallback->GenSurface(¶m); + stateCallback->recorder_->Prepare(); + stateCallback->surface_ = stateCallback->recorder_->GetSurface(0).get(); + stateCallback->surface_->SetWidthAndHeight(1280, 720); + stateCallback->surface_->SetQueueSize(3); + stateCallback->surface_->SetSize(1024 * 1024); + fc->AddSurface(stateCallback->surface_); + fc->SetFrameFps(FRAME_RATE_DEFAULT); + fc->SetVencParam(¶m); + int32_t ret = stateCallback->recorder_->Start(); + EXPECT_EQ(SUCCESS, ret); + stateCallback->camera_->StartLoopingCapture(*fc); + sleep(5); + stateCallback->recorder_->Stop(false); + stateCallback->camera_->StopLoopingCapture(); + stateCallback->recorder_->Release(); + delete fc; + delete cameraKit; + delete deviceCallback; + delete stateCallback; +} + +/* * + * @tc.number : SUB_MEDIA_CAMERA_DEV_01200 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(ActsMediaCameraTest, Test_Camera012, TestSize.Level0) +{ + CameraKit *cameraKit = new CameraKit(); + CameraDeviceCallback *deviceCallback = new CameraDeviceCallback(); + TestCameraStateCallback *stateCallback = new TestCameraStateCallback(); + cameraKit->RegisterCameraDeviceCallback(deviceCallback, g_hdl); + std::string cameraId = "camera001"; + cameraKit->CreateCamera(cameraId, stateCallback, g_hdl); + VideoEncodeParam param; + param.enGopMode = VENCODE_GOPMODE_NORMALP; + param.enType = ENCODE_H264; + param.enRcMode = VENCODE_RC_CBR; + param.picSize = PIC_1080P; + param.u32Profile = 0; + auto fc1080 = TestCreatCaptureFrameConfig(); + fc1080->SetVencParam(¶m); + stateCallback->camera_->CaptureFrame(*fc1080); + delete cameraKit; + delete deviceCallback; + delete stateCallback; +} + +/* * + * @tc.number : SUB_MEDIA_CAMERA_DEV_01300 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(ActsMediaCameraTest, Test_Camera013, TestSize.Level0) +{ + CameraKit *cameraKit = new CameraKit(); + CameraDeviceCallback *deviceCallback = new CameraDeviceCallback(); + TestCameraStateCallback *stateCallback = new TestCameraStateCallback(); + cameraKit->RegisterCameraDeviceCallback(deviceCallback, g_hdl); + std::string cameraId = "camera001"; + cameraKit->CreateCamera(cameraId, stateCallback, g_hdl); + VideoEncodeParam param; + param.enGopMode = VENCODE_GOPMODE_NORMALP; + param.enType = ENCODE_H264; + param.enRcMode = VENCODE_RC_CBR; + param.picSize = PIC_720P; + param.u32Profile = 0; + auto fc720 = TestCreatCaptureFrameConfig(); + fc720->SetVencParam(¶m); + stateCallback->camera_->CaptureFrame(*fc720); + delete cameraKit; + delete deviceCallback; + delete stateCallback; +} + +/* * + * @tc.number : SUB_MEDIA_CAMERA_PREVIEW_00100 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(ActsMediaCameraTest, Test_Preview001, TestSize.Level0) +{ + CameraKit *cameraKit = new CameraKit(); + CameraDeviceCallback *deviceCallback = new CameraDeviceCallback(); + TestPreviewCameraStateCallback *stateCallback = new TestPreviewCameraStateCallback(); + cameraKit->RegisterCameraDeviceCallback(deviceCallback, g_hdl); + std::string cameraId = "camera001"; + cameraKit->CreateCamera(cameraId, stateCallback, g_hdl); + FrameConfig *fc = new FrameConfig(FrameConfigType::PREVIEW); + fc->AddSurface(stateCallback->surface_); + stateCallback->camera_->StartLoopingCapture(*fc); + printf("start preview---"); + sleep(15); + stateCallback->camera_->StopLoopingCapture(); + delete fc; + delete cameraKit; + delete deviceCallback; + delete stateCallback; +} \ No newline at end of file diff --git a/multimedia_lite/multimedia_posix/camera/src/ActsMediaCameraTest.h b/multimedia_lite/multimedia_posix/camera/src/ActsMediaCameraTest.h new file mode 100755 index 0000000000000000000000000000000000000000..4559cdefd571beadfddf1826223b0a21a9191379 --- /dev/null +++ b/multimedia_lite/multimedia_posix/camera/src/ActsMediaCameraTest.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2020 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 CAMERA_DEMO_TEST_H +#define CAMERA_DEMO_TEST_H + +#include "gtest/gtest.h" + +namespace OHOS::Media { +/* 定义函数回调FLAG取值常量 */ +enum TestCallBackFlag { + FLAG0 = 0, + FLAG1 = 1, +}; + +/* 预定义测试数据:VideoSize */ +enum TestVideoSize { + WIDTH = 1920, + HEIGHT = 1080, +}; + +class ActsMediaCameraTest : public testing::Test { +public: + // SetUpTestCase:测试套预置动作,在第一个TestCase之前执行 + static void SetUpTestCase(void); + // TearDownTestCase:测试套清理动作,在最后一个TestCase之后执行 + static void TearDownTestCase(void); + // 用例的预置动作 + void SetUp(void); + // 用例的清理动作 + void TearDown(void); + // 定义两个常量 正常cameraID 和 异常 cameraID + static const std::string NORMALID; + static const std::string ABNORMALID; +}; + +const std::string ActsMediaCameraTest::NORMALID = "0"; +const std::string ActsMediaCameraTest::ABNORMALID = "STRING0"; + +class CameraFlag { +public: + // CameraDeviceCallBack Flag + static int32_t g_onCameraAvailableFlag; + static int32_t g_onCameraUnavailableFlag; + static int32_t g_onCameraAccessPrioritiesChangedFlag; + static int32_t g_onTorchModeAvailableFlag; + static int32_t g_onTorchModeUnavailableFlag; + // CameraStateCallback + static int32_t g_onCreatedFlag; + static int32_t g_onCreateFailedFlag; + static int32_t g_onReleasedFlag; + // FrameStateCallback + static int32_t g_onCaptureTriggerAbortedFlag; + static int32_t g_onCaptureTriggerCompletedFlag; + static int32_t g_onCaptureTriggerStartedFlag; + static int32_t g_onFrameCompletedFlag; + static int32_t g_onFrameErrorFlag; + static int32_t g_onFrameProgressedFlag; + static int32_t g_onFrameStartedFlag; +}; +// CameraDeviceCallBack +int32_t CameraFlag::g_onCameraAvailableFlag = FLAG0; +int32_t CameraFlag::g_onCameraUnavailableFlag = FLAG0; +int32_t CameraFlag::g_onCameraAccessPrioritiesChangedFlag = FLAG0; +int32_t CameraFlag::g_onTorchModeAvailableFlag = FLAG0; +int32_t CameraFlag::g_onTorchModeUnavailableFlag = FLAG0; +// CameraStateCallback +int32_t CameraFlag::g_onCreatedFlag = FLAG0; +int32_t CameraFlag::g_onCreateFailedFlag = FLAG0; +int32_t CameraFlag::g_onReleasedFlag = FLAG0; +// FrameStateCallback +int32_t CameraFlag::g_onCaptureTriggerAbortedFlag = FLAG0; +int32_t CameraFlag::g_onCaptureTriggerCompletedFlag = FLAG0; +int32_t CameraFlag::g_onCaptureTriggerStartedFlag = FLAG0; +int32_t CameraFlag::g_onFrameCompletedFlag = FLAG0; +int32_t CameraFlag::g_onFrameErrorFlag = FLAG0; +int32_t CameraFlag::g_onFrameProgressedFlag = FLAG0; +int32_t CameraFlag::g_onFrameStartedFlag = FLAG0; +} // namespace OHOS::Media +#endif // CAMERA_DEMO_TEST_H \ No newline at end of file diff --git a/multimedia_lite/multimedia_posix/player/BUILD.gn b/multimedia_lite/multimedia_posix/player/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..d794ce0c14f9501e21e2c26f7fe05a0427723f0f --- /dev/null +++ b/multimedia_lite/multimedia_posix/player/BUILD.gn @@ -0,0 +1,93 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsPlayerTest") { + suite_name = "acts" + sources = [ + "src/player_test.cpp", + ] + + include_dirs = [ + "//foundation/multimedia/services/media_lite/common/include", + "//foundation/multimedia/services/media_lite/player/include", + "//third_party/bounds_checking_function/include", + ] + outdir = rebase_path("$root_out_dir") + ldflags = ["-L$outdir"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/middleware/source_ohos/common/hitimer/lib"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/middleware/source_ohos/common/log/lib"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/middleware/source_ohos/common/mbuffer/lib"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/middleware/source_ohos/common/msghandler/lib"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/middleware/source_ohos/component/dcf/lib"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/middleware/source_ohos/component/dtcf/lib"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/middleware/source_ohos/component/eventhub/lib"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/middleware/source_ohos/component/fileformat/common/lib"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/middleware/source_ohos/component/fileformat/exif/lib"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/middleware/source_ohos/component/fileformat/mp4/lib"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/middleware/source_ohos/component/fileformat/ts/lib"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/middleware/source_ohos/component/fstool/lib"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/middleware/source_ohos/component/recorder_pro/lib"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/middleware/source_ohos/component/statemachine/fsm/lib"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/middleware/source_ohos/component/statemachine/hfsm/lib"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/middleware/source_ohos/component/storage/lib"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/middleware/source_ohos/media_adpt/hi3516dv300"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/middleware/source_ohos/thirdparty/openexif/lib"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/middleware/source_ohos/thirdparty/timers/lib"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/hardware/media_ohos/hal/audio/lib"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/hardware/media_ohos/hal/codec/lib"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/hardware/media_ohos/hal/common/lib"] + ldflags += ["-L${ohos_root_path}/vendor/hisi/hi35xx/hardware/media_ohos/hal/format/lib"] + ldflags += ["-lc"] + ldflags += ["-lm"] + ldflags += ["-lpthread"] + ldflags += ["-ldl"] + ldflags += ["-lstdc++"] + ldflags += ["-lsecurec"] + ldflags += ["-lexif"] + ldflags += ["-lopenexif"] + ldflags += ["-std=c++11"] + ldflags += ["-lmwlog"] + ldflags += ["-lmbuf"] + ldflags += ["-l_hicalcflicker"] + ldflags += ["-lmpi"] + ldflags += ["-lisp"] + ldflags += ["-ldnvqe"] + ldflags += ["-lupvqe"] + ldflags += ["-laacdec"] + ldflags += ["-laacenc"] + ldflags += ["-laaccomm"] + ldflags += ["-l_hiawb"] + ldflags += ["-l_hildci"] + ldflags += ["-l_hidrc"] + ldflags += ["-l_hiir_auto"] + ldflags += ["-l_hidehaze"] + ldflags += ["-l_hiacs"] + ldflags += ["-l_hiae"] + ldflags += ["-lVoiceEngine"] + ldflags += ["-ltde"] + ldflags += ["-laudio_hw"] + ldflags += ["-lcodec"] + ldflags += ["-lhiaacdec"] + ldflags += ["-lsys_hal"] + ldflags += ["-lformat_demuxer"] + ldflags += ["-live"] + ldflags += ["-lhdmi"] + deps = [ + "//third_party/bounds_checking_function:libsec_shared", + "//foundation/multimedia/services/media_lite:player", + ] + + cflags = [ "-Wno-error" ] +} diff --git a/multimedia_lite/multimedia_posix/player/Test.json b/multimedia_lite/multimedia_posix/player/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..6263f7258e1368744b996c622de1db1d62b38e48 --- /dev/null +++ b/multimedia_lite/multimedia_posix/player/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for hcpptest demo test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/multimedia", + "target": "/test_root/multimedia" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/multimedia/ActsPlayerTest.bin" + } +} \ No newline at end of file diff --git a/multimedia_lite/multimedia_posix/player/src/player_test.cpp b/multimedia_lite/multimedia_posix/player/src/player_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..6b31759d2f9fcfa900feff15705954c558c4101c --- /dev/null +++ b/multimedia_lite/multimedia_posix/player/src/player_test.cpp @@ -0,0 +1,505 @@ +/* + * Copyright (c) 2020 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 "fstream" +#include "iostream" +#include "thread" +#include "unistd.h" +#include +#include +#include +#include "securec.h" +#include "gtest/gtest.h" +#include "surface.h" +#include "source.h" +#include "player.h" +#include "format.h" + +const int FRAME_RATE_DEFAULT = 30; +const int FILE_PATH_LEN = 2048; + +#define DOFUNC_STR_NORET(func, str) \ + do { \ + HI_S32 s32Ret = 0; \ + s32Ret = func; \ + if (s32Ret != HI_SUCCESS) \ + { \ + printf("[liteplayer_sample][%s:%d] ret:%d, %s \n", __FILE__, __LINE__, s32Ret, str); \ + return NULL; \ + } \ + } while (0) + +#define DOFUNC_STR_RET(func, str) \ + do { \ + HI_S32 s32Ret = 0; \ + s32Ret = func; \ + if (s32Ret != HI_SUCCESS) \ + { \ + printf("[liteplayer_sample][%s:%d] ret:%d, %s \n", __FILE__, __LINE__, s32Ret, str); \ + return HI_FAILURE; \ + } \ + } while (0) + +#define IS_OK(ret) \ +do { \ + if (ret != 0) { \ + printf("[%s: %d] ret:%d\n", __func__, __LINE__, ret); \ + } \ +} while (0) + +using namespace std; +using namespace OHOS::Media; +using namespace testing::ext; + +namespace OHOS { +using OHOS::Media::Player; +using OHOS::Media::PlayerSeekMode; +using OHOS::Media::Source; +using OHOS::Media::Format; +using OHOS::Media::StreamSource; +using OHOS::Media::StreamCallback; + +class StreamSourceSample; +class StreamSource; +class StreamCallback; +class Format; +typedef struct TagTestSample { + std::shared_ptr adaptr; + pthread_t process; + pthread_mutex_t mutex; + int32_t isThreadRunning; + int32_t sourceType; + char filePath[FILE_PATH_LEN]; + std::shared_ptr streamSample; +} TestSample; + +typedef struct TagIdleBuffer { + size_t idx; + size_t offset; + size_t size; +} IdleBuffer; + +class StreamSourceSample :public StreamSource { +public: + StreamSourceSample(void); + ~StreamSourceSample(void); + void OnBufferAvailable(size_t index, size_t offset, size_t size); + void SetStreamCallback(const std::shared_ptr &callback); + uint8_t *GetBufferAddress(size_t idx); + void QueueBuffer(size_t index, size_t offset, size_t size, int64_t timestampUs, uint32_t flags); + int GetAvailableBuffer(IdleBuffer* buffer); + std::weak_ptr m_callBack; +private: + + std::vector aviableBuffer; + pthread_mutex_t m_mutex; +}; + +StreamSourceSample::StreamSourceSample(void) +{ + aviableBuffer.clear(); + pthread_mutex_init(&m_mutex, nullptr); +} + +StreamSourceSample::~StreamSourceSample(void) +{ + aviableBuffer.clear(); + pthread_mutex_destroy(&m_mutex); +} + +void StreamSourceSample::SetStreamCallback(const std::shared_ptr &callback) +{ + m_callBack = callback; +} + +uint8_t *StreamSourceSample::GetBufferAddress(size_t idx) +{ + std::shared_ptr callback = m_callBack.lock(); + if (callback == nullptr) { + return nullptr; + } + return callback->GetBuffer(idx); +} + +void StreamSourceSample::QueueBuffer(size_t index, size_t offset, size_t size, int64_t timestampUs, uint32_t flags) +{ + std::shared_ptr callback = m_callBack.lock(); + if (callback == nullptr) { + return; + } + callback->QueueBuffer(index, offset, size, timestampUs, flags); +} + +void StreamSourceSample::OnBufferAvailable(size_t index, size_t offset, size_t size) +{ + IdleBuffer buffer; + pthread_mutex_lock(&m_mutex); + buffer.idx = index; + buffer.offset = offset; + buffer.size = size; + aviableBuffer.push_back(buffer); + pthread_mutex_unlock(&m_mutex); +} + +int StreamSourceSample::GetAvailableBuffer(IdleBuffer* buffer) +{ + pthread_mutex_lock(&m_mutex); + if (aviableBuffer.empty()) { + pthread_mutex_unlock(&m_mutex); + return -1; + } + *buffer = aviableBuffer[0]; + aviableBuffer.erase(aviableBuffer.begin()); + pthread_mutex_unlock(&m_mutex); + return 0; +} +static void* StreamProcess(void* arg) +{ +#define READ_LEN (1024) + IdleBuffer buffer; + int ret; + uint8_t *data = nullptr; + size_t readLen; + size_t len; + TestSample *sample = (TestSample *)arg; + FILE* pFile = fopen(sample->filePath, "rb"); + if (pFile == nullptr) { + return nullptr; + } + prctl(PR_SET_NAME, "StreamProc", 0, 0, 0); + printf("[%s,%d] file:%s\n", __func__, __LINE__, sample->filePath); + while(sample->isThreadRunning) { + ret = sample->streamSample->GetAvailableBuffer(&buffer); + if (ret != 0) { + usleep(20000); + continue; + } + data = sample->streamSample->GetBufferAddress(buffer.idx); + if (data == nullptr) { + printf("[%s, %d] get buffer null", __func__, __LINE__); + break; + } + len = (buffer.size < READ_LEN) ? buffer.size : READ_LEN; + readLen = fread(data + buffer.offset, 1, len, pFile); + if (readLen <= len && readLen > 0) { + sample->streamSample->QueueBuffer(buffer.idx, buffer.offset, readLen, 0, 8); + } else { + sample->streamSample->QueueBuffer(buffer.idx, buffer.offset, readLen, 0, 4); + break; + } + } + fclose(pFile); + printf("[%s,%d]\n", __func__, __LINE__); + return NULL; +} + +void SetSchParam(void) +{ + int ret; + struct sched_param param; + pthread_attr_t attr; + ret = pthread_attr_getschedparam(&attr, ¶m); + param.sched_priority = 9; + ret = pthread_setschedparam(pthread_self(), SCHED_RR, ¶m); +} +} // namespace OHOS + +using namespace OHOS; +const int HI_SUCCESS = 0; +const int HI_FAILURE = -1; + +static TagTestSample g_tagTestSample; +static const char *VEDIO_FILE_NAME = "0506_480p.mp4"; +static const char *AUDIO_FILE_NAME = "AACLC_1channel_001.aac"; +class Demo : public testing::Test { +protected: + static void SetUpTestCase(void) { + } + static void TearDownTestCase(void) { + } + virtual void SetUp() + { + SetSchParam(); + g_tagTestSample.adaptr = std::make_shared(); + } + virtual void TearDown() + { + int32_t ret = g_tagTestSample.adaptr->Reset(); + ret = g_tagTestSample.adaptr->Release(); + if (g_tagTestSample.sourceType == 2) { + pthread_mutex_lock(&g_tagTestSample.mutex); + g_tagTestSample.isThreadRunning = 0; + pthread_mutex_unlock(&g_tagTestSample.mutex); + pthread_join(g_tagTestSample.process, nullptr); + pthread_mutex_destroy(&g_tagTestSample.mutex); + } + } +}; + +static int32_t CreateAndSetSource(int32_t sourceType, const char *argv) +{ + if (sourceType != 1 && sourceType != 2) { + printf("unsupport!\n", errno); + return -1; + } + g_tagTestSample.sourceType = sourceType; + if (realpath(argv, g_tagTestSample.filePath) == nullptr) { + printf("realpath input file failed, errno: %d!\n", errno); + return -1; + } + if (sourceType == 1) { + std::string uri(g_tagTestSample.filePath); + std::map header; + Source source(uri, header); + int32_t ret = g_tagTestSample.adaptr->SetSource(source); + EXPECT_EQ(HI_SUCCESS, ret); + } else { + struct stat stFileState = {0}; + if (lstat(g_tagTestSample.filePath, &stFileState) != 0) { + printf("lstat %s failed, please check the file exist, errno:%d\n", g_tagTestSample.filePath, errno); + return -1; + } + g_tagTestSample.streamSample = std::make_shared(); + Format formats; + formats.SetFormat(CODEC_MIME, MIME_AUDIO_AAC); + Source source(g_tagTestSample.streamSample, formats); + + int32_t ret1 = g_tagTestSample.adaptr->SetSource(source); // forward + EXPECT_EQ(HI_SUCCESS, ret1); + pthread_mutex_init(&g_tagTestSample.mutex, nullptr); + g_tagTestSample.isThreadRunning = 1; + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setstacksize(&attr, 0x10000); + int32_t ret = pthread_create(&g_tagTestSample.process, &attr, StreamProcess, &g_tagTestSample); + if (ret != 0) { + printf("pthread_create failed %d\n", ret); + g_tagTestSample.isThreadRunning = 0; + return -1; + } + } + return 0; +} + +HWTEST_F(Demo, Test_SetSource01, TestSize.Level0){ + int32_t ret = CreateAndSetSource(1, VEDIO_FILE_NAME); + EXPECT_EQ(HI_SUCCESS, ret); +} + +HWTEST_F(Demo, Test_Prepare01, TestSize.Level0){ + int32_t ret = CreateAndSetSource(1, VEDIO_FILE_NAME); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Prepare(); + EXPECT_EQ(HI_SUCCESS, ret); +} + +HWTEST_F(Demo, Test_Prepare02, TestSize.Level0){ + int32_t ret = g_tagTestSample.adaptr->Prepare(); + EXPECT_EQ(HI_FAILURE, ret); +} + +HWTEST_F(Demo, Test_Play01, TestSize.Level0){ + int32_t ret = CreateAndSetSource(1, VEDIO_FILE_NAME); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Prepare(); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Play(); + sleep(10); + EXPECT_EQ(HI_SUCCESS, ret); +} + +HWTEST_F(Demo, Test_Play02, TestSize.Level0){ + int32_t ret = g_tagTestSample.adaptr->Play(); + EXPECT_EQ(HI_FAILURE, ret); +} + +HWTEST_F(Demo, Test_Play03, TestSize.Level0){ + int32_t ret = CreateAndSetSource(2, AUDIO_FILE_NAME); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Prepare(); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Play(); + sleep(10); + EXPECT_EQ(HI_SUCCESS, ret); +} + +HWTEST_F(Demo, Test_IsPlaying01, TestSize.Level0){ + int32_t ret = CreateAndSetSource(1, VEDIO_FILE_NAME); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Prepare(); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Play(); + EXPECT_EQ(HI_SUCCESS, ret); + sleep(10); + bool flag = g_tagTestSample.adaptr->IsPlaying(); // IsLoop() + EXPECT_EQ(true, flag); +} + +HWTEST_F(Demo, Test_Stop01, TestSize.Level0){ + int32_t ret = CreateAndSetSource(1, VEDIO_FILE_NAME); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Prepare(); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Play(); + EXPECT_EQ(HI_SUCCESS, ret); + sleep(10); + ret = g_tagTestSample.adaptr->Stop(); + EXPECT_EQ(HI_SUCCESS, ret); +} + +HWTEST_F(Demo, Test_Pause01, TestSize.Level0){ + int32_t ret = CreateAndSetSource(1, VEDIO_FILE_NAME); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Prepare(); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Play(); + EXPECT_EQ(HI_SUCCESS, ret); + sleep(10); + ret = g_tagTestSample.adaptr->Pause(); + EXPECT_EQ(HI_SUCCESS, ret); +} + + +HWTEST_F(Demo, Test_SetVolume01, TestSize.Level0){ + int32_t ret = CreateAndSetSource(1, VEDIO_FILE_NAME); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Prepare(); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Play(); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->SetVolume(50, 50); + EXPECT_EQ(HI_SUCCESS, ret); +} + +HWTEST_F(Demo, Test_IsLooping01, TestSize.Level0){ + int32_t ret = CreateAndSetSource(1, VEDIO_FILE_NAME); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Prepare(); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Play(); + EXPECT_EQ(HI_SUCCESS, ret); + bool flag = g_tagTestSample.adaptr->IsLooping(); + EXPECT_EQ(false, flag); +} + +HWTEST_F(Demo, Test_GetPlayerState01, TestSize.Level0){ + int32_t ret = CreateAndSetSource(1, VEDIO_FILE_NAME); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Prepare(); + EXPECT_EQ(HI_SUCCESS, ret); + int32_t state; + ret = g_tagTestSample.adaptr->GetPlayerState(state); + EXPECT_EQ(HI_SUCCESS, ret); +} + +HWTEST_F(Demo, Test_GetCurrentPosition01, TestSize.Level0){ + int32_t ret = CreateAndSetSource(1, VEDIO_FILE_NAME); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Prepare(); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Play(); + EXPECT_EQ(HI_SUCCESS, ret); + sleep(10); + int64_t currentPosition; + ret = g_tagTestSample.adaptr->GetCurrentPosition(currentPosition); + EXPECT_EQ(HI_SUCCESS, ret); +} + +HWTEST_F(Demo, Test_GetDuration01, TestSize.Level0){ + int32_t ret = CreateAndSetSource(1, VEDIO_FILE_NAME); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Prepare(); + EXPECT_EQ(HI_SUCCESS, ret); + int64_t duration; + ret = g_tagTestSample.adaptr->GetDuration(duration); + EXPECT_EQ(HI_SUCCESS, ret); +} + +HWTEST_F(Demo, Test_GetVideoWidth01, TestSize.Level0){ + int32_t ret = CreateAndSetSource(1, VEDIO_FILE_NAME); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Prepare(); + EXPECT_EQ(HI_SUCCESS, ret); + int32_t videoWidth; + ret = g_tagTestSample.adaptr->GetVideoWidth(videoWidth); + EXPECT_EQ(HI_SUCCESS, ret); +} + +HWTEST_F(Demo, Test_GetVideoHeight01, TestSize.Level0){ + int32_t ret = CreateAndSetSource(1, VEDIO_FILE_NAME); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Prepare(); + EXPECT_EQ(HI_SUCCESS, ret); + int32_t videoHeight; + ret = g_tagTestSample.adaptr->GetVideoHeight(videoHeight); + EXPECT_EQ(HI_SUCCESS, ret); +} + +HWTEST_F(Demo, Test_SetPlaybackSpeed01, TestSize.Level0){ + int32_t ret = CreateAndSetSource(1, VEDIO_FILE_NAME); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Prepare(); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Play(); +} + +HWTEST_F(Demo, Test_GetPlaybackSpeed01, TestSize.Level0){ + int32_t ret = CreateAndSetSource(1, VEDIO_FILE_NAME); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Prepare(); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Play(); + EXPECT_EQ(HI_SUCCESS, ret); +} + +HWTEST_F(Demo, Test_SetLoop01, TestSize.Level0){ + int32_t ret = CreateAndSetSource(1, VEDIO_FILE_NAME); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Prepare(); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Play(); + EXPECT_EQ(HI_SUCCESS, ret); + sleep(10); + bool loop = true; + ret = g_tagTestSample.adaptr->SetLoop(loop); + EXPECT_EQ(HI_SUCCESS, ret); +} + +HWTEST_F(Demo, Test_Reset01, TestSize.Level0){ + int32_t ret = CreateAndSetSource(1, VEDIO_FILE_NAME); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Prepare(); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Play(); + EXPECT_EQ(HI_SUCCESS, ret); + sleep(10); + ret = g_tagTestSample.adaptr->Reset(); + EXPECT_EQ(HI_SUCCESS, ret); +} + +HWTEST_F(Demo, Test_Release01, TestSize.Level0){ + int32_t ret = CreateAndSetSource(1, VEDIO_FILE_NAME); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Prepare(); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Play(); + EXPECT_EQ(HI_SUCCESS, ret); + sleep(10); + ret = g_tagTestSample.adaptr->Reset(); + EXPECT_EQ(HI_SUCCESS, ret); + ret = g_tagTestSample.adaptr->Release(); + EXPECT_EQ(HI_SUCCESS, ret); +} \ No newline at end of file diff --git a/multimedia_lite/multimedia_posix/recorder/BUILD.gn b/multimedia_lite/multimedia_posix/recorder/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..cf6e0f9f04ba533e090a871abe87f30e0ce49f74 --- /dev/null +++ b/multimedia_lite/multimedia_posix/recorder/BUILD.gn @@ -0,0 +1,61 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsMediaRecorderTest") { + suite_name = "acts" + sources = [ + "src/RecoderTest.cpp", + ] + + include_dirs = [ + "src", + "//kernel/liteos_a/kernel/include", + "//kernel/liteos_a/kernel/common", + "//foundation/multimedia/services/media_lite/camera/src", + "//foundation/multimedia/services/media_lite/audio_capture/include", + "//foundation/multimedia/services/media_lite/common/include", + "//foundation/multimedia/services/media_lite/recorder/include", + "//third_party/bounds_checking_function/include", + "//third_party/bounds_checking_function/include", + ] + outdir = rebase_path("$root_out_dir") + ldflags = ["-L$outdir"] + ldflags += ["-Wl,-rpath-link,$outdir"] + ldflags += ["-Wl,-L$outdir"] + ldflags += ["-lc"] + ldflags += ["-lm"] + ldflags += ["-lpthread"] + ldflags += ["-ldl"] + ldflags += ["-lstdc++"] + ldflags += ["-lformat_muxer"] + ldflags += ["-live"] + ldflags += ["-lmp4"] + ldflags += ["-lrecorder_pro"] + ldflags += ["-lfileformat"] + ldflags += ["-ldtcf"] + ldflags += ["-lhitimer"] + ldflags += ["-lmedia_common"] + ldflags += ["-laudio_capturer"] + ldflags += ["-luproc"] + ldflags += ["-lcodec"] + ldflags += ["-laudio_hw"] + deps = [ + "//third_party/bounds_checking_function:libsec_shared", + "//foundation/multimedia/services/media_lite:recorder", + "//foundation/multimedia/services/media_lite:camera", + "//foundation/multimedia/services/media_lite:audio_capturer", + ] + cflags = [ "-Wno-error" ] +} diff --git a/multimedia_lite/multimedia_posix/recorder/Test.json b/multimedia_lite/multimedia_posix/recorder/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..5192478601aadb75637c6b37ff4249551be6675b --- /dev/null +++ b/multimedia_lite/multimedia_posix/recorder/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for hcpptest demo test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/multimedia", + "target": "/test_root/multimedia" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/multimedia/ActsMediaRecorderTest.bin" + } +} \ No newline at end of file diff --git a/multimedia_lite/multimedia_posix/recorder/src/RecoderTest.cpp b/multimedia_lite/multimedia_posix/recorder/src/RecoderTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..d868b8c89d6275e6f1c402359fa32854619f85c0 --- /dev/null +++ b/multimedia_lite/multimedia_posix/recorder/src/RecoderTest.cpp @@ -0,0 +1,1073 @@ +/* + * Copyright (c) 2020 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 "camera_config.h" +#include "camera_kit.h" +#include "camera_state_callback.h" +#include "event_handler.h" +#include "frame_config.h" +#include "frame_state_callback.h" +#include "fstream" +#include "iostream" +#include "recorder.h" +#include "surface.h" +#include "thread" +#include "unistd.h" +#include "gtest/gtest.h" +#include + +#define FRAME_RATE_DEFAULT 30 +using namespace std; +using namespace OHOS::Media; + +using namespace testing::ext; + +EventHandler *g_hdl = nullptr; + +class RecoderTest : public testing::Test { +protected: + static void SetUpTestCase(void) + { + g_hdl = new EventHandler; + } + static void TearDownTestCase(void) + { + if (g_hdl != nullptr) { + delete g_hdl; + g_hdl = NULL; + } + } + virtual void SetUp() {} + virtual void TearDown() {} +}; + +/* +This is recorder format struct +*/ +typedef struct Format { + VideoSourceType VideoSource; + AudioSourceType AudioSource; + int32_t AudioChannels; + AudioCodecFormat AudioEncoder; + int32_t AudioEncodingBitRate; + int32_t AudioSampleRate; + VideoCodecFormat VideoEncoder; + int32_t VideoEncodingBitRate; + int32_t VideoFrameRate; + int32_t width; + int32_t height; + double CaptureRate; +} RecorderFormat; + +namespace OHOS { +void GenSurface1(RecorderFormat ft); +void TestSaveCapture(char *p, uint32_t size) +{ + cout << "Start saving picture" << endl; + struct timeval tv; + gettimeofday(&tv, NULL); + struct tm *ltm = localtime(&tv.tv_sec); + ostringstream ss("Capture_"); + ss << "Capture" << ltm->tm_hour << "-" << ltm->tm_min << "-" << ltm->tm_sec << ".jpg"; + + ofstream pic("/tmp/" + ss.str()); + cout << "write " << size << " bytes" << endl; + pic.write(p, size); + cout << "Saving picture end" << endl; +} + +class TestFrameStateCallback : public FrameStateCallback { + void OnFrameCompleted(Camera &camera, FrameConfig &frameConfig, FrameResult frameResult) override + { + if (frameConfig.GetFrameConfigType() != CAPTURE) { + cout << "Test frame completed." << endl; + return; + } + // write file; + cout << "Try to read picture." << endl; + auto surfaceList = frameConfig.GetSurfaceList(); + Surface *surface = nullptr; + if (surfaceList->empty()) { + delete &frameConfig; + cout << "Receive empty frame config" << endl; + return; + } + surface = surfaceList->front(); + SurfaceBuffer *buffer = surface->AcquireBuffer(); + if (buffer != nullptr) { + TestSaveCapture(static_cast(buffer->GetVirAddr()), buffer->GetSize()); + surface->ReleaseBuffer(buffer); + } + + delete surface; + delete &frameConfig; + } +}; + +class TestConsumer : public IBufferConsumerListener { + void OnBufferAvailable() override + { + return; + } +}; + +class TestPreviewCameraStateCallback : public CameraStateCallback { +public: + TestPreviewCameraStateCallback() : camera_(nullptr), fsc_(nullptr), surface_(nullptr) {} + ~TestPreviewCameraStateCallback() + { + if (surface_ != nullptr) { + delete surface_; + } + if (fsc_ != nullptr) { + delete fsc_; + } + } + void GenSurface() + { + surface_ = Surface::CreateSurface(); + auto consumer = new TestConsumer; + surface_->RegisterConsumerListener(*consumer); + } + void OnCreated(Camera &c) override + { + fsc_ = new TestFrameStateCallback; + CameraConfig *cc = CameraConfig::CreateCameraConfig(); + cc->SetFrameStateCallback(fsc_, g_hdl); + c.Configure(cc); + GenSurface(); + surface_->SetUserData("region_position_x", "100"); + surface_->SetUserData("region_position_y", "100"); + surface_->SetUserData("region_width", "192"); + surface_->SetUserData("region_height", "108"); + surface_->SetQueueSize(2); + surface_->SetWidthAndHeight(1920, 1080); + camera_ = &c; + } + void OnCreateFailed(std::string cameraId, int32_t errorCode) override + { + printf("OnCreateFailed\n"); + } + void OnReleased(Camera &c) override {} + Surface *surface_; + Camera *camera_; + FrameStateCallback *fsc_; +}; + +class TestCameraStateCallback : public CameraStateCallback { +public: + TestCameraStateCallback() : camera_(nullptr), fsc_(nullptr), surface_(nullptr) + { + recorder_ = new Recorder(); + } + ~TestCameraStateCallback() + { + if (recorder_ != nullptr) { + delete recorder_; + } + if (fsc_ != nullptr) { + delete fsc_; + } + } + void GenSurface(VideoEncodeParam *param) + { + std::cout << "recorder main " << std::endl; + int ret = 0; + int32_t sampleRate = 48000; + int32_t channelCount = 1; + AudioCodecFormat audioFormat = AAC_LC; + AudioSourceType inputSource = AUDIO_MIC; + int32_t audioEncodingBitRate = sampleRate; + VideoSourceType source = VIDEO_SOURCE_SURFACE_ES; + int32_t frameRate = 30; + float fps = 30; + int32_t rate = 4096; + int32_t sourceId = 0; + int32_t audioSourceId = 0; + int32_t width = 1920; + int32_t height = 1080; + VideoCodecFormat encoder; + if (param->enType == ENCODE_H265) { + encoder = HEVC; + } else { + encoder = H264; + } + if (param->picSize == PIC_1080P) { + width = 1920; + height = 1080; + } else { + width = 1280; + height = 720; + } + if ((ret = recorder_->SetVideoSource(source, sourceId)) != SUCCESS) { + printf("SetVideoSource fialed :0x%x\n", ret); + } + if ((ret = recorder_->SetVideoEncoder(sourceId, encoder)) != SUCCESS) { + printf("SetVideoEncoder fialed :0x%x\n", ret); + } + if ((ret = recorder_->SetVideoSize(sourceId, width, height)) != SUCCESS) { + printf("SetVideoSize fialed :0x%x\n", ret); + } + if ((ret = recorder_->SetVideoFrameRate(sourceId, frameRate)) != SUCCESS) { + printf("SetVideoFrameRate fialed :0x%x\n", ret); + } + if ((ret = recorder_->SetVideoEncodingBitRate(sourceId, rate)) != SUCCESS) { + printf("SetVideoEncodingBitRate fialed :0x%x\n", ret); + } + if ((ret = recorder_->SetCaptureRate(sourceId, frameRate)) != SUCCESS) { + printf("SetCaptureRate fialed :0x%x\n", ret); + } + if ((ret = recorder_->SetAudioSource(inputSource, audioSourceId)) != SUCCESS) { + printf("SetAudioSource fialed :0x%x\n", ret); + } + if ((ret = recorder_->SetAudioEncoder(audioSourceId, audioFormat)) != SUCCESS) { + printf("SetAudioEncoder fialed :0x%x\n", ret); + } + if ((ret = recorder_->SetAudioSampleRate(audioSourceId, sampleRate)) != SUCCESS) { + printf("SetAudioSampleRate fialed :0x%x\n", ret); + } + if ((ret = recorder_->SetAudioChannels(audioSourceId, channelCount)) != SUCCESS) { + printf("SetAudioChannels fialed :0x%x\n", ret); + } + if ((ret = recorder_->SetAudioEncodingBitRate(audioSourceId, audioEncodingBitRate)) != SUCCESS) { + printf("SetAudioEncodingBitRate fialed :0x%x\n", ret); + } + } + + int32_t GenSurface1(RecorderFormat ft) + { + VideoSourceType source = ft.VideoSource; + AudioSourceType inputSource = ft.AudioSource; + int32_t channelCount = ft.AudioChannels; + AudioCodecFormat audioFormat = ft.AudioEncoder; + int32_t audioEncodingBitRate = ft.AudioEncodingBitRate; + int32_t sampleRate = ft.AudioSampleRate; + VideoCodecFormat encoder = ft.VideoEncoder; + int32_t rate = ft.VideoEncodingBitRate; + int32_t frameRate = ft.VideoFrameRate; + int32_t width = ft.width; + int32_t height = ft.height; + double fps = ft.CaptureRate; + int32_t sourceId = 0; + int32_t audioSourceId = 0; + int32_t ret = 0; + if ((ret = recorder_->SetVideoSource(source, sourceId)) != SUCCESS) { + printf("SetVideoSource fialed :0x%x\n", ret); + return ret; + } + surface_ = recorder_->GetSurface(sourceId).get(); + surface_->SetWidthAndHeight(width, height); + + printf("SetVideoSource SUCCESS\n"); + if ((ret = recorder_->SetVideoEncoder(sourceId, encoder)) != SUCCESS) { + printf("SetVideoEncoder fialed :0x%x\n", ret); + return ret; + } + printf("SetVideoSource SUCCESS\n"); + if ((ret = recorder_->SetVideoSize(sourceId, width, height)) != SUCCESS) { + printf("SetVideoSize fialed :0x%x\n", ret); + return ret; + } + printf("SetVideoSize SUCCESS\n"); + if ((ret = recorder_->SetVideoFrameRate(sourceId, frameRate)) != SUCCESS) { + printf("SetVideoFrameRate fialed :0x%x\n", ret); + return ret; + } + printf("SetVideoFrameRate SUCCESS\n"); + if ((ret = recorder_->SetVideoEncodingBitRate(sourceId, rate)) != SUCCESS) { + printf("SetVideoEncodingBitRate fialed :0x%x\n", ret); + return ret; + } + printf("SetVideoEncodingBitRate SUCCESS\n"); + if ((ret = recorder_->SetCaptureRate(sourceId, fps)) != SUCCESS) { + printf("SetCaptureRate fialed :0x%x\n", ret); + return ret; + } + if ((ret = recorder_->SetAudioSource(inputSource, audioSourceId)) != SUCCESS) { + printf("SetAudioSource fialed :0x%x\n", ret); + return ret; + } + printf("SetAudioSource SUCCESS\n"); + if ((ret = recorder_->SetAudioEncoder(audioSourceId, audioFormat)) != SUCCESS) { + printf("SetAudioEncoder fialed :0x%x\n", ret); + return ret; + } + printf("SetAudioEncoder SUCCESS\n"); + if ((ret = recorder_->SetAudioSampleRate(audioSourceId, sampleRate)) != SUCCESS) { + printf("SetAudioSampleRate fialed :0x%x\n", ret); + return ret; + } + printf("SetAudioSampleRate SUCCESS\n"); + if ((ret = recorder_->SetAudioChannels(audioSourceId, channelCount)) != SUCCESS) { + printf("SetAudioChannels fialed :0x%x\n", ret); + return ret; + } + printf("SetAudioChannels SUCCESS\n"); + if ((ret = recorder_->SetAudioEncodingBitRate(audioSourceId, audioEncodingBitRate)) != SUCCESS) { + printf("SetAudioEncodingBitRate fialed :0x%x\n", ret); + return ret; + } + printf("SetAudioEncodingBitRate SUCCESS\n"); + if ((ret = recorder_->Prepare()) != SUCCESS) { + printf("Prepare fialed :0x%x\n", ret); + return ret; + } + printf("Prepare SUCCESS\n"); + + return SUCCESS; + } + void OnCreated(Camera &c) override + { + fsc_ = new TestFrameStateCallback; + CameraConfig *cc = CameraConfig::CreateCameraConfig(); + cc->SetFrameStateCallback(fsc_, g_hdl); + c.Configure(cc); + camera_ = &c; + } + void OnCreateFailed(std::string cameraId, int32_t errorCode) override + { + printf("OnCreateFailed\n"); + } + void OnReleased(Camera &c) override {} + Surface *surface_; + Recorder *recorder_; + Camera *camera_; + FrameStateCallback *fsc_; +}; +} // namespace OHOS + +using namespace OHOS; +using namespace std; +FrameConfig *TestCreatCaptureFrameConfig() +{ + FrameConfig *fc = new FrameConfig(CAPTURE); + Surface *surface = Surface::CreateSurface(); + surface->SetWidthAndHeight(1920, 1080); + fc->AddSurface(surface); + return fc; +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_03400 + * @tc.name : test recoder setting parms + * @tc.desc : test recoder setting parms avaliable + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(RecoderTest, Test_Recorder_0010, TestSize.Level0) +{ + CameraKit *cameraKit = new CameraKit(); + CameraDeviceCallback *deviceCallback = new CameraDeviceCallback(); + TestCameraStateCallback *stateCallback = new TestCameraStateCallback(); + EventHandler *handler = new EventHandler(); + cameraKit->RegisterCameraDeviceCallback(deviceCallback, handler); + RecorderFormat fmt = { VIDEO_SOURCE_SURFACE_ES, AUDIO_MIC, 1, AAC_LC, 16000, 24000, H264, 1, 1, 900, 600, 30.0 }; + int32_t ret = stateCallback->GenSurface1(fmt); + EXPECT_EQ(SUCCESS, ret); + std::string cameraId = "camera001"; + cameraKit->CreateCamera(cameraId, stateCallback, handler); + VideoEncodeParam param; + param.enGopMode = VENCODE_GOPMODE_NORMALP; + param.enType = ENCODE_H265; + param.enRcMode = VENCODE_RC_CBR; + param.picSize = PIC_1080P; + FrameConfig *fc = new FrameConfig(RECORD); + fc->AddSurface(stateCallback->surface_); + fc->SetFrameFps(25); + fc->SetVencParam(¶m); + ret = stateCallback->recorder_->Start(); + EXPECT_EQ(SUCCESS, ret); + stateCallback->camera_->StartLoopingCapture(*fc); + sleep(5); + int32_t ret2 = stateCallback->recorder_->Pause(); + EXPECT_EQ(SUCCESS, ret2); + sleep(2); + int32_t ret3 = stateCallback->recorder_->Stop(true); + EXPECT_EQ(SUCCESS, ret3); + stateCallback->camera_->StopLoopingCapture(); + stateCallback->recorder_->Release(); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_03300 + * @tc.name : test recoder setting parms + * @tc.desc : test recoder setting parms avaliable + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(RecoderTest, Test_Recorder_0020, TestSize.Level0) +{ + CameraKit *cameraKit = new CameraKit(); + CameraDeviceCallback *deviceCallback = new CameraDeviceCallback(); + TestCameraStateCallback *stateCallback = new TestCameraStateCallback(); + EventHandler *handler = new EventHandler(); + cameraKit->RegisterCameraDeviceCallback(deviceCallback, handler); + RecorderFormat fmt = { VIDEO_SOURCE_SURFACE_ES, AUDIO_MIC, 1, AAC_LC, 16000, 24000, H264, 1, 1, 800, 600, 30.0 }; + int32_t ret = stateCallback->GenSurface1(fmt); + EXPECT_EQ(SUCCESS, ret); + std::string cameraId = "camera001"; + cameraKit->CreateCamera(cameraId, stateCallback, handler); + VideoEncodeParam param; + param.enGopMode = VENCODE_GOPMODE_NORMALP; + param.enType = ENCODE_H265; + param.enRcMode = VENCODE_RC_CBR; + param.picSize = PIC_1080P; + FrameConfig *fc = new FrameConfig(RECORD); + fc->AddSurface(stateCallback->surface_); + fc->SetFrameFps(25); + fc->SetVencParam(¶m); + ret = stateCallback->recorder_->Start(); + EXPECT_EQ(SUCCESS, ret); + stateCallback->camera_->StartLoopingCapture(*fc); + sleep(5); + int32_t ret2 = stateCallback->recorder_->Pause(); + EXPECT_EQ(SUCCESS, ret2); + sleep(2); + int32_t ret3 = stateCallback->recorder_->Stop(true); + EXPECT_EQ(SUCCESS, ret3); + stateCallback->camera_->StopLoopingCapture(); + stateCallback->recorder_->Release(); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_03200 + * @tc.name : test recoder setting parms + * @tc.desc : test recoder setting parms avaliable + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(RecoderTest, Test_Recorder_0030, TestSize.Level0) +{ + CameraKit *cameraKit = new CameraKit(); + CameraDeviceCallback *deviceCallback = new CameraDeviceCallback(); + TestCameraStateCallback *stateCallback = new TestCameraStateCallback(); + EventHandler *handler = new EventHandler(); + cameraKit->RegisterCameraDeviceCallback(deviceCallback, handler); + RecorderFormat fmt = { VIDEO_SOURCE_SURFACE_ES, AUDIO_MIC, 1, AAC_LC, 16000, 24000, H264, 1, 1, 1920, 1080, 30.0 }; + int32_t ret = stateCallback->GenSurface1(fmt); + EXPECT_EQ(SUCCESS, ret); + std::string cameraId = "camera001"; + cameraKit->CreateCamera(cameraId, stateCallback, handler); + VideoEncodeParam param; + param.enGopMode = VENCODE_GOPMODE_NORMALP; + param.enType = ENCODE_H265; + param.enRcMode = VENCODE_RC_CBR; + param.picSize = PIC_1080P; + FrameConfig *fc = new FrameConfig(RECORD); + fc->AddSurface(stateCallback->surface_); + fc->SetFrameFps(25); + fc->SetVencParam(¶m); + ret = stateCallback->recorder_->Start(); + EXPECT_EQ(SUCCESS, ret); + stateCallback->camera_->StartLoopingCapture(*fc); + sleep(5); + int32_t ret2 = stateCallback->recorder_->Pause(); + EXPECT_EQ(SUCCESS, ret2); + sleep(2); + int32_t ret3 = stateCallback->recorder_->Stop(true); + EXPECT_EQ(SUCCESS, ret3); + stateCallback->camera_->StopLoopingCapture(); + stateCallback->recorder_->Release(); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_03100 + * @tc.name : test recoder setting parms + * @tc.desc : test recoder setting parms avaliable + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(RecoderTest, Test_Recorder_0040, TestSize.Level0) +{ + CameraKit *cameraKit = new CameraKit(); + CameraDeviceCallback *deviceCallback = new CameraDeviceCallback(); + TestCameraStateCallback *stateCallback = new TestCameraStateCallback(); + EventHandler *handler = new EventHandler(); + cameraKit->RegisterCameraDeviceCallback(deviceCallback, handler); + RecorderFormat fmt = { VIDEO_SOURCE_SURFACE_ES, AUDIO_MIC, 1, AAC_LC, 16000, 24000, HEVC, 1, 1, 1920, 1080, 30.0 }; + int32_t ret = stateCallback->GenSurface1(fmt); + EXPECT_EQ(SUCCESS, ret); + std::string cameraId = "camera001"; + cameraKit->CreateCamera(cameraId, stateCallback, handler); + VideoEncodeParam param; + param.enGopMode = VENCODE_GOPMODE_NORMALP; + param.enType = ENCODE_H265; + param.enRcMode = VENCODE_RC_CBR; + param.picSize = PIC_1080P; + FrameConfig *fc = new FrameConfig(RECORD); + fc->AddSurface(stateCallback->surface_); + fc->SetFrameFps(25); + fc->SetVencParam(¶m); + ret = stateCallback->recorder_->Start(); + EXPECT_EQ(SUCCESS, ret); + stateCallback->camera_->StartLoopingCapture(*fc); + sleep(5); + int32_t ret2 = stateCallback->recorder_->Pause(); + EXPECT_EQ(SUCCESS, ret2); + sleep(2); + int32_t ret3 = stateCallback->recorder_->Stop(true); + EXPECT_EQ(SUCCESS, ret3); + stateCallback->camera_->StopLoopingCapture(); + stateCallback->recorder_->Release(); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_03000 + * @tc.name : test recoder setting parms + * @tc.desc : test recoder setting parms avaliable + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(RecoderTest, Test_Recorder_0050, TestSize.Level0) +{ + CameraKit *cameraKit = new CameraKit(); + CameraDeviceCallback *deviceCallback = new CameraDeviceCallback(); + TestCameraStateCallback *stateCallback = new TestCameraStateCallback(); + EventHandler *handler = new EventHandler(); + cameraKit->RegisterCameraDeviceCallback(deviceCallback, handler); + RecorderFormat fmt = { VIDEO_SOURCE_SURFACE_ES, AUDIO_MIC, 1, AAC_LC, 16000, 24000, HEVC, 1, 1, 1920, 1080, 30.0 }; + int32_t ret = stateCallback->GenSurface1(fmt); + EXPECT_EQ(SUCCESS, ret); + std::string cameraId = "camera001"; + cameraKit->CreateCamera(cameraId, stateCallback, handler); + VideoEncodeParam param; + param.enGopMode = VENCODE_GOPMODE_NORMALP; + param.enType = ENCODE_H265; + param.enRcMode = VENCODE_RC_CBR; + param.picSize = PIC_1080P; + FrameConfig *fc = new FrameConfig(RECORD); + fc->AddSurface(stateCallback->surface_); + fc->SetFrameFps(25); + fc->SetVencParam(¶m); + ret = stateCallback->recorder_->Start(); + EXPECT_EQ(SUCCESS, ret); + stateCallback->camera_->StartLoopingCapture(*fc); + sleep(5); + int32_t ret2 = stateCallback->recorder_->Pause(); + EXPECT_EQ(SUCCESS, ret2); + sleep(2); + int32_t ret3 = stateCallback->recorder_->Stop(true); + EXPECT_EQ(SUCCESS, ret3); + stateCallback->camera_->StopLoopingCapture(); + stateCallback->recorder_->Release(); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_00100 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetVideoSource01, TestSize.Level0) +{ + cout << "Test_SetVideoSource01 starting..." << endl; + Recorder *recorder = new Recorder(); + int32_t sourceId = 0; + int ret = recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_ES, sourceId); + EXPECT_EQ(SUCCESS, ret); + cout << "Test_SetVideoSource01 ending..." << endl; +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_00200 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetVideoSource02, TestSize.Level0) +{ + cout << "Test_SetVideoSource02 starting..." << endl; + Recorder *recorder = new Recorder(); + int32_t sourceId = 0; + int ret = recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_YUV, sourceId); + EXPECT_EQ(SUCCESS, ret); + cout << "Test_SetVideoSource02 ending..." << endl; +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_00300 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetVideoEncoder01, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t sourceId = 0; + int ret = recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_ES, sourceId); + EXPECT_EQ(SUCCESS, ret); + ret = recorder->SetVideoEncoder(sourceId, HEVC); + EXPECT_EQ(SUCCESS, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_00400 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetVideoEncoder02, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t sourceId = 10000; + int ret = recorder->SetVideoEncoder(sourceId, HEVC); + EXPECT_EQ(ERR_INVALID_PARAM, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_00500 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetVideoSize01, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t sourceId = 0; + int32_t width = 1920; + int32_t height = 1080; + int ret = recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_ES, sourceId); + EXPECT_EQ(SUCCESS, ret); + ret = recorder->SetVideoSize(sourceId, width, height); + EXPECT_EQ(SUCCESS, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_00600 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetVideoSize02, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t sourceId = 0; + int32_t width = -1920; + int32_t height = -1080; + int ret = recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_ES, sourceId); + EXPECT_EQ(SUCCESS, ret); + ret = recorder->SetVideoSize(sourceId, width, height); + EXPECT_EQ(ERR_INVALID_PARAM, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_00700 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetVideoSize03, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t sourceId = 10000; + int32_t width = 1920; + int32_t height = 1080; + int ret = recorder->SetVideoSize(sourceId, width, height); + EXPECT_EQ(ERR_INVALID_PARAM, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_00800 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetVideoFrameRate01, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t sourceId = 0; + int32_t frameRate = 30; + int ret = recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_ES, sourceId); + EXPECT_EQ(SUCCESS, ret); + ret = recorder->SetVideoFrameRate(sourceId, frameRate); + EXPECT_EQ(SUCCESS, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_00900 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetVideoFrameRate02, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t sourceId = 10000; + int32_t frameRate = 30; + int ret = recorder->SetVideoFrameRate(sourceId, frameRate); + EXPECT_EQ(ERR_INVALID_PARAM, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_01000 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetVideoEncodingBitRate01, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t sourceId = 0; + int32_t rate = 4096; + int ret = recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_ES, sourceId); + EXPECT_EQ(SUCCESS, ret); + ret = recorder->SetVideoEncodingBitRate(sourceId, rate); + EXPECT_EQ(SUCCESS, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_01100 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetVideoEncodingBitRate02, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t sourceId = 10000; + int32_t rate = 4096; + int ret = recorder->SetVideoEncodingBitRate(sourceId, rate); + EXPECT_EQ(ERR_INVALID_PARAM, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_01200 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetCaptureRate01, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t sourceId = 0; + double fps = 30.0; + int ret = recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_ES, sourceId); + EXPECT_EQ(SUCCESS, ret); + ret = recorder->SetCaptureRate(sourceId, fps); + EXPECT_EQ(SUCCESS, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_01300 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetCaptureRate02, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t sourceId = 10000; + double fps = 30.0; + int ret = recorder->SetCaptureRate(sourceId, fps); + EXPECT_EQ(ERR_INVALID_PARAM, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_01400 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetAudioSource01, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t audioSourceId = 0; + int ret = recorder->SetAudioSource(AUDIO_MIC, audioSourceId); + EXPECT_EQ(SUCCESS, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_01500 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetAudioSource02, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t audioSourceId = 0; + int ret = recorder->SetAudioSource(AUDIO_SOURCE_INVALID, audioSourceId); + EXPECT_EQ(ERR_INVALID_PARAM, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_01600 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetAudioEncoder01, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t audioSourceId = 0; + int ret = recorder->SetAudioSource(AUDIO_MIC, audioSourceId); + EXPECT_EQ(SUCCESS, ret); + ret = recorder->SetAudioEncoder(audioSourceId, AAC_LC); + EXPECT_EQ(SUCCESS, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_01700 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetAudioEncoder02, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t audioSourceId = 0; + int ret = recorder->SetAudioSource(AUDIO_MIC, audioSourceId); + EXPECT_EQ(SUCCESS, ret); + ret = recorder->SetAudioEncoder(audioSourceId, AUDIO_DEFAULT); + EXPECT_EQ(ERR_INVALID_PARAM, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_01800 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetAudioEncoder03, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t audioSourceId = 10000; + int ret = recorder->SetAudioEncoder(audioSourceId, AAC_LC); + EXPECT_EQ(ERR_INVALID_PARAM, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_01900 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetAudioSampleRate01, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t audioSourceId = 0; + int32_t sampleRate = 48000; + int ret = recorder->SetAudioSource(AUDIO_MIC, audioSourceId); + EXPECT_EQ(SUCCESS, ret); + ret = recorder->SetAudioSampleRate(audioSourceId, sampleRate); + EXPECT_EQ(SUCCESS, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_02000 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetAudioSamplingRate02, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t audioSourceId = 10000; + int32_t sampleRate = 48000; + int ret = recorder->SetAudioSampleRate(audioSourceId, sampleRate); + EXPECT_EQ(ERR_INVALID_PARAM, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_02100 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetAudioChannels01, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t audioSourceId = 0; + int32_t channelCount = 1; + int ret = recorder->SetAudioSource(AUDIO_MIC, audioSourceId); + EXPECT_EQ(SUCCESS, ret); + ret = recorder->SetAudioChannels(audioSourceId, channelCount); + EXPECT_EQ(SUCCESS, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_02200 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetAudioChannels02, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t audioSourceId = 100000; + int32_t channelCount = 1; + int ret = recorder->SetAudioChannels(audioSourceId, channelCount); + EXPECT_EQ(ERR_INVALID_PARAM, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_02300 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetAudioChannels03, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t audioSourceId = 0; + int32_t channelCount = 1; + int ret = recorder->SetAudioChannels(audioSourceId, channelCount); + EXPECT_EQ(ERR_INVALID_PARAM, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_02400 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetAudioEncodingBitRate01, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t audioSourceId = 0; + int32_t audioEncodingBitRate = 48000; + int ret = recorder->SetAudioSource(AUDIO_MIC, audioSourceId); + EXPECT_EQ(SUCCESS, ret); + ret = recorder->SetAudioEncodingBitRate(audioSourceId, audioEncodingBitRate); + EXPECT_EQ(SUCCESS, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_02500 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_SetAudioEncodingBitRate02, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t audioSourceId = 10000; + int32_t audioEncodingBitRate = 48000; + int ret = recorder->SetAudioEncodingBitRate(audioSourceId, audioEncodingBitRate); + EXPECT_EQ(ERR_INVALID_PARAM, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_02600 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_Prepare01, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t sourceId = 0; + int32_t audioSourceId = 0; + int ret = recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_ES, sourceId); + EXPECT_EQ(SUCCESS, ret); + ret = recorder->SetAudioSource(AUDIO_MIC, audioSourceId); + EXPECT_EQ(SUCCESS, ret); + ret = recorder->SetAudioSource(AUDIO_MIC, audioSourceId); + EXPECT_EQ(SUCCESS, ret); + ret = recorder->Prepare(); + EXPECT_EQ(ERR_INVALID_PARAM, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_02700 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_GetSurface01, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t sourceId = 0; + int ret = recorder->SetVideoSource(VIDEO_SOURCE_SURFACE_ES, sourceId); + EXPECT_EQ(SUCCESS, ret); + Surface *surface = recorder->GetSurface(sourceId).get(); + ret = (int32_t)(surface == nullptr); + EXPECT_EQ(SUCCESS, ret); +} + +/* * + * @tc.number : SUB_MEDIA_REC_PARAM_02800 + * @tc.name : get cameraKit instance ptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(RecoderTest, Test_GetSurface02, TestSize.Level0) +{ + Recorder *recorder = new Recorder(); + int32_t sourceId = 10000; + Surface *surface = recorder->GetSurface(sourceId).get(); + EXPECT_EQ(nullptr, surface); +} \ No newline at end of file diff --git a/open_posix_testsuite/conformance/interfaces/BUILD.gn b/open_posix_testsuite/conformance/interfaces/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..d4f010fc7ea25ec21141daf7e0586aeb7229a7fb --- /dev/null +++ b/open_posix_testsuite/conformance/interfaces/BUILD.gn @@ -0,0 +1,614 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +open_source_suite("ActsOpenPosixTest") { + compiler = ohos_build_compiler_dir + "/bin/" + ohos_build_compiler + suite_name = "acts" + exec_command_path = "//third_party/ltp/testcases/open_posix_testsuite/" + prebuild_command = "make clean && make distclean && ./scripts/generate-makefiles.sh $compiler ${ohos_root_path} && make -C conformance/interfaces" + exec_sub_dir = "conformance/interfaces" + deps = [":install_patch"] + build_args = [ + "sched_getparam/sched_getparam_1-1.run-test", + "sched_getparam/sched_getparam_2-1.run-test", + "sched_getparam/sched_getparam_3-1.run-test", + "sched_getparam/sched_getparam_4-1.run-test", + "sched_get_priority_max/sched_get_priority_max_1-1.run-test", + "sched_get_priority_max/sched_get_priority_max_1-2.run-test", + "sched_get_priority_max/sched_get_priority_max_2-1.run-test", + "sched_get_priority_min/sched_get_priority_min_1-1.run-test", + "sched_get_priority_min/sched_get_priority_min_1-2.run-test", + "sched_get_priority_min/sched_get_priority_min_2-1.run-test", + "sched_getscheduler/sched_getscheduler_1-1.run-test", + "sched_getscheduler/sched_getscheduler_3-1.run-test", + "sched_getscheduler/sched_getscheduler_4-1.run-test", + "sched_getscheduler/sched_getscheduler_5-1.run-test", + "sched_rr_get_interval/sched_rr_get_interval_1-1.run-test", + "sched_rr_get_interval/sched_rr_get_interval_2-1.run-test", + "sched_rr_get_interval/sched_rr_get_interval_3-1.run-test", + "sched_setparam/sched_setparam_1-1.run-test", + "sched_setparam/sched_setparam_5-1.run-test", + "sched_setparam/sched_setparam_22-1.run-test", + "sched_setparam/sched_setparam_23-7.run-test", + "sched_setparam/sched_setparam_27-1.run-test", + "sched_setscheduler/sched_setscheduler_4-1.run-test", + "sched_setscheduler/sched_setscheduler_17-5.run-test", + "sched_setscheduler/sched_setscheduler_17-7.run-test", + "sched_setscheduler/sched_setscheduler_19-5.run-test", + "sched_setscheduler/sched_setscheduler_21-1.run-test", + "raise/raise_1-1.run-test", + "raise/raise_1-2.run-test", + "raise/raise_2-1.run-test", + "raise/raise_4-1.run-test", + "raise/raise_6-1.run-test", + "raise/raise_7-1.run-test", + "asctime/asctime_1-1.run-test", + "clock/clock_2-1.run-test", + "clock_getcpuclockid/clock_getcpuclockid_6-1.run-test", + "clock_getres/clock_getres_1-1.run-test", + "clock_getres/clock_getres_3-1.run-test", + "clock_getres/clock_getres_5-1.run-test", + "clock_getres/clock_getres_6-1.run-test", + "clock_gettime/clock_gettime_1-1.run-test", + "clock_gettime/clock_gettime_1-2.run-test", + "clock_gettime/clock_gettime_2-1.run-test", + "clock_gettime/clock_gettime_3-1.run-test", + "clock_gettime/clock_gettime_7-1.run-test", + "clock_gettime/clock_gettime_8-1.run-test", + "clock_gettime/clock_gettime_8-2.run-test", + "clock_nanosleep/clock_nanosleep_1-1.run-test", + "clock_nanosleep/clock_nanosleep_1-5.run-test", + "clock_nanosleep/clock_nanosleep_2-2.run-test", + "clock_nanosleep/clock_nanosleep_2-3.run-test", + "clock_nanosleep/clock_nanosleep_13-1.run-test", + "clock_settime/clock_settime_1-1.run-test", + "clock_settime/clock_settime_6-1.run-test", + "clock_settime/clock_settime_8-1.run-test", + "clock_settime/clock_settime_17-1.run-test", + "clock_settime/clock_settime_20-1.run-test", + "ctime/ctime_1-1.run-test", + "difftime/difftime_1-1.run-test", + "gmtime/gmtime_1-1.run-test", + "gmtime/gmtime_2-1.run-test", + "localtime/localtime_1-1.run-test", + "mktime/mktime_1-1.run-test", + "nanosleep/nanosleep_1-1.run-test", + "nanosleep/nanosleep_5-1.run-test", + "time/time_1-1.run-test", + "timer_create/timer_create_3-1.run-test", + "timer_create/timer_create_8-1.run-test", + "timer_create/timer_create_16-1.run-test", + "timer_create/speculative/timer_create_speculative_2-1.run-test", + "timer_delete/timer_delete_1-1.run-test", + "timer_delete/timer_delete_1-2.run-test", + "timer_gettime/timer_gettime_1-1.run-test", + "timer_gettime/timer_gettime_1-2.run-test", + "timer_gettime/timer_gettime_2-1.run-test", + "timer_gettime/timer_gettime_2-2.run-test", + "timer_settime/timer_settime_3-1.run-test", + "timer_settime/timer_settime_3-2.run-test", + "timer_settime/timer_settime_3-3.run-test", + "timer_settime/timer_settime_8-1.run-test", + "timer_settime/timer_settime_8-2.run-test", + "timer_settime/timer_settime_8-3.run-test", + "timer_settime/timer_settime_8-4.run-test", + "timer_settime/timer_settime_3-1.run-test", + "timer_settime/timer_settime_3-1.run-test", + "pthread_atfork/pthread_atfork_1-1.run-test", + "pthread_atfork/pthread_atfork_1-2.run-test", + "pthread_atfork/pthread_atfork_2-1.run-test", + "pthread_atfork/pthread_atfork_2-2.run-test", + "pthread_atfork/pthread_atfork_3-2.run-test", + "pthread_atfork/pthread_atfork_4-1.run-test", + "pthread_attr_destroy/pthread_attr_destroy_1-1.run-test", + "pthread_attr_destroy/pthread_attr_destroy_2-1.run-test", + "pthread_attr_destroy/pthread_attr_destroy_3-1.run-test", + "pthread_attr_getdetachstate/pthread_attr_getdetachstate_1-1.run-test", + "pthread_attr_getdetachstate/pthread_attr_getdetachstate_1-2.run-test", + "pthread_attr_getinheritsched/pthread_attr_getinheritsched_1-1.run-test", + "pthread_attr_getschedparam/pthread_attr_getschedparam_1-1.run-test", + "pthread_attr_getscope/pthread_attr_getscope_1-1.run-test", + "pthread_attr_getstacksize/pthread_attr_getstacksize_1-1.run-test", + "pthread_attr_init/pthread_attr_init_1-1.run-test", + "pthread_attr_init/pthread_attr_init_2-1.run-test", + "pthread_attr_init/pthread_attr_init_3-1.run-test", + "pthread_attr_init/pthread_attr_init_4-1.run-test", + "pthread_attr_setdetachstate/pthread_attr_setdetachstate_1-1.run-test", + "pthread_attr_setdetachstate/pthread_attr_setdetachstate_1-2.run-test", + "pthread_attr_setdetachstate/pthread_attr_setdetachstate_2-1.run-test", + "pthread_attr_setdetachstate/pthread_attr_setdetachstate_4-1.run-test", + "pthread_attr_setinheritsched/pthread_attr_setinheritsched_1-1.run-test", + "pthread_attr_setinheritsched/pthread_attr_setinheritsched_2-1.run-test", + "pthread_attr_setinheritsched/pthread_attr_setinheritsched_2-2.run-test", + "pthread_attr_setinheritsched/pthread_attr_setinheritsched_2-3.run-test", + "pthread_attr_setinheritsched/pthread_attr_setinheritsched_2-4.run-test", + "pthread_attr_setinheritsched/pthread_attr_setinheritsched_4-1.run-test", + "pthread_attr_setschedparam/pthread_attr_setschedparam_1-1.run-test", + "pthread_attr_setschedparam/pthread_attr_setschedparam_1-2.run-test", + "pthread_attr_setschedparam/pthread_attr_setschedparam_1-3.run-test", + "pthread_attr_setschedparam/pthread_attr_setschedparam_1-4.run-test", + "pthread_attr_setschedparam/speculative/pthread_attr_setschedparam_speculative_3-1.run-test", + "pthread_attr_setschedparam/speculative/pthread_attr_setschedparam_speculative_3-2.run-test", + "pthread_attr_setschedpolicy/pthread_attr_setschedpolicy_1-2.run-test", + "pthread_attr_setschedpolicy/pthread_attr_setschedpolicy_1-3.run-test", + "pthread_attr_setschedpolicy/pthread_attr_setschedpolicy_4-1.run-test", + "pthread_attr_setscope/pthread_attr_setscope_4-1.run-test", + "pthread_attr_setscope/pthread_attr_setscope_5-1.run-test", + "pthread_attr_setstacksize/pthread_attr_setstacksize_1-1.run-test", + "pthread_attr_setstacksize/pthread_attr_setstacksize_2-1.run-test", + "pthread_barrierattr_destroy/pthread_barrierattr_destroy_1-1.run-test", + "pthread_barrierattr_getpshared/pthread_barrierattr_getpshared_1-1.run-test", + "pthread_barrierattr_init/pthread_barrierattr_init_1-1.run-test", + "pthread_barrierattr_init/pthread_barrierattr_init_2-1.run-test", + "pthread_barrierattr_setpshared/pthread_barrierattr_setpshared_1-1.run-test", + "pthread_barrierattr_setpshared/pthread_barrierattr_setpshared_2-1.run-test", + "pthread_barrier_destroy/pthread_barrier_destroy_1-1.run-test", + "pthread_barrier_init/pthread_barrier_init_1-1.run-test", + "pthread_barrier_init/pthread_barrier_init_3-1.run-test", + "pthread_barrier_init/pthread_barrier_init_4-1.run-test", + "pthread_barrier_wait/pthread_barrier_wait_1-1.run-test", + "pthread_barrier_wait/pthread_barrier_wait_2-1.run-test", + "pthread_cancel/pthread_cancel_1-1.run-test", + "pthread_cancel/pthread_cancel_1-2.run-test", + "pthread_cancel/pthread_cancel_1-3.run-test", + "pthread_cancel/pthread_cancel_2-1.run-test", + "pthread_cancel/pthread_cancel_2-2.run-test", + "pthread_cancel/pthread_cancel_2-3.run-test", + "pthread_cancel/pthread_cancel_3-1.run-test", + "pthread_cancel/pthread_cancel_4-1.run-test", + "pthread_cleanup_pop/pthread_cleanup_pop_1-1.run-test", + "pthread_cleanup_pop/pthread_cleanup_pop_1-2.run-test", + "pthread_cleanup_pop/pthread_cleanup_pop_1-3.run-test", + "pthread_cleanup_push/pthread_cleanup_push_1-1.run-test", + "pthread_cleanup_push/pthread_cleanup_push_1-2.run-test", + "pthread_cleanup_push/pthread_cleanup_push_1-3.run-test", + "pthread_condattr_destroy/pthread_condattr_destroy_1-1.run-test", + "pthread_condattr_destroy/pthread_condattr_destroy_2-1.run-test", + "pthread_condattr_destroy/pthread_condattr_destroy_3-1.run-test", + "pthread_condattr_destroy/pthread_condattr_destroy_4-1.run-test", + "pthread_condattr_getclock/pthread_condattr_getclock_1-1.run-test", + "pthread_condattr_getclock/pthread_condattr_getclock_1-2.run-test", + "pthread_condattr_getpshared/pthread_condattr_getpshared_1-1.run-test", + "pthread_condattr_getpshared/pthread_condattr_getpshared_1-2.run-test", + "pthread_condattr_getpshared/pthread_condattr_getpshared_2-1.run-test", + "pthread_condattr_init/pthread_condattr_init_1-1.run-test", + "pthread_condattr_init/pthread_condattr_init_3-1.run-test", + "pthread_condattr_setclock/pthread_condattr_setclock_1-1.run-test", + "pthread_condattr_setclock/pthread_condattr_setclock_1-2.run-test", + "pthread_condattr_setclock/pthread_condattr_setclock_2-1.run-test", + "pthread_condattr_setpshared/pthread_condattr_setpshared_1-1.run-test", + "pthread_condattr_setpshared/pthread_condattr_setpshared_1-2.run-test", + "pthread_condattr_setpshared/pthread_condattr_setpshared_2-1.run-test", + "pthread_cond_signal/pthread_cond_signal_1-1.run-test", + "pthread_cond_signal/pthread_cond_signal_2-1.run-test", + "pthread_cond_signal/pthread_cond_signal_2-2.run-test", + "pthread_cond_signal/pthread_cond_signal_4-1.run-test", + "pthread_mutexattr_settype/pthread_mutexattr_settype_1-1.run-test", + "pthread_mutexattr_settype/pthread_mutexattr_settype_3-1.run-test", + "pthread_mutexattr_settype/pthread_mutexattr_settype_3-2.run-test", + "pthread_mutexattr_settype/pthread_mutexattr_settype_3-3.run-test", + "pthread_mutexattr_settype/pthread_mutexattr_settype_3-4.run-test", + "pthread_mutexattr_settype/pthread_mutexattr_settype_7-1.run-test", + "pthread_mutex_destroy/pthread_mutex_destroy_1-1.run-test", + "pthread_mutex_destroy/pthread_mutex_destroy_2-1.run-test", + "pthread_mutex_destroy/pthread_mutex_destroy_2-2.run-test", + "pthread_mutex_destroy/pthread_mutex_destroy_3-1.run-test", + "pthread_mutex_destroy/pthread_mutex_destroy_5-1.run-test", + "pthread_mutex_destroy/pthread_mutex_destroy_5-2.run-test", + "pthread_mutex_init/pthread_mutex_init_1-1.run-test", + "pthread_mutex_init/pthread_mutex_init_2-1.run-test", + "pthread_mutex_init/pthread_mutex_init_3-1.run-test", + "pthread_mutex_init/pthread_mutex_init_4-1.run-test", + "pthread_mutex_lock/pthread_mutex_lock_1-1.run-test", + "pthread_mutex_lock/pthread_mutex_lock_2-1.run-test", + "pthread_mutex_timedlock/pthread_mutex_timedlock_4-1.run-test", + "pthread_mutex_timedlock/pthread_mutex_timedlock_5-1.run-test", + "pthread_mutex_timedlock/pthread_mutex_timedlock_5-2.run-test", + "pthread_mutex_timedlock/pthread_mutex_timedlock_5-3.run-test", + "pthread_mutex_trylock/pthread_mutex_trylock_1-1.run-test", + "pthread_mutex_trylock/pthread_mutex_trylock_3-1.run-test", + "pthread_mutex_trylock/pthread_mutex_trylock_4-1.run-test", + "pthread_mutex_unlock/pthread_mutex_unlock_1-1.run-test", + "pthread_mutex_unlock/pthread_mutex_unlock_2-1.run-test", + "pthread_mutex_unlock/pthread_mutex_unlock_3-1.run-test", + "pthread_once/pthread_once_1-1.run-test", + "pthread_rwlock_rdlock/pthread_rwlock_rdlock_1-1.run-test", + "pthread_rwlock_rdlock/pthread_rwlock_rdlock_2-3.run-test", + "pthread_rwlockattr_destroy/pthread_rwlockattr_destroy_1-1.run-test", + "pthread_rwlockattr_destroy/pthread_rwlockattr_destroy_2-1.run-test", + "pthread_rwlockattr_getpshared/pthread_rwlockattr_getpshared_1-1.run-test", + "pthread_rwlockattr_getpshared/pthread_rwlockattr_getpshared_4-1.run-test", + "pthread_rwlockattr_init/pthread_rwlockattr_init_1-1.run-test", + "pthread_rwlockattr_init/pthread_rwlockattr_init_2-1.run-test", + "pthread_rwlockattr_setpshared/pthread_rwlockattr_setpshared_1-1.run-test", + "pthread_rwlock_destroy/pthread_rwlock_destroy_1-1.run-test", + "pthread_rwlock_destroy/pthread_rwlock_destroy_3-1.run-test", + "pthread_rwlock_init/pthread_rwlock_init_1-1.run-test", + "pthread_rwlock_init/pthread_rwlock_init_2-1.run-test", + "pthread_rwlock_init/pthread_rwlock_init_3-1.run-test", + "pthread_rwlock_init/pthread_rwlock_init_6-1.run-test", + "pthread_rwlock_unlock/pthread_rwlock_unlock_2-1.run-test", + "pthread_rwlock_wrlock/pthread_rwlock_wrlock_1-1.run-test", + "pthread_rwlock_rdlock/pthread_rwlock_rdlock_5-1.run-test", + "pthread_rwlock_timedrdlock/pthread_rwlock_timedrdlock_2-1.run-test", + "pthread_rwlock_timedrdlock/pthread_rwlock_timedrdlock_5-1.run-test", + "pthread_rwlock_timedwrlock/pthread_rwlock_timedwrlock_2-1.run-test", + "pthread_rwlock_timedwrlock/pthread_rwlock_timedwrlock_5-1.run-test", + "pthread_rwlock_tryrdlock/pthread_rwlock_tryrdlock_1-1.run-test", + "pthread_rwlock_trywrlock/pthread_rwlock_trywrlock_1-1.run-test", + "pthread_rwlock_trywrlock/speculative/pthread_rwlock_trywrlock_speculative_3-1.run-test", + "pthread_rwlock_unlock/pthread_rwlock_unlock_1-1.run-test", + "pthread_rwlock_unlock/pthread_rwlock_unlock_4-1.run-test", + "pthread_rwlock_unlock/pthread_rwlock_unlock_4-2.run-test", + "pthread_self/pthread_self_1-1.run-test", + "pthread_setcancelstate/pthread_setcancelstate_1-1.run-test", + "pthread_setcancelstate/pthread_setcancelstate_1-2.run-test", + "pthread_setcancelstate/pthread_setcancelstate_2-1.run-test", + "pthread_setcancelstate/pthread_setcancelstate_3-1.run-test", + "pthread_setcanceltype/pthread_setcanceltype_1-2.run-test", + "pthread_setcanceltype/pthread_setcanceltype_2-1.run-test", + "pthread_setschedparam/pthread_setschedparam_1-1.run-test", + "pthread_setschedparam/pthread_setschedparam_4-1.run-test", + "pthread_setspecific/pthread_setspecific_1-1.run-test", + "pthread_setspecific/pthread_setspecific_1-2.run-test", + "pthread_spin_destroy/pthread_spin_destroy_1-1.run-test", + "aio_cancel/aio_cancel_9-1.run-test", + "aio_cancel/aio_cancel_10-1.run-test", + "aio_fsync/aio_fsync_12-1.run-test", + "lio_listio/lio_listio_6-1.run-test", + "fsync/fsync_5-1.run-test", + "fsync/fsync_7-1.run-test", + "mq_close/mq_close_1-1.run-test", + "mq_close/mq_close_3-2.run-test", + "mq_getattr/mq_getattr_2-1.run-test", + "mq_getattr/mq_getattr_2-2.run-test", + "mq_getattr/mq_getattr_3-1.run-test", + "mq_getattr/speculative/mq_getattr_speculative_7-1.run-test", + "mq_open/mq_open_12-1.run-test", + "mq_open/mq_open_13-1.run-test", + "mq_open/mq_open_15-1.run-test", + "mq_open/mq_open_21-1.run-test", + "mq_open/mq_open_23-1.run-test", + "mq_open/mq_open_25-2.run-test", + "mq_open/mq_open_27-1.run-test", + "mq_open/mq_open_27-2.run-test", + "mq_open/mq_open_29-1.run-test", + "mq_open/mq_open_3-1.run-test", + "mq_open/mq_open_7-3.run-test", + "mq_open/speculative/mq_open_speculative_2-2.run-test", + "mq_open/speculative/mq_open_speculative_2-3.run-test", + "mq_open/speculative/mq_open_speculative_26-1.run-test", + "mq_receive/mq_receive_10-1.run-test", + "mq_receive/mq_receive_11-1.run-test", + "mq_receive/mq_receive_11-2.run-test", + "mq_receive/mq_receive_7-1.run-test", + "mq_send/mq_send_13-1.run-test", + "mq_send/mq_send_2-1.run-test", + "mq_send/mq_send_4-1.run-test", + "mq_send/mq_send_4-2.run-test", + "mq_setattr/mq_setattr_1-1.run-test", + "mq_setattr/mq_setattr_1-2.run-test", + "mq_setattr/mq_setattr_2-1.run-test", + "mq_setattr/mq_setattr_5-1.run-test", + "mq_timedreceive/mq_timedreceive_13-1.run-test", + "mq_timedreceive/mq_timedreceive_14-1.run-test", + "mq_timedreceive/mq_timedreceive_7-1.run-test", + "mq_timedsend/mq_timedsend_13-1.run-test", + "mq_timedsend/mq_timedsend_19-1.run-test", + "mq_timedsend/mq_timedsend_2-1.run-test", + "mq_timedsend/mq_timedsend_4-1.run-test", + "mq_timedsend/mq_timedsend_4-2.run-test", + "mq_unlink/mq_unlink_1-1.run-test", + "mq_unlink/mq_unlink_2-1.run-test", + "mq_unlink/mq_unlink_2-2.run-test", + "mq_unlink/mq_unlink_7-1.run-test", + "mq_unlink/speculative/mq_unlink_speculative_7-2.run-test", + "sem_destroy/sem_destroy_4-1.run-test", + "sem_destroy/sem_destroy_3-1.run-test", + "sem_getvalue/sem_getvalue_2-2.run-test", + "sem_init/sem_init_1-1.run-test", + "sem_init/sem_init_2-1.run-test", + "sem_init/sem_init_2-2.run-test", + "sem_init/sem_init_3-1.run-test", + "sem_init/sem_init_5-1.run-test", + "sem_init/sem_init_5-2.run-test", + "sem_timedwait/sem_timedwait_11-1.run-test", + "sem_timedwait/sem_timedwait_1-1.run-test", + "sem_timedwait/sem_timedwait_2-2.run-test", + "sem_timedwait/sem_timedwait_4-1.run-test", + "sem_timedwait/sem_timedwait_6-1.run-test", + "sem_timedwait/sem_timedwait_6-2.run-test", + "sem_timedwait/sem_timedwait_7-1.run-test", + "sem_unlink/sem_unlink_5-1.run-test", + "shm_open/shm_open_39-1.run-test", + "shm_unlink/shm_unlink_10-1.run-test", + "sigaction/sigaction_1-10.run-test", + "sigaction/sigaction_1-11.run-test", + "sigaction/sigaction_1-12.run-test", + "sigaction/sigaction_1-13.run-test", + "sigaction/sigaction_1-14.run-test", + "sigaction/sigaction_1-15.run-test", + "sigaction/sigaction_1-16.run-test", + "sigaction/sigaction_1-17.run-test", + "sigaction/sigaction_1-18.run-test", + "sigaction/sigaction_1-19.run-test", + "sigaction/sigaction_1-1.run-test", + "sigaction/sigaction_1-20.run-test", + "sigaction/sigaction_1-22.run-test", + "sigaction/sigaction_1-23.run-test", + "sigaction/sigaction_1-24.run-test", + "sigaction/sigaction_1-25.run-test", + "sigaction/sigaction_1-26.run-test", + "sigaction/sigaction_1-2.run-test", + "sigaction/sigaction_1-3.run-test", + "sigaction/sigaction_1-4.run-test", + "sigaction/sigaction_1-6.run-test", + "sigaction/sigaction_1-7.run-test", + "sigaction/sigaction_18-10.run-test", + "sigaction/sigaction_18-11.run-test", + "sigaction/sigaction_18-12.run-test", + "sigaction/sigaction_18-13.run-test", + "sigaction/sigaction_18-14.run-test", + "sigaction/sigaction_18-15.run-test", + "sigaction/sigaction_18-16.run-test", + "sigaction/sigaction_18-17.run-test", + "sigaction/sigaction_18-18.run-test", + "sigaction/sigaction_18-19.run-test", + "sigaction/sigaction_18-1.run-test", + "sigaction/sigaction_18-20.run-test", + "sigaction/sigaction_18-22.run-test", + "sigaction/sigaction_18-23.run-test", + "sigaction/sigaction_18-24.run-test", + "sigaction/sigaction_18-25.run-test", + "sigaction/sigaction_18-26.run-test", + "sigaction/sigaction_18-2.run-test", + "sigaction/sigaction_18-3.run-test", + "sigaction/sigaction_18-4.run-test", + "sigaction/sigaction_18-6.run-test", + "sigaction/sigaction_18-7.run-test", + "sigaction/sigaction_18-8.run-test", + "sigaction/sigaction_18-9.run-test", + "sigaction/sigaction_1-8.run-test", + "sigaction/sigaction_1-9.run-test", + "sigaction/sigaction_2-10.run-test", + "sigaction/sigaction_2-11.run-test", + "sigaction/sigaction_2-12.run-test", + "sigaction/sigaction_2-13.run-test", + "sigaction/sigaction_2-14.run-test", + "sigaction/sigaction_2-15.run-test", + "sigaction/sigaction_2-16.run-test", + "sigaction/sigaction_2-17.run-test", + "sigaction/sigaction_2-18.run-test", + "sigaction/sigaction_2-19.run-test", + "sigaction/sigaction_2-1.run-test", + "sigaction/sigaction_2-20.run-test", + "sigaction/sigaction_2-22.run-test", + "sigaction/sigaction_2-23.run-test", + "sigaction/sigaction_2-24.run-test", + "sigaction/sigaction_2-25.run-test", + "sigaction/sigaction_2-26.run-test", + "sigaction/sigaction_2-2.run-test", + "sigaction/sigaction_2-3.run-test", + "sigaction/sigaction_2-4.run-test", + "sigaction/sigaction_25-10.run-test", + "sigaction/sigaction_25-11.run-test", + "sigaction/sigaction_25-12.run-test", + "sigaction/sigaction_25-13.run-test", + "sigaction/sigaction_25-14.run-test", + "sigaction/sigaction_25-15.run-test", + "sigaction/sigaction_25-16.run-test", + "sigaction/sigaction_25-17.run-test", + "sigaction/sigaction_25-18.run-test", + "sigaction/sigaction_25-19.run-test", + "sigaction/sigaction_25-1.run-test", + "sigaction/sigaction_25-20.run-test", + "sigaction/sigaction_25-21.run-test", + "sigaction/sigaction_25-22.run-test", + "sigaction/sigaction_25-23.run-test", + "sigaction/sigaction_25-24.run-test", + "sigaction/sigaction_25-25.run-test", + "sigaction/sigaction_25-26.run-test", + "sigaction/sigaction_25-2.run-test", + "sigaction/sigaction_25-3.run-test", + "sigaction/sigaction_25-4.run-test", + "sigaction/sigaction_25-6.run-test", + "sigaction/sigaction_25-7.run-test", + "sigaction/sigaction_25-8.run-test", + "sigaction/sigaction_25-9.run-test", + "sigaction/sigaction_2-6.run-test", + "sigaction/sigaction_2-7.run-test", + "sigaction/sigaction_28-10.run-test", + "sigaction/sigaction_28-11.run-test", + "sigaction/sigaction_28-12.run-test", + "sigaction/sigaction_28-13.run-test", + "sigaction/sigaction_28-14.run-test", + "sigaction/sigaction_28-15.run-test", + "sigaction/sigaction_28-16.run-test", + "sigaction/sigaction_28-17.run-test", + "sigaction/sigaction_28-18.run-test", + "sigaction/sigaction_28-19.run-test", + "sigaction/sigaction_28-1.run-test", + "sigaction/sigaction_28-20.run-test", + "sigaction/sigaction_28-22.run-test", + "sigaction/sigaction_28-23.run-test", + "sigaction/sigaction_28-24.run-test", + "sigaction/sigaction_28-25.run-test", + "sigaction/sigaction_28-26.run-test", + "sigaction/sigaction_28-2.run-test", + "sigaction/sigaction_28-3.run-test", + "sigaction/sigaction_28-4.run-test", + "sigaction/sigaction_28-6.run-test", + "sigaction/sigaction_28-7.run-test", + "sigaction/sigaction_28-8.run-test", + "sigaction/sigaction_28-9.run-test", + "sigaction/sigaction_2-8.run-test", + "sigaction/sigaction_2-9.run-test", + "sigaction/sigaction_30-1.run-test", + "sigaction/sigaction_4-100.run-test", + "sigaction/sigaction_4-101.run-test", + "sigaction/sigaction_4-102.run-test", + "sigaction/sigaction_4-103.run-test", + "sigaction/sigaction_4-104.run-test", + "sigaction/sigaction_4-53.run-test", + "sigaction/sigaction_4-54.run-test", + "sigaction/sigaction_4-55.run-test", + "sigaction/sigaction_4-56.run-test", + "sigaction/sigaction_4-58.run-test", + "sigaction/sigaction_4-59.run-test", + "sigaction/sigaction_4-60.run-test", + "sigaction/sigaction_4-61.run-test", + "sigaction/sigaction_4-62.run-test", + "sigaction/sigaction_4-63.run-test", + "sigaction/sigaction_4-64.run-test", + "sigaction/sigaction_4-65.run-test", + "sigaction/sigaction_4-66.run-test", + "sigaction/sigaction_4-67.run-test", + "sigaction/sigaction_4-68.run-test", + "sigaction/sigaction_4-69.run-test", + "sigaction/sigaction_4-70.run-test", + "sigaction/sigaction_4-71.run-test", + "sigaction/sigaction_4-72.run-test", + "sigaction/sigaction_4-73.run-test", + "sigaction/sigaction_4-74.run-test", + "sigaction/sigaction_4-75.run-test", + "sigaction/sigaction_4-76.run-test", + "sigaction/sigaction_4-77.run-test", + "sigaction/sigaction_4-78.run-test", + "sigaction/sigaction_4-79.run-test", + "sigaction/sigaction_4-80.run-test", + "sigaction/sigaction_4-81.run-test", + "sigaction/sigaction_4-82.run-test", + "sigaction/sigaction_4-84.run-test", + "sigaction/sigaction_4-85.run-test", + "sigaction/sigaction_4-86.run-test", + "sigaction/sigaction_4-87.run-test", + "sigaction/sigaction_4-88.run-test", + "sigaction/sigaction_4-89.run-test", + "sigaction/sigaction_4-90.run-test", + "sigaction/sigaction_4-91.run-test", + "sigaction/sigaction_4-92.run-test", + "sigaction/sigaction_4-93.run-test", + "sigaction/sigaction_4-94.run-test", + "sigaction/sigaction_4-95.run-test", + "sigaction/sigaction_4-96.run-test", + "sigaction/sigaction_4-97.run-test", + "sigaction/sigaction_4-98.run-test", + "sigaction/sigaction_4-99.run-test", + "sigaction/sigaction_6-10.run-test", + "sigaction/sigaction_6-11.run-test", + "sigaction/sigaction_6-12.run-test", + "sigaction/sigaction_6-13.run-test", + "sigaction/sigaction_6-14.run-test", + "sigaction/sigaction_6-15.run-test", + "sigaction/sigaction_6-16.run-test", + "sigaction/sigaction_6-17.run-test", + "sigaction/sigaction_6-18.run-test", + "sigaction/sigaction_6-19.run-test", + "sigaction/sigaction_6-1.run-test", + "sigaction/sigaction_6-20.run-test", + "sigaction/sigaction_6-22.run-test", + "sigaction/sigaction_6-23.run-test", + "sigaction/sigaction_6-24.run-test", + "sigaction/sigaction_6-25.run-test", + "sigaction/sigaction_6-26.run-test", + "sigaction/sigaction_6-2.run-test", + "sigaction/sigaction_6-3.run-test", + "sigaction/sigaction_6-4.run-test", + "sigaction/sigaction_6-6.run-test", + "sigaction/sigaction_6-7.run-test", + "sigaction/sigaction_6-8.run-test", + "sigaction/sigaction_6-9.run-test", + "sigaction/sigaction_8-10.run-test", + "sigaction/sigaction_8-11.run-test", + "sigaction/sigaction_8-12.run-test", + "sigaction/sigaction_8-13.run-test", + "sigaction/sigaction_8-14.run-test", + "sigaction/sigaction_8-15.run-test", + "sigaction/sigaction_8-16.run-test", + "sigaction/sigaction_8-17.run-test", + "sigaction/sigaction_8-18.run-test", + "sigaction/sigaction_8-19.run-test", + "sigaction/sigaction_8-1.run-test", + "sigaction/sigaction_8-20.run-test", + "sigaction/sigaction_8-21.run-test", + "sigaction/sigaction_8-22.run-test", + "sigaction/sigaction_8-23.run-test", + "sigaction/sigaction_8-24.run-test", + "sigaction/sigaction_8-25.run-test", + "sigaction/sigaction_8-26.run-test", + "sigaction/sigaction_8-2.run-test", + "sigaction/sigaction_8-3.run-test", + "sigaction/sigaction_8-4.run-test", + "sigaction/sigaction_8-7.run-test", + "sigaction/sigaction_8-8.run-test", + "sigaction/sigaction_8-9.run-test", + "sigaddset/sigaddset_1-1.run-test", + "sigaddset/sigaddset_1-2.run-test", + "sigaddset/sigaddset_1-3.run-test", + "sigaddset/sigaddset_2-1.run-test", + "sigaddset/sigaddset_4-1.run-test", + "sigaltstack/sigaltstack_11-1.run-test", + "sigaltstack/sigaltstack_12-1.run-test", + "sigdelset/sigdelset_1-1.run-test", + "sigdelset/sigdelset_1-2.run-test", + "sigdelset/sigdelset_1-3.run-test", + "sigdelset/sigdelset_1-4.run-test", + "sigdelset/sigdelset_4-1.run-test", + "sigfillset/sigfillset_1-1.run-test", + "sighold/sighold_1-1.run-test", + "sighold/sighold_2-1.run-test", + "sighold/sighold_3-1.run-test", + "sigignore/sigignore_1-1.run-test", + "sigignore/sigignore_4-1.run-test", + "sigignore/sigignore_5-1.run-test", + "sigignore/sigignore_6-1.run-test", + "sigignore/sigignore_6-2.run-test", + "sigismember/sigismember_3-1.run-test", + "sigismember/sigismember_4-1.run-test", + "sigpause/sigpause_1-1.run-test", + "sigpause/sigpause_2-1.run-test", + "sigpause/sigpause_3-1.run-test", + "sigpending/sigpending_1-1.run-test", + "sigpending/sigpending_2-1.run-test", + "sigprocmask/sigprocmask_12-1.run-test", + "sigprocmask/sigprocmask_15-1.run-test", + "sigprocmask/sigprocmask_17-1.run-test", + "sigprocmask/sigprocmask_4-1.run-test", + "sigprocmask/sigprocmask_5-1.run-test", + "sigprocmask/sigprocmask_6-1.run-test", + "sigprocmask/sigprocmask_7-1.run-test", + "sigprocmask/sigprocmask_8-1.run-test", + "sigprocmask/sigprocmask_8-2.run-test", + "sigprocmask/sigprocmask_8-3.run-test", + "sigprocmask/sigprocmask_9-1.run-test", + "sigqueue/sigqueue_9-1.run-test", + "sigrelse/sigrelse_1-1.run-test", + "sigrelse/sigrelse_2-1.run-test", + "sigrelse/sigrelse_3-1.run-test", + "sigsuspend/sigsuspend_3-1.run-test", + "sigsuspend/sigsuspend_4-1.run-test", + "sigsuspend/sigsuspend_6-1.run-test", + "sigtimedwait/sigtimedwait_1-1.run-test", + "sigtimedwait/sigtimedwait_6-1.run-test", + "sigwait/sigwait_4-1.run-test", + "sigwaitinfo/sigwaitinfo_3-1.run-test", + ] + +} + +build_ext_component("install_patch") { + exec_path = rebase_path(".", root_build_dir) + command = "./../../ltp-patch/patch.sh" +} diff --git a/open_posix_testsuite/conformance/interfaces/Test.json b/open_posix_testsuite/conformance/interfaces/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..a1c09217122b24e27fecf68a961132af80653c2a --- /dev/null +++ b/open_posix_testsuite/conformance/interfaces/Test.json @@ -0,0 +1,26 @@ +{ + "description": "Config for hcpptest demo test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/open_posix_testsuite/ActsOpenPosixTest", + "target": "/test_root/open_posix_testsuite/ActsOpenPosixTest" + } + ] + } + ], + "driver": { + "type": "OpenSourceTest", + "pre_cmd": "su", + "execute": "/test_root/open_posix_testsuite/ActsOpenPosixTest" + } +} diff --git a/open_posix_testsuite/ltp-patch/CFLAGS.patch b/open_posix_testsuite/ltp-patch/CFLAGS.patch new file mode 100755 index 0000000000000000000000000000000000000000..f6bb749df74f869c5ffec6742876e0ea06cc50a6 --- /dev/null +++ b/open_posix_testsuite/ltp-patch/CFLAGS.patch @@ -0,0 +1,5 @@ +--- third_party/ltp/testcases/open_posix_testsuite/CFLAGS 2020-08-29 16:32:39.817825435 +0800 ++++ test/xts/acts/open_posix_testsuite/ltp-patch/CFLAGS 2020-08-29 16:33:09.077825435 +0800 +@@ -1 +1 @@ +--std=c99 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -W -Wall ++-std=c99 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 diff --git a/open_posix_testsuite/ltp-patch/generate-makefiles.sh.patch b/open_posix_testsuite/ltp-patch/generate-makefiles.sh.patch new file mode 100755 index 0000000000000000000000000000000000000000..0f7f3ae26e99f9db8dffee38c233a139ce5bbdae --- /dev/null +++ b/open_posix_testsuite/ltp-patch/generate-makefiles.sh.patch @@ -0,0 +1,27 @@ +--- third_party/ltp/testcases/open_posix_testsuite/scripts/generate-makefiles.sh 2020-09-03 20:31:21.369825435 +0800 ++++ test/xts/acts/open_posix_testsuite/ltp-patch/generate-makefiles.sh 2020-09-03 20:33:42.534681514 +0800 +@@ -107,6 +107,7 @@ + # + + # Path variables. ++CC := ${COMPILE_PATH} + top_srcdir?= `echo "$prereq_dir" | awk '{ gsub(/[^\/]+/, "..", $0); print }'` + subdir= $prereq_cache_dir + srcdir= \$(top_srcdir)/\$(subdir) +@@ -118,6 +119,7 @@ + + # Build variables + CFLAGS+= -I\$(top_srcdir)/include ++CFLAGS+= --target=arm-liteos --sysroot=${BUILD_ROOT_PATH}prebuilts/lite/sysroot + + # XXX: for testfrmw.c -- needs to be moved into a library. + CFLAGS+= -I\$(srcdir) +@@ -303,6 +305,8 @@ + GLOBAL_BOILERPLATE="${TOP_SRCDIR}/.global_boilerplate" + + CONFIG_MK="../../include/mk/config-openposix.mk" ++COMPILE_PATH=$1 ++BUILD_ROOT_PATH=$2 + + rm -f "$GLOBAL_BOILERPLATE" + diff --git a/open_posix_testsuite/ltp-patch/patch.sh b/open_posix_testsuite/ltp-patch/patch.sh new file mode 100755 index 0000000000000000000000000000000000000000..b4deaacebacd12c0c358ce7af93fbf308432f717 --- /dev/null +++ b/open_posix_testsuite/ltp-patch/patch.sh @@ -0,0 +1,16 @@ +#!/bin/bash +echo "Patching..." + +cd ../../../../../../ + +project_path=$(pwd) + +echo $project_path + +patch -p0 third_party/ltp/testcases/open_posix_testsuite/scripts/generate-makefiles.sh < ./test/xts/acts/open_posix_testsuite/ltp-patch/generate-makefiles.sh.patch + +echo "\n\n\n" + +patch -p0 third_party/ltp/testcases/open_posix_testsuite/CFLAGS < ./test/xts/acts/open_posix_testsuite/ltp-patch/CFLAGS.patch + +echo "\n\n\n" diff --git a/readme.md b/readme.md new file mode 100755 index 0000000000000000000000000000000000000000..fff7bfacc54d5d54ffed9a7d9ffe38e5448139e4 --- /dev/null +++ b/readme.md @@ -0,0 +1 @@ +详见:https://gitee.com/openharmony/docs/blob/master/readme/XTS认证子系统README.md diff --git a/sample_lite/hcpptest_posix/BUILD.gn b/sample_lite/hcpptest_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..1d187699ce565612f01b2a4122c4317741e599df --- /dev/null +++ b/sample_lite/hcpptest_posix/BUILD.gn @@ -0,0 +1,27 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsHcpptestDemoTest") { + suite_name = "acts" + sources = [ + "src/demo.cpp", + "src/IsPrimeParamTest.cpp", + ] + + include_dirs = [ + "src", + ] + cflags = [ "-Wno-error" ] +} \ No newline at end of file diff --git a/sample_lite/hcpptest_posix/Test.json b/sample_lite/hcpptest_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..4d6f88042811a536305dc0ae9b2635d88591f74b --- /dev/null +++ b/sample_lite/hcpptest_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for hcpptest demo test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/sample", + "target": "/test_root/sample" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/sample/hcpptest_demo.bin" + } +} \ No newline at end of file diff --git a/sample_lite/hcpptest_posix/src/IsPrimeParamTest.cpp b/sample_lite/hcpptest_posix/src/IsPrimeParamTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..266d794a25886c002c25702b5beed0d932715262 --- /dev/null +++ b/sample_lite/hcpptest_posix/src/IsPrimeParamTest.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// --------------------<测试 参数化>----------------------------------- +#include "gtest/gtest.h" +#include +#include "demo.h" +using namespace ::testing; + +struct ParamList { + bool out; + int in; +}; + +class IsPrimeParamTest : public ::testing::TestWithParam { +}; + +// if n is prime num return true else return false +static bool IsPrimeNum(int n) +{ + if (n < NUM2) { + return false; + } + int i; + for (i = NUM2; i <= sqrt(n); i++) { + if ((n % i) == 0) { + return false; + } + } + return true; +} + +TEST_P(IsPrimeParamTest, IsPrime) +{ + bool out = GetParam().out; + int in = GetParam().in; + EXPECT_EQ(out, IsPrimeNum(in)); +} + +INSTANTIATE_TEST_CASE_P(IsPrimeParamTest, + IsPrimeParamTest, + Values(ParamList{false, NUM10}, ParamList{true, NUM3}, ParamList{false, NUM0}, ParamList{false, NG_NUM1})); diff --git a/sample_lite/hcpptest_posix/src/demo.cpp b/sample_lite/hcpptest_posix/src/demo.cpp new file mode 100755 index 0000000000000000000000000000000000000000..56c6f987a37cc18b1f5330c2343fcf2f9f220346 --- /dev/null +++ b/sample_lite/hcpptest_posix/src/demo.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "demo.h" +using namespace std; +using namespace testing::ext; + +class Demo: public testing::Test { +protected: + // SetUpTestCase:测试套预置动作,在第一个TestCase之前执行 + static void SetUpTestCase(void) {} + // TearDownTestCase:测试套清理动作,在最后一个TestCase之后执行 + static void TearDownTestCase(void) {} + // 用例的预置动作 + virtual void SetUp() {} + // 用例的清理动作 + virtual void TearDown() {} +}; + + +// Return the sum of n. If n is negative, return 0. +static int Sum(int n) +{ + if (n <= 0) { + return 0; + } + int sum = 0; + for (int i = 1; i <= n; i++) { + sum += i; + } + return sum; +} + +/** + * @tc.number : TEST_CASE_100 + * @tc.name : Demo test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(Demo, Negative, TestSize.Level0) { + EXPECT_EQ(NUM0, Sum(NG_NUM5)); + EXPECT_EQ(NUM0, Sum(NG_NUM1)); +} + +/** + * @tc.number : TEST_CASE_200 + * @tc.name : Demo test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(Demo, Zero, TestSize.Level0) { + EXPECT_EQ(NUM0, Sum(NUM0)); +} + +/** + * @tc.number : TEST_CASE_300 + * @tc.name : Demo test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(Demo, Positive, TestSize.Level0) { + EXPECT_EQ(NUM1, Sum(NUM1)); + EXPECT_EQ(NUM45, Sum(NUM10)); + EXPECT_EQ(NUM4950, Sum(NUM100)); +} diff --git a/sample_lite/hcpptest_posix/src/demo.h b/sample_lite/hcpptest_posix/src/demo.h new file mode 100755 index 0000000000000000000000000000000000000000..9c953f443d7fbbed5875718e3f1f811fae749b53 --- /dev/null +++ b/sample_lite/hcpptest_posix/src/demo.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020 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 HCPPTEST_DEMO_H +#define HCPPTEST_DEMO_H +/** + * test numbers using in test cases +*/ +enum TestNums { + NG_NUM1 = -1, + NG_NUM5 = -5, + NUM0 = 0, + NUM1 = 1, + NUM2 = 2, + NUM3 = 3, + NUM4 = 4, + NUM10 = 10, + NUM45 = 45, + NUM100 = 100, + NUM4950 = 4950, +}; + +#endif //HCPPTEST_DEMO_H diff --git a/sample_lite/hctest_hal/BUILD.gn b/sample_lite/hctest_hal/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..a66826569a2ba9286be71fdc2c3f0ca94c14ab51 --- /dev/null +++ b/sample_lite/hctest_hal/BUILD.gn @@ -0,0 +1,25 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") +hctest_suite("ActsHctestDemoTest") { + suite_name = "acts" + sources = [ + "src/test_demo1.c", + "src/test_demo2.c", + ] + + include_dirs = [ ] + + cflags = [ "-Wno-error" ] +} diff --git a/sample_lite/hctest_hal/Test.tmpl b/sample_lite/hctest_hal/Test.tmpl new file mode 100755 index 0000000000000000000000000000000000000000..be8407e1286041a5af2bdc75a15633337376eb9d --- /dev/null +++ b/sample_lite/hctest_hal/Test.tmpl @@ -0,0 +1,19 @@ +{ + "description": "Config for $module test cases", + "environment": [ + { + "type": "device", + "label": "wifiiot" + } + ], + "kits": [ + { + "type": "DeployKit", + "timeout": "20000", + "burn_file": "$subsystem/$module.bin" + } + ], + "driver": { + "type": "CTestLite" + } +} \ No newline at end of file diff --git a/sample_lite/hctest_hal/prebuilt/BUILD.gn b/sample_lite/hctest_hal/prebuilt/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..0ac31afcbc45edb849d67885b7d77a82217b0434 --- /dev/null +++ b/sample_lite/hctest_hal/prebuilt/BUILD.gn @@ -0,0 +1,21 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +ctest_prebuilt_suite("hctest_prebuilt") { + suite_name = "acts" + sources = [ + "libhctest_demo.a", + ] +} diff --git a/sample_lite/hctest_hal/prebuilt/Test.json b/sample_lite/hctest_hal/prebuilt/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..51445731d934e3405d5fb6cf2077db65b2c7b5d4 --- /dev/null +++ b/sample_lite/hctest_hal/prebuilt/Test.json @@ -0,0 +1,13 @@ +{ + "description": "Config for $module test cases", + "kits": [ + { + "type": "DeployKit", + "timeout": "20000", + "burn_file": "$subsystem/$module.bin" + } + ], + "driver": { + "type": "CTestLite" + } +} \ No newline at end of file diff --git a/sample_lite/hctest_hal/src/test_demo1.c b/sample_lite/hctest_hal/src/test_demo1.c new file mode 100755 index 0000000000000000000000000000000000000000..fab8dfa4cc816ea138b983f4180c571b63f04dfb --- /dev/null +++ b/sample_lite/hctest_hal/src/test_demo1.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2020 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 "hctest.h" + +/** + * @tc.name: register a test suit named "IntTestSuite" + * @param: test subsystem name + * @param: example module name + * @param: IntTestSuite test suit name + */ +LITE_TEST_SUIT(test, example, IntTestSuite); + +/** + * @tc.setup: define a setup for test suit, format:"IntTestSuite + SetUp" + * @return: true setup success + */ +static BOOL IntTestSuiteSetUp() +{ + LiteTestPrint("test_demo1 setup\n"); + return TRUE; +} + +/** + * @tc.teardown: define a setup for test suit, format:"IntTestSuite + TearDown" + * @return: true teardown success + */ +static BOOL IntTestSuiteTearDown() +{ + LiteTestPrint("test_demo1 tearDown\n"); + return TRUE; +} + +/** + * @tc.number : Test_Case_100 + * @tc.name : Verify int check function + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(IntTestSuite, TestCase001, LEVEL1) +{ + TEST_ASSERT_EQUAL_INT(LEVEL2, LEVEL3); +}; + +/** + * @tc.number : Test_Case_200 + * @tc.name : Verify int check function + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(IntTestSuite, TestCase002, LEVEL2) +{ + TEST_ASSERT_EQUAL_INT(LEVEL2, LEVEL2); +}; + +RUN_TEST_SUITE(IntTestSuite); \ No newline at end of file diff --git a/sample_lite/hctest_hal/src/test_demo2.c b/sample_lite/hctest_hal/src/test_demo2.c new file mode 100755 index 0000000000000000000000000000000000000000..7eb979500a643afd63300ba08219c0a7afc66e9a --- /dev/null +++ b/sample_lite/hctest_hal/src/test_demo2.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2020 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 "hctest.h" + +/** + * @tc.name: register a test suit named "StringTestSuite" + * @param: test subsystem name + * @param: example module name + * @param: StringTestSuite test suit name + */ +LITE_TEST_SUIT(test, example, StringTestSuite); + +/** + * @tc.setup: define a setup for test suit, format:"StringTestSuite + SetUp" + * @return: true——setup success + */ +static BOOL StringTestSuiteSetUp() +{ + LiteTestPrint("test_demo2 setup\n"); + return TRUE; +} + +/** + * @tc.teardown: define a setup for test suit, format:"StringTestSuite + TearDown" + * @return: true——teardown success + */ +static BOOL StringTestSuiteTearDown() +{ + LiteTestPrint("test_demo2 tearDown\n"); + return TRUE; +} + +/** + * @tc.number : Test_Case_300 + * @tc.name : Verify string check function + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(StringTestSuite, TestCase003, LEVEL1) +{ + const char* value = "testing"; + TEST_ASSERT_EQUAL_STRING(value, "testing1"); +}; + +/** + * @tc.number : Test_Case_400 + * @tc.name : Verify string check function + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +LITE_TEST_CASE(StringTestSuite, TestCase004, LEVEL2) +{ + const char* value = "testing"; + TEST_ASSERT_EQUAL_STRING(value, "testing"); +}; + +RUN_TEST_SUITE(StringTestSuite); \ No newline at end of file diff --git a/security_lite/BUILD.gn b/security_lite/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..575ff1fa7636ca6f79c0dfec1dc1a9f278fbbf70 --- /dev/null +++ b/security_lite/BUILD.gn @@ -0,0 +1,19 @@ + # Copyright (c) 2020 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. + +group("securitytest") { + deps = [ + "//test/xts/acts/security_lite/permission_posix/dac:ActsDacTest", + "//test/xts/acts/security_lite/datahuks_posix:ActsSecurityDataTest", + ] +} diff --git a/security_lite/datahuks_hal/BUILD.gn b/security_lite/datahuks_hal/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..c38fa9f3a43f9a78a7ed773330c9d9b099c188c8 --- /dev/null +++ b/security_lite/datahuks_hal/BUILD.gn @@ -0,0 +1,31 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hctest_suite("ActsSecurityDataTest") { + suite_name = "acts" + sources = [ + "src/security_data_huks_gen_del_test.c", + "src/security_data_huks_sign_verify_test.c", + "src/security_data_huks_enc_test.c", + "src/security_data_huks_dec_test.c", + "src/security_data_huks_export_hash_random_test.c", + ] + + include_dirs = [ + "src", + "//base/security/interfaces/innerkits/huks_lite/", + ] + cflags = [ "-Wno-error" ] +} diff --git a/security_lite/datahuks_hal/Test.tmpl b/security_lite/datahuks_hal/Test.tmpl new file mode 100755 index 0000000000000000000000000000000000000000..be8407e1286041a5af2bdc75a15633337376eb9d --- /dev/null +++ b/security_lite/datahuks_hal/Test.tmpl @@ -0,0 +1,19 @@ +{ + "description": "Config for $module test cases", + "environment": [ + { + "type": "device", + "label": "wifiiot" + } + ], + "kits": [ + { + "type": "DeployKit", + "timeout": "20000", + "burn_file": "$subsystem/$module.bin" + } + ], + "driver": { + "type": "CTestLite" + } +} \ No newline at end of file diff --git a/security_lite/datahuks_hal/src/security_data_huks.h b/security_lite/datahuks_hal/src/security_data_huks.h new file mode 100755 index 0000000000000000000000000000000000000000..48563919ac018c4625d41f51c3b4a769b61c1296 --- /dev/null +++ b/security_lite/datahuks_hal/src/security_data_huks.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2020 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 TEST_XTS_ACTS_SECURITY_LITE_DATAHUKS_HAL_SRC_SECURITY_DATA_HUKS_H +#define TEST_XTS_ACTS_SECURITY_LITE_DATAHUKS_HAL_SRC_SECURITY_DATA_HUKS_H + +#include "hctest.h" +#include "hks_client.h" +#include "hks_types.h" +#include "securec.h" +#include +#include +#include +#include +#include + +#define NUM1 1 +#define NUM2 2 +#define NUM3 3 +#define NUM4 4 +#define NUM5 5 +#define NUM6 6 +#define NUM10 10 +#define NUM11 11 +#define NUM12 12 +#define NUM15 15 +#define NUM16 16 +#define NUM20 20 +#define NUM21 21 +#define NUM24 24 +#define NUM25 25 +#define NUM30 30 +#define NUM31 31 +#define NUM32 32 +#define NUM33 33 +#define NUM60 60 +#define NUM63 63 +#define NUM64 64 +#define NUM65 65 +#define NUM88 88 +#define NUM100 100 +#define NUM111 111 +#define NUM128 128 +#define NUM192 192 +#define NUM256 256 +#define NUM1025 1025 +#define NUM134 (-134) +#define NUM135 (-135) +#define NUM138 (-138) +#define NUM142 (-142) +#define NUM1000 (-1000) +#define NUM1004 (-1004) +#define NUM1005 (-1005) +#define NUM1006 (-1006) +#define NUM1007 (-1007) +#define NUM1010 (-1010) +#define MAX_INT 2147483647 +#define HKS_FREE_PTR1(p) { if ((p) != NULL) { free(p); (p) = NULL; }} + +void HksStBlobInit1(struct hks_blob *blob, size_t nmemb, size_t size, uint8_t type); + +void HksBlobDestroyT1(struct hks_blob *blob); + +int TestSecShuksGenerateKeyNormal(void); + +int TestSecShuksDeleteKeyNormal(void); + +int TestSecShuksExportPublicNormal(struct hks_blob *keyAlias, struct hks_blob *publicKey1); + +void BuildBlobData(struct hks_blob *param, const char *str, uint8_t type, uint32_t size, uint8_t isDataNull); + +void HexStringToByte(const char *str, int nLen, unsigned char *pHex); + +void TestInitKeyParam1(struct hks_key_param *keyParam, uint32_t keyType, uint32_t keyLen, uint32_t keyMode, + uint32_t keyUsage); + +int TestSecShuksImportPublicNormal(void); + +#endif diff --git a/security_lite/datahuks_hal/src/security_data_huks_dec_test.c b/security_lite/datahuks_hal/src/security_data_huks_dec_test.c new file mode 100755 index 0000000000000000000000000000000000000000..6039aea03dcf62d1bf09bdf185bf570e517a8b90 --- /dev/null +++ b/security_lite/datahuks_hal/src/security_data_huks_dec_test.c @@ -0,0 +1,1363 @@ +/* Copyright (c) 2020 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 "security_data_huks.h" +#include "hctest.h" +#include "hks_client.h" +#include "hks_types.h" +#include +#include +#include +#include +#include + +/* * + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is security + * @param : module name is securityData + * @param : test suit name is SecurityDataHuksDecTestSuite + */ +LITE_TEST_SUIT(security, securityData, SecurityDataHuksDecTestSuite); + +/* * + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL SecurityDataHuksDecTestSuiteSetUp(void) +{ + int32_t status; + status = hks_init(); + if (status != 0) { + status = hks_refresh_key_info(); + } + TEST_ASSERT_EQUAL_INT(0, status); + return TRUE; +} + +/* * + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL SecurityDataHuksDecTestSuiteTearDown(void) +{ + printf("-++++++++++++++++++++++++++++++++++++++++++++-\n"); + return TRUE; +} + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Decrypt key +// begin++++++++++++++++++++++++++++++++++++++++++++++++++++0760-0990 + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0760, LEVEL1) +{ + char alias[] = "test_hks_aead_encrypt"; + int32_t statusEncrypt; + int32_t statusDecrypt; + + struct hks_blob key; + HksStBlobInit1(&key, 1, NUM16, HKS_BLOB_TYPE_KEY); + hks_generate_random(&key); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + struct hks_blob nonce; + HksStBlobInit1(&nonce, 1, NUM16, HKS_BLOB_TYPE_IV); + hks_generate_random(&nonce); + + struct hks_blob aad; + HksStBlobInit1(&aad, 1, NUM16, HKS_BLOB_TYPE_AAD); + hks_generate_random(&aad); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + HksStBlobInit1(&plaintext, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + hks_generate_random(&plaintext); + + struct hks_blob ciphertext; + HksStBlobInit1(&ciphertext, 1, NUM64 + HKS_SALT_MAX_SIZE, HKS_BLOB_TYPE_CIPHER_TEXT); + statusEncrypt = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(0, statusEncrypt); + + struct hks_blob decrypted; + HksStBlobInit1(&decrypted, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + statusDecrypt = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(0, statusDecrypt); + + size_t k; + for (k = 0; k < decrypted.size; k++) { + TEST_ASSERT_EQUAL_INT(plaintext.data[k], decrypted.data[k]); + } + HksBlobDestroyT1(&key); + HksBlobDestroyT1(&nonce); + HksBlobDestroyT1(&aad); + HksBlobDestroyT1(&plaintext); + HksBlobDestroyT1(&ciphertext); + HksBlobDestroyT1(&decrypted); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0770, LEVEL1) +{ + char alias[] = "test_hks_aead_encrypt"; + int32_t statusEncrypt; + int32_t statusDecrypt; + + struct hks_blob key; + HksStBlobInit1(&key, 1, NUM24, HKS_BLOB_TYPE_KEY); + hks_generate_random(&key); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM192; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + struct hks_blob nonce; + HksStBlobInit1(&nonce, 1, NUM16, HKS_BLOB_TYPE_IV); + hks_generate_random(&nonce); + + struct hks_blob aad; + HksStBlobInit1(&aad, 1, NUM16, HKS_BLOB_TYPE_AAD); + hks_generate_random(&aad); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + HksStBlobInit1(&plaintext, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + hks_generate_random(&plaintext); + + struct hks_blob ciphertext; + HksStBlobInit1(&ciphertext, 1, NUM64 + HKS_SALT_MAX_SIZE, HKS_BLOB_TYPE_CIPHER_TEXT); + statusEncrypt = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(0, statusEncrypt); + + struct hks_blob decrypted; + HksStBlobInit1(&decrypted, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + statusDecrypt = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(0, statusDecrypt); + + size_t k; + for (k = 0; k < decrypted.size; k++) { + TEST_ASSERT_EQUAL_INT(plaintext.data[k], decrypted.data[k]); + } + HksBlobDestroyT1(&key); + HksBlobDestroyT1(&nonce); + HksBlobDestroyT1(&aad); + HksBlobDestroyT1(&plaintext); + HksBlobDestroyT1(&ciphertext); + HksBlobDestroyT1(&decrypted); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0780, LEVEL1) +{ + char alias[] = "test_hks_aead_encrypt"; + int32_t statusEncrypt; + int32_t statusDecrypt; + + struct hks_blob key; + HksStBlobInit1(&key, 1, NUM32, HKS_BLOB_TYPE_KEY); + hks_generate_random(&key); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM256; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + struct hks_blob nonce; + HksStBlobInit1(&nonce, 1, NUM16, HKS_BLOB_TYPE_IV); + hks_generate_random(&nonce); + + struct hks_blob aad; + HksStBlobInit1(&aad, 1, NUM16, HKS_BLOB_TYPE_AAD); + hks_generate_random(&aad); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + HksStBlobInit1(&plaintext, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + hks_generate_random(&plaintext); + + struct hks_blob ciphertext; + HksStBlobInit1(&ciphertext, 1, NUM64 + HKS_SALT_MAX_SIZE, HKS_BLOB_TYPE_CIPHER_TEXT); + statusEncrypt = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(0, statusEncrypt); + + struct hks_blob decrypted; + HksStBlobInit1(&decrypted, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + statusDecrypt = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(0, statusDecrypt); + + size_t k; + for (k = 0; k < decrypted.size; k++) { + TEST_ASSERT_EQUAL_INT(plaintext.data[k], decrypted.data[k]); + } + HksBlobDestroyT1(&key); + HksBlobDestroyT1(&nonce); + HksBlobDestroyT1(&aad); + HksBlobDestroyT1(&plaintext); + HksBlobDestroyT1(&ciphertext); + HksBlobDestroyT1(&decrypted); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0790, LEVEL2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob *key = NULL; // = NULL + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0800, LEVEL2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = NUM32; // != key_param.key_len / 8 + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM1006, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0810, LEVEL2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = NULL; // = NULL + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM1006, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0820, LEVEL2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = 0; // != HKS_KEY_TYPE_AES + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM1006, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0830, LEVEL2) +{ + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param *keyParam = NULL; // = NULL + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0840, LEVEL2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = 0; // != HKS_ALG_GCM + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0850, LEVEL2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM12; // != 128 192 256 + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0860, LEVEL2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = 0; // != HKS_KEY_TYPE_AES + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0870, LEVEL2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = NUM88; // != HKS_PADDING_NONE + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0880, LEVEL2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = 0; // = 0 + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0890, LEVEL2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param *cryptParam = NULL; // = NULL + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0900, LEVEL2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = 0; // = 0 + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0910, LEVEL2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = NULL; // = NULL + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0920, LEVEL2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = 0; // = 0 + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0930, LEVEL2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = NULL; // = NULL + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0940, LEVEL2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob *decrypted = NULL; // = NULL + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0950, LEVEL2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = NULL; // = NULL + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0960, LEVEL2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = NUM15; // < -16 + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0970, LEVEL2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob *ciphertext = NULL; // = NULL + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, ciphertext); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0980, LEVEL2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = NULL; // = NULL + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1200 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt0990, LEVEL2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = NUM10; // < -16 + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Decrypt key +// begin++++++++++++++++++++++++++++++++++++++++++++++++++++0760-0990 + +RUN_TEST_SUITE(SecurityDataHuksDecTestSuite); diff --git a/security_lite/datahuks_hal/src/security_data_huks_enc_test.c b/security_lite/datahuks_hal/src/security_data_huks_enc_test.c new file mode 100755 index 0000000000000000000000000000000000000000..ddad43073fa1e727221fdc8a5aa73acbc645db89 --- /dev/null +++ b/security_lite/datahuks_hal/src/security_data_huks_enc_test.c @@ -0,0 +1,1384 @@ +/* Copyright (c) 2020 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 "security_data_huks.h" +#include "hctest.h" +#include "hks_client.h" +#include "hks_types.h" +#include +#include +#include +#include +#include + +/* * + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is security + * @param : module name is securityData + * @param : test suit name is securityDataHuksEncTestSuite + */ +LITE_TEST_SUIT(security, securityData, SecurityDataHuksEncTestSuite); + +/* * + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL SecurityDataHuksEncTestSuiteSetUp(void) +{ + int32_t status; + status = hks_init(); + if (status != 0) { + status = hks_refresh_key_info(); + } + TEST_ASSERT_EQUAL_INT(0, status); + return TRUE; +} + +/* * + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL SecurityDataHuksEncTestSuiteTearDown(void) +{ + printf("-++++++++++++++++++++++++++++++++++++++++++++-\n"); + return TRUE; +} + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Encrypt key +// begin++++++++++++++++++++++++++++++++++++++++++++++++++++0520-0750 + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0520, LEVEL1) +{ + char alias[] = "test_hks_aead_encrypt"; + int32_t statusEncrypt; + int32_t statusDecrypt; + + struct hks_blob key; + HksStBlobInit1(&key, 1, NUM16, HKS_BLOB_TYPE_KEY); + hks_generate_random(&key); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + struct hks_blob nonce; + HksStBlobInit1(&nonce, 1, NUM16, HKS_BLOB_TYPE_IV); + hks_generate_random(&nonce); + + struct hks_blob aad; + HksStBlobInit1(&aad, 1, NUM16, HKS_BLOB_TYPE_AAD); + hks_generate_random(&aad); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + HksStBlobInit1(&plaintext, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + hks_generate_random(&plaintext); + + struct hks_blob ciphertext; + HksStBlobInit1(&ciphertext, 1, NUM64 + HKS_SALT_MAX_SIZE, HKS_BLOB_TYPE_CIPHER_TEXT); + statusEncrypt = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(0, statusEncrypt); + + struct hks_blob decrypted; + HksStBlobInit1(&decrypted, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + statusDecrypt = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(0, statusDecrypt); + + size_t k; + for (k = 0; k < decrypted.size; k++) { + TEST_ASSERT_EQUAL_INT(plaintext.data[k], decrypted.data[k]); + } + HksBlobDestroyT1(&key); + HksBlobDestroyT1(&nonce); + HksBlobDestroyT1(&aad); + HksBlobDestroyT1(&plaintext); + HksBlobDestroyT1(&ciphertext); + HksBlobDestroyT1(&decrypted); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0530, LEVEL1) +{ + char alias[] = "test_hks_aead_encrypt"; + int32_t statusEncrypt; + int32_t statusDecrypt; + + struct hks_blob key; + HksStBlobInit1(&key, 1, NUM24, HKS_BLOB_TYPE_KEY); + hks_generate_random(&key); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM192; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + struct hks_blob nonce; + HksStBlobInit1(&nonce, 1, NUM16, HKS_BLOB_TYPE_IV); + hks_generate_random(&nonce); + + struct hks_blob aad; + HksStBlobInit1(&aad, 1, NUM16, HKS_BLOB_TYPE_AAD); + hks_generate_random(&aad); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + HksStBlobInit1(&plaintext, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + hks_generate_random(&plaintext); + + struct hks_blob ciphertext; + HksStBlobInit1(&ciphertext, 1, NUM64 + HKS_SALT_MAX_SIZE, HKS_BLOB_TYPE_CIPHER_TEXT); + statusEncrypt = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(0, statusEncrypt); + + struct hks_blob decrypted; + HksStBlobInit1(&decrypted, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + statusDecrypt = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(0, statusDecrypt); + + size_t k; + for (k = 0; k < decrypted.size; k++) { + TEST_ASSERT_EQUAL_INT(plaintext.data[k], decrypted.data[k]); + } + HksBlobDestroyT1(&key); + HksBlobDestroyT1(&nonce); + HksBlobDestroyT1(&aad); + HksBlobDestroyT1(&plaintext); + HksBlobDestroyT1(&ciphertext); + HksBlobDestroyT1(&decrypted); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0540, LEVEL1) +{ + char alias[] = "test_hks_aead_encrypt"; + int32_t statusEncrypt; + int32_t statusDecrypt; + + struct hks_blob key; + HksStBlobInit1(&key, 1, NUM32, HKS_BLOB_TYPE_KEY); + hks_generate_random(&key); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM256; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + struct hks_blob nonce; + HksStBlobInit1(&nonce, 1, NUM16, HKS_BLOB_TYPE_IV); + hks_generate_random(&nonce); + + struct hks_blob aad; + HksStBlobInit1(&aad, 1, NUM16, HKS_BLOB_TYPE_AAD); + hks_generate_random(&aad); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + HksStBlobInit1(&plaintext, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + hks_generate_random(&plaintext); + + struct hks_blob ciphertext; + HksStBlobInit1(&ciphertext, 1, NUM64 + HKS_SALT_MAX_SIZE, HKS_BLOB_TYPE_CIPHER_TEXT); + statusEncrypt = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(0, statusEncrypt); + + struct hks_blob decrypted; + HksStBlobInit1(&decrypted, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + statusDecrypt = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + TEST_ASSERT_EQUAL_INT(0, statusDecrypt); + + size_t k; + for (k = 0; k < decrypted.size; k++) { + TEST_ASSERT_EQUAL_INT(plaintext.data[k], decrypted.data[k]); + } + HksBlobDestroyT1(&key); + HksBlobDestroyT1(&nonce); + HksBlobDestroyT1(&aad); + HksBlobDestroyT1(&plaintext); + HksBlobDestroyT1(&ciphertext); + HksBlobDestroyT1(&decrypted); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0550, LEVEL2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob *key = NULL; // = NULL + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0560, LEVEL2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = NUM32; // != key_param.key_len / 8 + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM1006, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0570, LEVEL2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = NULL; // = NULL + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM1006, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0580, LEVEL2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = 0; // != HKS_BLOB_TYPE_KEY + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM1006, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0590, LEVEL2) +{ + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param *keyParam = NULL; // = NULL + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0600, LEVEL2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = 0; // != HKS_ALG_GCM + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0610, LEVEL2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM11; // != 128 192 256 + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0620, LEVEL2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = 0; // != HKS_KEY_TYPE_AES + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0630, LEVEL2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = NUM88; // != HKS_PADDING_NONE + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0640, LEVEL2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = 0; // = 0 + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0650, LEVEL2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param *cryptParam = NULL; // = NULL + + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0660, LEVEL2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = NUM10; // < 12 + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0670, LEVEL2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = NULL; // = NULL + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0680, LEVEL2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = 0; // = 0 + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0690, LEVEL2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = NULL; // = NULL + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0700, LEVEL2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob *plaintext = NULL; // = NULL + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0710, LEVEL2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = NULL; // = NULL + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0720, LEVEL2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = 0; // = 0 + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0730, LEVEL2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob *ciphertext = NULL; // = NULL + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, ciphertext); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0740, LEVEL2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = NULL; // = NULL + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1100 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt0750, LEVEL2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = NUM10; // < +16 + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Encrypt key +// end==++++++++++++++++++++++++++++++++++++++++++++++++++++0520-0750 + +RUN_TEST_SUITE(SecurityDataHuksEncTestSuite); diff --git a/security_lite/datahuks_hal/src/security_data_huks_export_hash_random_test.c b/security_lite/datahuks_hal/src/security_data_huks_export_hash_random_test.c new file mode 100755 index 0000000000000000000000000000000000000000..8c845d472f602fa61ebc6f51a2bb9bdd2e2dd9ab --- /dev/null +++ b/security_lite/datahuks_hal/src/security_data_huks_export_hash_random_test.c @@ -0,0 +1,675 @@ +/* Copyright (c) 2020 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 "security_data_huks.h" +#include "hctest.h" +#include "hks_client.h" +#include "hks_types.h" +#include +#include +#include +#include +#include + +/* * + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is security + * @param : module name is securityData + * @param : test suit name is SecurityDataHuksExportHashRandomHmacTestSuite + */ +LITE_TEST_SUIT(security, securityData, SecurityDataHuksExportHashRandomHmacTestSuite); + +/* * + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL SecurityDataHuksExportHashRandomHmacTestSuiteSetUp(void) +{ + int32_t status; + status = hks_init(); + if (status != 0) { + status = hks_refresh_key_info(); + } + TEST_ASSERT_EQUAL_INT(0, status); + return TRUE; +} + +/* * + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL SecurityDataHuksExportHashRandomHmacTestSuiteTearDown(void) +{ + printf("-++++++++++++++++++++++++++++++++++++++++++++-\n"); + return TRUE; +} + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Export Public key +// begin++++++++++++++++++++++++++++++++++++++++++++++1000-1090 + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0700 + * @tc.name : Export Public Key + * @tc.desc : [C- SECURITY -1800] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataExportPublicKey1000, LEVEL1) +{ + int32_t status; + char testFileName[] = "keyalias1"; + struct hks_blob keyAlias = { 0 }; + + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + (void)TestSecShuksGenerateKeyNormal(); + + struct hks_blob publicKey1 = { 0 }; + HksStBlobInit1(&publicKey1, 1, NUM32, HKS_BLOB_TYPE_KEY); + status = hks_export_public_key(&keyAlias, &publicKey1); + TEST_ASSERT_EQUAL_INT(0, status); + HksBlobDestroyT1(&publicKey1); + (void)TestSecShuksDeleteKeyNormal(); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0700 + * @tc.name : Export Public Key + * @tc.desc : [C- SECURITY -1800] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataExportPublicKey1010, LEVEL2) +{ + int32_t status; + struct hks_blob *keyAlias = NULL; // = NULL + struct hks_blob publicKey1 = { 0 }; + + publicKey1.data = (uint8_t *)malloc(NUM32); + if (publicKey1.data == NULL) { + return; + } + publicKey1.size = NUM32; + publicKey1.type = HKS_BLOB_TYPE_KEY; + + status = hks_export_public_key(keyAlias, &publicKey1); + TEST_ASSERT_EQUAL_INT(NUM1000, status); + HksBlobDestroyT1(&publicKey1); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0700 + * @tc.name : Export Public Key + * @tc.desc : [C- SECURITY -1800] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataExportPublicKey1020, LEVEL2) +{ + int32_t status; + char testFileName[] = "Test_file_north_interfaces"; + struct hks_blob keyAlias = { 0 }; + struct hks_blob publicKey1 = { 0 }; + keyAlias.data = NULL; // = NULL + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + publicKey1.data = (uint8_t *)malloc(NUM32); + if (publicKey1.data == NULL) { + return; + } + publicKey1.size = NUM32; + publicKey1.type = HKS_BLOB_TYPE_KEY; + + status = hks_export_public_key(&keyAlias, &publicKey1); + TEST_ASSERT_EQUAL_INT(NUM135, status); + HksBlobDestroyT1(&publicKey1); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0700 + * @tc.name : Export Public Key + * @tc.desc : [C- SECURITY -1800] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataExportPublicKey1030, LEVEL2) +{ + int32_t status; + char testFileName[] = "Test_file_north_interfaces"; + struct hks_blob keyAlias = { 0 }; + struct hks_blob publicKey1 = { 0 }; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = 0; // != HKS_BLOB_TYPE_ALIAS + + publicKey1.data = (uint8_t *)malloc(NUM32); + if (publicKey1.data == NULL) { + return; + } + publicKey1.size = NUM32; + publicKey1.type = HKS_BLOB_TYPE_KEY; + + status = hks_export_public_key(&keyAlias, &publicKey1); + TEST_ASSERT_EQUAL_INT(NUM135, status); + HksBlobDestroyT1(&publicKey1); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0700 + * @tc.name : Export Public Key + * @tc.desc : [C- SECURITY -1800] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataExportPublicKey1040, LEVEL2) +{ + int32_t status; + char testFileName[] = "Test_file_north_interfaces"; + struct hks_blob keyAlias = { 0 }; + struct hks_blob publicKey1 = { 0 }; + + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = 0; // = 0 + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + publicKey1.data = (uint8_t *)malloc(NUM32); + if (publicKey1.data == NULL) { + return; + } + publicKey1.size = NUM32; + publicKey1.type = HKS_BLOB_TYPE_KEY; + + status = hks_export_public_key(&keyAlias, &publicKey1); + TEST_ASSERT_EQUAL_INT(NUM135, status); + HksBlobDestroyT1(&publicKey1); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0700 + * @tc.name : Export Public Key + * @tc.desc : [C- SECURITY -1800] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataExportPublicKey1050, LEVEL2) +{ + int32_t status; + char testFileName[] = "Test_file_north_interfaces"; + struct hks_blob keyAlias = { 0 }; + struct hks_blob publicKey1 = { 0 }; + + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = NUM65; // > 64 + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + publicKey1.data = (uint8_t *)malloc(NUM32); + if (publicKey1.data == NULL) { + return; + } + publicKey1.size = NUM32; + publicKey1.type = HKS_BLOB_TYPE_KEY; + + status = hks_export_public_key(&keyAlias, &publicKey1); + TEST_ASSERT_EQUAL_INT(NUM135, status); + HksBlobDestroyT1(&publicKey1); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0700 + * @tc.name : Export Public Key + * @tc.desc : [C- SECURITY -1800] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataExportPublicKey1060, LEVEL2) +{ + int32_t status; + char testFileName[] = "Test_file_north_interfaces"; + struct hks_blob keyAlias = { 0 }; + struct hks_blob *publicKey1 = NULL; // = NULL + + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + status = hks_export_public_key(&keyAlias, publicKey1); + TEST_ASSERT_EQUAL_INT(NUM1000, status); + HksBlobDestroyT1(&keyAlias); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0700 + * @tc.name : Export Public Key + * @tc.desc : [C- SECURITY -1800] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataExportPublicKey1070, LEVEL2) +{ + int32_t status; + char testFileName[] = "Test_file_north_interfaces"; + struct hks_blob keyAlias = { 0 }; + struct hks_blob publicKey1 = { 0 }; + + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + publicKey1.data = (uint8_t *)malloc(NUM31); + if (publicKey1.data == NULL) { + return; + } + publicKey1.size = NUM31; // < 32 + publicKey1.type = HKS_BLOB_TYPE_KEY; + + status = hks_export_public_key(&keyAlias, &publicKey1); + TEST_ASSERT_EQUAL_INT(NUM1007, status); + HksBlobDestroyT1(&publicKey1); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0700 + * @tc.name : Export Public Key + * @tc.desc : [C- SECURITY -1800] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataExportPublicKey1080, LEVEL2) +{ + int32_t status; + char testFileName[] = "Test_file_north_interfaces"; + struct hks_blob keyAlias = { 0 }; + struct hks_blob publicKey1 = { 0 }; + + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + publicKey1.data = NULL; // = NULL + publicKey1.size = NUM32; + publicKey1.type = HKS_BLOB_TYPE_KEY; + + status = hks_export_public_key(&keyAlias, &publicKey1); + TEST_ASSERT_EQUAL_INT(NUM1007, status); + HksBlobDestroyT1(&publicKey1); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0700 + * @tc.name : Export Public Key + * @tc.desc : [C- SECURITY -1800] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataExportPublicKey1090, LEVEL2) +{ + int32_t status; + char testFileName[] = "Test_file_north_interfaces"; + struct hks_blob keyAlias = { 0 }; + struct hks_blob publicKey1 = { 0 }; + + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + publicKey1.data = (uint8_t *)malloc(NUM32); + if (publicKey1.data == NULL) { + return; + } + publicKey1.size = NUM32; + publicKey1.type = HKS_BLOB_TYPE_KEY; + + status = hks_export_public_key(&keyAlias, &publicKey1); + TEST_ASSERT_EQUAL_INT(NUM1010, status); + HksBlobDestroyT1(&publicKey1); +} + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Export Public key +// end++++++++++++++++++++++++++++++++++++++++++++++++1000-1090 + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Hash +// begin+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++1100-1190 + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1600 + * @tc.name : Hash + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataHash1100, LEVEL1) +{ + struct hks_blob src, dst; + src.data = (uint8_t *)"123456"; + src.size = NUM6; + dst.data = (uint8_t *)malloc(NUM65); + if (dst.data == NULL) { + return; + } + dst.size = NUM65; + + int32_t res = hks_hash(HKS_ALG_HASH_SHA_256, &src, &dst); + TEST_ASSERT_EQUAL_INT(0, res); + free(dst.data); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1600 + * @tc.name : Hash + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataHash1110, LEVEL1) +{ + struct hks_blob src, dst; + src.data = (uint8_t *)"123456"; + src.size = NUM6; + dst.data = (uint8_t *)malloc(NUM65); + if (dst.data == NULL) { + return; + } + dst.size = NUM65; + + int32_t res = hks_hash(HKS_ALG_HASH_SHA_512, &src, &dst); + TEST_ASSERT_EQUAL_INT(0, res); + free(dst.data); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1600 + * @tc.name : Hash + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataHash1120, LEVEL2) +{ + struct hks_blob srcData = { 0 }; + const char tmpData6[] = "30313233343536373839616263646566"; + BuildBlobData(&srcData, tmpData6, HKS_BLOB_TYPE_RAW, NUM16, 0); + + struct hks_blob hash = { 0 }; + const char tmpData7[] = "3031323334353637383961626364656630313233343536373839616263646566"; + BuildBlobData(&hash, tmpData7, HKS_BLOB_TYPE_RAW, NUM32, 0); + + uint32_t alg = HKS_ALG_HASH_SHA_1; // != HKS_ALG_HASH_SHA_256 HKS_ALG_HASH_SHA_512 + int32_t status = hks_hash(alg, &srcData, &hash); + HksBlobDestroyT1(&srcData); + HksBlobDestroyT1(&hash); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1600 + * @tc.name : Hash + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataHash1130, LEVEL2) +{ + struct hks_blob *srcData = NULL; // = NULL + + struct hks_blob hash = { 0 }; + const char tmpData7[] = "3031323334353637383961626364656630313233343536373839616263646566"; + BuildBlobData(&hash, tmpData7, HKS_BLOB_TYPE_RAW, NUM32, 0); + + uint32_t alg = HKS_ALG_HASH_SHA_256; + int32_t status = hks_hash(alg, srcData, &hash); + HksBlobDestroyT1(&hash); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1600 + * @tc.name : Hash + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataHash1140, LEVEL2) +{ + struct hks_blob srcData = { 0 }; + const char tmpData6[] = "30313233343536373839616263646566"; + BuildBlobData(&srcData, tmpData6, HKS_BLOB_TYPE_RAW, NUM16, 1); // srcData.data = NULL + + struct hks_blob hash = { 0 }; + const char tmpData7[] = "3031323334353637383961626364656630313233343536373839616263646566"; + BuildBlobData(&hash, tmpData7, HKS_BLOB_TYPE_RAW, NUM32, 0); + + uint32_t alg = HKS_ALG_HASH_SHA_256; + int32_t status = hks_hash(alg, &srcData, &hash); + HksBlobDestroyT1(&srcData); + HksBlobDestroyT1(&hash); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1600 + * @tc.name : Hash + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataHash1150, LEVEL2) +{ + struct hks_blob srcData = { 0 }; + srcData.data = (uint8_t *)"1234567890abcdefghigkl0123456789"; + srcData.size = 0; // = 0 + srcData.type = HKS_BLOB_TYPE_RAW; + + struct hks_blob hash = { 0 }; + const char tmpData7[] = "3031323334353637383961626364656630313233343536373839616263646566"; + BuildBlobData(&hash, tmpData7, HKS_BLOB_TYPE_RAW, NUM32, 0); + + uint32_t alg = HKS_ALG_HASH_SHA_256; + int32_t status = hks_hash(alg, &srcData, &hash); + HksBlobDestroyT1(&hash); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1600 + * @tc.name : Hash + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataHash1160, LEVEL2) +{ + struct hks_blob srcData = { 0 }; + const char tmpData6[] = "30313233343536373839616263646566"; + BuildBlobData(&srcData, tmpData6, HKS_BLOB_TYPE_RAW, NUM16, 0); + + struct hks_blob *hash = NULL; // = NULL + + uint32_t alg = HKS_ALG_HASH_SHA_256; + int32_t status = hks_hash(alg, &srcData, hash); + HksBlobDestroyT1(&srcData); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1600 + * @tc.name : Hash + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataHash1170, LEVEL2) +{ + struct hks_blob srcData = { 0 }; + const char tmpData6[] = "30313233343536373839616263646566"; + BuildBlobData(&srcData, tmpData6, HKS_BLOB_TYPE_RAW, NUM16, 0); + + struct hks_blob hash = { 0 }; + const char tmpData7[] = "3031323334353637383961626364656630313233343536373839616263646566"; + BuildBlobData(&hash, tmpData7, HKS_BLOB_TYPE_RAW, NUM32, 1); // hash.data = NULL + + uint32_t alg = HKS_ALG_HASH_SHA_256; + int32_t status = hks_hash(alg, &srcData, &hash); + HksBlobDestroyT1(&srcData); + HksBlobDestroyT1(&hash); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1600 + * @tc.name : Hash + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataHash1180, LEVEL2) +{ + struct hks_blob srcData = { 0 }; + const char tmpData6[] = "30313233343536373839616263646566"; + BuildBlobData(&srcData, tmpData6, HKS_BLOB_TYPE_RAW, NUM16, 0); + + struct hks_blob hash = { 0 }; + const char tmpData7[] = "303132333435363738396162636465663031323334353637383961626361"; + BuildBlobData(&hash, tmpData7, HKS_BLOB_TYPE_RAW, NUM30, 0); // hash.size < 32 + + uint32_t alg = HKS_ALG_HASH_SHA_256; + int32_t status = hks_hash(alg, &srcData, &hash); + HksBlobDestroyT1(&srcData); + HksBlobDestroyT1(&hash); + TEST_ASSERT_EQUAL_INT(NUM1007, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1600 + * @tc.name : Hash + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataHash1190, LEVEL2) +{ + struct hks_blob srcData = { 0 }; + const char tmpData6[] = "30313233343536373839616263646566"; + BuildBlobData(&srcData, tmpData6, HKS_BLOB_TYPE_RAW, NUM16, 0); + + struct hks_blob hash = { 0 }; + const char tmpData7[] = "303132333435363738396162636465663031323334353637383961626361303132333435363738396162636465663031323334353637383961626361"; + BuildBlobData(&hash, tmpData7, HKS_BLOB_TYPE_RAW, NUM60, 0); // hash.size < 64 + + uint32_t alg = HKS_ALG_HASH_SHA_512; + int32_t status = hks_hash(alg, &srcData, &hash); + HksBlobDestroyT1(&srcData); + HksBlobDestroyT1(&hash); + TEST_ASSERT_EQUAL_INT(NUM1007, status); +} + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Hash +// end+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++1100-1190 + + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Generate random +// beign++++++++++++++++++++++++++++++++++++++++++++++++1200-1230 + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0800 + * @tc.name : Generate Random + * @tc.desc : [C- SECURITY -1700] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataGenerateRandom1200, LEVEL1) +{ + int32_t statusFirst; + int32_t statusSecond; + struct hks_blob randomFirst = { 0 }; + struct hks_blob randomSecond = { 0 }; + + HksStBlobInit1(&randomFirst, 1, NUM64, 0); + HksStBlobInit1(&randomSecond, 1, NUM64, 0); + statusFirst = hks_generate_random(&randomFirst); + statusSecond = hks_generate_random(&randomSecond); + TEST_ASSERT_EQUAL_INT(0, statusFirst); + TEST_ASSERT_EQUAL_INT(0, statusSecond); + TEST_ASSERT_NOT_EQUAL(randomFirst.data, randomSecond.data); + + HksBlobDestroyT1(&randomFirst); + HksBlobDestroyT1(&randomSecond); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0800 + * @tc.name : Generate Random + * @tc.desc : [C- SECURITY -1700] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataGenerateRandom1210, LEVEL2) +{ + int32_t status; + struct hks_blob *random = NULL; // = NULL + + status = hks_generate_random(random); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0800 + * @tc.name : Generate Random + * @tc.desc : [C- SECURITY -1700] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataGenerateRandom1220, LEVEL2) +{ + int32_t status; + struct hks_blob random = { 0 }; + + random.data = NULL; // = NULL + random.size = NUM32; + random.type = HKS_BLOB_TYPE_KEY; + + status = hks_generate_random(&random); + TEST_ASSERT_EQUAL_INT(NUM1000, status); + HksBlobDestroyT1(&random); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0800 + * @tc.name : Generate Random + * @tc.desc : [C- SECURITY -1700] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksExportHashRandomHmacTestSuite, securityDataGenerateRandom1230, LEVEL2) +{ + int32_t status; + struct hks_blob random = { 0 }; + + random.data = (uint8_t *)malloc(NUM1025); + if (random.data == NULL) { + return; + } + random.size = NUM1025; // > 1024 + random.type = HKS_BLOB_TYPE_KEY; + + status = hks_generate_random(&random); + TEST_ASSERT_EQUAL_INT(NUM135, status); + HksBlobDestroyT1(&random); +} + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Generate random +// end++++++++++++++++++++++++++++++++++++++++++++++++++1200-1230 + +RUN_TEST_SUITE(SecurityDataHuksExportHashRandomHmacTestSuite); diff --git a/security_lite/datahuks_hal/src/security_data_huks_gen_del_test.c b/security_lite/datahuks_hal/src/security_data_huks_gen_del_test.c new file mode 100755 index 0000000000000000000000000000000000000000..ead36c653999e49f8292f1065d6d0e8dfd8f1291 --- /dev/null +++ b/security_lite/datahuks_hal/src/security_data_huks_gen_del_test.c @@ -0,0 +1,873 @@ +/* Copyright (c) 2020 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 "security_data_huks.h" +#include "hctest.h" +#include "hks_client.h" +#include "hks_types.h" +#include "securec.h" +#include +#include +#include +#include +#include + +void HksStBlobInit1(struct hks_blob *blob, size_t nmemb, size_t size, uint8_t type) +{ + if (blob == NULL || nmemb == 0 || size == 0) { + TEST_ASSERT_EQUAL_INT(0, 1); + return; + } + blob->data = (uint8_t *)calloc(nmemb, size); + if (blob->data == NULL) { + TEST_ASSERT_EQUAL_INT(0, 1); + return; + } + if (memset_s(blob->data, size, 0, size) != EOK) { + TEST_ASSERT_EQUAL_INT(0, 1); + } + blob->size = size; + blob->type = type; +} +void HksBlobDestroyT1(struct hks_blob *blob) +{ + if (blob == NULL) { + return; + } + if (blob && blob->data) { + memset_s(blob->data, blob->size, 0, blob->size); + HKS_FREE_PTR1(blob->data); + } + blob->data = NULL; + blob->size = 0; + blob->type = HKS_BLOB_TYPE_RAW; +} +int TestSecShuksGenerateKeyNormal(void) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + struct hks_blob keyAlias; + + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + int32_t status = hks_generate_key(&keyAlias, &keyParam); + TEST_ASSERT_EQUAL_INT(0, status); + return 0; +} +int TestSecShuksDeleteKeyNormal(void) +{ + char testFileName[] = "keyalias1"; + struct hks_blob keyAlias = { 0 }; + + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + int32_t status = hks_delete_key(&keyAlias); + TEST_ASSERT_EQUAL_INT(0, status); + return 0; +} +int TestSecShuksExportPublicNormal(struct hks_blob *keyAlias, struct hks_blob *publicKey1) +{ + int32_t status = hks_export_public_key(keyAlias, publicKey1); + TEST_ASSERT_EQUAL_INT(0, status); + return 0; +} +void BuildBlobData(struct hks_blob *param, const char *str, uint8_t type, uint32_t size, uint8_t isDataNull) +{ + if (param == NULL) { + TEST_ASSERT_EQUAL_INT(0, 1); + return; + } + param->type = type; + param->size = size; + if (isDataNull == NUM1) { + param->data = NULL; + } else { + if (size == 0) { + return; + } + unsigned char *buff = (unsigned char *)malloc(size + NUM2); + if (buff == NULL) { + return; + } + memset_s(buff, size + NUM2, 0, size + NUM2); + HexStringToByte(str, size * NUM2, buff); + param->data = (uint8_t *)buff; + } +} +void HexStringToByte(const char *str, int nLen, unsigned char *pHex) +{ + unsigned int number = 4; + if (pHex == NULL) { + TEST_ASSERT_EQUAL_INT(0, 1); + return; + } + if (nLen % NUM2) { + TEST_ASSERT_EQUAL_INT(0, 1); + } + int nHexLen = nLen / NUM2; + unsigned char nibble[2]; + if (nHexLen >= MAX_INT) { + TEST_ASSERT_EQUAL_INT(0, 1); + return; + } + for (int i = 0; i < nHexLen; i++) { + nibble[0] = str[i * NUM2]; + nibble[1] = str[i * NUM2 + NUM1]; + for (int j = 0; j < NUM2; j++) { + if (nibble[j] <= 'F' && nibble[j] >= 'A') { + nibble[j] = nibble[j] - 'A' + NUM10; + } else if (nibble[j] <= 'f' && nibble[j] >= 'a') { + nibble[j] = nibble[j] - 'a' + NUM10; + } else if (nibble[j] >= '0' && nibble[j] <= '9') { + nibble[j] = nibble[j] - '0'; + } else { + TEST_ASSERT_EQUAL_INT(0, 1); + } + } + pHex[i] = nibble[0] << number; + pHex[i] |= nibble[1]; + } +} + +void TestInitKeyParam1(struct hks_key_param *keyParam, uint32_t keyType, uint32_t keyLen, uint32_t keyMode, + uint32_t keyUsage) +{ + if (keyParam == NULL) { + TEST_ASSERT_EQUAL_INT(0, 1); + return; + } + keyParam->key_type = keyType; + keyParam->key_len = keyLen; + keyParam->key_pad = HKS_PADDING_NONE; + keyParam->key_mode = keyMode; + keyParam->key_domain = HKS_ECC_CURVE_ED25519; + keyParam->key_usage = keyUsage; + + const char tmpData1[] = "111111"; + BuildBlobData(&keyParam->key_auth_id, tmpData1, HKS_BLOB_TYPE_AUTH_ID, NUM3, 0); +} + +int TestSecShuksImportPublicNormal(void) +{ + char testFileName[] = "keyalias1"; + struct hks_key_param keyParam1 = { 0 }; + + keyParam1.key_type = HKS_KEY_TYPE_EDDSA_PUBLIC_KEY_ED25519; + keyParam1.key_len = NUM256; + keyParam1.key_usage = NUM3; + keyParam1.key_pad = NUM4; + keyParam1.key_mode = NUM5; + keyParam1.key_role = NUM6; + keyParam1.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam1.key_auth_id.data = (uint8_t *)testFileName; + keyParam1.key_auth_id.size = sizeof(testFileName); + + struct hks_blob publicKey1 = { 0 }; + HksStBlobInit1(&publicKey1, NUM1, NUM32, HKS_BLOB_TYPE_KEY); + + struct hks_blob keyAlias; + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + + int32_t status = hks_import_public_key(&keyAlias, &keyParam1, &publicKey1); + TEST_ASSERT_EQUAL_INT(0, status); + + HksBlobDestroyT1(&publicKey1); + return 0; +} + +/* * + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is security + * @param : module name is securityData + * @param : test suit name is SecurityDataHuksGenDelTestSuite + */ +LITE_TEST_SUIT(security, securityData, SecurityDataHuksGenDelTestSuite); + +/* * + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL SecurityDataHuksGenDelTestSuiteSetUp(void) +{ + int32_t status; + status = hks_init(); + if (status != 0) { + status = hks_refresh_key_info(); + } + TEST_ASSERT_EQUAL_INT(0, status); + return TRUE; +} + +/* * + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL SecurityDataHuksGenDelTestSuiteTearDown(void) +{ + printf("-++++++++++++++++++++++++++++++++++++++++++++-\n"); + return TRUE; +} + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++generate key +// begin+++++++++++++++++++++++++++++++++++++++++++++++++++0000-0120 + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL0_0100 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey0000, LEVEL1) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + int32_t statusGenerate; + int32_t statusDelete; + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + struct hks_blob keyAliasGenerate; + HksStBlobInit1(&keyAliasGenerate, sizeof(uint8_t), sizeof(testFileName) + NUM3, HKS_BLOB_TYPE_ALIAS); + if (memcpy_s(keyAliasGenerate.data, sizeof(testFileName), testFileName, sizeof(testFileName)) != EOK) { + HksBlobDestroyT1(&keyAliasGenerate); + TEST_FAIL(); + return; + } + char tmpGenerate[3] = { 0 }; + if (strcat_s((char *)keyAliasGenerate.data, strlen((char *)keyAliasGenerate.data) + strlen(tmpGenerate) + 1, tmpGenerate) != EOK) { + HksBlobDestroyT1(&keyAliasGenerate); + TEST_FAIL(); + return; + } + keyAliasGenerate.size = strlen((char *)keyAliasGenerate.data); + statusGenerate = hks_generate_key(&keyAliasGenerate, &keyParam); + TEST_ASSERT_EQUAL_INT(0, statusGenerate); + HksBlobDestroyT1(&keyAliasGenerate); + struct hks_blob keyAliasDelete; + HksStBlobInit1(&keyAliasDelete, sizeof(uint8_t), sizeof(testFileName) + NUM3, HKS_BLOB_TYPE_ALIAS); + if (memcpy_s(keyAliasDelete.data, sizeof(testFileName), testFileName, sizeof(testFileName)) != EOK) { + HksBlobDestroyT1(&keyAliasDelete); + TEST_FAIL(); + return; + } + char tmpDelete[3] = { 0 }; + if (strcat_s((char *)keyAliasDelete.data, strlen((char *)keyAliasDelete.data) + strlen(tmpDelete) + 1, tmpDelete) != EOK) { + HksBlobDestroyT1(&keyAliasDelete); + TEST_FAIL(); + return; + } + keyAliasDelete.size = strlen((char *)keyAliasDelete.data); + statusDelete = hks_delete_key(&keyAliasDelete); + TEST_ASSERT_EQUAL_INT(0, statusDelete); + HksBlobDestroyT1(&keyAliasDelete); +}; + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL0_0100 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey0010, LEVEL2) +{ + char testFileName1[] = "key_auth_id1"; + struct hks_blob *keyAlias = NULL; // = NULL + int32_t status; + + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + + status = hks_generate_key(keyAlias, &keyParam); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL0_0100 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey0020, LEVEL2) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + struct hks_blob keyAlias; + int32_t status; + + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = 0; // = 0 + + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + + status = hks_generate_key(&keyAlias, &keyParam); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL0_0100 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey0030, LEVEL2) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + struct hks_blob keyAlias; + int32_t status; + + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = NUM65; // > 64 + + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + + status = hks_generate_key(&keyAlias, &keyParam); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL0_0100 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey0040, LEVEL2) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + struct hks_blob keyAlias; + int32_t status; + + keyAlias.type = 0; // != HKS_BLOB_TYPE_ALIAS + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + + status = hks_generate_key(&keyAlias, &keyParam); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL0_0100 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey0050, LEVEL2) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + struct hks_blob keyAlias; + int32_t status; + + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + keyAlias.data = NULL; // = NULL + keyAlias.size = sizeof(testFileName); + + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + + status = hks_generate_key(&keyAlias, &keyParam); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL0_0100 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey0060, LEVEL2) +{ + char testFileName[] = "keyalias1"; + struct hks_blob keyAlias; + int32_t status; + + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + + struct hks_key_param *keyParam = NULL; // = NULL + + status = hks_generate_key(&keyAlias, keyParam); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL0_0100 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey0070, LEVEL2) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + struct hks_blob keyAlias; + int32_t status; + + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = NUM1; // != HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519 + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + + status = hks_generate_key(&keyAlias, &keyParam); + TEST_ASSERT_EQUAL_INT(NUM134, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL0_0100 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey0080, LEVEL2) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + struct hks_blob keyAlias; + int32_t status; + + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = 0; // = 0 + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + + status = hks_generate_key(&keyAlias, &keyParam); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL0_0100 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey0090, LEVEL2) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + struct hks_blob keyAlias; + int32_t status; + + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = NUM65; // > 64 + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + + status = hks_generate_key(&keyAlias, &keyParam); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL0_0100 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey0100, LEVEL2) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + struct hks_blob keyAlias; + int32_t status; + + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = 0; // != HKS_BLOB_TYPE_AUTHID + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + + status = hks_generate_key(&keyAlias, &keyParam); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL0_0100 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey0110, LEVEL2) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + struct hks_blob keyAlias; + int32_t status; + + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + + struct hks_key_param keyParam; + keyParam.key_auth_id.data = NULL; // = NULL + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + + status = hks_generate_key(&keyAlias, &keyParam); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL0_0100 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1400] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey0120, LEVEL2) +{ + int status; + char testFileName[] = "keyalias1", testFileName1[] = "key_auth_id1"; + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t*)testFileName1; + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + for (int j = 0; j < NUM21; j++) { + struct hks_blob keyAlias; + HksStBlobInit1(&keyAlias, sizeof(uint8_t), sizeof(testFileName) + NUM3, HKS_BLOB_TYPE_ALIAS); + if (memcpy_s(keyAlias.data, sizeof(testFileName), testFileName, sizeof(testFileName)) != EOK) { + HksBlobDestroyT1(&keyAlias); + TEST_FAIL(); + return; + } + char tmp[3] = { 0 }; + sprintf_s(tmp, sizeof(tmp), "%d", j); + if (strcat_s((char*)keyAlias.data, strlen((char*)keyAlias.data) + strlen(tmp) + 1, tmp) != EOK) { + HksBlobDestroyT1(&keyAlias); + TEST_FAIL(); + return; + } + keyAlias.size = strlen((char*)keyAlias.data); + status = hks_generate_key(&keyAlias, &keyParam); + if (j < NUM20){ + TEST_ASSERT_EQUAL_INT(0, status); + } + else { + TEST_ASSERT_EQUAL_INT(NUM142, status); + } + HksBlobDestroyT1(&keyAlias); + } + for (int j = 0; j < NUM20; j++) { + struct hks_blob keyAlias; + HksStBlobInit1(&keyAlias, sizeof(uint8_t), sizeof(testFileName) + NUM3, HKS_BLOB_TYPE_ALIAS); + if (memcpy_s(keyAlias.data, sizeof(testFileName), testFileName, sizeof(testFileName)) != EOK) { + HksBlobDestroyT1(&keyAlias); + TEST_FAIL(); + return; + } + char tmp[3] = { 0 }; + sprintf_s(tmp, sizeof(tmp), "%d", j); + if (strcat_s((char*)keyAlias.data, strlen((char*)keyAlias.data) + strlen(tmp) + 1, tmp) != EOK) { + HksBlobDestroyT1(&keyAlias); + TEST_FAIL(); + return; + } + keyAlias.size = strlen((char*)keyAlias.data); + status = hks_delete_key(&keyAlias); + TEST_ASSERT_EQUAL_INT(0, status); + HksBlobDestroyT1(&keyAlias); + } +} + + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++generate key +// end+++++++++++++++++++++++++++++++++++++++++++++++++++++0000-0120 + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Delete key +// begin+++++++++++++++++++++++++++++++++++++++++++++++++++++0130-0190 +/* * + * @tc.number : SUB_SEC_DataPro_HuksL0_0400 + * @tc.name : Delete key + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksGenDelTestSuite, securityDataDeleteKey0130, LEVEL1) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + int32_t statusGenerate; + int32_t statusDelete; + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + struct hks_blob keyAliasGenerate; + HksStBlobInit1(&keyAliasGenerate, sizeof(uint8_t), sizeof(testFileName) + NUM3, HKS_BLOB_TYPE_ALIAS); + if (memcpy_s(keyAliasGenerate.data, sizeof(testFileName), testFileName, sizeof(testFileName)) != EOK) { + HksBlobDestroyT1(&keyAliasGenerate); + TEST_FAIL(); + return; + } + char tmpGenerate[3] = { 0 }; + if (strcat_s((char *)keyAliasGenerate.data, strlen((char *)keyAliasGenerate.data) + strlen(tmpGenerate) + 1, tmpGenerate) != EOK) { + HksBlobDestroyT1(&keyAliasGenerate); + TEST_FAIL(); + return; + } + keyAliasGenerate.size = strlen((char *)keyAliasGenerate.data); + statusGenerate = hks_generate_key(&keyAliasGenerate, &keyParam); + TEST_ASSERT_EQUAL_INT(0, statusGenerate); + HksBlobDestroyT1(&keyAliasGenerate); + struct hks_blob keyAliasDelete; + HksStBlobInit1(&keyAliasDelete, sizeof(uint8_t), sizeof(testFileName) + NUM3, HKS_BLOB_TYPE_ALIAS); + if (memcpy_s(keyAliasDelete.data, sizeof(testFileName), testFileName, sizeof(testFileName)) != EOK) { + HksBlobDestroyT1(&keyAliasDelete); + TEST_FAIL(); + return; + } + char tmpDelete[3] = { 0 }; + if (strcat_s((char *)keyAliasDelete.data, strlen((char *)keyAliasDelete.data) + strlen(tmpDelete) + 1, tmpDelete) != EOK) { + HksBlobDestroyT1(&keyAliasDelete); + TEST_FAIL(); + return; + } + keyAliasDelete.size = strlen((char *)keyAliasDelete.data); + statusDelete = hks_delete_key(&keyAliasDelete); + TEST_ASSERT_EQUAL_INT(0, statusDelete); + HksBlobDestroyT1(&keyAliasDelete); +}; + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL0_0400 + * @tc.name : Delete key + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksGenDelTestSuite, securityDataDeleteKey0140, LEVEL2) +{ + int32_t status; + struct hks_blob *keyAlias = NULL; // = NULL + + status = hks_delete_key(keyAlias); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL0_0400 + * @tc.name : Delete key + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksGenDelTestSuite, securityDataDeleteKey0150, LEVEL2) +{ + int32_t status; + char testFileName[] = "Test_file_north_interfaces"; + struct hks_blob keyAlias = { 0 }; + + keyAlias.data = NULL; // = NULL + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + status = hks_delete_key(&keyAlias); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL0_0400 + * @tc.name : Delete key + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksGenDelTestSuite, securityDataDeleteKey0160, LEVEL2) +{ + int32_t status; + char testFileName[] = "Test_file_north_interfaces"; + struct hks_blob keyAlias = { 0 }; + + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = 0; // != HKS_BLOB_TYPE_ALIAS + + status = hks_delete_key(&keyAlias); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} +/* * + * @tc.number : SUB_SEC_DataPro_HuksL0_0400 + * @tc.name : Delete key + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksGenDelTestSuite, securityDataDeleteKey0170, LEVEL2) +{ + int32_t status; + char testFileName[] = "Test_file_north_interfaces"; + struct hks_blob keyAlias = { 0 }; + + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = 0; + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + status = hks_delete_key(&keyAlias); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} +/* * + * @tc.number : SUB_SEC_DataPro_HuksL0_0400 + * @tc.name : Delete key + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksGenDelTestSuite, securityDataDeleteKey0180, LEVEL2) +{ + int32_t status; + char testFileName[] = "Test_file_north_interfaces"; + struct hks_blob keyAlias = { 0 }; + + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = NUM65; + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + status = hks_delete_key(&keyAlias); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL0_0400 + * @tc.name : Delete key + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksGenDelTestSuite, securityDataDeleteKey0190, LEVEL2) +{ + int32_t status; + char testFileName[] = "Test_file_north_interfaces"; + struct hks_blob keyAlias = { 0 }; + + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + status = hks_delete_key(&keyAlias); + TEST_ASSERT_EQUAL_INT(NUM1010, status); +} +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Delete key +// end+++++++++++++++++++++++++++++++++++++++++++++++++++++++0130-0190 + +RUN_TEST_SUITE(SecurityDataHuksGenDelTestSuite); diff --git a/security_lite/datahuks_hal/src/security_data_huks_sign_verify_test.c b/security_lite/datahuks_hal/src/security_data_huks_sign_verify_test.c new file mode 100755 index 0000000000000000000000000000000000000000..f3d3ca9aab935723793c107326f5b725b2981274 --- /dev/null +++ b/security_lite/datahuks_hal/src/security_data_huks_sign_verify_test.c @@ -0,0 +1,1333 @@ +/* Copyright (c) 2020 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 "security_data_huks.h" +#include "hctest.h" +#include "hks_client.h" +#include "hks_types.h" +#include +#include +#include +#include +#include + +/* * + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is security + * @param : module name is securityData + * @param : test suit name is SecurityDataHuksSignVerifyTestSuite + */ +LITE_TEST_SUIT(security, securityData, SecurityDataHuksSignVerifyTestSuite); + +/* * + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL SecurityDataHuksSignVerifyTestSuiteSetUp(void) +{ + int32_t status; + status = hks_init(); + if (status != 0) { + status = hks_refresh_key_info(); + } + TEST_ASSERT_EQUAL_INT(0, status); + return TRUE; +} + +/* * + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL SecurityDataHuksSignVerifyTestSuiteTearDown(void) +{ + printf("-++++++++++++++++++++++++++++++++++++++++++++-\n"); + return TRUE; +} + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Sign key +// begin+++++++++++++++++++++++++++++++++++++++++++++++++++++++0200-0340 + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0900 + * @tc.name : Asymmetric Sign + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0200, LEVEL2) +{ + int32_t statusAsymmetricSign; + int32_t statusAsymmetricVerify; + unsigned char testFileName[] = "keyalias1"; + struct hks_blob keyAlias = { 0 }; + + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32]; + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + uint32_t alg = HKS_ALG_HASH_SHA_256; + struct hks_blob src; + src.data = (uint8_t *)"123456"; + src.size = NUM6; + int32_t status = hks_hash(alg, &src, &hash); + TEST_ASSERT_EQUAL_INT(0, status); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + (void)TestSecShuksGenerateKeyNormal(); + struct hks_blob signature = { 0 }; + HksStBlobInit1(&signature, 1, NUM64, 0); + statusAsymmetricSign = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(0, statusAsymmetricSign); + + statusAsymmetricVerify = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(0, statusAsymmetricVerify); + + HksBlobDestroyT1(&signature); + (void)TestSecShuksDeleteKeyNormal(); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0900 + * @tc.name : Asymmetric Sign + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0210, LEVEL2) +{ + int32_t status; + unsigned char testFileName[] = "test_ed25519_6"; + struct hks_blob *keyAlias = NULL; // = NULL + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + + status = hks_asymmetric_sign(keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0900 + * @tc.name : Asymmetric Sign + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0220, LEVEL2) +{ + int32_t status; + unsigned char testFileName[] = "test_ed25519_6"; + struct hks_blob keyAlias; + keyAlias.data = NULL; // = NULL + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0900 + * @tc.name : Asymmetric Sign + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0230, LEVEL2) +{ + int32_t status; + unsigned char testFileName[] = "test_ed25519_6"; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = 0; // = 0 + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0900 + * @tc.name : Asymmetric Sign + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0240, LEVEL2) +{ + int32_t status; + unsigned char testFileName[] = "test_ed25519_6"; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = NUM65; // > 64 + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0900 + * @tc.name : Asymmetric Sign + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0250, LEVEL2) +{ + int32_t status; + unsigned char testFileName[] = "test_ed25519_6"; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = 0; // != HKS_BLOB_TYPE_ALIAS + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0900 + * @tc.name : Asymmetric Sign + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0260, LEVEL2) +{ + int32_t status; + unsigned char testFileName[] = "test_ed25519_6"; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param *keyParam = NULL; // = NULL + + status = hks_asymmetric_sign(&keyAlias, keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0900 + * @tc.name : Asymmetric Sign + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0270, LEVEL2) +{ + int32_t status; + unsigned char testFileName[] = "test_ed25519_6"; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = 0; // = 0 + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + + status = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0900 + * @tc.name : Asymmetric Sign + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0280, LEVEL2) +{ + int32_t status; + unsigned char testFileName[] = "test_ed25519_6"; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = 0; // != HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519 + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0900 + * @tc.name : Asymmetric Sign + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0290, LEVEL2) +{ + int32_t status; + unsigned char testFileName[] = "test_ed25519_6"; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t sig[NUM64]; + + struct hks_blob *hash = NULL; // = NULL + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_sign(&keyAlias, &keyParam, hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0900 + * @tc.name : Asymmetric Sign + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0300, LEVEL2) +{ + int32_t status; + unsigned char testFileName[] = "test_ed25519_6"; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = NULL; // = NULL + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0900 + * @tc.name : Asymmetric Sign + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0310, LEVEL2) +{ + int32_t status; + unsigned char testFileName[] = "test_ed25519_6"; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = 0; // = 0 + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0900 + * @tc.name : Asymmetric Sign + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0320, LEVEL2) +{ + int32_t status; + unsigned char testFileName[] = "test_ed25519_6"; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob *signature = NULL; // = NULL + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + + status = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, signature); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0900 + * @tc.name : Asymmetric Sign + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0330, LEVEL2) +{ + int32_t status; + unsigned char testFileName[] = "test_ed25519_6"; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = NULL; // = NULL + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM138, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_0900 + * @tc.name : Asymmetric Sign + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricSign0340, LEVEL2) +{ + int32_t status; + unsigned char testFileName[] = "test_ed25519_6"; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = sig; + signature.size = NUM63; // < 64 + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM138, status); +} + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Sign key +// end+++++++++++++++++++++++++++++++++++++++++++++++++++++++++0200-0340 + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Verify key +// begin+++++++++++++++++++++++++++++++++++++++++++++++++++++0350-0510 + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1000 + * @tc.name : Asymmetric Verify + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0350, LEVEL2) +{ + int32_t statusAsymmetricSign; + int32_t statusAsymmetricVerify; + + unsigned char testFileName[] = "keyalias1"; + struct hks_blob keyAlias = { 0 }; + + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32]; + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + uint32_t alg = HKS_ALG_HASH_SHA_256; + struct hks_blob src; + src.data = (uint8_t *)"123456"; + src.size = NUM6; + int32_t status = hks_hash(alg, &src, &hash); + TEST_ASSERT_EQUAL_INT(0, status); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + struct hks_key_param keyParam2 = { 0 }; + keyParam2.key_type = HKS_KEY_TYPE_EDDSA_PUBLIC_KEY_ED25519; + keyParam2.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam2.key_mode = HKS_ALG_GCM; + keyParam2.key_len = NUM32; + keyParam2.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam2.key_auth_id.data = (uint8_t *)testFileName; + keyParam2.key_auth_id.size = sizeof(testFileName); + + (void)TestSecShuksGenerateKeyNormal(); + struct hks_blob pubKey = { 0 }; + HksStBlobInit1(&pubKey, 1, NUM32, HKS_BLOB_TYPE_KEY); + + (void)TestSecShuksExportPublicNormal(&keyAlias, &pubKey); + struct hks_blob signature = { 0 }; + HksStBlobInit1(&signature, 1, NUM64, 0); + statusAsymmetricSign = hks_asymmetric_sign(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(0, statusAsymmetricSign); + + statusAsymmetricVerify = hks_asymmetric_verify(&pubKey, &keyParam2, &hash, &signature); + TEST_ASSERT_EQUAL_INT(0, statusAsymmetricVerify); + + HksBlobDestroyT1(&signature); + (void)TestSecShuksDeleteKeyNormal(); + HksBlobDestroyT1(&pubKey); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1000 + * @tc.name : Asymmetric Verify + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0360, LEVEL2) +{ + int32_t status; + unsigned char testFileName[NUM32]; + struct hks_blob *keyAlias = NULL; // = NULL + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_verify(keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1000 + * @tc.name : Asymmetric Verify + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0370, LEVEL2) +{ + int32_t status; + unsigned char testFileName[NUM32]; + struct hks_blob keyAlias; + keyAlias.data = NULL; // = NULL + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1000 + * @tc.name : Asymmetric Verify + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0380, LEVEL2) +{ + int32_t status; + unsigned char testFileName[NUM32]; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = 0; // = 0 + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1000 + * @tc.name : Asymmetric Verify + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0390, LEVEL2) +{ + int32_t status; + unsigned char testFileName[NUM32]; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = NUM65; // > 64 + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1000 + * @tc.name : Asymmetric Verify + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0400, LEVEL2) +{ + int32_t status; + unsigned char testFileName[NUM32]; + struct hks_blob keyAlias; + keyAlias.data = NULL; // = NULL + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_KEY; + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_PUBLIC_KEY_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM1006, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1000 + * @tc.name : Asymmetric Verify + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0410, LEVEL2) +{ + int32_t status; + unsigned char testFileName[NUM32]; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = NUM25; // != 32 + keyAlias.type = HKS_BLOB_TYPE_KEY; + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_PUBLIC_KEY_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM1006, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1000 + * @tc.name : Asymmetric Verify + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0420, LEVEL2) +{ + int32_t status; + unsigned char testFileName[NUM32]; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = 0; // = else + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM1006, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1000 + * @tc.name : Asymmetric Verify + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0430, LEVEL2) +{ + int32_t status; + unsigned char testFileName[NUM32]; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param *keyParam = NULL; // = NULL + + status = hks_asymmetric_verify(&keyAlias, keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1000 + * @tc.name : Asymmetric Verify + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0440, LEVEL2) +{ + int32_t status; + unsigned char testFileName[NUM32]; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = 0; // = 0 + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1000 + * @tc.name : Asymmetric Verify + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0450, LEVEL2) +{ + int32_t status; + unsigned char testFileName[NUM32]; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_KEY; + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = 0; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1000 + * @tc.name : Asymmetric Verify + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0460, LEVEL2) +{ + int32_t status; + unsigned char testFileName[NUM32]; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t sig[NUM64]; + + struct hks_blob *hash = NULL; // = NULL + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_verify(&keyAlias, &keyParam, hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1000 + * @tc.name : Asymmetric Verify + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0470, LEVEL2) +{ + int32_t status; + unsigned char testFileName[NUM32]; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = NULL; // = NULL + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1000 + * @tc.name : Asymmetric Verify + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0480, LEVEL2) +{ + int32_t status; + unsigned char testFileName[NUM32]; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = 0; // = 0 + + struct hks_blob signature; + signature.data = sig; + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1000 + * @tc.name : Asymmetric Verify + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0490, LEVEL2) +{ + int32_t status; + unsigned char testFileName[NUM32]; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob *signature = NULL; // = NULL + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, signature); + TEST_ASSERT_EQUAL_INT(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1000 + * @tc.name : Asymmetric Verify + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0500, LEVEL2) +{ + int32_t status; + unsigned char testFileName[NUM32]; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = NULL; // = NULL + signature.size = sizeof(sig); + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL0_1000 + * @tc.name : Asymmetric Verify + * @tc.desc : [C- SECURITY -1900] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +LITE_TEST_CASE(SecurityDataHuksSignVerifyTestSuite, securityDataAsymmetricVerify0510, LEVEL2) +{ + int32_t status; + unsigned char testFileName[NUM32]; + struct hks_blob keyAlias; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + uint8_t hash1[NUM32], sig[NUM64]; + + struct hks_blob hash; + hash.data = (uint8_t *)hash1; + hash.size = sizeof(hash1); + + struct hks_blob signature; + signature.data = sig; + signature.size = NUM63; // < 64 + + struct hks_key_param keyParam = { 0 }; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_usage = HKS_KEY_USAGE_SIGN | HKS_KEY_USAGE_VERIFY; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_len = NUM32; + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_auth_id.data = (uint8_t *)testFileName; + keyParam.key_auth_id.size = sizeof(testFileName); + + status = hks_asymmetric_verify(&keyAlias, &keyParam, &hash, &signature); + TEST_ASSERT_EQUAL_INT(NUM135, status); +} + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Verify key +// end+++++++++++++++++++++++++++++++++++++++++++++++++++++++0350-0510 + +RUN_TEST_SUITE(SecurityDataHuksSignVerifyTestSuite); diff --git a/security_lite/datahuks_posix/BUILD.gn b/security_lite/datahuks_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..3c00479211b087e3abfac3683a775b4ce02de1a1 --- /dev/null +++ b/security_lite/datahuks_posix/BUILD.gn @@ -0,0 +1,39 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsSecurityDataTest") { + suite_name = "acts" + sources = [ + "src/SecurityDataHuksGenDelTest.cpp", + "src/SecurityDataHuksEncTest.cpp", + "src/SecurityDataHuksDecTest.cpp", + "src/SecurityDataHuksHashRandomHmacTest.cpp", + ] + + include_dirs = [ + "src", + "//base/security/interfaces/innerkits/huks_lite/", + ] + deps = [ + "//base/security/frameworks/huks_lite/source:huks", + ] + cflags = [ "-Wno-error" ] + + ldflags = [ + "-lstdc++", + "-lm", + "-lpthread", + ] +} diff --git a/security_lite/datahuks_posix/Test.json b/security_lite/datahuks_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..d57a10afca56a7793d759c0cd3736ad4a19a14eb --- /dev/null +++ b/security_lite/datahuks_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for hcpptest demo test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/security", + "target": "/test_root/security" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/security/ActsSecurityDataTest.bin" + } +} \ No newline at end of file diff --git a/security_lite/datahuks_posix/src/SecurityDataHuks.h b/security_lite/datahuks_posix/src/SecurityDataHuks.h new file mode 100755 index 0000000000000000000000000000000000000000..699da550c99ba9178aab3625d7e2f1b9e54a6ce5 --- /dev/null +++ b/security_lite/datahuks_posix/src/SecurityDataHuks.h @@ -0,0 +1,372 @@ +/* + * Copyright (c) 2020 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 TEST_XTS_ACTS_SECURITY_LITE_DATAHUKS_POSIX_SRC_SECURITYDATAHUKS_H +#define TEST_XTS_ACTS_SECURITY_LITE_DATAHUKS_POSIX_SRC_SECURITYDATAHUKS_H +#include "hks_client.h" +#include "hks_types.h" +#include +#include +#include +#include +#include +#include +#include "gtest/gtest.h" +#include +#include +#include +#include "hks_errno.h" +#include +#include + +#define DOUBLE_INT(x) ((x) * 2) +#define DOUBLE_STR_LEN(x) ((x) * 2 + 1) +#define FILE_ERROR -1 +#define FILE_PATH_LENGTH 256 +#define HICHAIN_FILEPATH "/storage/" +#define HKS_FREE_PTR1(p) { if ((p) != NULL) { free(p); (p) = NULL; }} + +constexpr int NUM1 = 1; +constexpr int NUM2 = 2; +constexpr int NUM3 = 3; +constexpr int NUM4 = 4; +constexpr int NUM5 = 5; +constexpr int NUM6 = 6; +constexpr int NUM8 = 8; +constexpr int NUM9 = 9; +constexpr int NUM10 = 10; +constexpr int NUM11 = 11; +constexpr int NUM15 = 15; +constexpr int NUM16 = 16; +constexpr int NUM20 = 20; +constexpr int NUM30 = 30; +constexpr int NUM21 = 21; +constexpr int NUM24 = 24; +constexpr int NUM32 = 32; +constexpr int NUM60 = 60; +constexpr int NUM62 = 62; +constexpr int NUM64 = 64; +constexpr int NUM65 = 65; +constexpr int NUM88 = 88; +constexpr int NUM100 = 100; +constexpr int NUM128 = 128; +constexpr int NUM192 = 192; +constexpr int NUM256 = 256; +constexpr int NUM1025 = 1025; +constexpr int NUM2048 = 2048; +constexpr int NUM1234567 = 1234567; +constexpr int NUM1000000 = 1000000; +constexpr int NUM134 = -134; +constexpr int NUM135 = -135; +constexpr int NUM142 = -142; +constexpr int NUM1000 = -1000; +constexpr int NUM1006 = -1006; +constexpr int NUM1007 = -1007; +constexpr int NUM1010 = -1010; +constexpr int G_COUNT_MEM = 10000; +constexpr int MAX_INT = 2147483647; + +using namespace std; +using namespace testing::ext; +using errno_t = int32_t; + +static errno_t FopenS(FILE **fp, const char *filename, const char *modes) +{ + *fp = fopen(filename, modes); + return 0; +} + +static int32_t FileSize(const char *filename) +{ + FILE *fp = nullptr; + errno_t err; + int32_t size; + + if (filename == nullptr) { + return -1; + } + + err = FopenS(&fp, filename, "rb"); + if (err != 0 || fp == nullptr) { + return -1; + } + + if (fseek(fp, 0L, SEEK_END) != 0) { + fclose(fp); + return -1; + } + + size = ftell(fp); + fclose(fp); + + return size; +} +static int32_t FileWrite(const char *filename, uint32_t offset, const uint8_t *buf, uint32_t len) +{ + FILE *fp = nullptr; + errno_t err; + size_t size; + char path[256] = {0}; + + if (filename == NULL || buf == NULL) { + return -1; + } + + err = FopenS(&fp, filename, "wb+"); + if (err != 0 || fp == nullptr) { + return -1; + } + + size = fwrite(buf, 1, len, fp); + fclose(fp); + + if (size != len) { + return -1; + } + + return 0; +} + +static int32_t FileRead(const char *filename, uint32_t offset, uint8_t *buf, uint32_t len) +{ + FILE* fp = nullptr; + errno_t err; + size_t size; + + if (filename == NULL || buf == NULL) { + return -1; + } + + if (access(filename, 0) == -1) { + return 0; + } + + err = FopenS(&fp, filename, "rb"); + if (err == NUM2) { + return 0; + } + if (err != 0 || fp == nullptr) { + return -1; + } + + size = fread(buf, 1, len, fp); + fclose(fp); + + if (size == 0) { + return -1; + } + + return size; +} + +static uint64_t GetTimeMs() +{ + struct timeval timeVal; + gettimeofday(&timeVal, nullptr); + + return (uint64_t)NUM1000000 * timeVal.tv_sec + timeVal.tv_usec; +} + +static void AddLog(const char* logType, const char *tag, const char *func, const char *format, const va_list* ap) +{ + char* buf = (char*)malloc(NUM2048); + if (buf == nullptr) { + return; + } + int offset = sprintf_s(buf, (NUM2048), "[%s][%llu]%s %s: ", logType, (unsigned long long)GetTimeMs(), tag, func); + + offset += vsprintf_s(buf + offset, (NUM2048) - offset, format, *ap); + + free(buf); + buf = nullptr; +} + +static void Logi(const char *tag, const char *func, const char *format, ...) +{ + va_list args; + va_start(args, format); + AddLog("Info", tag, func, format, &args); + va_end(args); +} + +static void Logw(const char *tag, const char *func, const char *format, ...) +{ + va_list args; + va_start(args, format); + AddLog("Warn", tag, func, format, &args); + va_end(args); +} + +static void Loge(const char *tag, const char *func, const char *format, ...) +{ + va_list args; + va_start(args, format); + AddLog("Error", tag, func, format, &args); + va_end(args); +} + +static void Logd(const char *tag, const char *func, const char *format, ...) +{ + va_list args; + va_start(args, format); + AddLog("Debug", tag, func, format, &args); + va_end(args); +} + + +static uint8_t g_hksHardwareUdidId[32] = { + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0A, 0x0C, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1A, 0x1C, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, +}; + +static int32_t HksTestGetHardwareUdid(uint8_t* udid, uint32_t udidLen) +{ + int err; + if ((udid == NULL) || (udidLen != NUM32)) { + return -1; + } + + int32_t rc = 1234567; + if (rc <= 0) { + err = memcpy_s(udid, NUM32, g_hksHardwareUdidId, NUM32); + if (err != EOK) { + return -1; + } + } + + char buf[128] = {0}; + uint32_t offset = 0; + for (uint32_t i = 0; i < udidLen; ++i) { + offset += sprintf_s(buf + offset, NUM128 - offset, "%02x ", udid[i]); + } + + Logd("[hks_tester]", __func__, buf); + return 0; +} + +static void HksStBlobInit1(struct hks_blob *blob, size_t nmemb, size_t size, uint8_t type) +{ + if (blob == nullptr || nmemb == 0 || size == 0) { + EXPECT_EQ(0, 1); + return; + } + blob->data = (uint8_t *)calloc(nmemb, size); + if (blob->data == NULL) { + EXPECT_EQ(0, 1); + return; + } + if (memset_s(blob->data, size, 0, size) != EOK) { + EXPECT_EQ(0, 1); + return; + } + blob->size = size; + blob->type = type; +} + +static void HksBlobDestroyT1(struct hks_blob *blob) +{ + if (blob == nullptr) { + EXPECT_EQ(0, 1); + return; + } + if (blob && blob->data) { + if (memset_s(blob->data, blob->size, 0, blob->size) != EOK) { + EXPECT_EQ(0, 1); + return; + } + HKS_FREE_PTR1(blob->data); + } + blob->data = NULL; + blob->size = 0; + blob->type = HKS_BLOB_TYPE_RAW; +} + +static void HexStringToByte(const char *str, int nLen, unsigned char *pHex) +{ + unsigned int number = 4; + if (nLen % NUM2) { + EXPECT_EQ(0, 1); + return; + } + int nHexLen = nLen / NUM2; + unsigned char nibble[2]; + if (nHexLen < MAX_INT) { + for (int i = 0; i < nHexLen; i++) { + nibble[0] = str[i * NUM2]; + nibble[1] = str[i * NUM2 + NUM1]; + for (int j = 0; j < NUM2; j++) { + if (nibble[j] <= 'F' && nibble[j] >= 'A') { + nibble[j] = nibble[j] - 'A' + NUM10; + } else if (nibble[j] <= 'f' && nibble[j] >= 'a') { + nibble[j] = nibble[j] - 'a' + NUM10; + } else if (nibble[j] >= '0' && nibble[j] <= '9') { + nibble[j] = nibble[j] - '0'; + } else { + EXPECT_EQ(0, 1); + return; + } + } + pHex[i] = nibble[0] << number; + pHex[i] |= nibble[1]; + } + } +} + +static void BuildBlobData(struct hks_blob *param, const char *str, uint8_t type, uint32_t size, uint8_t isDataNull) +{ + if (param == nullptr) { + EXPECT_EQ(0, 1); + return; + } + param->type = type; + param->size = size; + if (isDataNull == 1) + param->data = NULL; + else { + if (size + NUM2 == 0) { + EXPECT_EQ(0, 1); + return; + } + unsigned char *buff = (unsigned char *)malloc(size + NUM2); + if (buff == nullptr) { + EXPECT_EQ(0, 1); + return; + } + if (memset_s(buff, size + NUM2, 0, size + NUM2) != EOK) { + EXPECT_EQ(0, 1); + return; + } + HexStringToByte(str, size * NUM2, buff); + param->data = (uint8_t *)buff; + } +} + +static void TestInitKeyParam1(struct hks_key_param *keyParam, uint32_t keyType, uint32_t keyLen, uint32_t keyMode, + uint32_t keyUsage) +{ + keyParam->key_type = keyType; + keyParam->key_len = keyLen; + keyParam->key_pad = HKS_PADDING_NONE; + keyParam->key_mode = keyMode; + keyParam->key_domain = HKS_ECC_CURVE_ED25519; + keyParam->key_usage = keyUsage; + + const char tmpData1[] = "111111"; + BuildBlobData(&keyParam->key_auth_id, tmpData1, HKS_BLOB_TYPE_AUTH_ID, NUM3, 0); +} + +#endif diff --git a/security_lite/datahuks_posix/src/SecurityDataHuksDecTest.cpp b/security_lite/datahuks_posix/src/SecurityDataHuksDecTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..1de9a325ff2e79f6c6102fbc26b1408de4888a4a --- /dev/null +++ b/security_lite/datahuks_posix/src/SecurityDataHuksDecTest.cpp @@ -0,0 +1,1376 @@ +/* Copyright (c) 2020 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 "SecurityDataHuks.h" +#include "hks_client.h" +#include "hks_types.h" +#include +#include +#include +#include +#include +#include "gtest/gtest.h" +using namespace std; +using namespace testing::ext; + +class SecurityDataHuksDecTestSuite : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() + { + int32_t status; + struct hks_file_callbacks fileCallbacks; + + fileCallbacks.read = FileRead; + fileCallbacks.write = FileWrite; + fileCallbacks.file_size = FileSize; + + status = hks_register_file_callbacks(&fileCallbacks); + EXPECT_EQ(0, status); + + struct hks_log_f_group logFunc; + logFunc.log_info = Logi; + logFunc.log_warn = Logw; + logFunc.log_error = Loge; + logFunc.log_debug = Logd; + + status = hks_register_log_interface(&logFunc); + EXPECT_EQ(0, status); + + status = hks_register_get_hardware_udid_callback(HksTestGetHardwareUdid); + + EXPECT_EQ(0, status); + + status = hks_init(); + if (status != 0) { + status = hks_refresh_key_info(); + } + EXPECT_EQ(0, status); +} + // Testcase teardown + virtual void TearDown() {} +}; + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Decrypt key +// begin++++++++++++++++++++++++++++++++++++++++++++++++++++4500-6800 + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt4500, TestSize.Level1) +{ + char alias[] = "test_hks_aead_encrypt"; + int32_t s; + int32_t statusEncrypt; + int32_t statusDecrypt; + + struct hks_blob key; + HksStBlobInit1(&key, 1, NUM16, HKS_BLOB_TYPE_KEY); + s = hks_generate_random(&key); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + struct hks_blob nonce; + HksStBlobInit1(&nonce, 1, NUM16, HKS_BLOB_TYPE_IV); + s = hks_generate_random(&nonce); + + struct hks_blob aad; + HksStBlobInit1(&aad, 1, NUM16, HKS_BLOB_TYPE_AAD); + s = hks_generate_random(&aad); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + HksStBlobInit1(&plaintext, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + s = hks_generate_random(&plaintext); + + struct hks_blob ciphertext; + HksStBlobInit1(&ciphertext, 1, NUM64 + HKS_SALT_MAX_SIZE, HKS_BLOB_TYPE_CIPHER_TEXT); + statusEncrypt = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(0, statusEncrypt); + + struct hks_blob decrypted; + HksStBlobInit1(&decrypted, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + statusDecrypt = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(0, statusDecrypt); + + size_t k; + for (k = 0; k < decrypted.size; k++) { + EXPECT_EQ(plaintext.data[k], decrypted.data[k]); + } + HksBlobDestroyT1(&key); + HksBlobDestroyT1(&nonce); + HksBlobDestroyT1(&aad); + HksBlobDestroyT1(&plaintext); + HksBlobDestroyT1(&ciphertext); + HksBlobDestroyT1(&decrypted); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt4600, TestSize.Level1) +{ + char alias[] = "test_hks_aead_encrypt"; + int32_t s; + int32_t statusEncrypt; + int32_t statusDecrypt; + + struct hks_blob key; + HksStBlobInit1(&key, 1, NUM24, HKS_BLOB_TYPE_KEY); + s = hks_generate_random(&key); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM192; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + struct hks_blob nonce; + HksStBlobInit1(&nonce, 1, NUM16, HKS_BLOB_TYPE_IV); + s = hks_generate_random(&nonce); + + struct hks_blob aad; + HksStBlobInit1(&aad, 1, NUM16, HKS_BLOB_TYPE_AAD); + s = hks_generate_random(&aad); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + HksStBlobInit1(&plaintext, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + s = hks_generate_random(&plaintext); + + struct hks_blob ciphertext; + HksStBlobInit1(&ciphertext, 1, NUM64 + HKS_SALT_MAX_SIZE, HKS_BLOB_TYPE_CIPHER_TEXT); + statusEncrypt = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(0, statusEncrypt); + + struct hks_blob decrypted; + HksStBlobInit1(&decrypted, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + statusDecrypt = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(0, statusDecrypt); + + size_t k; + for (k = 0; k < decrypted.size; k++) { + EXPECT_EQ(plaintext.data[k], decrypted.data[k]); + } + HksBlobDestroyT1(&key); + HksBlobDestroyT1(&nonce); + HksBlobDestroyT1(&aad); + HksBlobDestroyT1(&plaintext); + HksBlobDestroyT1(&ciphertext); + HksBlobDestroyT1(&decrypted); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt4700, TestSize.Level1) +{ + char alias[] = "test_hks_aead_encrypt"; + int32_t s; + int32_t statusEncrypt; + int32_t statusDecrypt; + + struct hks_blob key; + HksStBlobInit1(&key, 1, NUM32, HKS_BLOB_TYPE_KEY); + s = hks_generate_random(&key); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM256; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + struct hks_blob nonce; + HksStBlobInit1(&nonce, 1, NUM16, HKS_BLOB_TYPE_IV); + s = hks_generate_random(&nonce); + + struct hks_blob aad; + HksStBlobInit1(&aad, 1, NUM16, HKS_BLOB_TYPE_AAD); + s = hks_generate_random(&aad); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + HksStBlobInit1(&plaintext, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + s = hks_generate_random(&plaintext); + + struct hks_blob ciphertext; + HksStBlobInit1(&ciphertext, 1, NUM64 + HKS_SALT_MAX_SIZE, HKS_BLOB_TYPE_CIPHER_TEXT); + statusEncrypt = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(0, statusEncrypt); + + struct hks_blob decrypted; + HksStBlobInit1(&decrypted, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + statusDecrypt = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(0, statusDecrypt); + + size_t k; + for (k = 0; k < decrypted.size; k++) { + EXPECT_EQ(plaintext.data[k], decrypted.data[k]); + } + HksBlobDestroyT1(&key); + HksBlobDestroyT1(&nonce); + HksBlobDestroyT1(&aad); + HksBlobDestroyT1(&plaintext); + HksBlobDestroyT1(&ciphertext); + HksBlobDestroyT1(&decrypted); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt4800, TestSize.Level2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob *key = nullptr; // = NULL + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt4900, TestSize.Level2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = NUM32; // != key_param.key_len / 8 + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(NUM1006, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt5000, TestSize.Level2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = NULL; // = NULL + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(NUM1006, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt5100, TestSize.Level2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = 0; // != HKS_KEY_TYPE_AES + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(NUM1006, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt5200, TestSize.Level2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param *keyParam = nullptr; // = NULL + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt5300, TestSize.Level2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = 0; // != HKS_ALG_GCM + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt5400, TestSize.Level2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = 12; // != 128 192 256 + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt5500, TestSize.Level2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = 0; // != HKS_KEY_TYPE_AES + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt5600, TestSize.Level2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = NUM88; // != HKS_PADDING_NONE + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt5700, TestSize.Level2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = 0; // = 0 + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt5800, TestSize.Level2) +{ + char alias[] = "test_hks_aead_decrypt"; + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param *cryptParam = nullptr; // = NULL + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt5900, TestSize.Level2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = 0; // = 0 + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt6000, TestSize.Level2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = NULL; // = NULL + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt6100, TestSize.Level2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = 0; // = 0 + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt6200, TestSize.Level2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = NULL; // = NULL + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt6300, TestSize.Level2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob *decrypted = nullptr; // = NULL + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, decrypted, &ciphertext); + EXPECT_EQ(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt6400, TestSize.Level2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = NULL; // = NULL + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt6500, TestSize.Level2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = NUM15; // < -16 + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt6600, TestSize.Level2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob *ciphertext = nullptr; // = NULL + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, ciphertext); + EXPECT_EQ(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt6700, TestSize.Level2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = NULL; // = NULL + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1100 + * @tc.name : Aead Decrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksDecTestSuite, securityDataAeadDecrypt6800, TestSize.Level2) +{ + char alias[] = "test_hks_aead_decrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], decrypted1[NUM100], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob decrypted; + decrypted.data = (uint8_t *)decrypted1; + decrypted.size = sizeof(decrypted1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = NUM10; // < -16 + + status = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(NUM135, status); +} + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Decrypt key +// begin++++++++++++++++++++++++++++++++++++++++++++++++++++4500-6800 diff --git a/security_lite/datahuks_posix/src/SecurityDataHuksEncTest.cpp b/security_lite/datahuks_posix/src/SecurityDataHuksEncTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..e4e5ae7cd0e62f7a3b19e126d6a23e11f806fb71 --- /dev/null +++ b/security_lite/datahuks_posix/src/SecurityDataHuksEncTest.cpp @@ -0,0 +1,1398 @@ +/* Copyright (c) 2020 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 "SecurityDataHuks.h" +#include "hks_client.h" +#include "hks_types.h" +#include +#include +#include +#include +#include +#include "gtest/gtest.h" +using namespace std; +using namespace testing::ext; + +class SecurityDataHuksEncTestSuite : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() + { + int32_t status; + struct hks_file_callbacks fileCallbacks; + + fileCallbacks.read = FileRead; + fileCallbacks.write = FileWrite; + fileCallbacks.file_size = FileSize; + + status = hks_register_file_callbacks(&fileCallbacks); + EXPECT_EQ(0, status); + + struct hks_log_f_group logFunc; + logFunc.log_info = Logi; + logFunc.log_warn = Logw; + logFunc.log_error = Loge; + logFunc.log_debug = Logd; + + status = hks_register_log_interface(&logFunc); + EXPECT_EQ(0, status); + + status = hks_register_get_hardware_udid_callback(HksTestGetHardwareUdid); + + EXPECT_EQ(0, status); + + status = hks_init(); + if (status != 0) { + status = hks_refresh_key_info(); + } + EXPECT_EQ(0, status); + } + // Testcase teardown + virtual void TearDown() {} +}; + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Encrypt key +// begin++++++++++++++++++++++++++++++++++++++++++++++++++++2100-4400 + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt2100, TestSize.Level1) +{ + char alias[] = "test_hks_aead_encrypt"; + int32_t s; + int32_t statusEncrypt; + int32_t statusDecrypt; + + struct hks_blob key; + HksStBlobInit1(&key, 1, NUM16, HKS_BLOB_TYPE_KEY); + s = hks_generate_random(&key); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + struct hks_blob nonce; + HksStBlobInit1(&nonce, 1, NUM16, HKS_BLOB_TYPE_IV); + s = hks_generate_random(&nonce); + + struct hks_blob aad; + HksStBlobInit1(&aad, 1, NUM16, HKS_BLOB_TYPE_AAD); + s = hks_generate_random(&aad); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + HksStBlobInit1(&plaintext, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + s = hks_generate_random(&plaintext); + + struct hks_blob ciphertext; + HksStBlobInit1(&ciphertext, 1, NUM64 + HKS_SALT_MAX_SIZE, HKS_BLOB_TYPE_CIPHER_TEXT); + statusEncrypt = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(0, statusEncrypt); + + struct hks_blob decrypted; + HksStBlobInit1(&decrypted, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + statusDecrypt = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(0, statusDecrypt); + + size_t k; + for (k = 0; k < decrypted.size; k++) { + EXPECT_EQ(plaintext.data[k], decrypted.data[k]); + } + HksBlobDestroyT1(&key); + HksBlobDestroyT1(&nonce); + HksBlobDestroyT1(&aad); + HksBlobDestroyT1(&plaintext); + HksBlobDestroyT1(&ciphertext); + HksBlobDestroyT1(&decrypted); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt2200, TestSize.Level1) +{ + char alias[] = "test_hks_aead_encrypt"; + int32_t s; + int32_t statusEncrypt; + int32_t statusDecrypt; + + struct hks_blob key; + HksStBlobInit1(&key, 1, NUM24, HKS_BLOB_TYPE_KEY); + s = hks_generate_random(&key); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM192; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + struct hks_blob nonce; + HksStBlobInit1(&nonce, 1, NUM16, HKS_BLOB_TYPE_IV); + s = hks_generate_random(&nonce); + + struct hks_blob aad; + HksStBlobInit1(&aad, 1, NUM16, HKS_BLOB_TYPE_AAD); + s = hks_generate_random(&aad); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + HksStBlobInit1(&plaintext, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + s = hks_generate_random(&plaintext); + + struct hks_blob ciphertext; + HksStBlobInit1(&ciphertext, 1, NUM64 + HKS_SALT_MAX_SIZE, HKS_BLOB_TYPE_CIPHER_TEXT); + statusEncrypt = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(0, statusEncrypt); + + struct hks_blob decrypted; + HksStBlobInit1(&decrypted, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + statusDecrypt = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(0, statusDecrypt); + + size_t k; + for (k = 0; k < decrypted.size; k++) { + EXPECT_EQ(plaintext.data[k], decrypted.data[k]); + } + HksBlobDestroyT1(&key); + HksBlobDestroyT1(&nonce); + HksBlobDestroyT1(&aad); + HksBlobDestroyT1(&plaintext); + HksBlobDestroyT1(&ciphertext); + HksBlobDestroyT1(&decrypted); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt2300, TestSize.Level1) +{ + char alias[] = "test_hks_aead_encrypt"; + int32_t s; + int32_t statusEncrypt; + int32_t statusDecrypt; + + struct hks_blob key; + HksStBlobInit1(&key, 1, NUM32, HKS_BLOB_TYPE_KEY); + s = hks_generate_random(&key); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM256; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + struct hks_blob nonce; + HksStBlobInit1(&nonce, 1, NUM16, HKS_BLOB_TYPE_IV); + s = hks_generate_random(&nonce); + + struct hks_blob aad; + HksStBlobInit1(&aad, 1, NUM16, HKS_BLOB_TYPE_AAD); + s = hks_generate_random(&aad); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + HksStBlobInit1(&plaintext, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + s = hks_generate_random(&plaintext); + + struct hks_blob ciphertext; + HksStBlobInit1(&ciphertext, 1, NUM64 + HKS_SALT_MAX_SIZE, HKS_BLOB_TYPE_CIPHER_TEXT); + statusEncrypt = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(0, statusEncrypt); + + struct hks_blob decrypted; + HksStBlobInit1(&decrypted, 1, NUM64, HKS_BLOB_TYPE_PLAIN_TEXT); + statusDecrypt = hks_aead_decrypt(&key, &keyParam, &cryptParam, &decrypted, &ciphertext); + EXPECT_EQ(0, statusDecrypt); + + size_t k; + for (k = 0; k < decrypted.size; k++) { + EXPECT_EQ(plaintext.data[k], decrypted.data[k]); + } + HksBlobDestroyT1(&key); + HksBlobDestroyT1(&nonce); + HksBlobDestroyT1(&aad); + HksBlobDestroyT1(&plaintext); + HksBlobDestroyT1(&ciphertext); + HksBlobDestroyT1(&decrypted); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt2400, TestSize.Level2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob *key = nullptr; // = NULL + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt2500, TestSize.Level2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = NUM32; // != key_param.key_len / 8 + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(NUM1006, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt2600, TestSize.Level2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = NULL; // = NULL + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(NUM1006, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt2700, TestSize.Level2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = 0; // != HKS_BLOB_TYPE_KEY + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(NUM1006, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt2800, TestSize.Level2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param *keyParam = nullptr; // = NULL + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt2900, TestSize.Level2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = 0; // != HKS_ALG_GCM + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt3000, TestSize.Level2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM11; // != 128 192 256 + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt3100, TestSize.Level2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = 0; // != HKS_KEY_TYPE_AES + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt3200, TestSize.Level2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = NUM88; // != HKS_PADDING_NONE + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt3300, TestSize.Level2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = 0; // = 0 + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(NUM134, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt3400, TestSize.Level2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param *cryptParam = nullptr; // = NULL + + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt3500, TestSize.Level2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = NUM10; // < 12 + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt3600, TestSize.Level2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = NULL; // = NULL + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt3700, TestSize.Level2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = 0; // = 0 + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt3800, TestSize.Level2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = NULL; // = NULL + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt3900, TestSize.Level2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob *plaintext = nullptr; // = NULL + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, plaintext, &ciphertext); + EXPECT_EQ(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt4000, TestSize.Level2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = NULL; // = NULL + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt4100, TestSize.Level2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = 0; // = 0 + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt4200, TestSize.Level2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob *ciphertext = nullptr; // = NULL + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, ciphertext); + EXPECT_EQ(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt4300, TestSize.Level2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = NULL; // = NULL + ciphertext.size = sizeof(ciphertext1); + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1000 + * @tc.name : Aead Encrypt + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksEncTestSuite, securityDataAeadEncrypt4400, TestSize.Level2) +{ + char alias[] = "test_hks_aead_encrypt"; + + uint8_t key1[NUM16], nonce1[NUM16], aad1[NUM16], plaintext1[NUM64], ciphertext1[NUM100]; + + int32_t status; + struct hks_blob key; + key.type = HKS_BLOB_TYPE_KEY; + key.data = (uint8_t *)key1; + key.size = sizeof(key1); + + struct hks_key_param keyParam; + keyParam.key_type = HKS_KEY_TYPE_AES; + keyParam.key_len = NUM128; + keyParam.key_usage = HKS_KEY_USAGE_ENCRYPT | HKS_KEY_USAGE_DECRYPT; + keyParam.key_mode = HKS_ALG_GCM; + keyParam.key_pad = HKS_PADDING_NONE; + keyParam.key_auth_id.data = (uint8_t *)alias; + keyParam.key_auth_id.size = sizeof(alias); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + + struct hks_crypt_param cryptParam; + + struct hks_blob nonce; + nonce.data = (uint8_t *)nonce1; + nonce.size = sizeof(nonce1); + + struct hks_blob aad; + aad.data = (uint8_t *)aad1; + aad.size = sizeof(aad1); + + cryptParam.nonce = nonce; + cryptParam.aad = aad; + + struct hks_blob plaintext; + plaintext.data = (uint8_t *)plaintext1; + plaintext.size = sizeof(plaintext1); + + struct hks_blob ciphertext; + ciphertext.data = (uint8_t *)ciphertext1; + ciphertext.size = NUM10; // < +16 + + status = hks_aead_encrypt(&key, &keyParam, &cryptParam, &plaintext, &ciphertext); + EXPECT_EQ(NUM135, status); +} + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Encrypt key +// end==++++++++++++++++++++++++++++++++++++++++++++++++++++2100-4400 + diff --git a/security_lite/datahuks_posix/src/SecurityDataHuksGenDelTest.cpp b/security_lite/datahuks_posix/src/SecurityDataHuksGenDelTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..a247c10ae0932072c14aaa761f07b49aba9ce012 --- /dev/null +++ b/security_lite/datahuks_posix/src/SecurityDataHuksGenDelTest.cpp @@ -0,0 +1,717 @@ +/* Copyright (c) 2020 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 "SecurityDataHuks.h" +#include "hks_client.h" +#include "hks_types.h" +#include +#include +#include +#include +#include +#include +#include "gtest/gtest.h" +#include +#include +#include +#include "hks_errno.h" +#include +#include +using namespace std; +using namespace testing::ext; + +class SecurityDataHuksGenDelTestSuite : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() + { + int32_t status; + struct hks_file_callbacks fileCallbacks; + + fileCallbacks.read = FileRead; + fileCallbacks.write = FileWrite; + fileCallbacks.file_size = FileSize; + + status = hks_register_file_callbacks(&fileCallbacks); + EXPECT_EQ(0, status); + + struct hks_log_f_group logFunc; + logFunc.log_info = Logi; + logFunc.log_warn = Logw; + logFunc.log_error = Loge; + logFunc.log_debug = Logd; + + status = hks_register_log_interface(&logFunc); + EXPECT_EQ(0, status); + + status = hks_register_get_hardware_udid_callback(HksTestGetHardwareUdid); + + EXPECT_EQ(0, status); + + status = hks_init(); + if (status != 0) { + status = hks_refresh_key_info(); + } + EXPECT_EQ(0, status); + } + // Testcase teardown + virtual void TearDown() {} +}; + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++generate key +// begin+++++++++++++++++++++++++++++++++++++++++++++++++++0100-1300 + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL1_0000 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey0100, TestSize.Level1) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + int32_t statusGenerate; + int32_t statusDelete; + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + struct hks_blob keyAliasGenerate; + HksStBlobInit1(&keyAliasGenerate, sizeof(uint8_t), sizeof(testFileName) + NUM3, HKS_BLOB_TYPE_ALIAS); + if (memcpy_s(keyAliasGenerate.data, sizeof(testFileName), testFileName, sizeof(testFileName)) != EOK) { + HksBlobDestroyT1(&keyAliasGenerate); + EXPECT_EQ(0, 1); + return; + } + char tmpGenerate[NUM3] = { 0 }; + if (strcat_s((char *)keyAliasGenerate.data, strlen((char *)keyAliasGenerate.data) + strlen(tmpGenerate) + 1, tmpGenerate) != EOK) { + HksBlobDestroyT1(&keyAliasGenerate); + EXPECT_EQ(0, 1); + return; + } + keyAliasGenerate.size = strlen((char *)keyAliasGenerate.data); + statusGenerate = hks_generate_key(&keyAliasGenerate, &keyParam); + EXPECT_EQ(0, statusGenerate); + HksBlobDestroyT1(&keyAliasGenerate); + struct hks_blob keyAliasDelete; + HksStBlobInit1(&keyAliasDelete, sizeof(uint8_t), sizeof(testFileName) + NUM3, HKS_BLOB_TYPE_ALIAS); + if (memcpy_s(keyAliasDelete.data, sizeof(testFileName), testFileName, sizeof(testFileName)) != EOK) { + HksBlobDestroyT1(&keyAliasDelete); + EXPECT_EQ(0, 1); + return; + } + char tmpDelete[NUM3] = { 0 }; + if (strcat_s((char *)keyAliasDelete.data, strlen((char *)keyAliasDelete.data) + strlen(tmpDelete) + 1, tmpDelete) != EOK) { + HksBlobDestroyT1(&keyAliasDelete); + EXPECT_EQ(0, 1); + return; + } + keyAliasDelete.size = strlen((char *)keyAliasDelete.data); + statusDelete = hks_delete_key(&keyAliasDelete); + EXPECT_EQ(0, statusDelete); + HksBlobDestroyT1(&keyAliasDelete); +}; + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL1_0000 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey0200, TestSize.Level2) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + struct hks_blob *keyAlias = nullptr; // = NULL + int32_t status; + + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + + status = hks_generate_key(keyAlias, &keyParam); + EXPECT_EQ(NUM1000, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL1_0000 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey0300, TestSize.Level2) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + struct hks_blob keyAlias; + int32_t status; + + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = 0; // = 0 + + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + + status = hks_generate_key(&keyAlias, &keyParam); + EXPECT_EQ(NUM135, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL1_0000 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey0400, TestSize.Level2) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + struct hks_blob keyAlias; + int32_t status; + + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = NUM65; // > 64 + + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + + status = hks_generate_key(&keyAlias, &keyParam); + EXPECT_EQ(NUM135, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL1_0000 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey0500, TestSize.Level2) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + struct hks_blob keyAlias; + int32_t status; + + keyAlias.type = 0; // != HKS_BLOB_TYPE_ALIAS + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + + status = hks_generate_key(&keyAlias, &keyParam); + EXPECT_EQ(NUM135, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL1_0000 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey0600, TestSize.Level2) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + struct hks_blob keyAlias; + + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + keyAlias.data = NULL; // = NULL + keyAlias.size = sizeof(testFileName); + + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + + int32_t status = hks_generate_key(&keyAlias, &keyParam); + EXPECT_EQ(NUM135, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL1_0000 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey0700, TestSize.Level2) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + struct hks_blob keyAlias; + int32_t status; + + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + + struct hks_key_param *keyParam = nullptr; // = NULL + + status = hks_generate_key(&keyAlias, keyParam); + EXPECT_EQ(NUM1000, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL1_0000 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey0800, TestSize.Level2) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + struct hks_blob keyAlias; + int32_t status; + + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = 1; // != HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519 + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + + status = hks_generate_key(&keyAlias, &keyParam); + EXPECT_EQ(NUM134, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL1_0000 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey0900, TestSize.Level2) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + struct hks_blob keyAlias; + int32_t status; + + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = 0; // = 0 + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + + status = hks_generate_key(&keyAlias, &keyParam); + EXPECT_EQ(NUM135, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL1_0000 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey1000, TestSize.Level2) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + struct hks_blob keyAlias; + int32_t status; + + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = NUM65; // > 64 + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + + status = hks_generate_key(&keyAlias, &keyParam); + EXPECT_EQ(NUM135, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL1_0000 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey1100, TestSize.Level2) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + struct hks_blob keyAlias; + int32_t status; + + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = 0; // != HKS_BLOB_TYPE_AUTHID + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + + status = hks_generate_key(&keyAlias, &keyParam); + EXPECT_EQ(NUM135, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL1_0000 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey1200, TestSize.Level2) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + struct hks_blob keyAlias; + int32_t status; + + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + + struct hks_key_param keyParam; + keyParam.key_auth_id.data = NULL; // = NULL + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + + status = hks_generate_key(&keyAlias, &keyParam); + EXPECT_EQ(NUM1000, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL1_0000 + * @tc.name : Generate key + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksGenDelTestSuite, securityDataGenerateKey1300, TestSize.Level2) +{ + char testFileName[] = "keyalias1", testFileName1[] = "key_auth_id1"; + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t*)testFileName1; + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + for (int j = 0; j < NUM21; j++) { + struct hks_blob keyAlias; + HksStBlobInit1(&keyAlias, sizeof(uint8_t), sizeof(testFileName) + NUM3, HKS_BLOB_TYPE_ALIAS); + if (memcpy_s(keyAlias.data, sizeof(testFileName), testFileName, sizeof(testFileName)) != EOK) { + HksBlobDestroyT1(&keyAlias); + EXPECT_EQ(0, 1); + return; + } + char tmp[NUM3] = { 0 }; + sprintf_s(tmp, sizeof(tmp), "%d", j); + if (strcat_s((char*)keyAlias.data, strlen((char*)keyAlias.data) + strlen(tmp) + 1, tmp) != EOK) { + HksBlobDestroyT1(&keyAlias); + EXPECT_EQ(0, 1); + return; + } + keyAlias.size = strlen((char*)keyAlias.data); + int status = hks_generate_key(&keyAlias, &keyParam); + if (j < NUM20){ + EXPECT_EQ(0, status); + } + else { + EXPECT_EQ(NUM142, status); + } + HksBlobDestroyT1(&keyAlias); + } + for (int j = 0; j < NUM20; j++) { + struct hks_blob keyAlias; + HksStBlobInit1(&keyAlias, sizeof(uint8_t), sizeof(testFileName) + NUM3, HKS_BLOB_TYPE_ALIAS); + if (memcpy_s(keyAlias.data, sizeof(testFileName), testFileName, sizeof(testFileName)) != EOK) { + HksBlobDestroyT1(&keyAlias); + EXPECT_EQ(0, 1); + return; + } + char tmp[NUM3] = { 0 }; + sprintf_s(tmp, sizeof(tmp), "%d", j); + if (strcat_s((char*)keyAlias.data, strlen((char*)keyAlias.data) + strlen(tmp) + 1, tmp) != EOK) { + HksBlobDestroyT1(&keyAlias); + EXPECT_EQ(0, 1); + return; + } + keyAlias.size = strlen((char*)keyAlias.data); + int status = hks_delete_key(&keyAlias); + EXPECT_EQ(0, status); + HksBlobDestroyT1(&keyAlias); + } +} + + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++generate key +// end+++++++++++++++++++++++++++++++++++++++++++++++++++++0100-1300 + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Delete key +// begin+++++++++++++++++++++++++++++++++++++++++++++++++++++1400-2000 + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL1_0400 + * @tc.name : Delete key + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksGenDelTestSuite, securityDataDeleteKey1400, TestSize.Level1) +{ + char testFileName[] = "keyalias1"; + char testFileName1[] = "key_auth_id1"; + int32_t statusGenerate; + int32_t statusDelete; + struct hks_key_param keyParam; + keyParam.key_auth_id.data = (uint8_t *)testFileName1; + keyParam.key_auth_id.size = sizeof(testFileName1); + keyParam.key_auth_id.type = HKS_BLOB_TYPE_AUTH_ID; + keyParam.key_type = HKS_KEY_TYPE_EDDSA_KEYPAIR_ED25519; + keyParam.key_len = 0; + keyParam.key_usage = 0; + keyParam.key_pad = 0; + struct hks_blob keyAliasGenerate; + HksStBlobInit1(&keyAliasGenerate, sizeof(uint8_t), sizeof(testFileName) + NUM3, HKS_BLOB_TYPE_ALIAS); + if (memcpy_s(keyAliasGenerate.data, sizeof(testFileName), testFileName, sizeof(testFileName)) != EOK) { + HksBlobDestroyT1(&keyAliasGenerate); + EXPECT_EQ(0, 1); + return; + } + char tmpGenerate[NUM3] = { 0 }; + if (strcat_s((char *)keyAliasGenerate.data, strlen((char *)keyAliasGenerate.data) + strlen(tmpGenerate) + 1, tmpGenerate) != EOK) { + HksBlobDestroyT1(&keyAliasGenerate); + EXPECT_EQ(0, 1); + return; + } + keyAliasGenerate.size = strlen((char *)keyAliasGenerate.data); + statusGenerate = hks_generate_key(&keyAliasGenerate, &keyParam); + EXPECT_EQ(0, statusGenerate); + HksBlobDestroyT1(&keyAliasGenerate); + struct hks_blob keyAliasDelete; + HksStBlobInit1(&keyAliasDelete, sizeof(uint8_t), sizeof(testFileName) + NUM3, HKS_BLOB_TYPE_ALIAS); + if (memcpy_s(keyAliasDelete.data, sizeof(testFileName), testFileName, sizeof(testFileName)) != EOK) { + HksBlobDestroyT1(&keyAliasDelete); + EXPECT_EQ(0, 1); + return; + } + char tmpDelete[NUM3] = { 0 }; + if (strcat_s((char *)keyAliasDelete.data, strlen((char *)keyAliasDelete.data) + strlen(tmpDelete) + 1, tmpDelete) != EOK) { + HksBlobDestroyT1(&keyAliasDelete); + EXPECT_EQ(0, 1); + return; + } + keyAliasDelete.size = strlen((char *)keyAliasDelete.data); + statusDelete = hks_delete_key(&keyAliasDelete); + EXPECT_EQ(0, statusDelete); + HksBlobDestroyT1(&keyAliasDelete); +}; + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL1_0400 + * @tc.name : Delete key + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksGenDelTestSuite, securityDataDeleteKey1500, TestSize.Level2) +{ + int32_t status; + char testFileName[] = "Test_file_north_interfaces"; + struct hks_blob *keyAlias = nullptr; // = NULL + + status = hks_delete_key(keyAlias); + EXPECT_EQ(NUM1000, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL1_0400 + * @tc.name : Delete key + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksGenDelTestSuite, securityDataDeleteKey1600, TestSize.Level2) +{ + int32_t status; + char testFileName[] = "Test_file_north_interfaces"; + struct hks_blob keyAlias = { 0 }; + + keyAlias.data = NULL; // = NULL + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + status = hks_delete_key(&keyAlias); + EXPECT_EQ(NUM135, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL1_0400 + * @tc.name : Delete key + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksGenDelTestSuite, securityDataDeleteKey1700, TestSize.Level2) +{ + int32_t status; + char testFileName[] = "Test_file_north_interfaces"; + struct hks_blob keyAlias = { 0 }; + + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = 0; // != HKS_BLOB_TYPE_ALIAS + + status = hks_delete_key(&keyAlias); + EXPECT_EQ(NUM135, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL1_0400 + * @tc.name : Delete key + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksGenDelTestSuite, securityDataDeleteKey1800, TestSize.Level2) +{ + int32_t status; + char testFileName[] = "Test_file_north_interfaces"; + struct hks_blob keyAlias = { 0 }; + + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = 0; + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + status = hks_delete_key(&keyAlias); + EXPECT_EQ(NUM135, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL1_0400 + * @tc.name : Delete key + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksGenDelTestSuite, securityDataDeleteKey1900, TestSize.Level2) +{ + int32_t status; + char testFileName[] = "Test_file_north_interfaces"; + struct hks_blob keyAlias = { 0 }; + + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = NUM65; + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + status = hks_delete_key(&keyAlias); + EXPECT_EQ(NUM135, status); +} + +/* * + * @tc.number : SUB_SEC_DataPro_HuksL1_0400 + * @tc.name : Delete key + * @tc.desc : [C- SECURITY -1500] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksGenDelTestSuite, securityDataDeleteKey2000, TestSize.Level2) +{ + int32_t status; + char testFileName[] = "Test_file_north_interfaces"; + struct hks_blob keyAlias = { 0 }; + + keyAlias.data = (uint8_t *)testFileName; + keyAlias.size = sizeof(testFileName); + keyAlias.type = HKS_BLOB_TYPE_ALIAS; + + status = hks_delete_key(&keyAlias); + EXPECT_EQ(NUM1010, status); +} +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Delete key +// end+++++++++++++++++++++++++++++++++++++++++++++++++++++++1400-2000 + diff --git a/security_lite/datahuks_posix/src/SecurityDataHuksHashRandomHmacTest.cpp b/security_lite/datahuks_posix/src/SecurityDataHuksHashRandomHmacTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..ee05620f054f605eb55386a67598e0574a17aa5a --- /dev/null +++ b/security_lite/datahuks_posix/src/SecurityDataHuksHashRandomHmacTest.cpp @@ -0,0 +1,543 @@ +/* Copyright (c) 2020 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 "SecurityDataHuks.h" +#include "hks_client.h" +#include "hks_types.h" +#include +#include +#include +#include +#include +#include "gtest/gtest.h" +using namespace std; +using namespace testing::ext; + +class SecurityDataHuksHashRandomHmacTestSuite : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() + { + int32_t status; + struct hks_file_callbacks fileCallbacks; + + fileCallbacks.read = FileRead; + fileCallbacks.write = FileWrite; + fileCallbacks.file_size = FileSize; + + status = hks_register_file_callbacks(&fileCallbacks); + EXPECT_EQ(0, status); + + struct hks_log_f_group logFunc; + logFunc.log_info = Logi; + logFunc.log_warn = Logw; + logFunc.log_error = Loge; + logFunc.log_debug = Logd; + + status = hks_register_log_interface(&logFunc); + EXPECT_EQ(0, status); + + status = hks_register_get_hardware_udid_callback(HksTestGetHardwareUdid); + + EXPECT_EQ(0, status); + + status = hks_init(); + if (status != 0) { + status = hks_refresh_key_info(); + } + EXPECT_EQ(0, status); + } + + // Testcase teardown + virtual void TearDown() {} +}; + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Hash +// begin+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++6900-7800 + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1500 + * @tc.name : Hash + * @tc.desc : [C- SECURITY -1600] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksHashRandomHmacTestSuite, securityDataHash6900, TestSize.Level1) +{ + struct hks_blob src, dst; + src.data = (uint8_t *)"123456"; + src.size = NUM6; + dst.data = (uint8_t *)malloc(NUM65); + if (dst.data == NULL) { + EXPECT_EQ(0, 1); + } + dst.size = NUM65; + + int32_t res = hks_hash(HKS_ALG_HASH_SHA_256, &src, &dst); + EXPECT_EQ(0, res); + free(dst.data); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1500 + * @tc.name : Hash + * @tc.desc : [C- SECURITY -1600] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksHashRandomHmacTestSuite, securityDataHash7000, TestSize.Level1) +{ + struct hks_blob src, dst; + src.data = (uint8_t *)"123456"; + src.size = NUM6; + dst.data = (uint8_t *)malloc(NUM65); + if (dst.data == NULL) { + EXPECT_EQ(0, 1); + } + dst.size = NUM65; + + int32_t res = hks_hash(HKS_ALG_HASH_SHA_512, &src, &dst); + EXPECT_EQ(0, res); + free(dst.data); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1500 + * @tc.name : Hash + * @tc.desc : [C- SECURITY -1600] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksHashRandomHmacTestSuite, securityDataHash7100, TestSize.Level2) +{ + struct hks_blob srcData = { 0 }; + char tmpData6[] = "30313233343536373839616263646566"; + BuildBlobData(&srcData, tmpData6, HKS_BLOB_TYPE_RAW, NUM16, 0); + + struct hks_blob hash = { 0 }; + char tmpData7[] = "3031323334353637383961626364656630313233343536373839616263646566"; + BuildBlobData(&hash, tmpData7, HKS_BLOB_TYPE_RAW, NUM32, 0); + + uint32_t alg = HKS_ALG_HASH_SHA_1; // != HKS_ALG_HASH_SHA_256 HKS_ALG_HASH_SHA_512 + int32_t status = hks_hash(alg, &srcData, &hash); + HksBlobDestroyT1(&srcData); + HksBlobDestroyT1(&hash); + EXPECT_EQ(NUM135, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1500 + * @tc.name : Hash + * @tc.desc : [C- SECURITY -1600] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksHashRandomHmacTestSuite, securityDataHash7200, TestSize.Level2) +{ + struct hks_blob *srcData = nullptr; // = NULL + + struct hks_blob hash = { 0 }; + const char tmpData7[] = "3031323334353637383961626364656630313233343536373839616263646566"; + BuildBlobData(&hash, tmpData7, HKS_BLOB_TYPE_RAW, NUM32, 0); + + uint32_t alg = HKS_ALG_HASH_SHA_256; + int32_t status = hks_hash(alg, srcData, &hash); + HksBlobDestroyT1(&hash); + EXPECT_EQ(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1500 + * @tc.name : Hash + * @tc.desc : [C- SECURITY -1600] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksHashRandomHmacTestSuite, securityDataHash7300, TestSize.Level2) +{ + struct hks_blob srcData = { 0 }; + const char tmpData6[] = "30313233343536373839616263646566"; + BuildBlobData(&srcData, tmpData6, HKS_BLOB_TYPE_RAW, NUM16, 1); // srcData.data = NULL + + struct hks_blob hash = { 0 }; + const char tmpData7[] = "3031323334353637383961626364656630313233343536373839616263646566"; + BuildBlobData(&hash, tmpData7, HKS_BLOB_TYPE_RAW, NUM32, 0); + + uint32_t alg = HKS_ALG_HASH_SHA_256; + int32_t status = hks_hash(alg, &srcData, &hash); + HksBlobDestroyT1(&srcData); + HksBlobDestroyT1(&hash); + EXPECT_EQ(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1500 + * @tc.name : Hash + * @tc.desc : [C- SECURITY -1600] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksHashRandomHmacTestSuite, securityDataHash7400, TestSize.Level2) +{ + struct hks_blob srcData = { 0 }; + srcData.data = (uint8_t *)"1234567890abcdefghigkl0123456789"; + srcData.size = 0; // = 0 + srcData.type = HKS_BLOB_TYPE_RAW; + + struct hks_blob hash = { 0 }; + const char tmpData7[] = "3031323334353637383961626364656630313233343536373839616263646566"; + BuildBlobData(&hash, tmpData7, HKS_BLOB_TYPE_RAW, NUM32, 0); + + uint32_t alg = HKS_ALG_HASH_SHA_256; + int32_t status = hks_hash(alg, &srcData, &hash); + HksBlobDestroyT1(&hash); + EXPECT_EQ(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1500 + * @tc.name : Hash + * @tc.desc : [C- SECURITY -1600] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksHashRandomHmacTestSuite, securityDataHash7500, TestSize.Level2) +{ + struct hks_blob srcData = { 0 }; + const char tmpData6[] = "30313233343536373839616263646566"; + BuildBlobData(&srcData, tmpData6, HKS_BLOB_TYPE_RAW, NUM16, 0); + + struct hks_blob *hash = nullptr; // = NULL + + uint32_t alg = HKS_ALG_HASH_SHA_256; + int32_t status = hks_hash(alg, &srcData, hash); + HksBlobDestroyT1(&srcData); + EXPECT_EQ(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1500 + * @tc.name : Hash + * @tc.desc : [C- SECURITY -1600] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksHashRandomHmacTestSuite, securityDataHash7600, TestSize.Level2) +{ + struct hks_blob srcData = { 0 }; + const char tmpData6[] = "30313233343536373839616263646566"; + BuildBlobData(&srcData, tmpData6, HKS_BLOB_TYPE_RAW, NUM16, 0); + + struct hks_blob hash = { 0 }; + const char tmpData7[] = "3031323334353637383961626364656630313233343536373839616263646566"; + BuildBlobData(&hash, tmpData7, HKS_BLOB_TYPE_RAW, NUM32, 1); // hash.data = NULL + + uint32_t alg = HKS_ALG_HASH_SHA_256; + int32_t status = hks_hash(alg, &srcData, &hash); + HksBlobDestroyT1(&srcData); + HksBlobDestroyT1(&hash); + EXPECT_EQ(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1500 + * @tc.name : Hash + * @tc.desc : [C- SECURITY -1600] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksHashRandomHmacTestSuite, securityDataHash7700, TestSize.Level2) +{ + struct hks_blob srcData = { 0 }; + const char tmpData6[] = "30313233343536373839616263646566"; + BuildBlobData(&srcData, tmpData6, HKS_BLOB_TYPE_RAW, NUM16, 0); + + struct hks_blob hash = { 0 }; + const char tmpData7[] = "303132333435363738396162636465663031323334353637383961611266"; + BuildBlobData(&hash, tmpData7, HKS_BLOB_TYPE_RAW, NUM30, 0); // hash.size < 32 + + uint32_t alg = HKS_ALG_HASH_SHA_256; + int32_t status = hks_hash(alg, &srcData, &hash); + HksBlobDestroyT1(&srcData); + HksBlobDestroyT1(&hash); + EXPECT_EQ(NUM1007, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1500 + * @tc.name : Hash + * @tc.desc : [C- SECURITY -1600] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksHashRandomHmacTestSuite, securityDataHash7800, TestSize.Level2) +{ + struct hks_blob srcData = { 0 }; + const char tmpData6[] = "30313233343536373839616263646566"; + BuildBlobData(&srcData, tmpData6, HKS_BLOB_TYPE_RAW, NUM16, 0); + + struct hks_blob hash = { 0 }; + const char tmpData7[] = "303132333435363738396162636465663031323334353637383961626364656630313233343536373839616263646566303132333435363738396162"; + BuildBlobData(&hash, tmpData7, HKS_BLOB_TYPE_RAW, NUM60, 0); // hash.size < 64 + + uint32_t alg = HKS_ALG_HASH_SHA_512; + int32_t status = hks_hash(alg, &srcData, &hash); + HksBlobDestroyT1(&srcData); + HksBlobDestroyT1(&hash); + EXPECT_EQ(NUM1007, status); +} + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Hash +// end+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++6900-7800 + + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Generate random +// beign++++++++++++++++++++++++++++++++++++++++++++++++7900-8200 + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_0700 + * @tc.name : Generate Random + * @tc.desc : [C- SECURITY -1700] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksHashRandomHmacTestSuite, securityDataGenerateRandom7900, TestSize.Level1) +{ + int32_t status; + struct hks_blob random = { 0 }; + + random.data = (uint8_t *)calloc(1, NUM64); + if (random.data == NULL) { + EXPECT_EQ(0, 1); + return; + } + if (memset_s(random.data, NUM64, 0, NUM64) != EOK) { + EXPECT_EQ(0, 1); + } + random.size = NUM64; + random.type = 0; + status = hks_generate_random(&random); + EXPECT_EQ(0, status); + + HksBlobDestroyT1(&random); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_0700 + * @tc.name : Generate Random + * @tc.desc : [C- SECURITY -1700] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksHashRandomHmacTestSuite, securityDataGenerateRandom8000, TestSize.Level2) +{ + int32_t status; + struct hks_blob *random = nullptr; // = NULL + + status = hks_generate_random(random); + EXPECT_EQ(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_0700 + * @tc.name : Generate Random + * @tc.desc : [C- SECURITY -1700] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksHashRandomHmacTestSuite, securityDataGenerateRandom8100, TestSize.Level2) +{ + int32_t status; + struct hks_blob random = { 0 }; + + random.data = NULL; // = NULL + random.size = NUM32; + random.type = HKS_BLOB_TYPE_KEY; + + status = hks_generate_random(&random); + EXPECT_EQ(NUM1000, status); + HksBlobDestroyT1(&random); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_0700 + * @tc.name : Generate Random + * @tc.desc : [C- SECURITY -1700] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksHashRandomHmacTestSuite, securityDataGenerateRandom8200, TestSize.Level2) +{ + int32_t status; + struct hks_blob random = { 0 }; + + random.data = (uint8_t *)malloc(NUM1025); + if (random.data == NULL) { + EXPECT_EQ(0, 1); + } + random.size = NUM1025; // > 1024 + random.type = HKS_BLOB_TYPE_KEY; + + status = hks_generate_random(&random); + EXPECT_EQ(NUM135, status); + HksBlobDestroyT1(&random); +} + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Generate random +// end++++++++++++++++++++++++++++++++++++++++++++++++++7900-8200 + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Hmac +// begin+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++8300-9700 + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1400 + * @tc.name : Hmac + * @tc.desc : [C- SECURITY -2000] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksHashRandomHmacTestSuite, securityDataHmac8300, TestSize.Level1) +{ + struct hks_blob keyAlias; + uint32_t alg = hks_alg_hmac(HKS_ALG_HASH_SHA_256); + struct hks_blob srcData; + srcData.data = (uint8_t *)"123456789"; + srcData.size = NUM9; + + struct hks_blob output; + output.data = (uint8_t *)malloc(NUM65); + output.size = NUM65; + keyAlias.data = (uint8_t *)"1234567890abcdefghigkl0123456789"; + keyAlias.size = NUM32; + keyAlias.type = HKS_KEY_USAGE_EXPORT; + + int32_t status = hks_hmac(&keyAlias, alg, &srcData, &output); + EXPECT_EQ(0, status); + + HKS_FREE_PTR1(output.data); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1400 + * @tc.name : Hmac + * @tc.desc : [C- SECURITY -2000] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksHashRandomHmacTestSuite, securityDataHmac8400, TestSize.Level1) +{ + struct hks_blob keyAlias; + uint32_t alg = hks_alg_hmac(HKS_ALG_HASH_SHA_512); + struct hks_blob srcData; + srcData.data = (uint8_t *)"123456789"; + srcData.size = NUM9; + + struct hks_blob output; + output.data = (uint8_t *)malloc(NUM65); + output.size = NUM65; + keyAlias.data = (uint8_t *)"1234567890abcdefghigkl0123456789"; + keyAlias.size = NUM65; + keyAlias.type = HKS_KEY_USAGE_EXPORT; + + int32_t status = hks_hmac(&keyAlias, alg, &srcData, &output); + EXPECT_EQ(0, status); + + HKS_FREE_PTR1(output.data); +}; + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1400 + * @tc.name : Hmac + * @tc.desc : [C- SECURITY -2000] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksHashRandomHmacTestSuite, securityDataHmac8500, TestSize.Level2) +{ + struct hks_blob *key = nullptr; // key = NULL + struct hks_blob srcData = { 0 }; + const char tmpData6[] = "3031323334353637"; + BuildBlobData(&srcData, tmpData6, HKS_BLOB_TYPE_RAW, NUM8, 0); + + struct hks_blob output = { 0 }; + const char tmpData7[] = "3031323334353637303132333435363730313233343536373031323334353637"; + BuildBlobData(&output, tmpData7, HKS_BLOB_TYPE_RAW, NUM32, 0); + + uint32_t alg = hks_alg_hmac(HKS_ALG_HASH_SHA_256); + int32_t status = hks_hmac(key, alg, &srcData, &output); + HksBlobDestroyT1(&srcData); + HksBlobDestroyT1(&output); + EXPECT_EQ(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1400 + * @tc.name : Hmac + * @tc.desc : [C- SECURITY -2000] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksHashRandomHmacTestSuite, securityDataHmac8600, TestSize.Level2) +{ + struct hks_blob key = { 0 }; + const char tmpData5[] = "3031323334353637303132333435363730313233343536373031323334353637"; + BuildBlobData(&key, tmpData5, HKS_BLOB_TYPE_RAW, NUM32, NUM1); // key.data = NULL + + struct hks_blob srcData = { 0 }; + const char tmpData6[] = "3031323334353637"; + BuildBlobData(&srcData, tmpData6, HKS_BLOB_TYPE_RAW, NUM8, 0); + + struct hks_blob output = { 0 }; + const char tmpData7[] = "3031323334353637303132333435363730313233343536373031323334353637"; + BuildBlobData(&output, tmpData7, HKS_BLOB_TYPE_RAW, NUM32, 0); + + uint32_t alg = hks_alg_hmac(HKS_ALG_HASH_SHA_256); + int32_t status = hks_hmac(&key, alg, &srcData, &output); + HksBlobDestroyT1(&key); + HksBlobDestroyT1(&srcData); + HksBlobDestroyT1(&output); + EXPECT_EQ(NUM1000, status); +} + +/* + * @tc.number : SUB_SEC_DataPro_HuksL1_1400 + * @tc.name : Hmac + * @tc.desc : [C- SECURITY -2000] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SecurityDataHuksHashRandomHmacTestSuite, securityDataHmac8700, TestSize.Level2) +{ + struct hks_blob key = { 0 }; + key.data = (uint8_t *)"1234567890abcdefghigkl0123456789"; + key.size = 0; // key.size <= 0 + key.type = HKS_BLOB_TYPE_RAW; + + struct hks_blob srcData = { 0 }; + const char tmpData6[] = "3031323334353637"; + BuildBlobData(&srcData, tmpData6, HKS_BLOB_TYPE_RAW, NUM8, 0); + + struct hks_blob output = { 0 }; + const char tmpData7[] = "3031323334353637303132333435363730313233343536373031323334353637"; + BuildBlobData(&output, tmpData7, HKS_BLOB_TYPE_RAW, NUM32, 0); + + uint32_t alg = hks_alg_hmac(HKS_ALG_HASH_SHA_256); + int32_t status = hks_hmac(&key, alg, &srcData, &output); + HksBlobDestroyT1(&srcData); + HksBlobDestroyT1(&output); + EXPECT_EQ(NUM1000, status); +} diff --git a/security_lite/permission_posix/dac/BUILD.gn b/security_lite/permission_posix/dac/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..589e74f5706fe85903c3c37af890bd977a5ad96c --- /dev/null +++ b/security_lite/permission_posix/dac/BUILD.gn @@ -0,0 +1,35 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsDacTest") { + suite_name = "acts" + sources = [ + "src/ActsDacPreTest.cpp", + "src/ActsDacTest.cpp", + "src/ActsSystemDevDacTest.cpp", + "src/ActsSystemJffsDacTest.cpp", + ] + + include_dirs = [ + "src", + "//third_party/bounds_checking_function/include", + ] + + public_deps = [ + "//third_party/bounds_checking_function:libsec_shared", + ] + + cflags = [ "-Wno-error" ] +} \ No newline at end of file diff --git a/security_lite/permission_posix/dac/Test.json b/security_lite/permission_posix/dac/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..cf5b7776b0917e8aa9b99dea51e32c60bc0d1326 --- /dev/null +++ b/security_lite/permission_posix/dac/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for hcpptest demo test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/security", + "target": "/test_root/security" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/security/ActsDacTest.bin" + } +} \ No newline at end of file diff --git a/security_lite/permission_posix/dac/src/ActsDacPreTest.cpp b/security_lite/permission_posix/dac/src/ActsDacPreTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..4615a55c75282ad15686ac511a99eeaea1557ce3 --- /dev/null +++ b/security_lite/permission_posix/dac/src/ActsDacPreTest.cpp @@ -0,0 +1,667 @@ +/* + * Copyright (c) 2020 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 "ActsDacTest.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "gtest/gtest.h" + +#ifdef __LINUX__ +#include +#include +#include +#else +#include +#endif + +#ifdef __LINUX__ +__BEGIN_DECLS +extern int capget(cap_user_header_t hdrp, cap_user_data_t datap); +extern int capset(cap_user_header_t hdrp, const cap_user_data_t datap); +__END_DECLS +#endif + +using namespace std; +using namespace testing::ext; + +class DacPreTestSuite : public testing::Test { +protected: + // SetUpTestCase:测试套预置动作,在第一个TestCase之前执行 + static void SetUpTestCase(void) {} + // TearDownTestCase:测试套清理动作,在最后一个TestCase之后执行 + static void TearDownTestCase(void) {} + // 用例的预置动作 + virtual void SetUp() + { + // uid=gid=0 + struct __user_cap_header_struct capheader; + struct __user_cap_data_struct capdata[CAP_NUM]; + int ret; + memset_s(&capheader, sizeof(struct __user_cap_header_struct), 0, sizeof(struct __user_cap_header_struct)); + memset_s(capdata, CAP_NUM * sizeof(struct __user_cap_data_struct), 0, + CAP_NUM * sizeof(struct __user_cap_data_struct)); + capdata[0].permitted = 0xffffffff; + capdata[1].permitted = 0xffffffff; + capheader.version = _LINUX_CAPABILITY_VERSION_3; + capdata[CAP_TO_INDEX(CAP_SETPCAP)].effective |= CAP_TO_MASK(CAP_SETPCAP); + capdata[CAP_TO_INDEX(CAP_SETUID)].effective |= CAP_TO_MASK(CAP_SETUID); + capdata[CAP_TO_INDEX(CAP_SETGID)].effective |= CAP_TO_MASK(CAP_SETGID); + ret = capset(&capheader, &capdata[0]); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting privileges"; + ret = setuid(UID0); + EXPECT_EQ(ret, 0) << "ErrInfo: Set uid failed,now uid=" << getuid(); + ret = setgid(GID0); + EXPECT_EQ(ret, 0) << "ErrInfo: Set gid failed,now gid=" << getgid(); + } + // 用例的清理动作 + virtual void TearDown() {} +}; + +static int TestSetUid() +{ + int ret; + int exitCode = 0; + uid_t ruid1, euid1, suid1; + // setuid + ret = setuid(0); + if (ret != 0) { + LOG("Failed in setting uid=0,now uid=%d", getuid()); + exitCode = 1; + } + getresuid(&ruid1, &euid1, &suid1); + EXPECT_TRUE((ruid1 == 0) && (euid1 == 0) && (suid1 == 0)) << "Failed in setting uid:ruid=" << ruid1 << ",euid=" << + euid1 << ",suid=" << suid1; + ret = setuid(UID1000); + if (ret != 0) { + LOG("Failed in setting uid=1000,now uid=%d", getuid()); + exitCode = 1; + } + getresuid(&ruid1, &euid1, &suid1); + EXPECT_TRUE((ruid1 == UID1000) && (euid1 == UID1000) && (suid1 == UID1000)) << "Failed in setting uid:ruid=" << + ruid1 << ",euid=" << euid1 << ",suid=" << suid1; + ret = setuid(UID10000); + if (ret != 0) { + LOG("Failed in setting uid=10000,now uid=%d", getuid()); + exitCode = 1; + } + getresuid(&ruid1, &euid1, &suid1); + EXPECT_TRUE((ruid1 == UID10000) && (euid1 == UID10000) && (suid1 == UID10000)) << "Failed in setting uid:ruid=" << + ruid1 << ",euid=" << euid1 << ",suid=" << suid1; + ret = setuid(MAX_INT); + if (ret != 0) { + LOG("Failed in setting uid=MAX_INT,now uid=%d", getuid()); + exitCode = 1; + } + getresuid(&ruid1, &euid1, &suid1); + EXPECT_TRUE((ruid1 == MAX_INT) && (euid1 == MAX_INT) && (suid1 == MAX_INT)) << "Failed in setting uid:ruid=" << + ruid1 << ",euid=" << euid1 << ",suid=" << suid1; + return exitCode; +} + +static void TestSetREUid() +{ + int ret; + uid_t ruid1, euid1, suid1; + // setreuid + ret = setreuid(0, 0); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting reuid,now uid=" << getuid(); + getresuid(&ruid1, &euid1, &suid1); + EXPECT_TRUE((ruid1 == 0) && (euid1 == 0) && (suid1 == 0)) << "Failed in setting uid:ruid=" << ruid1 << ",euid=" << + euid1 << ",suid=" << suid1; + ret = setreuid(UID1000, UID1000); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting reuid,now uid=" << getuid(); + getresuid(&ruid1, &euid1, &suid1); + EXPECT_TRUE((ruid1 == UID1000) && (euid1 == UID1000) && (suid1 == UID1000)) << "Failed in setting uid:ruid=" << + ruid1 << ",euid=" << euid1 << ",suid=" << suid1; + ret = setreuid(UID10000, UID10000); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting reuid,now uid=" << getuid(); + getresuid(&ruid1, &euid1, &suid1); + EXPECT_TRUE((ruid1 == UID10000) && (euid1 == UID10000) && (suid1 == UID10000)) << "Failed in setting uid:ruid=" << + ruid1 << ",euid=" << euid1 << ",suid=" << suid1; + ret = setreuid(MAX_INT, MAX_INT); + EXPECT_EQ(ret, 0) << "ErrInfo: Set uid = MAX_INT,now uid=" << getuid(); + getresuid(&ruid1, &euid1, &suid1); + EXPECT_TRUE((ruid1 == MAX_INT) && (euid1 == MAX_INT) && (suid1 == MAX_INT)) << "Failed in setting uid:ruid=" << + ruid1 << ",euid=" << euid1 << ",suid=" << suid1; +} + +static void TestSetRESUid() +{ + int ret; + uid_t ruid1, euid1, suid1; + // setresuid + ret = setresuid(0, 0, 0); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting resuid,now uid=" << getuid(); + getresuid(&ruid1, &euid1, &suid1); + EXPECT_TRUE((ruid1 == 0) && (euid1 == 0) && (suid1 == 0)) << "Failed in setting uid:ruid=" << ruid1 << ",euid=" << + euid1 << ",suid=" << suid1; + ret = setresuid(UID1000, UID1000, UID1000); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting resuid,now uid=" << getuid(); + getresuid(&ruid1, &euid1, &suid1); + EXPECT_TRUE((ruid1 == UID1000) && (euid1 == UID1000) && (suid1 == UID1000)) << "Failed in setting uid:ruid=" << + ruid1 << ",euid=" << euid1 << ",suid=" << suid1; + ret = setresuid(UID10000, UID10000, UID10000); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting resuid,now uid=" << getuid(); + getresuid(&ruid1, &euid1, &suid1); + EXPECT_TRUE((ruid1 == UID10000) && (euid1 == UID10000) && (suid1 == UID10000)) << "Failed in setting uid:ruid=" << + ruid1 << ",euid=" << euid1 << ",suid=" << suid1; + ret = setresuid(MAX_INT, MAX_INT, MAX_INT); + EXPECT_EQ(ret, 0) << "ErrInfo: Set uid = MAX_INT,now uid=" << getuid(); + getresuid(&ruid1, &euid1, &suid1); + EXPECT_TRUE((ruid1 == MAX_INT) && (euid1 == MAX_INT) && (suid1 == MAX_INT)) << "Failed in setting uid:ruid=" << + ruid1 << ",euid=" << euid1 << ",suid=" << suid1; +} + +static void TestSetUidAbnormal() +{ + int ret; + uid_t ruid1, euid1, suid1, ruid, euid, suid; + getresuid(&ruid, &euid, &suid); + // setuid = -1 + ret = setuid(ABNORMALINT); + EXPECT_EQ(ret, -1) << "ErrInfo: Set uid=-1,now uid=" << getuid(); + getresuid(&ruid1, &euid1, &suid1); + EXPECT_TRUE((ruid1 == ruid) && (euid1 == euid) && (suid1 == suid)) << "Failed in setting uid:ruid=" << ruid1 << + ",euid=" << euid1 << ",suid=" << suid1; + // setreuid = -1 + ret = setreuid(ABNORMALINT, ABNORMALINT); + EXPECT_EQ(ret, -1) << "ErrInfo: Set uid=-1,now uid=" << getuid(); + getresuid(&ruid1, &euid1, &suid1); + EXPECT_TRUE((ruid1 == ruid) && (euid1 == euid) && (suid1 == suid)) << "Failed in setting uid:ruid=" << ruid1 << + ",euid=" << euid1 << ",suid=" << suid1; + // setresuid = -1 + ret = setresuid(ABNORMALINT, ABNORMALINT, ABNORMALINT); + EXPECT_EQ(ret, -1) << "ErrInfo: Set uid=-1,now uid=" << getuid(); + getresuid(&ruid1, &euid1, &suid1); + EXPECT_TRUE((ruid1 == ruid) && (euid1 == euid) && (suid1 == suid)) << "Failed in setting uid:ruid=" << ruid1 << + ",euid=" << euid1 << ",suid=" << suid1; +} + +static int TestSetGid() +{ + int ret; + int exitCode = 0; + gid_t rgid1, egid1, sgid1; + // setgid + ret = setgid(0); + if (ret != 0) { + LOG("Failed in setting gid=0,now gid=%d", getgid()); + exitCode = 1; + } + getresgid(&rgid1, &egid1, &sgid1); + EXPECT_TRUE((rgid1 == 0) && (egid1 == 0) && (sgid1 == 0)) << "Failed in setting gid:rgid=" << rgid1 << ",egid=" << + egid1 << ",sgid=" << sgid1; + ret = setgid(GID1000); + if (ret != 0) { + LOG("Failed in setting gid=1000,now gid=%d", getgid()); + exitCode = 1; + } + getresgid(&rgid1, &egid1, &sgid1); + EXPECT_TRUE((rgid1 == GID1000) && (egid1 == GID1000) && (sgid1 == GID1000)) << "Failed in setting gid:rgid=" << + rgid1 << ",egid=" << egid1 << ",sgid=" << sgid1; + ret = setgid(GID10000); + if (ret != 0) { + LOG("Failed in setting gid=10000,now gid=%d", getgid()); + exitCode = 1; + } + getresgid(&rgid1, &egid1, &sgid1); + EXPECT_TRUE((rgid1 == GID10000) && (egid1 == GID10000) && (sgid1 == GID10000)) << "Failed in setting gid:rgid=" << + rgid1 << ",egid=" << egid1 << ",sgid=" << sgid1; + ret = setgid(MAX_INT); + if (ret != 0) { + LOG("Failed in setting gid=MAX_INT,now gid=%d", getgid()); + exitCode = 1; + } + getresgid(&rgid1, &egid1, &sgid1); + EXPECT_TRUE((rgid1 == MAX_INT) && (egid1 == MAX_INT) && (sgid1 == MAX_INT)) << "Failed in setting gid:rgid=" << + rgid1 << ",egid=" << egid1 << ",sgid=" << sgid1; + return exitCode; +} + +static void TestSetREGid() +{ + int ret; + gid_t rgid1, egid1, sgid1; + // setregid + ret = setregid(0, 0); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting regid,now uid=" << getuid(); + getresgid(&rgid1, &egid1, &sgid1); + EXPECT_TRUE((rgid1 == 0) && (egid1 == 0) && (sgid1 == 0)) << "Failed in setting gid:rgid=" << rgid1 << ",egid=" << + egid1 << ",sgid=" << sgid1; + ret = setregid(GID1000, GID1000); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting regid,now uid=" << getuid(); + getresgid(&rgid1, &egid1, &sgid1); + EXPECT_TRUE((rgid1 == GID1000) && (egid1 == GID1000) && (sgid1 == GID1000)) << "Failed in setting gid:rgid=" << + rgid1 << ",egid=" << egid1 << ",sgid=" << sgid1; + ret = setregid(GID10000, GID10000); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting regid,now uid=" << getuid(); + getresgid(&rgid1, &egid1, &sgid1); + EXPECT_TRUE((rgid1 == GID10000) && (egid1 == GID10000) && (sgid1 == GID10000)) << "Failed in setting gid:rgid=" << + rgid1 << ",egid=" << egid1 << ",sgid=" << sgid1; + ret = setregid(MAX_INT, MAX_INT); + EXPECT_EQ(ret, 0) << "ErrInfo: Set gid = MAX_INT,now uid=" << getuid(); + getresgid(&rgid1, &egid1, &sgid1); + EXPECT_TRUE((rgid1 == MAX_INT) && (egid1 == MAX_INT) && (sgid1 == MAX_INT)) << "Failed in setting gid:rgid=" << + rgid1 << ",egid=" << egid1 << ",sgid=" << sgid1; +} + +static void TestSetRESGid() +{ + int ret; + gid_t rgid1, egid1, sgid1; + // setresgid + ret = setresgid(0, 0, 0); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting resgid,now uid=" << getuid(); + getresgid(&rgid1, &egid1, &sgid1); + EXPECT_TRUE((rgid1 == 0) && (egid1 == 0) && (sgid1 == 0)) << "Failed in setting gid:rgid=" << rgid1 << ",egid=" << + egid1 << ",sgid=" << sgid1; + ret = setresgid(GID1000, GID1000, GID1000); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting resgid,now uid=" << getuid(); + getresgid(&rgid1, &egid1, &sgid1); + EXPECT_TRUE((rgid1 == GID1000) && (egid1 == GID1000) && (sgid1 == GID1000)) << "Failed in setting gid:rgid=" << + rgid1 << ",egid=" << egid1 << ",sgid=" << sgid1; + ret = setresgid(GID10000, GID10000, GID10000); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting resgid,now uid=" << getuid(); + getresgid(&rgid1, &egid1, &sgid1); + EXPECT_TRUE((rgid1 == GID10000) && (egid1 == GID10000) && (sgid1 == GID10000)) << "Failed in setting gid:rgid=" << + rgid1 << ",egid=" << egid1 << ",sgid=" << sgid1; + ret = setresgid(MAX_INT, MAX_INT, MAX_INT); + getresgid(&rgid1, &egid1, &sgid1); + EXPECT_EQ(ret, 0) << "ErrInfo: Set gid = MAX_INT,now uid=" << getuid(); + EXPECT_TRUE((rgid1 == MAX_INT) && (egid1 == MAX_INT) && (sgid1 == MAX_INT)) << "Failed in setting gid:rgid=" << + rgid1 << ",egid=" << egid1 << ",sgid=" << sgid1; +} + +static void TestSetGidAbnormal() +{ + int ret; + gid_t rgid1, egid1, sgid1, rgid, egid, sgid; + getresgid(&rgid, &egid, &sgid); + // setgid = -1 + ret = setgid(ABNORMALINT); + EXPECT_EQ(ret, -1) << "ErrInfo: Set gid=-1,now uid=" << getuid(); + getresgid(&rgid1, &egid1, &sgid1); + EXPECT_TRUE((rgid1 == rgid) && (egid1 == egid) && (sgid1 == sgid)) << "Failed in setting gid:rgid=" << rgid1 << + ",egid=" << egid1 << ",sgid=" << sgid1; + // setregid = -1 + ret = setregid(ABNORMALINT, ABNORMALINT); + EXPECT_EQ(ret, -1) << "ErrInfo: Set gid=-1,now uid=" << getuid(); + getresgid(&rgid1, &egid1, &sgid1); + EXPECT_TRUE((rgid1 == rgid) && (egid1 == egid) && (sgid1 == sgid)) << "Failed in setting gid:rgid=" << rgid1 << + ",egid=" << egid1 << ",sgid=" << sgid1; + // setresgid = -1 + ret = setresgid(ABNORMALINT, ABNORMALINT, ABNORMALINT); + EXPECT_EQ(ret, -1) << "ErrInfo: Set gid=-1,now uid=" << getuid(); + getresgid(&rgid1, &egid1, &sgid1); + EXPECT_TRUE((rgid1 == rgid) && (egid1 == egid) && (sgid1 == sgid)) << "Failed in setting gid:rgid=" << rgid1 << + ",egid=" << egid1 << ",sgid=" << sgid1; +} + +static int TestSetGroups() +{ + int ret; + int exitCode = 0; + gid_t list[SIZE255]; + for (size_t num = 0; num < SIZE253; num++) { + list[num] = num; + } + list[SIZE254] = MAX_INT; + ret = setgroups(SIZE255, list); + if (ret != 0) { + LOG("Failed in setting groups"); + exitCode = 1; + } + return exitCode; +} + +static void TsetFork(uid_t uid, gid_t gid, size_t size, const gid_t list[]) +{ + int ret; + int status = 0; + ret = setuid(uid); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting uid,now uid=" << getuid(); + ret = setgid(gid); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting gid,now uid=" << getuid(); + setgroups(0, nullptr); + ret = setgroups(size, list); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting groups,now uid=" << getuid(); + // fork + gid_t reallist[SIZE255]; + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + uid_t retuid = getuid(); + if (retuid != uid) { + LOG("ErrInfo: Failed in getting uid,uid=%d,pid=%d,ppid=%d", ret, getpid(), getppid()); + exitCode = 1; + } + gid_t retgid = getgid(); + if (retgid != gid) { + LOG("ErrInfo: Failed in getting gid,gid=%d,pid=%d,ppid=%d", ret, getpid(), getppid()); + exitCode = 1; + } + int retgroups = getgroups(0, reallist); + if (retgroups == -1) { + LOG("ErrInfo: Failed in getting groups,getroups=%d,pid=%d,ppid=%d", ret, getpid(), getppid()); + exitCode = 1; + } + exit(exitCode); + } else { + waitpid(pid, &status, 0); + usleep(SLEEP_NUM); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0010 + * @tc.name : securityDACTest0010 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(DacPreTestSuite, securityDACTest0010, TestSize.Level1) +{ + int ret; + uid_t ruid, euid, suid; + getresuid(&ruid, &euid, &suid); + TestSetUid(); + TestSetREUid(); + TestSetRESUid(); + TestSetUidAbnormal(); + // Restore the test environment + ret = setresuid(ruid, euid, suid); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting resuid,now uid=" << getuid(); +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0020 + * @tc.name : securityDACTest0020 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(DacPreTestSuite, securityDACTest0020, TestSize.Level1) +{ + int ret; + gid_t rgid, egid, sgid; + getresgid(&rgid, &egid, &sgid); + TestSetGid(); + TestSetREGid(); + TestSetRESGid(); + TestSetGidAbnormal(); + // Restore the test environment + ret = setresgid(rgid, egid, sgid); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting resgid,now uid=" << getuid(); +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0030 + * @tc.name : securityDACTest0030 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(DacPreTestSuite, securityDACTest0030, TestSize.Level1) +{ + int ret; + gid_t grouplist[SIZE255]; + int groupsize = getgroups(0, grouplist); + if (groupsize >= 0) { + getgroups(groupsize, grouplist); + } else { + EXPECT_GE(groupsize, 0) << "ErrInfo: Failed in getgroups"; + } + gid_t list1[SIZE1] = {1}; + gid_t list2[SIZE1] = {MAX_INT}; + gid_t list3[SIZE1] = {}; + // setgroups equal 1 + ret = setgroups(SIZE1, list1); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting groups,now uid=" << getuid(); + // setgroups equal MAX_INT + ret = setgroups(SIZE1, list2); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting groups,now uid=" << getuid(); + // setgroups equal NULL + ret = setgroups(SIZE1, list3); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting groups,now uid=" << getuid(); + // Restore the test environment + ret = setgroups(groupsize, grouplist); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting groups,now uid=" << getuid(); +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0040 + * @tc.name : securityDACTest0040 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(DacPreTestSuite, securityDACTest0040, TestSize.Level2) +{ + int ret; + gid_t grouplist[SIZE255]; + gid_t list1[SIZE2]={0, 0}; + gid_t list2[SIZE2]={1, 1}; + gid_t list3[SIZE2]={MAX_INT, MAX_INT}; + int groupsize = getgroups(0, grouplist); + if (groupsize >= 0) { + getgroups(groupsize, grouplist); + } else { + EXPECT_GE(groupsize, 0) << "ErrInfo: Failed in getgroups"; + } + // setgroups = 0,0 + ret = setgroups(SIZE2, list1); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting groups,now uid=" << getuid(); + // setgroups = 1,1 + ret = setgroups(SIZE2, list2); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting groups,now uid=" << getuid(); + // setgroups = MAX_INT,MAX_INT + ret = setgroups(SIZE2, list3); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting groups,now uid=" << getuid(); + // Restore the test environment + setgroups(0, nullptr); + ret = setgroups(groupsize, grouplist); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting groups,now uid=" << getuid(); +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0050 + * @tc.name : securityDACTest0050 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(DacPreTestSuite, securityDACTest0050, TestSize.Level3) +{ + int ret; + gid_t grouplist[SIZE255]; + gid_t list1[SIZE3]={GID0, GID0, MAX_INT}; + gid_t list2[SIZE3]={GID10000, GID10000, MAX_INT}; + gid_t list3[SIZE3]={GID0, MAX_INT, MAX_INT}; + int groupsize = getgroups(0, grouplist); + if (groupsize >= 0) { + getgroups(groupsize, grouplist); + } else { + EXPECT_GE(groupsize, 0) << "ErrInfo: Failed in getgroups"; + } + // setgroups = 0, 0, MAX_INT + ret = setgroups(SIZE3, list1); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting groups,now uid=" << getuid(); + // setgroups = 10000, 10000, MAX_INT + ret = setgroups(SIZE3, list2); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting groups,now uid=" << getuid(); + // setgroups = 0, MAX_INT, MAX_INT + ret = setgroups(SIZE3, list3); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting groups,now uid=" << getuid(); + + // Restore the test environment + setgroups(0, nullptr); + ret = setgroups(groupsize, grouplist); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting groups,now uid=" << getuid(); +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0060 + * @tc.name : securityDACTest0060 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(DacPreTestSuite, securityDACTest0060, TestSize.Level3) +{ + int ret; + gid_t grouplist[SIZE255]; + int groupsize = getgroups(0, grouplist); + if (groupsize >= 0) { + getgroups(groupsize, grouplist); + } else { + EXPECT_GE(groupsize, 0) << "ErrInfo: Failed in getgroups"; + } + gid_t list0[SIZE255]; + for (size_t num0 = 0; num0 < SIZE254; num0++) { + list0[num0] = num0; + } + list0[SIZE254] = MAX_INT; + ret = setgroups(SIZE255, list0); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting groups,now uid=" << getuid(); + + // Restore the test environment + setgroups(0, nullptr); + ret = setgroups(groupsize, grouplist); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting groups,now uid=" << getuid(); + + gid_t list1[INVAILD_SIZE]; + for (size_t num1 = 0; num1 < MAX_SIZE; num1++) { + list1[num1] = num1; + } + list1[MAX_SIZE] = MAX_INT; + ret = setgroups(INVAILD_SIZE, list1); + EXPECT_EQ(ret, -1) << "ErrInfo: Set groups size over 255,size=" << SIZE2; + + // Restore the test environment + setgroups(0, nullptr); + ret = setgroups(groupsize, grouplist); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting groups,now uid=" << getuid(); +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0070 + * @tc.name : securityDACTest0070 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(DacPreTestSuite, securityDACTest0070, TestSize.Level2) +{ + int ret; + int status = 0; + pid_t pid; + for (int num = 0; num < NUM3; num++) { + pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + break; + } + } + if (pid == 0) { + int exitCode = 0; + for (int number = 0; number < NUM3000; number++) { + ret = TestSetUid(); + if (ret != 0) { + LOG("Failed in TestSetUid when the %d time", number); + exitCode = 1; + break; + } + ret = TestSetGid(); + if (ret != 0) { + LOG("Failed in TestSetGid when the %d time", number); + exitCode = 1; + break; + } + ret = TestSetGroups(); + if (ret != 0) { + LOG("Failed in TestSetGroups when the %d time", number); + exitCode = 1; + break; + } + // Restore the test environment + setuid(0); + setgid(0); + setgroups(0, nullptr); + } + exit(exitCode); + } else { + while (wait(&status) > 0) { + usleep(SLEEP_NUM); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo:Pid = " << wait(&status) << + ",the WEXITSTATUS return code is " << WEXITSTATUS(status); + usleep(SLEEP_NUM); + } + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0080 + * @tc.name : securityDACTest0080 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(DacPreTestSuite, securityDACTest0080, TestSize.Level2) +{ + gid_t grouplist[SIZE255]; + int groupsize = getgroups(0, grouplist); + if (groupsize >= 0) { + getgroups(groupsize, grouplist); + } else { + EXPECT_GE(groupsize, 0) << "ErrInfo: Failed in getgroups"; + } + gid_t list1[SIZE1] = {GID10000}; + gid_t list2[SIZE1] = {}; + gid_t list3[SIZE255]; + for (size_t num = 0; num < SIZE254; num++) { + list3[num] = num; + } + list3[SIZE254] = MAX_INT; + + TsetFork(UID0, GID10000, SIZE1, list1); + TsetFork(UID10000, GID10000, SIZE1, list1); + TsetFork(MAX_INT, GID10000, SIZE1, list1); + TsetFork(UID10000, GID0, SIZE1, list1); + TsetFork(UID10000, MAX_INT, SIZE1, list1); + TsetFork(UID10000, GID10000, SIZE1, list2); + TsetFork(UID10000, GID10000, SIZE255, list3); + + usleep(SLEEP_NUM); +} \ No newline at end of file diff --git a/security_lite/permission_posix/dac/src/ActsDacTest.cpp b/security_lite/permission_posix/dac/src/ActsDacTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..bb51f5d0a7a514dc72c84f04c8820c7371cdb68a --- /dev/null +++ b/security_lite/permission_posix/dac/src/ActsDacTest.cpp @@ -0,0 +1,396 @@ +/* + * Copyright (c) 2020 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 "ActsDacTest.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "gtest/gtest.h" + +#ifdef __LINUX__ +#include +#include +#include +#else +#include +#endif + +#ifdef __LINUX__ +__BEGIN_DECLS +extern int capget(cap_user_header_t hdrp, cap_user_data_t datap); +extern int capset(cap_user_header_t hdrp, const cap_user_data_t datap); +__END_DECLS +#endif + +using namespace std; +using namespace testing::ext; + +class DacTestSuite : public testing::Test { +protected: + // SetUpTestCase:测试套预置动作,在第一个TestCase之前执行 + static void SetUpTestCase(void) + { + // uid=gid=555 + SetUid555Gid555(); + RemoveDir("/storage/DacTestSuite"); + RemoveDir("/storage/DacTestSuite1"); + // uid=gid=0 + SetUid0Gid0(); + RemoveDir("/storage/DacTestSuite"); + RemoveDir("/storage/DacTestSuite1"); + } + // TearDownTestCase:测试套清理动作,在最后一个TestCase之后执行 + static void TearDownTestCase(void) {} + // 用例的预置动作 + virtual void SetUp() + { + // uid=gid=0 + SetUid0Gid0(); + } + // 用例的清理动作 + virtual void TearDown() + { + RemoveDir("/storage/DacTestSuite"); + RemoveDir("/storage/DacTestSuite1"); + } +}; + +static void NoChownCapFunc() +{ + struct __user_cap_header_struct capheader; + struct __user_cap_data_struct capdata[CAP_NUM]; + int ret; + memset_s(&capheader, sizeof(struct __user_cap_header_struct), 0, sizeof(struct __user_cap_header_struct)); + memset_s(capdata, CAP_NUM * sizeof(struct __user_cap_data_struct), 0, + CAP_NUM * sizeof(struct __user_cap_data_struct)); + capdata[0].permitted = 0xffffffff; + capdata[1].permitted = 0xffffffff; + capheader.version = _LINUX_CAPABILITY_VERSION_3; + capdata[CAP_TO_INDEX(CAP_SETPCAP)].effective |= CAP_TO_MASK(CAP_SETPCAP); + capdata[CAP_TO_INDEX(CAP_SETUID)].effective |= CAP_TO_MASK(CAP_SETUID); + capdata[CAP_TO_INDEX(CAP_SETGID)].effective |= CAP_TO_MASK(CAP_SETGID); + capdata[CAP_TO_INDEX(CAP_CHOWN)].effective &= ~CAP_TO_MASK(CAP_CHOWN); + capdata[CAP_TO_INDEX(CAP_FOWNER)].effective &= ~CAP_TO_MASK(CAP_FOWNER); + capdata[CAP_TO_INDEX(CAP_DAC_OVERRIDE)].effective &= ~CAP_TO_MASK(CAP_DAC_OVERRIDE); + capdata[CAP_TO_INDEX(CAP_DAC_READ_SEARCH)].effective &= ~CAP_TO_MASK(CAP_DAC_READ_SEARCH); + ret = capset(&capheader, &capdata[0]); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting privileges"; +} + +static void ChownCapFunc() +{ + struct __user_cap_header_struct capheader; + struct __user_cap_data_struct capdata[CAP_NUM]; + int ret; + memset_s(&capheader, sizeof(struct __user_cap_header_struct), 0, sizeof(struct __user_cap_header_struct)); + memset_s(capdata, CAP_NUM * sizeof(struct __user_cap_data_struct), 0, + CAP_NUM * sizeof(struct __user_cap_data_struct)); + capdata[0].permitted = 0xffffffff; + capdata[1].permitted = 0xffffffff; + capheader.version = _LINUX_CAPABILITY_VERSION_3; + capdata[CAP_TO_INDEX(CAP_SETPCAP)].effective |= CAP_TO_MASK(CAP_SETPCAP); + capdata[CAP_TO_INDEX(CAP_SETUID)].effective |= CAP_TO_MASK(CAP_SETUID); + capdata[CAP_TO_INDEX(CAP_SETGID)].effective |= CAP_TO_MASK(CAP_SETGID); + capdata[CAP_TO_INDEX(CAP_CHOWN)].effective |= CAP_TO_MASK(CAP_CHOWN); + capdata[CAP_TO_INDEX(CAP_FOWNER)].effective &= ~CAP_TO_MASK(CAP_FOWNER); + capdata[CAP_TO_INDEX(CAP_DAC_OVERRIDE)].effective &= ~CAP_TO_MASK(CAP_DAC_OVERRIDE); + capdata[CAP_TO_INDEX(CAP_DAC_READ_SEARCH)].effective &= ~CAP_TO_MASK(CAP_DAC_READ_SEARCH); + ret = capset(&capheader, &capdata[0]); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting privileges"; +} + +static void CreateTxt() +{ + int ret; + int fd = 0; + char cap[] = "DacTestSuite!\n"; + // uid=gid=0 + SetUid0Gid0(); + umask(ZEROUMASK); + ret = mkdir("/storage/DacTestSuite", CHMOD700); + EXPECT_EQ(ret, 0) << "ErrInfo: Now uid=" << getuid(); + ret = mkdir("/storage/DacTestSuite/Dac", RWX); + EXPECT_EQ(ret, 0) << "ErrInfo: Now uid=" << getuid(); + fd = open("/storage/DacTestSuite/Dac.txt", O_WRONLY | O_CREAT | O_TRUNC, CHMOD700); + if (fd >= 0) { + write(fd, cap, sizeof(cap)); + close(fd); + } else { + EXPECT_GE(fd, 0) << "Creat txt error"; + } +} + +static void CreateTxt1() +{ + int ret; + int fd = 0; + char cap[] = "DacTestSuite!\n"; + // uid=gid=0 & chown cap + struct __user_cap_header_struct capheader; + struct __user_cap_data_struct capdata[CAP_NUM]; + memset_s(&capheader, sizeof(struct __user_cap_header_struct), 0, sizeof(struct __user_cap_header_struct)); + memset_s(capdata, CAP_NUM * sizeof(struct __user_cap_data_struct), 0, + CAP_NUM * sizeof(struct __user_cap_data_struct)); + capdata[0].permitted = 0xffffffff; + capdata[1].permitted = 0xffffffff; + capheader.version = _LINUX_CAPABILITY_VERSION_3; + capdata[CAP_TO_INDEX(CAP_SETPCAP)].effective |= CAP_TO_MASK(CAP_SETPCAP); + capdata[CAP_TO_INDEX(CAP_SETUID)].effective |= CAP_TO_MASK(CAP_SETUID); + capdata[CAP_TO_INDEX(CAP_SETGID)].effective |= CAP_TO_MASK(CAP_SETGID); + capdata[CAP_TO_INDEX(CAP_CHOWN)].effective |= CAP_TO_MASK(CAP_CHOWN); + ret = capset(&capheader, &capdata[0]); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting privileges"; + ret = setuid(UID0); + EXPECT_EQ(ret, 0) << "ErrInfo: Set uid failed,now uid=" << getuid(); + ret = setgid(GID0); + EXPECT_EQ(ret, 0) << "ErrInfo: Set gid failed,now gid=" << getgid(); + umask(ZEROUMASK); + ret = mkdir("/storage/DacTestSuite1", CHMOD700); + EXPECT_EQ(ret, 0) << "ErrInfo: Now uid=" << getuid(); + ret = mkdir("/storage/DacTestSuite1/Dac1", RWX); + EXPECT_EQ(ret, 0) << "ErrInfo: Now uid=" << getuid(); + fd = open("/storage/DacTestSuite1/Dac.txt", O_WRONLY | O_CREAT | O_TRUNC, CHMOD700); + if (fd >= 0) { + write(fd, cap, sizeof(cap)); + close(fd); + } else { + EXPECT_GE(fd, 0) << "Creat txt error"; + } + ret = chown("/storage/DacTestSuite1/Dac.txt", UID555, GID555); + EXPECT_EQ(ret, 0) << "ErrInfo: chown error,now uid=" << getuid(); + ret = chown("/storage/DacTestSuite1", UID555, GID555); + EXPECT_EQ(ret, 0) << "ErrInfo: chown error,now uid=" << getuid(); +} + +static void ThreeProcessReadOneTxt() +{ + int status = 0; + int fd = 0; + pid_t pid; + CreateTxt(); + for (int num = 0; num < NUM3; num++) { + pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + break; + } + } // get one parent & Three children + usleep(SLEEP_NUM); + if (pid == 0) { + SetUid0Gid0(); + int exitCode = 0; + for (int number = 0; number < NUM1000; number++) { + fd = open("/storage/DacTestSuite/Dac.txt", O_WRONLY); + if (fd >= 0) { + close(fd); + } else { + LOG("open txt error when the %d time", number); + exitCode = 1; + break; + } + } + exit(exitCode); + } else { + SetUid555Gid555(); + for (int number2 = 0; number2 < NUM500; number2++) { + fd = open("/storage/DacTestSuite/Dac.txt", O_WRONLY); + if (fd >= 0) { + EXPECT_EQ(fd, WRONGNUM) << "ErrInfo: Open txt without DAC,now uid=" << getuid() << ",No." << number2; + close(fd); + break; + } + } + while (wait(&status) > 0) { + usleep(SLEEP_NUM); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo:Pid = " << wait(&status) << + ",the WEXITSTATUS return code is " << WEXITSTATUS(status); + } + } +} + +static void TwoProcessReadTwoTxt() +{ + int status = 0; + int fd = 0; + CreateTxt(); + CreateTxt1(); + pid_t pid = fork(); + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + SetUid0Gid0(); // uid=gid=0 + for (int number = 0; number < NUM1000; number++) { + fd = open("/storage/DacTestSuite/Dac.txt", O_WRONLY); // uid=gid=0 + if (fd >= 0) { + close(fd); + } else { + LOG("open txt error when the %d time", number); + exitCode = 1; + break; + } + fd = open("/storage/DacTestSuite1/Dac.txt", O_WRONLY); // uid=gid=555 + if (fd >= 0) { + LOG("open txt with wrong uid&gid when the %d time", number); + close(fd); + exitCode = 1; + break; + } + } + exit(exitCode); + } else { + SetUid555Gid555(); // uid=gid=555 + for (int number2 = 0; number2 < NUM500; number2++) { + fd = open("/storage/DacTestSuite/Dac.txt", O_WRONLY); // uid=gid=0 + if (fd >= 0) { + EXPECT_EQ(fd, WRONGNUM) << "ErrInfo: Open txt,now uid=" << getuid() << ",No." << number2; + close(fd); + break; + } + fd = open("/storage/DacTestSuite1/Dac.txt", O_WRONLY); // uid=gid=1 + if (fd >= 0) { + close(fd); + } else { + EXPECT_EQ(fd, 0) << "ErrInfo: Failed in open txt,now uid=" << getuid() << ",No." << number2; + break; + } + } + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +static void TenProcessReadSameTxt() +{ + int ret; + int status = 0; + int fd = 0; + CreateTxt(); + pid_t pid; + for (int num = 0; num < NUM3; num++) { + pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + ret = setuid(num); + EXPECT_EQ(ret, 0) << "ErrInfo: Set uid failed,now uid=" << getuid(); + break; + } + } // get one parent & three children + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + for (int number = 0; number < NUM1000; number++) { + fd = open("/storage/DacTestSuite/Dac.txt", O_WRONLY); + if (getuid() == 0) { + if (fd >= 0) { + close(fd); + } else { + LOG("open txt error when the %d time", number); + exitCode = 1; + break; + } + } else { + if (fd >= 0) { + LOG("open txt with wrong uid&gid when the %d time", number); + close(fd); + exitCode = 1; + break; + } + } + } + exit(exitCode); + } else { + waitpid(pid, &status, 0); + usleep(SLEEP_NUM); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0140 + * @tc.name : securityDACTest0140 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(DacTestSuite, securityDACTest0140, TestSize.Level2) +{ + int ret; + int status = 0; + CreateTxt(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + NoChownCapFunc(); + // uid=gid=0 + setuid(UID0); + setgid(GID0); + ret = chmod("/storage/DacTestSuite/Dac.txt", CHMOD700); + if (ret != 0) { + LOG("Failed in chmod 700"); + exitCode = 1; + } + ret = chmod("/storage/DacTestSuite/Dac.txt", CHMOD111); + if (ret != 0) { + LOG("Failed in chmod 111"); + exitCode = 1; + } + ret = chmod("/storage/DacTestSuite/Dac.txt", -1); + if (ret != 0) { + LOG("Failed in chmod -1"); + exitCode = 1; + } + ret = chmod("/storage/DacTestSuite/Dac.txt", -777); + if (ret != 0) { + LOG("Failed in chmod -777"); + exitCode = 1; + } + // uid=gid=10000 + setuid(UID10000); + setgid(GID10000); + EXPECT_EQ(ret, 0) << "ErrInfo: Set gid failed,now gid=" << getgid(); + ret = chmod("/storage/DacTestSuite/Dac.txt", CHMOD777); + EXPECT_EQ(ret, -1) << "ErrInfo: Chmod 777 with wrong uid,now uid=" << getuid(); + // restore + setuid(UID0); + setgid(GID0); + chmod("/storage/DacTestSuite/Dac.txt", CHMOD777); + exit(exitCode); + } else { + waitpid(pid, &status, 0); + usleep(SLEEP_NUM); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} diff --git a/security_lite/permission_posix/dac/src/ActsDacTest.h b/security_lite/permission_posix/dac/src/ActsDacTest.h new file mode 100755 index 0000000000000000000000000000000000000000..6556f16b913771377bf5b9c8948a61b7642637d0 --- /dev/null +++ b/security_lite/permission_posix/dac/src/ActsDacTest.h @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2020 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 XTS_ACTS_SECURITY_LITE_PERMISSSION_POSIX_DAC_SRC_ACTSDACTEST_H +#define XTS_ACTS_SECURITY_LITE_PERMISSSION_POSIX_DAC_SRC_ACTSDACTEST_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "gtest/gtest.h" + +#ifdef __LINUX__ +#include +#include +#include +#else +#include +#endif + +#ifdef __LINUX__ +__BEGIN_DECLS +extern int capget(cap_user_header_t hdrp, cap_user_data_t datap); +extern int capset(cap_user_header_t hdrp, const cap_user_data_t datap); +__END_DECLS +#endif + +constexpr int WRONGNUM = -1; +constexpr int NUM3 = 3; +constexpr int NUM500 = 500; +constexpr int NUM1000 = 1000; +constexpr int NUM3000 = 3000; + +constexpr int ABNORMALINT = -100; +constexpr int SINGLESIZE = 1; +constexpr int CAP_NUM = 2; +constexpr int SLEEP_NUM = 500000; +constexpr unsigned int MAX_INT = 2147483647; + +constexpr size_t SIZE1 = 1; +constexpr size_t SIZE2 = 2; +constexpr size_t SIZE3 = 3; +constexpr size_t SIZE253 = 253; +constexpr size_t SIZE254 = 254; +constexpr size_t SIZE255 = 255; +constexpr size_t SIZE512 = 512; +constexpr size_t MAX_SIZE = 65536; +constexpr size_t INVAILD_SIZE = 65537; + +constexpr uid_t UID0 = 0; +constexpr uid_t UID555 = 555; +constexpr uid_t UID1000 = 1000; +constexpr uid_t UID10000 = 10000; +constexpr gid_t GID0 = 0; +constexpr gid_t GID555 = 555; +constexpr gid_t GID1000 = 1000; +constexpr gid_t GID10000 = 10000; + +constexpr mode_t ZEROUMASK = 0000; +constexpr mode_t NORWX = 0001; +constexpr mode_t RWX = 0777; +constexpr mode_t CHMOD000 = 00000; +constexpr mode_t CHMOD111 = 00111; +constexpr mode_t CHMOD700 = 00700; +constexpr mode_t CHMOD777 = 00777; + +extern "C" { +#define LOG(format, ...) fprintf(stdout, format "\n", ##__VA_ARGS__) +} + +static int RemoveDir(const char* dirname) +{ + char curDir[] = "."; + char upDir[] = ".."; + char updirname[SIZE512]; + DIR* dir = nullptr; + struct dirent* dp = nullptr; + struct stat upDirStat; + struct __user_cap_header_struct capheader; + struct __user_cap_data_struct capdata[CAP_NUM]; + memset_s(&capheader, sizeof(struct __user_cap_header_struct), 0, sizeof(struct __user_cap_header_struct)); + memset_s(capdata, CAP_NUM * sizeof(struct __user_cap_data_struct), 0, + CAP_NUM * sizeof(struct __user_cap_data_struct)); + capdata[0].permitted = 0xffffffff; + capdata[1].permitted = 0xffffffff; + capdata[0].effective = 0xffffffff; + capdata[1].effective = 0xffffffff; + capheader.version = _LINUX_CAPABILITY_VERSION_3; + capset(&capheader, &capdata[0]); + // 参数传递进来的目录不存在,直接返回 + if (access(dirname, F_OK != 0)) { + return 0; + } + dir = opendir(dirname); + while ((dp = readdir(dir)) != nullptr) { + if ((strcmp(curDir, dp->d_name) == 0) || (strcmp(upDir, dp->d_name) == 0)) { + continue; + } + int spr = sprintf_s(updirname, SIZE512, "%s/%s", dirname, dp->d_name); + if (spr == -1) { + closedir(dir); + return -1; + } + stat(updirname, &upDirStat); + if (upDirStat.st_mode & S_IFDIR) { // 目录文件,递归删除目录中内容 + RemoveDir(updirname); // 递归调用 + } else { // 普通文件直接删除 + unlink(updirname); + } + } + closedir(dir); + int ret = rmdir(dirname); // 删除空目录 + if (ret != 0) { + return -1; + } + capdata[CAP_TO_INDEX(CAP_DAC_OVERRIDE)].effective &= ~CAP_TO_MASK(CAP_DAC_OVERRIDE); + capdata[CAP_TO_INDEX(CAP_DAC_READ_SEARCH)].effective &= ~CAP_TO_MASK(CAP_DAC_READ_SEARCH); + capset(&capheader, &capdata[0]); + return 0; +} + +static void SetUid0Gid0() +{ + struct __user_cap_header_struct capheader; + struct __user_cap_data_struct capdata[CAP_NUM]; + int ret; + memset_s(&capheader, sizeof(struct __user_cap_header_struct), 0, sizeof(struct __user_cap_header_struct)); + memset_s(capdata, CAP_NUM * sizeof(struct __user_cap_data_struct), 0, + CAP_NUM * sizeof(struct __user_cap_data_struct)); + capdata[0].permitted = 0xffffffff; + capdata[1].permitted = 0xffffffff; + capheader.version = _LINUX_CAPABILITY_VERSION_3; + capdata[CAP_TO_INDEX(CAP_SETPCAP)].effective |= CAP_TO_MASK(CAP_SETPCAP); + capdata[CAP_TO_INDEX(CAP_SETUID)].effective |= CAP_TO_MASK(CAP_SETUID); + capdata[CAP_TO_INDEX(CAP_SETGID)].effective |= CAP_TO_MASK(CAP_SETGID); + ret = capset(&capheader, &capdata[0]); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting privileges"; + ret = setuid(UID0); + EXPECT_EQ(ret, 0) << "ErrInfo: Set uid failed,now uid=" << getuid(); + ret = setgid(GID0); + EXPECT_EQ(ret, 0) << "ErrInfo: Set gid failed,now gid=" << getgid(); +} + +static void SetUid555Gid555() +{ + struct __user_cap_header_struct capheader; + struct __user_cap_data_struct capdata[CAP_NUM]; + int ret; + memset_s(&capheader, sizeof(struct __user_cap_header_struct), 0, sizeof(struct __user_cap_header_struct)); + memset_s(capdata, CAP_NUM * sizeof(struct __user_cap_data_struct), 0, + CAP_NUM * sizeof(struct __user_cap_data_struct)); + capdata[0].permitted = 0xffffffff; + capdata[1].permitted = 0xffffffff; + capheader.version = _LINUX_CAPABILITY_VERSION_3; + capdata[CAP_TO_INDEX(CAP_SETPCAP)].effective |= CAP_TO_MASK(CAP_SETPCAP); + capdata[CAP_TO_INDEX(CAP_SETUID)].effective |= CAP_TO_MASK(CAP_SETUID); + capdata[CAP_TO_INDEX(CAP_SETGID)].effective |= CAP_TO_MASK(CAP_SETGID); + ret = capset(&capheader, &capdata[0]); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting privileges"; + ret = setuid(UID555); + EXPECT_EQ(ret, 0) << "ErrInfo: Set uid failed,now uid=" << getuid(); + ret = setgid(GID555); + EXPECT_EQ(ret, 0) << "ErrInfo: Set gid failed,now gid=" << getgid(); +} + +#endif \ No newline at end of file diff --git a/security_lite/permission_posix/dac/src/ActsSystemDevDacTest.cpp b/security_lite/permission_posix/dac/src/ActsSystemDevDacTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..d54e8c50944f6a941aa0fa2382ba6348c18633d1 --- /dev/null +++ b/security_lite/permission_posix/dac/src/ActsSystemDevDacTest.cpp @@ -0,0 +1,1910 @@ +/* + * Copyright (c) 2020 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 "ActsDacTest.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "gtest/gtest.h" + +#ifdef __LINUX__ +#include +#include +#include +#else +#include +#endif + +#ifdef __LINUX__ +__BEGIN_DECLS +extern int capget(cap_user_header_t hdrp, cap_user_data_t datap); +extern int capset(cap_user_header_t hdrp, const cap_user_data_t datap); +__END_DECLS +#endif + +using namespace std; +using namespace testing::ext; + +class SystemDevDacTestSuite : public testing::Test { +protected: + // SetUpTestCase:测试套预置动作,在第一个TestCase之前执行 + static void SetUpTestCase(void) + { + setuid(UID0); + setgid(GID0); + RemoveDir("/dev/SystemDevDacTestSuite"); + } + // TearDownTestCase:测试套清理动作,在最后一个TestCase之后执行 + static void TearDownTestCase(void) {} + // 用例的预置动作 + virtual void SetUp() + { + setuid(UID0); + setgid(GID0); + } + // 用例的清理动作 + virtual void TearDown() + { + RemoveDir("/dev/SystemDevDacTestSuite"); + } +}; + +static void ChildFuncNoCap() +{ + struct __user_cap_header_struct capheader; + struct __user_cap_data_struct capdata[CAP_NUM]; + int ret; + memset_s(&capheader, sizeof(struct __user_cap_header_struct), 0, sizeof(struct __user_cap_header_struct)); + memset_s(capdata, CAP_NUM * sizeof(struct __user_cap_data_struct), 0, + CAP_NUM * sizeof(struct __user_cap_data_struct)); + capdata[0].permitted = 0xffffffff; + capdata[1].permitted = 0xffffffff; + capheader.version = _LINUX_CAPABILITY_VERSION_3; + capdata[CAP_TO_INDEX(CAP_SETPCAP)].effective |= CAP_TO_MASK(CAP_SETPCAP); + capdata[CAP_TO_INDEX(CAP_SETUID)].effective |= CAP_TO_MASK(CAP_SETUID); + capdata[CAP_TO_INDEX(CAP_SETGID)].effective |= CAP_TO_MASK(CAP_SETGID); + capdata[CAP_TO_INDEX(CAP_CHOWN)].effective &= ~CAP_TO_MASK(CAP_CHOWN); + capdata[CAP_TO_INDEX(CAP_FOWNER)].effective &= ~CAP_TO_MASK(CAP_FOWNER); + capdata[CAP_TO_INDEX(CAP_DAC_OVERRIDE)].effective &= ~CAP_TO_MASK(CAP_DAC_OVERRIDE); + capdata[CAP_TO_INDEX(CAP_DAC_READ_SEARCH)].effective &= ~CAP_TO_MASK(CAP_DAC_READ_SEARCH); + ret = capset(&capheader, &capdata[0]); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting privileges"; +} + +static void ChildFuncOverrideCap() +{ + struct __user_cap_header_struct capheader; + struct __user_cap_data_struct capdata[CAP_NUM]; + int ret; + memset_s(&capheader, sizeof(struct __user_cap_header_struct), 0, sizeof(struct __user_cap_header_struct)); + memset_s(capdata, CAP_NUM * sizeof(struct __user_cap_data_struct), 0, + CAP_NUM * sizeof(struct __user_cap_data_struct)); + capdata[0].permitted = 0xffffffff; + capdata[1].permitted = 0xffffffff; + capheader.version = _LINUX_CAPABILITY_VERSION_3; + capdata[CAP_TO_INDEX(CAP_SETPCAP)].effective |= CAP_TO_MASK(CAP_SETPCAP); + capdata[CAP_TO_INDEX(CAP_SETUID)].effective |= CAP_TO_MASK(CAP_SETUID); + capdata[CAP_TO_INDEX(CAP_SETGID)].effective |= CAP_TO_MASK(CAP_SETGID); + capdata[CAP_TO_INDEX(CAP_CHOWN)].effective &= ~CAP_TO_MASK(CAP_CHOWN); + capdata[CAP_TO_INDEX(CAP_FOWNER)].effective &= ~CAP_TO_MASK(CAP_FOWNER); + capdata[CAP_TO_INDEX(CAP_DAC_OVERRIDE)].effective |= CAP_TO_MASK(CAP_DAC_OVERRIDE); + capdata[CAP_TO_INDEX(CAP_DAC_READ_SEARCH)].effective &= ~CAP_TO_MASK(CAP_DAC_READ_SEARCH); + ret = capset(&capheader, &capdata[0]); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting privileges"; +} + +static void ChildFuncReadsearchCap() +{ + struct __user_cap_header_struct capheader; + struct __user_cap_data_struct capdata[CAP_NUM]; + int ret; + memset_s(&capheader, sizeof(struct __user_cap_header_struct), 0, sizeof(struct __user_cap_header_struct)); + memset_s(capdata, CAP_NUM * sizeof(struct __user_cap_data_struct), 0, + CAP_NUM * sizeof(struct __user_cap_data_struct)); + capdata[0].permitted = 0xffffffff; + capdata[1].permitted = 0xffffffff; + capheader.version = _LINUX_CAPABILITY_VERSION_3; + capdata[CAP_TO_INDEX(CAP_SETPCAP)].effective |= CAP_TO_MASK(CAP_SETPCAP); + capdata[CAP_TO_INDEX(CAP_SETUID)].effective |= CAP_TO_MASK(CAP_SETUID); + capdata[CAP_TO_INDEX(CAP_SETGID)].effective |= CAP_TO_MASK(CAP_SETGID); + capdata[CAP_TO_INDEX(CAP_CHOWN)].effective &= ~CAP_TO_MASK(CAP_CHOWN); + capdata[CAP_TO_INDEX(CAP_FOWNER)].effective &= ~CAP_TO_MASK(CAP_FOWNER); + capdata[CAP_TO_INDEX(CAP_DAC_OVERRIDE)].effective &= ~CAP_TO_MASK(CAP_DAC_OVERRIDE); + capdata[CAP_TO_INDEX(CAP_DAC_READ_SEARCH)].effective |= CAP_TO_MASK(CAP_DAC_READ_SEARCH); + ret = capset(&capheader, &capdata[0]); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting privileges"; +} + +static void ChildFuncBothCap() +{ + struct __user_cap_header_struct capheader; + struct __user_cap_data_struct capdata[CAP_NUM]; + int ret; + memset_s(&capheader, sizeof(struct __user_cap_header_struct), 0, sizeof(struct __user_cap_header_struct)); + memset_s(capdata, CAP_NUM * sizeof(struct __user_cap_data_struct), 0, + CAP_NUM * sizeof(struct __user_cap_data_struct)); + capdata[0].permitted = 0xffffffff; + capdata[1].permitted = 0xffffffff; + capheader.version = _LINUX_CAPABILITY_VERSION_3; + capdata[CAP_TO_INDEX(CAP_SETPCAP)].effective |= CAP_TO_MASK(CAP_SETPCAP); + capdata[CAP_TO_INDEX(CAP_SETUID)].effective |= CAP_TO_MASK(CAP_SETUID); + capdata[CAP_TO_INDEX(CAP_SETGID)].effective |= CAP_TO_MASK(CAP_SETGID); + capdata[CAP_TO_INDEX(CAP_CHOWN)].effective &= ~CAP_TO_MASK(CAP_CHOWN); + capdata[CAP_TO_INDEX(CAP_FOWNER)].effective &= ~CAP_TO_MASK(CAP_FOWNER); + capdata[CAP_TO_INDEX(CAP_DAC_OVERRIDE)].effective |= CAP_TO_MASK(CAP_DAC_OVERRIDE); + capdata[CAP_TO_INDEX(CAP_DAC_READ_SEARCH)].effective |= CAP_TO_MASK(CAP_DAC_READ_SEARCH); + ret = capset(&capheader, &capdata[0]); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting privileges"; +} + +static void CreateDevDir() +{ + int ret; + setuid(UID0); + setgid(GID0); + umask(ZEROUMASK); + ret = mkdir("/dev/SystemDevDacTestSuite", CHMOD777); + EXPECT_EQ(ret, 0) << "ErrInfo: Now uid=" << getuid(); + ret = mkdir("/dev/SystemDevDacTestSuite/mkdir", CHMOD777); + EXPECT_EQ(ret, 0) << "ErrInfo: Now uid=" << getuid(); +} + +static void CreateDevTxt() +{ + int ret; + int fd = 0; + setuid(UID0); + setgid(GID0); + umask(ZEROUMASK); + ret = mkdir("/dev/SystemDevDacTestSuite", CHMOD777); + EXPECT_EQ(ret, 0) << "ErrInfo: Now uid=" << getuid(); + fd = open("/dev/SystemDevDacTestSuite/Dac.txt", O_WRONLY | O_CREAT | O_TRUNC, CHMOD777); + // dev/ not allow creat folders + if (fd >= 0) { + EXPECT_EQ(fd, WRONGNUM) << "Creat txt /dev"; + close(fd); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0290 + * @tc.name : securityDACTest0290 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0290, TestSize.Level2) +{ + int ret; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite", 0333); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 333,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID0); + setgid(GID555); + ret = rmdir("/dev/SystemDevDacTestSuite/mkdir"); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0300 + * @tc.name : securityDACTest0300 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0300, TestSize.Level2) +{ + int ret; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite", 0611); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 611,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID555); + setgid(GID0); + ret = rmdir("/dev/SystemDevDacTestSuite/mkdir"); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0310 + * @tc.name : securityDACTest0310 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0310, TestSize.Level2) +{ + int ret; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite", 0105); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 105,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID555); + setgid(GID555); + ret = rmdir("/dev/SystemDevDacTestSuite/mkdir"); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0320 + * @tc.name : securityDACTest0320 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0320, TestSize.Level2) +{ + int ret; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite", 0555); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 555,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID555); + setgid(GID555); + ret = rmdir("/dev/SystemDevDacTestSuite/mkdir"); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0330 + * @tc.name : securityDACTest0330 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0330, TestSize.Level2) +{ + int ret; + gid_t list[SINGLESIZE] = {0}; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite", 0666); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 666,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncNoCap(); + setuid(UID555); + setgid(GID555); + setgroups(SINGLESIZE, list); + ret = rmdir("/dev/SystemDevDacTestSuite/mkdir"); + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + chmod("/dev/SystemDevDacTestSuite", 0777); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0340 + * @tc.name : securityDACTest0340 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0340, TestSize.Level2) +{ + int ret; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite", 0777); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 777,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncNoCap(); + setuid(UID0); + setgid(GID555); + ret = rmdir("/dev/SystemDevDacTestSuite/mkdir"); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0350 + * @tc.name : securityDACTest0350 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0350, TestSize.Level2) +{ + int ret; + struct stat buf = { 0 }; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite", 0166); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 166,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID555); + setgid(GID0); + ret = stat("/dev/SystemDevDacTestSuite/mkdir", &buf); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0360 + * @tc.name : securityDACTest0360 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0360, TestSize.Level2) +{ + int ret; + struct stat buf = { 0 }; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite", 0111); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 111,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID0); + setgid(GID0); + ret = stat("/dev/SystemDevDacTestSuite/mkdir", &buf); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0370 + * @tc.name : securityDACTest0370 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0370, TestSize.Level2) +{ + int ret; + struct stat buf = { 0 }; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite", 0210); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 210,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID0); + setgid(GID0); + ret = stat("/dev/SystemDevDacTestSuite/mkdir", &buf); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0380 + * @tc.name : securityDACTest0380 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0380, TestSize.Level2) +{ + int ret; + struct stat buf = { 0 }; + gid_t list[SINGLESIZE] = {0}; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite", 0655); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 655,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID555); + setgid(GID555); + setgroups(SINGLESIZE, list); + ret = stat("/dev/SystemDevDacTestSuite/mkdir", &buf); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0390 + * @tc.name : securityDACTest0390 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0390, TestSize.Level2) +{ + int ret; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite", 0570); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 570,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncReadsearchCap(); + setuid(UID555); + setgid(GID0); + ret = rename("/dev/SystemDevDacTestSuite/mkdir", "/dev/SystemDevDacTestSuite/mkdir_bak"); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0400 + * @tc.name : securityDACTest0400 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0400, TestSize.Level2) +{ + int ret; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite", 0306); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 306,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID555); + setgid(GID0); + ret = rename("/dev/SystemDevDacTestSuite/mkdir", "/dev/SystemDevDacTestSuite/mkdir_bak"); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0410 + * @tc.name : securityDACTest0410 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0410, TestSize.Level2) +{ + int ret; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite", 0027); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 027,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID555); + setgid(GID555); + ret = rename("/dev/SystemDevDacTestSuite/mkdir", "/dev/SystemDevDacTestSuite/mkdir_bak"); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0420 + * @tc.name : securityDACTest0420 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0420, TestSize.Level2) +{ + int ret; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite", 0401); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 401,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncReadsearchCap(); + setuid(UID0); + setgid(GID555); + ret = chdir("/dev/SystemDevDacTestSuite/mkdir"); + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0430 + * @tc.name : securityDACTest0430 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0430, TestSize.Level2) +{ + int ret; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite", 0507); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 507,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID0); + setgid(GID555); + ret = chdir("/dev/SystemDevDacTestSuite/mkdir"); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0440 + * @tc.name : securityDACTest0440 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0440, TestSize.Level2) +{ + int ret; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite", 0347); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 347,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID0); + setgid(GID0); + ret = chdir("/dev/SystemDevDacTestSuite/mkdir"); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0450 + * @tc.name : securityDACTest0450 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0450, TestSize.Level2) +{ + int ret; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite", 0063); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 063,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID555); + setgid(GID555); + ret = chdir("/dev/SystemDevDacTestSuite/mkdir"); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0460 + * @tc.name : securityDACTest0460 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0460, TestSize.Level2) +{ + int ret; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite", 0230); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 230,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID555); + setgid(GID555); + ret = chdir("/dev/SystemDevDacTestSuite/mkdir"); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0470 + * @tc.name : securityDACTest0470 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0470, TestSize.Level2) +{ + int ret; + gid_t list[SINGLESIZE] = {0}; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite", 0724); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 724,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID555); + setgid(GID555); + setgroups(SINGLESIZE, list); + ret = chdir("/dev/SystemDevDacTestSuite/mkdir"); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + chdir("/storage"); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0480 + * @tc.name : securityDACTest0480 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0480, TestSize.Level2) +{ + int ret; + char *argv[] = {nullptr, nullptr}; + char *envp[] = {nullptr}; + CreateDevTxt(); + ret = chmod("/dev/SystemDevDacTestSuite", 0702); + // dev/shm can not change chmod + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod ,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID555); + setgid(GID0); + ret = execve("/dev/SystemDevDacTestSuite/Dac.txt", argv, envp); + // the file is not elf , can not exec + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0490 + * @tc.name : securityDACTest0490 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0490, TestSize.Level2) +{ + int ret; + char *argv[] = {nullptr, nullptr}; + char *envp[] = {nullptr}; + CreateDevTxt(); + ret = chmod("/dev/SystemDevDacTestSuite", 0473); + // dev/shm can not change chmod + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod ,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID0); + setgid(GID0); + ret = execve("/dev/SystemDevDacTestSuite/Dac.txt", argv, envp); + // the file is not elf , can not exec + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0500 + * @tc.name : securityDACTest0500 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0500, TestSize.Level2) +{ + int ret; + char *argv[] = {nullptr, nullptr}; + char *envp[] = {nullptr}; + CreateDevTxt(); + ret = chmod("/dev/SystemDevDacTestSuite", 0261); + // dev/shm can not change chmod + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod ,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID555); + setgid(GID555); + ret = execve("/dev/SystemDevDacTestSuite/Dac.txt", argv, envp); + // the file is not elf , can not exec + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0510 + * @tc.name : securityDACTest0510 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0510, TestSize.Level2) +{ + int ret; + CreateDevTxt(); + ret = chmod("/dev/SystemDevDacTestSuite", 0460); + // dev/shm can not change chmod + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod ,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID0); + setgid(GID555); + ret = access("/dev/SystemDevDacTestSuite/Dac.txt", F_OK); + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0520 + * @tc.name : securityDACTest0520 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0520, TestSize.Level2) +{ + int ret; + CreateDevTxt(); + ret = chmod("/dev/SystemDevDacTestSuite", 0562); + // dev/shm can not change chmod + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod ,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID0); + setgid(GID555); + ret = access("/dev/SystemDevDacTestSuite/Dac.txt", F_OK); + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0530 + * @tc.name : securityDACTest0530 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0530, TestSize.Level2) +{ + int ret; + CreateDevTxt(); + ret = chmod("/dev/SystemDevDacTestSuite", 0076); + // dev/shm can not change chmod + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod ,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID0); + setgid(GID0); + ret = access("/dev/SystemDevDacTestSuite/Dac.txt", F_OK); + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0540 + * @tc.name : securityDACTest0540 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0540, TestSize.Level2) +{ + int ret; + gid_t list[SINGLESIZE] = {0}; + CreateDevTxt(); + ret = chmod("/dev/SystemDevDacTestSuite", 0076); + // dev/shm can not change chmod + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod ,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID555); + setgid(GID555); + setgroups(SINGLESIZE, list); + ret = access("/dev/SystemDevDacTestSuite/Dac.txt", F_OK); + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0550 + * @tc.name : securityDACTest0550 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0550, TestSize.Level2) +{ + int ret; + gid_t list[SINGLESIZE] = {0}; + CreateDevTxt(); + ret = chmod("/dev/SystemDevDacTestSuite", 0132); + // dev/shm can not change chmod + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod ,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID555); + setgid(GID555); + setgroups(SINGLESIZE, list); + ret = access("/dev/SystemDevDacTestSuite/Dac.txt", F_OK); + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0560 + * @tc.name : securityDACTest0560 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0560, TestSize.Level2) +{ + int ret; + gid_t list[SINGLESIZE] = {0}; + CreateDevTxt(); + ret = chmod("/dev/SystemDevDacTestSuite", 0241); + // dev/shm can not change chmod + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod ,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID555); + setgid(GID555); + setgroups(SINGLESIZE, list); + ret = access("/dev/SystemDevDacTestSuite/Dac.txt", F_OK); + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0570 + * @tc.name : securityDACTest0570 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0570, TestSize.Level2) +{ + int ret; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite/mkdir", 0456); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 456,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID0); + setgid(GID555); + ret = mkdir("/dev/SystemDevDacTestSuite/mkdir/Dac", NORWX); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0580 + * @tc.name : securityDACTest0580 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0580, TestSize.Level2) +{ + int ret; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite/mkdir", 0167); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 167,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID555); + setgid(GID0); + ret = mkdir("/dev/SystemDevDacTestSuite/mkdir/Dac", NORWX); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0590 + * @tc.name : securityDACTest0590 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0590, TestSize.Level2) +{ + int ret; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite/mkdir", 0511); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 511,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID555); + setgid(GID555); + ret = mkdir("/dev/SystemDevDacTestSuite/mkdir/Dac", NORWX); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0600 + * @tc.name : securityDACTest0600 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0600, TestSize.Level2) +{ + int ret; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite/mkdir", 0640); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 640,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID555); + setgid(GID555); + ret = mkdir("/dev/SystemDevDacTestSuite/mkdir/Dac", NORWX); + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0610 + * @tc.name : securityDACTest0610 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0610, TestSize.Level2) +{ + int ret; + CreateDevTxt(); + ret = chmod("/dev/SystemDevDacTestSuite", 0362); + // dev/shm can not change chmod + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod ,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID0); + setgid(GID555); + ret = unlink("/dev/SystemDevDacTestSuite/Dac.txt"); + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0620 + * @tc.name : securityDACTest0620 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0620, TestSize.Level2) +{ + int ret; + CreateDevTxt(); + ret = chmod("/dev/SystemDevDacTestSuite", 0526); + // dev/shm can not change chmod + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod ,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID0); + setgid(GID555); + ret = unlink("/dev/SystemDevDacTestSuite/Dac.txt"); + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0630 + * @tc.name : securityDACTest0630 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0630, TestSize.Level2) +{ + int ret; + CreateDevTxt(); + ret = chmod("/dev/SystemDevDacTestSuite", 0604); + // dev/shm can not change chmod + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod ,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID0); + setgid(GID0); + ret = unlink("/dev/SystemDevDacTestSuite/Dac.txt"); + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0640 + * @tc.name : securityDACTest0640 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0640, TestSize.Level2) +{ + int ret; + CreateDevTxt(); + ret = chmod("/dev/SystemDevDacTestSuite", 0671); + // dev/shm can not change chmod + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod ,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID0); + setgid(GID0); + ret = unlink("/dev/SystemDevDacTestSuite/Dac.txt"); + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0650 + * @tc.name : securityDACTest0650 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0650, TestSize.Level2) +{ + int ret; + CreateDevTxt(); + ret = chmod("/dev/SystemDevDacTestSuite", 0743); + // dev/shm can not change chmod + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod ,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID0); + setgid(GID0); + ret = unlink("/dev/SystemDevDacTestSuite/Dac.txt"); + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0660 + * @tc.name : securityDACTest0660 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0660, TestSize.Level2) +{ + int ret; + gid_t list[SINGLESIZE] = {0}; + CreateDevTxt(); + ret = chmod("/dev/SystemDevDacTestSuite", 0235); + // dev/shm can not change chmod + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod ,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID555); + setgid(GID555); + setgroups(SINGLESIZE, list); + ret = unlink("/dev/SystemDevDacTestSuite/Dac.txt"); + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0670 + * @tc.name : securityDACTest0670 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0670, TestSize.Level2) +{ + int ret; + int fd = 0; + CreateDevTxt(); + ret = chmod("/dev/SystemDevDacTestSuite", 0371); + // dev/shm can not change chmod + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod ,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID555); + setgid(GID0); + fd = open("/dev/SystemDevDacTestSuite/Dac.txt", O_WRONLY); + if (fd >= 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + close(fd); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0680 + * @tc.name : securityDACTest0680 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0680, TestSize.Level2) +{ + int ret; + int fd = 0; + CreateDevTxt(); + ret = chmod("/dev/SystemDevDacTestSuite", 0702); + // dev/shm can not change chmod + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod ,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID555); + setgid(GID0); + fd = open("/dev/SystemDevDacTestSuite/Dac.txt", O_WRONLY); + if (fd >= 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + close(fd); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0690 + * @tc.name : securityDACTest0690 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0690, TestSize.Level2) +{ + int ret; + int fd = 0; + CreateDevTxt(); + ret = chmod("/dev/SystemDevDacTestSuite", 0406); + // dev/shm can not change chmod + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod ,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID555); + setgid(GID555); + fd = open("/dev/SystemDevDacTestSuite/Dac.txt", O_WRONLY); + if (fd >= 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + close(fd); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0700 + * @tc.name : securityDACTest0700 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0700, TestSize.Level2) +{ + int ret; + int fd = 0; + gid_t list[SINGLESIZE] = {0}; + CreateDevTxt(); + ret = chmod("/dev/SystemDevDacTestSuite", 0257); + // dev/shm can not change chmod + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod ,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID555); + setgid(GID555); + setgroups(SINGLESIZE, list); + fd = open("/dev/SystemDevDacTestSuite/Dac.txt", O_WRONLY); + if (fd >= 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + close(fd); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0710 + * @tc.name : securityDACTest0710 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0710, TestSize.Level2) +{ + int ret; + DIR* dir = nullptr; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite/mkdir", 0750); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 750,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID0); + setgid(GID555); + dir = opendir("/dev/SystemDevDacTestSuite/mkdir"); + if (dir == nullptr) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + closedir(dir); + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0720 + * @tc.name : securityDACTest0720 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0720, TestSize.Level2) +{ + int ret; + DIR* dir = nullptr; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite/mkdir", 0143); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 143,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID0); + setgid(GID0); + dir = opendir("/dev/SystemDevDacTestSuite/mkdir"); + if (dir == nullptr) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + closedir(dir); + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0730 + * @tc.name : securityDACTest0730 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0730, TestSize.Level2) +{ + int ret; + DIR* dir = nullptr; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite/mkdir", 0521); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 521,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID555); + setgid(GID555); + dir = opendir("/dev/SystemDevDacTestSuite/mkdir"); + if (dir == nullptr) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + closedir(dir); + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0740 + * @tc.name : securityDACTest0740 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0740, TestSize.Level2) +{ + int ret; + DIR* dir = nullptr; + gid_t list[SINGLESIZE] = {0}; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite/mkdir", 0016); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 016,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID555); + setgid(GID555); + setgroups(SINGLESIZE, list); + dir = opendir("/dev/SystemDevDacTestSuite/mkdir"); + if (dir == nullptr) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + closedir(dir); + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0750 + * @tc.name : securityDACTest0750 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemDevDacTestSuite, securityDACTest0750, TestSize.Level2) +{ + int ret; + DIR* dir = nullptr; + gid_t list[SINGLESIZE] = {0}; + CreateDevDir(); + ret = chmod("/dev/SystemDevDacTestSuite/mkdir", 0407); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 407,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID555); + setgid(GID555); + setgroups(SINGLESIZE, list); + dir = opendir("/dev/SystemDevDacTestSuite/mkdir"); + if (dir == nullptr) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + closedir(dir); + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} \ No newline at end of file diff --git a/security_lite/permission_posix/dac/src/ActsSystemJffsDacTest.cpp b/security_lite/permission_posix/dac/src/ActsSystemJffsDacTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..8761b604baf3cfb07522503c1fcaa8602cc58f90 --- /dev/null +++ b/security_lite/permission_posix/dac/src/ActsSystemJffsDacTest.cpp @@ -0,0 +1,1192 @@ +/* + * Copyright (c) 2020 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 "ActsDacTest.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "gtest/gtest.h" + +#ifdef __LINUX__ +#include +#include +#include +#else +#include +#endif + +#ifdef __LINUX__ +__BEGIN_DECLS +extern int capget(cap_user_header_t hdrp, cap_user_data_t datap); +extern int capset(cap_user_header_t hdrp, const cap_user_data_t datap); +__END_DECLS +#endif + +using namespace std; +using namespace testing::ext; + +class SystemJffsDacTestSuite : public testing::Test { +protected: + // SetUpTestCase:测试套预置动作,在第一个TestCase之前执行 + static void SetUpTestCase(void) + { + setuid(UID0); + setgid(GID0); + RemoveDir("/storage/SystemJffsDacTestSuite"); + } + // TearDownTestCase:测试套清理动作,在最后一个TestCase之后执行 + static void TearDownTestCase(void) {} + // 用例的预置动作 + virtual void SetUp() + { + setuid(UID0); + setgid(GID0); + } + // 用例的清理动作 + virtual void TearDown() + { + RemoveDir("/storage/SystemJffsDacTestSuite"); + } +}; + +static void ChildFuncNoCap() +{ + struct __user_cap_header_struct capheader; + struct __user_cap_data_struct capdata[CAP_NUM]; + int ret; + memset_s(&capheader, sizeof(struct __user_cap_header_struct), 0, sizeof(struct __user_cap_header_struct)); + memset_s(capdata, CAP_NUM * sizeof(struct __user_cap_data_struct), 0, + CAP_NUM * sizeof(struct __user_cap_data_struct)); + capdata[0].permitted = 0xffffffff; + capdata[1].permitted = 0xffffffff; + capheader.version = _LINUX_CAPABILITY_VERSION_3; + capdata[CAP_TO_INDEX(CAP_SETPCAP)].effective |= CAP_TO_MASK(CAP_SETPCAP); + capdata[CAP_TO_INDEX(CAP_SETUID)].effective |= CAP_TO_MASK(CAP_SETUID); + capdata[CAP_TO_INDEX(CAP_SETGID)].effective |= CAP_TO_MASK(CAP_SETGID); + capdata[CAP_TO_INDEX(CAP_CHOWN)].effective &= ~CAP_TO_MASK(CAP_CHOWN); + capdata[CAP_TO_INDEX(CAP_FOWNER)].effective &= ~CAP_TO_MASK(CAP_FOWNER); + capdata[CAP_TO_INDEX(CAP_DAC_OVERRIDE)].effective &= ~CAP_TO_MASK(CAP_DAC_OVERRIDE); + capdata[CAP_TO_INDEX(CAP_DAC_READ_SEARCH)].effective &= ~CAP_TO_MASK(CAP_DAC_READ_SEARCH); + ret = capset(&capheader, &capdata[0]); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting privileges"; +} + +static void ChildFuncOverrideCap() +{ + struct __user_cap_header_struct capheader; + struct __user_cap_data_struct capdata[CAP_NUM]; + int ret; + memset_s(&capheader, sizeof(struct __user_cap_header_struct), 0, sizeof(struct __user_cap_header_struct)); + memset_s(capdata, CAP_NUM * sizeof(struct __user_cap_data_struct), 0, + CAP_NUM * sizeof(struct __user_cap_data_struct)); + capdata[0].permitted = 0xffffffff; + capdata[1].permitted = 0xffffffff; + capheader.version = _LINUX_CAPABILITY_VERSION_3; + capdata[CAP_TO_INDEX(CAP_SETPCAP)].effective |= CAP_TO_MASK(CAP_SETPCAP); + capdata[CAP_TO_INDEX(CAP_SETUID)].effective |= CAP_TO_MASK(CAP_SETUID); + capdata[CAP_TO_INDEX(CAP_SETGID)].effective |= CAP_TO_MASK(CAP_SETGID); + capdata[CAP_TO_INDEX(CAP_CHOWN)].effective &= ~CAP_TO_MASK(CAP_CHOWN); + capdata[CAP_TO_INDEX(CAP_FOWNER)].effective &= ~CAP_TO_MASK(CAP_FOWNER); + capdata[CAP_TO_INDEX(CAP_DAC_OVERRIDE)].effective |= CAP_TO_MASK(CAP_DAC_OVERRIDE); + capdata[CAP_TO_INDEX(CAP_DAC_READ_SEARCH)].effective &= ~CAP_TO_MASK(CAP_DAC_READ_SEARCH); + ret = capset(&capheader, &capdata[0]); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting privileges"; +} + +static void ChildFuncReadsearchCap() +{ + struct __user_cap_header_struct capheader; + struct __user_cap_data_struct capdata[CAP_NUM]; + int ret; + memset_s(&capheader, sizeof(struct __user_cap_header_struct), 0, sizeof(struct __user_cap_header_struct)); + memset_s(capdata, CAP_NUM * sizeof(struct __user_cap_data_struct), 0, + CAP_NUM * sizeof(struct __user_cap_data_struct)); + capdata[0].permitted = 0xffffffff; + capdata[1].permitted = 0xffffffff; + capheader.version = _LINUX_CAPABILITY_VERSION_3; + capdata[CAP_TO_INDEX(CAP_SETPCAP)].effective |= CAP_TO_MASK(CAP_SETPCAP); + capdata[CAP_TO_INDEX(CAP_SETUID)].effective |= CAP_TO_MASK(CAP_SETUID); + capdata[CAP_TO_INDEX(CAP_SETGID)].effective |= CAP_TO_MASK(CAP_SETGID); + capdata[CAP_TO_INDEX(CAP_CHOWN)].effective &= ~CAP_TO_MASK(CAP_CHOWN); + capdata[CAP_TO_INDEX(CAP_FOWNER)].effective &= ~CAP_TO_MASK(CAP_FOWNER); + capdata[CAP_TO_INDEX(CAP_DAC_OVERRIDE)].effective &= ~CAP_TO_MASK(CAP_DAC_OVERRIDE); + capdata[CAP_TO_INDEX(CAP_DAC_READ_SEARCH)].effective |= CAP_TO_MASK(CAP_DAC_READ_SEARCH); + ret = capset(&capheader, &capdata[0]); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting privileges"; +} + +static void ChildFuncBothCap() +{ + struct __user_cap_header_struct capheader; + struct __user_cap_data_struct capdata[CAP_NUM]; + int ret; + memset_s(&capheader, sizeof(struct __user_cap_header_struct), 0, sizeof(struct __user_cap_header_struct)); + memset_s(capdata, CAP_NUM * sizeof(struct __user_cap_data_struct), 0, + CAP_NUM * sizeof(struct __user_cap_data_struct)); + capdata[0].permitted = 0xffffffff; + capdata[1].permitted = 0xffffffff; + capheader.version = _LINUX_CAPABILITY_VERSION_3; + capdata[CAP_TO_INDEX(CAP_SETPCAP)].effective |= CAP_TO_MASK(CAP_SETPCAP); + capdata[CAP_TO_INDEX(CAP_SETUID)].effective |= CAP_TO_MASK(CAP_SETUID); + capdata[CAP_TO_INDEX(CAP_SETGID)].effective |= CAP_TO_MASK(CAP_SETGID); + capdata[CAP_TO_INDEX(CAP_CHOWN)].effective &= ~CAP_TO_MASK(CAP_CHOWN); + capdata[CAP_TO_INDEX(CAP_FOWNER)].effective &= ~CAP_TO_MASK(CAP_FOWNER); + capdata[CAP_TO_INDEX(CAP_DAC_OVERRIDE)].effective |= CAP_TO_MASK(CAP_DAC_OVERRIDE); + capdata[CAP_TO_INDEX(CAP_DAC_READ_SEARCH)].effective |= CAP_TO_MASK(CAP_DAC_READ_SEARCH); + ret = capset(&capheader, &capdata[0]); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in setting privileges"; +} + +static void CreateDir() +{ + int ret; + // uid=gid=0 + setuid(UID0); + setgid(GID0); + umask(ZEROUMASK); + ret = mkdir("/storage/SystemJffsDacTestSuite", CHMOD777); + EXPECT_EQ(ret, 0) << "ErrInfo: Now uid=" << getuid(); + ret = mkdir("/storage/SystemJffsDacTestSuite/mkdir", CHMOD777); + EXPECT_EQ(ret, 0) << "ErrInfo: Now uid=" << getuid(); +} + +static void CreateTxt() +{ + int ret; + int fd = 0; + char cap[] = "SystemJffsDacTestSuite!\n"; + // uid=gid=0 + setuid(UID0); + setgid(GID0); + umask(ZEROUMASK); + ret = mkdir("/storage/SystemJffsDacTestSuite", CHMOD777); + EXPECT_EQ(ret, 0) << "ErrInfo: Now uid=" << getuid(); + fd = open("/storage/SystemJffsDacTestSuite/Dac.txt", O_WRONLY | O_CREAT | O_TRUNC, CHMOD777); + if (fd >= 0) { + write(fd, cap, sizeof(cap)); + close(fd); + } else { + EXPECT_GE(fd, 0) << "Creat txt error"; + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0820 + * @tc.name : securityDACTest0820 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest0820, TestSize.Level2) +{ + int ret; + struct stat buf = { 0 }; + CreateTxt(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0000); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 000,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncOverrideCap(); + setuid(UID0); + setgid(GID0); + ret = stat("/storage/SystemJffsDacTestSuite/Dac.txt", &buf); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0840 + * @tc.name : securityDACTest0840 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest0840, TestSize.Level2) +{ + int ret; + struct stat buf = { 0 }; + CreateTxt(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0334); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 334,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncReadsearchCap(); + setuid(UID555); + setgid(GID555); + ret = stat("/storage/SystemJffsDacTestSuite/Dac.txt", &buf); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0850 + * @tc.name : securityDACTest0850 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest0850, TestSize.Level2) +{ + int ret; + struct stat buf = { 0 }; + gid_t list[SINGLESIZE] = {0}; + CreateTxt(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0334); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 334,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID555); + setgid(GID555); + setgroups(SINGLESIZE, list); + ret = stat("/storage/SystemJffsDacTestSuite/Dac.txt", &buf); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0860 + * @tc.name : securityDACTest0860 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest0860, TestSize.Level2) +{ + int ret; + CreateTxt(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0614); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 614,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID0); + setgid(GID555); + ret = rename("/storage/SystemJffsDacTestSuite/Dac.txt", "/storage/SystemJffsDacTestSuite/Dac_bak.txt"); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0890 + * @tc.name : securityDACTest0890 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest0890, TestSize.Level2) +{ + int ret; + CreateTxt(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0765); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 765,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncNoCap(); + setuid(UID0); + setgid(GID0); + ret = rename("/storage/SystemJffsDacTestSuite/Dac.txt", "/storage/SystemJffsDacTestSuite/Dac_bak.txt"); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0920 + * @tc.name : securityDACTest0920 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest0920, TestSize.Level2) +{ + int ret; + CreateDir(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0256); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 256,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncBothCap(); + setuid(UID555); + setgid(GID0); + ret = chdir("/storage/SystemJffsDacTestSuite/mkdir"); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + chdir("/storage"); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0930 + * @tc.name : securityDACTest0930 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest0930, TestSize.Level2) +{ + int ret; + CreateDir(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0235); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 235,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncReadsearchCap(); + setuid(UID0); + setgid(GID0); + ret = chdir("/storage/SystemJffsDacTestSuite/mkdir"); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + chdir("/storage"); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0940 + * @tc.name : securityDACTest0940 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest0940, TestSize.Level2) +{ + int ret; + CreateDir(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0670); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 672,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncNoCap(); + setuid(UID555); + setgid(GID555); + ret = chdir("/storage/SystemJffsDacTestSuite/mkdir"); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + chdir("/storage"); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0950 + * @tc.name : securityDACTest0950 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest0950, TestSize.Level2) +{ + int ret; + gid_t list[SINGLESIZE] = {0}; + CreateDir(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0116); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 116,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncReadsearchCap(); + setuid(UID555); + setgid(GID555); + setgroups(SINGLESIZE, list); + ret = chdir("/storage/SystemJffsDacTestSuite/mkdir"); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + chdir("/storage"); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0960 + * @tc.name : securityDACTest0960 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest0960, TestSize.Level2) +{ + int ret; + char *argv[] = {nullptr, nullptr}; + char *envp[] = {nullptr}; + CreateTxt(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0045); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 045,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncReadsearchCap(); + setuid(UID0); + setgid(GID555); + ret = execve("/storage/SystemJffsDacTestSuite/Dac.txt", argv, envp); + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0970 + * @tc.name : securityDACTest0970 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest0970, TestSize.Level2) +{ + int ret; + char *argv[] = {nullptr, nullptr}; + char *envp[] = {nullptr}; + CreateTxt(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0124); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 124,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncNoCap(); + setuid(UID555); + setgid(GID0); + ret = execve("/storage/SystemJffsDacTestSuite/Dac.txt", argv, envp); + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0980 + * @tc.name : securityDACTest0980 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest0980, TestSize.Level2) +{ + int ret; + char *argv[] = {nullptr, nullptr}; + char *envp[] = {nullptr}; + CreateTxt(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0536); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 536,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncNoCap(); + setuid(UID0); + setgid(GID0); + ret = execve("/storage/SystemJffsDacTestSuite/Dac.txt", argv, envp); + // the file is not elf , can not exec + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_0990 + * @tc.name : securityDACTest0990 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest0990, TestSize.Level2) +{ + int ret; + char *argv[] = {nullptr, nullptr}; + char *envp[] = {nullptr}; + CreateTxt(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0657); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 657,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncReadsearchCap(); + setuid(UID555); + setgid(GID555); + ret = execve("/storage/SystemJffsDacTestSuite/Dac.txt", argv, envp); + // the file is not elf , can not exec + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_1000 + * @tc.name : securityDACTest1000 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest1000, TestSize.Level2) +{ + int ret; + char *argv[] = {nullptr, nullptr}; + char *envp[] = {nullptr}; + gid_t list[SINGLESIZE] = {0}; + CreateTxt(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0310); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 310,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncNoCap(); + setuid(UID555); + setgid(GID555); + setgroups(SINGLESIZE, list); + ret = execve("/storage/SystemJffsDacTestSuite/Dac.txt", argv, envp); + // the file is not elf , can not exec + if (ret == 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_1010 + * @tc.name : securityDACTest1010 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest1010, TestSize.Level2) +{ + int ret; + CreateTxt(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0354); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 354,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncNoCap(); + setuid(UID0); + setgid(GID555); + ret = access("/storage/SystemJffsDacTestSuite/Dac.txt", F_OK); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_1030 + * @tc.name : securityDACTest1030 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest1030, TestSize.Level2) +{ + int ret; + CreateTxt(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0717); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 717,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncReadsearchCap(); + setuid(UID555); + setgid(GID555); + ret = access("/storage/SystemJffsDacTestSuite/Dac.txt", F_OK); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_1050 + * @tc.name : securityDACTest1050 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest1050, TestSize.Level2) +{ + int ret; + CreateDir(); + ret = chmod("/storage/SystemJffsDacTestSuite/mkdir", 0325); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 325,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncReadsearchCap(); + setuid(UID0); + setgid(GID0); + ret = mkdir("/storage/SystemJffsDacTestSuite/mkdir/Dac", NORWX); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_1080 + * @tc.name : securityDACTest1080 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest1080, TestSize.Level2) +{ + int ret; + gid_t list[SINGLESIZE] = {0}; + CreateDir(); + ret = chmod("/storage/SystemJffsDacTestSuite/mkdir", 0731); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 731,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncNoCap(); + setuid(UID555); + setgid(GID555); + setgroups(SINGLESIZE, list); + ret = mkdir("/storage/SystemJffsDacTestSuite/mkdir/Dac", NORWX); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_1090 + * @tc.name : securityDACTest1090 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest1090, TestSize.Level2) +{ + int ret; + gid_t list[SINGLESIZE] = {0}; + CreateDir(); + ret = chmod("/storage/SystemJffsDacTestSuite/mkdir", 0074); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 074,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncReadsearchCap(); + setuid(UID555); + setgid(GID555); + setgroups(SINGLESIZE, list); + ret = mkdir("/storage/SystemJffsDacTestSuite/mkdir/Dac", NORWX); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_1100 + * @tc.name : securityDACTest1100 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest1100, TestSize.Level2) +{ + int ret; + CreateTxt(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0175); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 175,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncReadsearchCap(); + setuid(UID555); + setgid(GID0); + ret = unlink("/storage/SystemJffsDacTestSuite/Dac.txt"); + if (ret != 0) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_1150 + * @tc.name : securityDACTest1150 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest1150, TestSize.Level2) +{ + int ret; + int fd = 0; + CreateTxt(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0120); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 120,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncReadsearchCap(); + setuid(UID0); + setgid(GID555); + fd = open("/storage/SystemJffsDacTestSuite/Dac.txt", F_OK); + if (fd >= 0) { + close(fd); + } else { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_1160 + * @tc.name : securityDACTest1160 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest1160, TestSize.Level2) +{ + int ret; + int fd = 0; + CreateTxt(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0564); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 564,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncReadsearchCap(); + setuid(UID0); + setgid(GID555); + fd = open("/storage/SystemJffsDacTestSuite/Dac.txt", F_OK); + if (fd >= 0) { + close(fd); + } else { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_1200 + * @tc.name : securityDACTest1200 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest1200, TestSize.Level2) +{ + int ret; + int fd = 0; + gid_t list[SINGLESIZE] = {0}; + CreateTxt(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0637); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 637,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncNoCap(); + setuid(UID555); + setgid(GID555); + setgroups(SINGLESIZE, list); + fd = open("/storage/SystemJffsDacTestSuite/Dac.txt", F_OK); + if (fd >= 0) { + close(fd); + } else { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_1210 + * @tc.name : securityDACTest1210 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest1210, TestSize.Level2) +{ + int ret; + DIR* dir = nullptr; + CreateDir(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0031); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 031,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncNoCap(); + setuid(UID555); + setgid(GID0); + dir = opendir("/storage/SystemJffsDacTestSuite/mkdir"); + if (dir == nullptr) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + closedir(dir); + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_1220 + * @tc.name : securityDACTest1220 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest1220, TestSize.Level2) +{ + int ret; + DIR* dir = nullptr; + CreateDir(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0712); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 312,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncNoCap(); + setuid(UID0); + setgid(GID0); + dir = opendir("/storage/SystemJffsDacTestSuite/mkdir"); + if (dir == nullptr) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + closedir(dir); + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_1230 + * @tc.name : securityDACTest1230 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest1230, TestSize.Level2) +{ + int ret; + DIR* dir = nullptr; + CreateDir(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0274); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 274,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncReadsearchCap(); + setuid(UID555); + setgid(GID555); + dir = opendir("/storage/SystemJffsDacTestSuite/mkdir"); + if (dir == nullptr) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + closedir(dir); + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} + +/* * + * @tc.number : SUB_SEC_AppSEC_PermissionMgmt_DAC_1240 + * @tc.name : securityDACTest1240 + * @tc.desc : [C- SECURITY -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + */ +HWTEST_F(SystemJffsDacTestSuite, securityDACTest1240, TestSize.Level2) +{ + int ret; + DIR* dir = nullptr; + gid_t list[SINGLESIZE] = {0}; + CreateDir(); + ret = chmod("/storage/SystemJffsDacTestSuite", 0665); + EXPECT_EQ(ret, 0) << "ErrInfo: Failed in chmod 665,now uid=" << getuid(); + pid_t pid = fork(); + ASSERT_TRUE(pid >= 0) << "======== Fork Error! ========="; + usleep(SLEEP_NUM); + if (pid == 0) { + int exitCode = 0; + ChildFuncReadsearchCap(); + setuid(UID555); + setgid(GID555); + setgroups(SINGLESIZE, list); + dir = opendir("/storage/SystemJffsDacTestSuite/mkdir"); + if (dir == nullptr) { + LOG("VFS error with DAC or Capability, now the uid=%d", getuid()); + exitCode = 1; + } + closedir(dir); + exit(exitCode); + } else { + int status = 0; + waitpid(pid, &status, 0); + EXPECT_TRUE(WIFEXITED(status) > 0) << "ErrInfo: Exit error"; + EXPECT_EQ(WEXITSTATUS(status), 0) << "ErrInfo: WEXITSTATUS is " << WEXITSTATUS(status); + } +} \ No newline at end of file diff --git a/startup_lite/bootstrap_posix/BUILD.gn b/startup_lite/bootstrap_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..cb94e215ac6aedbf7cd12c2fc19a8d5f0ddeb807 --- /dev/null +++ b/startup_lite/bootstrap_posix/BUILD.gn @@ -0,0 +1,36 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsBootstrapTest") { + suite_name = "acts" + sources = [ + "src/SamgrApiTest.h", + "src/SamgrApiTest.cpp", + ] + + include_dirs = [ + "src", + "//utils/native/liteos/include", + "//kernel/liteos_a/kernel/common", + "//third_party/bounds_checking_function/include/", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/samgr", + ] + cflags = [ "-Wno-error" ] + + deps = [ + "//foundation/distributedschedule/services/samgr_lite/samgr:samgr", + "//third_party/bounds_checking_function:libsec_shared", + ] +} diff --git a/startup_lite/bootstrap_posix/Test.json b/startup_lite/bootstrap_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..cedebaacdb4acf90032771177d81a768f0cdc734 --- /dev/null +++ b/startup_lite/bootstrap_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for hcpptest demo test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/startup", + "target": "/test_root/startup" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/startup/ActsBootstrapTest.bin" + } +} \ No newline at end of file diff --git a/startup_lite/bootstrap_posix/src/SamgrApiTest.cpp b/startup_lite/bootstrap_posix/src/SamgrApiTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..8ef519605a17573d8c7e5bf757b7d63b920245e1 --- /dev/null +++ b/startup_lite/bootstrap_posix/src/SamgrApiTest.cpp @@ -0,0 +1,477 @@ +/* + * Copyright (c) 2020 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. + * + * Description : common function for samgr api test cases + * Create : 2020/07/23 + */ + +#include "SamgrApiTest.h" +#include "gtest/gtest.h" +#include "log.h" +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +using namespace testing::ext; + +static int g_initIndex = 0; +static int g_coreInit[API_PRI_MAX] = {0}; +static int g_sysRun[API_PRI_MAX] = {0}; +static int g_sysServiceInit[API_PRI_MAX] = {0}; +static int g_sysFeatureInit[API_PRI_MAX] = {0}; +static int g_sysExServiceInit[API_PRI_MAX] = {0}; +static int g_sysExFeatureInit[API_PRI_MAX] = {0}; +static int g_appServiceInit[API_PRI_MAX] = {0}; +static int g_appFeatureInit[API_PRI_MAX] = {0}; + +static void PrintInitIndex(const int initArr[]) +{ + for (int i = 0; i < API_PRI_MAX; i++) { + if (i == API_PRI_DEFAULT) { + HILOG_INFO(HILOG_MODULE_HIVIEW, "default: %d", initArr[i]); + continue; + } + HILOG_INFO(HILOG_MODULE_HIVIEW, "%d: %d", i, initArr[i]); + } +} + +static void CoreInitDef(void) +{ + g_coreInit[API_PRI_DEFAULT] = g_initIndex++; +} + +static void CoreInit0(void) +{ + g_coreInit[API_PRI0] = g_initIndex++; +} +static void CoreInit1(void) +{ + g_coreInit[API_PRI1] = g_initIndex++; +} +static void CoreInit2(void) +{ + g_coreInit[API_PRI2] = g_initIndex++; +} +static void CoreInit3(void) +{ + g_coreInit[API_PRI3] = g_initIndex++; +} +static void CoreInit4(void) +{ + g_coreInit[API_PRI4] = g_initIndex++; +} + +static void SysRunDef(void) +{ + g_sysRun[API_PRI_DEFAULT] = g_initIndex++; +} +static void SysRun0(void) +{ + g_sysRun[API_PRI0] = g_initIndex++; +} +static void SysRun1(void) +{ + g_sysRun[API_PRI1] = g_initIndex++; +} +static void SysRun2(void) +{ + g_sysRun[API_PRI2] = g_initIndex++; +} +static void SysRun3(void) +{ + g_sysRun[API_PRI3] = g_initIndex++; +} +static void SysRun4(void) +{ + g_sysRun[API_PRI4] = g_initIndex++; +} + +static void SysServiceInitDef(void) +{ + g_sysServiceInit[API_PRI_DEFAULT] = g_initIndex++; +} +static void SysServiceInit0(void) +{ + g_sysServiceInit[API_PRI0] = g_initIndex++; +} +static void SysServiceInit1(void) +{ + g_sysServiceInit[API_PRI1] = g_initIndex++; +} +static void SysServiceInit2(void) +{ + g_sysServiceInit[API_PRI2] = g_initIndex++; +} +static void SysServiceInit3(void) +{ + g_sysServiceInit[API_PRI3] = g_initIndex++; +} +static void SysServiceInit4(void) +{ + g_sysServiceInit[API_PRI4] = g_initIndex++; +} + +static void SysFeatureInitDef(void) +{ + g_sysFeatureInit[API_PRI_DEFAULT] = g_initIndex++; +} +static void SysFeatureInit0(void) +{ + g_sysFeatureInit[API_PRI0] = g_initIndex++; +} +static void SysFeatureInit1(void) +{ + g_sysFeatureInit[API_PRI1] = g_initIndex++; +} +static void SysFeatureInit2(void) +{ + g_sysFeatureInit[API_PRI2] = g_initIndex++; +} +static void SysFeatureInit3(void) +{ + g_sysFeatureInit[API_PRI3] = g_initIndex++; +} +static void SysFeatureInit4(void) +{ + g_sysFeatureInit[API_PRI4] = g_initIndex++; +} + +static void SysExSerInitDef(void) +{ + g_sysExServiceInit[API_PRI_DEFAULT] = g_initIndex++; +} +static void SysExSerInit0(void) +{ + g_sysExServiceInit[API_PRI0] = g_initIndex++; +} +static void SysExSerInit1(void) +{ + g_sysExServiceInit[API_PRI1] = g_initIndex++; +} +static void SysExSerInit2(void) +{ + g_sysExServiceInit[API_PRI2] = g_initIndex++; +} +static void SysExSerInit3(void) +{ + g_sysExServiceInit[API_PRI3] = g_initIndex++; +} +static void SysExSerInit4(void) +{ + g_sysExServiceInit[API_PRI4] = g_initIndex++; +} + +static void SysExFeaInitDef(void) +{ + g_sysExFeatureInit[API_PRI_DEFAULT] = g_initIndex++; +} +static void SysExFeaInit0(void) +{ + g_sysExFeatureInit[API_PRI0] = g_initIndex++; +} +static void SysExFeaInit1(void) +{ + g_sysExFeatureInit[API_PRI1] = g_initIndex++; +} +static void SysExFeaInit2(void) +{ + g_sysExFeatureInit[API_PRI2] = g_initIndex++; +} +static void SysExFeaInit3(void) +{ + g_sysExFeatureInit[API_PRI3] = g_initIndex++; +} +static void SysExFeaInit4(void) +{ + g_sysExFeatureInit[API_PRI4] = g_initIndex++; +} + +static void AppServiceInitDef(void) +{ + g_appServiceInit[API_PRI_DEFAULT] = g_initIndex++; +} +static void AppServiceInit0(void) +{ + g_appServiceInit[API_PRI0] = g_initIndex++; +} +static void AppServiceInit1(void) +{ + g_appServiceInit[API_PRI1] = g_initIndex++; +} +static void AppServiceInit2(void) +{ + g_appServiceInit[API_PRI2] = g_initIndex++; +} +static void AppServiceInit3(void) +{ + g_appServiceInit[API_PRI3] = g_initIndex++; +} +static void AppServiceInit4(void) +{ + g_appServiceInit[API_PRI4] = g_initIndex++; +} + +static void AppFeatureInitDef(void) +{ + g_appFeatureInit[API_PRI_DEFAULT] = g_initIndex++; +} +static void AppFeatureInit0(void) +{ + g_appFeatureInit[API_PRI0] = g_initIndex++; +} +static void AppFeatureInit1(void) +{ + g_appFeatureInit[API_PRI1] = g_initIndex++; +} +static void AppFeatureInit2(void) +{ + g_appFeatureInit[API_PRI2] = g_initIndex++; +} +static void AppFeatureInit3(void) +{ + g_appFeatureInit[API_PRI3] = g_initIndex++; +} +static void AppFeatureInit4(void) +{ + g_appFeatureInit[API_PRI4] = g_initIndex++; +} + +// 接口注册后的启动顺序依赖hos_init.h中的定义的数字大小 + +// 第0个执行,内部按照0~4优先级执行,default优先级为2 +CORE_INIT(CoreInitDef); +CORE_INIT_PRI(CoreInit0, 0); +CORE_INIT_PRI(CoreInit1, 1); +CORE_INIT_PRI(CoreInit4, 4); +CORE_INIT_PRI(CoreInit2, 2); +CORE_INIT_PRI(CoreInit3, 3); + +// 最后一个执行,内部按照0~4优先级执行,default优先级为2 +SYS_RUN(SysRunDef); +SYS_RUN_PRI(SysRun0, 0); +SYS_RUN_PRI(SysRun1, 1); +SYS_RUN_PRI(SysRun4, 4); +SYS_RUN_PRI(SysRun2, 2); +SYS_RUN_PRI(SysRun3, 3); + +// 第1个执行,内部按照0~4优先级执行,default优先级为2 +SYS_SERVICE_INIT(SysServiceInitDef); +SYS_SERVICE_INIT_PRI(SysServiceInit0, 0); +SYS_SERVICE_INIT_PRI(SysServiceInit1, 1); +SYS_SERVICE_INIT_PRI(SysServiceInit4, 4); +SYS_SERVICE_INIT_PRI(SysServiceInit2, 2); +SYS_SERVICE_INIT_PRI(SysServiceInit3, 3); + +// 第2个执行,内部按照0~4优先级执行,default优先级为2 +SYS_FEATURE_INIT(SysFeatureInitDef); +SYS_FEATURE_INIT_PRI(SysFeatureInit0, 0); +SYS_FEATURE_INIT_PRI(SysFeatureInit2, 2); +SYS_FEATURE_INIT_PRI(SysFeatureInit1, 1); +SYS_FEATURE_INIT_PRI(SysFeatureInit3, 3); +SYS_FEATURE_INIT_PRI(SysFeatureInit4, 4); + +// 第3个执行,注意和APP_SERVICE_INIT_XXX并列,谁先注册先执行谁,内部按照0~4优先级执行,default优先级为2 +SYSEX_SERVICE_INIT(SysExSerInitDef); +SYSEX_SERVICE_INIT_PRI(SysExSerInit0, 0); +SYSEX_SERVICE_INIT_PRI(SysExSerInit1, 1); +SYSEX_SERVICE_INIT_PRI(SysExSerInit2, 2); +SYSEX_SERVICE_INIT_PRI(SysExSerInit3, 3); +SYSEX_SERVICE_INIT_PRI(SysExSerInit4, 4); + +// 第4个执行,注意和APP_FEATURE_INIT_XXX并列,谁先注册先执行谁,内部按照0~4优先级执行,default优先级为2 +SYSEX_FEATURE_INIT(SysExFeaInitDef); +SYSEX_FEATURE_INIT_PRI(SysExFeaInit0, 0); +SYSEX_FEATURE_INIT_PRI(SysExFeaInit1, 1); +SYSEX_FEATURE_INIT_PRI(SysExFeaInit2, 2); +SYSEX_FEATURE_INIT_PRI(SysExFeaInit3, 3); +SYSEX_FEATURE_INIT_PRI(SysExFeaInit4, 4); + +// 第3个执行,注意和SYSEX_SERVICE_INIT_XXX并列,谁先注册先执行谁,内部按照0~4优先级执行,default优先级为2 +APP_SERVICE_INIT(AppServiceInitDef); +APP_SERVICE_INIT_PRI(AppServiceInit0, 0); +APP_SERVICE_INIT_PRI(AppServiceInit4, 4); +APP_SERVICE_INIT_PRI(AppServiceInit3, 3); +APP_SERVICE_INIT_PRI(AppServiceInit2, 2); +APP_SERVICE_INIT_PRI(AppServiceInit1, 1); + +// 第4个执行,注意和SYSEX_FEATURE_INIT_XXX并列,谁先注册先执行谁,内部按照0~4优先级执行,default优先级为2 +APP_FEATURE_INIT(AppFeatureInitDef); +APP_FEATURE_INIT_PRI(AppFeatureInit0, 0); +APP_FEATURE_INIT_PRI(AppFeatureInit1, 1); +APP_FEATURE_INIT_PRI(AppFeatureInit3, 3); +APP_FEATURE_INIT_PRI(AppFeatureInit4, 4); +APP_FEATURE_INIT_PRI(AppFeatureInit2, 2); + +class SamgrApiTest : public testing::Test { +protected: + static void SetUpTestCase(void) {} + static void TearDownTestCase(void) {} + virtual void SetUp() {} + virtual void TearDown() {} +}; + +/** + * @tc.number : SUB_START_Bootstrap_Samgr_0100 + * @tc.name : check total init index + * @tc.desc : check total init index, return success + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(SamgrApiTest, SUB_START_Bootstrap_Samgr_0100, TestSize.Level0) +{ + HILOG_INFO(HILOG_MODULE_HIVIEW, "[SUB_START_Bootstrap_Samgr_0100:%d]", g_initIndex); + EXPECT_EQ(g_initIndex, SAMGR_API_GROUP_NUM*SAMGR_API_CALL_NUM); +} + +/** + * @tc.number : SUB_START_Bootstrap_Samgr_0200 + * @tc.name : check core init index + * @tc.desc : check core init, return success + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(SamgrApiTest, SUB_START_Bootstrap_Samgr_0200, TestSize.Level0) +{ + HILOG_INFO(HILOG_MODULE_HIVIEW, "g_coreInit"); + PrintInitIndex(g_coreInit); + EXPECT_EQ(g_coreInit[API_PRI0], GET_INIT_INDEX(CORE_INIT_E, API_PRI0)); + EXPECT_EQ(g_coreInit[API_PRI1], GET_INIT_INDEX(CORE_INIT_E, API_PRI1)); + EXPECT_EQ(g_coreInit[API_PRI_DEFAULT], GET_INIT_INDEX(CORE_INIT_E, API_PRI_DEFAULT)); + EXPECT_EQ(g_coreInit[API_PRI2], GET_INIT_INDEX(CORE_INIT_E, API_PRI2)); + EXPECT_EQ(g_coreInit[API_PRI3], GET_INIT_INDEX(CORE_INIT_E, API_PRI3)); + EXPECT_EQ(g_coreInit[API_PRI4], GET_INIT_INDEX(CORE_INIT_E, API_PRI4)); +} + +/** + * @tc.number : SUB_START_Bootstrap_Samgr_0300 + * @tc.name : check system service init index + * @tc.desc : check system service init, return success + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(SamgrApiTest, SUB_START_Bootstrap_Samgr_0300, TestSize.Level0) +{ + HILOG_INFO(HILOG_MODULE_HIVIEW, "g_sysServiceInit"); + PrintInitIndex(g_sysServiceInit); + EXPECT_EQ(g_sysServiceInit[API_PRI0], GET_INIT_INDEX(SYS_SERVICE_INIT_E, API_PRI0)); + EXPECT_EQ(g_sysServiceInit[API_PRI1], GET_INIT_INDEX(SYS_SERVICE_INIT_E, API_PRI1)); + EXPECT_EQ(g_sysServiceInit[API_PRI_DEFAULT], GET_INIT_INDEX(SYS_SERVICE_INIT_E, API_PRI_DEFAULT)); + EXPECT_EQ(g_sysServiceInit[API_PRI2], GET_INIT_INDEX(SYS_SERVICE_INIT_E, API_PRI2)); + EXPECT_EQ(g_sysServiceInit[API_PRI3], GET_INIT_INDEX(SYS_SERVICE_INIT_E, API_PRI3)); + EXPECT_EQ(g_sysServiceInit[API_PRI4], GET_INIT_INDEX(SYS_SERVICE_INIT_E, API_PRI4)); +} + +/** + * @tc.number : SUB_START_Bootstrap_Samgr_0400 + * @tc.name : check system feature init index + * @tc.desc : check system feature init, return success + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(SamgrApiTest, SUB_START_Bootstrap_Samgr_0400, TestSize.Level0) +{ + HILOG_INFO(HILOG_MODULE_HIVIEW, "g_sysFeatureInit"); + PrintInitIndex(g_sysFeatureInit); + EXPECT_EQ(g_sysFeatureInit[API_PRI0], GET_INIT_INDEX(SYS_FEATURE_INIT_E, API_PRI0)); + EXPECT_EQ(g_sysFeatureInit[API_PRI1], GET_INIT_INDEX(SYS_FEATURE_INIT_E, API_PRI1)); + EXPECT_EQ(g_sysFeatureInit[API_PRI_DEFAULT], GET_INIT_INDEX(SYS_FEATURE_INIT_E, API_PRI_DEFAULT)); + EXPECT_EQ(g_sysFeatureInit[API_PRI2], GET_INIT_INDEX(SYS_FEATURE_INIT_E, API_PRI2)); + EXPECT_EQ(g_sysFeatureInit[API_PRI3], GET_INIT_INDEX(SYS_FEATURE_INIT_E, API_PRI3)); + EXPECT_EQ(g_sysFeatureInit[API_PRI4], GET_INIT_INDEX(SYS_FEATURE_INIT_E, API_PRI4)); +} + +/** + * @tc.number : SUB_START_Bootstrap_Samgr_0500 + * @tc.name : check system extend service and app service init index + * @tc.desc : check system extend service and app service init, return success + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(SamgrApiTest, SUB_START_Bootstrap_Samgr_0500, TestSize.Level0) +{ + HILOG_INFO(HILOG_MODULE_HIVIEW, "g_sysExServiceInit"); + PrintInitIndex(g_sysExServiceInit); + HILOG_INFO(HILOG_MODULE_HIVIEW, "g_appServiceInit"); + PrintInitIndex(g_appServiceInit); + EXPECT_EQ(g_sysExServiceInit[API_PRI0], GET_INIT_INDEX(APP_SERVICE_INIT_E, 0)); + EXPECT_EQ(g_appServiceInit[API_PRI0], GET_INIT_INDEX(APP_SERVICE_INIT_E, 1)); + EXPECT_EQ(g_sysExServiceInit[API_PRI1], GET_INIT_INDEX(APP_SERVICE_INIT_E, 2)); + EXPECT_EQ(g_appServiceInit[API_PRI1], GET_INIT_INDEX(APP_SERVICE_INIT_E, 3)); + EXPECT_EQ(g_sysExServiceInit[API_PRI_DEFAULT], GET_INIT_INDEX(APP_SERVICE_INIT_E, 4)); + EXPECT_EQ(g_sysExServiceInit[API_PRI2], GET_INIT_INDEX(APP_SERVICE_INIT_E, 5)); + EXPECT_EQ(g_appServiceInit[API_PRI_DEFAULT], GET_INIT_INDEX(APP_SERVICE_INIT_E, 6)); + EXPECT_EQ(g_appServiceInit[API_PRI2], GET_INIT_INDEX(APP_SERVICE_INIT_E, 7)); + EXPECT_EQ(g_sysExServiceInit[API_PRI3], GET_INIT_INDEX(APP_SERVICE_INIT_E, 8)); + EXPECT_EQ(g_appServiceInit[API_PRI3], GET_INIT_INDEX(APP_SERVICE_INIT_E, 9)); + EXPECT_EQ(g_sysExServiceInit[API_PRI4], GET_INIT_INDEX(APP_SERVICE_INIT_E, 10)); + EXPECT_EQ(g_appServiceInit[API_PRI4], GET_INIT_INDEX(APP_SERVICE_INIT_E, 11)); +} + +/** + * @tc.number : SUB_START_Bootstrap_Samgr_0600 + * @tc.name : check system extend feature and app feature init index + * @tc.desc : check system extend feature and app feature init, return success + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(SamgrApiTest, SUB_START_Bootstrap_Samgr_0600, TestSize.Level0) +{ + HILOG_INFO(HILOG_MODULE_HIVIEW, "g_sysExFeatureInit"); + PrintInitIndex(g_sysExFeatureInit); + HILOG_INFO(HILOG_MODULE_HIVIEW, "g_appFeatureInit"); + PrintInitIndex(g_appFeatureInit); + EXPECT_EQ(g_sysExFeatureInit[API_PRI0], GET_INIT_INDEX(APP_FEATURE_INIT_E, 0)); + EXPECT_EQ(g_appFeatureInit[API_PRI0], GET_INIT_INDEX(APP_FEATURE_INIT_E, 1)); + EXPECT_EQ(g_sysExFeatureInit[API_PRI1], GET_INIT_INDEX(APP_FEATURE_INIT_E, 2)); + EXPECT_EQ(g_appFeatureInit[API_PRI1], GET_INIT_INDEX(APP_FEATURE_INIT_E, 3)); + EXPECT_EQ(g_sysExFeatureInit[API_PRI_DEFAULT], GET_INIT_INDEX(APP_FEATURE_INIT_E, 4)); + EXPECT_EQ(g_sysExFeatureInit[API_PRI2], GET_INIT_INDEX(APP_FEATURE_INIT_E, 5)); + EXPECT_EQ(g_appFeatureInit[API_PRI_DEFAULT], GET_INIT_INDEX(APP_FEATURE_INIT_E, 6)); + EXPECT_EQ(g_appFeatureInit[API_PRI2], GET_INIT_INDEX(APP_FEATURE_INIT_E, 7)); + EXPECT_EQ(g_sysExFeatureInit[API_PRI3], GET_INIT_INDEX(APP_FEATURE_INIT_E, 8)); + EXPECT_EQ(g_appFeatureInit[API_PRI3], GET_INIT_INDEX(APP_FEATURE_INIT_E, 9)); + EXPECT_EQ(g_sysExFeatureInit[API_PRI4], GET_INIT_INDEX(APP_FEATURE_INIT_E, 10)); + EXPECT_EQ(g_appFeatureInit[API_PRI4], GET_INIT_INDEX(APP_FEATURE_INIT_E, 11)); +} + +/** + * @tc.number : SUB_START_Bootstrap_Samgr_0700 + * @tc.name : check system run index + * @tc.desc : check system run, return success + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(SamgrApiTest, SUB_START_Bootstrap_Samgr_0700, TestSize.Level0) +{ + HILOG_INFO(HILOG_MODULE_HIVIEW, "g_sysRun"); + PrintInitIndex(g_sysRun); + EXPECT_EQ(g_sysRun[API_PRI0], GET_INIT_INDEX(SYS_RUN_E, API_PRI0)); + EXPECT_EQ(g_sysRun[API_PRI1], GET_INIT_INDEX(SYS_RUN_E, API_PRI1)); + EXPECT_EQ(g_sysRun[API_PRI_DEFAULT], GET_INIT_INDEX(SYS_RUN_E, API_PRI_DEFAULT)); + EXPECT_EQ(g_sysRun[API_PRI2], GET_INIT_INDEX(SYS_RUN_E, API_PRI2)); + EXPECT_EQ(g_sysRun[API_PRI3], GET_INIT_INDEX(SYS_RUN_E, API_PRI3)); + EXPECT_EQ(g_sysRun[API_PRI4], GET_INIT_INDEX(SYS_RUN_E, API_PRI4)); +} diff --git a/startup_lite/bootstrap_posix/src/SamgrApiTest.h b/startup_lite/bootstrap_posix/src/SamgrApiTest.h new file mode 100755 index 0000000000000000000000000000000000000000..0ea626cafc0a62c3fb1f90730a08a53e62bbcf83 --- /dev/null +++ b/startup_lite/bootstrap_posix/src/SamgrApiTest.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2020 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 XTS_HITS_SAMGR_API_EXPECT_H +#define XTS_HITS_SAMGR_API_EXPECT_H + +constexpr int SAMGR_API_GROUP_NUM = 8; +constexpr int SAMGR_API_CALL_NUM = 6; +#define GET_INIT_INDEX(G, pri) ((G)*(SAMGR_API_CALL_NUM)+(pri)) + +using SamgrApiGroup = enum TagSamgrApiGroup { + CORE_INIT_E = 0, + SYS_SERVICE_INIT_E, + SYS_FEATURE_INIT_E, + APP_SERVICE_INIT_E, + SYSEX_SERVICE_INIT_E, + APP_FEATURE_INIT_E, + SYSEX_FEATURE_INIT, + SYS_RUN_E, +}; + +using SamgrApiPri = enum TagSamgrApiPri { + API_PRI0 = 0, + API_PRI1, + API_PRI_DEFAULT, + API_PRI2, + API_PRI3, + API_PRI4, + API_PRI_MAX, +}; + +#endif // XTS_HITS_SAMGR_API_EXPECT_H \ No newline at end of file diff --git a/startup_lite/parameter_posix/BUILD.gn b/startup_lite/parameter_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..f9ee376cb023bc141404f3822a60b9d50e8dea40 --- /dev/null +++ b/startup_lite/parameter_posix/BUILD.gn @@ -0,0 +1,36 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsParameterTest") { + suite_name = "acts" + sources = [ + "src/ParameterTest.cpp", + ] + + include_dirs = [ + "src", + "//base/startup/interfaces/kits/syspara_lite" + ] + + deps = [ + "//base/startup/frameworks/syspara_lite/parameter:parameter" + ] + cflags = [ "-Wno-error" ] + ldflags = [ + "-lstdc++", + "-lm", + "-lpthread" + ] +} diff --git a/startup_lite/parameter_posix/Test.json b/startup_lite/parameter_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..411fa4ce5315ae96a34ab2abc43af6d73c15a3b4 --- /dev/null +++ b/startup_lite/parameter_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for hcpptest demo test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/startup", + "target": "/test_root/startup" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/startup/ActsParameterTest.bin" + } +} \ No newline at end of file diff --git a/startup_lite/parameter_posix/src/ParameterTest.cpp b/startup_lite/parameter_posix/src/ParameterTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..f4226b169dc6a1d7b915c3d907f90e3d90721885 --- /dev/null +++ b/startup_lite/parameter_posix/src/ParameterTest.cpp @@ -0,0 +1,413 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include "parameter.h" +using namespace std; +using namespace testing::ext; + +namespace StartUpLite { + static const int GET_DEF_PARA_FUN_MAX = 24; + static const int MAX_LEN = 128; + static const int WRONG_LEN = 2; +class ParameterTest : public testing::Test { +protected: + static void SetUpTestCase(void) + { + mkdir("/data", S_IRUSR | S_IWUSR); + mkdir("/data/system", S_IRUSR | S_IWUSR); + mkdir("/data/system/param", S_IRUSR | S_IWUSR); + } + static void TearDownTestCase(void) {} + virtual void SetUp() {} + virtual void TearDown() {} + string defSysParam = "data of sys param ***..."; + using GetRdonlyPara = char* (*)(); + using GetDefParaNode = struct TagGetDefParaNode { + char const *funName; + GetRdonlyPara fun; + }; + GetDefParaNode getDefPara[StartUpLite::GET_DEF_PARA_FUN_MAX] = { + {"GetProductType", GetProductType}, + {"GetManufacture", GetManufacture}, + {"GetBrand", GetBrand}, + {"GetMarketName", GetMarketName}, + {"GetProductSeries", GetProductSeries}, + {"GetProductModel", GetProductModel}, + {"GetSoftwareModel", GetSoftwareModel}, + {"GetHardwareModel", GetHardwareModel}, + {"GetHardwareProfile", GetHardwareProfile}, + {"GetOsName", GetOsName}, + {"GetDisplayVersion", GetDisplayVersion}, + {"GetBootloaderVersion", GetBootloaderVersion}, + {"GetSecurityPatchTag", GetSecurityPatchTag}, + {"GetAbiList", GetAbiList}, + {"GetFirstApiLevel", GetFirstApiLevel}, + {"GetSdkApiLevel", GetSdkApiLevel}, + {"GetIncrementalVersion", GetIncrementalVersion}, + {"GetVersionId", GetVersionId}, + {"GetBuildType", GetBuildType}, + {"GetBuildUser", GetBuildUser}, + {"GetBuildHost", GetBuildHost}, + {"GetBuildTime", GetBuildTime}, + {"GetBuildRootHash", GetBuildRootHash}, + {"GetSerial", GetSerial}, + }; +}; + +/** + * @tc.number : SUB_START_Para_Setting_Legal_0010 + * @tc.name : SetParameter legal test with Lowercase alphanumeric, underscore, dot + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(ParameterTest, SUB_START_Para_Setting_Legal_0010, TestSize.Level0) +{ + int ret; + + char key[] = "rw.sys.version"; + char value[] = "OEM-hisi-10.1.0"; + ret = SetParameter(key, value); + EXPECT_EQ(ret, 0); +} + +/** + * @tc.number : SUB_START_Para_Setting_Legal_0020 + * @tc.name : SetParameter legal test with key 31 bytes, value 127 bytes + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(ParameterTest, SUB_START_Para_Setting_Legal_0020, TestSize.Level0) +{ + int ret; + + char key1[] = "rw.sys.version.version.version."; + char value1[] = "set with key = 31"; + ret = SetParameter(key1, value1); + EXPECT_EQ(ret, 0); + + char key2[] = "rw.sys.version.version"; + char value2[] = "abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890\ +abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrs"; + ret = SetParameter(key2, value2); + EXPECT_EQ(ret, 0); +} + +/** + * @tc.number : SUB_START_Para_Setting_ilLegal_0010 + * @tc.name : SetParameter legal test with key is nullptr, value is nullptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(ParameterTest, SUB_START_Para_Setting_ilLegal_0010, TestSize.Level2) +{ + int ret; + + char value[] = "test with null"; + ret = SetParameter(nullptr, value); + EXPECT_EQ(ret, -9); + + char key[] = "rw.sys.version"; + ret = SetParameter(key, nullptr); + EXPECT_EQ(ret, -9); +} + +/** + * @tc.number : SUB_START_Para_Setting_ilLegal_0020 + * @tc.name : SetParameter legal test with key is NULL, value is NULL + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(ParameterTest, SUB_START_Para_Setting_ilLegal_0020, TestSize.Level2) +{ + int ret = SetParameter("\0", "\0"); + EXPECT_EQ(ret, -9); +} + +/** + * @tc.number : SUB_START_Para_Setting_ilLegal_key_0010 + * @tc.name : SetParameter legal test with key 32 or more than 32 bytes + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(ParameterTest, SUB_START_Para_Setting_ilLegal_key_0010, TestSize.Level2) +{ + int ret; + + char key1[] = "rw.sys.version.version.version.v"; + char value1[] = "set with key = 32"; + ret = SetParameter(key1, value1); + EXPECT_EQ(ret, -9); + + char key2[] = "rw.sys.version.version.version.version"; + char value2[] = "set with key > 32"; + ret = SetParameter(key2, value2); + EXPECT_EQ(ret, -9); +} + +/** + * @tc.number : SUB_START_Para_Setting_ilLegal_key_0030 + * @tc.name : SetParameter legal test with illegal characters + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(ParameterTest, SUB_START_Para_Setting_ilLegal_key_0030, TestSize.Level2) +{ + int ret; + + char key[] = "rw.sys.version*%version"; + char value[] = "set value with illegal key"; + ret = SetParameter(key, value); + EXPECT_EQ(ret, -9); +} + +/** + * @tc.number : SUB_START_Para_Setting_ilLegal_value_0010 + * @tc.name : SetParameter legal test with value is 128 or more than 128 bytes + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(ParameterTest, SUB_START_Para_Setting_ilLegal_value_0010, TestSize.Level2) +{ + int ret; + + char key1[] = "rw.sys.version.version"; + char value1[] = "abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890\ +abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrst"; + ret = SetParameter(key1, value1); + EXPECT_EQ(ret, -9); + + char key2[] = "rw.sys.version.version"; + char value2[] = "abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890\ +abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890"; + ret = SetParameter(key2, value2); + EXPECT_EQ(ret, -9); +} + +/** + * @tc.number : SUB_START_Para_Getting_Legal_0010 + * @tc.name : GetParameter legal test with Lowercase alphanumeric, underscore, dot + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(ParameterTest, SUB_START_Para_Getting_Legal_0010, TestSize.Level0) +{ + int ret; + + char key[] = "rw.sys.version"; + char rightVal[] = "OEM-hisi-10.1.0"; + char value[StartUpLite::MAX_LEN] = {0}; + ret = GetParameter(key, defSysParam.c_str(), value, StartUpLite::MAX_LEN); + EXPECT_EQ(ret, strlen(rightVal)); + EXPECT_STREQ(value, rightVal); +} + +/** + * @tc.number : SUB_START_Para_Getting_Legal_0020 + * @tc.name : GetParameter legal test with defaut value point is nullptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(ParameterTest, SUB_START_Para_Getting_Legal_0020, TestSize.Level0) +{ + int ret; + + char key[] = "rw.sys.version"; + char rightVal[] = "OEM-hisi-10.1.0"; + char value[StartUpLite::MAX_LEN] = {0}; + ret = GetParameter(key, nullptr, value, StartUpLite::MAX_LEN); + EXPECT_EQ(ret, strlen(rightVal)); + EXPECT_STREQ(value, rightVal); +} + +/** + * @tc.number : SUB_START_Para_Getting_Legal_0030 + * @tc.name : GetParameter legal test with length is 31 bytes, value is 127 bytes + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(ParameterTest, SUB_START_Para_Getting_Legal_0030, TestSize.Level0) +{ + int ret; + + char key1[] = "rw.sys.version.version.version."; + char rightVal1[] = "set with key = 31"; + char value1[StartUpLite::MAX_LEN] = {0}; + ret = GetParameter(key1, defSysParam.c_str(), value1, StartUpLite::MAX_LEN); + EXPECT_EQ(ret, strlen(rightVal1)); + EXPECT_STREQ(value1, rightVal1); + + char key2[] = "rw.sys.version.version"; + char rightVal2[] = "abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890\ +abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrs"; + char value2[StartUpLite::MAX_LEN] = {0}; + ret = GetParameter(key2, defSysParam.c_str(), value2, StartUpLite::MAX_LEN); + EXPECT_EQ(ret, strlen(rightVal2)); + EXPECT_STREQ(value2, rightVal2); +} + +/** + * @tc.number : SUB_START_Para_Getting_ilLegal_0010 + * @tc.name : GetParameter legal test with value length is too short + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(ParameterTest, SUB_START_Para_Getting_ilLegal_0010, TestSize.Level2) +{ + int ret; + + char key[] = "rw.sys.version"; + char value[StartUpLite::WRONG_LEN] = {0}; + ret = GetParameter(key, defSysParam.c_str(), value, StartUpLite::WRONG_LEN); + EXPECT_EQ(ret, -9); +} + +/** + * @tc.number : SUB_START_Para_Getting_ilLegal_0020 + * @tc.name : GetParameter legal test with value point is nullptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(ParameterTest, SUB_START_Para_Getting_ilLegal_0020, TestSize.Level2) +{ + int ret; + + char key[] = "rw.sys.version"; + ret = GetParameter(key, defSysParam.c_str(), nullptr, StartUpLite::MAX_LEN); + EXPECT_EQ(ret, -9); +} + +/** + * @tc.number : SUB_START_Para_Getting_ilLegal_0030 + * @tc.name : GetParameter legal test with key is not exist and vlan len is too short + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(ParameterTest, SUB_START_Para_Getting_ilLegal_0030, TestSize.Level2) +{ + int ret; + + char key1[] = "rw.product.not.exist"; + char value1[StartUpLite::MAX_LEN] = {0}; + ret = GetParameter(key1, defSysParam.c_str(), value1, StartUpLite::MAX_LEN); + EXPECT_EQ(ret, strlen(defSysParam.c_str())); + EXPECT_STREQ(value1, defSysParam.c_str()); + + char value2[StartUpLite::WRONG_LEN] = {0}; + ret = GetParameter(key1, defSysParam.c_str(), value2, StartUpLite::WRONG_LEN); + EXPECT_EQ(ret, -1); +} + +/** + * @tc.number : SUB_START_Para_Getting_ilLegal_0040 + * @tc.name : GetParameter legal test with key is 32 bytes + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(ParameterTest, SUB_START_Para_Getting_ilLegal_0040, TestSize.Level2) +{ + int ret; + + char key[] = "rw.sys.version.version.version.v"; + char value[StartUpLite::MAX_LEN] = {0}; + ret = GetParameter(key, defSysParam.c_str(), value, StartUpLite::MAX_LEN); + EXPECT_EQ(ret, -9); +} + +/** + * @tc.number : SUB_START_Para_Getting_ilLegal_0050 + * @tc.name : GetParameter legal test with key is nullptr + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(ParameterTest, SUB_START_Para_Getting_ilLegal_0050, TestSize.Level2) +{ + int ret; + + char value[StartUpLite::MAX_LEN] = {0}; + ret = GetParameter(nullptr, defSysParam.c_str(), value, StartUpLite::MAX_LEN); + EXPECT_EQ(ret, -9); +} + +/** + * @tc.number : SUB_START_Para_Getting_ilLegal_0060 + * @tc.name : GetParameter legal test with key is illegal with Special characters + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(ParameterTest, SUB_START_Para_Getting_ilLegal_0060, TestSize.Level2) +{ + int ret; + + char key[] = "rw.sys.version*%version"; + char value[StartUpLite::MAX_LEN] = {0}; + ret = GetParameter(key, defSysParam.c_str(), value, StartUpLite::MAX_LEN); + EXPECT_EQ(ret, -9); +} + +/** + * @tc.number : SUB_START_Para_Getting_ReadOnly_0010 + * @tc.name : GetParameter read only parameter legal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(ParameterTest, SUB_START_Para_Getting_ReadOnly_0010, TestSize.Level0) +{ + char *value = nullptr; + + for (int loop = 0; loop < StartUpLite::GET_DEF_PARA_FUN_MAX; loop++) { + value = getDefPara[loop].fun(); + EXPECT_STRNE(value, (char *)nullptr); + if (value != nullptr) { + free(value); + } + } +} +} \ No newline at end of file diff --git a/uikit_lite/BUILD.gn b/uikit_lite/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..3f38038e8177c1b8ad5b7e330412fe13dd68175a --- /dev/null +++ b/uikit_lite/BUILD.gn @@ -0,0 +1,31 @@ + # Copyright (c) 2020 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. + +group("uikit_test") { + deps = [ + "//test/xts/acts/uikit_lite/uibutton_posix:ActsUIButtonTest", + #"//test/xts/acts/uikit_lite/mvp_posix:ActsMVPTest", + #"//test/xts/acts/uikit_lite/uianimator_posix:ActsUIAnimatorTest", + "//test/xts/acts/uikit_lite/uicanvas_posix:ActsUICanvasTest", + "//test/xts/acts/uikit_lite/uichart_posix:ActsUIChartTest", + "//test/xts/acts/uikit_lite/uiclock_posix:ActsUIClockTest", + "//test/xts/acts/uikit_lite/uiimage_posix:ActsUIImageTest", + #"//test/xts/acts/uikit_lite/uilabel_posix:ActsUILabelTest", + "//test/xts/acts/uikit_lite/uilayout_posix:ActsUILayoutTest", + "//test/xts/acts/uikit_lite/uiprogress_posix:ActsUIProgressTest", + "//test/xts/acts/uikit_lite/uislider_posix:ActsUISliderTest", + "//test/xts/acts/uikit_lite/uisnapshot_posix:ActsUISnapshotTest", + "//test/xts/acts/uikit_lite/uiviewGroup_posix:ActsUIViewGroupTest", + "//test/xts/acts/uikit_lite/utils_posix:ActsUtilsTest", + ] +} \ No newline at end of file diff --git a/uikit_lite/uibutton_posix/BUILD.gn b/uikit_lite/uibutton_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..04d3bb7279ca5119f47b55f6688e3cc6aadcc743 --- /dev/null +++ b/uikit_lite/uibutton_posix/BUILD.gn @@ -0,0 +1,75 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsUIButtonTest") { + suite_name = "acts" + sources = [ + "src/buttonTest.cpp", + "src/checkBoxTest.cpp", + "src/radioButtonTest.cpp", + "src/toggleButtonTest.cpp", + "src/labelButtonTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "//foundation/graphic/lite/services/wms", + "//foundation/graphic/lite/services/wms/client/interfaces", + "//foundation/graphic/lite/interfaces/utils", + "//foundation/graphic/lite/frameworks/ui/include", + "//foundation/graphic/lite/config", + "//foundation/graphic/lite/interfaces/ui", + "//foundation/graphic/lite/interfaces", + "//foundation/graphic/lite/hals/include", + "//foundation/graphic/lite/huawei_proprietary/include", + "//foundation/graphic/lite/tools", + "//foundation/graphic/lite/frameworks/ui/src", + "//foundation/graphic/lite/services/ims/include", + "//third_party/bounds_checking_function/include", + "//foundation/graphic/lite/frameworks/surface/include", + "//utils/native/lite/include", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/registry", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/samgr", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/communication/broadcast", + "//vendor/hisi/hi35xx/hi3516dv300/Hi3516DV300_SDK_V6.0.0.1_B010/mpp/include" + ] + ldflags = [ + "-Wl,-Map=toggleButtonTest.map", + "-T", + ] + + ldflags += [ + "${ohos_root_path}build/lite/platform/hi3516dv300_liteos_a/init.ld", + "-L${ohos_root_path}vendor/hisi/camera/hi3516dv300/Hi3516DV300_SDK_V6.0.0.1_B010/mpp/lib", + "-ltde", "-lmpi", "-ldnvqe", "-lVoiceEngine", "-lupvqe" + ] + + deps = [ + "//foundation/graphic/lite/utils:litegraphicutils", + "//foundation/graphic/lite/services/wms:wms_client", + "//base/hiviewdfx/frameworks/hilog_lite/featured:hilog_shared", + "//third_party/bounds_checking_function:libsec_shared", + "//foundation/communication/frameworks/ipc_lite:liteipc_adapter", + "//foundation/graphic/lite/frameworks/surface:litesurface", + "//foundation/graphic/lite/frameworks/ui:liteui", + "//foundation/graphic/lite/hals:graphic_hals", + "//foundation/distributedschedule/services/samgr_lite/samgr_client:client", + "//foundation/distributedschedule/services/samgr_lite/samgr:samgr", + "//foundation/distributedschedule/services/samgr_lite/communication/broadcast", + "//foundation/graphic/lite/tools/graphic_test_framework:litegraphictestframework", + ] + + cflags = [ "-fno-rtti"] +} diff --git a/uikit_lite/uibutton_posix/Test.json b/uikit_lite/uibutton_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..6164ffb2d127118971a7dde4c7a0d833c6b70d1d --- /dev/null +++ b/uikit_lite/uibutton_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for uikit uibutton test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/uikit", + "target": "/test_root/uikit" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/uikit/ActsUIButtonTest.bin" + } +} \ No newline at end of file diff --git a/uikit_lite/uibutton_posix/src/buttonTest.cpp b/uikit_lite/uibutton_posix/src/buttonTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..c376f1e541013271b9b8b2740b9863e6075c3afc --- /dev/null +++ b/uikit_lite/uibutton_posix/src/buttonTest.cpp @@ -0,0 +1,236 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "components/ui_button.h" +#include "core/system_booter.h" + +using namespace OHOS; +using namespace testing::ext; + +class ButtonTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + SystemBooter::Init(); + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_BUTTON_POSITION_0100 +* @tc.name test button position api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ButtonTest, testButtonPosition, TestSize.Level0){ + UIButton* button = new UIButton(); + EXPECT_EQ(button->GetX(), 0); + EXPECT_EQ(button->GetY(), 0); + + button->SetPosition(30, 200); + EXPECT_EQ(button->GetX(), 30); + EXPECT_EQ(button->GetY(), 200); + + button->SetX(60); + button->SetY(160); + EXPECT_EQ(button->GetX(), 60); + EXPECT_EQ(button->GetY(), 160); + + button->SetPosition(100, 200, 300, 400); + EXPECT_EQ(button->GetX(), 100); + EXPECT_EQ(button->GetY(), 200); + delete(button); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_BUTTON_SIZE_0100 +* @tc.name test button size api by normal value +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ButtonTest, testButtonSizeNormal, TestSize.Level0){ + UIButton* button = new UIButton(); + EXPECT_EQ(button->GetWidth(), -1); + EXPECT_EQ(button->GetHeight(), -1); + + button->SetWidth(90); + button->SetHeight(60); + EXPECT_EQ(button->GetWidth(), 90); + EXPECT_EQ(button->GetHeight(), 60); + + button->SetPosition(100, 200, 300, 400); + EXPECT_EQ(button->GetWidth(), 300); + EXPECT_EQ(button->GetHeight(), 400); + delete(button); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_BUTTON_SIZE_0200 +* @tc.name test button size api by abnormal value +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ButtonTest, testButtonSizeAbnormal, TestSize.Level0){ + UIButton* button = new UIButton(); + button->SetWidth(-90); + button->SetHeight(-60); + EXPECT_EQ(button->GetWidth(), -90); + EXPECT_EQ(button->GetHeight(), -60); + delete(button); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_BUTTON_STYLE_0100 +* @tc.name test button style api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ButtonTest, testButtonStyle, TestSize.Level0){ + UIButton* button = new UIButton(); + button->SetStyle(STYLE_BACKGROUND_OPA, 0); + button->SetStyle(STYLE_BACKGROUND_COLOR, 800); + button->SetStyle(STYLE_BORDER_RADIUS, 100); + button->SetStyle(STYLE_IMAGE_OPA, 190); + + EXPECT_EQ(button->GetStyle(STYLE_BACKGROUND_OPA), 0); + EXPECT_EQ(button->GetStyle(STYLE_BACKGROUND_COLOR), 800); + EXPECT_EQ(button->GetStyle(STYLE_BORDER_RADIUS), 100); + EXPECT_EQ(button->GetStyle(STYLE_IMAGE_OPA), 190); + delete(button); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_BUTTON_STYLE_0200 +* @tc.name test button style for release api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ButtonTest, testButtonStyleStateReleased, TestSize.Level0){ + UIButton* button = new UIButton(); + button->SetStyleForState(STYLE_BACKGROUND_OPA, 100, UIButton::RELEASED); + button->SetStyleForState(STYLE_BORDER_RADIUS, 200, UIButton::RELEASED); + button->SetStyleForState(STYLE_BACKGROUND_COLOR, 300, UIButton::RELEASED); + + EXPECT_EQ(button->GetStyleForState(STYLE_BACKGROUND_OPA, UIButton::RELEASED), 100); + EXPECT_EQ(button->GetStyleForState(STYLE_BORDER_RADIUS, UIButton::RELEASED), 200); + EXPECT_EQ(button->GetStyleForState(STYLE_BACKGROUND_COLOR, UIButton::RELEASED), 300); + delete(button); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_BUTTON_STYLE_0300 +* @tc.name test button style for pressed api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ButtonTest, testButtonStyleStatePressed, TestSize.Level0){ + UIButton* button = new UIButton(); + button->SetStyleForState(STYLE_BACKGROUND_OPA, 50, UIButton::PRESSED); + button->SetStyleForState(STYLE_BORDER_RADIUS, 100, UIButton::PRESSED); + button->SetStyleForState(STYLE_BACKGROUND_COLOR, 900, UIButton::PRESSED); + + EXPECT_EQ(button->GetStyleForState(STYLE_BACKGROUND_OPA, UIButton::PRESSED), 50); + EXPECT_EQ(button->GetStyleForState(STYLE_BORDER_RADIUS, UIButton::PRESSED), 100); + EXPECT_EQ(button->GetStyleForState(STYLE_BACKGROUND_COLOR, UIButton::PRESSED), 900); + delete(button); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_BUTTON_STYLE_0400 +* @tc.name test button style for inactivate api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ButtonTest, testButtonStyleStateInactive, TestSize.Level0){ + UIButton* button = new UIButton(); + button->SetStyleForState(STYLE_BACKGROUND_OPA, 150, UIButton::INACTIVE); + button->SetStyleForState(STYLE_BORDER_RADIUS, 800, UIButton::INACTIVE); + button->SetStyleForState(STYLE_BACKGROUND_COLOR, 1900, UIButton::INACTIVE); + + EXPECT_EQ(button->GetStyleForState(STYLE_BACKGROUND_OPA, UIButton::INACTIVE), 150); + EXPECT_EQ(button->GetStyleForState(STYLE_BORDER_RADIUS, UIButton::INACTIVE), 800); + EXPECT_EQ(button->GetStyleForState(STYLE_BACKGROUND_COLOR, UIButton::INACTIVE), 1900); + delete(button); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_BUTTON_IMAGE_POSITION_0100 +* @tc.name test button set image position api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ButtonTest, testButtonSetImagePosition, TestSize.Level0){ + UIButton* button = new UIButton(); + button->SetImagePosition(170, 190); + EXPECT_EQ(button->GetImageX(), 170); + EXPECT_EQ(button->GetImageY(), 190); + + button->SetImagePosition(-170, -190); + EXPECT_EQ(button->GetImageX(), -170); + EXPECT_EQ(button->GetImageY(), -190); + delete(button); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_BUTTON_IMAGE_SRC_0100 +* @tc.name test button set image src api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ButtonTest, testButtonSetImageSrc, TestSize.Level0){ + UIButton* button = new UIButton(); + char* path = nullptr; + button->SetImageSrc(path, path); + EXPECT_EQ(button->GetCurImageSrc()->GetPath(), nullptr); + button->SetImageSrc("/user/data/A021_028.bin", "/user/data/A021_029.bin"); + EXPECT_NE(button->GetCurImageSrc()->GetPath(), nullptr); + delete(button); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_BUTTON_TOUCHABLE_0100 +* @tc.name test button touchable api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ButtonTest, testButtonTouchable, TestSize.Level0){ + UIButton* button = new UIButton(); + EXPECT_EQ(button->IsTouchable(), true); + + button->Disable(); + EXPECT_EQ(button->IsTouchable(), false); + + button->Enable(); + EXPECT_EQ(button->IsTouchable(), true); + delete(button); +} \ No newline at end of file diff --git a/uikit_lite/uibutton_posix/src/checkBoxTest.cpp b/uikit_lite/uibutton_posix/src/checkBoxTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..ff9debc1dccec89946a5ef7a3765dff2eec4e1e3 --- /dev/null +++ b/uikit_lite/uibutton_posix/src/checkBoxTest.cpp @@ -0,0 +1,174 @@ + +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "components/root_view.h" +#include "components/ui_checkbox.h" +#include "components/ui_view_group.h" +#include "core/system_booter.h" + +using namespace OHOS; +using namespace testing::ext; + +class CheckBoxTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + SystemBooter::Init(); + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_CHECKBOX_POSITION_0100 +* @tc.name test checkbox position api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CheckBoxTest, testCheckBoxPosition, TestSize.Level0){ + UICheckBox* checkbox = new UICheckBox(); + EXPECT_EQ(checkbox->GetX(), 0); + EXPECT_EQ(checkbox->GetY(), 0); + + checkbox->SetPosition(30, 200); + EXPECT_EQ(checkbox->GetX(), 30); + EXPECT_EQ(checkbox->GetY(), 200); + + checkbox->SetX(60); + checkbox->SetY(160); + EXPECT_EQ(checkbox->GetX(), 60); + EXPECT_EQ(checkbox->GetY(), 160); + + checkbox->SetPosition(100, 200, 300, 400); + EXPECT_EQ(checkbox->GetX(), 100); + EXPECT_EQ(checkbox->GetY(), 200); + delete(checkbox); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_CHECKBOX_SIZE_0100 +* @tc.name test checkbox size api by normal value +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CheckBoxTest, testCheckBoxSizeNormal, TestSize.Level0){ + UICheckBox* checkbox = new UICheckBox(); + EXPECT_EQ(checkbox->GetWidth(), 56); + EXPECT_EQ(checkbox->GetHeight(), 56); + + checkbox->SetWidth(90); + checkbox->SetHeight(60); + EXPECT_EQ(checkbox->GetWidth(), 90); + EXPECT_EQ(checkbox->GetHeight(), 60); + + checkbox->SetPosition(100, 200, 300, 400); + EXPECT_EQ(checkbox->GetWidth(), 300); + EXPECT_EQ(checkbox->GetHeight(), 400); + delete(checkbox); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_CHECKBOX_SIZE_0100 +* @tc.name test checkbox size api by abnormal value +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CheckBoxTest, testCheckBoxSizeAbnormal, TestSize.Level0){ + UICheckBox* checkbox = new UICheckBox(); + checkbox->SetWidth(-90); + checkbox->SetHeight(-60); + EXPECT_EQ(checkbox->GetWidth(), -90); + EXPECT_EQ(checkbox->GetHeight(), -60); + delete(checkbox); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_CHECKBOX_STATE_0100 +* @tc.name test checkbox set state api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CheckBoxTest, testCheckBoxSetState, TestSize.Level0){ + UICheckBox* checkbox = new UICheckBox(); + EXPECT_EQ(checkbox->GetState(), UICheckBox::UNSELECTED); + + checkbox->SetState(UICheckBox::SELECTED); + EXPECT_EQ(checkbox->GetState(), UICheckBox::SELECTED); + + checkbox->SetState(UICheckBox::UNSELECTED); + EXPECT_EQ(checkbox->GetState(), UICheckBox::UNSELECTED); + delete(checkbox); +} + + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_CHECKBOX_STYLE_0100 +* @tc.name test checkbox style api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CheckBoxTest, testCheckBoxStyle, TestSize.Level0){ + UICheckBox* checkbox = new UICheckBox(); + checkbox->SetStyle(STYLE_BACKGROUND_OPA, 0); + checkbox->SetStyle(STYLE_BACKGROUND_COLOR, 200); + checkbox->SetStyle(STYLE_BORDER_RADIUS, 100); + checkbox->SetStyle(STYLE_IMAGE_OPA, 190); + + EXPECT_EQ(checkbox->GetStyle(STYLE_BACKGROUND_OPA), 0); + EXPECT_EQ(checkbox->GetStyle(STYLE_BACKGROUND_COLOR), 200); + EXPECT_EQ(checkbox->GetStyle(STYLE_BORDER_RADIUS), 100); + EXPECT_EQ(checkbox->GetStyle(STYLE_IMAGE_OPA), 190); + delete(checkbox); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_CHECKBOX_EVENT_0100 +* @tc.name test checkbox event api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CheckBoxTest, testCheckBoxEvent, TestSize.Level0){ + RootView* rootView = RootView::GetInstance(); + UIViewGroup* viewGroup = static_cast(rootView); + UICheckBox* checkbox1 = new UICheckBox(); + UICheckBox* checkbox2 = new UICheckBox(); + UICheckBox* checkbox3 = new UICheckBox(); + viewGroup->Add(checkbox1); + viewGroup->Add(checkbox2); + viewGroup->Add(checkbox3); + ClickEvent event({ 345, 430 }); + checkbox1->OnClickEvent(event); + checkbox2->OnClickEvent(event); + EXPECT_EQ(checkbox1->GetState(), UICheckBox::SELECTED); + EXPECT_EQ(checkbox2->GetState(), UICheckBox::SELECTED); + EXPECT_EQ(checkbox3->GetState(), UICheckBox::UNSELECTED); + delete(checkbox1); + delete(checkbox2); + delete(checkbox3); +} \ No newline at end of file diff --git a/uikit_lite/uibutton_posix/src/labelButtonTest.cpp b/uikit_lite/uibutton_posix/src/labelButtonTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..06939613409597bc421f948b48e0c49bbf2d8a67 --- /dev/null +++ b/uikit_lite/uibutton_posix/src/labelButtonTest.cpp @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "components/root_view.h" +#include "components/ui_label_button.h" +#include "font/ui_font.h" +#include "ui_text_language.h" + +using namespace OHOS; +using namespace testing::ext; + +class LabelButtonTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_LABELBUTTON_BABELBUTTON_SETTEXT_0100 +* @tc.name test label button set text api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(LabelButtonTest, testLabelButtonSetText, TestSize.Level0) { + const char* text = "abc"; + UILabelButton* labelBtn = new UILabelButton(); + labelBtn->SetText(text); + EXPECT_EQ(strcmp(labelBtn->GetText(), text), 0); + delete(labelBtn); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_LABELBUTTON_BABELBUTTON_SETLABELPOSITION_0100 +* @tc.name test label button set label position api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(LabelButtonTest, testLabelButtonSetLabelPosition, TestSize.Level0) { + UILabelButton* labelBtn = new UILabelButton(); + labelBtn->SetLablePosition(10, 20); + EXPECT_EQ(labelBtn->GetLabelPosition().x, 10); + EXPECT_EQ(labelBtn->GetLabelPosition().y, 20); + delete(labelBtn); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_LABELBUTTON_BABELBUTTON_SETALIGN_0100 +* @tc.name test label button set align api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(LabelButtonTest, testLabelButtonSetAlign, TestSize.Level0) { + UILabelButton* labelBtn = new UILabelButton(); + labelBtn->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_RIGHT); + EXPECT_EQ(labelBtn->GetAlign(), UITextLanguageAlignment::TEXT_ALIGNMENT_RIGHT); + delete(labelBtn); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_LABELBUTTON_BABELBUTTON_SETDIRECT_0100 +* @tc.name test label button set direct api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(LabelButtonTest, testLabelButtonSetDirect, TestSize.Level0) { + UILabelButton* labelBtn = new UILabelButton(); + labelBtn->SetDirect(UITextLanguageDirect::TEXT_DIRECT_RTL); + EXPECT_EQ(labelBtn->GetDirect(), UITextLanguageDirect::TEXT_DIRECT_RTL); + delete(labelBtn); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_LABELBUTTON_BABELBUTTON_SETFONT_0100 +* @tc.name test label button set font api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(LabelButtonTest, testLabelButtonSetFont, TestSize.Level0) { + UILabelButton* labelBtn = new UILabelButton(); + UITextLanguageFontId expectFontId = UITextLanguageFontId::F_HYQIHEI_65S_30_4; + labelBtn->SetFontId(expectFontId); + EXPECT_EQ(labelBtn->GetFontId(), expectFontId); + UITextLanguageFontId expectFontId2 = UITextLanguageFontId::F_HYQIHEI_65S_38_4; + labelBtn->SetFont("HYQiHei-65S", 38); + EXPECT_EQ(labelBtn->GetFontId(), expectFontId2); + delete(labelBtn); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_LABELBUTTON_BABELBUTTON_SETLABELSTYLE_0100 +* @tc.name test label button set label style api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(LabelButtonTest, testLabelButtonSetLabelStyle, TestSize.Level0) { + UILabelButton* labelBtn = new UILabelButton(); + Style &style = labelBtn->GetLabelStyle(); + style.rect.opacity = 0; + labelBtn->SetLabelStyle(style); + EXPECT_EQ(labelBtn->GetLabelStyle().rect.opacity, 0); + delete(labelBtn); +} \ No newline at end of file diff --git a/uikit_lite/uibutton_posix/src/radioButtonTest.cpp b/uikit_lite/uibutton_posix/src/radioButtonTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..8ac96b2eee7ceeb62ebd23c164b935aa7349e135 --- /dev/null +++ b/uikit_lite/uibutton_posix/src/radioButtonTest.cpp @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "components/root_view.h" +#include "components/ui_radiobutton.h" +#include "components/ui_view_group.h" +#include "core/system_booter.h" + +using namespace OHOS; +using namespace testing::ext; + +class RadioButtonTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + SystemBooter::Init(); + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_RADIOBUTTON_POSITION_0100 +* @tc.name test radio button position api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RadioButtonTest, testRadioButtonPosition, TestSize.Level0){ + UIRadioButton* radioButton = new UIRadioButton("aasd"); + EXPECT_EQ(radioButton->GetX(), 0); + EXPECT_EQ(radioButton->GetY(), 0); + + radioButton->SetPosition(30, 200); + EXPECT_EQ(radioButton->GetX(), 30); + EXPECT_EQ(radioButton->GetY(), 200); + + radioButton->SetX(60); + radioButton->SetY(160); + EXPECT_EQ(radioButton->GetX(), 60); + EXPECT_EQ(radioButton->GetY(), 160); + + radioButton->SetPosition(100, 200, 300, 400); + EXPECT_EQ(radioButton->GetX(), 100); + EXPECT_EQ(radioButton->GetY(), 200); + delete(radioButton); +} + + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_RADIOBUTTON_SIZE_0100 +* @tc.name test radio button size api by normal value +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RadioButtonTest, testRadioButtonSizeNormal, TestSize.Level0){ + UIRadioButton* radioButton = new UIRadioButton("aasd"); + EXPECT_EQ(radioButton->GetWidth(), 56); + EXPECT_EQ(radioButton->GetHeight(), 56); + + radioButton->SetWidth(90); + radioButton->SetHeight(60); + EXPECT_EQ(radioButton->GetWidth(), 90); + EXPECT_EQ(radioButton->GetHeight(), 60); + + radioButton->SetPosition(100, 200, 300, 400); + EXPECT_EQ(radioButton->GetWidth(), 300); + EXPECT_EQ(radioButton->GetHeight(), 400); + delete(radioButton); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_RADIOBUTTON_SIZE_0200 +* @tc.name test radio button size api by abnormal value +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RadioButtonTest, testRadioButtonSizeAbnormal, TestSize.Level0){ + UIRadioButton* radioButton = new UIRadioButton("aasd"); + radioButton->SetWidth(-90); + radioButton->SetHeight(-60); + EXPECT_EQ(radioButton->GetWidth(), -90); + EXPECT_EQ(radioButton->GetHeight(), -60); + delete(radioButton); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_RADIOBUTTON_STATE_0100 +* @tc.name test radio button set state api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RadioButtonTest, testRadioButtonSetState, TestSize.Level0){ + UIRadioButton* radioButton = new UIRadioButton("aasd"); + EXPECT_EQ(radioButton->GetState(), UIRadioButton::UNSELECTED); + + radioButton->SetState(UIRadioButton::SELECTED); + EXPECT_EQ(radioButton->GetState(), UIRadioButton::SELECTED); + + radioButton->SetState(UIRadioButton::UNSELECTED); + EXPECT_EQ(radioButton->GetState(), UIRadioButton::UNSELECTED); + delete(radioButton); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_RADIOBUTTON_STYLE_0100 +* @tc.name test radio button style api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RadioButtonTest, testRadioButtonStyle, TestSize.Level0){ + UIRadioButton* radioButton = new UIRadioButton("aasd"); + radioButton->SetStyle(STYLE_BACKGROUND_OPA, 0); + radioButton->SetStyle(STYLE_BACKGROUND_COLOR, 200); + radioButton->SetStyle(STYLE_BORDER_RADIUS, 100); + radioButton->SetStyle(STYLE_IMAGE_OPA, 190); + + EXPECT_EQ(radioButton->GetStyle(STYLE_BACKGROUND_OPA), 0); + EXPECT_EQ(radioButton->GetStyle(STYLE_BACKGROUND_COLOR), 200); + EXPECT_EQ(radioButton->GetStyle(STYLE_BORDER_RADIUS), 100); + EXPECT_EQ(radioButton->GetStyle(STYLE_IMAGE_OPA), 190); + delete(radioButton); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_RADIOBUTTON_EVENT_0100 +* @tc.name test radio button event api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RadioButtonTest, testRadioButtonEvent, TestSize.Level0){ + RootView* rootView = RootView::GetInstance(); + UIViewGroup* viewGroup = static_cast(rootView); + UIRadioButton* radioButton1 = new UIRadioButton("aasd"); + UIRadioButton* radioButton2 = new UIRadioButton("aasd"); + UIRadioButton* radioButton3 = new UIRadioButton("aasd"); + viewGroup->Add(radioButton1); + viewGroup->Add(radioButton2); + viewGroup->Add(radioButton3); + ClickEvent event({ 345, 430 }); + radioButton1->OnClickEvent(event); + EXPECT_EQ(radioButton1->GetState(), UICheckBox::SELECTED); + radioButton2->OnClickEvent(event); + EXPECT_EQ(radioButton1->GetState(), UICheckBox::UNSELECTED); + EXPECT_EQ(radioButton2->GetState(), UICheckBox::SELECTED); + EXPECT_EQ(radioButton3->GetState(), UICheckBox::UNSELECTED); + delete(radioButton1); + delete(radioButton2); + delete(radioButton3); +} \ No newline at end of file diff --git a/uikit_lite/uibutton_posix/src/toggleButtonTest.cpp b/uikit_lite/uibutton_posix/src/toggleButtonTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..6b94f8a93e798b9003d7ff7712a0c08b5ab4d33a --- /dev/null +++ b/uikit_lite/uibutton_posix/src/toggleButtonTest.cpp @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "components/ui_toggle_button.h" +#include "core/system_booter.h" +using namespace OHOS; +using namespace testing::ext; + +class ToggleButtonTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) + { + SystemBooter::Init(); + } + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_TOGGLEBUTTON_POSITION_0100 +* @tc.name test toggle button position api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ToggleButtonTest, testToggleButtonPosition, TestSize.Level0){ + UIToggleButton* togglebutton = new UIToggleButton(); + EXPECT_EQ(togglebutton->GetX(), 0); + EXPECT_EQ(togglebutton->GetY(), 0); + + togglebutton->SetPosition(30, 200); + EXPECT_EQ(togglebutton->GetX(), 30); + EXPECT_EQ(togglebutton->GetY(), 200); + + togglebutton->SetX(60); + togglebutton->SetY(160); + EXPECT_EQ(togglebutton->GetX(), 60); + EXPECT_EQ(togglebutton->GetY(), 160); + + togglebutton->SetPosition(100, 200, 300, 400); + EXPECT_EQ(togglebutton->GetX(), 100); + EXPECT_EQ(togglebutton->GetY(), 200); + delete(togglebutton); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_TOGGLEBUTTON_SIZE_0100 +* @tc.name test toggle button size api by normal value +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ToggleButtonTest, testToggleButtonSizeNormal, TestSize.Level0){ + UIToggleButton* togglebutton = new UIToggleButton(); + EXPECT_EQ(togglebutton->GetWidth(), 64); + EXPECT_EQ(togglebutton->GetHeight(), 64); + + togglebutton->SetWidth(90); + togglebutton->SetHeight(60); + EXPECT_EQ(togglebutton->GetWidth(), 90); + EXPECT_EQ(togglebutton->GetHeight(), 60); + + togglebutton->SetPosition(100, 200, 300, 400); + EXPECT_EQ(togglebutton->GetWidth(), 300); + EXPECT_EQ(togglebutton->GetHeight(), 400); + delete(togglebutton); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_TOGGLEBUTTON_SIZE_0200 +* @tc.name test toggle button size api by abnormal value +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ToggleButtonTest, testToggleButtonOSizeAbnormal, TestSize.Level0){ + UIToggleButton* togglebutton = new UIToggleButton(); + togglebutton->SetWidth(-90); + togglebutton->SetHeight(-60); + EXPECT_EQ(togglebutton->GetWidth(), -90); + EXPECT_EQ(togglebutton->GetHeight(), -60); + delete(togglebutton); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_TOGGLEBUTTON_STATE_0100 +* @tc.name test toggle button set state api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ToggleButtonTest, testToggleButtonSetState, TestSize.Level0){ + UIToggleButton* togglebutton = new UIToggleButton(); + EXPECT_EQ(togglebutton->GetState(), false); + + togglebutton->SetState(true); + EXPECT_EQ(togglebutton->GetState(), true); + + togglebutton->SetState(false); + EXPECT_EQ(togglebutton->GetState(), false); + delete(togglebutton); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_TOGGLEBUTTON_STYLE_0100 +* @tc.name test toggle button style api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ToggleButtonTest, testToggleButtonStyle, TestSize.Level0){ + UIToggleButton* togglebutton = new UIToggleButton(); + togglebutton->SetStyle(STYLE_BACKGROUND_OPA, 100); + togglebutton->SetStyle(STYLE_BACKGROUND_COLOR, 300); + togglebutton->SetStyle(STYLE_BORDER_RADIUS, 200); + + EXPECT_EQ(togglebutton->GetStyle(STYLE_BACKGROUND_OPA), 100); + EXPECT_EQ(togglebutton->GetStyle(STYLE_BACKGROUND_COLOR), 300); + EXPECT_EQ(togglebutton->GetStyle(STYLE_BORDER_RADIUS), 200); + + togglebutton->SetStyle(STYLE_BACKGROUND_OPA, 50); + togglebutton->SetStyle(STYLE_BACKGROUND_COLOR, 900); + togglebutton->SetStyle(STYLE_BORDER_RADIUS, 100); + + EXPECT_EQ(togglebutton->GetStyle(STYLE_BACKGROUND_OPA), 50); + EXPECT_EQ(togglebutton->GetStyle(STYLE_BACKGROUND_COLOR), 900); + EXPECT_EQ(togglebutton->GetStyle(STYLE_BORDER_RADIUS), 100); + + togglebutton->SetStyle(STYLE_BACKGROUND_OPA, 150); + togglebutton->SetStyle(STYLE_BACKGROUND_COLOR, 1900); + togglebutton->SetStyle(STYLE_BORDER_RADIUS, 800); + + EXPECT_EQ(togglebutton->GetStyle(STYLE_BACKGROUND_OPA), 150); + EXPECT_EQ(togglebutton->GetStyle(STYLE_BACKGROUND_COLOR), 1900); + EXPECT_EQ(togglebutton->GetStyle(STYLE_BORDER_RADIUS), 800); + + delete(togglebutton); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BUTTON_TOGGLEBUTTON_EVENT_0100 +* @tc.name test toggle button event api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ToggleButtonTest, testToggleButtonEvent, TestSize.Level0){ + UIToggleButton* togglebutton = new UIToggleButton(); + togglebutton->SetPosition(300, 400); + togglebutton->SetWidth(90); + togglebutton->SetHeight(60); + togglebutton->SetState(true); + ClickEvent event({310, 410}); + togglebutton->OnClickEvent(event); + EXPECT_EQ(togglebutton->GetState(), false); + delete(togglebutton); +} \ No newline at end of file diff --git a/uikit_lite/uicanvas_posix/BUILD.gn b/uikit_lite/uicanvas_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..ebf93920fd6e82857a576d203998559f25d4db90 --- /dev/null +++ b/uikit_lite/uicanvas_posix/BUILD.gn @@ -0,0 +1,71 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsUICanvasTest") { + suite_name = "acts" + sources = [ + "src/canvasTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "//foundation/graphic/lite/services/wms", + "//foundation/graphic/lite/services/wms/client/interfaces", + "//foundation/graphic/lite/interfaces/utils", + "//foundation/graphic/lite/interfaces", + "//foundation/graphic/lite/frameworks/ui/include", + "//foundation/graphic/lite/config", + "//foundation/graphic/lite/interfaces/ui", + "//foundation/graphic/lite/hals/include", + "//foundation/graphic/lite/huawei_proprietary/include", + "//foundation/graphic/lite/tools", + "//foundation/graphic/lite/frameworks/ui/src", + "//foundation/graphic/lite/services/ims/include", + "//third_party/bounds_checking_function/include", + "//foundation/graphic/lite/frameworks/surface/include", + "//utils/native/lite/include", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/registry", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/samgr", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/communication/broadcast", + "//vendor/hisi/hi35xx/hi3516dv300/Hi3516DV300_SDK_V6.0.0.1_B010/mpp/include" + ] + ldflags = [ + "-Wl,-Map=toggleButtonTest.map", + "-T", + ] + + ldflags += [ + "${ohos_root_path}build/lite/platform/hi3516dv300_liteos_a/init.ld", + "-L${ohos_root_path}vendor/hisi/camera/hi3516dv300/Hi3516DV300_SDK_V6.0.0.1_B010/mpp/lib", + "-ltde", "-lmpi", "-ldnvqe", "-lVoiceEngine", "-lupvqe" + ] + + deps = [ + "//foundation/graphic/lite/utils:litegraphicutils", + "//foundation/graphic/lite/services/wms:wms_client", + "//base/hiviewdfx/frameworks/hilog_lite/featured:hilog_shared", + "//third_party/bounds_checking_function:libsec_shared", + "//foundation/communication/frameworks/ipc_lite:liteipc_adapter", + "//foundation/graphic/lite/frameworks/surface:litesurface", + "//foundation/graphic/lite/frameworks/ui:liteui", + "//foundation/graphic/lite/hals:graphic_hals", + "//foundation/distributedschedule/services/samgr_lite/samgr_client:client", + "//foundation/distributedschedule/services/samgr_lite/samgr:samgr", + "//foundation/distributedschedule/services/samgr_lite/communication/broadcast", + "//foundation/graphic/lite/tools/graphic_test_framework:litegraphictestframework", + ] + + cflags = [ "-fno-rtti"] +} diff --git a/uikit_lite/uicanvas_posix/Test.json b/uikit_lite/uicanvas_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..8f81e6870a2d0c53479116ef46316c69ab047003 --- /dev/null +++ b/uikit_lite/uicanvas_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for uikit uicanvas test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/uikit", + "target": "/test_root/uikit" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/uikit/ActsUICanvasTest.bin" + } +} \ No newline at end of file diff --git a/uikit_lite/uicanvas_posix/src/canvasTest.cpp b/uikit_lite/uicanvas_posix/src/canvasTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..3a497138acd23a5abe5caf3d40358e045804b44e --- /dev/null +++ b/uikit_lite/uicanvas_posix/src/canvasTest.cpp @@ -0,0 +1,226 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "components/root_view.h" +#include "components/ui_canvas.h" +#include "components/ui_view_group.h" + +using namespace OHOS; +using namespace testing::ext; + +class CanvasTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_CANVAS_CANVAS_STYLE_0100 +* @tc.name test canvas style api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CanvasTest, testCanvasStyle, TestSize.Level0) { + Paint* paint = new Paint(); + Paint::PaintStyle paintStyle = Paint::PaintStyle::FILL_STYLE; + paint->SetStyle(Paint::PaintStyle::FILL_STYLE); + EXPECT_EQ(paint->GetStyle(), paintStyle); + delete(paint); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CANVAS_CANVAS_STROKEWIDTH_0100 +* @tc.name test canvas stroke width api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CanvasTest, testCanvasStrokeWidth, TestSize.Level0) { + Paint* paint = new Paint(); + uint16_t width = 10; + paint->SetStrokeWidth(width); + EXPECT_EQ(paint->GetStrokeWidth(), width); + delete(paint); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CANVAS_CANVAS_OPACITY_0100 +* @tc.name test canvas opacity api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CanvasTest, testCanvasOpacity, TestSize.Level0) { + Paint* paint = new Paint(); + uint8_t opacity = OPA_50; + paint->SetOpacity(OPA_50); + EXPECT_EQ(paint->GetOpacity(), opacity); + delete(paint); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CANVAS_CANVAS_FILLCOLOR_0100 +* @tc.name test canvas fill color api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CanvasTest, testCanvasFillColor, TestSize.Level0) { + Paint* paint = new Paint(); + ColorType color = Color::Red(); + paint->SetFillColor(color); + EXPECT_EQ(paint->GetFillColor().full, color.full); + delete(paint); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CANVAS_CANVAS_STROKECOLOR_0100 +* @tc.name test canvas stroke color api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CanvasTest, testCanvasStrokeColor, TestSize.Level0) { + Paint* paint = new Paint(); + ColorType color = Color::Red(); + paint->SetStrokeColor(color); + EXPECT_EQ(paint->GetStrokeColor().full, color.full); + delete(paint); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CANVAS_CANVAS_STARTPOSITION_0100 +* @tc.name test canvas start position api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CanvasTest, testCanvasStartPosition, TestSize.Level0) { + Paint* paint = new Paint(); + UICanvas* canvas = new UICanvas(); + canvas->SetStartPosition({ 50, 100 }); + EXPECT_EQ(canvas->GetStartPosition().x, 50); + EXPECT_EQ(canvas->GetStartPosition().y, 100); + delete(paint); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CANVAS_CANVAS_DRAWLINE_0200 +* @tc.name test canvas draw line position api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CanvasTest, testCanvasDrawLine, TestSize.Level0) { + RootView* rootView = RootView::GetInstance(); + UIViewGroup* viewGroup = static_cast(rootView); + viewGroup->SetPosition(0, 0); + UICanvas* canvas = new UICanvas(); + Paint paint; + canvas->DrawLine({ 0, 50 }, { 50, 100 }, paint); + viewGroup->Add(canvas); + EXPECT_EQ(canvas->GetStartPosition().x, 50); + viewGroup->Remove(canvas); + delete(canvas); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CANVAS_CANVAS_DRAWCURVE_0200 +* @tc.name test canvas draw curve api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CanvasTest, testCanvasDrawCurve, TestSize.Level0) { + RootView* rootView = RootView::GetInstance(); + UIViewGroup* viewGroup = static_cast(rootView); + viewGroup->SetPosition(0, 0); + UICanvas* canvas = new UICanvas(); + Paint paint; + canvas->DrawCurve({ 100, 100 }, { 150, 100 }, { 150, 100 }, { 150, 200 }, paint); + viewGroup->Add(canvas); + EXPECT_EQ(canvas->GetStartPosition().y, 200); + viewGroup->Remove(canvas); + delete(canvas); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CANVAS_CANVAS_DRAWRECT_0200 +* @tc.name test canvas draw rect api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CanvasTest, testCanvasDrawRect, TestSize.Level0) { + RootView* rootView = RootView::GetInstance(); + UIViewGroup* viewGroup = static_cast(rootView); + viewGroup->SetPosition(0, 0); + UICanvas* canvas = new UICanvas(); + Paint paint; + canvas->DrawRect({0, 50}, 50, 50, paint); + viewGroup->Add(canvas); + EXPECT_EQ(canvas->GetStartPosition().y, 0); + viewGroup->Remove(canvas); + delete(canvas); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CANVAS_CANVAS_DRAWCIRCLE_0200 +* @tc.name test canvas draw circle api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CanvasTest, testCanvasDrawCircle, TestSize.Level0) { + RootView* rootView = RootView::GetInstance(); + UIViewGroup* viewGroup = static_cast(rootView); + viewGroup->SetPosition(0, 0); + UICanvas* canvas = new UICanvas(); + Paint paint; + canvas->DrawCircle({50, 50}, 25, paint); + viewGroup->Add(canvas); + EXPECT_EQ(canvas->GetStartPosition().y, 0); + viewGroup->Remove(canvas); + delete(canvas); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CANVAS_CANVAS_DRAWSECTOR_0200 +* @tc.name test canvas draw sector api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CanvasTest, testCanvasDrawSector, TestSize.Level0) { + RootView* rootView = RootView::GetInstance(); + UIViewGroup* viewGroup = static_cast(rootView); + viewGroup->SetPosition(0, 0); + UICanvas* canvas = new UICanvas(); + Paint paint; + canvas->DrawSector({50, 0}, 50, 0, 90, paint); + viewGroup->Add(canvas); + EXPECT_EQ(canvas->GetStartPosition().y, 0); + viewGroup->Remove(canvas); + delete(canvas); +} \ No newline at end of file diff --git a/uikit_lite/uichart_posix/BUILD.gn b/uikit_lite/uichart_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..1baf9d9766db5ca0e62529485ac348cf8fca80fc --- /dev/null +++ b/uikit_lite/uichart_posix/BUILD.gn @@ -0,0 +1,71 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsUIChartTest") { + suite_name = "acts" + sources = [ + "src/chartTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "//foundation/graphic/lite/services/wms", + "//foundation/graphic/lite/services/wms/client/interfaces", + "//foundation/graphic/lite/interfaces/utils", + "//foundation/graphic/lite/interfaces", + "//foundation/graphic/lite/frameworks/ui/include", + "//foundation/graphic/lite/config", + "//foundation/graphic/lite/interfaces/ui", + "//foundation/graphic/lite/hals/include", + "//foundation/graphic/lite/huawei_proprietary/include", + "//foundation/graphic/lite/tools", + "//foundation/graphic/lite/frameworks/ui/src", + "//foundation/graphic/lite/services/ims/include", + "//third_party/bounds_checking_function/include", + "//foundation/graphic/lite/frameworks/surface/include", + "//utils/native/lite/include", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/registry", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/samgr", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/communication/broadcast", + "//vendor/hisi/hi35xx/hi3516dv300/Hi3516DV300_SDK_V6.0.0.1_B010/mpp/include" + ] + ldflags = [ + "-Wl,-Map=toggleButtonTest.map", + "-T", + ] + + ldflags += [ + "${ohos_root_path}build/lite/platform/hi3516dv300_liteos_a/init.ld", + "-L${ohos_root_path}vendor/hisi/camera/hi3516dv300/Hi3516DV300_SDK_V6.0.0.1_B010/mpp/lib", + "-ltde", "-lmpi", "-ldnvqe", "-lVoiceEngine", "-lupvqe" + ] + + deps = [ + "//foundation/graphic/lite/utils:litegraphicutils", + "//foundation/graphic/lite/services/wms:wms_client", + "//base/hiviewdfx/frameworks/hilog_lite/featured:hilog_shared", + "//third_party/bounds_checking_function:libsec_shared", + "//foundation/communication/frameworks/ipc_lite:liteipc_adapter", + "//foundation/graphic/lite/frameworks/surface:litesurface", + "//foundation/graphic/lite/frameworks/ui:liteui", + "//foundation/graphic/lite/hals:graphic_hals", + "//foundation/distributedschedule/services/samgr_lite/samgr_client:client", + "//foundation/distributedschedule/services/samgr_lite/samgr:samgr", + "//foundation/distributedschedule/services/samgr_lite/communication/broadcast", + "//foundation/graphic/lite/tools/graphic_test_framework:litegraphictestframework", + ] + + cflags = [ "-fno-rtti"] +} diff --git a/uikit_lite/uichart_posix/Test.json b/uikit_lite/uichart_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..dfbe65a5bd0dd6f2f653568b700f974949231390 --- /dev/null +++ b/uikit_lite/uichart_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for uikit uichart test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/uikit", + "target": "/test_root/uikit" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/uikit/ActsUIChartTest.bin" + } +} \ No newline at end of file diff --git a/uikit_lite/uichart_posix/src/chartTest.cpp b/uikit_lite/uichart_posix/src/chartTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..5168166ae7e073b431c5568f046e14d9ae6537b7 --- /dev/null +++ b/uikit_lite/uichart_posix/src/chartTest.cpp @@ -0,0 +1,482 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "components/root_view.h" +#include "components/ui_axis.h" +#include "components/ui_chart.h" +#include "components/ui_view_group.h" + +using namespace OHOS; +using namespace testing::ext; + +class ChartTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_CHART_CHART_ADDPOINTS_0100 +* @tc.name test chart add points api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ChartTest, testChartAddPoints, TestSize.Level0) { + UIChartDataSerial* data = new UIChartDataSerial(); + data->SetMaxDataCount(5); + bool ret = data->AddPoints(nullptr, 0); + EXPECT_EQ(ret, false); + + Point pointArray[5] = { {0, 2478}, {1, 2600}, {2, 3000}, {3, 3200}, {4, 3500} }; + ret = data->AddPoints(pointArray, 5); + EXPECT_EQ(ret, true); + + ret = data->AddPoints(pointArray, 1); + EXPECT_EQ(ret, false); + delete(data); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CHART_CHART_GETPOINT_0100 +* @tc.name test chart get point api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ChartTest, testChartGetPoint, TestSize.Level0) { + UIChartDataSerial* data = new UIChartDataSerial(); + data->SetMaxDataCount(5); + + Point pointArray[5] = { {0, 2478}, {1, 2600}, {2, 3000}, {3, 3200}, {4, 3500} }; + bool ret = data->AddPoints(pointArray, 5); + EXPECT_EQ(ret, true); + + Point point; + ret = data->GetPoint(1, point); + EXPECT_EQ(ret, true); + EXPECT_EQ(point.x, 1); + EXPECT_EQ(point.y, 2600); + delete(data); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CHART_CHART_MODIFYPOINT_0100 +* @tc.name test chart modify point api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ChartTest, testChartModifyPoint, TestSize.Level0) { + UIChartDataSerial* data = new UIChartDataSerial(); + data->SetMaxDataCount(5); + + Point pointArray[5] = { {0, 2478}, {1, 2600}, {2, 3000}, {3, 3200}, {4, 3500} }; + bool ret = data->AddPoints(pointArray, 5); + EXPECT_EQ(ret, true); + + Point point = { 1, 200 }; + ret = data->ModifyPoint(6, point); + EXPECT_EQ(ret, false); + + ret = data->ModifyPoint(1, point); + EXPECT_EQ(ret, true); + + Point point1; + ret = data->GetPoint(1, point1); + EXPECT_EQ(ret, true); + EXPECT_EQ(point1.x, 1); + EXPECT_EQ(point1.y, 200); + delete(data); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CHART_CHART_HIDEPOINTS_0100 +* @tc.name test chart hide points api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ChartTest, testChartHidePoints, TestSize.Level0) { + UIChartDataSerial* data = new UIChartDataSerial(); + data->SetMaxDataCount(5); + uint16_t index = 3; + uint16_t count = 5; + data->HidePoint(index, count); + EXPECT_EQ(data->GetHideIndex(), index); + EXPECT_EQ(data->GetHideCount(), count); + delete(data); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CHART_CHART_CLEARDATA_0100 +* @tc.name test chart clear data api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ChartTest, testChartClearData, TestSize.Level0) { + UIChartDataSerial* data = new UIChartDataSerial(); + data->SetMaxDataCount(5); + + Point pointArray[5] = { {0, 2478}, {1, 2600}, {2, 3000}, {3, 3200}, {4, 3500} }; + bool ret = data->AddPoints(pointArray, 5); + EXPECT_EQ(ret, true); + + data->ClearData(); + + Point point; + ret = data->GetPoint(1, point); + EXPECT_EQ(ret, false); + delete(data); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CHART_CHART_GETDATACOUNT_0100 +* @tc.name test chart get data count api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ChartTest, testChartGetDataCount, TestSize.Level0) { + UIChartDataSerial* data = new UIChartDataSerial(); + data->SetMaxDataCount(5); + + Point pointArray[5] = { {0, 2478}, {1, 2600}, {2, 3000}, {3, 3200}, {4, 3500} }; + bool ret = data->AddPoints(pointArray, 5); + EXPECT_EQ(ret, true); + + uint16_t count = data->GetDataCount(); + EXPECT_EQ(count, 5); + + data->ClearData(); + count = data->GetDataCount(); + EXPECT_EQ(count, 0); + delete(data); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CHART_CHART_ENABLESMOOTH_0100 +* @tc.name test chart enable smooth api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ChartTest, testChartEnableSmooth, TestSize.Level0) { + UIChartDataSerial* data = new UIChartDataSerial(); + data->SetMaxDataCount(5); + + data->EnableSmooth(true); + + bool ret = data->IsSmooth(); + EXPECT_EQ(ret, true); + delete(data); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CHART_CHART_GETPEAKINDEX_0100 +* @tc.name test chart get peak index api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ChartTest, testChartGetPeakIndex, TestSize.Level0) { + UIChartDataSerial* data = new UIChartDataSerial(); + data->SetMaxDataCount(5); + + Point pointArray[5] = { {0, 2478}, {1, 2600}, {2, 3000}, {3, 200}, {4, 1654} }; + bool ret = data->AddPoints(pointArray, 5); + EXPECT_EQ(ret, true); + + uint16_t index = data->GetPeakIndex(); + EXPECT_EQ(index, 2); + + int16_t value = data->GetPeakData(); + EXPECT_EQ(value, 3000); + delete(data); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CHART_CHART_GETVALLEYINDEX_0100 +* @tc.name test chart get valley index api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ChartTest, testChartGetValleyIndex, TestSize.Level0) { + UIChartDataSerial* data = new UIChartDataSerial(); + data->SetMaxDataCount(5); + + Point pointArray[5] = { {0, 2478}, {1, 2600}, {2, 3000}, {3, 200}, {4, 1654} }; + bool ret = data->AddPoints(pointArray, 5); + EXPECT_EQ(ret, true); + + uint16_t index = data->GetValleyIndex(); + EXPECT_EQ(index, 3); + + int16_t value = data->GetValleyData(); + EXPECT_EQ(value, 200); + delete(data); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CHART_CHART_GETLATESTINDEX_0100 +* @tc.name test chart get latest index api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ChartTest, testChartGetLatestIndex, TestSize.Level0) { + UIChartDataSerial* data = new UIChartDataSerial(); + data->SetMaxDataCount(5); + + Point pointArray[5] = { {0, 2478}, {1, 2600}, {2, 3000}, {3, 200}, {4, 1654} }; + bool ret = data->AddPoints(pointArray, 5); + EXPECT_EQ(ret, true); + + uint16_t index = data->GetLatestIndex(); + EXPECT_EQ(index, 4); + delete(data); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CHART_CHART_SETLASTPOINTINDEX_0100 +* @tc.name test chart set last point index api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ChartTest, testChartSetLastPointIndex, TestSize.Level0) { + UIChartDataSerial* data = new UIChartDataSerial(); + data->SetMaxDataCount(5); + Point pointArray[5] = { {0, 2478}, {1, 2600}, {2, 3000}, {3, 200}, {4, 1654} }; + bool ret = data->AddPoints(pointArray, 5); + EXPECT_EQ(ret, true); + + uint16_t index = data->GetLastPointIndex(); + EXPECT_EQ(index, 0); + + data->SetLastPointIndex(4); + EXPECT_EQ(data->GetLastPointIndex(), 4); + delete(data); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CHART_CHART_SETLINECOLOR_0100 +* @tc.name test chart set line color api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ChartTest, testChartSetLineColor, TestSize.Level0) { + UIChartDataSerial* data = new UIChartDataSerial(); + data->SetMaxDataCount(5); + ColorType color = Color::Red(); + data->SetLineColor(color); + EXPECT_EQ(data->GetLineColor().full, color.full); + delete(data); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CHART_CHART_SETFILLCOLOR_0100 +* @tc.name test chart set fill color api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ChartTest, testChartSetFillColor, TestSize.Level0) { + UIChartDataSerial* data = new UIChartDataSerial(); + data->SetMaxDataCount(5); + ColorType color = Color::Red(); + data->SetFillColor(color); + EXPECT_EQ(data->GetFillColor().full, color.full); + delete(data); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CHART_CHART_SETHEADPOINTSTYLE_0100 +* @tc.name test chart set head point style api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ChartTest, testChartSetHeadPointStyle, TestSize.Level0) { + UIChartDataSerial* data = new UIChartDataSerial(); + data->SetMaxDataCount(5); + + UIChartDataSerial::PointStyle pointStyle; + pointStyle.fillColor = Color::Red(); + pointStyle.radius = 5; + pointStyle.strokeColor = Color::White(); + pointStyle.strokeWidth = 10; + + data->SetHeadPointStyle(pointStyle); + + UIChartDataSerial::PointStyle pointStyle1 = data->GetHeadPointStyle(); + + EXPECT_EQ(pointStyle1.fillColor.full, pointStyle.fillColor.full); + EXPECT_EQ(pointStyle1.strokeColor.full, pointStyle.strokeColor.full); + EXPECT_EQ(pointStyle1.strokeWidth, pointStyle.strokeWidth); + EXPECT_EQ(pointStyle1.radius, pointStyle.radius); + delete(data); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CHART_CHART_SETTOPPOINTSTYLE_0100 +* @tc.name test chart set top point style api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ChartTest, testChartSetTopPointStyle, TestSize.Level0) { + UIChartDataSerial* data = new UIChartDataSerial(); + data->SetMaxDataCount(5); + UIChartDataSerial::PointStyle pointStyle; + pointStyle.fillColor = Color::Red(); + pointStyle.radius = 5; + pointStyle.strokeColor = Color::White(); + pointStyle.strokeWidth = 10; + data->SetTopPointStyle(pointStyle); + UIChartDataSerial::PointStyle pointStyle1 = data->GetTopPointStyle(); + EXPECT_EQ(pointStyle1.fillColor.full, pointStyle.fillColor.full); + EXPECT_EQ(pointStyle1.strokeColor.full, pointStyle.strokeColor.full); + EXPECT_EQ(pointStyle1.strokeWidth, pointStyle.strokeWidth); + EXPECT_EQ(pointStyle1.radius, pointStyle.radius); + delete(data); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CHART_CHART_SETBOTTOMPOINTSTYLE_0100 +* @tc.name test chart set bottmo point style api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ChartTest, testChartSetBottomPointStyle, TestSize.Level0) { + UIChartDataSerial* data = new UIChartDataSerial(); + data->SetMaxDataCount(5); + UIChartDataSerial::PointStyle pointStyle; + pointStyle.fillColor = Color::Red(); + pointStyle.radius = 5; + pointStyle.strokeColor = Color::White(); + pointStyle.strokeWidth = 10; + data->SetBottomPointStyle(pointStyle); + UIChartDataSerial::PointStyle pointStyle1 = data->GetBottomPointStyle(); + EXPECT_EQ(pointStyle1.fillColor.full, pointStyle.fillColor.full); + EXPECT_EQ(pointStyle1.strokeColor.full, pointStyle.strokeColor.full); + EXPECT_EQ(pointStyle1.strokeWidth, pointStyle.strokeWidth); + EXPECT_EQ(pointStyle1.radius, pointStyle.radius); + delete(data); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CHART_CHART_ADDDATASERIAL_0100 +* @tc.name test chart add data serial style api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ChartTest, testChartAddDataSerial, TestSize.Level0) { + UIChartDataSerial* data = new UIChartDataSerial(); + data->SetMaxDataCount(5); + UIChartPillar* chart = new UIChartPillar(); + bool ret = chart->AddDataSerial(nullptr); + EXPECT_EQ(ret, false); + ret= chart->AddDataSerial(data); + EXPECT_EQ(ret, true); + ret = chart->AddDataSerial(data); + EXPECT_EQ(ret, false); + delete(chart); + delete(data); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CHART_CHART_DELETEDATASERIAL_0100 +* @tc.name test chart delete data serial style api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ChartTest, testChartDeleteDataSerial, TestSize.Level0) { + UIChartDataSerial* data = new UIChartDataSerial(); + data->SetMaxDataCount(5); + UIChartPillar* chart = new UIChartPillar(); + bool ret = chart->DeleteDataSerial(nullptr); + EXPECT_EQ(ret, false); + ret = chart->DeleteDataSerial(data); + EXPECT_EQ(ret, false); + ret = chart->AddDataSerial(data); + EXPECT_EQ(ret, true); + ret = chart->DeleteDataSerial(data); + EXPECT_EQ(ret, true); + delete(chart); + delete(data); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CHART_CHART_CLEARDATASERIAL_0100 +* @tc.name test chart clear data serial style api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ChartTest, testChartClearDataSerial, TestSize.Level0) { + UIChartDataSerial* data = new UIChartDataSerial(); + data->SetMaxDataCount(5); + UIChartPillar* chart = new UIChartPillar(); + bool ret = chart->AddDataSerial(data); + EXPECT_EQ(ret, true); + chart->ClearDataSerial(); + ret = chart->DeleteDataSerial(data); + EXPECT_EQ(ret, false); + delete(chart); + delete(data); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CHART_CHART_SETHEIGHT_0100 +* @tc.name test chart height style api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ChartTest, testChartSetHeight, TestSize.Level0) { + UIChartPillar* chart = new UIChartPillar(); + chart->SetHeight(50); + EXPECT_EQ(chart->GetHeight(), 50); + delete(chart); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CHART_CHART_SETWIDTH_0100 +* @tc.name test chart width style api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ChartTest, testChartSetWidth, TestSize.Level0) { + UIChartPillar* chart = new UIChartPillar(); + chart->SetWidth(50); + EXPECT_EQ(chart->GetWidth(), 50); + delete(chart); +} \ No newline at end of file diff --git a/uikit_lite/uiclock_posix/BUILD.gn b/uikit_lite/uiclock_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..d5ce5fa27672bf45f5393fc96db724b9bcc8d44e --- /dev/null +++ b/uikit_lite/uiclock_posix/BUILD.gn @@ -0,0 +1,72 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsUIClockTest") { + suite_name = "acts" + sources = [ + "src/analogClockTest.cpp", + "src/digitalClockTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "//foundation/graphic/lite/services/wms", + "//foundation/graphic/lite/services/wms/client/interfaces", + "//foundation/graphic/lite/interfaces/utils", + "//foundation/graphic/lite/frameworks/ui/include", + "//foundation/graphic/lite/config", + "//foundation/graphic/lite/interfaces/ui", + "//foundation/graphic/lite/interfaces", + "//foundation/graphic/lite/hals/include", + "//foundation/graphic/lite/huawei_proprietary/include", + "//foundation/graphic/lite/tools", + "//foundation/graphic/lite/frameworks/ui/src", + "//foundation/graphic/lite/services/ims/include", + "//third_party/bounds_checking_function/include", + "//foundation/graphic/lite/frameworks/surface/include", + "//utils/native/lite/include", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/registry", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/samgr", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/communication/broadcast", + "//vendor/hisi/hi35xx/hi3516dv300/Hi3516DV300_SDK_V6.0.0.1_B010/mpp/include" + ] + ldflags = [ + "-Wl,-Map=toggleButtonTest.map", + "-T", + ] + + ldflags += [ + "${ohos_root_path}build/lite/platform/hi3516dv300_liteos_a/init.ld", + "-L${ohos_root_path}vendor/hisi/camera/hi3516dv300/Hi3516DV300_SDK_V6.0.0.1_B010/mpp/lib", + "-ltde", "-lmpi", "-ldnvqe", "-lVoiceEngine", "-lupvqe" + ] + + deps = [ + "//foundation/graphic/lite/utils:litegraphicutils", + "//foundation/graphic/lite/services/wms:wms_client", + "//base/hiviewdfx/frameworks/hilog_lite/featured:hilog_shared", + "//third_party/bounds_checking_function:libsec_shared", + "//foundation/communication/frameworks/ipc_lite:liteipc_adapter", + "//foundation/graphic/lite/frameworks/surface:litesurface", + "//foundation/graphic/lite/frameworks/ui:liteui", + "//foundation/graphic/lite/hals:graphic_hals", + "//foundation/distributedschedule/services/samgr_lite/samgr_client:client", + "//foundation/distributedschedule/services/samgr_lite/samgr:samgr", + "//foundation/distributedschedule/services/samgr_lite/communication/broadcast", + "//foundation/graphic/lite/tools/graphic_test_framework:litegraphictestframework", + ] + + cflags = [ "-fno-rtti"] +} diff --git a/uikit_lite/uiclock_posix/Test.json b/uikit_lite/uiclock_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..6be2b34e3bf4e0d53b0ab61923067b0bb389eb6c --- /dev/null +++ b/uikit_lite/uiclock_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for uikit uiclock test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/uikit", + "target": "/test_root/uikit" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/uikit/ActsUIClockTest.bin" + } +} \ No newline at end of file diff --git a/uikit_lite/uiclock_posix/src/analogClockTest.cpp b/uikit_lite/uiclock_posix/src/analogClockTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..0ca16d85f6a529252b6e81262584f4059fad2306 --- /dev/null +++ b/uikit_lite/uiclock_posix/src/analogClockTest.cpp @@ -0,0 +1,222 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "components/ui_abstract_clock.h" +#include "components/ui_analog_clock.h" +#include "components/ui_image_view.h" + +using namespace OHOS; +using namespace testing::ext; + +class AnalogClockTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_ANALOGCLOCK_ANALOGCLOCK_SETTIME24HOUR_0100 +* @tc.name test analog clock set time 24 hour api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(AnalogClockTest, testAnalogClockSetTime24Hour, TestSize.Level0) { + UIAnalogClock* clock = new UIAnalogClock(); + uint8_t currentHour = 14; + uint8_t currentMinute = 40; + uint8_t currentSecond = 30; + clock->SetTime24Hour(currentHour, currentMinute, currentSecond); + + EXPECT_EQ(clock->GetCurrentHour(), currentHour); + EXPECT_EQ(clock->GetCurrentMinute(), currentMinute); + EXPECT_EQ(clock->GetCurrentSecond(), currentSecond); + delete(clock); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_ANALOGCLOCK_ANALOGCLOCK_SETTIME12HOURAM_0100 +* @tc.name test analog clock set time 12 hour api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(AnalogClockTest, testAnalogClockSetTime12HourAM, TestSize.Level0) { + UIAnalogClock* clock = new UIAnalogClock(); + uint8_t currentHour = 10; + uint8_t currentMinute = 40; + uint8_t currentSecond = 30; + clock->SetTime12Hour(currentHour, currentMinute, currentSecond, true); + + EXPECT_EQ(clock->GetCurrentHour(), currentHour); + EXPECT_EQ(clock->GetCurrentMinute(), currentMinute); + EXPECT_EQ(clock->GetCurrentSecond(), currentSecond); + delete(clock); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_ANALOGCLOCK_ANALOGCLOCK_SETTIME12HOURPM_0100 +* @tc.name test analog clock set time 12 hour api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(AnalogClockTest, testAnalogClockSetTime12HourPM, TestSize.Level0) { + UIAnalogClock* clock = new UIAnalogClock(); + uint8_t currentHour = 10; + uint8_t currentMinute = 40; + uint8_t currentSecond = 30; + clock->SetTime12Hour(currentHour, currentMinute, currentSecond, false); + + EXPECT_EQ(clock->GetCurrentHour(), currentHour + 12); + EXPECT_EQ(clock->GetCurrentMinute(), currentMinute); + EXPECT_EQ(clock->GetCurrentSecond(), currentSecond); + delete(clock); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_ANALOGCLOCK_ANALOGCLOCK_SETWORKMODE_0100 +* @tc.name test analog clock set work mode api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(AnalogClockTest, testAnalogClockSetWorkMode, TestSize.Level0) { + UIAbstractClock* clock = new UIAbstractClock(); + clock->SetWorkMode(UIAbstractClock::NORMAL); + EXPECT_EQ(clock->GetWorkMode(), UIAbstractClock::NORMAL); + clock->SetWorkMode(UIAbstractClock::ALWAYS_ON); + EXPECT_EQ(clock->GetWorkMode(), UIAbstractClock::ALWAYS_ON); + delete(clock); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_ANALOGCLOCK_ANALOGCLOCK_SETHANDIMAGE_0100 +* @tc.name test analog clock set hand image api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(AnalogClockTest, testAnalogClockSetHandImage, TestSize.Level0) { + UIAnalogClock* clock = new UIAnalogClock(); + Point position = { 214, 3 }; + Point center = { 14, 223 }; + clock->SetHandLine(UIAnalogClock::HandType::SECOND_HAND, position, center, Color::White(), 1, 223, 255); + EXPECT_EQ(clock->GetHandPosition(UIAnalogClock::HandType::SECOND_HAND).x, position.x); + EXPECT_EQ(clock->GetHandPosition(UIAnalogClock::HandType::SECOND_HAND).y, position.y); + EXPECT_EQ(clock->GetHandRotateCenter(UIAnalogClock::HandType::SECOND_HAND).x, center.x); + EXPECT_EQ(clock->GetHandRotateCenter(UIAnalogClock::HandType::SECOND_HAND).y, center.y); + delete(clock); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_ANALOGCLOCK_ANALOGCLOCK_SETHANDLINE_0100 +* @tc.name test analog clock set hand line api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(AnalogClockTest, testAnalogClockSetHandLine, TestSize.Level0) { + UIAnalogClock* clock = new UIAnalogClock(); + Point position = { 214, 3 }; + Point center = { 14, 223 }; + UIImageView* image = new UIImageView(); + image->SetSrc("..\\config\\faces\\default\\B024_009.bin"); + clock->SetHandImage(UIAnalogClock::HandType::HOUR_HAND, *image, position, center); + EXPECT_EQ(clock->GetHandPosition(UIAnalogClock::HandType::HOUR_HAND).x, position.x); + EXPECT_EQ(clock->GetHandPosition(UIAnalogClock::HandType::HOUR_HAND).y, position.y); + EXPECT_EQ(clock->GetHandRotateCenter(UIAnalogClock::HandType::HOUR_HAND).x, center.x); + EXPECT_EQ(clock->GetHandRotateCenter(UIAnalogClock::HandType::HOUR_HAND).y, center.y); + delete(clock); + delete(image); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_ANALOGCLOCK_ANALOGCLOCK_SETINITTIME24HOUR_0100 +* @tc.name test analog clock set init time 24 hour api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(AnalogClockTest, testAnalogClockSetInitTime24Hour, TestSize.Level0) { + uint8_t initHour = 6; + uint8_t initMinute = 0; + uint8_t initSecond = 0; + UIAnalogClock* clock = new UIAnalogClock(); + clock->SetInitTime24Hour(initHour, initMinute, initSecond); + EXPECT_EQ(clock->GetCurrentHour(), initHour); + EXPECT_EQ(clock->GetCurrentMinute(), initMinute); + EXPECT_EQ(clock->GetCurrentSecond(), initSecond); + EXPECT_EQ(clock->GetHandInitAngle(UIAnalogClock::HandType::HOUR_HAND), 180); + EXPECT_EQ(clock->GetHandCurrentAngle(UIAnalogClock::HandType::HOUR_HAND), 180); + + uint8_t currentHour = 9; + uint8_t currentMinute = 0; + uint8_t currentSecond = 0; + clock->SetTime24Hour(currentHour, currentMinute, currentSecond); + EXPECT_EQ(clock->GetHandInitAngle(UIAnalogClock::HandType::HOUR_HAND), 180); + EXPECT_EQ(clock->GetHandCurrentAngle(UIAnalogClock::HandType::HOUR_HAND), 270); + delete(clock); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_ANALOGCLOCK_ANALOGCLOCK_SETINITTIME12HOUR_0100 +* @tc.name test analog clock set init time 12 hour api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(AnalogClockTest, testAnalogClockSetInitTime12HourAM, TestSize.Level0) { + uint8_t initHour = 6; + uint8_t initMinute = 0; + uint8_t initSecond = 0; + UIAnalogClock* clock = new UIAnalogClock(); + clock->SetInitTime12Hour(initHour, initMinute, initSecond, true); + EXPECT_EQ(clock->GetCurrentHour(), initHour); + EXPECT_EQ(clock->GetCurrentMinute(), initMinute); + EXPECT_EQ(clock->GetCurrentSecond(), initSecond); + EXPECT_EQ(clock->GetHandInitAngle(UIAnalogClock::HandType::HOUR_HAND), 180); + EXPECT_EQ(clock->GetHandCurrentAngle(UIAnalogClock::HandType::HOUR_HAND), 180); + delete(clock); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_ANALOGCLOCK_ANALOGCLOCK_SETINITTIME12HOUR_0200 +* @tc.name test analog clock set init time 12 hour api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(AnalogClockTest, testAnalogClockSetInitTime12HourPM, TestSize.Level0) { + uint8_t initHour = 6; + uint8_t initMinute = 0; + uint8_t initSecond = 0; + UIAnalogClock* clock = new UIAnalogClock(); + clock->SetInitTime12Hour(initHour, initMinute, initSecond, false); + EXPECT_EQ(clock->GetCurrentHour(), initHour + 12); + EXPECT_EQ(clock->GetCurrentMinute(), initMinute); + EXPECT_EQ(clock->GetCurrentSecond(), initSecond); + EXPECT_EQ(clock->GetHandInitAngle(UIAnalogClock::HandType::HOUR_HAND), 180); + EXPECT_EQ(clock->GetHandCurrentAngle(UIAnalogClock::HandType::HOUR_HAND), 180); + delete(clock); +} \ No newline at end of file diff --git a/uikit_lite/uiclock_posix/src/digitalClockTest.cpp b/uikit_lite/uiclock_posix/src/digitalClockTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..d096d12a1cfee7856a4ea4ed6a3a796a241946af --- /dev/null +++ b/uikit_lite/uiclock_posix/src/digitalClockTest.cpp @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "gtest/gtest.h" +#include +#include "components/root_view.h" +#include "components/ui_digital_clock.h" +#include "components/ui_view_group.h" +#include "font/ui_font.h" + +using namespace OHOS; +using namespace testing::ext; + +class DigitalClockTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_DIGITALCLOCK_DIGITALCLOCK_DISPLAYMODE_0100 +* @tc.name test digital clock display mode api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(DigitalClockTest, testDigitalClockDisplayMode, TestSize.Level0) { + UIDigitalClock *clock = new UIDigitalClock(); + clock->SetDisplayMode(UIDigitalClock::DisplayMode::DISPLAY_12_HOUR_NO_SECONDS); + EXPECT_EQ(clock->GetDisplayMode(), UIDigitalClock::DisplayMode::DISPLAY_12_HOUR_NO_SECONDS); + clock->SetDisplayMode(UIDigitalClock::DisplayMode::DISPLAY_24_HOUR_NO_SECONDS); + EXPECT_EQ(clock->GetDisplayMode(), UIDigitalClock::DisplayMode::DISPLAY_24_HOUR_NO_SECONDS); + clock->SetDisplayMode(UIDigitalClock::DisplayMode::DISPLAY_12_HOUR); + EXPECT_EQ(clock->GetDisplayMode(), UIDigitalClock::DisplayMode::DISPLAY_12_HOUR); + clock->SetDisplayMode(UIDigitalClock::DisplayMode::DISPLAY_24_HOUR); + EXPECT_EQ(clock->GetDisplayMode(), UIDigitalClock::DisplayMode::DISPLAY_24_HOUR); + delete(clock); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_DIGITALCLOCK_DIGITALCLOCK_OPACITY_0100 +* @tc.name test digital clock set opacity api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(DigitalClockTest, testDigitalClockSetOpacity, TestSize.Level0) { + uint8_t opacity = 255; + UIDigitalClock *clock = new UIDigitalClock(); + clock->SetOpacity(opacity); + EXPECT_EQ(clock->GetOpacity(), opacity); + delete(clock); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_DIGITALCLOCK_DIGITALCLOCK_SETTIME24HOUR_0100 +* @tc.name test digital clock set time 24 hour api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(DigitalClockTest, testDigitalClockSetTime24Hour, TestSize.Level0) { + UIDigitalClock *clock = new UIDigitalClock(); + uint8_t currentHour = 14; + uint8_t currentMinute = 40; + uint8_t currentSecond = 30; + clock->SetTime24Hour(currentHour, currentMinute, currentSecond); + EXPECT_EQ(clock->GetCurrentHour(), currentHour); + EXPECT_EQ(clock->GetCurrentMinute(), currentMinute); + EXPECT_EQ(clock->GetCurrentSecond(), currentSecond); + delete(clock); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_DIGITALCLOCK_DIGITALCLOCK_SETTIME12HOURAM_0100 +* @tc.name test digital clock set time 12 hour api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(DigitalClockTest, testDigitalClockSetTime12HourAM, TestSize.Level0) { + UIDigitalClock *clock = new UIDigitalClock(); + uint8_t currentHour = 14; + uint8_t currentMinute = 40; + uint8_t currentSecond = 30; + clock->SetTime12Hour(currentHour, currentMinute, currentSecond, true); + EXPECT_EQ(clock->GetCurrentHour(), currentHour-12); + EXPECT_EQ(clock->GetCurrentMinute(), currentMinute); + EXPECT_EQ(clock->GetCurrentSecond(), currentSecond); + delete(clock); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_DIGITALCLOCK_DIGITALCLOCK_SETTIME12HOURPM_0100 +* @tc.name test digital clock set time 12 hour api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(DigitalClockTest, testDigitalClockSetTime12HourPM, TestSize.Level0) { + UIDigitalClock *clock = new UIDigitalClock(); + uint8_t currentHour = 10; + uint8_t currentMinute = 40; + uint8_t currentSecond = 30; + clock->SetTime12Hour(currentHour, currentMinute, currentSecond, false); + + EXPECT_EQ(clock->GetCurrentHour(), currentHour + 12); + EXPECT_EQ(clock->GetCurrentMinute(), currentMinute); + EXPECT_EQ(clock->GetCurrentSecond(), currentSecond); + delete(clock); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_DIGITALCLOCK_DIGITALCLOCK_SETFONTID_0200 +* @tc.name test digital clock set font id api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(DigitalClockTest, testDigitalClockSetFontId, TestSize.Level0) { + UIDigitalClock *clock = new UIDigitalClock(); + uint8_t fontId = 0; + clock->SetFontId(fontId); + EXPECT_EQ(clock->GetStyle(STYLE_TEXT_FONT), 0); + delete(clock); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_DIGITALCLOCK_DIGITALCLOCK_SETWORKMODE_0200 +* @tc.name test digital clock set work mode api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(DigitalClockTest, testDigitalClockSetWorkMode, TestSize.Level0) { + UIDigitalClock *clock = new UIDigitalClock(); + + clock->SetWorkMode(UIAbstractClock::ALWAYS_ON); + EXPECT_EQ(clock->GetWorkMode(), UIAbstractClock::ALWAYS_ON); + delete(clock); +} diff --git a/uikit_lite/uiimage_posix/BUILD.gn b/uikit_lite/uiimage_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..a092ff2da834dcd0d94825174e7a9eb7245842e8 --- /dev/null +++ b/uikit_lite/uiimage_posix/BUILD.gn @@ -0,0 +1,72 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsUIImageTest") { + suite_name = "acts" + sources = [ + "src/imageViewTest.cpp", + "src/imageAnimatorTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "//foundation/graphic/lite/services/wms", + "//foundation/graphic/lite/services/wms/client/interfaces", + "//foundation/graphic/lite/interfaces/utils", + "//foundation/graphic/lite/frameworks/ui/include", + "//foundation/graphic/lite/config", + "//foundation/graphic/lite/interfaces/ui", + "//foundation/graphic/lite/interfaces", + "//foundation/graphic/lite/hals/include", + "//foundation/graphic/lite/huawei_proprietary/include", + "//foundation/graphic/lite/tools", + "//foundation/graphic/lite/frameworks/ui/src", + "//foundation/graphic/lite/services/ims/include", + "//third_party/bounds_checking_function/include", + "//foundation/graphic/lite/frameworks/surface/include", + "//utils/native/lite/include", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/registry", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/samgr", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/communication/broadcast", + "//vendor/hisi/hi35xx/hi3516dv300/Hi3516DV300_SDK_V6.0.0.1_B010/mpp/include" + ] + ldflags = [ + "-Wl,-Map=toggleButtonTest.map", + "-T", + ] + + ldflags += [ + "${ohos_root_path}build/lite/platform/hi3516dv300_liteos_a/init.ld", + "-L${ohos_root_path}vendor/hisi/camera/hi3516dv300/Hi3516DV300_SDK_V6.0.0.1_B010/mpp/lib", + "-ltde", "-lmpi", "-ldnvqe", "-lVoiceEngine", "-lupvqe" + ] + + deps = [ + "//foundation/graphic/lite/utils:litegraphicutils", + "//foundation/graphic/lite/services/wms:wms_client", + "//base/hiviewdfx/frameworks/hilog_lite/featured:hilog_shared", + "//third_party/bounds_checking_function:libsec_shared", + "//foundation/communication/frameworks/ipc_lite:liteipc_adapter", + "//foundation/graphic/lite/frameworks/surface:litesurface", + "//foundation/graphic/lite/frameworks/ui:liteui", + "//foundation/graphic/lite/hals:graphic_hals", + "//foundation/distributedschedule/services/samgr_lite/samgr_client:client", + "//foundation/distributedschedule/services/samgr_lite/samgr:samgr", + "//foundation/distributedschedule/services/samgr_lite/communication/broadcast", + "//foundation/graphic/lite/tools/graphic_test_framework:litegraphictestframework", + ] + + cflags = [ "-fno-rtti"] +} diff --git a/uikit_lite/uiimage_posix/Test.json b/uikit_lite/uiimage_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..f08d30824ab6f804a9a877a1eb0d5cb87d41d10a --- /dev/null +++ b/uikit_lite/uiimage_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for uikit uiimage view test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/uikit", + "target": "/test_root/uikit" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/uikit/ActsUIImageTest.bin" + } +} \ No newline at end of file diff --git a/uikit_lite/uiimage_posix/src/imageAnimatorTest.cpp b/uikit_lite/uiimage_posix/src/imageAnimatorTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..b417066c5a6ad5b95ad4851f45170c613938e9b5 --- /dev/null +++ b/uikit_lite/uiimage_posix/src/imageAnimatorTest.cpp @@ -0,0 +1,204 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "components/ui_image_animator.h" + +using namespace OHOS; +using namespace testing::ext; + +class ImageAnimatorTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} + ImageAnimatorInfo imageAnimatorInfoData[4] = { + { "..\\config\\images\\A021_001.bin", {50, 50}, 116, 116 }, + { "..\\config\\images\\A021_002.bin", {50, 50}, 116, 116 }, + { "..\\config\\images\\A021_003.bin", {50, 50}, 116, 116 }, + { "..\\config\\images\\A021_004.bin", {50, 50}, 116, 116 }, + }; +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGEANIMATOR_IMAGEANIMATOR_TIMEOFUPDATE_0100 +* @tc.name test image animator time of update api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageAnimatorTest, testImageAnimatorTimeOfUpdate, TestSize.Level0) { + UIImageAnimatorView* imageAnimator = new UIImageAnimatorView(); + uint16_t time = 300; + imageAnimator->SetTimeOfUpdate(time); + + EXPECT_EQ(imageAnimator->GetTimeOfUpdate(), time); + delete(imageAnimator); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGEANIMATOR_IMAGEANIMATOR_IMAGEANIMATORSRC_0100 +* @tc.name test image animator image animator src api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageAnimatorTest, testImageAnimatorImageAnimatorSrc, TestSize.Level0) { + UIImageAnimatorView* imageAnimator = new UIImageAnimatorView(); + uint8_t imageNum = 4; + imageAnimator->SetImageAnimatorSrc(reinterpret_cast(&imageAnimatorInfoData[0]), imageNum); + + EXPECT_EQ(imageAnimator->GetImageAnimatorImageNum(), imageNum); + delete(imageAnimator); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGEANIMATOR_IMAGEANIMATOR_IMAGEANIMATORSRC_0200 +* @tc.name test image animator image animator src api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageAnimatorTest, testImageAnimatorImageAnimatorSrc2, TestSize.Level0) { + UIImageAnimatorView* imageAnimator = new UIImageAnimatorView(); + ImageAnimatorInfo* info = &imageAnimatorInfoData[0]; + imageAnimator->SetImageAnimatorSrc(reinterpret_cast(&imageAnimatorInfoData[0]), 4); + EXPECT_EQ(imageAnimator->GetImageAnimatorSrc(), info); + delete(imageAnimator); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGEANIMATOR_IMAGEANIMATOR_SIZEFIXED_0200 +* @tc.name test image animator size fixed api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageAnimatorTest, testImageAnimatorSzieFixed, TestSize.Level0) { + UIImageAnimatorView* imageAnimator = new UIImageAnimatorView(); + bool fixed = true; + imageAnimator->SetSizeFixed(fixed); + + EXPECT_EQ(imageAnimator->IsSizeFixed(), fixed); + delete(imageAnimator); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGEANIMATOR_IMAGEANIMATOR_REPEAT_0200 +* @tc.name test image animator repeat api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageAnimatorTest, testImageAnimatorRepeat, TestSize.Level0) { + UIImageAnimatorView* imageAnimator = new UIImageAnimatorView(); + bool repeat = true; + imageAnimator->SetRepeat(repeat); + + EXPECT_EQ(imageAnimator->IsRepeat(), repeat); + delete(imageAnimator); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGEANIMATOR_IMAGEANIMATOR_REVERSE_0200 +* @tc.name test image animator reverse api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageAnimatorTest, testImageAnimatorReverse, TestSize.Level0) { + UIImageAnimatorView* imageAnimator = new UIImageAnimatorView(); + bool reverse = true; + imageAnimator->SetReverse(reverse); + + EXPECT_EQ(imageAnimator->IsReverse(), reverse); + delete(imageAnimator); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGEANIMATOR_IMAGEANIMATOR_STATE_0200 +* @tc.name test image animator state api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageAnimatorTest, testImageAnimatorState, TestSize.Level0) { + UIImageAnimatorView* imageAnimator = new UIImageAnimatorView(); + uint8_t state = Animator::STOP; + EXPECT_EQ(imageAnimator->GetState(), state); + delete(imageAnimator); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGEANIMATOR_IMAGEANIMATOR_START_0200 +* @tc.name test image animator start api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageAnimatorTest, testImageAnimatorStart, TestSize.Level0) { + UIImageAnimatorView* imageAnimator = new UIImageAnimatorView(); + imageAnimator->Start(); + EXPECT_EQ(imageAnimator->GetState(), Animator::START); + delete(imageAnimator); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGEANIMATOR_IMAGEANIMATOR_STOP_0200 +* @tc.name test image animator stop api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageAnimatorTest, testImageAnimatorStop, TestSize.Level0) { + UIImageAnimatorView* imageAnimator = new UIImageAnimatorView(); + imageAnimator->Stop(true); + EXPECT_EQ(imageAnimator->GetState(), Animator::STOP); + delete(imageAnimator); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGEANIMATOR_IMAGEANIMATOR_PAUSE_0200 +* @tc.name test image animator pause api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageAnimatorTest, testImageAnimatorPause, TestSize.Level0) { + UIImageAnimatorView* imageAnimator = new UIImageAnimatorView(); + imageAnimator->Pause(); + EXPECT_EQ(imageAnimator->GetState(), Animator::PAUSE); + delete(imageAnimator); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGEANIMATOR_IMAGEANIMATOR_RESUME_0200 +* @tc.name test image animator resume api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageAnimatorTest, testImageAnimatorResume, TestSize.Level0) { + UIImageAnimatorView* imageAnimator = new UIImageAnimatorView(); + imageAnimator->Resume(); + EXPECT_EQ(imageAnimator->GetState(), Animator::START); + delete(imageAnimator); +} \ No newline at end of file diff --git a/uikit_lite/uiimage_posix/src/imageViewTest.cpp b/uikit_lite/uiimage_posix/src/imageViewTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..60586129a6a83e45547beaa697a7fbc5e126ba0b --- /dev/null +++ b/uikit_lite/uiimage_posix/src/imageViewTest.cpp @@ -0,0 +1,294 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "components/ui_image_view.h" + +using namespace OHOS; +using namespace testing::ext; + +class ImageViewTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGE_IMAGE_POSITION_0100 +* @tc.name test image option api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageViewTest, testImagePosition, TestSize.Level0) { + UIImageView* imageView = new UIImageView(); + imageView->SetPosition(10, 10); + imageView->SetHeight(100); + imageView->SetWidth(200); + + EXPECT_EQ(imageView->GetX(), 10); + EXPECT_EQ(imageView->GetY(), 10); + + imageView->SetPosition(30, 50, 70, 90); + EXPECT_EQ(imageView->GetX(), 30); + EXPECT_EQ(imageView->GetY(), 50); + delete(imageView); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGE_IMAGE_SIZE_0100 +* @tc.name test image option api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageViewTest, testImageSize, TestSize.Level0) { + UIImageView* imageView = new UIImageView(); + imageView->SetHeight(100); + imageView->SetWidth(200); + EXPECT_EQ(imageView->GetHeight(), 100); + EXPECT_EQ(imageView->GetWidth(), 200); + + imageView->SetPosition(30, 50, 70, 90); + EXPECT_EQ(imageView->GetWidth(), 70); + EXPECT_EQ(imageView->GetHeight(), 90); + delete(imageView); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGE_IMAGE_RESIZE_0100 +* @tc.name test image option api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageViewTest, testImageReSize, TestSize.Level0) { + UIImageView* imageView = new UIImageView(); + imageView->SetHeight(100); + imageView->SetWidth(200); + imageView->Resize(100, 300); + EXPECT_EQ(imageView->GetWidth(), 100); + EXPECT_EQ(imageView->GetHeight(), 300); + delete(imageView); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGE_IMAGE_PATH_0100 +* @tc.name test image path api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageViewTest, testImagePath, TestSize.Level0) { + UIImageView* imageView = new UIImageView(); + char* srcPath = nullptr; + imageView->SetSrc(srcPath); + EXPECT_EQ(imageView->GetPath(), nullptr); + + ImageInfo* srcPath2 = nullptr; + imageView->SetSrc(srcPath2); + EXPECT_EQ(imageView->GetPath(), nullptr); + + imageView->SetSrc("..\\config\\images\\A021_001.bin"); + EXPECT_NE(imageView->GetPath(), nullptr); + + imageView->SetSrc("..\\config\\images\\A021_001.bin"); + EXPECT_NE(imageView->GetPath(), nullptr); + delete(imageView); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGE_IMAGE_AUTOENABLE_0100 +* @tc.name test image auto enable api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageViewTest, testImageAutoEnable, TestSize.Level0) { + UIImageView* imageView = new UIImageView(); + imageView->SetAutoEnable(true); + EXPECT_EQ(imageView->GetAutoEnable(), true); + delete(imageView); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGE_IMAGE_PARENT_0100 +* @tc.name test image parent api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageViewTest, testImageParent, TestSize.Level0) { + UIImageView* imageView = new UIImageView(); + + imageView->SetParent(nullptr); + EXPECT_EQ(imageView->GetParent(), nullptr); + + UIView uiView; + imageView->SetParent(&uiView); + EXPECT_NE(imageView->GetParent(), nullptr); + delete(imageView); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGE_IMAGE_NEXTSIBLING_0100 +* @tc.name test image next sibling api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageViewTest, testImageNextSibling, TestSize.Level0) { + UIImageView* imageView = new UIImageView(); + imageView->SetNextSibling(nullptr); + EXPECT_EQ(imageView->GetNextSibling(), nullptr); + + UIView uiView; + imageView->SetNextSibling(&uiView); + EXPECT_NE(imageView->GetNextSibling(), nullptr); + delete(imageView); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGE_IMAGE_VISIBLE_0100 +* @tc.name test image visible api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageViewTest, testImageVisible, TestSize.Level0) { + UIImageView* imageView = new UIImageView(); + imageView->SetVisible(true); + EXPECT_EQ(imageView->IsVisible(), true); + + imageView->SetVisible(false); + EXPECT_EQ(imageView->IsVisible(), false); + delete(imageView); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGE_IMAGE_TOUCHABLE_0100 +* @tc.name test image touchable api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageViewTest, testImageTouchable, TestSize.Level0) { + UIImageView* imageView = new UIImageView(); + imageView->SetTouchable(true); + EXPECT_EQ(imageView->IsTouchable(), true); + + imageView->SetTouchable(false); + EXPECT_EQ(imageView->IsTouchable(), false); + delete(imageView); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGE_IMAGE_DRAGGABLE_0100 +* @tc.name test image draggable api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageViewTest, testImageDraggable, TestSize.Level0) { + UIImageView* imageView = new UIImageView(); + imageView->SetDraggable(true); + EXPECT_EQ(imageView->IsDraggable(), true); + + imageView->SetDraggable(false); + EXPECT_EQ(imageView->IsDraggable(), false); + delete(imageView); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGE_IMAGE_DRAGPARENTINSTREAD_0100 +* @tc.name test image drag parent instead api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageViewTest, testImageDragParentInstead, TestSize.Level0) { + UIImageView* imageView = new UIImageView(); + imageView->SetDragParentInstead(true); + EXPECT_EQ(imageView->IsDragParentInstead(), true); + + imageView->SetDragParentInstead(false); + EXPECT_EQ(imageView->IsDragParentInstead(), false); + delete(imageView); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGE_IMAGE_LISTENER_0100 +* @tc.name test image listener api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageViewTest, testImageListener, TestSize.Level0) { + UIImageView* imageView = new UIImageView(); + imageView->SetOnDragListener(nullptr); + EXPECT_EQ(imageView->GetOnDragListener(), nullptr); + + imageView->SetOnClickListener(nullptr); + EXPECT_EQ(imageView->GetOnClickListener(), nullptr); + + imageView->SetOnLongPressListener(nullptr); + EXPECT_EQ(imageView->GetOnLongPressListener(), nullptr); + delete(imageView); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGE_IMAGE_VIEW_0100 +* @tc.name test image view api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageViewTest, testImageViewTest1, TestSize.Level0) { + UIImageView* imageView = new UIImageView(); + imageView->SetViewId(nullptr); + EXPECT_EQ(imageView->GetViewId(), nullptr); + + imageView->SetViewIndex(101); + EXPECT_EQ(imageView->GetViewIndex(), 101); + delete(imageView); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_IMAGE_IMAGE_STYLE_0100 +* @tc.name test image style api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ImageViewTest, testImageViewTest2, TestSize.Level0) { + UIImageView* imageView = new UIImageView(); + imageView->SetStyle(STYLE_BACKGROUND_OPA, 0); + imageView->SetStyle(STYLE_BACKGROUND_COLOR, 800); + imageView->SetStyle(STYLE_BORDER_RADIUS, 100); + imageView->SetStyle(STYLE_IMAGE_OPA, 190); + + EXPECT_EQ(imageView->GetStyle(STYLE_BACKGROUND_OPA), 0); + EXPECT_EQ(imageView->GetStyle(STYLE_BACKGROUND_COLOR), 800); + EXPECT_EQ(imageView->GetStyle(STYLE_BORDER_RADIUS), 100); + EXPECT_EQ(imageView->GetStyle(STYLE_IMAGE_OPA), 190); + delete(imageView); +} \ No newline at end of file diff --git a/uikit_lite/uilayout_posix/BUILD.gn b/uikit_lite/uilayout_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..83dda504db65b77d708e4e02ea7089d7e0c03a26 --- /dev/null +++ b/uikit_lite/uilayout_posix/BUILD.gn @@ -0,0 +1,71 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsUILayoutTest") { + suite_name = "acts" + sources = [ + "src/listTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "//foundation/graphic/lite/services/wms", + "//foundation/graphic/lite/services/wms/client/interfaces", + "//foundation/graphic/lite/interfaces/utils", + "//foundation/graphic/lite/frameworks/ui/include", + "//foundation/graphic/lite/config", + "//foundation/graphic/lite/interfaces/ui", + "//foundation/graphic/lite/interfaces", + "//foundation/graphic/lite/hals/include", + "//foundation/graphic/lite/huawei_proprietary/include", + "//foundation/graphic/lite/tools", + "//foundation/graphic/lite/frameworks/ui/src", + "//foundation/graphic/lite/services/ims/include", + "//third_party/bounds_checking_function/include", + "//foundation/graphic/lite/frameworks/surface/include", + "//utils/native/lite/include", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/registry", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/samgr", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/communication/broadcast", + "//vendor/hisi/hi35xx/hi3516dv300/Hi3516DV300_SDK_V6.0.0.1_B010/mpp/include" + ] + ldflags = [ + "-Wl,-Map=toggleButtonTest.map", + "-T", + ] + + ldflags += [ + "${ohos_root_path}build/lite/platform/hi3516dv300_liteos_a/init.ld", + "-L${ohos_root_path}vendor/hisi/camera/hi3516dv300/Hi3516DV300_SDK_V6.0.0.1_B010/mpp/lib", + "-ltde", "-lmpi", "-ldnvqe", "-lVoiceEngine", "-lupvqe" + ] + + deps = [ + "//foundation/graphic/lite/utils:litegraphicutils", + "//foundation/graphic/lite/services/wms:wms_client", + "//base/hiviewdfx/frameworks/hilog_lite/featured:hilog_shared", + "//third_party/bounds_checking_function:libsec_shared", + "//foundation/communication/frameworks/ipc_lite:liteipc_adapter", + "//foundation/graphic/lite/frameworks/surface:litesurface", + "//foundation/graphic/lite/frameworks/ui:liteui", + "//foundation/graphic/lite/hals:graphic_hals", + "//foundation/distributedschedule/services/samgr_lite/samgr_client:client", + "//foundation/distributedschedule/services/samgr_lite/samgr:samgr", + "//foundation/distributedschedule/services/samgr_lite/communication/broadcast", + "//foundation/graphic/lite/tools/graphic_test_framework:litegraphictestframework", + ] + + cflags = [ "-fno-rtti"] +} diff --git a/uikit_lite/uilayout_posix/Test.json b/uikit_lite/uilayout_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..f0a10b836b46c58d06a9e7ecdd5e51167f593615 --- /dev/null +++ b/uikit_lite/uilayout_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for uikit uilayout test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/uikit", + "target": "/test_root/uikit" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/uikit/ActsUILayoutTest.bin" + } +} \ No newline at end of file diff --git a/uikit_lite/uilayout_posix/src/listTest.cpp b/uikit_lite/uilayout_posix/src/listTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..caec9e921681ee715ffac886a5aa0bd88cc7366e --- /dev/null +++ b/uikit_lite/uilayout_posix/src/listTest.cpp @@ -0,0 +1,295 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "utils/list.h" + +using namespace OHOS; +using namespace testing::ext; + +class ListTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_LIST_LIST_FRONT_0100 +* @tc.name test list front api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ListTest, testListFront, TestSize.Level0) { + List* list = new List(); + list->PushBack(1); + list->PushBack(2); + EXPECT_EQ(list->Front(), 1); + delete(list); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_LIST_LIST_BACK_0100 +* @tc.name test list back api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ListTest, testListBack, TestSize.Level0) { + List* list = new List(); + list->PushBack(1); + list->PushBack(2); + EXPECT_EQ(list->Back(), 2); + delete(list); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_LIST_LIST_PUSHBACK_0100 +* @tc.name test list push back api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ListTest, testListPushBack, TestSize.Level0) { + List* list = new List(); + list->PushBack(1); + list->PushBack(2); + EXPECT_EQ(list->Size(), 2); + EXPECT_EQ(list->Front(), 1); + EXPECT_EQ(list->Back(), 2); + delete(list); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_LIST_LIST_PUSHFRONT_0100 +* @tc.name test list push front api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ListTest, testListPushFront, TestSize.Level0) { + List* list = new List(); + list->PushFront(1); + list->PushFront(2); + EXPECT_EQ(list->Size(), 2); + EXPECT_EQ(list->Front(), 2); + EXPECT_EQ(list->Back(), 1); + delete(list); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_LIST_LIST_POPBACK_0100 +* @tc.name test list pop back api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ListTest, testListPopBack, TestSize.Level0) { + List* list = new List(); + list->PushBack(1); + list->PushBack(2); + list->PopBack(); + EXPECT_EQ(list->Size(), 1); + EXPECT_EQ(list->Front(), 1); + EXPECT_EQ(list->Back(), 1); + delete(list); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_LIST_LIST_POPFRONT_0100 +* @tc.name test list pop front api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ListTest, testListPopFront, TestSize.Level0) { + List* list = new List(); + list->PushBack(1); + list->PushBack(2); + list->PopFront(); + EXPECT_EQ(list->Size(), 1); + EXPECT_EQ(list->Front(), 2); + EXPECT_EQ(list->Back(), 2); + delete(list); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_LIST_LIST_INSERT_0100 +* @tc.name test list insert api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ListTest, testListInsert, TestSize.Level0) { + List* list = new List(); + list->PushBack(1); + list->PushBack(2); + ListNode* node = list->Tail(); + list->Insert(node, 3); + EXPECT_EQ(list->Size(), 3); + EXPECT_EQ(list->Front(), 1); + EXPECT_EQ(list->Head()->next_->data_, 3); + EXPECT_EQ(list->Back(), 2); + delete(list); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_LIST_LIST_REMOVE_0100 +* @tc.name test list remove api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ListTest, testListRemove, TestSize.Level0) { + List* list = new List(); + list->PushBack(1); + list->PushBack(2); + ListNode* node = list->Head(); + list->Remove(node); + EXPECT_EQ(list->Size(), 1); + EXPECT_EQ(list->Front(), 2); + EXPECT_EQ(list->Back(), 2); + delete(list); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_LIST_LIST_CLEAR_0100 +* @tc.name test list clear api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ListTest, testListClear, TestSize.Level0) { + List* list = new List(); + list->PushBack(1); + list->PushBack(2); + list->Clear(); + EXPECT_EQ(list->Size(), 0); + delete(list); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_LIST_LIST_HEAD_0100 +* @tc.name test list head api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ListTest, testListHead, TestSize.Level0) { + List* list = new List(); + list->PushBack(1); + list->PushBack(2); + EXPECT_EQ(list->Head()->data_, 1); + delete(list); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_LIST_LIST_TAIL_0100 +* @tc.name test list tail api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ListTest, testListTail, TestSize.Level0) { + List* list = new List(); + list->PushBack(1); + list->PushBack(2); + EXPECT_EQ(list->Tail()->data_, 2); + delete(list); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_LIST_LIST_BEGIN_0100 +* @tc.name test list begin api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ListTest, testListBegin, TestSize.Level0) { + List* list = new List(); + list->PushBack(1); + list->PushBack(2); + EXPECT_EQ(list->Begin()->data_, 1); + delete(list); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_LIST_LIST_NEXT_0100 +* @tc.name test list next api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ListTest, testListNext, TestSize.Level0) { + List* list = new List(); + list->PushBack(1); + list->PushBack(2); + EXPECT_EQ(list->Next(list->Head())->data_, 2); + delete(list); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_LIST_LIST_ISEMPTY_0100 +* @tc.name test list is empty api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ListTest, testListIsEmpty, TestSize.Level0) { + List* list = new List(); + list->PushBack(1); + EXPECT_EQ(list->IsEmpty(), false); + list->Clear(); + EXPECT_EQ(list->IsEmpty(), true); + delete(list); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_LIST_LIST_SIZE_0100 +* @tc.name test list size api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ListTest, testListSize, TestSize.Level0) { + List* list = new List(); + list->PushBack(1); + EXPECT_EQ(list->Size(), 1); + list->Clear(); + EXPECT_EQ(list->Size(), 0); + delete(list); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_LIST_LIST_END_0100 +* @tc.name test list end api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ListTest, testListEnd, TestSize.Level0) { + List* list = new List(); + list->PushBack(1); + list->PushBack(2); + EXPECT_EQ(list->End()->next_->data_, 1); + delete(list); +} \ No newline at end of file diff --git a/uikit_lite/uiprogress_posix/BUILD.gn b/uikit_lite/uiprogress_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..e74309a2247110615c562597301dbab5fe43dd62 --- /dev/null +++ b/uikit_lite/uiprogress_posix/BUILD.gn @@ -0,0 +1,72 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsUIProgressTest") { + suite_name = "acts" + sources = [ + "src/boxProgressTest.cpp", + "src/circleProgressTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "//foundation/graphic/lite/services/wms", + "//foundation/graphic/lite/services/wms/client/interfaces", + "//foundation/graphic/lite/interfaces/utils", + "//foundation/graphic/lite/frameworks/ui/include", + "//foundation/graphic/lite/config", + "//foundation/graphic/lite/interfaces/ui", + "//foundation/graphic/lite/interfaces", + "//foundation/graphic/lite/hals/include", + "//foundation/graphic/lite/huawei_proprietary/include", + "//foundation/graphic/lite/tools", + "//foundation/graphic/lite/frameworks/ui/src", + "//foundation/graphic/lite/services/ims/include", + "//third_party/bounds_checking_function/include", + "//foundation/graphic/lite/frameworks/surface/include", + "//utils/native/lite/include", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/registry", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/samgr", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/communication/broadcast", + "//vendor/hisi/hi35xx/hi3516dv300/Hi3516DV300_SDK_V6.0.0.1_B010/mpp/include" + ] + ldflags = [ + "-Wl,-Map=toggleButtonTest.map", + "-T", + ] + + ldflags += [ + "${ohos_root_path}build/lite/platform/hi3516dv300_liteos_a/init.ld", + "-L${ohos_root_path}vendor/hisi/camera/hi3516dv300/Hi3516DV300_SDK_V6.0.0.1_B010/mpp/lib", + "-ltde", "-lmpi", "-ldnvqe", "-lVoiceEngine", "-lupvqe" + ] + + deps = [ + "//foundation/graphic/lite/utils:litegraphicutils", + "//foundation/graphic/lite/services/wms:wms_client", + "//base/hiviewdfx/frameworks/hilog_lite/featured:hilog_shared", + "//third_party/bounds_checking_function:libsec_shared", + "//foundation/communication/frameworks/ipc_lite:liteipc_adapter", + "//foundation/graphic/lite/frameworks/surface:litesurface", + "//foundation/graphic/lite/frameworks/ui:liteui", + "//foundation/graphic/lite/hals:graphic_hals", + "//foundation/distributedschedule/services/samgr_lite/samgr_client:client", + "//foundation/distributedschedule/services/samgr_lite/samgr:samgr", + "//foundation/distributedschedule/services/samgr_lite/communication/broadcast", + "//foundation/graphic/lite/tools/graphic_test_framework:litegraphictestframework", + ] + + cflags = [ "-fno-rtti"] +} diff --git a/uikit_lite/uiprogress_posix/Test.json b/uikit_lite/uiprogress_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..0e268f76c17320ec3f11c1f43ed8921a26f2bacf --- /dev/null +++ b/uikit_lite/uiprogress_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for uikit uiprogress test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/uikit", + "target": "/test_root/uikit" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/uikit/ActsUIProgressTest.bin" + } +} \ No newline at end of file diff --git a/uikit_lite/uiprogress_posix/src/boxProgressTest.cpp b/uikit_lite/uiprogress_posix/src/boxProgressTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..fd5e83f000f81ae08b5197a354b7fd87e4f263a5 --- /dev/null +++ b/uikit_lite/uiprogress_posix/src/boxProgressTest.cpp @@ -0,0 +1,246 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "components/ui_box_progress.h" + +using namespace OHOS; +using namespace testing::ext; + +class BoxProgressTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_BOXPROGRESS_STEP_0100 +* @tc.name test box progress step api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(BoxProgressTest, testBoxProgressStepTest1, TestSize.Level0) { + auto boxProgress = new UIBoxProgress(); + uint16_t step = 0; + int16_t value = 1; + boxProgress->SetRange(100, 0); + boxProgress->SetValue(0); + boxProgress->SetStep(step); + boxProgress->SetValue(value); + EXPECT_EQ(boxProgress->GetStep(), step); + delete(boxProgress); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BOXPROGRESS_STEP_0200 +* @tc.name test box progress step api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(BoxProgressTest, testBoxProgressStepTest2, TestSize.Level0) { + auto boxProgress = new UIBoxProgress(); + uint16_t step = 10; + int16_t value = 20; + boxProgress->SetRange(100, 0); + boxProgress->SetValue(value); + boxProgress->SetStep(step); + boxProgress->SetValue(value + step - 1); + EXPECT_EQ(boxProgress->GetStep(), step); + EXPECT_EQ(boxProgress->GetValue(), value + step - 1); + delete(boxProgress); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BOXPROGRESS_STEP_0300 +* @tc.name test box progress step api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(BoxProgressTest, testBoxProgressStepTest3, TestSize.Level0) { + auto boxProgress = new UIBoxProgress(); + uint16_t step = 10; + int16_t value = 20; + boxProgress->SetRange(100, 0); + boxProgress->SetValue(value); + boxProgress->SetStep(step); + boxProgress->SetValue(value - step + 1); + EXPECT_EQ(boxProgress->GetStep(), step); + EXPECT_EQ(boxProgress->GetValue(), value - step + 1); + delete(boxProgress); +} +/** +* @tc.number SUB_UIKIT_NDKAPI_BOXPROGRESS_DRIECTION_0100 +* @tc.name test box progress direction api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(BoxProgressTest, testBoxProgressDirection, TestSize.Level0) { + UIBoxProgress *boxProgress = new UIBoxProgress(); + UIBoxProgress::Direction direction = UIBoxProgress::Direction::DIR_BOTTOM_TO_TOP; + boxProgress->SetDirection(direction); + + EXPECT_EQ(boxProgress->GetDirection(), direction); + delete(boxProgress); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BOXPROGRESS_VALIDWIDTH_0100 +* @tc.name test box progress valid width api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(BoxProgressTest, testBoxProgressValidWidth, TestSize.Level0) { + UIBoxProgress *boxProgress = new UIBoxProgress(); + boxProgress->Resize(100, 100); + int16_t validWidth = 10; + boxProgress->SetValidWidth(validWidth); + EXPECT_EQ(boxProgress->GetValidWidth(), validWidth); + delete(boxProgress); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BOXPROGRESS_VALIDHEIGHT_0100 +* @tc.name test box progress valid height api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(BoxProgressTest, testBoxProgressValidHeight, TestSize.Level0) { + UIBoxProgress *boxProgress = new UIBoxProgress(); + boxProgress->Resize(100, 100); + int16_t validHeight = 10; + boxProgress->SetValidHeight(validHeight); + + EXPECT_EQ(boxProgress->GetValidHeight(), validHeight); + delete(boxProgress); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BOXPROGRESS_VALUE_0100 +* @tc.name test box progress value api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(BoxProgressTest, testBoxProgressValueTest1, TestSize.Level0) { + UIBoxProgress *boxProgress = new UIBoxProgress(); + int16_t value = 10; + boxProgress->SetValue(value); + + EXPECT_EQ(boxProgress->GetValue(), value); + delete(boxProgress); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BOXPROGRESS_VALUE_0200 +* @tc.name test box progress value api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(BoxProgressTest, testBoxProgressValueTest2, TestSize.Level0) { + UIBoxProgress *boxProgress = new UIBoxProgress(); + int16_t rangeMax = 500; + int16_t rangeMin = 100; + boxProgress->SetRange(rangeMax, rangeMin); + + int16_t value = rangeMin - 1; + boxProgress->SetValue(value); + EXPECT_EQ(boxProgress->GetValue(), rangeMin); + delete(boxProgress); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BOXPROGRESS_VALUE_0300 +* @tc.name test box progress value api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(BoxProgressTest, testBoxProgressValueTest3, TestSize.Level0) { + UIBoxProgress *boxProgress = new UIBoxProgress(); + int16_t rangeMax = 500; + int16_t rangeMin = 100; + boxProgress->SetRange(rangeMax, rangeMin); + + int16_t value = rangeMax + 1; + boxProgress->SetValue(value); + EXPECT_EQ(boxProgress->GetValue(), rangeMax); + delete(boxProgress); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BOXPROGRESS_RANGE_0100 +* @tc.name test box progress range api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(BoxProgressTest, testBoxProgressRange, TestSize.Level0) { + UIBoxProgress *boxProgress = new UIBoxProgress(); + int16_t rangeMax = 500; + int16_t rangeMin = 100; + boxProgress->SetRange(rangeMax, rangeMin); + + EXPECT_EQ(boxProgress->GetRangeMax(), rangeMax); + EXPECT_EQ(boxProgress->GetRangeMin(), rangeMin); + delete(boxProgress); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BOXPROGRESS_WIDTH_0100 +* @tc.name test box progress width api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(BoxProgressTest, testBoxProgressWidth, TestSize.Level0) { + UIBoxProgress *boxProgress = new UIBoxProgress(); + int16_t width = 100; + boxProgress->SetWidth(width); + + EXPECT_EQ(boxProgress->GetWidth(), width); + EXPECT_EQ(boxProgress->GetValidWidth(), width); + delete(boxProgress); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_BOXPROGRESS_HEIGHT_0100 +* @tc.name test box progress height api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(BoxProgressTest, testBoxProgressHeight, TestSize.Level0) { + UIBoxProgress *boxProgress = new UIBoxProgress(); + int16_t height = 100; + boxProgress->SetHeight(height); + + EXPECT_EQ(boxProgress->GetHeight(), height); + EXPECT_EQ(boxProgress->GetValidHeight(), height); + delete(boxProgress); +} \ No newline at end of file diff --git a/uikit_lite/uiprogress_posix/src/circleProgressTest.cpp b/uikit_lite/uiprogress_posix/src/circleProgressTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..a6a34bdaea85bd2df31606b668d42058b3669182 --- /dev/null +++ b/uikit_lite/uiprogress_posix/src/circleProgressTest.cpp @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "components/ui_circle_progress.h" + +using namespace OHOS; +using namespace testing::ext; + +class CircleProgressTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_CIRCLEPROGRESS_CIRCLEPROGRESS_STEP_0100 +* @tc.name test circle progress step api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CircleProgressTest, testCircleProgressStep, TestSize.Level0) { + UICircleProgress* circleProgress = new UICircleProgress(); + uint16_t step = 10; + circleProgress->SetStep(step); + EXPECT_EQ(circleProgress->GetStep(), step); + delete(circleProgress); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CIRCLEPROGRESS_CIRCLEPROGRESS_RADIUS_0100 +* @tc.name test circle progress radius api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CircleProgressTest, testCircleProgressRadius, TestSize.Level0) { + UICircleProgress *circleProgress = new UICircleProgress(); + uint16_t radius = 10; + circleProgress->SetRadius(radius); + + EXPECT_EQ(circleProgress->GetRadius(), radius); + delete(circleProgress); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CIRCLEPROGRESS_CIRCLEPROGRESS_CENTERPOSITION_0100 +* @tc.name test circle progress center position api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CircleProgressTest, testCircleProgressCenterPosition, TestSize.Level0) { + UICircleProgress *circleProgress = new UICircleProgress(); + circleProgress->Resize(100, 100); + int16_t centerX = 50; + int16_t centerY = 50; + circleProgress->SetCenterPosition(centerX, centerY); + + int16_t left = circleProgress->GetStyle(STYLE_PADDING_LEFT); + int16_t top = circleProgress->GetStyle(STYLE_PADDING_TOP); + int16_t borderWidth = circleProgress->GetStyle(STYLE_BORDER_WIDTH); + + EXPECT_EQ(circleProgress->GetCenterPosition().x, centerX + left + borderWidth); + EXPECT_EQ(circleProgress->GetCenterPosition().y, centerY + top + borderWidth); + delete(circleProgress); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CIRCLEPROGRESS_CIRCLEPROGRESS_CENTERPOSITION_0200 +* @tc.name test circle progress center position api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CircleProgressTest, testCircleProgressCenterPosition2, TestSize.Level0) { + UICircleProgress *circleProgress = new UICircleProgress(); + circleProgress->SetStyle(STYLE_PADDING_LEFT, 10); + circleProgress->SetStyle(STYLE_PADDING_TOP, 20); + circleProgress->SetStyle(STYLE_BORDER_WIDTH, 30); + circleProgress->Resize(100, 100); + int16_t centerX = 50; + int16_t centerY = 50; + circleProgress->SetCenterPosition(centerX, centerY); + + int16_t left = circleProgress->GetStyle(STYLE_PADDING_LEFT); + int16_t top = circleProgress->GetStyle(STYLE_PADDING_TOP); + int16_t borderWidth = circleProgress->GetStyle(STYLE_BORDER_WIDTH); + + EXPECT_EQ(circleProgress->GetCenterPosition().x, centerX); + EXPECT_EQ(circleProgress->GetCenterPosition().y, centerY); + delete(circleProgress); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CIRCLEPROGRESS_CIRCLEPROGRESS_VALUE_0100 +* @tc.name test circle progress value api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CircleProgressTest, testCircleProgressValue, TestSize.Level0) { + UICircleProgress *circleProgress = new UICircleProgress(); + int16_t value = 10; + circleProgress->SetValue(value); + + EXPECT_EQ(circleProgress->GetValue(), value); + delete(circleProgress); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CIRCLEPROGRESS_CIRCLEPROGRESS_RANGE_0100 +* @tc.name test circle progress range api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CircleProgressTest, testCircleProgressRange, TestSize.Level0) { + UICircleProgress *circleProgress = new UICircleProgress(); + int16_t rangeMax = 500; + int16_t rangeMin = 100; + circleProgress->SetRange(rangeMax, rangeMin); + EXPECT_EQ(circleProgress->GetRangeMax(), rangeMax); + EXPECT_EQ(circleProgress->GetRangeMin(), rangeMin); + delete(circleProgress); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CIRCLEPROGRESS_CIRCLEPROGRESS_STARTANGLE_0100 +* @tc.name test circle progress start angle api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CircleProgressTest, testCircleProgressStartAngle, TestSize.Level0) { + UICircleProgress *circleProgress = new UICircleProgress(); + int16_t startAngle = 50; + circleProgress->SetStartAngle(startAngle); + + EXPECT_EQ(circleProgress->GetStartAngle(), startAngle); + delete(circleProgress); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CIRCLEPROGRESS_CIRCLEPROGRESS_ENDANGLE_0100 +* @tc.name test circle progress end angle api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CircleProgressTest, testCircleProgressEndAngle, TestSize.Level0) { + UICircleProgress *circleProgress = new UICircleProgress(); + int16_t endAngle = 50; + circleProgress->SetEndAngle(endAngle); + + EXPECT_EQ(circleProgress->GetEndAngle(), endAngle); + delete(circleProgress); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_CIRCLEPROGRESS_CIRCLEPROGRESS_LINECOLOR_0100 +* @tc.name test circle progress line color api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(CircleProgressTest, testCircleProgressLineColor, TestSize.Level0) { + UICircleProgress *circleProgress = new UICircleProgress(); + circleProgress->GetBackgroundStyle().line.color = Color::Yellow(); + ColorType color = Color::Red(); + circleProgress->SetLineColor(color); + + EXPECT_EQ(circleProgress->GetForegroundStyle().line.color.full, color.full); + EXPECT_NE(circleProgress->GetBackgroundStyle().line.color.full, color.full); + + delete(circleProgress); +} \ No newline at end of file diff --git a/uikit_lite/uislider_posix/BUILD.gn b/uikit_lite/uislider_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..184b185db640fdf4496ca55a83ff2a27cf66ca96 --- /dev/null +++ b/uikit_lite/uislider_posix/BUILD.gn @@ -0,0 +1,71 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsUISliderTest") { + suite_name = "acts" + sources = [ + "src/sliderViewTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "//foundation/graphic/lite/services/wms", + "//foundation/graphic/lite/services/wms/client/interfaces", + "//foundation/graphic/lite/interfaces/utils", + "//foundation/graphic/lite/frameworks/ui/include", + "//foundation/graphic/lite/config", + "//foundation/graphic/lite/interfaces/ui", + "//foundation/graphic/lite/interfaces", + "//foundation/graphic/lite/hals/include", + "//foundation/graphic/lite/huawei_proprietary/include", + "//foundation/graphic/lite/tools", + "//foundation/graphic/lite/frameworks/ui/src", + "//foundation/graphic/lite/services/ims/include", + "//third_party/bounds_checking_function/include", + "//foundation/graphic/lite/frameworks/surface/include", + "//utils/native/lite/include", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/registry", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/samgr", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/communication/broadcast", + "//vendor/hisi/hi35xx/hi3516dv300/Hi3516DV300_SDK_V6.0.0.1_B010/mpp/include" + ] + ldflags = [ + "-Wl,-Map=toggleButtonTest.map", + "-T", + ] + + ldflags += [ + "${ohos_root_path}build/lite/platform/hi3516dv300_liteos_a/init.ld", + "-L${ohos_root_path}vendor/hisi/camera/hi3516dv300/Hi3516DV300_SDK_V6.0.0.1_B010/mpp/lib", + "-ltde", "-lmpi", "-ldnvqe", "-lVoiceEngine", "-lupvqe" + ] + + deps = [ + "//foundation/graphic/lite/utils:litegraphicutils", + "//foundation/graphic/lite/services/wms:wms_client", + "//base/hiviewdfx/frameworks/hilog_lite/featured:hilog_shared", + "//third_party/bounds_checking_function:libsec_shared", + "//foundation/communication/frameworks/ipc_lite:liteipc_adapter", + "//foundation/graphic/lite/frameworks/surface:litesurface", + "//foundation/graphic/lite/frameworks/ui:liteui", + "//foundation/graphic/lite/hals:graphic_hals", + "//foundation/distributedschedule/services/samgr_lite/samgr_client:client", + "//foundation/distributedschedule/services/samgr_lite/samgr:samgr", + "//foundation/distributedschedule/services/samgr_lite/communication/broadcast", + "//foundation/graphic/lite/tools/graphic_test_framework:litegraphictestframework", + ] + + cflags = [ "-fno-rtti"] +} diff --git a/uikit_lite/uislider_posix/Test.json b/uikit_lite/uislider_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..c886ad1aa785045201f36438555dbd6bae8f2ead --- /dev/null +++ b/uikit_lite/uislider_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for uikit uislider test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/uikit", + "target": "/test_root/uikit" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/uikit/ActsUISliderTest.bin" + } +} \ No newline at end of file diff --git a/uikit_lite/uislider_posix/src/sliderViewTest.cpp b/uikit_lite/uislider_posix/src/sliderViewTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..eba44631650960a84d566daf0f5c576d4442feda --- /dev/null +++ b/uikit_lite/uislider_posix/src/sliderViewTest.cpp @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "components/root_view.h" +#include "components/ui_slider.h" +#include "components/ui_view_group.h" + +using namespace OHOS; +using namespace testing::ext; + +class SliderViewTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_SLIDER_SLIDER_STEP_0100 +* @tc.name test slider step api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(SliderViewTest, testSliderStep, TestSize.Level0) { + UISlider* slider = new UISlider(); + int16_t step = 10; + slider->SetStep(step); + EXPECT_EQ(slider->GetStep(), step); + delete(slider); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_SLIDER_SLIDER_DIRECTION_0100 +* @tc.name test slider direction api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(SliderViewTest, testSliderDirection, TestSize.Level0) { + UISlider* slider = new UISlider(); + UISlider::Direction direction = UISlider::Direction::DIR_BOTTOM_TO_TOP; + slider->SetDirection(direction); + + EXPECT_EQ(slider->GetDirection(), direction); + delete(slider); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_SLIDER_SLIDER_VALIDWIDTH_0100 +* @tc.name test slider valid width api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(SliderViewTest, testSliderValidWidth, TestSize.Level0) { + UISlider* slider = new UISlider(); + slider->Resize(100, 100); + int16_t validWidth = 10; + slider->SetValidWidth(validWidth); + EXPECT_EQ(slider->GetValidWidth(), validWidth); + delete(slider); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_SLIDER_SLIDER_VALIDHEIGHT_0100 +* @tc.name test slider valid height api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(SliderViewTest, testSliderValidHeight, TestSize.Level0) { + UISlider* slider = new UISlider(); + slider->Resize(100, 100); + int16_t validHeight = 10; + slider->SetValidHeight(validHeight); + EXPECT_EQ(slider->GetValidHeight(), validHeight); + delete(slider); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_SLIDER_SLIDER_VALUE_0100 +* @tc.name test slider value api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(SliderViewTest, testSliderValue, TestSize.Level0) { + UISlider* slider = new UISlider(); + int16_t value = 10; + slider->SetValue(value); + EXPECT_EQ(slider->GetValue(), value); + delete(slider); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_SLIDER_SLIDER_RANGE_0100 +* @tc.name test slider range api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(SliderViewTest, testSliderRangeTest1, TestSize.Level0) { + UISlider* slider = new UISlider(); + int16_t rangeMax = 500; + int16_t rangeMin = 100; + slider->SetRange(rangeMax, rangeMin); + EXPECT_EQ(slider->GetRangeMax(), rangeMax); + EXPECT_EQ(slider->GetRangeMin(), rangeMin); + delete(slider); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_SLIDER_SLIDER_KNOBWIDTH_0100 +* @tc.name test slider knob width api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(SliderViewTest, testSliderRangeTest2, TestSize.Level0) { + UISlider* slider = new UISlider(); + int16_t knobWidth = 10; + slider->SetKnobWidth(knobWidth); + EXPECT_EQ(slider->GetKnobWidth(), knobWidth); + delete(slider); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_SLIDER_SLIDER_DEFAULTKNOBWIDTH_0100 +* @tc.name test slider default knob width api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(SliderViewTest, testSliderDefaultKnobWidthTest1, TestSize.Level0) { + RootView* rootView = RootView::GetInstance(); + UIViewGroup* viewGroup = static_cast(rootView); + viewGroup->SetPosition(0, 0); + viewGroup->SetWidth(HORIZONTAL_RESOLUTION); + viewGroup->SetHeight(VERTICAL_RESOLUTION); + + UISlider* slider = new UISlider(); + viewGroup->Add(slider); + int16_t width = 100; + int16_t height = 10; + slider->SetWidth(width); + slider->SetHeight(height); + slider->SetDirection(UISlider::Direction::DIR_LEFT_TO_RIGHT); + viewGroup->Invalidate(); + EXPECT_EQ(slider->GetKnobWidth(), height); + + slider->SetDirection(UISlider::Direction::DIR_RIGHT_TO_LEFT); + slider->Invalidate(); + EXPECT_EQ(slider->GetKnobWidth(), height); + + viewGroup->Remove(slider); + delete(slider); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_SLIDER_SLIDER_DEFAULTKNOBWIDTH_0200 +* @tc.name test slider default knob width api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(SliderViewTest, testSliderDefaultKnobWidthTest2, TestSize.Level0) { + RootView* rootView = RootView::GetInstance(); + UIViewGroup* viewGroup = static_cast(rootView); + viewGroup->SetPosition(0, 0); + viewGroup->SetWidth(HORIZONTAL_RESOLUTION); + viewGroup->SetHeight(VERTICAL_RESOLUTION); + + UISlider* slider = new UISlider(); + viewGroup->Add(slider); + int16_t width = 10; + int16_t height = 100; + slider->SetWidth(width); + slider->SetHeight(height); + slider->SetDirection(UISlider::Direction::DIR_BOTTOM_TO_TOP); + viewGroup->Invalidate(); + EXPECT_EQ(slider->GetKnobWidth(), width); + + slider->SetDirection(UISlider::Direction::DIR_TOP_TO_BOTTOM); + slider->Invalidate(); + EXPECT_EQ(slider->GetKnobWidth(), width); + + viewGroup->Remove(slider); + delete(slider); +} \ No newline at end of file diff --git a/uikit_lite/uisnapshot_posix/BUILD.gn b/uikit_lite/uisnapshot_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..6579487d31a12c3a726784d885fbf4d881a1e1af --- /dev/null +++ b/uikit_lite/uisnapshot_posix/BUILD.gn @@ -0,0 +1,71 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsUISnapshotTest") { + suite_name = "acts" + sources = [ + "src/snapshotTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "//foundation/graphic/lite/services/wms", + "//foundation/graphic/lite/services/wms/client/interfaces", + "//foundation/graphic/lite/interfaces/utils", + "//foundation/graphic/lite/frameworks/ui/include", + "//foundation/graphic/lite/config", + "//foundation/graphic/lite/interfaces/ui", + "//foundation/graphic/lite/interfaces", + "//foundation/graphic/lite/hals/include", + "//foundation/graphic/lite/huawei_proprietary/include", + "//foundation/graphic/lite/tools", + "//foundation/graphic/lite/frameworks/ui/src", + "//foundation/graphic/lite/services/ims/include", + "//third_party/bounds_checking_function/include", + "//foundation/graphic/lite/frameworks/surface/include", + "//utils/native/lite/include", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/registry", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/samgr", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/communication/broadcast", + "//vendor/hisi/hi35xx/hi3516dv300/Hi3516DV300_SDK_V6.0.0.1_B010/mpp/include" + ] + ldflags = [ + "-Wl,-Map=toggleButtonTest.map", + "-T", + ] + + ldflags += [ + "${ohos_root_path}build/lite/platform/hi3516dv300_liteos_a/init.ld", + "-L${ohos_root_path}vendor/hisi/camera/hi3516dv300/Hi3516DV300_SDK_V6.0.0.1_B010/mpp/lib", + "-ltde", "-lmpi", "-ldnvqe", "-lVoiceEngine", "-lupvqe" + ] + + deps = [ + "//foundation/graphic/lite/utils:litegraphicutils", + "//foundation/graphic/lite/services/wms:wms_client", + "//base/hiviewdfx/frameworks/hilog_lite/featured:hilog_shared", + "//third_party/bounds_checking_function:libsec_shared", + "//foundation/communication/frameworks/ipc_lite:liteipc_adapter", + "//foundation/graphic/lite/frameworks/surface:litesurface", + "//foundation/graphic/lite/frameworks/ui:liteui", + "//foundation/graphic/lite/hals:graphic_hals", + "//foundation/distributedschedule/services/samgr_lite/samgr_client:client", + "//foundation/distributedschedule/services/samgr_lite/samgr:samgr", + "//foundation/distributedschedule/services/samgr_lite/communication/broadcast", + "//foundation/graphic/lite/tools/graphic_test_framework:litegraphictestframework", + ] + + cflags = [ "-fno-rtti"] +} diff --git a/uikit_lite/uisnapshot_posix/Test.json b/uikit_lite/uisnapshot_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..b4f8be520a25fe609c5e7487807a33e525a54be2 --- /dev/null +++ b/uikit_lite/uisnapshot_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for uikit uisnapshot test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/uikit", + "target": "/test_root/uikit" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/uikit/ActsUISnapshotTest.bin" + } +} \ No newline at end of file diff --git a/uikit_lite/uisnapshot_posix/src/snapshotTest.cpp b/uikit_lite/uisnapshot_posix/src/snapshotTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..4edae3fe0a86a54317c3b0e1f2f0474d1acaf983 --- /dev/null +++ b/uikit_lite/uisnapshot_posix/src/snapshotTest.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "components/ui_snapshot.h" + +using namespace OHOS; +using namespace testing::ext; + +class SnapshotTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_SNAPSHOT_SNAPSHOT_ADD_0100 +* @tc.name test snapshot add api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(SnapshotTest, testSnapshotAdd, TestSize.Level0) { + UISnapShot* group = new UISnapShot(); + UIView* view = new UIView(); + group->Add(view); + EXPECT_EQ(view, group->GetChildrenHead()); + EXPECT_EQ(view->GetParent(), group); + delete(view); + delete(group); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_SNAPSHOT_SNAPSHOT_FREEZE_0100 +* @tc.name test snapshot freeze api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(SnapshotTest, testSnapshotFreeze, TestSize.Level0) { + UISnapShot* group = new UISnapShot(); + UIView* view = new UIView(); + group->Add(view); + group->Freeze(true); + EXPECT_EQ(false, group->IsViewGroup()); + group->UnFreeze(); + EXPECT_EQ(true, group->IsViewGroup()); + delete(view); + delete(group); +} \ No newline at end of file diff --git a/uikit_lite/uiviewGroup_posix/BUILD.gn b/uikit_lite/uiviewGroup_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..829ed2c63e6fbf5ca4cc2b0589f33a1333c24e7a --- /dev/null +++ b/uikit_lite/uiviewGroup_posix/BUILD.gn @@ -0,0 +1,71 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsUIViewGroupTest") { + suite_name = "acts" + sources = [ + "src/viewGroupTest.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "//foundation/graphic/lite/services/wms", + "//foundation/graphic/lite/services/wms/client/interfaces", + "//foundation/graphic/lite/interfaces/utils", + "//foundation/graphic/lite/frameworks/ui/include", + "//foundation/graphic/lite/config", + "//foundation/graphic/lite/interfaces/ui", + "//foundation/graphic/lite/interfaces", + "//foundation/graphic/lite/hals/include", + "//foundation/graphic/lite/huawei_proprietary/include", + "//foundation/graphic/lite/tools", + "//foundation/graphic/lite/frameworks/ui/src", + "//foundation/graphic/lite/services/ims/include", + "//third_party/bounds_checking_function/include", + "//foundation/graphic/lite/frameworks/surface/include", + "//utils/native/lite/include", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/registry", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/samgr", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/communication/broadcast", + "//vendor/hisi/hi35xx/hi3516dv300/Hi3516DV300_SDK_V6.0.0.1_B010/mpp/include" + ] + ldflags = [ + "-Wl,-Map=toggleButtonTest.map", + "-T", + ] + + ldflags += [ + "${ohos_root_path}build/lite/platform/hi3516dv300_liteos_a/init.ld", + "-L${ohos_root_path}vendor/hisi/camera/hi3516dv300/Hi3516DV300_SDK_V6.0.0.1_B010/mpp/lib", + "-ltde", "-lmpi", "-ldnvqe", "-lVoiceEngine", "-lupvqe" + ] + + deps = [ + "//foundation/graphic/lite/utils:litegraphicutils", + "//foundation/graphic/lite/services/wms:wms_client", + "//base/hiviewdfx/frameworks/hilog_lite/featured:hilog_shared", + "//third_party/bounds_checking_function:libsec_shared", + "//foundation/communication/frameworks/ipc_lite:liteipc_adapter", + "//foundation/graphic/lite/frameworks/surface:litesurface", + "//foundation/graphic/lite/frameworks/ui:liteui", + "//foundation/graphic/lite/hals:graphic_hals", + "//foundation/distributedschedule/services/samgr_lite/samgr_client:client", + "//foundation/distributedschedule/services/samgr_lite/samgr:samgr", + "//foundation/distributedschedule/services/samgr_lite/communication/broadcast", + "//foundation/graphic/lite/tools/graphic_test_framework:litegraphictestframework", + ] + + cflags = [ "-fno-rtti"] +} diff --git a/uikit_lite/uiviewGroup_posix/Test.json b/uikit_lite/uiviewGroup_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..0b93e97b3faf5687cb1e0bf465ff28c1715e8100 --- /dev/null +++ b/uikit_lite/uiviewGroup_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for uikit uiview group test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/uikit", + "target": "/test_root/uikit" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/uikit/ActsUIViewGroupTest.bin" + } +} \ No newline at end of file diff --git a/uikit_lite/uiviewGroup_posix/src/viewGroupTest.cpp b/uikit_lite/uiviewGroup_posix/src/viewGroupTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..f42aedfdda45bb28273c77260941ccf45654318e --- /dev/null +++ b/uikit_lite/uiviewGroup_posix/src/viewGroupTest.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "components/root_view.h" +#include "components/ui_view_group.h" + +using namespace OHOS; +using namespace testing::ext; + +class ViewGroupTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_VIEWGROUP_VIEWGROUP_ADD_0100 +* @tc.name test view group add api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ViewGroupTest, testViewGroupAdd, TestSize.Level0) { + UIViewGroup* group = new UIViewGroup(); + UIView* view = new UIView(); + group->Add(view); + EXPECT_EQ(view, group->GetChildrenHead()); + EXPECT_EQ(view->GetParent(), group); + delete(view); + delete(group); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_VIEWGROUP_VIEWGROUP_INSERT_0100 +* @tc.name test view group insert api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ViewGroupTest, testViewGroupInsert, TestSize.Level0) { + UIViewGroup* group = new UIViewGroup(); + UIView* preView = new UIView(); + UIView* view = new UIView(); + group->Add(preView); + group->Insert(preView, view); + EXPECT_EQ(view, preView->GetNextSibling()); + delete(preView); + delete(view); + delete(group); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_VIEWGROUP_VIEWGROUP_REMOVE_0100 +* @tc.name test view group remove api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ViewGroupTest, testViewGroupRemove, TestSize.Level0) { + UIViewGroup* group = new UIViewGroup(); + UIView* view = new UIView(); + group->Add(view); + group->Remove(view); + EXPECT_EQ(nullptr, group->GetChildrenHead()); + EXPECT_EQ(nullptr, view->GetParent()); + delete(view); + delete(group); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_VIEWGROUP_VIEWGROUP_REMOVEALL_0100 +* @tc.name test view group remove all api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ViewGroupTest, testViewGroupRemoveAll, TestSize.Level0) { + UIViewGroup* group = new UIViewGroup(); + UIView* view = new UIView(); + UIView* view2 = new UIView(); + group->Add(view); + group->RemoveAll(); + EXPECT_EQ(nullptr, group->GetChildrenHead()); + delete(view); + delete(view2); + delete(group); +} \ No newline at end of file diff --git a/uikit_lite/utils_posix/BUILD.gn b/uikit_lite/utils_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..21aae5f24c90aa7939b7659a3edc905a83f3959c --- /dev/null +++ b/uikit_lite/utils_posix/BUILD.gn @@ -0,0 +1,79 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsUtilsTest") { + suite_name = "acts" + sources = [ + "src/colorTest.cpp", + "src/geometry2dTest.cpp", + "src/lineTest.cpp", + "src/mathTest.cpp", + #"src/matrix3Test.cpp", + "src/polygonTest.cpp", + "src/rectTest.cpp", + "src/vector2Test.cpp", + "src/vector3Test.cpp", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "//foundation/graphic/lite/services/wms", + "//foundation/graphic/lite/services/wms/client/interfaces", + "//foundation/graphic/lite/interfaces/utils", + "//foundation/graphic/lite/frameworks/ui/include", + "//foundation/graphic/lite/config", + "//foundation/graphic/lite/interfaces/ui", + "//foundation/graphic/lite/interfaces", + "//foundation/graphic/lite/hals/include", + "//foundation/graphic/lite/huawei_proprietary/include", + "//foundation/graphic/lite/tools", + "//foundation/graphic/lite/frameworks/ui/src", + "//foundation/graphic/lite/services/ims/include", + "//third_party/bounds_checking_function/include", + "//foundation/graphic/lite/frameworks/surface/include", + "//utils/native/lite/include", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/registry", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/samgr", + "//foundation/distributedschedule/interfaces/kits/samgr_lite/communication/broadcast", + "//vendor/hisi/hi35xx/hi3516dv300/Hi3516DV300_SDK_V6.0.0.1_B010/mpp/include" + ] + ldflags = [ + "-Wl,-Map=toggleButtonTest.map", + "-T", + ] + + ldflags += [ + "${ohos_root_path}build/lite/platform/hi3516dv300_liteos_a/init.ld", + "-L${ohos_root_path}vendor/hisi/camera/hi3516dv300/Hi3516DV300_SDK_V6.0.0.1_B010/mpp/lib", + "-ltde", "-lmpi", "-ldnvqe", "-lVoiceEngine", "-lupvqe" + ] + + deps = [ + "//foundation/graphic/lite/utils:litegraphicutils", + "//foundation/graphic/lite/services/wms:wms_client", + "//base/hiviewdfx/frameworks/hilog_lite/featured:hilog_shared", + "//third_party/bounds_checking_function:libsec_shared", + "//foundation/communication/frameworks/ipc_lite:liteipc_adapter", + "//foundation/graphic/lite/frameworks/surface:litesurface", + "//foundation/graphic/lite/frameworks/ui:liteui", + "//foundation/graphic/lite/hals:graphic_hals", + "//foundation/distributedschedule/services/samgr_lite/samgr_client:client", + "//foundation/distributedschedule/services/samgr_lite/samgr:samgr", + "//foundation/distributedschedule/services/samgr_lite/communication/broadcast", + "//foundation/graphic/lite/tools/graphic_test_framework:litegraphictestframework", + ] + + cflags = [ "-fno-rtti"] +} diff --git a/uikit_lite/utils_posix/Test.json b/uikit_lite/utils_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..e6dc761a72506a60222129b3b0bb702b4ddff814 --- /dev/null +++ b/uikit_lite/utils_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for uikit utils test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/uikit", + "target": "/test_root/uikit" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/uikit/ActsUtilsTest.bin" + } +} \ No newline at end of file diff --git a/uikit_lite/utils_posix/src/colorTest.cpp b/uikit_lite/utils_posix/src/colorTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..1daeb7b29ce2feb39b9d749b69c7f7e909cd2d8d --- /dev/null +++ b/uikit_lite/utils_posix/src/colorTest.cpp @@ -0,0 +1,360 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "utils/color.h" + +using namespace OHOS; +using namespace testing::ext; + +class ColorTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_GETCOLORFROMRGB_0100 +* @tc.name test color get color from rgb api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorGetFromRGB, TestSize.Level0) { + EXPECT_EQ(Color::GetColorFromRGB(0, 0, 0).red, 0); + EXPECT_EQ(Color::GetColorFromRGB(0, 0, 0).green, 0); + EXPECT_EQ(Color::GetColorFromRGB(0, 0, 0).blue, 0); + EXPECT_EQ(Color::GetColorFromRGB(0, 0, 0).alpha, 0xFF); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_GETCOLORFROMRGBA_0100 +* @tc.name test color get color from rgba api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorGetFromRGBA, TestSize.Level0) { + EXPECT_EQ(Color::GetColorFromRGBA(0, 0, 0, 0).red, 0); + EXPECT_EQ(Color::GetColorFromRGBA(0, 0, 0, 0).green, 0); + EXPECT_EQ(Color::GetColorFromRGBA(0, 0, 0, 0).blue, 0); + EXPECT_EQ(Color::GetColorFromRGBA(0, 0, 0, 0).alpha, 0); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_TO32_0100 +* @tc.name test color to 32 api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorTo32Test1, TestSize.Level0) { + ColorType color; + color.red = 0; + color.green = 0; + color.blue = 0; + color.alpha = 0; + uint32_t color32 = 0; + EXPECT_EQ(Color::ColorTo32(color), color32); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_TO32_0200 +* @tc.name test color to 32 api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorTo32Test2, TestSize.Level0) { + Color16 color; + color.red = 0; + color.green = 0; + color.blue = 0; + EXPECT_EQ(Color::ColorTo32(color, 0), 0); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_TO16_0200 +* @tc.name test color to 16 api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorTo16, TestSize.Level0) { + Color32 color32; + color32.red = 0; + color32.green = 0; + color32.blue = 0; + EXPECT_EQ(Color::ColorTo16(color32), 0); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_WHITE_0200 +* @tc.name test color white api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorWhite, TestSize.Level0) { + ColorType white = Color::White(); + EXPECT_EQ(white.red, 0xFF); + EXPECT_EQ(white.green, 0xFF); + EXPECT_EQ(white.blue, 0xFF); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_SILVER_0200 +* @tc.name test color silver api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorSilver, TestSize.Level0) { + ColorType silver = Color::Silver(); + EXPECT_EQ(silver.red, 0xC0); + EXPECT_EQ(silver.green, 0xC0); + EXPECT_EQ(silver.blue, 0xC0); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_GRAY_0200 +* @tc.name test color gray api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorGray, TestSize.Level0) { + ColorType gray = Color::Gray(); + EXPECT_EQ(gray.red, 0x80); + EXPECT_EQ(gray.green, 0x80); + EXPECT_EQ(gray.blue, 0x80); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_BLACK_0200 +* @tc.name test color black api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorBlack, TestSize.Level0) { + ColorType black = Color::Black(); + EXPECT_EQ(black.red, 0x00); + EXPECT_EQ(black.green, 0x00); + EXPECT_EQ(black.blue, 0x00); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_RED_0200 +* @tc.name test color red api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorRed, TestSize.Level0) { + ColorType red = Color::Red(); + EXPECT_EQ(red.red, 0xFF); + EXPECT_EQ(red.green, 0x00); + EXPECT_EQ(red.blue, 0x00); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_MAROON_0200 +* @tc.name test color maroon api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorMaroon, TestSize.Level0) { + ColorType maroon = Color::Maroon(); + EXPECT_EQ(maroon.red, 0x80); + EXPECT_EQ(maroon.green, 0x00); + EXPECT_EQ(maroon.blue, 0x00); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_YELLOW_0200 +* @tc.name test color yellow api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorYellow, TestSize.Level0) { + ColorType yellow = Color::Yellow(); + EXPECT_EQ(yellow.red, 0xFF); + EXPECT_EQ(yellow.green, 0xFF); + EXPECT_EQ(yellow.blue, 0x00); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_OLIVE_0200 +* @tc.name test color olive api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorOlive, TestSize.Level0) { + ColorType olive = Color::Olive(); + EXPECT_EQ(olive.red, 0x80); + EXPECT_EQ(olive.green, 0x80); + EXPECT_EQ(olive.blue, 0x00); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_LIME_0200 +* @tc.name test color lime api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorLime, TestSize.Level0) { + ColorType lime = Color::Lime(); + EXPECT_EQ(lime.red, 0x00); + EXPECT_EQ(lime.green, 0xFF); + EXPECT_EQ(lime.blue, 0x00); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_GREEN_0200 +* @tc.name test color green api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorGreen, TestSize.Level0) { + ColorType green = Color::Green(); + EXPECT_EQ(green.red, 0x00); + EXPECT_EQ(green.green, 0xFF); + EXPECT_EQ(green.blue, 0x00); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_CYAN_0200 +* @tc.name test color cyan api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorCyan, TestSize.Level0) { + ColorType cyan = Color::Cyan(); + EXPECT_EQ(cyan.red, 0x00); + EXPECT_EQ(cyan.green, 0xFF); + EXPECT_EQ(cyan.blue, 0xFF); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_AQUA_0200 +* @tc.name test color aqua api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorAqua, TestSize.Level0) { + ColorType aqua = Color::Aqua(); + EXPECT_EQ(aqua.red, 0x00); + EXPECT_EQ(aqua.green, 0xFF); + EXPECT_EQ(aqua.blue, 0xFF); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_TEAL_0200 +* @tc.name test color teal api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorTeal, TestSize.Level0) { + ColorType teal = Color::Teal(); + EXPECT_EQ(teal.red, 0x00); + EXPECT_EQ(teal.green, 0x80); + EXPECT_EQ(teal.blue, 0x80); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_BLUE_0200 +* @tc.name test color blue api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorBlue, TestSize.Level0) { + ColorType blue = Color::Blue(); + EXPECT_EQ(blue.red, 0x00); + EXPECT_EQ(blue.green, 0x00); + EXPECT_EQ(blue.blue, 0xFF); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_NAVY_0200 +* @tc.name test color navy api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorNavy, TestSize.Level0) { + ColorType navy = Color::Navy(); + EXPECT_EQ(navy.red, 0x00); + EXPECT_EQ(navy.green, 0x00); + EXPECT_EQ(navy.blue, 0x80); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_MAGENTA_0200 +* @tc.name test color magenta api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorMagenta, TestSize.Level0) { + ColorType magenta = Color::Magenta(); + EXPECT_EQ(magenta.red, 0xFF); + EXPECT_EQ(magenta.green, 0x00); + EXPECT_EQ(magenta.blue, 0xFF); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_PURPLE_0200 +* @tc.name test color purple api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorPurple, TestSize.Level0) { + ColorType purple = Color::Purple(); + EXPECT_EQ(purple.red, 0x80); + EXPECT_EQ(purple.green, 0x00); + EXPECT_EQ(purple.blue, 0x80); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_COLOR_COLOR_Orange_0200 +* @tc.name test color orange api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(ColorTest, testColorOrange, TestSize.Level0) { + ColorType orange = Color::Orange(); + EXPECT_EQ(orange.red, 0xFF); + EXPECT_EQ(orange.green, 0xA5); + EXPECT_EQ(orange.blue, 0x00); +} \ No newline at end of file diff --git a/uikit_lite/utils_posix/src/geometry2dTest.cpp b/uikit_lite/utils_posix/src/geometry2dTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..3bb8cb7321bc3f6e9d3208ee88345fce6cd2d3bd --- /dev/null +++ b/uikit_lite/utils_posix/src/geometry2dTest.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "utils/geometry2d.h" + +using namespace OHOS; +using namespace testing::ext; + +class Geometry2dTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_GEOMETRY2D_INTERSECT_0100 +* @tc.name test geometry2d intersect api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Geometry2dTest, testGeometry2dIntersect, TestSize.Level0) { + Vector2 pt11 = { 0, 200 }; + Vector2 pt12 = { 400, 200 }; + Line* line1 = new Line(pt11, pt12); + Vector2 pt21 = { 200, 0 }; + Vector2 pt22 = { 200, 400 }; + Line* line2 = new Line(pt21, pt22); + Vector2 pt31 = { 0, 0 }; + Vector2 pt32 = { 500, 0 }; + Line* line3 = new Line(pt31, pt32); + Vector2 out; + + EXPECT_EQ(Intersect(*line1, *line2, out), true); + EXPECT_EQ(out.x_, 200); + EXPECT_EQ(out.y_, 200); + EXPECT_EQ(Intersect(*line1, *line3, out), false); + delete(line1); + delete(line2); + delete(line3); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_GEOMETRY2D_ISINTERSECT_0100 +* @tc.name test geometry2d is intersect api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Geometry2dTest, testGeometry2dIsIntersect, TestSize.Level0) { + Vector2 pt11 = { 0, 200 }; + Vector2 pt12 = { 400, 200 }; + Line* line1 = new Line(pt11, pt12); + Vector2 pt21 = { 200, 0 }; + Vector2 pt22 = { 200, 400 }; + Line* line2 = new Line(pt21, pt22); + Vector2 pt31 = { 0, 0 }; + Vector2 pt32 = { 500, 0 }; + Line* line3 = new Line(pt31, pt32); + + EXPECT_EQ(IsIntersect(*line1, *line2), true); + EXPECT_EQ(IsIntersect(*line1, *line3), false); + delete(line1); + delete(line2); + delete(line3); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_GEOMETRY2D_CLIP_0100 +* @tc.name test geometry2d clip api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Geometry2dTest, testGeometry2dClip, TestSize.Level0) { + Vector2 vertexes[4] = { {0, 0}, {500, 100}, {300, 500}, {100, 300} }; + Polygon* polygon = new Polygon(vertexes, 4); + Vector2 pt11 = { 100, 300 }; + Vector2 pt12 = { 500, 100 }; + Line* line = new Line(pt11, pt12); + Clip(*polygon, *line); + + EXPECT_EQ(polygon->GetVertexNum(), 3); + EXPECT_EQ(polygon->operator[](0).x_, 500); + EXPECT_EQ(polygon->operator[](0).y_, 100); + EXPECT_EQ(polygon->operator[](1).x_, 100); + EXPECT_EQ(polygon->operator[](1).y_, 300); + EXPECT_EQ(polygon->operator[](2).x_, 0); + EXPECT_EQ(polygon->operator[](2).y_, 0); + delete(polygon); + delete(line); +} \ No newline at end of file diff --git a/uikit_lite/utils_posix/src/lineTest.cpp b/uikit_lite/utils_posix/src/lineTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..298573e81c4f433f08dec05916acaf568d3a4dae --- /dev/null +++ b/uikit_lite/utils_posix/src/lineTest.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "utils/geometry2d.h" + +using namespace OHOS; +using namespace testing::ext; + +class LineTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_LINE_OPERATOR_0100 +* @tc.name test line operator api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(LineTest, testLineOpeartor, TestSize.Level0) { + Vector2 pt1 = { 100, 200 }; + Vector2 pt2 = { 300, 400 }; + Line* line = new Line(pt1, pt2); + + EXPECT_EQ(line->operator[](0).x_, 100); + EXPECT_EQ(line->operator[](0).y_, 200); + EXPECT_EQ(line->operator[](1).x_, 300); + EXPECT_EQ(line->operator[](1).y_, 400); + delete(line); +} \ No newline at end of file diff --git a/uikit_lite/utils_posix/src/mathTest.cpp b/uikit_lite/utils_posix/src/mathTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..bf8f13e39ee31010c849a7bd62e4a5e8092de72d --- /dev/null +++ b/uikit_lite/utils_posix/src/mathTest.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "utils/graphic_math.h" + +using namespace OHOS; +using namespace testing::ext; + +class MathTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_MATH_SIN_0100 +* @tc.name test math sin api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(MathTest, testMathSin, TestSize.Level0) { + EXPECT_EQ(Sin(0), 0); + EXPECT_EQ(Sin(90), 32767); + EXPECT_EQ(Sin(180), 0); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_MATH_FASTATAN2_0100 +* @tc.name test math fast atan2 api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(MathTest, testMathFastAtan2, TestSize.Level0) { + EXPECT_EQ(FastAtan2(0, 1), 0); + EXPECT_EQ(FastAtan2(1, 0), 90); + EXPECT_EQ(FastAtan2(0, -1), 180); + EXPECT_EQ(FastAtan2(-1, 0), 270); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_MATH_SQRT_0100 +* @tc.name test math sqrt api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(MathTest, testMathSqrt, TestSize.Level0) { + EXPECT_EQ(Sqrt(0), 0); + EXPECT_EQ(Sqrt(4), 2); + EXPECT_EQ(Sqrt(25), 5); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_MATH_FLOATTOINT64_0100 +* @tc.name test math float to int 64 api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(MathTest, testMathFloatToInt64, TestSize.Level0) { + EXPECT_EQ(FloatToInt64(1), 256); +} \ No newline at end of file diff --git a/uikit_lite/utils_posix/src/matrix3Test.cpp b/uikit_lite/utils_posix/src/matrix3Test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..b2283131aa99e482b8b2fb66b9dfafeb5c8432ce --- /dev/null +++ b/uikit_lite/utils_posix/src/matrix3Test.cpp @@ -0,0 +1,255 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "utils/graphic_math.h" + +using namespace OHOS; +using namespace testing::ext; + +class Matrix3Test : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_MATRIX3_GETDATA_0100 +* @tc.name test matrix3 get data api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Matrix3Test, testMatrix3GetData, TestSize.Level0) { + Matrix3* matrix = new Matrix3(1, 1, 1, 1, 1, 1, 1, 1, 1); + EXPECT_EQ(matrix->GetData()[0], 1); + EXPECT_EQ(matrix->GetData()[5], 1); + delete(matrix); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_MATRIX3_OPERATOR_0100 +* @tc.name test matrix3 operator api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Matrix3Test, testMatrix3Operator, TestSize.Level0) { + Matrix3* matrix1 = new Matrix3(1, 1, 1, 1, 1, 1, 1, 1, 1); + Matrix3* matrix2 = new Matrix3(1, 2, 3, 4, 5, 6, 7, 8, 9); + Matrix3* matrix3 = &matrix1->operator*(*matrix2); + + EXPECT_EQ(matrix3->GetData()[0], 6); + EXPECT_EQ(matrix3->GetData()[1], 6); + EXPECT_EQ(matrix3->GetData()[2], 6); + EXPECT_EQ(matrix3->GetData()[3], 15); + EXPECT_EQ(matrix3->GetData()[4], 15); + EXPECT_EQ(matrix3->GetData()[5], 15); + EXPECT_EQ(matrix3->GetData()[6], 24); + EXPECT_EQ(matrix3->GetData()[7], 24); + EXPECT_EQ(matrix3->GetData()[8], 24); + delete(matrix1); + delete(matrix2); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_MATRIX3_OPERATOR_0200 +* @tc.name test matrix3 operator api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Matrix3Test, testMatrix3Operator2, TestSize.Level0) { + Matrix3* matrix1 = new Matrix3(1, 1, 1, 1, 1, 1, 1, 1, 1); + Vector3* vector1 = new Vector3(1, 2, 3); + Vector3* vector2 = &matrix1->operator*(*vector1); + + EXPECT_EQ(vector2->x_, 6); + EXPECT_EQ(vector2->y_, 6); + EXPECT_EQ(vector2->z_, 6); + delete(matrix1); + delete(vector1); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_MATRIX3_OPERATOR_0300 +* @tc.name test matrix3 operator api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Matrix3Test, testMatrix3Operator3, TestSize.Level0) { + Matrix3* matrix = new Matrix3(1, 2, 3, 4, 5, 6, 7, 8, 9); + + EXPECT_EQ(*matrix->operator[](0), 1); + EXPECT_EQ(*matrix->operator[](1), 4); + EXPECT_EQ(*matrix->operator[](2), 7); + delete(matrix); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_MATRIX3_OPERATOR_0400 +* @tc.name test matrix3 operator api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Matrix3Test, testMatrix3Operator4, TestSize.Level0) { + Matrix3* matrix1 = new Matrix3(1, 2, 3, 4, 5, 6, 7, 8, 9); + Matrix3* matrix2 = new Matrix3(1, 1, 1, 1, 1, 1, 1, 1, 1); + matrix1->operator=(*matrix2); + EXPECT_EQ(matrix1->GetData()[0], 1); + EXPECT_EQ(matrix1->GetData()[1], 1); + EXPECT_EQ(matrix1->GetData()[2], 1); + EXPECT_EQ(matrix1->GetData()[3], 1); + EXPECT_EQ(matrix1->GetData()[4], 1); + EXPECT_EQ(matrix1->GetData()[5], 1); + EXPECT_EQ(matrix1->GetData()[6], 1); + EXPECT_EQ(matrix1->GetData()[7], 1); + EXPECT_EQ(matrix1->GetData()[8], 1); + delete(matrix1); + delete(matrix2); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_MATRIX3_OPERATOR_0500 +* @tc.name test matrix3 operator api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Matrix3Test, testMatrix3Operator5, TestSize.Level0) { + Matrix3* matrix1 = new Matrix3(1, 1, 1, 1, 1, 1, 1, 1, 1); + Matrix3* matrix2 = new Matrix3(1, 1, 1, 1, 1, 1, 1, 1, 1); + Matrix3* matrix3 = new Matrix3(1, 1, 1, 1, 1, 1, 8, 1, 1); + EXPECT_EQ(matrix1->operator==(*matrix2), true); + EXPECT_EQ(matrix1->operator==(*matrix3), false); + delete(matrix1); + delete(matrix2); + delete(matrix3); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_MATRIX3_DETERMINANT_0100 +* @tc.name test matrix3 determinant api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Matrix3Test, testMatrix3Determinant, TestSize.Level0) { + Matrix3* matrix1 = new Matrix3(1, 2, 2, 2, 1, 2, 2, 2, 1); + EXPECT_EQ(matrix1->Determinant(), 5); + delete(matrix1); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_MATRIX3_Inverse_0100 +* @tc.name test matrix3 inverse api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Matrix3Test, testMatrix3Inverse, TestSize.Level0) { + Matrix3* matrix1 = new Matrix3(1, 1, 1, 1, 1, 1, 1, 1, 1); + Matrix3* matrix2 = &matrix1->Inverse(); + EXPECT_EQ(matrix2->GetData()[0], 1); + EXPECT_EQ(matrix2->GetData()[1], 1); + EXPECT_EQ(matrix2->GetData()[2], 1); + EXPECT_EQ(matrix2->GetData()[3], 1); + EXPECT_EQ(matrix2->GetData()[4], 1); + EXPECT_EQ(matrix2->GetData()[5], 1); + EXPECT_EQ(matrix2->GetData()[6], 1); + EXPECT_EQ(matrix2->GetData()[7], 1); + EXPECT_EQ(matrix2->GetData()[8], 1); + delete(matrix1); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_MATRIX3_ROTATE_0100 +* @tc.name test matrix3 rotate api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Matrix3Test, testMatrix3Rotate, TestSize.Level0) { + Matrix3 rotate = Matrix3::Rotate(0, Vector2(0, 0)); + EXPECT_EQ(rotate.GetData()[0], 32767); + EXPECT_EQ(rotate.GetData()[1], 0); + EXPECT_EQ(rotate.GetData()[2], 0); + EXPECT_EQ(rotate.GetData()[3], 0); + EXPECT_EQ(rotate.GetData()[4], 32767); + EXPECT_EQ(rotate.GetData()[5], 0); + EXPECT_EQ(rotate.GetData()[6], 0); + EXPECT_EQ(rotate.GetData()[7], 0); + EXPECT_EQ(rotate.GetData()[8], 32768); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_MATRIX3_SCALE_0100 +* @tc.name test matrix3 scale api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Matrix3Test, testMatrix3Scale, TestSize.Level0) { + Matrix3 scale = Matrix3::Scale(Vector2(256, 256), Vector2(0, 0)); + EXPECT_EQ(scale.GetData()[0], 256); + EXPECT_EQ(scale.GetData()[1], 0); + EXPECT_EQ(scale.GetData()[2], 0); + EXPECT_EQ(scale.GetData()[3], 0); + EXPECT_EQ(scale.GetData()[4], 256); + EXPECT_EQ(scale.GetData()[5], 0); + EXPECT_EQ(scale.GetData()[6], 0); + EXPECT_EQ(scale.GetData()[7], 0); + EXPECT_EQ(scale.GetData()[8], 256); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_MATRIX3_TRANSLATE_0100 +* @tc.name test matrix3 translate api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Matrix3Test, testMatrix3Translate, TestSize.Level0) { + Matrix3 translate = Matrix3::Translate(Vector2(0, 0)); + EXPECT_EQ(translate.GetData()[0], 1); + EXPECT_EQ(translate.GetData()[1], 0); + EXPECT_EQ(translate.GetData()[2], 0); + EXPECT_EQ(translate.GetData()[3], 0); + EXPECT_EQ(translate.GetData()[4], 1); + EXPECT_EQ(translate.GetData()[5], 0); + EXPECT_EQ(translate.GetData()[6], 0); + EXPECT_EQ(translate.GetData()[7], 0); + EXPECT_EQ(translate.GetData()[8], 1); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_MATRIX3_FLOATTOINT64_0100 +* @tc.name test matrix3 float to int 64 api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Matrix3Test, testMatrix3FloatToInt64, TestSize.Level0) { + EXPECT_EQ(FloatToInt64(1), 256); +} \ No newline at end of file diff --git a/uikit_lite/utils_posix/src/polygonTest.cpp b/uikit_lite/utils_posix/src/polygonTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..5314b2f485071419abac1fbcb9a480644ba4a0de --- /dev/null +++ b/uikit_lite/utils_posix/src/polygonTest.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "utils/geometry2d.h" + +using namespace OHOS; +using namespace testing::ext; + +class PolygonTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_POLYGON_MAKEAABB_0100 +* @tc.name test polygon makeAABB api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(PolygonTest, testPolygonMakeAABB, TestSize.Level0) { + Vector2 vertexes[4] = { {0, 0}, {500, 100}, {300, 500}, {100, 300} }; + Polygon* polygon = new Polygon(vertexes, 4); + Rect rect = polygon->MakeAABB(); + EXPECT_EQ(rect.GetLeft(), 0); + EXPECT_EQ(rect.GetTop(), 0); + EXPECT_EQ(rect.GetRight(), 500); + EXPECT_EQ(rect.GetBottom(), 500); + delete(polygon); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_POLYGON_GETVERTEXNUM_0100 +* @tc.name test polygon get vertex num api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(PolygonTest, testPolygonGetVertexNum, TestSize.Level0) { + Vector2 vertexes[4] = { {0, 0}, {500, 100}, {300, 500}, {100, 300} }; + Polygon* polygon = new Polygon(vertexes, 4); + EXPECT_EQ(polygon->GetVertexNum(), 4); + delete(polygon); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_POLYGON_SETVERTEXNUM_0100 +* @tc.name test polygon set vertex num api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(PolygonTest, testPolygonSetVertexNum, TestSize.Level0) { + Polygon* polygon = new Polygon(); + polygon->SetVertexNum(8); + EXPECT_EQ(polygon->GetVertexNum(), 8); + delete(polygon); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_POLYGON_OPERATOR_0100 +* @tc.name test polygon operator api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(PolygonTest, testPolygonOperator, TestSize.Level0) { + Vector2 vertexes[4] = { {0, 0}, {500, 100}, {300, 500}, {100, 300} }; + Polygon* polygon = new Polygon(vertexes, 4); + EXPECT_EQ(polygon->operator[](1).x_, 500); + EXPECT_EQ(polygon->operator[](2).y_, 500); + delete(polygon); +} \ No newline at end of file diff --git a/uikit_lite/utils_posix/src/rectTest.cpp b/uikit_lite/utils_posix/src/rectTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..2876ab03dd83f88eab5c7f5be7a6466fc8bef242 --- /dev/null +++ b/uikit_lite/utils_posix/src/rectTest.cpp @@ -0,0 +1,482 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "utils/geometry2d.h" + +using namespace OHOS; +using namespace testing::ext; + +class RectTest : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_OPERATOR_0100 +* @tc.name test rect operator api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectOpeartor, TestSize.Level0) { + Rect* rect1 = new Rect(); + rect1->SetRect(100, 200, 300, 400); + Rect* rect = new Rect(); + rect->operator=(*rect1); + + EXPECT_EQ(rect->GetLeft(), 100); + EXPECT_EQ(rect->GetTop(), 200); + EXPECT_EQ(rect->GetRight(), 300); + EXPECT_EQ(rect->GetBottom(), 400); + delete(rect1); + delete(rect); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_SETRECT_0100 +* @tc.name test rect set rect api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectSetRect, TestSize.Level0) { + Rect* rect = new Rect(); + rect->SetRect(100, 200, 300, 400); + + EXPECT_EQ(rect->GetLeft(), 100); + EXPECT_EQ(rect->GetTop(), 200); + EXPECT_EQ(rect->GetRight(), 300); + EXPECT_EQ(rect->GetBottom(), 400); + delete(rect); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_GETWIDTH_0100 +* @tc.name test rect get width api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectGetWidth, TestSize.Level0) { + Rect* rect = new Rect(); + rect->SetRect(100, 200, 300, 400); + + EXPECT_EQ(rect->GetWidth(), 201); + delete(rect); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_GETHEIGHT_0100 +* @tc.name test rect get height api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectGetHeight, TestSize.Level0) { + Rect* rect = new Rect(); + rect->SetRect(100, 200, 300, 400); + + EXPECT_EQ(rect->GetHeight(), 201); + delete(rect); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_GETX_0100 +* @tc.name test rect get x api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectGetX, TestSize.Level0) { + Rect* rect = new Rect(); + rect->SetRect(100, 200, 300, 400); + + EXPECT_EQ(rect->GetX(), 100); + delete(rect); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_GETY_0100 +* @tc.name test rect get y api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectGetY, TestSize.Level0) { + Rect* rect = new Rect(); + rect->SetRect(100, 200, 300, 400); + + EXPECT_EQ(rect->GetY(), 200); + delete(rect); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_GETLEFT_0100 +* @tc.name test rect get left api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectGetLeft, TestSize.Level0) { + Rect* rect = new Rect(); + rect->SetRect(100, 200, 300, 400); + + EXPECT_EQ(rect->GetLeft(), 100); + delete(rect); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_GETTOP_0100 +* @tc.name test rect get top api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectGetTop, TestSize.Level0) { + Rect* rect = new Rect(); + rect->SetRect(100, 200, 300, 400); + + EXPECT_EQ(rect->GetTop(), 200); + delete(rect); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_GETRIGHT_0100 +* @tc.name test rect get right api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectGetRight, TestSize.Level0) { + Rect* rect = new Rect(); + rect->SetRect(100, 200, 300, 400); + + EXPECT_EQ(rect->GetRight(), 300); + delete(rect); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_GETBOTTOM_0100 +* @tc.name test rect get bottom api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectGetBOTTOM, TestSize.Level0) { + Rect* rect = new Rect(); + rect->SetRect(100, 200, 300, 400); + EXPECT_EQ(rect->GetBottom(), 400); + delete(rect); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_SETX_0100 +* @tc.name test rect set x api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectSetX, TestSize.Level0) { + Rect* rect = new Rect(); + rect->SetRect(100, 200, 300, 400); + rect->SetX(200); + EXPECT_EQ(rect->GetLeft(), 200); + EXPECT_EQ(rect->GetRight(), 400); + delete(rect); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_SETY_0100 +* @tc.name test rect set y api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectSetY, TestSize.Level0) { + Rect* rect = new Rect(); + rect->SetRect(100, 200, 300, 400); + rect->SetY(300); + EXPECT_EQ(rect->GetTop(), 300); + EXPECT_EQ(rect->GetBottom(), 500); + delete(rect); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_SETPOSITION_0100 +* @tc.name test rect set position api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectSetPosition, TestSize.Level0) { + Rect* rect = new Rect(); + rect->SetRect(100, 200, 300, 400); + rect->SetPosition(200, 300); + EXPECT_EQ(rect->GetLeft(), 200); + EXPECT_EQ(rect->GetRight(), 400); + EXPECT_EQ(rect->GetTop(), 300); + EXPECT_EQ(rect->GetBottom(), 500); + delete(rect); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_SETWIDTH_0100 +* @tc.name test rect set width api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectSetWidth, TestSize.Level0) { + Rect* rect = new Rect(); + rect->SetRect(100, 200, 300, 400); + rect->SetWidth(300); + EXPECT_EQ(rect->GetRight(), 399); + delete(rect); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_SETHIGHT_0100 +* @tc.name test rect set height api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectSetHeight, TestSize.Level0) { + Rect* rect = new Rect(); + rect->SetRect(100, 200, 300, 400); + rect->SetHeight(300); + EXPECT_EQ(rect->GetBottom(), 499); + delete(rect); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_SETLEFT_0100 +* @tc.name test rect set left api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectSetLeft, TestSize.Level0) { + Rect* rect = new Rect(); + rect->SetLeft(200); + EXPECT_EQ(rect->GetLeft(), 200); + delete(rect); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_SETTOP_0100 +* @tc.name test rect set top api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectSetTop, TestSize.Level0) { + Rect* rect = new Rect(); + rect->SetTop(200); + EXPECT_EQ(rect->GetTop(), 200); + delete(rect); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_SETRIGHT_0100 +* @tc.name test rect set right api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectSetRight, TestSize.Level0) { + Rect* rect = new Rect(); + rect->SetRight(200); + EXPECT_EQ(rect->GetRight(), 200); + delete(rect); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_SETBOTTOM_0100 +* @tc.name test rect set bottom api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectSetBOTTOM, TestSize.Level0) { + Rect* rect = new Rect(); + rect->SetBottom(200); + EXPECT_EQ(rect->GetBottom(), 200); + delete(rect); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_RESIZE_0100 +* @tc.name test rect set resize api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectResize, TestSize.Level0) { + Rect* rect = new Rect(); + rect->SetRect(100, 200, 300, 400); + rect->Resize(300, 300); + + EXPECT_EQ(rect->GetLeft(), 100); + EXPECT_EQ(rect->GetTop(), 200); + EXPECT_EQ(rect->GetRight(), 399); + EXPECT_EQ(rect->GetBottom(), 499); + delete(rect); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_GETSIZE_0100 +* @tc.name test rect get size api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectGetSize, TestSize.Level0) { + Rect* rect = new Rect(); + rect->SetRect(100, 200, 300, 400); + EXPECT_EQ(rect->GetSize(), 40401); + delete(rect); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_INTERSECT_0100 +* @tc.name test rect intersect api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectIntersect, TestSize.Level0) { + Rect* rect1 = new Rect(100, 200, 300, 400); + Rect* rect2 = new Rect(0, 0, 500, 600); + Rect* rect3 = new Rect(100, 500, 300, 600); + + EXPECT_EQ(rect1->Intersect(*rect1, *rect2), true); + EXPECT_EQ(rect1->Intersect(*rect1, *rect3), false); + delete(rect1); + delete(rect2); + delete(rect3); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_ISINTERSECT_0100 +* @tc.name test rect is intersect api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectIsIntersect, TestSize.Level0) { + Rect* rect1 = new Rect(100, 200, 300, 400); + Rect* rect2 = new Rect(0, 0, 500, 600); + Rect* rect3 = new Rect(100, 500, 300, 700); + + EXPECT_EQ(rect1->IsIntersect(*rect2), true); + EXPECT_EQ(rect1->IsIntersect(*rect3), false); + delete(rect1); + delete(rect2); + delete(rect3); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_JOIN_0100 +* @tc.name test rect join api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectJoin, TestSize.Level0) { + Rect* rect1 = new Rect(100, 200, 300, 400); + Rect* rect2 = new Rect(0, 0, 500, 600); + Rect* rect3 = new Rect(100, 500, 300, 700); + + rect1->Join(*rect1, *rect2); + EXPECT_EQ(rect1->GetLeft(), 0); + EXPECT_EQ(rect1->GetTop(), 0); + EXPECT_EQ(rect1->GetRight(), 500); + EXPECT_EQ(rect1->GetBottom(), 600); + + rect1->Join(*rect1, *rect3); + EXPECT_EQ(rect1->GetLeft(), 0); + EXPECT_EQ(rect1->GetTop(), 0); + EXPECT_EQ(rect1->GetRight(), 500); + EXPECT_EQ(rect1->GetBottom(), 700); + delete(rect1); + delete(rect2); + delete(rect3); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_ISCONTAINS_0100 +* @tc.name test rect is contains api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectIsContains, TestSize.Level0) { + Rect* rect1 = new Rect(100, 200, 300, 400); + Vector2 pt1 = { 200, 300 }; + Vector2 pt2 = { 0, 0 }; + + EXPECT_EQ(rect1->IsContains(pt1), true); + EXPECT_EQ(rect1->IsContains(pt2), false); + delete(rect1); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_ISCONTAINS_0200 +* @tc.name test rect is contains api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectIsContains2, TestSize.Level0) { + Rect* rect1 = new Rect(100, 200, 300, 400); + Point pt1; + pt1.x = 200; + pt1.y = 300; + Point pt2; + pt2.x = 0; + pt2.y = 0; + EXPECT_EQ(rect1->IsContains(pt1), true); + EXPECT_EQ(rect1->IsContains(pt2), false); + delete(rect1); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_GEOMETRY2D_RECT_ISCONTAINS_0300 +* @tc.name test rect is contains api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(RectTest, testRectIsContains3, TestSize.Level0) { + Rect* rect1 = new Rect(100, 200, 300, 400); + Rect* rect2 = new Rect(0, 0, 500, 600); + Rect* rect3 = new Rect(100, 500, 300, 700); + + EXPECT_EQ(rect2->IsContains(*rect1), true); + EXPECT_EQ(rect2->IsContains(*rect3), false); + delete(rect1); + delete(rect2); + delete(rect3); +} diff --git a/uikit_lite/utils_posix/src/vector2Test.cpp b/uikit_lite/utils_posix/src/vector2Test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..5fc24bdaf183fe48f68e4ea00e2530d5a133226b --- /dev/null +++ b/uikit_lite/utils_posix/src/vector2Test.cpp @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "utils/graphic_math.h" + +using namespace OHOS; +using namespace testing::ext; + +class Vector2Test : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_VECTOR2_DOT_0100 +* @tc.name test vector2 dot api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Vector2Test, testVector2Dot, TestSize.Level0) { + Vector2* vector1 = new Vector2(5, 4); + Vector2* vector2 = new Vector2(3, 2); + + EXPECT_EQ(vector1->Dot(*vector2), 23); + delete(vector1); + delete(vector2); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_VECTOR2_CROSS_0100 +* @tc.name test vector2 cross api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Vector2Test, testVector2Cross, TestSize.Level0) { + Vector2* vector1 = new Vector2(5, 4); + Vector2* vector2 = new Vector2(3, 5); + + EXPECT_EQ(vector1->Cross(*vector2), 13); + delete(vector1); + delete(vector2); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_VECTOR2_OPERATOR_0100 +* @tc.name test vector2 operator api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Vector2Test, testVector2Operator, TestSize.Level0) { + Vector2* vector1 = new Vector2(5, 4); + Vector2 vector2 = vector1->operator-(); + + EXPECT_EQ(vector2.x_, 65531); + EXPECT_EQ(vector2.y_, 65532); + delete(vector1); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_VECTOR2_OPERATOR_0200 +* @tc.name test vector2 operator api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Vector2Test, testVector2Operator2, TestSize.Level0) { + Vector2* vector1 = new Vector2(5, 7); + Vector2* vector2 = new Vector2(3, 5); + Vector2 vector3 = vector1->operator-(*vector2); + + EXPECT_EQ(vector3.x_, 2); + EXPECT_EQ(vector3.y_, 2); + delete(vector1); + delete(vector2); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_VECTOR2_OPERATOR_0300 +* @tc.name test vector2 operator api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Vector2Test, testVector2Operator3, TestSize.Level0) { + Vector2* vector1 = new Vector2(5, 7); + Vector2* vector2 = new Vector2(3, 5); + Vector2 vector3 = vector1->operator+(*vector2); + + EXPECT_EQ(vector3.x_, 8); + EXPECT_EQ(vector3.y_, 12); + delete(vector1); + delete(vector2); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_VECTOR2_OPERATOR_0400 +* @tc.name test vector2 operator api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Vector2Test, testVector2Operator4, TestSize.Level0) { + Vector2* vector1 = new Vector2(5, 7); + Vector2 vector2 = vector1->operator*(2); + + EXPECT_EQ(vector2.x_, 10); + EXPECT_EQ(vector2.y_, 14); + delete(vector1); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_VECTOR2_OPERATOR_0500 +* @tc.name test vector2 operator api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Vector2Test, testVector2Operator5, TestSize.Level0) { + Vector2* vector1 = new Vector2(5, 7); + Vector2* vector2 = new Vector2(5, 7); + Vector2* vector3 = new Vector2(5, 8); + + EXPECT_EQ(vector1->operator==(*vector2), true); + EXPECT_EQ(vector1->operator==(*vector3), false); + delete(vector1); + delete(vector2); + delete(vector3); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_VECTOR2_OPERATOR_0600 +* @tc.name test vector2 operator api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Vector2Test, testVector2Operator6, TestSize.Level0) { + Vector2* vector1 = new Vector2(5, 7); + Vector2* vector2 = new Vector2(1, 2); + vector1->operator=(*vector2); + EXPECT_EQ(vector1->x_, 1); + EXPECT_EQ(vector1->y_, 2); + delete(vector1); + delete(vector2); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_VECTOR2_OPERATOR_0700 +* @tc.name test vector2 operator api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Vector2Test, testVector2Operator7, TestSize.Level0) { + Vector2* vector1 = new Vector2(5, 7); + Vector2* vector2 = new Vector2(1, 2); + vector1->operator+=(*vector2); + EXPECT_EQ(vector1->x_, 6); + EXPECT_EQ(vector1->y_, 9); + delete(vector1); + delete(vector2); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_VECTOR2_OPERATOR_0800 +* @tc.name test vector2 operator api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Vector2Test, testVector2Operator8, TestSize.Level0) { + Vector2* vector1 = new Vector2(5, 7); + Vector2* vector2 = new Vector2(1, 2); + vector1->operator-=(*vector2); + EXPECT_EQ(vector1->x_, 4); + EXPECT_EQ(vector1->y_, 5); + delete(vector1); + delete(vector2); +} \ No newline at end of file diff --git a/uikit_lite/utils_posix/src/vector3Test.cpp b/uikit_lite/utils_posix/src/vector3Test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..2e38805fceb16b0d63271f6d5a6e7d0f27664bb7 --- /dev/null +++ b/uikit_lite/utils_posix/src/vector3Test.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#include +#include "utils/graphic_math.h" + +using namespace OHOS; +using namespace testing::ext; + +class Vector3Test : public testing::Test { +protected: + // SetUpTestCase: Testsuit setup, run before 1st testcase + static void SetUpTestCase(void) {} + // TearDownTestCase: Testsuit teardown, run after last testcase + static void TearDownTestCase(void) {} + // Testcase setup + virtual void SetUp() {} + // Testcase teardown + virtual void TearDown() {} +}; + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_VECTOR3_OPERATOR_0100 +* @tc.name test vector3 operator api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Vector3Test, testVector3Operator, TestSize.Level0) { + Vector3* vector1 = new Vector3(3, 5, 7); + EXPECT_EQ(vector1->operator[](0), 3); + EXPECT_EQ(vector1->operator[](1), 5); + EXPECT_EQ(vector1->operator[](2), 7); + delete(vector1); +} + +/** +* @tc.number SUB_UIKIT_NDKAPI_MATH_VECTOR3_OPERATOR_0200 +* @tc.name test vector3 operator api +* @tc.desc [C- SOFTWARE -0200] +* @tc.size SMALL +* @tc.type FUNC +*/ +HWTEST_F(Vector3Test, testVector3Operator2, TestSize.Level0) { + Vector3* vector1 = new Vector3(3, 5, 7); + Vector3* vector2 = new Vector3(3, 5, 7); + Vector3* vector3 = new Vector3(3, 5, 9); + + EXPECT_EQ(vector1->operator==(*vector2), true); + EXPECT_EQ(vector1->operator==(*vector3), false); + delete(vector1); + delete(vector2); + delete(vector3); +} \ No newline at end of file diff --git a/utils_lite/kvstore_hal/BUILD.gn b/utils_lite/kvstore_hal/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..21546c46b1065bbc3ebc84acf7b6569acd5f5d57 --- /dev/null +++ b/utils_lite/kvstore_hal/BUILD.gn @@ -0,0 +1,28 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hctest_suite("ActsKvStoreTest") { + suite_name = "acts" + sources = [ + "src/kvstore_func_test.c", + ] + + include_dirs = [ + "src", + "//utils/native/lite/include", + "//base/iot_hardware/interfaces/kits/wifiiot_lite", + ] + cflags = [ "-Wno-error" ] +} diff --git a/utils_lite/kvstore_hal/Test.tmpl b/utils_lite/kvstore_hal/Test.tmpl new file mode 100755 index 0000000000000000000000000000000000000000..be8407e1286041a5af2bdc75a15633337376eb9d --- /dev/null +++ b/utils_lite/kvstore_hal/Test.tmpl @@ -0,0 +1,19 @@ +{ + "description": "Config for $module test cases", + "environment": [ + { + "type": "device", + "label": "wifiiot" + } + ], + "kits": [ + { + "type": "DeployKit", + "timeout": "20000", + "burn_file": "$subsystem/$module.bin" + } + ], + "driver": { + "type": "CTestLite" + } +} \ No newline at end of file diff --git a/utils_lite/kvstore_hal/src/kvstore_func_test.c b/utils_lite/kvstore_hal/src/kvstore_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..54cb1ce19511c2d94d105794d8f5c7c19bdfc5b5 --- /dev/null +++ b/utils_lite/kvstore_hal/src/kvstore_func_test.c @@ -0,0 +1,783 @@ +/* + * Copyright (c) 2020 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 "hos_types.h" +#include +#include "hctest.h" +#include "hos_errno.h" +#include "kv_store.h" +#include "utils_config.h" +#include "wifiiot_watchdog.h" + +#define MAX_KEY_LEN_TEST 32 +#define MAX_VALUE_LEN_TEST 128 +#define MAX_KEY_NUM_TEST 50 +#define MAX_CACHE_NUM_TEST 10 +#define INVALID_KEY_NUM 128 + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is utils + * @param : module name is kvStore + * @param : test suit name is KvStoreFuncTestSuite + */ +LITE_TEST_SUIT(utils, kvStore, KvStoreFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL KvStoreFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL KvStoreFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/* Create files in batches. */ +bool SetKVFiles (int num, const char* key, const char* value) +{ + int size; + int ret; + char keytemp[MAX_KEY_LEN_TEST] = {0}; + char valuetemp[MAX_VALUE_LEN_TEST] = {0}; + char temp[MAX_VALUE_LEN_TEST] = {0}; + if (num <= 0) { + return false; + } + for (int i = 1; i <= num; i++) { + size = sprintf_s(keytemp, MAX_KEY_LEN_TEST, "%s_%d", key, i); + if (size < 0) { + return false; + } + size = sprintf_s(valuetemp, MAX_VALUE_LEN_TEST, "%s_%d", value, i); + if (size < 0) { + return false; + } + ret = UtilsSetValue(keytemp, valuetemp); + if (i <= MAX_KEY_NUM_TEST) { + TEST_ASSERT_EQUAL_INT(0, ret); + } else { + TEST_ASSERT_EQUAL_INT(-1, ret); + } + ret = UtilsGetValue(keytemp, temp, MAX_VALUE_LEN_TEST); + if (i <= MAX_KEY_NUM_TEST) { +#ifdef FEATURE_KV_CACHE + TEST_ASSERT_EQUAL_INT(0, ret); +#else + TEST_ASSERT_GREATER_THAN_INT(0, ret); +#endif + TEST_ASSERT_EQUAL_STRING(valuetemp, temp); + } else { + TEST_ASSERT_EQUAL_INT(-1, ret); + } + memset_s(keytemp, MAX_KEY_LEN_TEST, 0, MAX_KEY_LEN_TEST); + memset_s(temp, MAX_VALUE_LEN_TEST, 0, MAX_VALUE_LEN_TEST); + memset_s(valuetemp, MAX_VALUE_LEN_TEST, 0, MAX_VALUE_LEN_TEST); + WatchDogKick(); + } + WatchDogKick(); + return true; +} + +/* Read files in batches. */ +bool ReadKVFiles (int num, const char* key, const char* value) +{ + int size; + int ret; + int i = 1; + char keytemp[MAX_KEY_LEN_TEST] = {0}; + char valuetemp[MAX_VALUE_LEN_TEST] = {0}; + char temp[MAX_VALUE_LEN_TEST] = {0}; + if (num <= 0) { + return false; + } + for (int loop = num; loop > 0; loop--) { + size = sprintf_s(keytemp, MAX_KEY_LEN_TEST, "%s_%d", key, loop); + if (size < 0) { + return false; + } + size = sprintf_s(valuetemp, MAX_VALUE_LEN_TEST, "%s_%d", value, loop); + if (size < 0) { + return false; + } + ret = UtilsGetValue(keytemp, temp, MAX_VALUE_LEN_TEST); + if (loop <= MAX_KEY_NUM_TEST) { + if (i <= MAX_CACHE_NUM_TEST) { +#ifdef FEATURE_KV_CACHE + TEST_ASSERT_EQUAL_INT(0, ret); +#else + TEST_ASSERT_GREATER_THAN_INT(0, ret); +#endif + } else { + TEST_ASSERT_GREATER_THAN_INT(0, ret); + } + TEST_ASSERT_EQUAL_STRING(valuetemp, temp); + i++; + } else { + TEST_ASSERT_EQUAL_INT(-1, ret); + } + memset_s(keytemp, MAX_KEY_LEN_TEST, 0, MAX_KEY_LEN_TEST); + memset_s(temp, MAX_VALUE_LEN_TEST, 0, MAX_VALUE_LEN_TEST); + memset_s(valuetemp, MAX_VALUE_LEN_TEST, 0, MAX_VALUE_LEN_TEST); + WatchDogKick(); + } + WatchDogKick(); + return true; +} + +/* Delete files in batches. */ +bool DeleteKVFiles (int num, const char* key) +{ + int size; + int ret; + char keytemp[MAX_KEY_LEN_TEST] = {0}; + + if (num <= 0) { + return false; + } + for (int i = 1; i <= num; i++) { + size = sprintf_s(keytemp, MAX_KEY_LEN_TEST, "%s_%d", key, i); + if (size < 0) { + return false; + } + ret = UtilsDeleteValue(keytemp); + if (i <= MAX_KEY_NUM_TEST) { + TEST_ASSERT_EQUAL_INT(0, ret); + } else { + TEST_ASSERT_EQUAL_INT(-1, ret); + } + memset_s(keytemp, MAX_KEY_LEN_TEST, 0, MAX_KEY_LEN_TEST); + WatchDogKick(); + } + WatchDogKick(); + return true; +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_100 + * @tc.name : UtilsSetValue parameter legal test(Lowercase alphanumeric, underscore, dot) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreSetValue001, LEVEL1) +{ + char key[] = "rw.sys.version"; + char value[] = "Hello world !"; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UtilsDeleteValue(key); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_500 + * @tc.name : UtilsSetValue parameter legal test(Lowercase alphanumeric, underscore, dot) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreSetValue002, LEVEL1) +{ + char key[] = "rw.sys.version_100"; + char value[] = "Hello world !"; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UtilsDeleteValue(key); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_800 + * @tc.name : UtilsSetValue parameter legal test(Lowercase alphanumeric, underscore, dot) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreSetValue003, LEVEL1) +{ + char key[] = "100"; + char value[] = "Hello world !"; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UtilsDeleteValue(key); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_600 + * @tc.name : UtilsSetValue parameter legal test(key = 31 Byte) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreSetValue004, LEVEL1) +{ + char key[] = "rw.sys.version.utilskvparameter"; + char value[] = "Hello world !"; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UtilsDeleteValue(key); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_700 + * @tc.name : UtilsSetValue parameter Illegal test(key = 32 Byte) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreSetValue005, LEVEL1) +{ + char key[] = "rw.sys.version.utilskvparameter1"; + char value[] = "Hello world !"; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(EC_INVALID, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_700 + * @tc.name : UtilsSetValue parameter Illegal test(key > 32 Byte) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreSetValue006, LEVEL1) +{ + char key[] = "rw.sys.version.utilskvparameterforillegal"; + char value[] = "Hello world !"; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(EC_INVALID, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_1100 + * @tc.name : UtilsSetValue parameter Illegal test(key is an invalid character) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreSetValue007, LEVEL1) +{ + char key[] = "Rw.sys.version"; + char value[] = "Hello world !"; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(EC_INVALID, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_1200 + * @tc.name : UtilsSetValue parameter Illegal test(key is an invalid character) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreSetValue008, LEVEL1) +{ + char key[] = "rw.sys.version-r3"; + char value[] = "Hello world !"; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(EC_INVALID, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_1200 + * @tc.name : UtilsSetValue parameter Illegal test(key is an invalid character) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreSetValue009, LEVEL1) +{ + char key[] = "re+r3"; + char value[] = "Hello world !"; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(EC_INVALID, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_1200 + * @tc.name : UtilsSetValue parameter Illegal test(key is an invalid character) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreSetValue010, LEVEL1) +{ + char key[] = "rw.sys.version*r3"; + char value[] = "Hello world !"; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(EC_INVALID, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_900 + * @tc.name : UtilsSetValue parameter legal test(Value is equal to 127 characters) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreSetValue011, LEVEL1) +{ + char key[] = "rw.sys.version"; + char value[] = "Two tigers Two tigers two tiger running so fast \ +running so fast one has no ears one has no tail How strange How strangesleeping"; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UtilsDeleteValue(key); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_1000 + * @tc.name : UtilsSetValue parameter Illegal test(Value is equal to 128 characters) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreSetValue012, LEVEL1) +{ + char key[] = "rw.sys.version"; + char value[] = "Two tigers Two tigers two tiger running so fast \ +running so fast one has no ears one has no tail How strange How strange sleeping"; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(EC_INVALID, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_1000 + * @tc.name : UtilsSetValue parameter Illegal test(Value greater than 128 characters) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreSetValue013, LEVEL1) +{ + char key[] = "rw.sys.version"; + char value[] = "Two tigers Two tigers two tiger running so fast \ +running so fast one has no ears one has no tail How strange How strange Are you sleeping"; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(EC_INVALID, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_1100 + * @tc.name : Value greater than 128 characters and key is an invalid character + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreSetValue014, LEVEL1) +{ + char key[] = "Rw.sys.version"; + char value[] = "Two tigers Two tigers two tiger running so fast \ +running so fast one has no ears one has no tail How strange How strange Are you sleeping"; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(EC_INVALID, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_100 + * @tc.name : UtilsSetValue parameter legal test(Lowercase alphanumeric, underscore, dot) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreSetValue015, LEVEL1) +{ + char key[] = "_._..__...___"; + char value[] = "!@#¥%……&*()——+~《》?,。、“‘;:、12345767890"; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UtilsDeleteValue(key); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_1200 + * @tc.name : UtilsSetValue parameter Illegal test(key contains space) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreSetValue016, LEVEL1) +{ + char key[] = "rw.sys.version space test"; + char value[] = "Hello world !"; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(EC_INVALID, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_100 + * @tc.name : UtilsSetValue parameter legal test(value contains only space) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreSetValue017, LEVEL1) +{ + char key[] = "rw.sys.version"; + char value[] = " "; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UtilsDeleteValue(key); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_300 + * @tc.name : Use the interface(UtilsGetValue) to get the kv value(cache) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreGetValue001, LEVEL1) +{ + char key[] = "rw.sys.version"; + char value[] = "It is never too old to learn"; + char temp[MAX_VALUE_LEN_TEST] = {0}; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UtilsGetValue(key, temp, MAX_VALUE_LEN_TEST); +#ifdef FEATURE_KV_CACHE + TEST_ASSERT_EQUAL_INT(0, ret); +#else + TEST_ASSERT_GREATER_THAN_INT(0, ret); +#endif + TEST_ASSERT_EQUAL_STRING(value, temp); + ret = UtilsDeleteValue(key); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_300 + * @tc.name : Use the interface(UtilsGetValue) to get the kv value(cache) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreGetValue002, LEVEL1) +{ + char key[] = "100"; + char value[] = "!@#¥%……&*()——+~《》?,。、“‘;:、12345767890"; + char temp[MAX_VALUE_LEN_TEST] = {0}; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UtilsGetValue(key, temp, MAX_VALUE_LEN_TEST); +#ifdef FEATURE_KV_CACHE + TEST_ASSERT_EQUAL_INT(0, ret); +#else + TEST_ASSERT_GREATER_THAN_INT(0, ret); +#endif + TEST_ASSERT_EQUAL_STRING(value, temp); + ret = UtilsDeleteValue(key); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_200 + * @tc.name : Use the interface(UtilsGetValue) to get the kv value(cache) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreGetValue003, LEVEL1) +{ + char key[] = "rw.sys.version.utilskvparameter"; + char value[] = "It is never too old to learn"; + char temp[MAX_VALUE_LEN_TEST] = {0}; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(0, ret); + + // Update the value of key + char value1[] = "Two tigers Two tigers two tiger running so fast \ +running so fast one has no ears one has no tail How strange How strangesleeping"; + ret = UtilsSetValue(key, value1); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UtilsGetValue(key, temp, MAX_VALUE_LEN_TEST); +#ifdef FEATURE_KV_CACHE + TEST_ASSERT_EQUAL_INT(0, ret); +#else + TEST_ASSERT_GREATER_THAN_INT(0, ret); +#endif + TEST_ASSERT_EQUAL_STRING(value1, temp); + ret = UtilsDeleteValue(key); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_300 + * @tc.name : UtilsGetValue parameter Illegal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreGetValue004, LEVEL1) +{ + char key[] = "Rw.sys.version"; + char temp[MAX_VALUE_LEN_TEST] = {0}; + int ret = UtilsGetValue(key, temp, MAX_VALUE_LEN_TEST); + TEST_ASSERT_EQUAL_INT(EC_INVALID, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_300 + * @tc.name : Use the interface(UtilsGetValue) to get the kv value(cache) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreGetValue005, LEVEL1) +{ + char key[] = "_._..__...___"; + char value[] = " "; + char temp[MAX_VALUE_LEN_TEST] = {0}; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = UtilsGetValue(key, temp, MAX_VALUE_LEN_TEST); +#ifdef FEATURE_KV_CACHE + TEST_ASSERT_EQUAL_INT(0, ret); +#else + TEST_ASSERT_GREATER_THAN_INT(0, ret); +#endif + TEST_ASSERT_EQUAL_STRING(value, temp); + ret = UtilsDeleteValue(key); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_400 + * @tc.name : UtilsDeleteValue parameter Illegal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreDeleteValue, LEVEL1) +{ + char key[] = "Rw.sys.version"; + int ret = UtilsDeleteValue(key); + TEST_ASSERT_EQUAL_INT(EC_INVALID, ret); +}; + +#ifdef FEATURE_KV_CACHE +/** + * @tc.number : SUB_UTILS_KV_STORE_300 + * @tc.name : Use the interface(ClearKVCache) to clear cache + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreClearCache001, LEVEL1) +{ + char key[] = "rw.sys.version"; + char value[] = "It is never too old to learn"; + char temp[MAX_VALUE_LEN_TEST] = {0}; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(0, ret); + // Get the value of key + ret = UtilsGetValue(key, temp, MAX_VALUE_LEN_TEST); + TEST_ASSERT_EQUAL_INT(0, ret); + TEST_ASSERT_EQUAL_STRING(value, temp); + // Clear cache + ret = ClearKVCache(); + TEST_ASSERT_EQUAL_INT(0, ret); + // Get the value of key + memset_s(temp, MAX_VALUE_LEN_TEST, 0, MAX_VALUE_LEN_TEST); + ret = UtilsGetValue(key, temp, MAX_VALUE_LEN_TEST); + TEST_ASSERT_GREATER_THAN_INT(0, ret); + TEST_ASSERT_EQUAL_STRING(value, temp); + // Clear key + ret = UtilsDeleteValue(key); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_200 + * @tc.name : Use the interface(ClearKVCache) to clear cache + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreClearCache002, LEVEL1) +{ + char key[] = "rw.sys.version"; + char value[] = "It is never too old to learn"; + char temp[MAX_VALUE_LEN_TEST] = {0}; + int ret = UtilsSetValue(key, value); + TEST_ASSERT_EQUAL_INT(0, ret); + + // Update the value of key + char value1[] = "Two tigers,Two tigers,two tiger,running so fast"; + ret = UtilsSetValue(key, value1); + TEST_ASSERT_EQUAL_INT(0, ret); + // Get the value of key + ret = UtilsGetValue(key, temp, MAX_VALUE_LEN_TEST); + TEST_ASSERT_EQUAL_INT(0, ret); + TEST_ASSERT_EQUAL_STRING(value1, temp); + // Clear cache + ret = ClearKVCache(); + TEST_ASSERT_EQUAL_INT(0, ret); + // Get the value of key + memset_s(temp, MAX_VALUE_LEN_TEST, 0, MAX_VALUE_LEN_TEST); + ret = UtilsGetValue(key, temp, MAX_VALUE_LEN_TEST); + TEST_ASSERT_GREATER_THAN_INT(0, ret); + TEST_ASSERT_EQUAL_STRING(value1, temp); + // Clear key + ret = UtilsDeleteValue(key); + TEST_ASSERT_EQUAL_INT(0, ret); +}; +#endif + +/** + * @tc.number : SUB_UTILS_KV_STORE_1600 + * @tc.name : Specification test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreCacheSize001, LEVEL1) +{ + char key[] = "rw.sys.version"; + char value[] = "It is never too old to learn"; + bool ret = false; + + ret = SetKVFiles(MAX_CACHE_NUM_TEST-1, key, value); + if (ret != true) + { + TEST_FAIL(); + } + ret = ReadKVFiles(MAX_CACHE_NUM_TEST-1, key, value); + if (ret != true) + { + TEST_FAIL(); + } + ret = DeleteKVFiles(MAX_CACHE_NUM_TEST-1, key); + if (ret != true) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_1600 + * @tc.name : Specification test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreCacheSize002, LEVEL1) +{ + char key[] = "rw.sys.version"; + char value[] = "It is never too old to learn"; + bool ret = false; + + ret = SetKVFiles(MAX_CACHE_NUM_TEST, key, value); + if (ret != true) + { + TEST_FAIL(); + } + ret = ReadKVFiles(MAX_CACHE_NUM_TEST, key, value); + if (ret != true) + { + TEST_FAIL(); + } + ret = DeleteKVFiles(MAX_CACHE_NUM_TEST, key); + if (ret != true) + { + TEST_FAIL(); + } +}; + +/** + * @tc.number : SUB_UTILS_KV_STORE_1600 + * @tc.name : Specification test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(KvStoreFuncTestSuite, testKvStoreCacheSize003, LEVEL1) +{ + char key[] = "rw.sys.version"; + char value[] = "It is never too old to learn"; + bool ret = false; + + ret = SetKVFiles(MAX_CACHE_NUM_TEST+1, key, value); + if (ret != true) + { + TEST_FAIL(); + } + ret = ReadKVFiles(MAX_CACHE_NUM_TEST+1, key, value); + if (ret != true) + { + TEST_FAIL(); + } + ret = DeleteKVFiles(MAX_CACHE_NUM_TEST+1, key); + if (ret != true) + { + TEST_FAIL(); + } +}; + +RUN_TEST_SUITE(KvStoreFuncTestSuite); diff --git a/utils_lite/kvstore_posix/BUILD.gn b/utils_lite/kvstore_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..d2c69fc488b2c6e65f8aae69812a5086e3b6c54d --- /dev/null +++ b/utils_lite/kvstore_posix/BUILD.gn @@ -0,0 +1,37 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hcpptest_suite("ActsKvStoreTest") { + suite_name = "acts" + sources = [ + "src/KvStoreTest.cpp" + ] + + include_dirs = [ + "src", + "//utils/native/lite/include", + "//utils/native/lite/kv_store/innerkits", + "//third_party/bounds_checking_function/include" + ] + deps = [ + "//utils/native/lite/kv_store:kv_store" + ] + cflags = [ "-Wno-error" ] + ldflags = [ + "-lstdc++", + "-lm", + "-lpthread" + ] +} diff --git a/utils_lite/kvstore_posix/Test.json b/utils_lite/kvstore_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..980fabab019fd035d5c774887cbf6d082b18ef3a --- /dev/null +++ b/utils_lite/kvstore_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for hcpptest demo test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/utils", + "target": "/test_root/utils" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/utils/ActsKvStoreTest.bin" + } +} \ No newline at end of file diff --git a/utils_lite/kvstore_posix/src/KvStoreTest.cpp b/utils_lite/kvstore_posix/src/KvStoreTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..fd46088ee80b6f83efda714f20387808a42fe611 --- /dev/null +++ b/utils_lite/kvstore_posix/src/KvStoreTest.cpp @@ -0,0 +1,726 @@ +/* + * Copyright (c) 2020 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 "gtest/gtest.h" +#include + +#include "utils_config.h" +#include "kv_store.h" +#include "kvstore_env.h" + +using namespace std; +using namespace testing::ext; + +const int MAX_KEY_LEN_TEST = 32; // Key length specifications +const int MAX_VALUE_LEN_TEST = 128; // Value length specifications +const int MAX_KEY_NUM_TEST = 50; // Maximum number of keys +const int MAX_CACHE_NUM_TEST = 10; // Minimum number of cache +const int INVALID_PARAMETER = -9; // Invalid parameter. + +class KvStoreTest : public testing::Test { +protected: + // SetUpTestCase:测试套预置动作,在第一个TestCase之前执行 + static void SetUpTestCase(void) + { + printf("----------test case with KvStoreTest start-------------\n"); + + + int ret = mkdir("/storage/com.huawei.kv", S_IRUSR | S_IWUSR); + printf("/storage/com.huawei.kv ret = %d\n", ret); + ret = UtilsSetEnv("/storage/com.huawei.kv"); + EXPECT_EQ(ret, 0); + } + // TearDownTestCase:测试套清理动作,在最后一个TestCase之后执行 + static void TearDownTestCase(void) + { + int ret = rmdir("/storage/com.huawei.kv/kvstore"); + printf("/storage/com.huawei.kv/kvstore ret = %d\n", ret); + ret = rmdir("/storage/com.huawei.kv"); + printf("/storage/com.huawei.kv ret = %d\n", ret); + printf("----------test case with KvStoreTest end-------------\n"); + } + // 用例的预置动作 + virtual void SetUp() {} + // 用例的清理动作 + virtual void TearDown() {} + bool TouchKVFiles (int num, const char* key, const char* value); + bool DeleteKVFiles (int num, const char* key); + bool ReadKVFiles (int num, const char* key, const char* value); +}; + +/* Create files in batches. */ +bool KvStoreTest::TouchKVFiles (int num, const char* key, const char* value) +{ + int size = 0; + int ret = 0; + char keytemp[MAX_KEY_LEN_TEST] = {0}; + char valuetemp[MAX_VALUE_LEN_TEST] = {0}; + char temp[MAX_VALUE_LEN_TEST] = {0}; + if (num <= 0) { + return false; + } + for (int i = 1; i <= num; i++) { + size = sprintf_s(keytemp, MAX_KEY_LEN_TEST, "%s_%d", key, i); + if (size < 0) { + return false; + } + size = sprintf_s(valuetemp, MAX_VALUE_LEN_TEST, "%s_%d", value, i); + if (size < 0) { + return false; + } + ret = UtilsSetValue(keytemp, valuetemp); + if (i <= MAX_KEY_NUM_TEST) { + EXPECT_EQ(ret, 0); + } else { + EXPECT_EQ(ret, -1); + } + ret = UtilsGetValue(keytemp, temp, MAX_VALUE_LEN_TEST); + if (i <= MAX_KEY_NUM_TEST) { + EXPECT_EQ(ret, 0); + EXPECT_STREQ(valuetemp, temp); + } else { + EXPECT_EQ(ret, -1); + } + memset_s(keytemp, MAX_KEY_LEN_TEST, 0, MAX_KEY_LEN_TEST); + memset_s(temp, MAX_VALUE_LEN_TEST, 0, MAX_VALUE_LEN_TEST); + memset_s(valuetemp, MAX_VALUE_LEN_TEST, 0, MAX_VALUE_LEN_TEST); + } + return true; +} + +/* Create files in batches. */ +bool KvStoreTest::ReadKVFiles (int num, const char* key, const char* value) +{ + int size = 0; + int ret = 0; + int i = 1; + char keytemp[MAX_KEY_LEN_TEST] = {0}; + char valuetemp[MAX_VALUE_LEN_TEST] = {0}; + char temp[MAX_VALUE_LEN_TEST] = {0}; + if (num <= 0) { + return false; + } + for (; num > 0; num--) { + size = sprintf_s(keytemp, MAX_KEY_LEN_TEST, "%s_%d", key, num); + if (size < 0) { + return false; + } + size = sprintf_s(valuetemp, MAX_VALUE_LEN_TEST, "%s_%d", value, num); + if (size < 0) { + return false; + } + ret = UtilsGetValue(keytemp, temp, MAX_VALUE_LEN_TEST); + if (num <= MAX_KEY_NUM_TEST) { + if (i <= MAX_CACHE_NUM_TEST) { + EXPECT_EQ(ret, 0); + } else { + EXPECT_GT(ret, 0); + } + EXPECT_STREQ(valuetemp, temp); + i++; + } else { + EXPECT_EQ(ret, -1); + } + memset_s(keytemp, MAX_KEY_LEN_TEST, 0, MAX_KEY_LEN_TEST); + memset_s(temp, MAX_VALUE_LEN_TEST, 0, MAX_VALUE_LEN_TEST); + memset_s(valuetemp, MAX_VALUE_LEN_TEST, 0, MAX_VALUE_LEN_TEST); + } + return true; +} + +/* Delete files in batches. */ +bool KvStoreTest::DeleteKVFiles (int num, const char* key) +{ + int size = 0; + int ret = 0; + char keytemp[MAX_KEY_LEN_TEST] = {0}; + + if (num <= 0) { + return false; + } + for (int i = 1; i <= num; i++) { + size = sprintf_s(keytemp, MAX_KEY_LEN_TEST, "%s_%d", key, i); + if (size < 0) { + return false; + } + ret = UtilsDeleteValue(keytemp); + if (i <= MAX_KEY_NUM_TEST) { + EXPECT_EQ(ret, 0); + } else { + EXPECT_EQ(ret, -1); + } + memset_s(keytemp, MAX_KEY_LEN_TEST, 0, MAX_KEY_LEN_TEST); + } + return true; +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_100 + * @tc.name : UtilsSetValue parameter legal test(Lowercase alphanumeric, underscore, dot) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(KvStoreTest, testUtilsSetValue001, TestSize.Level0) +{ + char key[] = "rw.sys.version"; + char value[] = "Hello world !"; + int ret = UtilsSetValue(key, value); + EXPECT_EQ(ret, 0); + + ret = UtilsDeleteValue(key); + EXPECT_EQ(ret, 0); +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_400 + * @tc.name : UtilsSetValue parameter legal test(Lowercase alphanumeric, underscore, dot) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(KvStoreTest, testUtilsSetValue002, TestSize.Level1) +{ + char key[] = "rw.sys.version_100"; + char value[] = "Hello world !"; + int ret = UtilsSetValue(key, value); + EXPECT_EQ(ret, 0); + + ret = UtilsDeleteValue(key); + EXPECT_EQ(ret, 0); +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_500 + * @tc.name : UtilsSetValue parameter legal test(Lowercase alphanumeric, underscore, dot) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(KvStoreTest, testUtilsSetValue003, TestSize.Level1) +{ + char key[] = "100"; + char value[] = "Hello world !"; + int ret = UtilsSetValue(key, value); + EXPECT_EQ(ret, 0); + + ret = UtilsDeleteValue(key); + EXPECT_EQ(ret, 0); +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_600 + * @tc.name : UtilsSetValue parameter legal test(key = 31 Byte) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(KvStoreTest, testUtilsSetValue004, TestSize.Level2) +{ + char key[] = "rw.sys.version.utilskvparameter"; + char value[] = "Hello world !"; + int ret = UtilsSetValue(key, value); + EXPECT_EQ(ret, 0); + + ret = UtilsDeleteValue(key); + EXPECT_EQ(ret, 0); +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_700 + * @tc.name : UtilsSetValue parameter Illegal test(key = 32 Byte) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(KvStoreTest, testUtilsSetValue005, TestSize.Level2) +{ + char key[] = "rw.sys.version.utilskvparameter1"; + char value[] = "Hello world !"; + int ret = UtilsSetValue(key, value); + EXPECT_EQ(ret, INVALID_PARAMETER); +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_700 + * @tc.name : UtilsSetValue parameter Illegal test(key = 33 Byte) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(KvStoreTest, testUtilsSetValue006, TestSize.Level2) +{ + char key[] = "rw.sys.version.utilskvparameter12"; + char value[] = "Hello world !"; + int ret = UtilsSetValue(key, value); + EXPECT_EQ(ret, INVALID_PARAMETER); +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_700 + * @tc.name : UtilsSetValue parameter Illegal test(key > 33 Byte) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(KvStoreTest, testUtilsSetValue007, TestSize.Level2) +{ + char key[] = "rw.sys.version.utilskvparameterforillegal"; + char value[] = "Hello world !"; + int ret = UtilsSetValue(key, value); + EXPECT_EQ(ret, INVALID_PARAMETER); +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_1100 + * @tc.name : UtilsSetValue parameter Illegal test(key is an invalid character) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(KvStoreTest, testUtilsSetValue008, TestSize.Level2) +{ + char key[] = "Rw.sys.version"; + char value[] = "Hello world !"; + int ret = UtilsSetValue(key, value); + EXPECT_EQ(ret, INVALID_PARAMETER); +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_1100 + * @tc.name : UtilsSetValue parameter Illegal test(key is an invalid character) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(KvStoreTest, testUtilsSetValue009, TestSize.Level2) +{ + char key[] = "rw.sys.version-r3"; + char value[] = "Hello world !"; + int ret = UtilsSetValue(key, value); + EXPECT_EQ(ret, INVALID_PARAMETER); +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_1100 + * @tc.name : UtilsSetValue parameter Illegal test(key is an invalid character) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(KvStoreTest, testUtilsSetValue010, TestSize.Level2) +{ + char key[] = "RE+R3"; + char value[] = "Hello world !"; + int ret = UtilsSetValue(key, value); + EXPECT_EQ(ret, INVALID_PARAMETER); +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_1100 + * @tc.name : UtilsSetValue parameter Illegal test(key is an invalid character) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(KvStoreTest, testUtilsSetValue0011, TestSize.Level2) +{ + char key[] = "rw.sys.version*r3"; + char value[] = "Hello world !"; + int ret = UtilsSetValue(key, value); + EXPECT_EQ(ret, INVALID_PARAMETER); +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_800 + * @tc.name : UtilsSetValue parameter legal test(Value is equal to 121 characters) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(KvStoreTest, testUtilsSetValue012, TestSize.Level0) +{ + char key[] = "rw.sys.version"; + char value[] = "Two tigers Two tigers two tiger running so fast \ +running so fast one has no ears one has no tail How strange How strange "; + int ret = UtilsSetValue(key, value); + EXPECT_EQ(ret, 0); + + ret = UtilsDeleteValue(key); + EXPECT_EQ(ret, 0); +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_800 + * @tc.name : UtilsSetValue parameter legal test(Value is equal to 126 characters) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(KvStoreTest, testUtilsSetValue013, TestSize.Level1) +{ + char key[] = "rw.sys.version"; + char value[] = "Two tigers Two tigers two tiger running so fast \ +running so fast one has no ears one has no tail How strange Howstrangesleeping"; + int ret = UtilsSetValue(key, value); + EXPECT_EQ(ret, 0); + + ret = UtilsDeleteValue(key); + EXPECT_EQ(ret, 0); +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_900 + * @tc.name : UtilsSetValue parameter legal test(Value is equal to 127 characters) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(KvStoreTest, testUtilsSetValue014, TestSize.Level1) +{ + char key[] = "rw.sys.version"; + char value[] = "Two tigers Two tigers two tiger running so fast \ +running so fast one has no ears one has no tail How strange How strangesleeping"; + int ret = UtilsSetValue(key, value); + EXPECT_EQ(ret, 0); + + ret = UtilsDeleteValue(key); + EXPECT_EQ(ret, 0); +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_1000 + * @tc.name : UtilsSetValue parameter Illegal test(Value is equal to 128 characters) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +HWTEST_F(KvStoreTest, testUtilsSetValue015, TestSize.Level1) +{ + char key[] = "rw.sys.version"; + char value[] = "Two tigers Two tigers two tiger running so fast \ +running so fast one has no ears one has no tail How strange How strange sleeping"; + int ret = UtilsSetValue(key, value); + EXPECT_EQ(ret, INVALID_PARAMETER); +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_1000 + * @tc.name : UtilsSetValue parameter Illegal test(Value greater than 128 characters) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(KvStoreTest, testUtilsSetValue016, TestSize.Level2) +{ + char key[] = "rw.sys.version"; + char value[] = "Two tigers Two tigers two tiger running so fast \ +running so fast one has no ears one has no tail How strange How strange Are you sleeping"; + int ret = UtilsSetValue(key, value); + EXPECT_EQ(ret, INVALID_PARAMETER); +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_1200 + * @tc.name : Value greater than 128 characters and key is an invalid character + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 2 + */ +HWTEST_F(KvStoreTest, testUtilsSetValue017, TestSize.Level2) +{ + char key[] = "Rw.sys.version"; + char value[] = "Two tigers Two tigers two tiger running so fast \ +running so fast one has no ears one has no tail How strange How strange Are you sleeping"; + int ret = UtilsSetValue(key, value); + EXPECT_EQ(ret, INVALID_PARAMETER); +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_300 + * @tc.name : Use the interface(UtilsGetValue) to get the kv value(cache) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(KvStoreTest, testUtilsGetValue001, TestSize.Level0) +{ + char key[] = "rw.sys.version"; + char value[] = "It is never too old to learn"; + char temp[MAX_VALUE_LEN_TEST] = {0}; + int ret = UtilsSetValue(key, value); + EXPECT_EQ(ret, 0); + + ret = UtilsGetValue(key, temp, MAX_VALUE_LEN_TEST); + EXPECT_EQ(ret, 0); + EXPECT_STREQ(value, temp); + ret = UtilsDeleteValue(key); + EXPECT_EQ(ret, 0); +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_300 + * @tc.name : Use the interface(UtilsGetValue) to get the kv value(cache) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(KvStoreTest, testUtilsGetValue002, TestSize.Level1) +{ + char key[] = "100"; + char value[] = "!@#¥%……&*()——+~《》?,。、“‘;:、12345767890"; + char temp[MAX_VALUE_LEN_TEST] = {0}; + int ret = UtilsSetValue(key, value); + EXPECT_EQ(ret, 0); + + ret = UtilsGetValue(key, temp, MAX_VALUE_LEN_TEST); + EXPECT_EQ(ret, 0); + EXPECT_STREQ(value, temp); + ret = UtilsDeleteValue(key); + EXPECT_EQ(ret, 0); +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_200 + * @tc.name : Use the interface(UtilsGetValue) to get the kv value(cache) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(KvStoreTest, testUtilsGetValue003, TestSize.Level1) +{ + char key[] = "rw.sys.version"; + char value[] = "It is never too old to learn"; + char temp[MAX_VALUE_LEN_TEST] = {0}; + // Update the value of key + char value1[] = "Two tigers,Two tigers,two tiger,running so fast"; + int ret = UtilsSetValue(key, value1); + EXPECT_EQ(ret, 0); + + ret = UtilsGetValue(key, temp, MAX_VALUE_LEN_TEST); + EXPECT_EQ(ret, 0); + EXPECT_STREQ(value1, temp); + ret = UtilsDeleteValue(key); + EXPECT_EQ(ret, 0); +} + +#ifdef FEATURE_KV_CACHE +/** + * @tc.number : SUB_UTILS_KV_STORE_300 + * @tc.name : Use the interface(ClearKVCache) to clear cache + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(KvStoreTest, testClearKVCache001, TestSize.Level0) +{ + char key[] = "rw.sys.version"; + char value[] = "It is never too old to learn"; + char temp[MAX_VALUE_LEN_TEST] = {0}; + int ret = UtilsSetValue(key, value); + EXPECT_EQ(ret, 0); + // Get the value of key + ret = UtilsGetValue(key, temp, MAX_VALUE_LEN_TEST); + EXPECT_EQ(ret, 0); + EXPECT_STREQ(value, temp); + // Clear cache + ret = ClearKVCache(); + EXPECT_EQ(ret, 0); + // Get the value of key + memset_s(temp, MAX_VALUE_LEN_TEST, 0, MAX_VALUE_LEN_TEST); + ret = UtilsGetValue(key, temp, MAX_VALUE_LEN_TEST); + EXPECT_GT(ret, 0); + EXPECT_STREQ(value, temp); + // Clear key + ret = UtilsDeleteValue(key); + EXPECT_EQ(ret, 0); +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_200 + * @tc.name : Use the interface(ClearKVCache) to clear cache + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(KvStoreTest, testClearKVCache002, TestSize.Level1) +{ + char key[] = "rw.sys.version"; + char value[] = "It is never too old to learn"; + char temp[MAX_VALUE_LEN_TEST] = {0}; + // Update the value of key + char value1[] = "Two tigers,Two tigers,two tiger,running so fast"; + int ret = UtilsSetValue(key, value1); + EXPECT_EQ(ret, 0); + // Get the value of key + ret = UtilsGetValue(key, temp, MAX_VALUE_LEN_TEST); + EXPECT_EQ(ret, 0); + EXPECT_STREQ(value1, temp); + // Clear cache + ret = ClearKVCache(); + EXPECT_EQ(ret, 0); + // Get the value of key + memset_s(temp, MAX_VALUE_LEN_TEST, 0, MAX_VALUE_LEN_TEST); + ret = UtilsGetValue(key, temp, MAX_VALUE_LEN_TEST); + EXPECT_GT(ret, 0); + EXPECT_STREQ(value1, temp); + // Clear key + ret = UtilsDeleteValue(key); + EXPECT_EQ(ret, 0); +} +#endif + +/** + * @tc.number : SUB_UTILS_KV_STORE_1300 + * @tc.name : Specification test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(KvStoreTest, testKVCacheCacheSize001, TestSize.Level1) +{ + char key[] = "rw.sys.version"; + char value[] = "It is never too old to learn"; + bool ret = false; + + ret = TouchKVFiles(MAX_CACHE_NUM_TEST-1, key, value); + if (ret == true) + { + SUCCEED(); + }else + { + ADD_FAILURE(); + } + ret = ReadKVFiles(MAX_CACHE_NUM_TEST-1, key, value); + if (ret == true) + { + SUCCEED(); + }else + { + ADD_FAILURE(); + } + ret = DeleteKVFiles(MAX_CACHE_NUM_TEST-1, key); + if (ret == true) + { + SUCCEED(); + }else + { + ADD_FAILURE(); + } +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_1300 + * @tc.name : Specification test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(KvStoreTest, testKVCacheCacheSize002, TestSize.Level1) +{ + char key[] = "rw.sys.version"; + char value[] = "It is never too old to learn"; + bool ret = false; + + ret = TouchKVFiles(MAX_CACHE_NUM_TEST, key, value); + if (ret == true) + { + SUCCEED(); + }else + { + ADD_FAILURE(); + } + ret = ReadKVFiles(MAX_CACHE_NUM_TEST, key, value); + if (ret == true) + { + SUCCEED(); + }else + { + ADD_FAILURE(); + } + ret = DeleteKVFiles(MAX_CACHE_NUM_TEST, key); + if (ret == true) + { + SUCCEED(); + }else + { + ADD_FAILURE(); + } +} + +/** + * @tc.number : SUB_UTILS_KV_STORE_1300 + * @tc.name : Specification test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 0 + */ +HWTEST_F(KvStoreTest, testKVCacheCacheSize003, TestSize.Level1) +{ + char key[] = "rw.sys.version"; + char value[] = "It is never too old to learn"; + bool ret = false; + + ret = TouchKVFiles(MAX_CACHE_NUM_TEST+1, key, value); + if (ret == true) + { + SUCCEED(); + }else + { + ADD_FAILURE(); + } + ret = ReadKVFiles(MAX_CACHE_NUM_TEST+1, key, value); + if (ret == true) + { + SUCCEED(); + }else + { + ADD_FAILURE(); + } + ret = DeleteKVFiles(MAX_CACHE_NUM_TEST+1, key); + if (ret == true) + { + SUCCEED(); + }else + { + ADD_FAILURE(); + } +} \ No newline at end of file diff --git a/utils_lite/parameter_hal/BUILD.gn b/utils_lite/parameter_hal/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..bed9a60bfcfc4274bb11b5fc45e2468987777448 --- /dev/null +++ b/utils_lite/parameter_hal/BUILD.gn @@ -0,0 +1,29 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hctest_suite("ActsParameterTest") { + suite_name = "acts" + sources = [ + "src/parameter_func_test.c", + "src/parameter_reli_test.c", + "src/parameter_utils.c" + ] + + include_dirs = [ + "src", + "//base/startup/interfaces/kits/syspara_lite", + ] + cflags = [ "-Wno-error" ] +} diff --git a/utils_lite/parameter_hal/Test.tmpl b/utils_lite/parameter_hal/Test.tmpl new file mode 100755 index 0000000000000000000000000000000000000000..be8407e1286041a5af2bdc75a15633337376eb9d --- /dev/null +++ b/utils_lite/parameter_hal/Test.tmpl @@ -0,0 +1,19 @@ +{ + "description": "Config for $module test cases", + "environment": [ + { + "type": "device", + "label": "wifiiot" + } + ], + "kits": [ + { + "type": "DeployKit", + "timeout": "20000", + "burn_file": "$subsystem/$module.bin" + } + ], + "driver": { + "type": "CTestLite" + } +} \ No newline at end of file diff --git a/utils_lite/parameter_hal/src/parameter_func_test.c b/utils_lite/parameter_hal/src/parameter_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..e764c14ee585c84bab05469bb6f9c87f258ce629 --- /dev/null +++ b/utils_lite/parameter_hal/src/parameter_func_test.c @@ -0,0 +1,1167 @@ +/* + * Copyright (c) 2020 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 "hos_types.h" +#include +#include "hctest.h" +#include "parameter.h" +#include "parameter_utils.h" + +#define MAX_LEN 128 +#define INVALID_LEN 2 +#define COMMON_ERROR (-1) +#define INVALID_PARAMETER (-9) + +static const char* g_defSysParam = "data of sys param ***..."; + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is utils + * @param : module name is parameter + * @param : test suit name is ParameterFuncTestSuite + */ +LITE_TEST_SUIT(utils, parameter, ParameterFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL ParameterFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL ParameterFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara001, LEVEL1) +{ + char* value = GetProductType(); + printf("Product Type=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara002, LEVEL1) +{ + char* value = GetManufacture(); + printf("Manufacture=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara003, LEVEL1) +{ + char* value = GetBrand(); + printf("Brand=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara004, LEVEL1) +{ + char* value = GetMarketName(); + printf("Market Name=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara005, LEVEL1) +{ + char* value = GetProductSeries(); + printf("Product Series=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara006, LEVEL1) +{ + char* value = GetProductModel(); + printf("Product Model=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara007, LEVEL1) +{ + char* value = GetHardwareModel(); + printf("Hardware Model=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara008, LEVEL1) +{ + char* value = GetHardwareProfile(); + printf("Hardware Profile=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara009, LEVEL1) +{ + char* value = GetSerial(); + printf("Serial=%s\n", value); + if (value == NULL) { + printf("The serial number needs to be written\n"); + TEST_IGNORE(); + } else { + TEST_ASSERT_EQUAL_INT(1, 1); + } + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara010, LEVEL1) +{ + char* value = GetOsName(); + printf("Os Name=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara011, LEVEL1) +{ + char* value = GetDisplayVersion(); + printf("Display Version=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara012, LEVEL1) +{ + char* value = GetBootloaderVersion(); + printf("Bootloader Version=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara013, LEVEL1) +{ + char* value = GetSecurityPatchTag(); + printf("Secure Patch Level=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara014, LEVEL1) +{ + char* value = GetAbiList(); + printf("Abi List=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara015, LEVEL1) +{ + char* value = GetFirstApiLevel(); + printf("First Api Level=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara016, LEVEL1) +{ + char* value = GetIncrementalVersion(); + printf("Incremental Version=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara017, LEVEL1) +{ + char* value = GetVersionId(); + printf("Version Id=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara018, LEVEL1) +{ + char* value = GetBuildType(); + printf("Build Type=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara019, LEVEL1) +{ + char* value = GetBuildUser(); + printf("Build User=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara020, LEVEL1) +{ + char* value = GetBuildHost(); + printf("Build Host=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara021, LEVEL1) +{ + char* value = GetBuildTime(); + printf("Build Time=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara022, LEVEL1) +{ + char* value = GetBuildRootHash(); + printf("Build Root Hash=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara023, LEVEL1) +{ + char* value = GetSoftwareModel(); + printf("Software Model=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Obtaining system parameter + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testObtainSysPara024, LEVEL1) +{ + char* value = GetSdkApiLevel(); + printf("Sdk Api Level=%s\n", value); + IsEmpty(value); + free(value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : SetParameter parameter legal test(Lowercase alphanumeric, underscore, dot) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testSetParameter001, LEVEL1) +{ + int ret; + + char key[] = "rw.sys.version_606"; + char value[] = "OEM-hisi-10.1.0"; + ret = SetParameter(key, value); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : SetParameter parameter legal test(Lowercase alphanumeric, underscore, dot) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testSetParameter002, LEVEL1) +{ + int ret; + + char key[] = "_._..__...___"; + char value[] = "!@#¥%……&*()——+~《》?,。、“‘;:、12345767890"; + ret = SetParameter(key, value); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : SetParameter parameter legal test(Lowercase alphanumeric, underscore, dot) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testSetParameter003, LEVEL1) +{ + int ret; + + char key[] = "keywithonlylowercase"; + char value[] = "test key with only lowercase"; + ret = SetParameter(key, value); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : SetParameter parameter legal test(Lowercase alphanumeric, underscore, dot) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testSetParameter004, LEVEL1) +{ + int ret; + + char key[] = "202006060602"; + char value[] = "test key with only number"; + ret = SetParameter(key, value); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : SetParameter parameter legal test(length:key 31 bytes, value 127 bytes) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testSetParameter005, LEVEL1) +{ + int ret; + + char key1[] = "rw.sys.version.version.version."; + char value1[] = "set with key = 31"; + ret = SetParameter(key1, value1); + TEST_ASSERT_EQUAL_INT(0, ret); + + char key2[] = "rw.sys.version.version"; + char value2[] = "abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890\ +abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrs"; + ret = SetParameter(key2, value2); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : SetParameter parameter illegal test(key is nullptr, value is nullptr) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testSetParameter006, LEVEL1) +{ + int ret; + + char value[] = "test with null"; + ret = SetParameter(NULL, value); + if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + } + + char key[] = "rw.sys.version"; + ret = SetParameter(key, NULL); + if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + } +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : SetParameter parameter illegal test(key is NULL, value is NULL) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testSetParameter007, LEVEL1) +{ + int ret; + + char value[] = "test with null"; + ret = SetParameter("\0", value); + if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + } + + char key[] = "rw.sys.version"; + ret = SetParameter(key, "\0"); + if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + } +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : SetParameter parameter illegal test(key len is 32 or more than 32 bytes) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testSetParameter008, LEVEL1) +{ + int ret; + + char key1[] = "rw.sys.version.version.version.v"; + char value1[] = "set with key = 32"; + ret = SetParameter(key1, value1); + if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + } + + char key2[] = "rw.sys.version.version.version.version"; + char value2[] = "set with key > 32"; + ret = SetParameter(key2, value2); + if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + } +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : SetParameter parameter illegal test(key with uppercase) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testSetParameter009, LEVEL1) +{ + int ret; + + char key[] = "Rw.Sys.Version.Version"; + char value[] = "set value with uppercase"; + ret = SetParameter(key, value); + if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + } +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : SetParameter parameter illegal test(key with blank) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testSetParameter010, LEVEL1) +{ + int ret; + + char key[] = "rw sys version version"; + char value[] = "set value with blank"; + ret = SetParameter(key, value); + if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + } +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : SetParameter parameter illegal test(key with special characters) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testSetParameter011, LEVEL1) +{ + int ret; + + char key[] = "rw+sys&version%version*"; + char value[] = "set value with special characters"; + ret = SetParameter(key, value); + if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + } +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : SetParameter parameter illegal test(value length is 128 or more than 128 bytes) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testSetParameter012, LEVEL1) +{ + int ret; + + char key1[] = "rw.sys.version.version1"; + char value1[] = "abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890\ +abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrst"; + ret = SetParameter(key1, value1); + if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + } + + char key2[] = "rw.sys.version.version2"; + char value2[] = "abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890\ +abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890"; + ret = SetParameter(key2, value2); + if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + } +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : SetParameter parameter legal test(value contains only blanks) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testSetParameter013, LEVEL1) +{ + int ret; + + char key[] = "key_for_blank_value"; + char value[] = " "; + ret = SetParameter(key, value); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : GetParameter parameter legal test(Lowercase alphanumeric, underscore, dot) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testGetParameter001, LEVEL1) +{ + int ret; + + char key[] = "rw.sys.version_606"; + char rightVal[] = "OEM-hisi-10.1.0"; + char value[MAX_LEN] = {0}; + SetParameter(key, rightVal); + ret = GetParameter(key, g_defSysParam, value, MAX_LEN); + TEST_ASSERT_EQUAL_INT(strlen(rightVal), ret); + TEST_ASSERT_EQUAL_STRING(rightVal, value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : GetParameter parameter legal test(Lowercase alphanumeric, underscore, dot) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testGetParameter002, LEVEL1) +{ + int ret; + + char key[] = "_._..__...___"; + char rightVal[] = "!@#¥%……&*()——+~《》?,。、“‘;:、12345767890"; + char value[MAX_LEN] = {0}; + SetParameter(key, rightVal); + ret = GetParameter(key, g_defSysParam, value, MAX_LEN); + TEST_ASSERT_EQUAL_INT(strlen(rightVal), ret); + TEST_ASSERT_EQUAL_STRING(rightVal, value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : GetParameter parameter legal test(Lowercase alphanumeric, underscore, dot) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testGetParameter003, LEVEL1) +{ + int ret; + + char key[] = "keywithonlylowercase"; + char rightVal[] = "test key with only lowercase"; + char value[MAX_LEN] = {0}; + SetParameter(key, rightVal); + ret = GetParameter(key, g_defSysParam, value, MAX_LEN); + TEST_ASSERT_EQUAL_INT(strlen(rightVal), ret); + TEST_ASSERT_EQUAL_STRING(rightVal, value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : GetParameter parameter legal test(Lowercase alphanumeric, underscore, dot) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testGetParameter004, LEVEL1) +{ + int ret; + + char key[] = "202006060602"; + char rightVal[] = "test key with only number"; + char value[MAX_LEN] = {0}; + SetParameter(key, rightVal); + ret = GetParameter(key, g_defSysParam, value, MAX_LEN); + TEST_ASSERT_EQUAL_INT(strlen(rightVal), ret); + TEST_ASSERT_EQUAL_STRING(rightVal, value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : GetParameter parameter legal test(defaut value point is nullptr) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testGetParameter005, LEVEL1) +{ + int ret; + + char key[] = "rw.sys.version_606"; + char rightVal[] = "OEM-hisi-10.1.0"; + char value[MAX_LEN] = {0}; + SetParameter(key, rightVal); + ret = GetParameter(key, NULL, value, MAX_LEN); + TEST_ASSERT_EQUAL_INT(strlen(rightVal), ret); + TEST_ASSERT_EQUAL_STRING(rightVal, value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : GetParameter parameter legal test(none exist key) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testGetParameter006, LEVEL1) +{ + int ret; + + char key[] = "none.exist.key"; + char value[MAX_LEN] = {0}; + ret = GetParameter(key, g_defSysParam, value, MAX_LEN); + TEST_ASSERT_EQUAL_INT(strlen(g_defSysParam), ret); + TEST_ASSERT_EQUAL_STRING(g_defSysParam, value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : GetParameter parameter legal test(length:key is 31 bytes, value is 127 bytes) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testGetParameter007, LEVEL1) +{ + int ret; + + char key1[] = "rw.sys.version.version.version."; + char rightVal1[] = "set with key = 31"; + char value1[MAX_LEN] = {0}; + SetParameter(key1, rightVal1); + ret = GetParameter(key1, g_defSysParam, value1, MAX_LEN); + TEST_ASSERT_EQUAL_INT(strlen(rightVal1), ret); + TEST_ASSERT_EQUAL_STRING(rightVal1, value1); + + char key2[] = "rw.sys.version.version"; + char rightVal2[] = "abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890\ +abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrs"; + char value2[MAX_LEN] = {0}; + SetParameter(key2, rightVal2); + ret = GetParameter(key2, g_defSysParam, value2, MAX_LEN); + TEST_ASSERT_EQUAL_INT(strlen(rightVal2), ret); + TEST_ASSERT_EQUAL_STRING(rightVal2, value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : GetParameter parameter illegal test(value length is too short) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testGetParameter008, LEVEL1) +{ + int ret; + + char key[] = "rw.sys.version_606"; + char rightVal[] = "OEM-hisi-10.1.0"; + char value[INVALID_LEN] = {0}; + SetParameter(key, rightVal); + ret = GetParameter(key, g_defSysParam, value, INVALID_LEN); + if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + } +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : GetParameter parameter illegal test(value point is nullptr) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testGetParameter009, LEVEL1) +{ + int ret; + + char key[] = "rw.sys.version_606"; + char rightVal[] = "OEM-hisi-10.1.0"; + SetParameter(key, rightVal); + ret = GetParameter(key, g_defSysParam, NULL, MAX_LEN); + if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + } +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : GetParameter parameter illegal test(key is not exist and value len is too short) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testGetParameter010, LEVEL1) +{ + int ret; + + char key[] = "none.exist.key"; + char value[INVALID_LEN] = {0}; + ret = GetParameter(key, g_defSysParam, value, INVALID_LEN); + TEST_ASSERT_EQUAL_INT(-1, ret); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : GetParameter parameter illegal test(key is not exist and defaut value point is nullptr) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testGetParameter011, LEVEL1) +{ + int ret; + + char key[] = "none.exist.key"; + char value[MAX_LEN] = {0}; + ret = GetParameter(key, NULL, value, MAX_LEN); + TEST_ASSERT_EQUAL_INT(-1, ret); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : GetParameter parameter illegal test(key len is 32 bytes) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testGetParameter012, LEVEL1) +{ + int ret; + + char key[] = "rw.sys.version.version.version.v"; + char value[MAX_LEN] = {0}; + ret = GetParameter(key, g_defSysParam, value, MAX_LEN); + if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + } +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : GetParameter parameter illegal test(key len is more than 32 bytes) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testGetParameter013, LEVEL1) +{ + int ret; + + char key[] = "rw.sys.version.version.version.version"; + char value[MAX_LEN] = {0}; + ret = GetParameter(key, g_defSysParam, value, MAX_LEN); + if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + } +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : GetParameter parameter illegal test(key is nullptr) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testGetParameter014, LEVEL1) +{ + int ret; + + char value[MAX_LEN] = {0}; + ret = GetParameter(NULL, g_defSysParam, value, MAX_LEN); + if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + } +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : GetParameter parameter illegal test(key with uppercase) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testGetParameter015, LEVEL1) +{ + int ret; + + char key[] = "Rw.Sys.Version.Version"; + char value[MAX_LEN] = {0}; + ret = GetParameter(key, g_defSysParam, value, MAX_LEN); + if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + } +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : GetParameter parameter illegal test(key with blank) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testGetParameter016, LEVEL1) +{ + int ret; + + char key[] = "rw sys version version"; + char value[MAX_LEN] = {0}; + ret = GetParameter(key, g_defSysParam, value, MAX_LEN); + if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + } +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : GetParameter parameter illegal test(key with special characters) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testGetParameter017, LEVEL1) +{ + int ret; + + char key[] = "rw+sys&version%version*"; + char value[MAX_LEN] = {0}; + ret = GetParameter(key, g_defSysParam, value, MAX_LEN); + if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + } +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : GetParameter parameter illegal test(key is NULL) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testGetParameter018, LEVEL1) +{ + int ret; + + char value[MAX_LEN] = {0}; + ret = GetParameter("\0", g_defSysParam, value, MAX_LEN); + if ((ret == COMMON_ERROR) || (ret == INVALID_PARAMETER)) + { + TEST_ASSERT_EQUAL_INT(1, 1); + } +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : GetParameter parameter legal test(value contains only blanks) + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testGetParameter019, LEVEL1) +{ + int ret; + + char key[] = "key_for_blank_value"; + char rightVal[] = " "; + char value[MAX_LEN] = {0}; + SetParameter(key, rightVal); + ret = GetParameter(key, g_defSysParam, value, MAX_LEN); + TEST_ASSERT_EQUAL_INT(strlen(rightVal), ret); + TEST_ASSERT_EQUAL_STRING(rightVal, value); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_100 + * @tc.name : Update value of parameter legal test + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterFuncTestSuite, testGetParameter020, LEVEL1) +{ + int ret; + + char key[] = "rw.sys.version_606"; + char rightVal1[] = "OEM-hisi-10.1.0"; + char value1[MAX_LEN] = {0}; + ret = SetParameter(key, rightVal1); + TEST_ASSERT_EQUAL_INT(0, ret); + ret = GetParameter(key, g_defSysParam, value1, MAX_LEN); + TEST_ASSERT_EQUAL_INT(strlen(rightVal1), ret); + TEST_ASSERT_EQUAL_STRING(rightVal1, value1); + + char rightVal2[] = "update the value of OEM-hisi-10.1.0"; + char value2[MAX_LEN] = {0}; + ret = SetParameter(key, rightVal2); + TEST_ASSERT_EQUAL_INT(0, ret); + ret = GetParameter(key, g_defSysParam, value2, MAX_LEN); + TEST_ASSERT_EQUAL_INT(strlen(rightVal2), ret); + TEST_ASSERT_EQUAL_STRING(rightVal2, value2); +}; + +RUN_TEST_SUITE(ParameterFuncTestSuite); diff --git a/utils_lite/parameter_hal/src/parameter_reli_test.c b/utils_lite/parameter_hal/src/parameter_reli_test.c new file mode 100755 index 0000000000000000000000000000000000000000..f520bbf79a14dbd4db0d608c4a66a696c4f84ece --- /dev/null +++ b/utils_lite/parameter_hal/src/parameter_reli_test.c @@ -0,0 +1,606 @@ +/* + * Copyright (c) 2020 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 "hos_types.h" +#include +#include "hctest.h" +#include "parameter.h" +#include "parameter_utils.h" + +#define QUERY_TIMES 50 + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is utils + * @param : module name is parameter + * @param : test suit name is ParameterReliTestSuite + */ +LITE_TEST_SUIT(utils, parameter, ParameterReliTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL ParameterReliTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL ParameterReliTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli001, LEVEL1) +{ + char* value1 = GetProductType(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetProductType(); + free(value); + } + char* value2 = GetProductType(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli002, LEVEL1) +{ + char* value1 = GetManufacture(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetManufacture(); + free(value); + } + char* value2 = GetManufacture(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli003, LEVEL1) +{ + char* value1 = GetBrand(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetBrand(); + free(value); + } + char* value2 = GetBrand(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli004, LEVEL1) +{ + char* value1 = GetMarketName(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetMarketName(); + free(value); + } + char* value2 = GetMarketName(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli005, LEVEL1) +{ + char* value1 = GetProductSeries(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetProductSeries(); + free(value); + } + char* value2 = GetProductSeries(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli006, LEVEL1) +{ + char* value1 = GetProductModel(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetProductModel(); + free(value); + } + char* value2 = GetProductModel(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli007, LEVEL1) +{ + char* value1 = GetHardwareModel(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetHardwareModel(); + free(value); + } + char* value2 = GetHardwareModel(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli008, LEVEL1) +{ + char* value1 = GetHardwareProfile(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetHardwareProfile(); + free(value); + } + char* value2 = GetHardwareProfile(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli009, LEVEL1) +{ + char* value1 = GetSerial(); + if (value1 == NULL) { + printf("The serial number needs to be written\n"); + TEST_IGNORE(); + } + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetSerial(); + free(value); + } + char* value2 = GetSerial(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli010, LEVEL1) +{ + char* value1 = GetOsName(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetOsName(); + free(value); + } + char* value2 = GetOsName(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli011, LEVEL1) +{ + char* value1 = GetDisplayVersion(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetDisplayVersion(); + free(value); + } + char* value2 = GetDisplayVersion(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli012, LEVEL1) +{ + char* value1 = GetBootloaderVersion(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetBootloaderVersion(); + free(value); + } + char* value2 = GetBootloaderVersion(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli013, LEVEL1) +{ + char* value1 = GetSecurityPatchTag(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetSecurityPatchTag(); + free(value); + } + char* value2 = GetSecurityPatchTag(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli014, LEVEL1) +{ + char* value1 = GetAbiList(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetAbiList(); + free(value); + } + char* value2 = GetAbiList(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli015, LEVEL1) +{ + char* value1 = GetFirstApiLevel(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetFirstApiLevel(); + free(value); + } + char* value2 = GetFirstApiLevel(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli016, LEVEL1) +{ + char* value1 = GetIncrementalVersion(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetIncrementalVersion(); + free(value); + } + char* value2 = GetIncrementalVersion(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli017, LEVEL1) +{ + char* value1 = GetVersionId(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetVersionId(); + free(value); + } + char* value2 = GetVersionId(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli018, LEVEL1) +{ + char* value1 = GetBuildType(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetBuildType(); + free(value); + } + char* value2 = GetBuildType(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli019, LEVEL1) +{ + char* value1 = GetBuildUser(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetBuildUser(); + free(value); + } + char* value2 = GetBuildUser(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli020, LEVEL1) +{ + char* value1 = GetBuildHost(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetBuildHost(); + free(value); + } + char* value2 = GetBuildHost(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli021, LEVEL1) +{ + char* value1 = GetBuildTime(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetBuildTime(); + free(value); + } + char* value2 = GetBuildTime(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli022, LEVEL1) +{ + char* value1 = GetBuildRootHash(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetBuildRootHash(); + free(value); + } + char* value2 = GetBuildRootHash(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli023, LEVEL1) +{ + char* value1 = GetSoftwareModel(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetSoftwareModel(); + free(value); + } + char* value2 = GetSoftwareModel(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +/** + * @tc.number : SUB_UTILS_PARAMETER_200 + * @tc.name : Obtaining system parameter for multiple times + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(ParameterReliTestSuite, testObtainSysParaReli024, LEVEL1) +{ + char* value1 = GetSdkApiLevel(); + IsEmpty(value1); + for (int i = 0; i < QUERY_TIMES; i++) + { + char* value = GetSdkApiLevel(); + free(value); + } + char* value2 = GetSdkApiLevel(); + TEST_ASSERT_EQUAL_STRING(value1, value2); + free(value1); + free(value2); +}; + +RUN_TEST_SUITE(ParameterReliTestSuite); diff --git a/utils_lite/parameter_hal/src/parameter_utils.c b/utils_lite/parameter_hal/src/parameter_utils.c new file mode 100755 index 0000000000000000000000000000000000000000..a9e8386109c726419569c8aeb804c78210e32702 --- /dev/null +++ b/utils_lite/parameter_hal/src/parameter_utils.c @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2020 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 "hctest.h" +#include "parameter_utils.h" + +void IsEmpty(const char* sysPara) +{ + if (sysPara != NULL) { + TEST_ASSERT_EQUAL_INT(1, 1); + } else { + TEST_ASSERT_EQUAL_INT(0, 1); + } +} \ No newline at end of file diff --git a/utils_lite/parameter_hal/src/parameter_utils.h b/utils_lite/parameter_hal/src/parameter_utils.h new file mode 100755 index 0000000000000000000000000000000000000000..f27c5295ae6c32b83d178c182e0d9c24ab42fec5 --- /dev/null +++ b/utils_lite/parameter_hal/src/parameter_utils.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020 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 PARAMETER_COMMON_H +#define PARAMETER_COMMON_H + +#ifdef __cplusplus +#if __cplusplus +#endif +#endif /* __cplusplus */ + +/** + * @tc.name :determines whether the string is empty. + * @param :system parameter + */ +void IsEmpty(const char* sysPara); + +#ifdef __cplusplus +#if __cplusplus +#endif +#endif /* __cplusplus */ + +#endif diff --git a/utils_lite/utilsfile_hal/BUILD.gn b/utils_lite/utilsfile_hal/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..2403a19f7a80d48209417e25396e5f6229170f4f --- /dev/null +++ b/utils_lite/utilsfile_hal/BUILD.gn @@ -0,0 +1,28 @@ + # Copyright (c) 2020 Huawei Device Co., Ltd. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. + +import("//test/xts/tools/build/suite_lite.gni") + +hctest_suite("ActsUtilsFileTest") { + suite_name = "acts" + sources = [ + "src/utils_file_func_test.c", + "src/utils_file_reli_test.c" + ] + + include_dirs = [ + "src", + "//utils/native/lite/include" + ] + cflags = [ "-Wno-error" ] +} diff --git a/utils_lite/utilsfile_hal/Test.tmpl b/utils_lite/utilsfile_hal/Test.tmpl new file mode 100755 index 0000000000000000000000000000000000000000..be8407e1286041a5af2bdc75a15633337376eb9d --- /dev/null +++ b/utils_lite/utilsfile_hal/Test.tmpl @@ -0,0 +1,19 @@ +{ + "description": "Config for $module test cases", + "environment": [ + { + "type": "device", + "label": "wifiiot" + } + ], + "kits": [ + { + "type": "DeployKit", + "timeout": "20000", + "burn_file": "$subsystem/$module.bin" + } + ], + "driver": { + "type": "CTestLite" + } +} \ No newline at end of file diff --git a/utils_lite/utilsfile_hal/src/utils_file_func_test.c b/utils_lite/utilsfile_hal/src/utils_file_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..d83ae2d2350155f081a4abc047eaf6c9ad5e1899 --- /dev/null +++ b/utils_lite/utilsfile_hal/src/utils_file_func_test.c @@ -0,0 +1,1053 @@ +/* + * Copyright (c) 2020 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 "hos_types.h" +#include +#include "hctest.h" +#include "utils_file.h" + +#define QUERY_TIMES 50 +#define FILE_SEEK_OFFSET_10 10 +#define FILE_SEEK_OFFSET_20 20 +#define FILE_SEEK_OFFSET_50 50 +#define FILE_SEEK_OFFSET_MINUS_10 (-10) +#define FILE_SEEK_OFFSET_MINUS_20 (-20) +#define FILE_SEEK_OFFSET_MINUS_50 (-50) +#define LENGTH_OF_READ_BUF 36 + +static const char* g_def = "utils_file_operation implement."; + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is utils + * @param : module name is utilsFile + * @param : test suit name is UtilsFileFuncTestSuite + */ +LITE_TEST_SUIT(utils, utilsFile, UtilsFileFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL UtilsFileFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL UtilsFileFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_100 + * @tc.name : File operation for file creat/close + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileCreatAndClose001, LEVEL1) +{ + char* fileName = "testfile101"; + int fd = UtilsFileOpen(fileName, O_RDONLY_FS | O_CREAT_FS, 0); + TEST_ASSERT_GREATER_THAN_INT(0, fd); + int ret = UtilsFileClose(fd); + TEST_ASSERT_EQUAL_INT(0, ret); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_100 + * @tc.name : File operation for file creat/close + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileCreatAndClose002, LEVEL1) +{ + char* fileName = "testfile102"; + int fd = UtilsFileOpen(fileName, O_WRONLY_FS | O_CREAT_FS, 0); + TEST_ASSERT_GREATER_THAN_INT(0, fd); + int ret = UtilsFileClose(fd); + TEST_ASSERT_EQUAL_INT(0, ret); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_100 + * @tc.name : File operation for file creat/close + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileCreatAndClose003, LEVEL1) +{ + char* fileName = "testfile103"; + int fd = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + TEST_ASSERT_GREATER_THAN_INT(0, fd); + int ret = UtilsFileClose(fd); + TEST_ASSERT_EQUAL_INT(0, ret); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_100 + * @tc.name : File operation for file open/close + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileOpenAndClose001, LEVEL1) +{ + char* fileName = "testfile104"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileClose(fd0); + int fd = UtilsFileOpen(fileName, O_RDONLY_FS, 0); + TEST_ASSERT_GREATER_THAN_INT(0, fd); + int ret = UtilsFileClose(fd); + TEST_ASSERT_EQUAL_INT(0, ret); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_100 + * @tc.name : File operation for file open/close + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileOpenAndClose002, LEVEL1) +{ + char* fileName = "testfile105"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileClose(fd0); + int fd = UtilsFileOpen(fileName, O_WRONLY_FS, 0); + TEST_ASSERT_GREATER_THAN_INT(0, fd); + int ret = UtilsFileClose(fd); + TEST_ASSERT_EQUAL_INT(0, ret); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_100 + * @tc.name : File operation for file open/close + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileOpenAndClose003, LEVEL1) +{ + char* fileName = "testfile106"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileClose(fd0); + int fd = UtilsFileOpen(fileName, O_RDWR_FS, 0); + TEST_ASSERT_GREATER_THAN_INT(0, fd); + int ret = UtilsFileClose(fd); + TEST_ASSERT_EQUAL_INT(0, ret); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_100 + * @tc.name : File operation for file open/close + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileOpenAndClose004, LEVEL1) +{ + char* fileName = "testfile107"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileClose(fd0); + int fd = UtilsFileOpen(fileName, O_RDWR_FS | O_TRUNC_FS, 0); + TEST_ASSERT_GREATER_THAN_INT(0, fd); + int ret = UtilsFileClose(fd); + TEST_ASSERT_EQUAL_INT(0, ret); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_100 + * @tc.name : File operation for file open/close + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileOpenAndClose005, LEVEL1) +{ + char* fileName = "testfile108"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileClose(fd0); + int fd = UtilsFileOpen(fileName, O_RDWR_FS | O_APPEND_FS, 0); + TEST_ASSERT_GREATER_THAN_INT(0, fd); + int ret = UtilsFileClose(fd); + TEST_ASSERT_EQUAL_INT(0, ret); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_200 + * @tc.name : File operation for file creat/close + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileCreatAndClose004, LEVEL1) +{ + char* fileName = "testfile109"; + int fd = UtilsFileOpen(fileName, O_RDONLY_FS | O_CREAT_FS | O_EXCL_FS, 0); + TEST_ASSERT_GREATER_THAN_INT(0, fd); + int ret = UtilsFileClose(fd); + TEST_ASSERT_EQUAL_INT(0, ret); + int fd1 = UtilsFileOpen(fileName, O_RDONLY_FS | O_CREAT_FS | O_EXCL_FS, 0); + TEST_ASSERT_EQUAL_INT(-1, fd1); + int ret1 = UtilsFileClose(fd1); + TEST_ASSERT_EQUAL_INT(-1, ret1); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_200 + * @tc.name : File operation for file creat/close + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileCreatAndClose005, LEVEL1) +{ + char* fileName = "testfile110"; + int fd = UtilsFileOpen(fileName, O_WRONLY_FS | O_CREAT_FS | O_EXCL_FS, 0); + TEST_ASSERT_GREATER_THAN_INT(0, fd); + int ret = UtilsFileClose(fd); + TEST_ASSERT_EQUAL_INT(0, ret); + int fd1 = UtilsFileOpen(fileName, O_WRONLY_FS | O_CREAT_FS | O_EXCL_FS, 0); + TEST_ASSERT_EQUAL_INT(-1, fd1); + int ret1 = UtilsFileClose(fd1); + TEST_ASSERT_EQUAL_INT(-1, ret1); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_200 + * @tc.name : File operation for file creat/close + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileCreatAndClose006, LEVEL1) +{ + char* fileName = "testfile111"; + int fd = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS | O_EXCL_FS, 0); + TEST_ASSERT_GREATER_THAN_INT(0, fd); + int ret = UtilsFileClose(fd); + TEST_ASSERT_EQUAL_INT(0, ret); + int fd1 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS | O_EXCL_FS, 0); + TEST_ASSERT_EQUAL_INT(-1, fd1); + int ret1 = UtilsFileClose(fd1); + TEST_ASSERT_EQUAL_INT(-1, ret1); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_200 + * @tc.name : File operation for file creat/close + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileCreatAndClose007, LEVEL1) +{ + char* fileName = "testfile112"; + int fd = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS | O_EXCL_FS | O_TRUNC_FS, 0); + TEST_ASSERT_GREATER_THAN_INT(0, fd); + int ret = UtilsFileClose(fd); + TEST_ASSERT_EQUAL_INT(0, ret); + int fd1 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS | O_EXCL_FS | O_TRUNC_FS, 0); + TEST_ASSERT_EQUAL_INT(-1, fd1); + int ret1 = UtilsFileClose(fd1); + TEST_ASSERT_EQUAL_INT(-1, ret1); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_200 + * @tc.name : File operation for file creat/close + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileCreatAndClose008, LEVEL1) +{ + char* fileName = "testfile113"; + int fd = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS | O_EXCL_FS | O_APPEND_FS, 0); + TEST_ASSERT_GREATER_THAN_INT(0, fd); + int ret = UtilsFileClose(fd); + TEST_ASSERT_EQUAL_INT(0, ret); + int fd1 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS | O_EXCL_FS | O_APPEND_FS, 0); + TEST_ASSERT_EQUAL_INT(-1, fd1); + int ret1 = UtilsFileClose(fd1); + TEST_ASSERT_EQUAL_INT(-1, ret1); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_100 + * @tc.name : File operation for file write + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileWrite001, LEVEL1) +{ + char* fileName = "testfile114"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileClose(fd0); + int fd = UtilsFileOpen(fileName, O_RDWR_FS, 0); + int ret = UtilsFileWrite(fd, g_def, strlen(g_def)); + TEST_ASSERT_GREATER_THAN_INT(0, ret); + UtilsFileClose(fd); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_100 + * @tc.name : File operation for file write + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileWrite002, LEVEL1) +{ + char* fileName = "testfile115"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + int fd = UtilsFileOpen(fileName, O_RDWR_FS | O_APPEND_FS, 0); + int ret = UtilsFileWrite(fd, g_def, strlen(g_def)); + TEST_ASSERT_GREATER_THAN_INT(0, ret); + UtilsFileClose(fd); + int fd1 = UtilsFileOpen(fileName, O_RDWR_FS | O_TRUNC_FS, 0); + int ret1 = UtilsFileWrite(fd1, g_def, strlen(g_def)); + TEST_ASSERT_GREATER_THAN_INT(0, ret1); + UtilsFileClose(fd1); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_100 + * @tc.name : Creat file with long file name + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testCreatLongNameFile, LEVEL1) +{ + char* fileName = "testLongFileName116-Ab123456789"; + int fd = UtilsFileOpen(fileName, O_RDONLY_FS | O_CREAT_FS, 0); + TEST_ASSERT_GREATER_THAN_INT(0, fd); + UtilsFileClose(fd); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_100 + * @tc.name : Creat file with special characters + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testCreatFileWithSpecChar, LEVEL1) +{ + char* fileName = "case117-~!@#$%^&*()+_/:?<;>|\\"; + int fd = UtilsFileOpen(fileName, O_RDONLY_FS | O_CREAT_FS, 0); + TEST_ASSERT_GREATER_THAN_INT(0, fd); + UtilsFileClose(fd); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_200 + * @tc.name : Open none exist file + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testOpenNotExistFile, LEVEL1) +{ + char* fileName = "fileNotExist118"; + int fd = UtilsFileOpen(fileName, O_RDONLY_FS, 0); + TEST_ASSERT_EQUAL_INT(-1, fd); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_200 + * @tc.name : Write none exist file + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testWriteNotExistFile, LEVEL1) +{ + int fd = 1073; + int ret = UtilsFileWrite(fd, g_def, strlen(g_def)); + TEST_ASSERT_EQUAL_INT(-1, ret); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_200 + * @tc.name : Close none exist file + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testCloseNotExistFile, LEVEL1) +{ + int fd = 1073; + int ret = UtilsFileClose(fd); + TEST_ASSERT_EQUAL_INT(-1, ret); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_200 + * @tc.name : Creat file with invalid long file name + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testCreatInvalidlongNameFile, LEVEL1) +{ + char* fileName = "copyLongFileName403-Abcdefg123456789Abcdefg123456789Abcdefg123456789\ + Abcdefg123456789Abcdefg123456789"; + int fd = UtilsFileOpen(fileName, O_RDONLY_FS | O_CREAT_FS, 0); + TEST_ASSERT_EQUAL_INT(-1, fd); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_300 + * @tc.name : File operation for fileseek + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileSeek001, LEVEL1) +{ + char* fileName = "testfile201"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + int fd = UtilsFileOpen(fileName, O_RDWR_FS, 0); + int ret = UtilsFileSeek(fd, FILE_SEEK_OFFSET_20, SEEK_SET_FS); + TEST_ASSERT_GREATER_OR_EQUAL_INT(0, ret); + UtilsFileClose(fd); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_300 + * @tc.name : File operation for fileseek + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileSeek002, LEVEL1) +{ + char* fileName = "testfile202"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + int fd = UtilsFileOpen(fileName, O_RDWR_FS, 0); + int ret = UtilsFileSeek(fd, FILE_SEEK_OFFSET_20, SEEK_CUR_FS); + TEST_ASSERT_GREATER_OR_EQUAL_INT(0, ret); + UtilsFileClose(fd); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_300 + * @tc.name : File operation for fileseek + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileSeek003, LEVEL1) +{ + char* fileName = "testfile203"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + int fd = UtilsFileOpen(fileName, O_RDWR_FS, 0); + int ret = UtilsFileSeek(fd, FILE_SEEK_OFFSET_MINUS_20, SEEK_END_FS); + TEST_ASSERT_GREATER_OR_EQUAL_INT(0, ret); + UtilsFileClose(fd); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_400 + * @tc.name : File operation for fileseek + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileSeek004, LEVEL1) +{ + char* fileName = "testfile204"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + int fd = UtilsFileOpen(fileName, O_RDWR_FS, 0); + int ret = UtilsFileSeek(fd, FILE_SEEK_OFFSET_50, SEEK_SET_FS); + TEST_ASSERT_EQUAL_INT(-1, ret); + UtilsFileClose(fd); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_400 + * @tc.name : File operation for fileseek + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileSeek005, LEVEL1) +{ + char* fileName = "testfile205"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + int fd = UtilsFileOpen(fileName, O_RDWR_FS, 0); + int ret = UtilsFileSeek(fd, FILE_SEEK_OFFSET_50, SEEK_CUR_FS); + TEST_ASSERT_EQUAL_INT(-1, ret); + UtilsFileClose(fd); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_400 + * @tc.name : File operation for fileseek + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileSeek006, LEVEL1) +{ + char* fileName = "testfile206"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + int fd = UtilsFileOpen(fileName, O_RDWR_FS, 0); + int ret = UtilsFileSeek(fd, FILE_SEEK_OFFSET_MINUS_50, SEEK_END_FS); + TEST_ASSERT_EQUAL_INT(-1, ret); + UtilsFileClose(fd); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_300 + * @tc.name : File operation for fileseek + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileSeek007, LEVEL1) +{ + char* fileName = "testfile207"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + int fd = UtilsFileOpen(fileName, O_RDWR_FS, 0); + int ret = UtilsFileSeek(fd, FILE_SEEK_OFFSET_20, SEEK_SET_FS); + ret = UtilsFileSeek(fd, FILE_SEEK_OFFSET_10, SEEK_CUR_FS); + TEST_ASSERT_GREATER_OR_EQUAL_INT(0, ret); + UtilsFileClose(fd); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_300 + * @tc.name : File operation for fileseek + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileSeek008, LEVEL1) +{ + char* fileName = "testfile208"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + int fd = UtilsFileOpen(fileName, O_RDWR_FS, 0); + int ret = UtilsFileSeek(fd, FILE_SEEK_OFFSET_20, SEEK_SET_FS); + ret = UtilsFileSeek(fd, FILE_SEEK_OFFSET_MINUS_10, SEEK_CUR_FS); + TEST_ASSERT_GREATER_OR_EQUAL_INT(0, ret); + UtilsFileClose(fd); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_400 + * @tc.name : File operation for fileseek + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileSeek009, LEVEL1) +{ + char* fileName = "testfile209"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + int fd = UtilsFileOpen(fileName, O_RDWR_FS, 0); + int ret = UtilsFileSeek(fd, FILE_SEEK_OFFSET_20, SEEK_SET_FS); + ret = UtilsFileSeek(fd, FILE_SEEK_OFFSET_50, SEEK_CUR_FS); + TEST_ASSERT_EQUAL_INT(-1, ret); + UtilsFileClose(fd); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_400 + * @tc.name : File operation for fileseek + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileSeek010, LEVEL1) +{ + char* fileName = "testfile210"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + int fd = UtilsFileOpen(fileName, O_RDWR_FS, 0); + int ret = UtilsFileSeek(fd, FILE_SEEK_OFFSET_20, SEEK_SET_FS); + ret = UtilsFileSeek(fd, FILE_SEEK_OFFSET_MINUS_50, SEEK_CUR_FS); + TEST_ASSERT_EQUAL_INT(-1, ret); + UtilsFileClose(fd); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_300 + * @tc.name : File operation for fileseek + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileSeek011, LEVEL1) +{ + char* fileName = "testfile211"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + int fd = UtilsFileOpen(fileName, O_RDWR_FS, 0); + int ret = UtilsFileSeek(fd, FILE_SEEK_OFFSET_20, SEEK_SET_FS); + ret = UtilsFileSeek(fd, FILE_SEEK_OFFSET_MINUS_50, SEEK_CUR_FS); + ret = UtilsFileSeek(fd, FILE_SEEK_OFFSET_MINUS_10, SEEK_CUR_FS); + TEST_ASSERT_GREATER_OR_EQUAL_INT(0, ret); + UtilsFileClose(fd); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_400 + * @tc.name : File seek for none exist file + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileSeekForNotExistFile, LEVEL1) +{ + int fd = 1073; + int ret = UtilsFileSeek(fd, FILE_SEEK_OFFSET_20, SEEK_SET_FS); + TEST_ASSERT_EQUAL_INT(-1, ret); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_500 + * @tc.name : Obtaining file size + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testObtainFileSize, LEVEL1) +{ + char* fileName = "testfile301"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + unsigned int fileLen = 0; + int ret = UtilsFileStat(fileName, &fileLen); + TEST_ASSERT_EQUAL_INT(0, ret); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_600 + * @tc.name : Obtaining size for none exist file + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testObtainSizeForNotExistFile, LEVEL1) +{ + char* fileName = "fileNotExist302"; + unsigned int fileLen = 0; + int ret = UtilsFileStat(fileName, &fileLen); + TEST_ASSERT_EQUAL_INT(-1, ret); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_500 + * @tc.name : File operation for file read + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileRead, LEVEL1) +{ + char* fileName = "testfile303"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + char buf[LENGTH_OF_READ_BUF] = {0}; + int fd = UtilsFileOpen(fileName, O_RDWR_FS, 0); + int ret = UtilsFileRead(fd, buf, LENGTH_OF_READ_BUF); + TEST_ASSERT_GREATER_OR_EQUAL_INT(0, ret); + UtilsFileClose(fd); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_600 + * @tc.name : Read none exist file + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testReadNotExistFile, LEVEL1) +{ + char buf[LENGTH_OF_READ_BUF] = {0}; + int fd = 1073; + int ret = UtilsFileRead(fd, buf, LENGTH_OF_READ_BUF); + TEST_ASSERT_EQUAL_INT(-1, ret); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_500 + * @tc.name : Obtaining size for file with long file name + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testObtainLongNameFileSize, LEVEL1) +{ + char* fileName = "testLongFileName305-Ab123456789"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + unsigned int fileLen = 0; + int ret = UtilsFileStat(fileName, &fileLen); + TEST_ASSERT_EQUAL_INT(0, ret); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_500 + * @tc.name : Obtaining size for file with special characters + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testObtainSizeForFileWithSpecChar, LEVEL1) +{ + char* fileName = "case307-~!@#$%^&*()+_/:?<;>|\\"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + unsigned int fileLen = 0; + int ret = UtilsFileStat(fileName, &fileLen); + TEST_ASSERT_EQUAL_INT(0, ret); + UtilsFileDelete(fileName); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_700 + * @tc.name : File operation for file copy + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileCopy, LEVEL1) +{ + char* fileName = "testfile401"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + char* fileNameCopy = "copyFile401"; + int ret = UtilsFileCopy(fileName, fileNameCopy); + TEST_ASSERT_EQUAL_INT(0, ret); + UtilsFileDelete(fileName); + UtilsFileDelete(fileNameCopy); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_800 + * @tc.name : Copy none exist file + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testCopyNotExistFile, LEVEL1) +{ + char* fileName = "fileNotExist402"; + char* fileNameCopy = "copyFile402"; + int ret = UtilsFileCopy(fileName, fileNameCopy); + TEST_ASSERT_EQUAL_INT(-1, ret); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_700 + * @tc.name : Copy file with long file name + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testCopyLongNameFile, LEVEL1) +{ + char* fileName = "testLongFileName403-Ab123456789"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + char* fileNameCopy = "copyLongFileName403-Ab123456789"; + int ret = UtilsFileCopy(fileName, fileNameCopy); + TEST_ASSERT_EQUAL_INT(0, ret); + UtilsFileDelete(fileName); + UtilsFileDelete(fileNameCopy); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_700 + * @tc.name : Copy file with special characters + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testCopyFileWithSpecChar, LEVEL1) +{ + char* fileName = "case404-~!@#$%^&*()+_/:?<;>|\\"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + char* fileNameCopy = "copy404-~!@#$%^&*()+_/:?<;>|\\"; + int ret = UtilsFileCopy(fileName, fileNameCopy); + TEST_ASSERT_EQUAL_INT(0, ret); + UtilsFileDelete(fileName); + UtilsFileDelete(fileNameCopy); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_900 + * @tc.name : File operation for file move + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileMove, LEVEL1) +{ + char* fileName = "testfile501"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + char* fileNameMove = "moveFile501"; + int ret = UtilsFileMove(fileName, fileNameMove); + TEST_ASSERT_EQUAL_INT(0, ret); + UtilsFileDelete(fileNameMove); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_1000 + * @tc.name : Move none exist file + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testMoveNotExistFile, LEVEL1) +{ + char* fileName = "fileNotExist502"; + char* fileNameMove = "moveFile502"; + int ret = UtilsFileMove(fileName, fileNameMove); + TEST_ASSERT_EQUAL_INT(-1, ret); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_900 + * @tc.name : Move file with long file name + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testMoveLongNameFile, LEVEL1) +{ + char* fileName = "testLongFileName503-Ab123456789"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + char* fileNameMove = "moveLongFileName503-Ab123456789"; + int ret = UtilsFileMove(fileName, fileNameMove); + TEST_ASSERT_EQUAL_INT(0, ret); + UtilsFileDelete(fileNameMove); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_900 + * @tc.name : Move file with special characters + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testMoveFileWithSpecChar, LEVEL1) +{ + char* fileName = "case504-~!@#$%^&*()+_/:?<;>|\\"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + char* fileNameMove = "move504-~!@#$%^&*()+_/:?<;>|\\"; + int ret = UtilsFileMove(fileName, fileNameMove); + TEST_ASSERT_EQUAL_INT(0, ret); + UtilsFileDelete(fileNameMove); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_1100 + * @tc.name : File operation for file delete + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testFileDelete, LEVEL1) +{ + char* fileName = "deleteFile601"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + int ret = UtilsFileDelete(fileName); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_1200 + * @tc.name : Delete none exist file + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testDeleteNotExistFile, LEVEL1) +{ + char* fileName = "fileNotExist602"; + int ret = UtilsFileDelete(fileName); + TEST_ASSERT_EQUAL_INT(-1, ret); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_1100 + * @tc.name : Delete file with long file name + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testDeleteLongNameFile, LEVEL1) +{ + char* fileName = "deleteLongFileName603-Ab1234567"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + int ret = UtilsFileDelete(fileName); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_1100 + * @tc.name : Delete file with special characters + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : FUNC + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileFuncTestSuite, testDeleteFileWithSpecChar, LEVEL1) +{ + char* fileName = "delete604-~!@#$%^&*()+_/:?<;>|\\"; + int fd0 = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd0, g_def, strlen(g_def)); + UtilsFileClose(fd0); + int ret = UtilsFileDelete(fileName); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +RUN_TEST_SUITE(UtilsFileFuncTestSuite); diff --git a/utils_lite/utilsfile_hal/src/utils_file_reli_test.c b/utils_lite/utilsfile_hal/src/utils_file_reli_test.c new file mode 100755 index 0000000000000000000000000000000000000000..77449e2328c11159332c7d17dc14b649c2e6afc2 --- /dev/null +++ b/utils_lite/utilsfile_hal/src/utils_file_reli_test.c @@ -0,0 +1,415 @@ +/* + * Copyright (c) 2020 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 "hos_types.h" +#include +#include "hctest.h" +#include "utils_file.h" + +#define FILE_SEEK_OFFSET_0 0 +#define FILE_SEEK_OFFSET_20 20 +#define FILE_SEEK_OFFSET_MINUS_20 (-20) +#define MAX_NUM_OF_OPENED_FILES 32 +#define LENGTH_OF_READ_BUF 36 +#define FILE_INDEX_31 31 +#define LENGTH_OF_FILE_NAME_BUF 32 + +static const char* g_def = "utils_file_operation implement."; + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is utils + * @param : module name is utilsFile + * @param : test suit name is UtilsFileReliTestSuite + */ +LITE_TEST_SUIT(utils, utilsFile, UtilsFileReliTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL UtilsFileReliTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL UtilsFileReliTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_1300 + * @tc.name : Creat file after max files opened + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileReliTestSuite, testCreatFileAfterMaxFilesOpened, LEVEL1) +{ + // Open 32 files + int fd32[MAX_NUM_OF_OPENED_FILES] = {0}; + for (int i = 0; i < MAX_NUM_OF_OPENED_FILES; i++) + { + int j = i + 1; + char fileName32[LENGTH_OF_FILE_NAME_BUF] = {0}; + int size = sprintf_s(fileName32, sizeof(fileName32), "%s%d", "testReli101-", j); + if (size < 0) { + TEST_ASSERT_EQUAL_INT(0, 1); + } + fd32[i] = UtilsFileOpen(fileName32, O_RDWR_FS | O_CREAT_FS, 0); + TEST_ASSERT_GREATER_THAN_INT(0, fd32[i]); + } + // Open the 33th file + char* fileName33 = "testReli101-33"; + int fd33 = UtilsFileOpen(fileName33, O_RDWR_FS | O_CREAT_FS, 0); + TEST_ASSERT_EQUAL_INT(-1, fd33); + // Close file + UtilsFileClose(fd32[0]); + fd33 = UtilsFileOpen(fileName33, O_RDWR_FS | O_CREAT_FS, 0); + TEST_ASSERT_GREATER_THAN_INT(0, fd33); + UtilsFileClose(fd33); + // Delete all files + for (int i = 0; i < MAX_NUM_OF_OPENED_FILES; i++) + { + int j = i + 1; + char fileName32[LENGTH_OF_FILE_NAME_BUF] = {0}; + int size = sprintf_s(fileName32, sizeof(fileName32), "%s%d", "testReli101-", j); + if (size < 0) { + TEST_ASSERT_EQUAL_INT(0, 1); + } + UtilsFileDelete(fileName32); + } + UtilsFileDelete(fileName33); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_1300 + * @tc.name : Delete file after max files opened + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileReliTestSuite, testDeleteFileAfterMaxFilesOpened, LEVEL1) +{ + // Open 32 files + int fd32[MAX_NUM_OF_OPENED_FILES] = {0}; + for (int i = 0; i < MAX_NUM_OF_OPENED_FILES; i++) + { + int j = i + 1; + char fileName32[LENGTH_OF_FILE_NAME_BUF] = {0}; + int size = sprintf_s(fileName32, sizeof(fileName32), "%s%d", "testReli101-", j); + if (size < 0) { + TEST_ASSERT_EQUAL_INT(0, 1); + } + fd32[i] = UtilsFileOpen(fileName32, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd32[i], g_def, strlen(g_def)); + } + // Delete file + char* fileName1 = "testReli101-1"; + int ret = UtilsFileDelete(fileName1); + TEST_ASSERT_EQUAL_INT(-1, ret); + // Close file + UtilsFileClose(fd32[FILE_INDEX_31]); + ret = UtilsFileDelete(fileName1); + TEST_ASSERT_EQUAL_INT(0, ret); + // Delete all files + for (int i = 0; i < MAX_NUM_OF_OPENED_FILES; i++) + { + int j = i + 1; + char fileName32[LENGTH_OF_FILE_NAME_BUF] = {0}; + int size = sprintf_s(fileName32, sizeof(fileName32), "%s%d", "testReli101-", j); + if (size < 0) { + TEST_ASSERT_EQUAL_INT(0, 1); + } + UtilsFileDelete(fileName32); + } +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_1300 + * @tc.name : Copy file after max files opened + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileReliTestSuite, testCopyFileAfterMaxFilesOpened, LEVEL1) +{ + // Open 32 files + int fd32[MAX_NUM_OF_OPENED_FILES] = {0}; + for (int i = 0; i < MAX_NUM_OF_OPENED_FILES; i++) + { + int j = i + 1; + char fileName32[LENGTH_OF_FILE_NAME_BUF] = {0}; + int size = sprintf_s(fileName32, sizeof(fileName32), "%s%d", "testReli101-", j); + if (size < 0) { + TEST_ASSERT_EQUAL_INT(0, 1); + } + fd32[i] = UtilsFileOpen(fileName32, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd32[i], g_def, strlen(g_def)); + } + // Copy file + char* fileName1 = "testReli101-1"; + char* fileNameCopy = "testReliCopy"; + int ret = UtilsFileCopy(fileName1, fileNameCopy); + TEST_ASSERT_EQUAL_INT(-1, ret); + // Close first file + UtilsFileClose(fd32[0]); + ret = UtilsFileCopy(fileName1, fileNameCopy); + TEST_ASSERT_EQUAL_INT(-1, ret); + // Close second file + UtilsFileClose(fd32[1]); + ret = UtilsFileCopy(fileName1, fileNameCopy); + TEST_ASSERT_EQUAL_INT(0, ret); + // Delete all files + for (int i = 0; i < MAX_NUM_OF_OPENED_FILES; i++) + { + int j = i + 1; + char fileName32[LENGTH_OF_FILE_NAME_BUF] = {0}; + int size = sprintf_s(fileName32, sizeof(fileName32), "%s%d", "testReli101-", j); + if (size < 0) { + TEST_ASSERT_EQUAL_INT(0, 1); + } + UtilsFileDelete(fileName32); + } + UtilsFileDelete(fileNameCopy); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_1300 + * @tc.name : Move file after max files opened + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileReliTestSuite, testMoveFileAfterMaxFilesOpened, LEVEL1) +{ + // Open 32 files + int fd32[MAX_NUM_OF_OPENED_FILES] = {0}; + for (int i = 0; i < MAX_NUM_OF_OPENED_FILES; i++) + { + int j = i + 1; + char fileName32[LENGTH_OF_FILE_NAME_BUF] = {0}; + int size = sprintf_s(fileName32, sizeof(fileName32), "%s%d", "testReli101-", j); + if (size < 0) { + TEST_ASSERT_EQUAL_INT(0, 1); + } + fd32[i] = UtilsFileOpen(fileName32, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd32[i], g_def, strlen(g_def)); + } + // Move file + char* fileName1 = "testReli101-1"; + char* fileNameMove = "testReliMove"; + int ret = UtilsFileMove(fileName1, fileNameMove); + TEST_ASSERT_EQUAL_INT(-1, ret); + // Close first file + UtilsFileClose(fd32[0]); + ret = UtilsFileMove(fileName1, fileNameMove); + TEST_ASSERT_EQUAL_INT(-1, ret); + // Close second file + UtilsFileClose(fd32[1]); + ret = UtilsFileMove(fileName1, fileNameMove); + TEST_ASSERT_EQUAL_INT(0, ret); + // Delete all files + for (int i = 0; i < MAX_NUM_OF_OPENED_FILES; i++) + { + int j = i + 1; + char fileName32[LENGTH_OF_FILE_NAME_BUF] = {0}; + int size = sprintf_s(fileName32, sizeof(fileName32), "%s%d", "testReli101-", j); + if (size < 0) { + TEST_ASSERT_EQUAL_INT(0, 1); + } + UtilsFileDelete(fileName32); + } + UtilsFileDelete(fileNameMove); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_1400 + * @tc.name : File operation flow + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileReliTestSuite, testFileOperFlow001, LEVEL1) +{ + char* fileName1 = "testReli102a"; + char* fileName2 = "testReli102b"; + // Creat file + int fd1 = UtilsFileOpen(fileName1, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd1, g_def, strlen(g_def)); + UtilsFileClose(fd1); + // Copy file + UtilsFileCopy(fileName1, fileName2); + // File operation for copied file + unsigned int fileLen = 0; + int ret = UtilsFileStat(fileName2, &fileLen); + TEST_ASSERT_EQUAL_INT(0, ret); + int fd2 = UtilsFileOpen(fileName2, O_RDWR_FS | O_APPEND_FS, 0); + TEST_ASSERT_GREATER_THAN_INT(0, fd2); + ret = UtilsFileWrite(fd2, g_def, strlen(g_def)); + TEST_ASSERT_GREATER_THAN_INT(0, ret); + ret = UtilsFileSeek(fd2, FILE_SEEK_OFFSET_20, SEEK_SET_FS); + TEST_ASSERT_GREATER_OR_EQUAL_INT(0, ret); + char buf[LENGTH_OF_READ_BUF] = {0}; + ret = UtilsFileRead(fd2, buf, LENGTH_OF_READ_BUF); + TEST_ASSERT_GREATER_OR_EQUAL_INT(0, ret); + ret = UtilsFileClose(fd2); + TEST_ASSERT_EQUAL_INT(0, ret); + // Delete all files + ret = UtilsFileDelete(fileName1); + TEST_ASSERT_EQUAL_INT(0, ret); + ret = UtilsFileDelete(fileName2); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_1400 + * @tc.name : File operation flow + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileReliTestSuite, testFileOperFlow002, LEVEL1) +{ + char* fileName1 = "testReli102a"; + char* fileName2 = "testReli102b"; + char* fileName3 = "testReli102c"; + // Creat file + int fd1 = UtilsFileOpen(fileName1, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileWrite(fd1, g_def, strlen(g_def)); + UtilsFileClose(fd1); + // Copy file + UtilsFileCopy(fileName1, fileName2); + // Move the copied file + int ret = UtilsFileMove(fileName2, fileName3); + TEST_ASSERT_EQUAL_INT(0, ret); + // File operation for moved file + unsigned int fileLen = 0; + ret = UtilsFileStat(fileName3, &fileLen); + TEST_ASSERT_EQUAL_INT(0, ret); + int fd2 = UtilsFileOpen(fileName3, O_RDWR_FS | O_APPEND_FS, 0); + TEST_ASSERT_GREATER_THAN_INT(0, fd2); + ret = UtilsFileWrite(fd2, g_def, strlen(g_def)); + TEST_ASSERT_GREATER_THAN_INT(0, ret); + ret = UtilsFileSeek(fd2, FILE_SEEK_OFFSET_20, SEEK_SET_FS); + TEST_ASSERT_GREATER_OR_EQUAL_INT(0, ret); + char buf[LENGTH_OF_READ_BUF] = {0}; + ret = UtilsFileRead(fd2, buf, LENGTH_OF_READ_BUF); + TEST_ASSERT_GREATER_OR_EQUAL_INT(0, ret); + ret = UtilsFileClose(fd2); + TEST_ASSERT_EQUAL_INT(0, ret); + // Delete all files + ret = UtilsFileDelete(fileName1); + TEST_ASSERT_EQUAL_INT(0, ret); + ret = UtilsFileDelete(fileName2); + TEST_ASSERT_EQUAL_INT(-1, ret); + ret = UtilsFileDelete(fileName3); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_1500 + * @tc.name : File operation flow for empty file + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileReliTestSuite, testEmptyFileOperFlow001, LEVEL1) +{ + char* fileName1 = "testReli103a"; + char* fileName2 = "testReli103b"; + // Creat an empty file + int fd1 = UtilsFileOpen(fileName1, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileClose(fd1); + // Copy file + int ret = UtilsFileCopy(fileName1, fileName2); + TEST_ASSERT_EQUAL_INT(0, ret); + // File operation for copied file + unsigned int fileLen = 0; + ret = UtilsFileStat(fileName2, &fileLen); + TEST_ASSERT_EQUAL_INT(0, ret); + int fd2 = UtilsFileOpen(fileName2, O_RDWR_FS, 0); + TEST_ASSERT_GREATER_THAN_INT(0, fd2); + ret = UtilsFileSeek(fd2, FILE_SEEK_OFFSET_0, SEEK_SET_FS); + TEST_ASSERT_GREATER_OR_EQUAL_INT(0, ret); + char buf[LENGTH_OF_READ_BUF] = {0}; + ret = UtilsFileRead(fd2, buf, LENGTH_OF_READ_BUF); + TEST_ASSERT_GREATER_OR_EQUAL_INT(0, ret); + ret = UtilsFileClose(fd2); + TEST_ASSERT_EQUAL_INT(0, ret); + // Delete all files + ret = UtilsFileDelete(fileName1); + TEST_ASSERT_EQUAL_INT(0, ret); + ret = UtilsFileDelete(fileName2); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +/** + * @tc.number : SUB_UTILS_FILE_OPERATION_1500 + * @tc.name : File operation flow for empty file + * @tc.desc : [C- SOFTWARE -0200] + * @tc.size : MEDIUM + * @tc.type : RELI + * @tc.level : Level 1 + */ +LITE_TEST_CASE(UtilsFileReliTestSuite, testEmptyFileOperFlow002, LEVEL1) +{ + char* fileName1 = "testReli103a"; + char* fileName2 = "testReli103b"; + char* fileName3 = "testReli103c"; + // Creat an empty file + int fd1 = UtilsFileOpen(fileName1, O_RDWR_FS | O_CREAT_FS, 0); + UtilsFileClose(fd1); + // Copy file + UtilsFileCopy(fileName1, fileName2); + // Move the copied file + int ret = UtilsFileMove(fileName2, fileName3); + TEST_ASSERT_EQUAL_INT(0, ret); + // File operation for moved file + unsigned int fileLen = 0; + ret = UtilsFileStat(fileName3, &fileLen); + TEST_ASSERT_EQUAL_INT(0, ret); + int fd2 = UtilsFileOpen(fileName3, O_RDWR_FS, 0); + TEST_ASSERT_GREATER_THAN_INT(0, fd2); + ret = UtilsFileSeek(fd2, FILE_SEEK_OFFSET_0, SEEK_SET_FS); + TEST_ASSERT_GREATER_OR_EQUAL_INT(0, ret); + char buf[LENGTH_OF_READ_BUF] = {0}; + ret = UtilsFileRead(fd2, buf, LENGTH_OF_READ_BUF); + TEST_ASSERT_GREATER_OR_EQUAL_INT(0, ret); + ret = UtilsFileClose(fd2); + TEST_ASSERT_EQUAL_INT(0, ret); + // Delete all files + ret = UtilsFileDelete(fileName1); + TEST_ASSERT_EQUAL_INT(0, ret); + ret = UtilsFileDelete(fileName2); + TEST_ASSERT_EQUAL_INT(-1, ret); + ret = UtilsFileDelete(fileName3); + TEST_ASSERT_EQUAL_INT(0, ret); +}; + +RUN_TEST_SUITE(UtilsFileReliTestSuite);