diff --git a/interfaces/kits/hyperaio/BUILD.gn b/interfaces/kits/hyperaio/BUILD.gn index 5a35a775cb9074b02b3963973d6d08306b6f4c7f..0ac7313efaa8868756b7dd5109ea85c5aa77e24b 100644 --- a/interfaces/kits/hyperaio/BUILD.gn +++ b/interfaces/kits/hyperaio/BUILD.gn @@ -61,7 +61,7 @@ ohos_shared_library("HyperAio") { "access_token:libaccesstoken_sdk" ] - innerapi_tags = [ "platformsdk" ] + install_images = [ "system" ] part_name = "file_api" subsystem_name = "filemanagement" } \ No newline at end of file diff --git a/interfaces/kits/hyperaio/include/hyperaio.h b/interfaces/kits/hyperaio/include/hyperaio.h index b4fd06b38d1a9bbc576b13eebfdee911ab0b1c86..b950ddc86f85efb65738bcc4768a334f49a302e9 100644 --- a/interfaces/kits/hyperaio/include/hyperaio.h +++ b/interfaces/kits/hyperaio/include/hyperaio.h @@ -22,7 +22,7 @@ namespace OHOS { namespace HyperAio { -#define IOURING_APP_PERMISSION (1U << 0) +#define HYPERAIO_APP_PERMISSION (1U << 0) #ifndef EOK #define EOK (0) #endif diff --git a/interfaces/kits/hyperaio/include/libhilog.h b/interfaces/kits/hyperaio/include/libhilog.h index 9e882f46b4731ff0a5deaf7f7ea74405a50ac14f..3535112a2d2ae8577ecbbbe46ac3b053e1b52e6b 100644 --- a/interfaces/kits/hyperaio/include/libhilog.h +++ b/interfaces/kits/hyperaio/include/libhilog.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -13,44 +13,65 @@ * limitations under the License. */ -#ifndef FILEMGMT_LIBHILOG_H -#define FILEMGMT_LIBHILOG_H +#ifndef HYPERAIO_LIBHILOG_H +#define HYPERAIO_LIBHILOG_H #include "hilog/log.h" #include namespace OHOS { -#ifndef LOG_DOMAIN -#define LOG_DOMAIN 0xD001600 -#endif - -#ifndef LOG_TAG -#define LOG_TAG "FileManagement" -#endif +namespace HyperAio { #if defined __FILE_NAME__ #define FILEMGMT_FILE_NAME __FILE_NAME__ #else -#include #define FILEMGMT_FILE_NAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) #endif +#ifndef HYPERAIO_LOG_DOMAIN +#define HYPERAIO_LOG_DOMAIN 0xD004388 +#endif + +#undef HYPERAIO_LOG_TAG +#define HYPERAIO_LOG_TAG "hyperaio" + +#ifdef HILOGD +#undef HILOGD +#endif + +#ifdef HILOGF +#undef HILOGF +#endif + +#ifdef HILOGE +#undef HILOGE +#endif + +#ifdef HILOGW +#undef HILOGW +#endif + +#ifdef HILOGI +#undef HILOGI +#endif + #define HILOGF(fmt, ...) \ - ((void)HILOG_IMPL(LOG_CORE, LOG_FATAL, LOG_DOMAIN, LOG_TAG, \ + ((void)HILOG_IMPL(LOG_CORE, LOG_FATAL, HYPERAIO_LOG_DOMAIN, HYPERAIO_LOG_TAG, \ "[%{public}s:%{public}d->%{public}s] " fmt, FILEMGMT_FILE_NAME, __LINE__, __FUNCTION__, ##__VA_ARGS__)) #define HILOGE(fmt, ...) \ - ((void)HILOG_IMPL(LOG_CORE, LOG_ERROR, LOG_DOMAIN, LOG_TAG, \ + ((void)HILOG_IMPL(LOG_CORE, LOG_ERROR, HYPERAIO_LOG_DOMAIN, HYPERAIO_LOG_TAG, \ "[%{public}s:%{public}d->%{public}s] " fmt, FILEMGMT_FILE_NAME, __LINE__, __FUNCTION__, ##__VA_ARGS__)) #define HILOGW(fmt, ...) \ - ((void)HILOG_IMPL(LOG_CORE, LOG_WARN, LOG_DOMAIN, LOG_TAG, \ + ((void)HILOG_IMPL(LOG_CORE, LOG_WARN, HYPERAIO_LOG_DOMAIN, HYPERAIO_LOG_TAG, \ "[%{public}s:%{public}d->%{public}s] " fmt, FILEMGMT_FILE_NAME, __LINE__, __FUNCTION__, ##__VA_ARGS__)) #define HILOGI(fmt, ...) \ - ((void)HILOG_IMPL(LOG_CORE, LOG_INFO, LOG_DOMAIN, LOG_TAG, \ + ((void)HILOG_IMPL(LOG_CORE, LOG_INFO, HYPERAIO_LOG_DOMAIN, HYPERAIO_LOG_TAG, \ "[%{public}s:%{public}d->%{public}s] " fmt, FILEMGMT_FILE_NAME, __LINE__, __FUNCTION__, ##__VA_ARGS__)) #define HILOGD(fmt, ...) \ - ((void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, LOG_DOMAIN, LOG_TAG, \ + ((void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, HYPERAIO_LOG_DOMAIN, HYPERAIO_LOG_TAG, \ "[%{public}s:%{public}d->%{public}s] " fmt, FILEMGMT_FILE_NAME, __LINE__, __FUNCTION__, ##__VA_ARGS__)) +} // namespace HyperAio } // namespace OHOS -#endif // FILEMGMT_LIBHILOG_H \ No newline at end of file +#endif // HYPERAIO_LIBHILOG_H \ No newline at end of file diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index 70f424b5cba590840bb049e34f53dae4bf949a95..95d96e87e2cc3ebb2a78eabf93767befa938ccde 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -44,7 +44,7 @@ uint32_t HyperAio::SupportIouring() { uint32_t flags = 0; if (HasAccessIouringPermission()) { - flags |= IOURING_APP_PERMISSION; + flags |= HYERAIO_APP_PERMISSION; } return flags; } @@ -93,7 +93,7 @@ int32_t HyperAio::StartOpenReqs(OpenReqs *req) } uint32_t totalReqs = req->reqNum; uint32_t count = 0; - for(uint32_t i = 0; i < totalReqs; i++){ + for (uint32_t i = 0; i < totalReqs; i++) { struct io_uring_sqe *sqe = GetSqeWithRetry(&uring_); if (sqe == nullptr) { HILOGE("get sqe failed"); @@ -134,8 +134,7 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) } uint32_t totalReqs = req->reqNum; uint32_t count = 0; - for(uint32_t i = 0; i < totalReqs; i++) - { + for (uint32_t i = 0; i < totalReqs; i++) { struct io_uring_sqe *sqe = GetSqeWithRetry(&uring_); if (sqe == nullptr) { HILOGE("get sqe failed"); @@ -175,8 +174,7 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) } uint32_t totalReqs = req->reqNum; uint32_t count = 0; - for(uint32_t i = 0; i < totalReqs; i++) - { + for (uint32_t i = 0; i < totalReqs; i++) { struct io_uring_sqe *sqe = GetSqeWithRetry(&uring_); if (sqe == nullptr) { HILOGE("get sqe failed"); diff --git a/interfaces/test/unittest/BUILD.gn b/interfaces/test/unittest/BUILD.gn index 95f924b844e04552b66b00271d787063419395ea..b14741b2da649fa1e16f379571ef92f85734771a 100644 --- a/interfaces/test/unittest/BUILD.gn +++ b/interfaces/test/unittest/BUILD.gn @@ -18,5 +18,6 @@ group("unittest") { "filemgmt_libn_test:filemgmt_libn_test", "remote_uri:remote_uri_test", "task_signal:task_signal_test", + "hyperaio:hyperaio_test" ] } diff --git a/interfaces/test/unittest/hyperaio/BUILD.gn b/interfaces/test/unittest/hyperaio/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0a7a58c87ec66e8706c0e46ef158dd035417fe67 --- /dev/null +++ b/interfaces/test/unittest/hyperaio/BUILD.gn @@ -0,0 +1,41 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/filemanagement/file_api/file_api.gni") + +ohos_unittest("hyperaio_test") { + module_out_path = "file_api/file_api" + + resource_config_file = "../resource/ohos_test.xml" + + sources = [ "hyperaio_test.cpp" ] + + include_dirs = [ + "include", + "${file_api_path}/interfaces/kits/hyperaio/include", + ] + + deps = [ + "${file_api_path}/interfaces/kits/hyperaio:HyperAio", + ] + + external_deps = [ + "access_token:libaccesstoken_sdk", + "c_utils:utils", + "c_utils:utilsbase", + "ipc:ipc_core", + "googletest:gtest_main", + "liburing:liburing", + ] +} diff --git a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..43569a16dc21afdb0517ea7a8bbf82e4415c3599 --- /dev/null +++ b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2025 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 "hyperaio.h" + +namespace { + using namespace std; + using namespace OHOS::HyperAio; + const uint64_t userData = 12345; + const uint32_t len = 1024; + class HyperAioTest : public testing::Test { + public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; + }; + std::function)> callBack = [](std::unique_ptr response) { + GTEST_LOG_(INFO) << "HyperAioTest callBack"; + }; + + /** + * @tc.name: HyperAio_StartOpenReqs_0000 + * @tc.desc: Test function of StartOpenReqs() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_StartOpenReqs_0000, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartOpenReqs_0000"; + std::unique_ptr hyperAio_ = std::make_unique(); + int32_t result = hyperAio_->SupportIouring(); + EXPECT_EQ((result & IOURING_APP_PERMISSION) == 0, true); + if ((result & IOURING_APP_PERMISSION) == 0) { + return; + } + result = hyperAio_->CtxInit(nullptr); + EXPECT_EQ(result, -EINVAL); + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartOpenReqs_0000"; + } + + /** + * @tc.name: HyperAio_StartOpenReqs_0001 + * @tc.desc: Test function of StartOpenReqs() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_StartOpenReqs_0001, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartOpenReqs_0001"; + std::unique_ptr hyperAio_ = std::make_unique(); + int32_t result = hyperAio_->SupportIouring(); + EXPECT_EQ((result & IOURING_APP_PERMISSION) == 0, true); + if ((result & IOURING_APP_PERMISSION) == 0) { + return; + } + result = hyperAio_->CtxInit(&callBack); + EXPECT_EQ(result, 0); + OpenInfo openInfo = {0, O_RDWR, 0, nullptr, userData}; + OpenReqs openReqs = {1, &openInfo}; + result = hyperAio_->StartOpenReqs(&openReqs); + EXPECT_EQ(result, 0); + result = hyperAio_->DestroyCtx(); + EXPECT_EQ(result, 0); + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartOpenReqs_0001"; + } + + /** + * @tc.name: HyperAio_StartOpenReqs_0002 + * @tc.desc: Test function of StartOpenReqs() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_StartOpenReqs_0002, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartOpenReqs_0002"; + std::unique_ptr hyperAio_ = std::make_unique(); + int32_t result = hyperAio_->SupportIouring(); + EXPECT_EQ((result & IOURING_APP_PERMISSION) == 0, true); + if ((result & IOURING_APP_PERMISSION) == 0) { + return; + } + OpenInfo openInfo = {0, O_RDWR, 0, nullptr, userData}; + OpenReqs openReqs = {1, &openInfo}; + result = hyperAio_->StartOpenReqs(&openReqs); + EXPECT_EQ(result, -EPERM); + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartOpenReqs_0002"; + } + + /** + * @tc.name: HyperAio_StartReadReqs_0000 + * @tc.desc: Test function of StartReadReqs() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_StartReadReqs_0000, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartReadReqs_0000"; + std::unique_ptr hyperAio_ = std::make_unique(); + int32_t result = hyperAio_->SupportIouring(); + EXPECT_EQ((result & IOURING_APP_PERMISSION) == 0, true); + if ((result & IOURING_APP_PERMISSION) == 0) { + return; + } + result = hyperAio_->CtxInit(nullptr); + EXPECT_EQ(result, -EINVAL); + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0000"; + } + + /** + * @tc.name: HyperAio_StartReadReqs_0001 + * @tc.desc: Test function of StartReadReqs() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_StartReadReqs_0001, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartReadReqs_0001"; + std::unique_ptr hyperAio_ = std::make_unique(); + int32_t result = hyperAio_->SupportIouring(); + EXPECT_EQ((result & IOURING_APP_PERMISSION) == 0, true); + if ((result & IOURING_APP_PERMISSION) == 0) { + return; + } + result = hyperAio_->CtxInit(&callBack); + EXPECT_EQ(result, 0); + ReadInfo readInfo = {0, len, 0, nullptr, userData}; + ReadReqs readReqs = {1, &readInfo}; + result = hyperAio_->StartReadReqs(&readReqs); + EXPECT_EQ(result, 0); + result = hyperAio_->DestroyCtx(); + EXPECT_EQ(result, 0); + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0001"; + } + + /** + * @tc.name: HyperAio_StartReadReqs_0002 + * @tc.desc: Test function of StartReadReqs() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_StartReadReqs_0002, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartReadReqs_0002"; + std::unique_ptr hyperAio_ = std::make_unique(); + int32_t result = hyperAio_->SupportIouring(); + EXPECT_EQ((result & IOURING_APP_PERMISSION) == 0, true); + if ((result & IOURING_APP_PERMISSION) == 0) { + return; + } + ReadInfo readInfo = {0, len, 0, nullptr, userData}; + ReadReqs readReqs = {1, &readInfo}; + result = hyperAio_->StartReadReqs(&readReqs); + EXPECT_EQ(result, -EPERM); + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0002"; + } + + /** + * @tc.name: HyperAio_StartCancelReqs_0000 + * @tc.desc: Test function of StartCancelReqs() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_StartCancelReqs_0000, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartCancelReqs_0000"; + std::unique_ptr hyperAio_ = std::make_unique(); + int32_t result = hyperAio_->SupportIouring(); + EXPECT_EQ((result & IOURING_APP_PERMISSION) == 0, true); + if ((result & IOURING_APP_PERMISSION) == 0) { + return; + } + result = hyperAio_->CtxInit(nullptr); + EXPECT_EQ(result, -EINVAL); + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartCancelReqs_0000"; + } + + /** + * @tc.name: HyperAio_StartCancelReqs_0001 + * @tc.desc: Test function of StartCancelReqs() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_StartCancelReqs_0001, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartCancelReqs_0001"; + std::unique_ptr hyperAio_ = std::make_unique(); + int32_t result = hyperAio_->SupportIouring(); + EXPECT_EQ((result & IOURING_APP_PERMISSION) == 0, true); + if ((result & IOURING_APP_PERMISSION) == 0) { + return; + } + result = hyperAio_->CtxInit(&callBack); + EXPECT_EQ(result, 0); + CancelInfo cancelInfo = {userData, 0}; + CancelReqs cancelReqs = {1, &cancelInfo}; + result = hyperAio_->StartCancelReqs(&cancelReqs); + EXPECT_EQ(result, 0); + result = hyperAio_->DestroyCtx(); + EXPECT_EQ(result, 0); + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartCancelReqs_0001"; + } + + /** + * @tc.name: HyperAio_StartCancelReqs_0002 + * @tc.desc: Test function of StartCancelReqs() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_StartCancelReqs_0002, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartCancelReqs_0002"; + std::unique_ptr hyperAio_ = std::make_unique(); + int32_t result = hyperAio_->SupportIouring(); + EXPECT_EQ((result & IOURING_APP_PERMISSION) == 0, true); + if ((result & IOURING_APP_PERMISSION) == 0) { + return; + } + CancelInfo cancelInfo = {userData, 0}; + CancelReqs cancelReqs = {1, &cancelInfo}; + result = hyperAio_->StartCancelReqs(&cancelReqs); + EXPECT_EQ(result, -EPERM); + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartCancelReqs_0002"; + } +}