From 490775b34e6ec690a8e51e053279153bc471a2df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 29 May 2025 19:39:09 +0800 Subject: [PATCH 1/9] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/kits/hyperaio/include/hyperaio.h | 21 +++-- interfaces/kits/hyperaio/src/hyperaio.cpp | 72 +++++++++------ .../test/unittest/hyperaio/hyperaio_test.cpp | 87 ++++++++++++++++++- 3 files changed, 143 insertions(+), 37 deletions(-) diff --git a/interfaces/kits/hyperaio/include/hyperaio.h b/interfaces/kits/hyperaio/include/hyperaio.h index 94d884d89..36ce34790 100644 --- a/interfaces/kits/hyperaio/include/hyperaio.h +++ b/interfaces/kits/hyperaio/include/hyperaio.h @@ -17,13 +17,14 @@ #define FILEMANAGEMENT_FILE_API_INTERFACES_KITS_IOURING_HYPER_AIO_H #include +#include #include -#ifdef HYPERAIO_USE_LIBURING -#include "liburing.h" -#endif + + namespace OHOS { namespace HyperAio { #define IOURING_APP_PERMISSION (1U << 0) + #ifndef EOK #define EOK (0) #endif @@ -75,6 +76,10 @@ struct IoResponse { } }; +#define DECLARE_PIMPL(ClassName) \ + class Impl; \ + std::shared_ptr pImpl_ + class HyperAio { public: using ProcessIoResultCallBack = std::function)>; @@ -85,15 +90,13 @@ public: int32_t StartCancelReqs(CancelReqs *req); int32_t DestroyCtx(); private: + std::mutex initmtx; + DECLARE_PIMPL(HyperAio); ProcessIoResultCallBack ioResultCallBack_ = nullptr; -#ifdef HYPERAIO_USE_LIBURING - io_uring uring_; std::thread harvestThread_; - std::atomic stopThread_; - std::atomic initialized_; + std::atomic stopThread_ = true; + std::atomic initialized_ = false; void HarvestRes(); - struct io_uring_sqe* GetSqeWithRetry(struct io_uring *ring); -#endif }; } } diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index cc81205b6..ebc6e77a7 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -21,7 +21,9 @@ #include "hyperaio_trace.h" #include "libhilog.h" #include "ipc_skeleton.h" - +#ifdef HYPERAIO_USE_LIBURING +#include "liburing.h" +#endif namespace OHOS { namespace HyperAio { #ifdef HYPERAIO_USE_LIBURING @@ -29,6 +31,10 @@ const uint32_t URING_QUEUE_SIZE = 512; const uint32_t DELAY = 20; const uint32_t BATCH_SIZE = 128; const uint32_t RETRIES = 3; +class HyperAio::Impl { +public: + io_uring uring_; +} static bool HasAccessIouringPermission() { @@ -52,14 +58,36 @@ uint32_t HyperAio::SupportIouring() return flags; } +struct io_uring_sqe* HyperAio::GetSqeWithRetry(struct io_uring *ring) +{ + struct io_uring_sqe *sqe; + for (uint32_t i = 0; i < RETRIES; i++) { + sqe = io_uring_get_sqe(ring); + if (sqe != nullptr) { + return sqe; + } + io_uring_submit(ring); + std::this_thread::sleep_for(std::chrono::milliseconds(DELAY)); + } + return nullptr; +} + int32_t HyperAio::CtxInit(ProcessIoResultCallBack *callBack) { + std::lock_guard lock(initmtx); HyperaioTrace trace("CtxInit"); + if (initialized_.load()) { + HILOGE("HyperAio has benn initialized"); + return EOK; + } if (callBack == nullptr) { HILOGE("callBack is null"); return -EINVAL; } - int32_t ret = io_uring_queue_init(URING_QUEUE_SIZE, &uring_, 0); + if (pImpl == nullptr) { + pImpl_ = std::make_shared(); + } + int32_t ret = io_uring_queue_init(URING_QUEUE_SIZE, &pImpl_->uring_, 0); if (ret < 0) { HILOGE("init io_uring failed, ret = %{public}d", ret); return ret; @@ -72,19 +100,6 @@ int32_t HyperAio::CtxInit(ProcessIoResultCallBack *callBack) return EOK; } -struct io_uring_sqe* HyperAio::GetSqeWithRetry(struct io_uring *ring) -{ - struct io_uring_sqe *sqe; - for (uint32_t i = 0; i < RETRIES; i++) { - sqe = io_uring_get_sqe(ring); - if (sqe != nullptr) { - return sqe; - } - io_uring_submit(ring); - std::this_thread::sleep_for(std::chrono::milliseconds(DELAY)); - } - return nullptr; -} int32_t HyperAio::StartOpenReqs(OpenReqs *req) { @@ -99,7 +114,7 @@ int32_t HyperAio::StartOpenReqs(OpenReqs *req) uint32_t totalReqs = req->reqNum; uint32_t count = 0; for (uint32_t i = 0; i < totalReqs; i++) { - struct io_uring_sqe *sqe = GetSqeWithRetry(&uring_); + struct io_uring_sqe *sqe = GetSqeWithRetry(&pImpl_->uring_); if (sqe == nullptr) { HILOGE("get sqe failed"); return -ENOMEM; @@ -111,7 +126,7 @@ int32_t HyperAio::StartOpenReqs(OpenReqs *req) count++; if (count >= BATCH_SIZE) { count = 0; - int32_t ret = io_uring_submit(&uring_); + int32_t ret = io_uring_submit(&pImpl_->uring_); if (ret < 0) { HILOGE("submit open reqs failed, ret = %{public}d", ret); return ret; @@ -119,7 +134,7 @@ int32_t HyperAio::StartOpenReqs(OpenReqs *req) } } if (count > 0 && count < BATCH_SIZE) { - int32_t ret = io_uring_submit(&uring_); + int32_t ret = io_uring_submit(&pImpl_->uring_); if (ret < 0) { HILOGE("submit open reqs failed, ret = %{public}d", ret); return ret; @@ -141,7 +156,7 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) uint32_t totalReqs = req->reqNum; uint32_t count = 0; for (uint32_t i = 0; i < totalReqs; i++) { - struct io_uring_sqe *sqe = GetSqeWithRetry(&uring_); + struct io_uring_sqe *sqe = GetSqeWithRetry(&pImpl_->uring_); if (sqe == nullptr) { HILOGE("get sqe failed"); return -ENOMEM; @@ -152,7 +167,7 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) count++; if (count >= BATCH_SIZE) { count = 0; - int32_t ret = io_uring_submit(&uring_); + int32_t ret = io_uring_submit(&pImpl_->uring_); if (ret < 0) { HILOGE("submit read reqs failed, ret = %{public}d", ret); return ret; @@ -160,7 +175,7 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) } } if (count > 0 && count < BATCH_SIZE) { - int32_t ret = io_uring_submit(&uring_); + int32_t ret = io_uring_submit(&pImpl_->uring_); if (ret < 0) { HILOGE("submit read reqs failed, ret = %{public}d", ret); return ret; @@ -182,7 +197,7 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) uint32_t totalReqs = req->reqNum; uint32_t count = 0; for (uint32_t i = 0; i < totalReqs; i++) { - struct io_uring_sqe *sqe = GetSqeWithRetry(&uring_); + struct io_uring_sqe *sqe = GetSqeWithRetry(&pImpl_->uring_); if (sqe == nullptr) { HILOGE("get sqe failed"); return -ENOMEM; @@ -193,7 +208,7 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) count++; if (count >= BATCH_SIZE) { count = 0; - int32_t ret = io_uring_submit(&uring_); + int32_t ret = io_uring_submit(&pImpl_->uring_); if (ret < 0) { HILOGE("submit cancel reqs failed, ret = %{public}d", ret); return ret; @@ -201,7 +216,7 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) } } if (count > 0 && count < BATCH_SIZE) { - int32_t ret = io_uring_submit(&uring_); + int32_t ret = io_uring_submit(&pImpl_->uring_); if (ret < 0) { HILOGE("submit cancel reqs failed, ret = %{public}d", ret); return ret; @@ -212,15 +227,18 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) void HyperAio::HarvestRes() { + if (pImpl == nullptr) { + return; + } while (!stopThread_.load()) { struct io_uring_cqe *cqe; - int32_t ret = io_uring_wait_cqe(&uring_, &cqe); + int32_t ret = io_uring_wait_cqe(&pImpl_->uring_, &cqe); if (ret < 0 || cqe == nullptr) { HILOGI("wait cqe failed, ret = %{public}d", ret); continue; } auto response = std::make_unique(cqe->user_data, cqe->res, cqe->flags); - io_uring_cqe_seen(&uring_, cqe); + io_uring_cqe_seen(&pImpl_->uring_, cqe); if (ioResultCallBack_) { ioResultCallBack_(std::move(response)); } @@ -233,7 +251,7 @@ int32_t HyperAio::DestroyCtx() if (harvestThread_.joinable()) { harvestThread_.join(); } - io_uring_queue_exit(&uring_); + io_uring_queue_exit(&pImpl_->uring_); initialized_.store(false); return EOK; } diff --git a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp index 91ca75c8d..9103cafb9 100644 --- a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp +++ b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp @@ -36,7 +36,92 @@ namespace { std::function)> callBack = [](std::unique_ptr response) { GTEST_LOG_(INFO) << "HyperAioTest callBack"; }; - + /** + * @tc.name: HyperAio_SupportIouring_0000 + * @tc.desc: Test function of SupportIouring() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_SupportIouring_0000, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_SupportIouring_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; + } + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_SupportIouring_0000"; + } + /** + * @tc.name: HyperAio_CtxInit_0000 + * @tc.desc: Test function of CtxInit() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_CtxInit_0000, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_CtxInit_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_CtxInit_0000"; + } + /** + * @tc.name: HyperAio_CtxInit_0001 + * @tc.desc: Test function of CtxInit() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_CtxInit_0001, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_CtxInit_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, EOK); + result = hyperAio_->CtxInit(callBack); + EXPECT_EQ(result, EOK); + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_CtxInit_0001"; + } + /** + * @tc.name: HyperAio_CtxInit_0002 + * @tc.desc: Test function of CtxInit() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_CtxInit_0002, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_CtxInit_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; + } + result = hyperAio_->CtxInit(nullptr); + EXPECT_EQ(result, -EINVAL); + result = hyperAio_->CtxInit(callBack); + EXPECT_EQ(result, EOK); + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_CtxInit_0002"; + } /** * @tc.name: HyperAio_StartOpenReqs_0000 * @tc.desc: Test function of StartOpenReqs() interface for SUCCESS. -- Gitee From af40549f505e6d1738e10beb5b26d6e6cfe1fee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 29 May 2025 20:54:50 +0800 Subject: [PATCH 2/9] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/kits/hyperaio/src/hyperaio.cpp | 28 +++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index ebc6e77a7..16e1a7dff 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -34,7 +34,7 @@ const uint32_t RETRIES = 3; class HyperAio::Impl { public: io_uring uring_; -} +}; static bool HasAccessIouringPermission() { @@ -58,7 +58,7 @@ uint32_t HyperAio::SupportIouring() return flags; } -struct io_uring_sqe* HyperAio::GetSqeWithRetry(struct io_uring *ring) +struct io_uring_sqe* GetSqeWithRetry(struct io_uring *ring) { struct io_uring_sqe *sqe; for (uint32_t i = 0; i < RETRIES; i++) { @@ -77,14 +77,14 @@ int32_t HyperAio::CtxInit(ProcessIoResultCallBack *callBack) std::lock_guard lock(initmtx); HyperaioTrace trace("CtxInit"); if (initialized_.load()) { - HILOGE("HyperAio has benn initialized"); + HILOGE("HyperAio has been initialized"); return EOK; } if (callBack == nullptr) { HILOGE("callBack is null"); return -EINVAL; } - if (pImpl == nullptr) { + if (pImpl_ == nullptr) { pImpl_ = std::make_shared(); } int32_t ret = io_uring_queue_init(URING_QUEUE_SIZE, &pImpl_->uring_, 0); @@ -100,9 +100,11 @@ int32_t HyperAio::CtxInit(ProcessIoResultCallBack *callBack) return EOK; } - int32_t HyperAio::StartOpenReqs(OpenReqs *req) { + if (pImpl_ == nullptr) { + return; + } HyperaioTrace trace("StartOpenReqs" + std::to_string(req->reqNum)); if (req == nullptr || req->reqs == nullptr) { return -EINVAL; @@ -145,6 +147,9 @@ int32_t HyperAio::StartOpenReqs(OpenReqs *req) int32_t HyperAio::StartReadReqs(ReadReqs *req) { + if (pImpl_ == nullptr) { + return -EINVAL; + } HyperaioTrace trace("StartReadReqs" + std::to_string(req->reqNum)); if (req == nullptr || req->reqs == nullptr) { return -EINVAL; @@ -186,6 +191,9 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) int32_t HyperAio::StartCancelReqs(CancelReqs *req) { + if (pImpl_ == nullptr) { + return -EINVAL; + } HyperaioTrace trace("StartCancelReqs" + std::to_string(req->reqNum)); if (req == nullptr || req->reqs == nullptr) { return -EINVAL; @@ -227,7 +235,7 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) void HyperAio::HarvestRes() { - if (pImpl == nullptr) { + if (pImpl_ == nullptr) { return; } while (!stopThread_.load()) { @@ -247,11 +255,17 @@ void HyperAio::HarvestRes() int32_t HyperAio::DestroyCtx() { + if (!initialized_.load()) { + HILOGE("HyperAio is not initialized"); + return -EPERM; + } stopThread_.store(true); if (harvestThread_.joinable()) { harvestThread_.join(); } - io_uring_queue_exit(&pImpl_->uring_); + if (pImpl_ != nullptr) { + io_uring_queue_exit(&pImpl_->uring_); + } initialized_.store(false); return EOK; } -- Gitee From 4a01619ab3f0c4b7348b29a78bbf777710cf04e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 29 May 2025 20:59:35 +0800 Subject: [PATCH 3/9] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/kits/hyperaio/BUILD.gn | 4 ---- interfaces/kits/hyperaio/src/hyperaio.cpp | 3 +-- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/interfaces/kits/hyperaio/BUILD.gn b/interfaces/kits/hyperaio/BUILD.gn index 191ab9c0e..93b6f3c96 100644 --- a/interfaces/kits/hyperaio/BUILD.gn +++ b/interfaces/kits/hyperaio/BUILD.gn @@ -47,16 +47,12 @@ ohos_shared_library("HyperAio") { debug = false } } - sources = [ "src/hyperaio.cpp", "src/hyperaio_trace.cpp" ] - public_configs = [ ":hyperaio_config" ] - deps = [ ] - external_deps = [ "c_utils:utils", "hilog:libhilog", diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index 16e1a7dff..64378ead9 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -256,8 +256,7 @@ void HyperAio::HarvestRes() int32_t HyperAio::DestroyCtx() { if (!initialized_.load()) { - HILOGE("HyperAio is not initialized"); - return -EPERM; + return EOK; } stopThread_.store(true); if (harvestThread_.joinable()) { -- Gitee From 284810da23cca8ecc8a743f3a29e0661779960a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 29 May 2025 21:52:36 +0800 Subject: [PATCH 4/9] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/kits/hyperaio/src/hyperaio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index 64378ead9..0d1033d1b 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -103,7 +103,7 @@ int32_t HyperAio::CtxInit(ProcessIoResultCallBack *callBack) int32_t HyperAio::StartOpenReqs(OpenReqs *req) { if (pImpl_ == nullptr) { - return; + return -EINVAL; } HyperaioTrace trace("StartOpenReqs" + std::to_string(req->reqNum)); if (req == nullptr || req->reqs == nullptr) { -- Gitee From 790c99576b958e861f0b54bd02efafc6dcfa2773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Sat, 7 Jun 2025 22:26:14 +0800 Subject: [PATCH 5/9] tdd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/test/unittest/hyperaio/BUILD.gn | 14 +- .../test/unittest/hyperaio/hyperaio_test.cpp | 179 +++++++++--------- .../test/unittest/hyperaio/include/liburing.h | 83 ++++++++ 3 files changed, 186 insertions(+), 90 deletions(-) create mode 100644 interfaces/test/unittest/hyperaio/include/liburing.h diff --git a/interfaces/test/unittest/hyperaio/BUILD.gn b/interfaces/test/unittest/hyperaio/BUILD.gn index af73bb55d..d5c17c97b 100644 --- a/interfaces/test/unittest/hyperaio/BUILD.gn +++ b/interfaces/test/unittest/hyperaio/BUILD.gn @@ -19,7 +19,11 @@ ohos_unittest("hyperaio_test") { resource_config_file = "../resource/ohos_test.xml" - sources = [ "hyperaio_test.cpp" ] + sources = [ + "hyperaio_test.cpp", + "${file_api_path}/interfaces/kits/hyperaio/src/hyperaio.cpp", + "${file_api_path}/interfaces/kits/hyperaio/src/hyperaio_trace.cpp" + ] include_dirs = [ "include", @@ -27,7 +31,6 @@ ohos_unittest("hyperaio_test") { ] deps = [ - "${file_api_path}/interfaces/kits/hyperaio:HyperAio", ] external_deps = [ @@ -35,9 +38,14 @@ ohos_unittest("hyperaio_test") { "c_utils:utils", "c_utils:utilsbase", "ipc:ipc_core", + "hilog:libhilog", "googletest:gtest_main", + "hitrace:hitrace_meter" + ] + defines = [ + "private = public" ] if (file_api_feature_hyperaio) { - external_deps += [ "liburing:liburing" ] + defines += [ "HYPERAIO_USE_LIBURING" ] } } diff --git a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp index 9103cafb9..e7bca96b0 100644 --- a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp +++ b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp @@ -17,7 +17,7 @@ #include #include #include - +#include #include "hyperaio.h" namespace { @@ -33,9 +33,9 @@ namespace { #ifdef HYPERAIO_USE_LIBURING const uint64_t userData = 12345; const uint32_t len = 1024; - std::function)> callBack = [](std::unique_ptr response) { + HyperAio::ProcessIoResultCallBack callBack = [](std::unique_ptr response) { GTEST_LOG_(INFO) << "HyperAioTest callBack"; - }; + } /** * @tc.name: HyperAio_SupportIouring_0000 * @tc.desc: Test function of SupportIouring() interface for SUCCESS. @@ -67,13 +67,12 @@ namespace { { GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_CtxInit_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); + int32_t result = hyperAio_->CtxInit(&callBack); + EXPECT_EQ(result, 0); + result = hyperAio_->CtxInit(&callBack); + hyperAio_->stopThread_.store(true); + EXPECT_EQ(result, 0); + hyperAio_->DestroyCtx(); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_CtxInit_0000"; } /** @@ -88,15 +87,8 @@ namespace { { GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_CtxInit_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, EOK); - result = hyperAio_->CtxInit(callBack); - EXPECT_EQ(result, EOK); + result = hyperAio_->CtxInit(nullptr); + EXPECT_EQ(result, -EINVAL); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_CtxInit_0001"; } /** @@ -111,16 +103,29 @@ namespace { { GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_CtxInit_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; - } - result = hyperAio_->CtxInit(nullptr); - EXPECT_EQ(result, -EINVAL); result = hyperAio_->CtxInit(callBack); - EXPECT_EQ(result, EOK); + EXPECT_EQ(result, 0); + hyperAio_->DestroyCtx(); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_CtxInit_0002"; + } + /** + * @tc.name: HyperAio_CtxInit_0003 + * @tc.desc: Test function of CtxInit() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_CtxInit_0003, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_CtxInit_0003"; + std::unique_ptr hyperAio_ = std::make_unique(); + result = hyperAio_->CtxInit(nullptr); + EXPECT_EQ(result, -EINVAL); + result = hyperAio_->CtxInit(&callBack); + EXPECT_EQ(result, 0); + hyperAio_->DestroyCtx(); + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_CtxInit_0003"; } /** * @tc.name: HyperAio_StartOpenReqs_0000 @@ -134,12 +139,9 @@ namespace { { 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); + result = hyperAio_->CtxInit(&callBack); + EXPECT_EQ(result, 0); + result = hyperAio_->StartOpenReqs(nullptr); EXPECT_EQ(result, -EINVAL); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartOpenReqs_0000"; } @@ -156,19 +158,10 @@ namespace { { 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); + EXPECT_EQ(result, -EPERM); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartOpenReqs_0001"; } @@ -184,18 +177,47 @@ namespace { { 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; - } + int32_t 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, -EPERM); + EXPECT_EQ(result, 0); + result = hyperAio_->DestoryCtx(); + EXPECT_EQ(result, 0); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartOpenReqs_0002"; } + /** + * @tc.name: HyperAio_StartOpenReqs_0003 + * @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_0003, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartOpenReqs_0003"; + std::unique_ptr hyperAio_ = std::make_unique(); + int32_t result = hyperAio_->CtxInit(&callBack); + EXPECT_EQ(result, 0); + OpenInfo* openInfo = new OpenInfo[300]; + for (int i = 0; i < 300; ++i) { + openInfo[i].dfd = 0; + openInfo[i].flags = o_RDWR; + openInfo[i].mode = 0; + openInfo[i].path = nullptr; + openInfo[i].userData = userData + i; + } + OpenReqs openReqs = {300, openInfos}; + result = hyperAio_->StartOpenReqs(&openReqs); + EXPECT_EQ(result, 0); + result = hyperAio_->DestoryCtx(); + EXPECT_EQ(result, 0); + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartOpenReqs_0003"; + } + /** * @tc.name: HyperAio_StartReadReqs_0000 * @tc.desc: Test function of StartReadReqs() interface for SUCCESS. @@ -208,13 +230,10 @@ namespace { { 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); + int32_t result = hyperAio_->CtxInit(&callBack); + result = hyperAio_->StartReadReqs(nullptr); EXPECT_EQ(result, -EINVAL); + result = hyperAio_->DestoryCtx(); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0000"; } @@ -230,17 +249,14 @@ namespace { { 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); + hyperAio_->initialized_.store(false); ReadInfo readInfo = {0, len, 0, nullptr, userData}; ReadReqs readReqs = {1, &readInfo}; result = hyperAio_->StartReadReqs(&readReqs); - EXPECT_EQ(result, 0); + EXPECT_EQ(result, -EPERM); + hyperAio_->initialized_.store(true); result = hyperAio_->DestroyCtx(); EXPECT_EQ(result, 0); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0001"; @@ -258,15 +274,13 @@ namespace { { 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; - } + int32_t result = hyperAio_->CtxInit(&callBack); ReadInfo readInfo = {0, len, 0, nullptr, userData}; ReadReqs readReqs = {1, &readInfo}; result = hyperAio_->StartReadReqs(&readReqs); - EXPECT_EQ(result, -EPERM); + EXPECT_EQ(result, 0); + result = hyperAio_->DestroyCtx(); + EXPECT_EQ(result, 0); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0002"; } @@ -282,13 +296,10 @@ namespace { { 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); + int32_t result = hyperAio_->CtxInit(&callBack); + result = hyperAio_->StartCancelReqs(nullptr); + result = hyperAio_->DestroyCtx(); + EXPECT_EQ(result, 0); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartCancelReqs_0000"; } @@ -304,17 +315,13 @@ namespace { { 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); + hyperAio_->initialized_.store(false); CancelInfo cancelInfo = {userData, 0}; CancelReqs cancelReqs = {1, &cancelInfo}; result = hyperAio_->StartCancelReqs(&cancelReqs); - EXPECT_EQ(result, 0); + EXPECT_EQ(result, -EPERM); + hyperAio_->initialized_.store(true); result = hyperAio_->DestroyCtx(); EXPECT_EQ(result, 0); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartCancelReqs_0001"; @@ -332,15 +339,13 @@ namespace { { 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; - } + int32_t result = hyperAio_->CtxInit(&callBack); CancelInfo cancelInfo = {userData, 0}; CancelReqs cancelReqs = {1, &cancelInfo}; result = hyperAio_->StartCancelReqs(&cancelReqs); - EXPECT_EQ(result, -EPERM); + EXPECT_EQ(result, 0); + result = hyperAio_->DestroyCtx(); + EXPECT_EQ(result, 0); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartCancelReqs_0002"; } #endif diff --git a/interfaces/test/unittest/hyperaio/include/liburing.h b/interfaces/test/unittest/hyperaio/include/liburing.h new file mode 100644 index 000000000..a8090aa71 --- /dev/null +++ b/interfaces/test/unittest/hyperaio/include/liburing.h @@ -0,0 +1,83 @@ +/* + * 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. + */ + +namespace OHOS { +namespace HyperAio { +#define O_RDWR 02 +struct io_uring_sqe { + int32_t data; +}; + +struct io_uring_cqe { + int32_t data; + uint64_t user_data; + int32_t res; + uint32_t flags; +}; + +struct io_uring { + int32_t data; +} + +inline struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring) +{ + return new io_uring_sqe(); +} + +inline int io_uring_submit(struct io_uring *ring) +{ + return 1; +} + +inline int io_uring_queue_init(unsigned entries, struct io_uring *ring, unsigned flags) +{ + return 1; +} + +inline void io_uring_sqe_set_data(struct io_uring_sqe *sqe, void *data) +{ + return; +} + +inline void io_uring_prep_openat(struct io_uring_sqe *sqe, int dfd, + const char *path, int flags, mode_t mode) +{ + return; +} + +inline void io_uring_prep_read(struct io_uring_sqe *sqe, int fd, + void *buf, unsigned nbytes, uint64_t offset) +{ + return; +} + +inline void io_uring_prep_cancel(struct io_uring_sqe *sqe, + void *user_data, int flags) +{ + return; +} + +inline int io_uring_wait_cqe(struct io_uring *ring, struct io_uring_cqe **cqe_ptr) +{ + return; +} + +inline void io_uring_queue_exit(struct io_uring *ring) +{ + return; +} + +} +} \ No newline at end of file -- Gitee From dbbbf22bf7645a38ddf75289e151bbee04828676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Sat, 7 Jun 2025 22:49:15 +0800 Subject: [PATCH 6/9] tdd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/kits/hyperaio/include/hyperaio.h | 1 + interfaces/kits/hyperaio/src/hyperaio.cpp | 2 +- .../test/unittest/hyperaio/hyperaio_test.cpp | 43 ++++++++++--------- .../test/unittest/hyperaio/include/liburing.h | 12 +++++- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/interfaces/kits/hyperaio/include/hyperaio.h b/interfaces/kits/hyperaio/include/hyperaio.h index 36ce34790..cccb42f53 100644 --- a/interfaces/kits/hyperaio/include/hyperaio.h +++ b/interfaces/kits/hyperaio/include/hyperaio.h @@ -18,6 +18,7 @@ #include #include +#include #include diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index 0d1033d1b..0cd3a512e 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -105,7 +105,6 @@ int32_t HyperAio::StartOpenReqs(OpenReqs *req) if (pImpl_ == nullptr) { return -EINVAL; } - HyperaioTrace trace("StartOpenReqs" + std::to_string(req->reqNum)); if (req == nullptr || req->reqs == nullptr) { return -EINVAL; } @@ -113,6 +112,7 @@ int32_t HyperAio::StartOpenReqs(OpenReqs *req) HILOGE("HyperAio is not initialized"); return -EPERM; } + HyperaioTrace trace("StartOpenReqs" + std::to_string(req->reqNum)); uint32_t totalReqs = req->reqNum; uint32_t count = 0; for (uint32_t i = 0; i < totalReqs; i++) { diff --git a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp index e7bca96b0..23620409a 100644 --- a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp +++ b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp @@ -17,12 +17,12 @@ #include #include #include -#include +#include "liburing.h" #include "hyperaio.h" -namespace { +namespace OHOS::HyperAio{ using namespace std; - using namespace OHOS::HyperAio; + using namespace testing; class HyperAioTest : public testing::Test { public: static void SetUpTestCase(void) {}; @@ -35,7 +35,7 @@ namespace { const uint32_t len = 1024; HyperAio::ProcessIoResultCallBack callBack = [](std::unique_ptr response) { GTEST_LOG_(INFO) << "HyperAioTest callBack"; - } + }; /** * @tc.name: HyperAio_SupportIouring_0000 * @tc.desc: Test function of SupportIouring() interface for SUCCESS. @@ -87,7 +87,7 @@ namespace { { GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_CtxInit_0001"; std::unique_ptr hyperAio_ = std::make_unique(); - result = hyperAio_->CtxInit(nullptr); + int32_t result = hyperAio_->CtxInit(nullptr); EXPECT_EQ(result, -EINVAL); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_CtxInit_0001"; } @@ -103,12 +103,12 @@ namespace { { GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_CtxInit_0002"; std::unique_ptr hyperAio_ = std::make_unique(); - result = hyperAio_->CtxInit(callBack); + result = hyperAio_->CtxInit(&callBack); EXPECT_EQ(result, 0); hyperAio_->DestroyCtx(); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_CtxInit_0002"; } - /** + /** * @tc.name: HyperAio_CtxInit_0003 * @tc.desc: Test function of CtxInit() interface for SUCCESS. * @tc.size: MEDIUM @@ -139,10 +139,11 @@ namespace { { GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartOpenReqs_0000"; std::unique_ptr hyperAio_ = std::make_unique(); - result = hyperAio_->CtxInit(&callBack); + int32_t result = hyperAio_->CtxInit(&callBack); EXPECT_EQ(result, 0); result = hyperAio_->StartOpenReqs(nullptr); EXPECT_EQ(result, -EINVAL); + hyperAio_->DestroyCtx(); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartOpenReqs_0000"; } @@ -160,7 +161,7 @@ namespace { std::unique_ptr hyperAio_ = std::make_unique(); OpenInfo openInfo = {0, O_RDWR, 0, nullptr, userData}; OpenReqs openReqs = {1, &openInfo}; - result = hyperAio_->StartOpenReqs(&openReqs); + int32_t result = hyperAio_->StartOpenReqs(&openReqs); EXPECT_EQ(result, -EPERM); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartOpenReqs_0001"; } @@ -183,12 +184,12 @@ namespace { OpenReqs openReqs = {1, &openInfo}; result = hyperAio_->StartOpenReqs(&openReqs); EXPECT_EQ(result, 0); - result = hyperAio_->DestoryCtx(); + result = hyperAio_->DestroyCtx(); EXPECT_EQ(result, 0); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartOpenReqs_0002"; } - /** + /** * @tc.name: HyperAio_StartOpenReqs_0003 * @tc.desc: Test function of StartOpenReqs() interface for SUCCESS. * @tc.size: MEDIUM @@ -202,18 +203,18 @@ namespace { std::unique_ptr hyperAio_ = std::make_unique(); int32_t result = hyperAio_->CtxInit(&callBack); EXPECT_EQ(result, 0); - OpenInfo* openInfo = new OpenInfo[300]; + OpenInfo* openInfos = new OpenInfo[300]; for (int i = 0; i < 300; ++i) { - openInfo[i].dfd = 0; - openInfo[i].flags = o_RDWR; - openInfo[i].mode = 0; - openInfo[i].path = nullptr; - openInfo[i].userData = userData + i; + openInfos[i].dfd = 0; + openInfos[i].flags = o_RDWR; + openInfos[i].mode = 0; + openInfos[i].path = nullptr; + openInfos[i].userData = userData + i; } OpenReqs openReqs = {300, openInfos}; result = hyperAio_->StartOpenReqs(&openReqs); EXPECT_EQ(result, 0); - result = hyperAio_->DestoryCtx(); + result = hyperAio_->DestroyCtx(); EXPECT_EQ(result, 0); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartOpenReqs_0003"; } @@ -233,7 +234,7 @@ namespace { int32_t result = hyperAio_->CtxInit(&callBack); result = hyperAio_->StartReadReqs(nullptr); EXPECT_EQ(result, -EINVAL); - result = hyperAio_->DestoryCtx(); + result = hyperAio_->DestroyCtx(); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0000"; } @@ -249,7 +250,7 @@ namespace { { GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartReadReqs_0001"; std::unique_ptr hyperAio_ = std::make_unique(); - result = hyperAio_->CtxInit(&callBack); + int32_t result = hyperAio_->CtxInit(&callBack); EXPECT_EQ(result, 0); hyperAio_->initialized_.store(false); ReadInfo readInfo = {0, len, 0, nullptr, userData}; @@ -315,7 +316,7 @@ namespace { { GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartCancelReqs_0001"; std::unique_ptr hyperAio_ = std::make_unique(); - result = hyperAio_->CtxInit(&callBack); + int32_t result = hyperAio_->CtxInit(&callBack); hyperAio_->initialized_.store(false); CancelInfo cancelInfo = {userData, 0}; CancelReqs cancelReqs = {1, &cancelInfo}; diff --git a/interfaces/test/unittest/hyperaio/include/liburing.h b/interfaces/test/unittest/hyperaio/include/liburing.h index a8090aa71..57b865785 100644 --- a/interfaces/test/unittest/hyperaio/include/liburing.h +++ b/interfaces/test/unittest/hyperaio/include/liburing.h @@ -29,7 +29,7 @@ struct io_uring_cqe { struct io_uring { int32_t data; -} +}; inline struct io_uring_sqe *io_uring_get_sqe(struct io_uring *ring) { @@ -70,6 +70,16 @@ inline void io_uring_prep_cancel(struct io_uring_sqe *sqe, } inline int io_uring_wait_cqe(struct io_uring *ring, struct io_uring_cqe **cqe_ptr) +{ + *cqe_ptr = new io_uring_cqe; + (*cqe_ptr)->data = 0; + (*cqe_ptr)->user_data = 0; + (*cqe_ptr)->res = 0; + (*cqe_ptr)->flags = 0; + return 1; +} + +inline void io_uring_cqe_seen(struct io_uring *ring, struct io_uring_cqe *cqe) { return; } -- Gitee From f1212858faba48c072b20abf0bcf1e73297682fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Sat, 7 Jun 2025 22:57:55 +0800 Subject: [PATCH 7/9] tdd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/kits/hyperaio/src/hyperaio.cpp | 4 ++-- interfaces/test/unittest/hyperaio/hyperaio_test.cpp | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index 0cd3a512e..214fc6ae4 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -150,7 +150,6 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) if (pImpl_ == nullptr) { return -EINVAL; } - HyperaioTrace trace("StartReadReqs" + std::to_string(req->reqNum)); if (req == nullptr || req->reqs == nullptr) { return -EINVAL; } @@ -158,6 +157,7 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) HILOGE("HyperAio is not initialized"); return -EPERM; } + HyperaioTrace trace("StartReadReqs" + std::to_string(req->reqNum)); uint32_t totalReqs = req->reqNum; uint32_t count = 0; for (uint32_t i = 0; i < totalReqs; i++) { @@ -194,7 +194,6 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) if (pImpl_ == nullptr) { return -EINVAL; } - HyperaioTrace trace("StartCancelReqs" + std::to_string(req->reqNum)); if (req == nullptr || req->reqs == nullptr) { return -EINVAL; } @@ -202,6 +201,7 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) HILOGE("HyperAio is not initialized"); return -EPERM; } + HyperaioTrace trace("StartCancelReqs" + std::to_string(req->reqNum)); uint32_t totalReqs = req->reqNum; uint32_t count = 0; for (uint32_t i = 0; i < totalReqs; i++) { diff --git a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp index 23620409a..736a93360 100644 --- a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp +++ b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp @@ -20,9 +20,10 @@ #include "liburing.h" #include "hyperaio.h" -namespace OHOS::HyperAio{ +namespace OHOS::HyperAio { using namespace std; using namespace testing; + class HyperAioTest : public testing::Test { public: static void SetUpTestCase(void) {}; @@ -103,7 +104,7 @@ namespace OHOS::HyperAio{ { GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_CtxInit_0002"; std::unique_ptr hyperAio_ = std::make_unique(); - result = hyperAio_->CtxInit(&callBack); + int32_t result = hyperAio_->CtxInit(&callBack); EXPECT_EQ(result, 0); hyperAio_->DestroyCtx(); GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_CtxInit_0002"; @@ -120,7 +121,7 @@ namespace OHOS::HyperAio{ { GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_CtxInit_0003"; std::unique_ptr hyperAio_ = std::make_unique(); - result = hyperAio_->CtxInit(nullptr); + int32_t result = hyperAio_->CtxInit(nullptr); EXPECT_EQ(result, -EINVAL); result = hyperAio_->CtxInit(&callBack); EXPECT_EQ(result, 0); @@ -206,7 +207,7 @@ namespace OHOS::HyperAio{ OpenInfo* openInfos = new OpenInfo[300]; for (int i = 0; i < 300; ++i) { openInfos[i].dfd = 0; - openInfos[i].flags = o_RDWR; + openInfos[i].flags = O_RDWR; openInfos[i].mode = 0; openInfos[i].path = nullptr; openInfos[i].userData = userData + i; -- Gitee From b04e5b016ccf3b0bfe857e50602203efb9fab04c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Sun, 8 Jun 2025 15:16:18 +0800 Subject: [PATCH 8/9] tdd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/kits/hyperaio/include/hyperaio.h | 1 - interfaces/kits/hyperaio/src/hyperaio.cpp | 1 - interfaces/test/unittest/hyperaio/hyperaio_test.cpp | 7 ++++--- interfaces/test/unittest/hyperaio/include/liburing.h | 10 +++++++--- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/interfaces/kits/hyperaio/include/hyperaio.h b/interfaces/kits/hyperaio/include/hyperaio.h index cccb42f53..f7f64104c 100644 --- a/interfaces/kits/hyperaio/include/hyperaio.h +++ b/interfaces/kits/hyperaio/include/hyperaio.h @@ -91,7 +91,6 @@ public: int32_t StartCancelReqs(CancelReqs *req); int32_t DestroyCtx(); private: - std::mutex initmtx; DECLARE_PIMPL(HyperAio); ProcessIoResultCallBack ioResultCallBack_ = nullptr; std::thread harvestThread_; diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index 214fc6ae4..e133eca52 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -74,7 +74,6 @@ struct io_uring_sqe* GetSqeWithRetry(struct io_uring *ring) int32_t HyperAio::CtxInit(ProcessIoResultCallBack *callBack) { - std::lock_guard lock(initmtx); HyperaioTrace trace("CtxInit"); if (initialized_.load()) { HILOGE("HyperAio has been initialized"); diff --git a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp index 736a93360..9cce3a295 100644 --- a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp +++ b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp @@ -34,6 +34,7 @@ namespace OHOS::HyperAio { #ifdef HYPERAIO_USE_LIBURING const uint64_t userData = 12345; const uint32_t len = 1024; + const uint32_t batchSize =300; HyperAio::ProcessIoResultCallBack callBack = [](std::unique_ptr response) { GTEST_LOG_(INFO) << "HyperAioTest callBack"; }; @@ -204,15 +205,15 @@ namespace OHOS::HyperAio { std::unique_ptr hyperAio_ = std::make_unique(); int32_t result = hyperAio_->CtxInit(&callBack); EXPECT_EQ(result, 0); - OpenInfo* openInfos = new OpenInfo[300]; - for (int i = 0; i < 300; ++i) { + std::unique_ptr openInfos(new OpenInfo[batchSize]); + for (int i = 0; i < batchSize; ++i) { openInfos[i].dfd = 0; openInfos[i].flags = O_RDWR; openInfos[i].mode = 0; openInfos[i].path = nullptr; openInfos[i].userData = userData + i; } - OpenReqs openReqs = {300, openInfos}; + OpenReqs openReqs = {batchSize, openInfos}; result = hyperAio_->StartOpenReqs(&openReqs); EXPECT_EQ(result, 0); result = hyperAio_->DestroyCtx(); diff --git a/interfaces/test/unittest/hyperaio/include/liburing.h b/interfaces/test/unittest/hyperaio/include/liburing.h index 57b865785..bcfa4e484 100644 --- a/interfaces/test/unittest/hyperaio/include/liburing.h +++ b/interfaces/test/unittest/hyperaio/include/liburing.h @@ -13,6 +13,9 @@ * limitations under the License. */ +#ifndef UNITTEST_HYPERAIO_INCLUDE_LIBURING_H +#define UNITTEST_HYPERAIO_INCLUDE_LIBURING_H + namespace OHOS { namespace HyperAio { #define O_RDWR 02 @@ -52,19 +55,19 @@ inline void io_uring_sqe_set_data(struct io_uring_sqe *sqe, void *data) } inline void io_uring_prep_openat(struct io_uring_sqe *sqe, int dfd, - const char *path, int flags, mode_t mode) + const char *path, int flags, mode_t mode) { return; } inline void io_uring_prep_read(struct io_uring_sqe *sqe, int fd, - void *buf, unsigned nbytes, uint64_t offset) + void *buf, unsigned nbytes, uint64_t offset) { return; } inline void io_uring_prep_cancel(struct io_uring_sqe *sqe, - void *user_data, int flags) + void *user_data, int flags) { return; } @@ -81,6 +84,7 @@ inline int io_uring_wait_cqe(struct io_uring *ring, struct io_uring_cqe **cqe_pt inline void io_uring_cqe_seen(struct io_uring *ring, struct io_uring_cqe *cqe) { + delete cqe; return; } -- Gitee From 19550846525daa79b723d95797d9907c05389204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Sun, 8 Jun 2025 16:38:47 +0800 Subject: [PATCH 9/9] tdd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/test/unittest/hyperaio/hyperaio_test.cpp | 6 +++--- interfaces/test/unittest/hyperaio/include/liburing.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp index 9cce3a295..ee66aaa54 100644 --- a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp +++ b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp @@ -34,7 +34,7 @@ namespace OHOS::HyperAio { #ifdef HYPERAIO_USE_LIBURING const uint64_t userData = 12345; const uint32_t len = 1024; - const uint32_t batchSize =300; + const uint32_t batchSize = 300; HyperAio::ProcessIoResultCallBack callBack = [](std::unique_ptr response) { GTEST_LOG_(INFO) << "HyperAioTest callBack"; }; @@ -205,7 +205,7 @@ namespace OHOS::HyperAio { std::unique_ptr hyperAio_ = std::make_unique(); int32_t result = hyperAio_->CtxInit(&callBack); EXPECT_EQ(result, 0); - std::unique_ptr openInfos(new OpenInfo[batchSize]); + auto openInfos = std::make_unique(batchSize); for (int i = 0; i < batchSize; ++i) { openInfos[i].dfd = 0; openInfos[i].flags = O_RDWR; @@ -213,7 +213,7 @@ namespace OHOS::HyperAio { openInfos[i].path = nullptr; openInfos[i].userData = userData + i; } - OpenReqs openReqs = {batchSize, openInfos}; + OpenReqs openReqs = {batchSize, openInfos.get()}; result = hyperAio_->StartOpenReqs(&openReqs); EXPECT_EQ(result, 0); result = hyperAio_->DestroyCtx(); diff --git a/interfaces/test/unittest/hyperaio/include/liburing.h b/interfaces/test/unittest/hyperaio/include/liburing.h index bcfa4e484..de049be01 100644 --- a/interfaces/test/unittest/hyperaio/include/liburing.h +++ b/interfaces/test/unittest/hyperaio/include/liburing.h @@ -94,4 +94,5 @@ inline void io_uring_queue_exit(struct io_uring *ring) } } -} \ No newline at end of file +} +#endif \ No newline at end of file -- Gitee