1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved. 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 "plugin_service.h" 17 #include <gtest/gtest.h> 18 #include "common_types.pb.h" 19 #include "plugin_command_builder.h" 20 #include "plugin_service.ipc.h" 21 #include "plugin_service_impl.h" 22 #include "plugin_session_manager.h" 23 #include "profiler_data_repeater.h" 24 #include "profiler_service_types.pb.h" 25 #include "socket_context.h" 26 27 using namespace testing::ext; 28 29 namespace { 30 constexpr uint32_t BUFFER_SIZE = 4096; 31 constexpr size_t QUEUE_MAX_SIZE = 4096; 32 constexpr uint32_t SAMPLE_INTERVAL = 20; 33 constexpr uint32_t START_WAIT = 2000000; 34 constexpr uint32_t END_WAIT = 1000000; 35 36 class PluginClientTest final : public IPluginServiceClient { 37 public: OnGetCommandResponse(SocketContext & context,::GetCommandResponse & response)38 bool OnGetCommandResponse(SocketContext& context, ::GetCommandResponse& response) override 39 { 40 return true; 41 } 42 }; 43 44 class UnitTestPluginService : public testing::Test { 45 public: SetUpTestCase()46 static void SetUpTestCase() {} TearDownTestCase()47 static void TearDownTestCase() {} 48 SetUp()49 void SetUp() 50 { 51 pluginService_ = std::make_shared<PluginService>(); 52 usleep(START_WAIT); // sleep for 2000000 us. 53 pluginClient_ = std::make_unique<PluginClientTest>(); 54 pluginServiceImp_ = std::make_unique<PluginServiceImpl>(*pluginService_); 55 commandBuilder_ = std::make_unique<PluginCommandBuilder>(); 56 pluginSessionMgr_ = std::make_shared<PluginSessionManager>(pluginService_); 57 pluginClient_->Connect(DEFAULT_UNIX_SOCKET_FULL_PATH); 58 pluginService_->SetPluginSessionManager(pluginSessionMgr_); 59 } 60 TearDown()61 void TearDown() 62 { 63 usleep(END_WAIT); 64 pluginService_ = nullptr; 65 } 66 67 public: 68 std::shared_ptr<PluginService> pluginService_ = nullptr; 69 std::unique_ptr<PluginClientTest> pluginClient_ = nullptr; 70 std::unique_ptr<PluginServiceImpl> pluginServiceImp_ = nullptr; 71 std::unique_ptr<PluginCommandBuilder> commandBuilder_ = nullptr; 72 std::shared_ptr<PluginSessionManager> pluginSessionMgr_ = nullptr; 73 uint32_t pluginId_; 74 }; 75 76 /** 77 * @tc.name: Service 78 * @tc.desc: Set plugin registration information. 79 * @tc.type: FUNC 80 */ 81 HWTEST_F(UnitTestPluginService, AddPluginInfo, TestSize.Level1) 82 { 83 RegisterPluginRequest request; 84 RegisterPluginResponse response; 85 PluginInfo plugin; 86 87 request.set_request_id(1); 88 request.set_path("abc.so"); 89 request.set_sha256("asdfasdfasdfasfd"); 90 request.set_name("abc.so"); 91 ASSERT_TRUE(response.status() != ResponseStatus::OK); 92 pluginId_ = response.plugin_id(); 93 94 plugin.name = "abc.so"; 95 plugin.bufferSizeHint = 0; 96 plugin.sha256 = ""; 97 ASSERT_TRUE(pluginService_->AddPluginInfo(plugin)); 98 } 99 100 /** 101 * @tc.name: Service 102 * @tc.desc: Set plugin configuration information. 103 * @tc.type: FUNC 104 */ 105 HWTEST_F(UnitTestPluginService, CreatePluginSession1, TestSize.Level1) 106 { 107 ProfilerPluginConfig ppc; 108 ppc.set_name("abc1.so"); 109 ppc.set_plugin_sha256("ASDFAADSF"); 110 ppc.set_sample_interval(SAMPLE_INTERVAL); 111 ASSERT_FALSE(pluginService_->CreatePluginSession(ppc, 112 std::make_shared<ProfilerDataRepeater<ProfilerPluginData>>(QUEUE_MAX_SIZE), 113 std::make_shared<ProfilerDataRepeater<ProfilerPluginState>>(QUEUE_MAX_SIZE))); 114 PluginInfo plugin; 115 plugin.name = "abc1.so"; 116 plugin.bufferSizeHint = 0; 117 plugin.sha256 = "ASDFAADSF"; 118 plugin.context = (SocketContext*)pluginClient_->unixSocketClient_.get(); 119 EXPECT_TRUE(pluginService_->AddPluginInfo(plugin)); 120 } 121 122 /** 123 * @tc.name: Service 124 * @tc.desc: Stop plugin session. 125 * @tc.type: FUNC 126 */ 127 HWTEST_F(UnitTestPluginService, StopPluginSession, TestSize.Level1) 128 { 129 ASSERT_FALSE(pluginService_->StopPluginSession("abc.so")); 130 PluginInfo plugin; 131 SocketContext ctx; 132 plugin.name = "abc4.so"; 133 plugin.bufferSizeHint = 0; 134 plugin.sha256 = "ASDFAADSF"; 135 plugin.context = &ctx; 136 pluginService_->AddPluginInfo(plugin); 137 EXPECT_FALSE(pluginService_->StopPluginSession("abc4.so")); 138 } 139 140 /** 141 * @tc.name: Service 142 * @tc.desc: GetPluginInfo test. 143 * @tc.type: FUNC 144 */ 145 HWTEST_F(UnitTestPluginService, GetPluginInfo, TestSize.Level1) 146 { 147 PluginInfo plugin; 148 EXPECT_FALSE(pluginService_->GetPluginInfo("edf.so", plugin)); 149 SocketContext ctx; 150 plugin.name = "abc7.so"; 151 plugin.bufferSizeHint = 0; 152 plugin.sha256 = "ASDFAADSF"; 153 plugin.context = &ctx; 154 pluginService_->AddPluginInfo(plugin); 155 EXPECT_TRUE(pluginService_->GetPluginInfo("abc7.so", plugin)); 156 } 157 158 /** 159 * @tc.name: Service 160 * @tc.desc: RemovePluginSessionCtx test. 161 * @tc.type: FUNC 162 */ 163 HWTEST_F(UnitTestPluginService, RemovePluginSessionCtx, TestSize.Level1) 164 { 165 PluginInfo plugin; 166 SocketContext ctx; 167 plugin.name = "abc8.so"; 168 plugin.bufferSizeHint = 0; 169 plugin.sha256 = "ASDFAADSF"; 170 plugin.context = &ctx; 171 pluginService_->AddPluginInfo(plugin); 172 EXPECT_TRUE(pluginService_->RemovePluginSessionCtx("abc8.so")); 173 } 174 175 /** 176 * @tc.name: Service 177 * @tc.desc: Remove the specified plugin. 178 * @tc.type: FUNC 179 */ 180 HWTEST_F(UnitTestPluginService, RemovePluginInfo, TestSize.Level1) 181 { 182 UnregisterPluginRequest request; 183 PluginInfo pi; 184 pi.id = 0; 185 pi.name = "abc9.so"; 186 pi.path = "abc9.so"; 187 pi.sha256 = "asdfasdf"; 188 ASSERT_FALSE(pluginService_->RemovePluginInfo(pi)); 189 pluginService_->AddPluginInfo(pi); 190 pi.id = pluginService_->GetPluginIdByName("abc9.so"); 191 EXPECT_TRUE(pluginService_->RemovePluginInfo(pi)); 192 } 193 194 /** 195 * @tc.name: Service 196 * @tc.desc: Setting report results. 197 * @tc.type: FUNC 198 */ 199 HWTEST_F(UnitTestPluginService, AppendResult, TestSize.Level1) 200 { 201 NotifyResultRequest nrr; 202 nrr.set_request_id(1); 203 nrr.set_command_id(1); 204 ASSERT_TRUE(pluginService_->AppendResult(nrr)); 205 } 206 207 /** 208 * @tc.name: Service 209 * @tc.desc: Get plugin status. 210 * @tc.type: FUNC 211 */ 212 HWTEST_F(UnitTestPluginService, GetPluginStatus, TestSize.Level1) 213 { 214 auto status = pluginService_->GetPluginStatus(); 215 ASSERT_TRUE(status.size() == 0); 216 } 217 218 /** 219 * @tc.name: Service 220 * @tc.desc: Gets the plugin with the specified name. 221 * @tc.type: FUNC 222 */ 223 HWTEST_F(UnitTestPluginService, GetPluginIdByName, TestSize.Level1) 224 { 225 ASSERT_TRUE(pluginService_->GetPluginIdByName("abc.so") == 0); 226 } 227 228 /** 229 * @tc.name: Service 230 * @tc.desc: Set plugin registration information. 231 * @tc.type: FUNC 232 */ 233 HWTEST_F(UnitTestPluginService, AddPluginInfo2, TestSize.Level1) 234 { 235 RegisterPluginRequest request; 236 RegisterPluginResponse response; 237 PluginInfo plugin; 238 239 request.set_request_id(2); 240 request.set_path("mem.so"); 241 request.set_sha256("asdfasdfasdfasfd"); 242 request.set_name("mem.so"); 243 ASSERT_TRUE(response.status() != ResponseStatus::OK); 244 pluginId_ = response.plugin_id(); 245 246 plugin.name = "mem.so"; 247 plugin.bufferSizeHint = 0; 248 plugin.sha256 = ""; 249 EXPECT_TRUE(pluginService_->AddPluginInfo(plugin)); 250 } 251 252 /** 253 * @tc.name: Service 254 * @tc.desc: Set plugin configuration information. 255 * @tc.type: FUNC 256 */ 257 HWTEST_F(UnitTestPluginService, CreatePluginSession12, TestSize.Level1) 258 { 259 ProfilerPluginConfig ppc; 260 ppc.set_name("mem.so"); 261 ppc.set_plugin_sha256("ASDFAADSF"); 262 ppc.set_sample_interval(SAMPLE_INTERVAL); 263 264 ASSERT_FALSE(pluginService_->CreatePluginSession(ppc, 265 std::make_shared<ProfilerDataRepeater<ProfilerPluginData>>(QUEUE_MAX_SIZE), 266 std::make_shared<ProfilerDataRepeater<ProfilerPluginState>>(QUEUE_MAX_SIZE))); 267 } 268 269 /** 270 * @tc.name: Service 271 * @tc.desc: Set session configuration. 272 * @tc.type: FUNC 273 */ 274 HWTEST_F(UnitTestPluginService, CreatePluginSession22, TestSize.Level1) 275 { 276 ProfilerPluginConfig ppc; 277 ppc.set_name("mem.so"); 278 ppc.set_plugin_sha256("ASDFAADSF"); 279 ppc.set_sample_interval(SAMPLE_INTERVAL); 280 281 ProfilerSessionConfig::BufferConfig bc; 282 bc.set_pages(1); 283 bc.set_policy(ProfilerSessionConfig_BufferConfig_Policy_RECYCLE); 284 285 ASSERT_FALSE(pluginService_->CreatePluginSession(ppc, bc, 286 std::make_shared<ProfilerDataRepeater<ProfilerPluginData>>(QUEUE_MAX_SIZE), 287 std::make_shared<ProfilerDataRepeater<ProfilerPluginState>>(QUEUE_MAX_SIZE))); 288 } 289 290 /** 291 * @tc.name: Service 292 * @tc.desc: Start plugin session. 293 * @tc.type: FUNC 294 */ 295 HWTEST_F(UnitTestPluginService, StartPluginSession2, TestSize.Level1) 296 { 297 ProfilerPluginConfig ppc; 298 ppc.set_name("mem.so"); 299 ppc.set_plugin_sha256("ASDFAADSF"); 300 ppc.set_sample_interval(SAMPLE_INTERVAL); 301 302 ASSERT_FALSE(pluginService_->StartPluginSession(ppc)); 303 } 304 305 /** 306 * @tc.name: Service 307 * @tc.desc: Stop plugin session. 308 * @tc.type: FUNC 309 */ 310 HWTEST_F(UnitTestPluginService, StopPluginSession2, TestSize.Level1) 311 { 312 ASSERT_FALSE(pluginService_->StopPluginSession("mem.so")); 313 } 314 315 /** 316 * @tc.name: Service 317 * @tc.desc: Destroy receiving test. 318 * @tc.type: FUNC 319 */ 320 HWTEST_F(UnitTestPluginService, DestroyPluginSession2, TestSize.Level1) 321 { 322 ASSERT_FALSE(pluginService_->DestroyPluginSession("mem.so")); 323 } 324 325 /** 326 * @tc.name: Service 327 * @tc.desc: Remove the specified plugin. 328 * @tc.type: FUNC 329 */ 330 HWTEST_F(UnitTestPluginService, RemovePluginInfo2, TestSize.Level1) 331 { 332 UnregisterPluginRequest request; 333 PluginInfo pi; 334 pi.id = 0; 335 pi.name = "mem.so"; 336 pi.path = "mem.so"; 337 pi.sha256 = "asdfasdf"; 338 ASSERT_FALSE(pluginService_->RemovePluginInfo(pi)); 339 } 340 341 /** 342 * @tc.name: Service 343 * @tc.desc: Setting report results. 344 * @tc.type: FUNC 345 */ 346 HWTEST_F(UnitTestPluginService, AppendResult2, TestSize.Level1) 347 { 348 NotifyResultRequest nrr; 349 nrr.set_request_id(2); 350 nrr.set_command_id(2); 351 ASSERT_TRUE(pluginService_->AppendResult(nrr)); 352 } 353 354 /** 355 * @tc.name: Service 356 * @tc.desc: Get plugin status. 357 * @tc.type: FUNC 358 */ 359 HWTEST_F(UnitTestPluginService, GetPluginStatus2, TestSize.Level1) 360 { 361 auto status = pluginService_->GetPluginStatus(); 362 ASSERT_TRUE(status.size() == 0); 363 } 364 365 /** 366 * @tc.name: Service 367 * @tc.desc: Gets the plugin with the specified name. 368 * @tc.type: FUNC 369 */ 370 HWTEST_F(UnitTestPluginService, GetPluginIdByName2, TestSize.Level1) 371 { 372 ASSERT_TRUE(pluginService_->GetPluginIdByName("mem.so") == 0); 373 } 374 375 /** 376 * @tc.name: Service 377 * @tc.desc: Set plugin registration information. 378 * @tc.type: FUNC 379 */ 380 HWTEST_F(UnitTestPluginService, AddPluginInfo3, TestSize.Level1) 381 { 382 RegisterPluginRequest request; 383 RegisterPluginResponse response; 384 PluginInfo plugin; 385 386 request.set_request_id(3); 387 request.set_path("cpu.so"); 388 request.set_sha256("asdfasdfasdfasfd"); 389 request.set_name("cpu.so"); 390 ASSERT_TRUE(response.status() != ResponseStatus::OK); 391 pluginId_ = response.plugin_id(); 392 393 plugin.name = "cpu.so"; 394 plugin.bufferSizeHint = 0; 395 plugin.sha256 = ""; 396 EXPECT_TRUE(pluginService_->AddPluginInfo(plugin)); 397 } 398 399 /** 400 * @tc.name: Service 401 * @tc.desc: Set plugin configuration information. 402 * @tc.type: FUNC 403 */ 404 HWTEST_F(UnitTestPluginService, CreatePluginSession13, TestSize.Level1) 405 { 406 ProfilerPluginConfig ppc; 407 ppc.set_name("cpu.so"); 408 ppc.set_plugin_sha256("ASDFAADSF"); 409 ppc.set_sample_interval(SAMPLE_INTERVAL); 410 411 ASSERT_FALSE(pluginService_->CreatePluginSession(ppc, 412 std::make_shared<ProfilerDataRepeater<ProfilerPluginData>>(QUEUE_MAX_SIZE), 413 std::make_shared<ProfilerDataRepeater<ProfilerPluginState>>(QUEUE_MAX_SIZE))); 414 } 415 416 /** 417 * @tc.name: Service 418 * @tc.desc: Set session configuration. 419 * @tc.type: FUNC 420 */ 421 HWTEST_F(UnitTestPluginService, CreatePluginSession23, TestSize.Level1) 422 { 423 ProfilerPluginConfig ppc; 424 ppc.set_name("cpu.so"); 425 ppc.set_plugin_sha256("ASDFAADSF"); 426 ppc.set_sample_interval(SAMPLE_INTERVAL); 427 428 ProfilerSessionConfig::BufferConfig bc; 429 bc.set_pages(1); 430 bc.set_policy(ProfilerSessionConfig_BufferConfig_Policy_RECYCLE); 431 432 ASSERT_FALSE(pluginService_->CreatePluginSession(ppc, bc, 433 std::make_shared<ProfilerDataRepeater<ProfilerPluginData>>(QUEUE_MAX_SIZE), 434 std::make_shared<ProfilerDataRepeater<ProfilerPluginState>>(QUEUE_MAX_SIZE))); 435 } 436 437 /** 438 * @tc.name: Service 439 * @tc.desc: Start plugin session. 440 * @tc.type: FUNC 441 */ 442 HWTEST_F(UnitTestPluginService, StartPluginSession3, TestSize.Level1) 443 { 444 ProfilerPluginConfig ppc; 445 ppc.set_name("cpu.so"); 446 ppc.set_plugin_sha256("ASDFAADSF"); 447 ppc.set_sample_interval(SAMPLE_INTERVAL); 448 449 ASSERT_FALSE(pluginService_->StartPluginSession(ppc)); 450 } 451 452 /** 453 * @tc.name: Service 454 * @tc.desc: Stop plugin session. 455 * @tc.type: FUNC 456 */ 457 HWTEST_F(UnitTestPluginService, StopPluginSession3, TestSize.Level1) 458 { 459 ASSERT_FALSE(pluginService_->StopPluginSession("cpu.so")); 460 } 461 462 /** 463 * @tc.name: Service 464 * @tc.desc: Destroy receiving test. 465 * @tc.type: FUNC 466 */ 467 HWTEST_F(UnitTestPluginService, DestroyPluginSession3, TestSize.Level1) 468 { 469 ASSERT_FALSE(pluginService_->DestroyPluginSession("cpu.so")); 470 } 471 472 /** 473 * @tc.name: Service 474 * @tc.desc: Remove the specified plugin. 475 * @tc.type: FUNC 476 */ 477 HWTEST_F(UnitTestPluginService, RemovePluginInfo3, TestSize.Level1) 478 { 479 UnregisterPluginRequest request; 480 PluginInfo pi; 481 pi.id = 0; 482 pi.name = "cpu.so"; 483 pi.path = "cpu.so"; 484 pi.sha256 = "asdfasdf"; 485 ASSERT_FALSE(pluginService_->RemovePluginInfo(pi)); 486 } 487 488 /** 489 * @tc.name: Service 490 * @tc.desc: Setting report results. 491 * @tc.type: FUNC 492 */ 493 HWTEST_F(UnitTestPluginService, AppendResult3, TestSize.Level1) 494 { 495 NotifyResultRequest nrr; 496 nrr.set_request_id(3); 497 nrr.set_command_id(3); 498 ASSERT_TRUE(pluginService_->AppendResult(nrr)); 499 } 500 501 /** 502 * @tc.name: Service 503 * @tc.desc: Get plugin status. 504 * @tc.type: FUNC 505 */ 506 HWTEST_F(UnitTestPluginService, GetPluginStatus3, TestSize.Level1) 507 { 508 auto status = pluginService_->GetPluginStatus(); 509 ASSERT_TRUE(status.size() == 0); 510 } 511 512 /** 513 * @tc.name: Service 514 * @tc.desc: Gets the plugin with the specified name. 515 * @tc.type: FUNC 516 */ 517 HWTEST_F(UnitTestPluginService, GetPluginIdByName3, TestSize.Level1) 518 { 519 ASSERT_TRUE(pluginService_->GetPluginIdByName("cpu.so") == 0); 520 } 521 522 /** 523 * @tc.name: Service 524 * @tc.desc: Set plugin registration information. 525 * @tc.type: FUNC 526 */ 527 HWTEST_F(UnitTestPluginService, AddPluginInfo4, TestSize.Level1) 528 { 529 RegisterPluginRequest request; 530 RegisterPluginResponse response; 531 PluginInfo plugin; 532 533 request.set_request_id(4); 534 request.set_path("stream.so"); 535 request.set_sha256("asdfasdfasdfasfd"); 536 request.set_name("stream.so"); 537 ASSERT_TRUE(response.status() != ResponseStatus::OK); 538 pluginId_ = response.plugin_id(); 539 540 plugin.name = "stream.so"; 541 plugin.bufferSizeHint = 0; 542 plugin.sha256 = ""; 543 EXPECT_TRUE(pluginService_->AddPluginInfo(plugin)); 544 plugin.bufferSizeHint = 10; 545 plugin.isStandaloneFileData = true; 546 plugin.outFileName = "test-file.bin"; 547 plugin.pluginVersion = "1.02"; 548 EXPECT_TRUE(pluginService_->AddPluginInfo(plugin)); 549 } 550 551 /** 552 * @tc.name: Service 553 * @tc.desc: Set plugin configuration information. 554 * @tc.type: FUNC 555 */ 556 HWTEST_F(UnitTestPluginService, CreatePluginSession14, TestSize.Level1) 557 { 558 ProfilerPluginConfig ppc; 559 ppc.set_name("stream.so"); 560 ppc.set_plugin_sha256("ASDFAADSF"); 561 ppc.set_sample_interval(SAMPLE_INTERVAL); 562 563 ASSERT_FALSE(pluginService_->CreatePluginSession(ppc, 564 std::make_shared<ProfilerDataRepeater<ProfilerPluginData>>(QUEUE_MAX_SIZE), 565 std::make_shared<ProfilerDataRepeater<ProfilerPluginState>>(QUEUE_MAX_SIZE))); 566 } 567 568 /** 569 * @tc.name: Service 570 * @tc.desc: Set session configuration. 571 * @tc.type: FUNC 572 */ 573 HWTEST_F(UnitTestPluginService, CreatePluginSession24, TestSize.Level1) 574 { 575 ProfilerPluginConfig ppc; 576 ppc.set_name("stream.so"); 577 ppc.set_plugin_sha256("ASDFAADSF"); 578 ppc.set_sample_interval(SAMPLE_INTERVAL); 579 580 ProfilerSessionConfig::BufferConfig bc; 581 bc.set_pages(1); 582 bc.set_policy(ProfilerSessionConfig_BufferConfig_Policy_RECYCLE); 583 584 ASSERT_FALSE(pluginService_->CreatePluginSession(ppc, bc, 585 std::make_shared<ProfilerDataRepeater<ProfilerPluginData>>(QUEUE_MAX_SIZE), 586 std::make_shared<ProfilerDataRepeater<ProfilerPluginState>>(QUEUE_MAX_SIZE))); 587 } 588 589 /** 590 * @tc.name: Service 591 * @tc.desc: Start plugin session. 592 * @tc.type: FUNC 593 */ 594 HWTEST_F(UnitTestPluginService, StartPluginSession4, TestSize.Level1) 595 { 596 ProfilerPluginConfig ppc; 597 ppc.set_name("stream.so"); 598 ppc.set_plugin_sha256("ASDFAADSF"); 599 ppc.set_sample_interval(SAMPLE_INTERVAL); 600 601 ASSERT_FALSE(pluginService_->StartPluginSession(ppc)); 602 } 603 604 /** 605 * @tc.name: Service 606 * @tc.desc: Stop plugin session. 607 * @tc.type: FUNC 608 */ 609 HWTEST_F(UnitTestPluginService, StopPluginSession4, TestSize.Level1) 610 { 611 ASSERT_FALSE(pluginService_->StopPluginSession("stream.so")); 612 } 613 614 /** 615 * @tc.name: Service 616 * @tc.desc: Destroy receiving test. 617 * @tc.type: FUNC 618 */ 619 HWTEST_F(UnitTestPluginService, DestroyPluginSession4, TestSize.Level1) 620 { 621 ASSERT_FALSE(pluginService_->DestroyPluginSession("stream.so")); 622 } 623 624 /** 625 * @tc.name: Service 626 * @tc.desc: Remove the specified plugin. 627 * @tc.type: FUNC 628 */ 629 HWTEST_F(UnitTestPluginService, RemovePluginInfo4, TestSize.Level1) 630 { 631 UnregisterPluginRequest request; 632 PluginInfo pi; 633 pi.id = 0; 634 pi.name = "stream.so"; 635 pi.path = "stream.so"; 636 pi.sha256 = "asdfasdf"; 637 ASSERT_FALSE(pluginService_->RemovePluginInfo(pi)); 638 } 639 640 /** 641 * @tc.name: Service 642 * @tc.desc: Setting report results. 643 * @tc.type: FUNC 644 */ 645 HWTEST_F(UnitTestPluginService, AppendResult4, TestSize.Level1) 646 { 647 NotifyResultRequest nrr; 648 nrr.set_request_id(4); 649 nrr.set_command_id(4); 650 ASSERT_TRUE(pluginService_->AppendResult(nrr)); 651 } 652 653 /** 654 * @tc.name: Service 655 * @tc.desc: Get plugin status. 656 * @tc.type: FUNC 657 */ 658 HWTEST_F(UnitTestPluginService, GetPluginStatus4, TestSize.Level1) 659 { 660 auto status = pluginService_->GetPluginStatus(); 661 ASSERT_TRUE(status.size() == 0); 662 } 663 664 /** 665 * @tc.name: Service 666 * @tc.desc: Gets the plugin with the specified name. 667 * @tc.type: FUNC 668 */ 669 HWTEST_F(UnitTestPluginService, GetPluginIdByName4, TestSize.Level1) 670 { 671 ASSERT_TRUE(pluginService_->GetPluginIdByName("stream.so") == 0); 672 } 673 674 /** 675 * @tc.name: Service 676 * @tc.desc: Set plugin registration information. 677 * @tc.type: FUNC 678 */ 679 HWTEST_F(UnitTestPluginService, AddPluginInfo5, TestSize.Level1) 680 { 681 RegisterPluginRequest request; 682 RegisterPluginResponse response; 683 PluginInfo plugin; 684 685 request.set_request_id(5); 686 request.set_path("sample.so"); 687 request.set_sha256("asdfasdfasdfasfd"); 688 request.set_name("sample.so"); 689 ASSERT_TRUE(response.status() != ResponseStatus::OK); 690 pluginId_ = response.plugin_id(); 691 692 plugin.name = "sample.so"; 693 plugin.bufferSizeHint = 0; 694 plugin.sha256 = ""; 695 EXPECT_TRUE(pluginService_->AddPluginInfo(plugin)); 696 } 697 698 /** 699 * @tc.name: Service 700 * @tc.desc: Set plugin configuration information. 701 * @tc.type: FUNC 702 */ 703 HWTEST_F(UnitTestPluginService, CreatePluginSession15, TestSize.Level1) 704 { 705 ProfilerPluginConfig ppc; 706 ppc.set_name("sample.so"); 707 ppc.set_plugin_sha256("ASDFAADSF"); 708 ppc.set_sample_interval(SAMPLE_INTERVAL); 709 710 ASSERT_FALSE(pluginService_->CreatePluginSession(ppc, 711 std::make_shared<ProfilerDataRepeater<ProfilerPluginData>>(QUEUE_MAX_SIZE), 712 std::make_shared<ProfilerDataRepeater<ProfilerPluginState>>(QUEUE_MAX_SIZE))); 713 } 714 715 /** 716 * @tc.name: Service 717 * @tc.desc: Set session configuration. 718 * @tc.type: FUNC 719 */ 720 HWTEST_F(UnitTestPluginService, CreatePluginSession25, TestSize.Level1) 721 { 722 ProfilerPluginConfig ppc; 723 ppc.set_name("sample.so"); 724 ppc.set_plugin_sha256("ASDFAADSF"); 725 ppc.set_sample_interval(SAMPLE_INTERVAL); 726 727 ProfilerSessionConfig::BufferConfig bc; 728 bc.set_pages(1); 729 bc.set_policy(ProfilerSessionConfig_BufferConfig_Policy_RECYCLE); 730 731 ASSERT_FALSE(pluginService_->CreatePluginSession(ppc, bc, 732 std::make_shared<ProfilerDataRepeater<ProfilerPluginData>>(QUEUE_MAX_SIZE), 733 std::make_shared<ProfilerDataRepeater<ProfilerPluginState>>(QUEUE_MAX_SIZE))); 734 } 735 736 /** 737 * @tc.name: Service 738 * @tc.desc: Start plugin session. 739 * @tc.type: FUNC 740 */ 741 HWTEST_F(UnitTestPluginService, StartPluginSession5, TestSize.Level1) 742 { 743 ProfilerPluginConfig ppc; 744 ppc.set_name("sample.so"); 745 ppc.set_plugin_sha256("ASDFAADSF"); 746 ppc.set_sample_interval(SAMPLE_INTERVAL); 747 ASSERT_TRUE(pluginService_->StartEpollThread()); 748 ASSERT_FALSE(pluginService_->StartPluginSession(ppc)); 749 ASSERT_TRUE(pluginService_->StopEpollThread()); 750 } 751 752 /** 753 * @tc.name: Service 754 * @tc.desc: Stop plugin session. 755 * @tc.type: FUNC 756 */ 757 HWTEST_F(UnitTestPluginService, StopPluginSession5, TestSize.Level1) 758 { 759 ASSERT_FALSE(pluginService_->StopPluginSession("sample.so")); 760 } 761 762 /** 763 * @tc.name: Service 764 * @tc.desc: Destroy receiving test. 765 * @tc.type: FUNC 766 */ 767 HWTEST_F(UnitTestPluginService, DestroyPluginSession5, TestSize.Level1) 768 { 769 ASSERT_FALSE(pluginService_->DestroyPluginSession("sample.so")); 770 } 771 772 /** 773 * @tc.name: Service 774 * @tc.desc: Remove the specified plugin. 775 * @tc.type: FUNC 776 */ 777 HWTEST_F(UnitTestPluginService, RemovePluginInfo5, TestSize.Level1) 778 { 779 UnregisterPluginRequest request; 780 PluginInfo pi; 781 pi.id = 0; 782 pi.name = "sample.so"; 783 pi.path = "sample.so"; 784 pi.sha256 = "asdfasdf"; 785 ASSERT_FALSE(pluginService_->RemovePluginInfo(pi)); 786 } 787 788 /** 789 * @tc.name: Service 790 * @tc.desc: Setting report results. 791 * @tc.type: FUNC 792 */ 793 HWTEST_F(UnitTestPluginService, AppendResult5, TestSize.Level1) 794 { 795 NotifyResultRequest nrr; 796 nrr.set_request_id(5); 797 nrr.set_command_id(5); 798 ASSERT_TRUE(pluginService_->AppendResult(nrr)); 799 } 800 801 /** 802 * @tc.name: Service 803 * @tc.desc: Get plugin status. 804 * @tc.type: FUNC 805 */ 806 HWTEST_F(UnitTestPluginService, GetPluginStatus5, TestSize.Level1) 807 { 808 auto status = pluginService_->GetPluginStatus(); 809 ASSERT_TRUE(status.size() == 0); 810 } 811 812 /** 813 * @tc.name: Service 814 * @tc.desc: Gets the plugin with the specified name. 815 * @tc.type: FUNC 816 */ 817 HWTEST_F(UnitTestPluginService, GetPluginIdByName5, TestSize.Level1) 818 { 819 ASSERT_TRUE(pluginService_->GetPluginIdByName("sample.so") == 0); 820 } 821 822 /** 823 * @tc.name: Service 824 * @tc.desc: test function RegisterPlugin. 825 * @tc.type: FUNC 826 */ 827 HWTEST_F(UnitTestPluginService, PluginServiceImpl_RegisterPlugin, TestSize.Level1) 828 { 829 RegisterPluginRequest request; 830 RegisterPluginResponse response; 831 SocketContext ctx; 832 833 request.set_request_id(5); 834 request.set_path("sample2.so"); 835 request.set_sha256(""); 836 request.set_name("sample2.so"); 837 request.set_buffer_size_hint(0); 838 EXPECT_TRUE(pluginServiceImp_->RegisterPlugin(ctx, request, response)); 839 request.set_sha256("abcdsfdsfad"); 840 EXPECT_FALSE(pluginServiceImp_->RegisterPlugin(ctx, request, response)); 841 UnregisterPluginRequest unRequest; 842 UnregisterPluginResponse unResponse; 843 uint32_t plugId = pluginService_->GetPluginIdByName("sample2.so"); 844 unRequest.set_plugin_id(plugId); 845 EXPECT_TRUE(pluginServiceImp_->UnregisterPlugin(ctx, unRequest, unResponse)); 846 } 847 848 /** 849 * @tc.name: Service 850 * @tc.desc: test function UnregisterPlugin 851 * @tc.type: FUNC 852 */ 853 HWTEST_F(UnitTestPluginService, PluginServiceImpl_UnregisterPlugin, TestSize.Level1) 854 { 855 UnregisterPluginRequest request; 856 UnregisterPluginResponse response; 857 SocketContext ctx; 858 request.set_plugin_id(1); 859 EXPECT_FALSE(pluginServiceImp_->UnregisterPlugin(ctx, request, response)); 860 861 GetCommandRequest gcRequest; 862 GetCommandResponse gcResponse; 863 EXPECT_FALSE(pluginServiceImp_->GetCommand(ctx, gcRequest, gcResponse)); 864 865 NotifyResultRequest nResRequest; 866 NotifyResultResponse nResResponse; 867 EXPECT_TRUE(pluginServiceImp_->NotifyResult(ctx, nResRequest, nResResponse)); 868 } 869 /** 870 * @tc.name: BuildCreateSessionCmd 871 * @tc.desc: build create session command 872 * @tc.type: FUNC 873 */ 874 HWTEST_F(UnitTestPluginService, pluginCommandBuilder, TestSize.Level1) 875 { 876 ProfilerPluginConfig ppc; 877 ppc.set_name("abc.so"); 878 ppc.set_plugin_sha256("ASDFAADSF"); 879 ppc.set_sample_interval(SAMPLE_INTERVAL); 880 const uint32_t pluginId = 1; 881 EXPECT_TRUE(commandBuilder_->BuildCreateSessionCmd(ppc, BUFFER_SIZE) != nullptr); 882 EXPECT_TRUE(commandBuilder_->BuildStartSessionCmd(ppc, pluginId) != nullptr); 883 EXPECT_TRUE(commandBuilder_->BuildRefreshSessionCmd(pluginId) != nullptr); 884 EXPECT_TRUE(commandBuilder_->BuildStopSessionCmd(pluginId) != nullptr); 885 EXPECT_TRUE(commandBuilder_->BuildDestroySessionCmd(pluginId) != nullptr); 886 EXPECT_FALSE(commandBuilder_->GetedCommandResponse(0)); 887 EXPECT_TRUE(commandBuilder_->GetedCommandResponse(1)); 888 } 889 890 /** 891 * @tc.name: PluginSessionManager 892 * @tc.desc: test plugin session manager checkBufferConfig 893 * @tc.type: FUNC 894 */ 895 HWTEST_F(UnitTestPluginService, PluginSessionManager_Check, TestSize.Level1) 896 { 897 PluginInfo plugin; 898 SocketContext ctx; 899 plugin.name = "abc_check.so"; 900 plugin.bufferSizeHint = 0; 901 plugin.sha256 = "asdfasdfasdfasfd"; 902 plugin.context = &ctx; 903 EXPECT_TRUE(pluginService_->AddPluginInfo(plugin)); 904 ProfilerSessionConfig::BufferConfig bc; 905 bc.set_pages(1); 906 bc.set_policy(ProfilerSessionConfig_BufferConfig_Policy_RECYCLE); 907 EXPECT_TRUE(pluginSessionMgr_->CheckBufferConfig(bc)); 908 ProfilerPluginConfig ppc; 909 ppc.set_name("abc_check.so"); 910 ppc.set_plugin_sha256("asdfasdfasdfasfd"); 911 EXPECT_TRUE(pluginSessionMgr_->CheckPluginSha256(ppc)); 912 } 913 914 /** 915 * @tc.name: profilerSessionConfig 916 * @tc.desc: test profiler session config 917 * @tc.type: FUNC 918 */ 919 HWTEST_F(UnitTestPluginService, PluginService_SessionConfig, TestSize.Level1) 920 { 921 std::vector<std::string> pluginNames = {"abc.so", "mem.so"}; 922 std::shared_ptr<ProfilerSessionConfig> config = std::make_shared<ProfilerSessionConfig>(); 923 pluginService_->SetProfilerSessionConfig(config, pluginNames); 924 925 PluginInfo plugin; 926 SocketContext ctx; 927 plugin.name = "test_check.so"; 928 plugin.bufferSizeHint = 0; 929 plugin.sha256 = "asdfasdfasdfasfd"; 930 plugin.context = &ctx; 931 EXPECT_TRUE(pluginService_->AddPluginInfo(plugin)); 932 } 933 934 } // namespace