1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <gtest/gtest.h> 17 #include <cerrno> 18 #include <string> 19 #include <vector> 20 #include "liburing.h" 21 #include "hyperaio.h" 22 23 namespace OHOS::HyperAio { 24 using namespace std; 25 using namespace testing; 26 27 class HyperAioTest : public testing::Test { 28 public: SetUpTestCase(void)29 static void SetUpTestCase(void) {}; TearDownTestCase()30 static void TearDownTestCase() {}; SetUp()31 void SetUp() {}; TearDown()32 void TearDown() {}; 33 }; 34 #ifdef HYPERAIO_USE_LIBURING 35 const uint64_t userData = 12345; 36 const uint32_t len = 1024; 37 const uint32_t batchSize = 300; 38 const uint32_t Threshold = 600; __anonfa93ff370102(std::unique_ptr<IoResponse> response) 39 HyperAio::ProcessIoResultCallBack callBack = [](std::unique_ptr<IoResponse> response) { 40 GTEST_LOG_(INFO) << "HyperAioTest callBack"; 41 }; 42 43 /** 44 * @tc.name: HyperAio_SupportIouring_0000 45 * @tc.desc: Test function of SupportIouring() interface for SUCCESS. 46 * @tc.size: MEDIUM 47 * @tc.type: FUNC 48 * @tc.level Level 1 49 */ 50 HWTEST_F(HyperAioTest, HyperAio_SupportIouring_0000, testing::ext::TestSize.Level1) 51 { 52 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_SupportIouring_0000"; 53 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 54 int32_t result = hyperAio_->SupportIouring(); 55 EXPECT_EQ((result & IOURING_APP_PERMISSION) == 0, true); 56 if ((result & IOURING_APP_PERMISSION) == 0) { 57 return; 58 } 59 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_SupportIouring_0000"; 60 } 61 62 /** 63 * @tc.name: HyperAio_CtxInit_0000 64 * @tc.desc: Test function of CtxInit() interface for SUCCESS. 65 * @tc.size: MEDIUM 66 * @tc.type: FUNC 67 * @tc.level Level 1 68 */ 69 HWTEST_F(HyperAioTest, HyperAio_CtxInit_0000, testing::ext::TestSize.Level0) 70 { 71 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_CtxInit_0000"; 72 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 73 int32_t result = hyperAio_->CtxInit(&callBack); 74 EXPECT_EQ(result, 0); 75 result = hyperAio_->CtxInit(&callBack); 76 hyperAio_->stopThread_.store(true); 77 EXPECT_EQ(result, 0); 78 hyperAio_->DestroyCtx(); 79 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_CtxInit_0000"; 80 } 81 82 /** 83 * @tc.name: HyperAio_CtxInit_0001 84 * @tc.desc: Test function of CtxInit() interface for SUCCESS. 85 * @tc.size: MEDIUM 86 * @tc.type: FUNC 87 * @tc.level Level 1 88 */ 89 HWTEST_F(HyperAioTest, HyperAio_CtxInit_0001, testing::ext::TestSize.Level1) 90 { 91 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_CtxInit_0001"; 92 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 93 int32_t result = hyperAio_->CtxInit(nullptr); 94 EXPECT_EQ(result, -EINVAL); 95 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_CtxInit_0001"; 96 } 97 98 /** 99 * @tc.name: HyperAio_CtxInit_0002 100 * @tc.desc: Test function of CtxInit() interface for SUCCESS. 101 * @tc.size: MEDIUM 102 * @tc.type: FUNC 103 * @tc.level Level 1 104 */ 105 HWTEST_F(HyperAioTest, HyperAio_CtxInit_0002, testing::ext::TestSize.Level1) 106 { 107 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_CtxInit_0002"; 108 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 109 int32_t result = hyperAio_->CtxInit(&callBack); 110 EXPECT_EQ(result, 0); 111 hyperAio_->DestroyCtx(); 112 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_CtxInit_0002"; 113 } 114 115 /** 116 * @tc.name: HyperAio_CtxInit_0003 117 * @tc.desc: Test function of CtxInit() interface for SUCCESS. 118 * @tc.size: MEDIUM 119 * @tc.type: FUNC 120 * @tc.level Level 1 121 */ 122 HWTEST_F(HyperAioTest, HyperAio_CtxInit_0003, testing::ext::TestSize.Level1) 123 { 124 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_CtxInit_0003"; 125 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 126 int32_t result = hyperAio_->CtxInit(nullptr); 127 EXPECT_EQ(result, -EINVAL); 128 result = hyperAio_->CtxInit(&callBack); 129 EXPECT_EQ(result, 0); 130 hyperAio_->DestroyCtx(); 131 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_CtxInit_0003"; 132 } 133 134 /** 135 * @tc.name: HyperAio_CtxInit_0004 136 * @tc.desc: Test function of CtxInit() interface for SUCCESS. 137 * @tc.size: MEDIUM 138 * @tc.type: FUNC 139 * @tc.level Level 1 140 */ 141 HWTEST_F(HyperAioTest, HyperAio_CtxInit_0004, testing::ext::TestSize.Level1) 142 { 143 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_CtxInit_0004"; 144 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 145 init_flag = false; 146 int32_t result = hyperAio_->CtxInit(&callBack); 147 EXPECT_EQ(result, -1); 148 init_flag = true; 149 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_CtxInit_0004"; 150 } 151 152 /** 153 * @tc.name: HyperAio_StartOpenReqs_0000 154 * @tc.desc: Test function of StartOpenReqs() interface for SUCCESS. 155 * @tc.size: MEDIUM 156 * @tc.type: FUNC 157 * @tc.level Level 1 158 */ 159 HWTEST_F(HyperAioTest, HyperAio_StartOpenReqs_0000, testing::ext::TestSize.Level1) 160 { 161 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartOpenReqs_0000"; 162 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 163 int32_t result = hyperAio_->CtxInit(&callBack); 164 EXPECT_EQ(result, 0); 165 result = hyperAio_->StartOpenReqs(nullptr); 166 EXPECT_EQ(result, -EINVAL); 167 hyperAio_->DestroyCtx(); 168 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartOpenReqs_0000"; 169 } 170 171 /** 172 * @tc.name: HyperAio_StartOpenReqs_0001 173 * @tc.desc: Test function of StartOpenReqs() interface for SUCCESS. 174 * @tc.size: MEDIUM 175 * @tc.type: FUNC 176 * @tc.level Level 1 177 */ 178 HWTEST_F(HyperAioTest, HyperAio_StartOpenReqs_0001, testing::ext::TestSize.Level1) 179 { 180 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartOpenReqs_0001"; 181 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 182 int32_t result = hyperAio_->CtxInit(&callBack); 183 EXPECT_EQ(result, 0); 184 hyperAio_->initialized_.store(false); 185 OpenInfo openInfo = {0, O_RDWR, 0, nullptr, userData}; 186 OpenReqs openReqs = {1, &openInfo}; 187 result = hyperAio_->StartOpenReqs(&openReqs); 188 EXPECT_EQ(result, -EPERM); 189 hyperAio_->initialized_.store(true); 190 result = hyperAio_->DestroyCtx(); 191 EXPECT_EQ(result, 0); 192 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartOpenReqs_0001"; 193 } 194 195 /** 196 * @tc.name: HyperAio_StartOpenReqs_0002 197 * @tc.desc: Test function of StartOpenReqs() interface for SUCCESS. 198 * @tc.size: MEDIUM 199 * @tc.type: FUNC 200 * @tc.level Level 1 201 */ 202 HWTEST_F(HyperAioTest, HyperAio_StartOpenReqs_0002, testing::ext::TestSize.Level0) 203 { 204 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartOpenReqs_0002"; 205 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 206 int32_t result = hyperAio_->CtxInit(&callBack); 207 EXPECT_EQ(result, 0); 208 OpenInfo openInfo = {0, O_RDWR, 0, nullptr, userData}; 209 OpenReqs openReqs = {1, &openInfo}; 210 result = hyperAio_->StartOpenReqs(&openReqs); 211 EXPECT_EQ(result, 0); 212 result = hyperAio_->DestroyCtx(); 213 EXPECT_EQ(result, 0); 214 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartOpenReqs_0002"; 215 } 216 217 /** 218 * @tc.name: HyperAio_StartOpenReqs_0003 219 * @tc.desc: Test function of StartOpenReqs() interface for SUCCESS. 220 * @tc.size: MEDIUM 221 * @tc.type: FUNC 222 * @tc.level Level 1 223 */ 224 HWTEST_F(HyperAioTest, HyperAio_StartOpenReqs_0003, testing::ext::TestSize.Level1) 225 { 226 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartOpenReqs_0003"; 227 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 228 int32_t result = hyperAio_->CtxInit(&callBack); 229 EXPECT_EQ(result, 0); 230 auto openInfos = std::make_unique<OpenInfo[]>(batchSize); 231 for (int i = 0; i < batchSize; ++i) { 232 openInfos[i].dfd = 0; 233 openInfos[i].flags = O_RDWR; 234 openInfos[i].mode = 0; 235 openInfos[i].path = nullptr; 236 openInfos[i].userData = userData + i; 237 } 238 OpenReqs openReqs = {batchSize, openInfos.get()}; 239 result = hyperAio_->StartOpenReqs(&openReqs); 240 EXPECT_EQ(result, 0); 241 sqe_flag = false; 242 result = hyperAio_->StartOpenReqs(&openReqs); 243 EXPECT_EQ(result, 0); 244 sqe_flag = true; 245 submit_flag = false; 246 result = hyperAio_->StartOpenReqs(&openReqs); 247 EXPECT_EQ(result, 0); 248 submit_flag = true; 249 result = hyperAio_->DestroyCtx(); 250 EXPECT_EQ(result, 0); 251 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartOpenReqs_0003"; 252 } 253 254 /** 255 * @tc.name: HyperAio_StartOpenReqs_0004 256 * @tc.desc: Test function of StartOpenReqs() interface for SUCCESS. 257 * @tc.size: MEDIUM 258 * @tc.type: FUNC 259 * @tc.level Level 1 260 */ 261 HWTEST_F(HyperAioTest, HyperAio_StartOpenReqs_0004, testing::ext::TestSize.Level1) 262 { 263 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartOpenReqs_0004"; 264 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 265 int32_t result = hyperAio_->CtxInit(&callBack); 266 EXPECT_EQ(result, 0); 267 auto openInfos = std::make_unique<OpenInfo[]>(Threshold); 268 for (int i = 0; i < Threshold; ++i) { 269 openInfos[i].dfd = 0; 270 openInfos[i].flags = O_RDWR; 271 openInfos[i].mode = 0; 272 openInfos[i].path = nullptr; 273 openInfos[i].userData = userData + i; 274 } 275 OpenReqs openReqs = {Threshold, openInfos.get()}; 276 result = hyperAio_->StartOpenReqs(&openReqs); 277 EXPECT_EQ(result, -EINVAL); 278 result = hyperAio_->DestroyCtx(); 279 EXPECT_EQ(result, 0); 280 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartOpenReqs_0004"; 281 } 282 283 /** 284 * @tc.name: HyperAio_StartOpenReqs_0005 285 * @tc.desc: Test function of StartOpenReqs() interface for SUCCESS. 286 * @tc.size: MEDIUM 287 * @tc.type: FUNC 288 * @tc.level Level 1 289 */ 290 HWTEST_F(HyperAioTest, HyperAio_StartOpenReqs_0005, testing::ext::TestSize.Level1) 291 { 292 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartOpenReqs_0005"; 293 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 294 int32_t result = hyperAio_->StartOpenReqs(nullptr); 295 EXPECT_EQ(result, -EINVAL); 296 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartOpenReqs_0005"; 297 } 298 299 /** 300 * @tc.name: HyperAio_StartReadReqs_0000 301 * @tc.desc: Test function of StartReadReqs() interface for SUCCESS. 302 * @tc.size: MEDIUM 303 * @tc.type: FUNC 304 * @tc.level Level 1 305 */ 306 HWTEST_F(HyperAioTest, HyperAio_StartReadReqs_0000, testing::ext::TestSize.Level1) 307 { 308 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartReadReqs_0000"; 309 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 310 int32_t result = hyperAio_->CtxInit(&callBack); 311 result = hyperAio_->StartReadReqs(nullptr); 312 EXPECT_EQ(result, -EINVAL); 313 result = hyperAio_->DestroyCtx(); 314 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0000"; 315 } 316 317 /** 318 * @tc.name: HyperAio_StartReadReqs_0001 319 * @tc.desc: Test function of StartReadReqs() interface for SUCCESS. 320 * @tc.size: MEDIUM 321 * @tc.type: FUNC 322 * @tc.level Level 1 323 */ 324 HWTEST_F(HyperAioTest, HyperAio_StartReadReqs_0001, testing::ext::TestSize.Level1) 325 { 326 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartReadReqs_0001"; 327 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 328 int32_t result = hyperAio_->CtxInit(&callBack); 329 EXPECT_EQ(result, 0); 330 hyperAio_->initialized_.store(false); 331 ReadInfo readInfo = {0, len, 0, nullptr, userData}; 332 ReadReqs readReqs = {1, &readInfo}; 333 result = hyperAio_->StartReadReqs(&readReqs); 334 EXPECT_EQ(result, -EPERM); 335 hyperAio_->initialized_.store(true); 336 result = hyperAio_->DestroyCtx(); 337 EXPECT_EQ(result, 0); 338 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0001"; 339 } 340 341 /** 342 * @tc.name: HyperAio_StartReadReqs_0002 343 * @tc.desc: Test function of StartReadReqs() interface for SUCCESS. 344 * @tc.size: MEDIUM 345 * @tc.type: FUNC 346 * @tc.level Level 1 347 */ 348 HWTEST_F(HyperAioTest, HyperAio_StartReadReqs_0002, testing::ext::TestSize.Level0) 349 { 350 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartReadReqs_0002"; 351 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 352 int32_t result = hyperAio_->CtxInit(&callBack); 353 ReadInfo readInfo = {0, len, 0, nullptr, userData}; 354 ReadReqs readReqs = {1, &readInfo}; 355 result = hyperAio_->StartReadReqs(&readReqs); 356 EXPECT_EQ(result, 0); 357 result = hyperAio_->DestroyCtx(); 358 EXPECT_EQ(result, 0); 359 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0002"; 360 } 361 362 /** 363 * @tc.name: HyperAio_StartReadReqs_0003 364 * @tc.desc: Test function of StartReadReqs() interface for SUCCESS. 365 * @tc.size: MEDIUM 366 * @tc.type: FUNC 367 * @tc.level Level 1 368 */ 369 HWTEST_F(HyperAioTest, HyperAio_StartReadReqs_0003, testing::ext::TestSize.Level1) 370 { 371 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartReadReqs_0003"; 372 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 373 int32_t result = hyperAio_->CtxInit(&callBack); 374 EXPECT_EQ(result, 0); 375 auto readInfos = std::make_unique<ReadInfo[]>(batchSize); 376 for (int i = 0; i < batchSize; ++i) { 377 readInfos[i].fd = 0; 378 readInfos[i].len = len; 379 readInfos[i].offset = 0; 380 readInfos[i].buf = nullptr; 381 readInfos[i].userData = userData + i; 382 } 383 ReadReqs readReqs = {batchSize, readInfos.get()}; 384 result = hyperAio_->StartReadReqs(&readReqs); 385 EXPECT_EQ(result, 0); 386 sqe_flag = false; 387 result = hyperAio_->StartReadReqs(&readReqs); 388 EXPECT_EQ(result, 0); 389 sqe_flag = true; 390 submit_flag = false; 391 result = hyperAio_->StartReadReqs(&readReqs); 392 EXPECT_EQ(result, 0); 393 submit_flag = true; 394 result = hyperAio_->DestroyCtx(); 395 EXPECT_EQ(result, 0); 396 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0003"; 397 } 398 399 /** 400 * @tc.name: HyperAio_StartReadReqs_0004 401 * @tc.desc: Test function of StartReadReqs() interface for SUCCESS. 402 * @tc.size: MEDIUM 403 * @tc.type: FUNC 404 * @tc.level Level 1 405 */ 406 HWTEST_F(HyperAioTest, HyperAio_StartReadReqs_0004, testing::ext::TestSize.Level1) 407 { 408 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartReadReqs_0004"; 409 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 410 int32_t result = hyperAio_->CtxInit(&callBack); 411 EXPECT_EQ(result, 0); 412 auto readInfos = std::make_unique<ReadInfo[]>(Threshold); 413 for (int i = 0; i < Threshold; ++i) { 414 readInfos[i].fd = 0; 415 readInfos[i].len = len; 416 readInfos[i].offset = 0; 417 readInfos[i].buf = nullptr; 418 readInfos[i].userData = userData + i; 419 } 420 ReadReqs readReqs = {Threshold, readInfos.get()}; 421 result = hyperAio_->StartReadReqs(&readReqs); 422 EXPECT_EQ(result, -EINVAL); 423 result = hyperAio_->DestroyCtx(); 424 EXPECT_EQ(result, 0); 425 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0004"; 426 } 427 428 /** 429 * @tc.name: HyperAio_StartReadReqs_0005 430 * @tc.desc: Test function of StartReadReqs() interface for SUCCESS. 431 * @tc.size: MEDIUM 432 * @tc.type: FUNC 433 * @tc.level Level 1 434 */ 435 HWTEST_F(HyperAioTest, HyperAio_StartReadReqs_0005, testing::ext::TestSize.Level1) 436 { 437 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartReadReqs_0005"; 438 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 439 int32_t result = hyperAio_->StartReadReqs(nullptr); 440 EXPECT_EQ(result, -EINVAL); 441 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0005"; 442 } 443 444 /** 445 * @tc.name: HyperAio_StartCancelReqs_0000 446 * @tc.desc: Test function of StartCancelReqs() interface for SUCCESS. 447 * @tc.size: MEDIUM 448 * @tc.type: FUNC 449 * @tc.level Level 1 450 */ 451 HWTEST_F(HyperAioTest, HyperAio_StartCancelReqs_0000, testing::ext::TestSize.Level1) 452 { 453 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartCancelReqs_0000"; 454 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 455 int32_t result = hyperAio_->CtxInit(&callBack); 456 result = hyperAio_->StartCancelReqs(nullptr); 457 result = hyperAio_->DestroyCtx(); 458 EXPECT_EQ(result, 0); 459 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartCancelReqs_0000"; 460 } 461 462 /** 463 * @tc.name: HyperAio_StartCancelReqs_0001 464 * @tc.desc: Test function of StartCancelReqs() interface for SUCCESS. 465 * @tc.size: MEDIUM 466 * @tc.type: FUNC 467 * @tc.level Level 1 468 */ 469 HWTEST_F(HyperAioTest, HyperAio_StartCancelReqs_0001, testing::ext::TestSize.Level1) 470 { 471 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartCancelReqs_0001"; 472 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 473 int32_t result = hyperAio_->CtxInit(&callBack); 474 hyperAio_->initialized_.store(false); 475 CancelInfo cancelInfo = {userData, 0}; 476 CancelReqs cancelReqs = {1, &cancelInfo}; 477 result = hyperAio_->StartCancelReqs(&cancelReqs); 478 EXPECT_EQ(result, -EPERM); 479 hyperAio_->initialized_.store(true); 480 result = hyperAio_->DestroyCtx(); 481 EXPECT_EQ(result, 0); 482 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartCancelReqs_0001"; 483 } 484 485 /** 486 * @tc.name: HyperAio_StartCancelReqs_0002 487 * @tc.desc: Test function of StartCancelReqs() interface for SUCCESS. 488 * @tc.size: MEDIUM 489 * @tc.type: FUNC 490 * @tc.level Level 1 491 */ 492 HWTEST_F(HyperAioTest, HyperAio_StartCancelReqs_0002, testing::ext::TestSize.Level0) 493 { 494 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartCancelReqs_0002"; 495 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 496 int32_t result = hyperAio_->CtxInit(&callBack); 497 CancelInfo cancelInfo = {userData, 0}; 498 CancelReqs cancelReqs = {1, &cancelInfo}; 499 result = hyperAio_->StartCancelReqs(&cancelReqs); 500 EXPECT_EQ(result, 0); 501 result = hyperAio_->DestroyCtx(); 502 EXPECT_EQ(result, 0); 503 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartCancelReqs_0002"; 504 } 505 506 /** 507 * @tc.name: HyperAio_StartCancelReqs_0003 508 * @tc.desc: Test function of StartCancelReqs() interface for SUCCESS. 509 * @tc.size: MEDIUM 510 * @tc.type: FUNC 511 * @tc.level Level 1 512 */ 513 HWTEST_F(HyperAioTest, HyperAio_StartCancelReqs_0003, testing::ext::TestSize.Level1) 514 { 515 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartCancelReqs_0003"; 516 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 517 int32_t result = hyperAio_->CtxInit(&callBack); 518 EXPECT_EQ(result, 0); 519 auto cancelInfos = std::make_unique<CancelInfo[]>(batchSize); 520 for (int i = 0; i < batchSize; ++i) { 521 cancelInfos[i].userData = userData + i; 522 cancelInfos[i].targetUserData = userData + i; 523 } 524 CancelReqs cancelReqs = {batchSize, cancelInfos.get()}; 525 result = hyperAio_->StartCancelReqs(&cancelReqs); 526 EXPECT_EQ(result, 0); 527 sqe_flag = false; 528 result = hyperAio_->StartCancelReqs(&cancelReqs); 529 EXPECT_EQ(result, 0); 530 sqe_flag = true; 531 submit_flag = false; 532 result = hyperAio_->StartCancelReqs(&cancelReqs); 533 EXPECT_EQ(result, 0); 534 submit_flag = true; 535 result = hyperAio_->DestroyCtx(); 536 EXPECT_EQ(result, 0); 537 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartCancelReqs_0003"; 538 } 539 540 /** 541 * @tc.name: HyperAio_StartCancelReqs_0004 542 * @tc.desc: Test function of StartCancelReqs() interface for SUCCESS. 543 * @tc.size: MEDIUM 544 * @tc.type: FUNC 545 * @tc.level Level 1 546 */ 547 HWTEST_F(HyperAioTest, HyperAio_StartCancelReqs_0004, testing::ext::TestSize.Level1) 548 { 549 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartCancelReqs_0004"; 550 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 551 int32_t result = hyperAio_->CtxInit(&callBack); 552 EXPECT_EQ(result, 0); 553 auto cancelInfos = std::make_unique<CancelInfo[]>(Threshold); 554 for (int i = 0; i < Threshold; ++i) { 555 cancelInfos[i].userData = userData + i; 556 cancelInfos[i].targetUserData = userData + i; 557 } 558 CancelReqs cancelReqs = {Threshold, cancelInfos.get()}; 559 result = hyperAio_->StartCancelReqs(&cancelReqs); 560 EXPECT_EQ(result, -EINVAL); 561 result = hyperAio_->DestroyCtx(); 562 EXPECT_EQ(result, 0); 563 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartCancelReqs_0004"; 564 } 565 566 /** 567 * @tc.name: HyperAio_StartCancelReqs_0005 568 * @tc.desc: Test function of StartCancelReqs() interface for SUCCESS. 569 * @tc.size: MEDIUM 570 * @tc.type: FUNC 571 * @tc.level Level 1 572 */ 573 HWTEST_F(HyperAioTest, HyperAio_StartCancelReqs_0005, testing::ext::TestSize.Level1) 574 { 575 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartCancelReqs_0005"; 576 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 577 int32_t result = hyperAio_->StartCancelReqs(nullptr); 578 EXPECT_EQ(result, -EINVAL); 579 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartCancelReqs_0005"; 580 } 581 582 /** 583 * @tc.name: HyperAio_HarvestRes_0000 584 * @tc.desc: Test function of HarvestRes() interface for SUCCESS. 585 * @tc.size: MEDIUM 586 * @tc.type: FUNC 587 * @tc.level Level 1 588 */ 589 HWTEST_F(HyperAioTest, HyperAio_HarvestRes_0000, testing::ext::TestSize.Level1) 590 { 591 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_HarvestRes_0000"; 592 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 593 int32_t result = hyperAio_->CtxInit(&callBack); 594 EXPECT_EQ(result, 0); 595 wait_flag = false; 596 hyperAio_->pImpl_ = nullptr; 597 result = hyperAio_->DestroyCtx(); 598 EXPECT_EQ(result, 0); 599 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_HarvestRes_0000"; 600 } 601 602 /** 603 * @tc.name: HyperAio_HarvestRes_0001 604 * @tc.desc: Test function of HarvestRes() interface for SUCCESS. 605 * @tc.size: MEDIUM 606 * @tc.type: FUNC 607 * @tc.level Level 1 608 */ 609 HWTEST_F(HyperAioTest, HyperAio_HarvestRes_0001, testing::ext::TestSize.Level1) 610 { 611 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_HarvestRes_0001"; 612 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 613 int32_t result = hyperAio_->CtxInit(&callBack); 614 EXPECT_EQ(result, 0); 615 cqe_res_flag = false; 616 std::this_thread::sleep_for(std::chrono::seconds(2)); 617 result = hyperAio_->DestroyCtx(); 618 EXPECT_EQ(result, 0); 619 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_HarvestRes_0001"; 620 } 621 622 /** 623 * @tc.name: HyperAio_DestroyCtx_0000 624 * @tc.desc: Test function of DestroyCtx() interface for SUCCESS. 625 * @tc.size: MEDIUM 626 * @tc.type: FUNC 627 * @tc.level Level 1 628 */ 629 HWTEST_F(HyperAioTest, HyperAio_DestroyCtx_0000, testing::ext::TestSize.Level1) 630 { 631 GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_DestroyCtx_0000"; 632 std::unique_ptr<HyperAio> hyperAio_ = std::make_unique<HyperAio>(); 633 int32_t result = hyperAio_->DestroyCtx(); 634 EXPECT_EQ(result, 0); 635 GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_DestroyCtx_0000"; 636 } 637 #endif 638 } 639