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:
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  */
HWTEST_F(UnitTestPluginService, AddPluginInfo, TestSize.Level1)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  */
HWTEST_F(UnitTestPluginService, CreatePluginSession1, TestSize.Level1)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, std::make_shared<ProfilerDataRepeater>(QUEUE_MAX_SIZE)));
112     PluginInfo plugin;
113     plugin.name = "abc1.so";
114     plugin.bufferSizeHint = 0;
115     plugin.sha256 = "ASDFAADSF";
116     plugin.context = (SocketContext*)pluginClient_->unixSocketClient_.get();
117     EXPECT_TRUE(pluginService_->AddPluginInfo(plugin));
118 }
119 
120 /**
121  * @tc.name: Service
122  * @tc.desc: Set session configuration.
123  * @tc.type: FUNC
124  */
HWTEST_F(UnitTestPluginService, CreatePluginSession2, TestSize.Level1)125 HWTEST_F(UnitTestPluginService, CreatePluginSession2, TestSize.Level1)
126 {
127     ProfilerPluginConfig ppc;
128     ppc.set_name("abc2.so");
129     ppc.set_plugin_sha256("ASDFAADSF");
130     ppc.set_sample_interval(SAMPLE_INTERVAL);
131     ProfilerSessionConfig::BufferConfig bc;
132     bc.set_pages(1);
133     bc.set_policy(ProfilerSessionConfig_BufferConfig_Policy_RECYCLE);
134     ASSERT_FALSE(pluginService_->CreatePluginSession(ppc, bc, std::make_shared<ProfilerDataRepeater>(QUEUE_MAX_SIZE)));
135     PluginInfo plugin;
136     plugin.name = "abc2.so";
137     plugin.bufferSizeHint = 0;
138     plugin.sha256 = "ASDFAADSF";
139     plugin.context = (SocketContext*)pluginClient_->unixSocketClient_.get();
140     pluginService_->AddPluginInfo(plugin);
141     ProfilerSessionConfig psc;
142     psc.set_session_mode(ProfilerSessionConfig::OFFLINE);
143     std::vector<string> names = {"abc2.so"};
144     pluginService_->SetProfilerSessionConfig(std::make_shared<ProfilerSessionConfig>(psc), names);
145     TraceFileWriterPtr traceWriter = std::make_shared<TraceFileWriter>("/data/local/tmp/tracewrite.trace");
146     pluginService_->SetTraceWriter(traceWriter);
147     EXPECT_TRUE(pluginService_->CreatePluginSession(ppc, bc, std::make_shared<ProfilerDataRepeater>(QUEUE_MAX_SIZE)));
148     uint32_t pluginId = pluginService_->GetPluginIdByName("abc2.so");
149     PluginContextPtr pluginCtx = pluginService_->GetPluginContextById(pluginId);
150     pluginService_->ReadShareMemoryOffline(*pluginCtx);
151     EXPECT_TRUE(pluginService_->DestroyPluginSession("abc2.so"));
152     EXPECT_TRUE(pluginService_->RemovePluginSessionCtx("abc2.so"));
153     pluginService_->RemovePluginInfo(plugin);
154 }
155 
156 /**
157  * @tc.name: Service
158  * @tc.desc: Start plugin session.
159  * @tc.type: FUNC
160  */
HWTEST_F(UnitTestPluginService, StartPluginSession, TestSize.Level1)161 HWTEST_F(UnitTestPluginService, StartPluginSession, TestSize.Level1)
162 {
163     ProfilerPluginConfig ppc;
164     ppc.set_name("abc3.so");
165     ppc.set_plugin_sha256("ASDFAADSF");
166     ppc.set_sample_interval(SAMPLE_INTERVAL);
167     ASSERT_FALSE(pluginService_->StartPluginSession(ppc));
168     PluginInfo plugin;
169     plugin.name = "abc3.so";
170     plugin.bufferSizeHint = 0;
171     plugin.sha256 = "ASDFAADSF";
172     plugin.context = (SocketContext*)pluginClient_->unixSocketClient_.get();
173     pluginService_->AddPluginInfo(plugin);
174     EXPECT_TRUE(pluginService_->StartPluginSession(ppc));
175 }
176 
177 /**
178  * @tc.name: Service
179  * @tc.desc: Stop plugin session.
180  * @tc.type: FUNC
181  */
HWTEST_F(UnitTestPluginService, StopPluginSession, TestSize.Level1)182 HWTEST_F(UnitTestPluginService, StopPluginSession, TestSize.Level1)
183 {
184     ASSERT_FALSE(pluginService_->StopPluginSession("abc.so"));
185     PluginInfo plugin;
186     SocketContext ctx;
187     plugin.name = "abc4.so";
188     plugin.bufferSizeHint = 0;
189     plugin.sha256 = "ASDFAADSF";
190     plugin.context = &ctx;
191     pluginService_->AddPluginInfo(plugin);
192     EXPECT_FALSE(pluginService_->StopPluginSession("abc4.so"));
193 }
194 
195 /**
196  * @tc.name: Service
197  * @tc.desc: Destroy receiving test.
198  * @tc.type: FUNC
199  */
HWTEST_F(UnitTestPluginService, DestroyPluginSession, TestSize.Level1)200 HWTEST_F(UnitTestPluginService, DestroyPluginSession, TestSize.Level1)
201 {
202     ASSERT_FALSE(pluginService_->DestroyPluginSession("abc.so"));
203     PluginInfo plugin;
204     plugin.name = "abc5.so";
205     plugin.bufferSizeHint = 0;
206     plugin.sha256 = "ASDFAADSF";
207     plugin.context = (SocketContext*)pluginClient_->unixSocketClient_.get();
208     pluginService_->AddPluginInfo(plugin);
209     EXPECT_TRUE(pluginService_->DestroyPluginSession("abc5.so"));
210 }
211 /**
212  * @tc.name: Service
213  * @tc.desc: RefreshPluginSession  test.
214  * @tc.type: FUNC
215  */
HWTEST_F(UnitTestPluginService, RefreshPluginSession, TestSize.Level1)216 HWTEST_F(UnitTestPluginService, RefreshPluginSession, TestSize.Level1)
217 {
218     ASSERT_FALSE(pluginService_->RefreshPluginSession("abc.so"));
219     PluginInfo plugin;
220     SocketContext ctx;
221     plugin.name = "abc6.so";
222     plugin.bufferSizeHint = 0;
223     plugin.sha256 = "ASDFAADSF";
224     plugin.context = (SocketContext*)pluginClient_->unixSocketClient_.get();
225     pluginService_->AddPluginInfo(plugin);
226     EXPECT_TRUE(pluginService_->RefreshPluginSession("abc6.so"));
227 }
228 /**
229  * @tc.name: Service
230  * @tc.desc: GetPluginInfo  test.
231  * @tc.type: FUNC
232  */
HWTEST_F(UnitTestPluginService, GetPluginInfo, TestSize.Level1)233 HWTEST_F(UnitTestPluginService, GetPluginInfo, TestSize.Level1)
234 {
235     PluginInfo plugin;
236     EXPECT_FALSE(pluginService_->GetPluginInfo("edf.so", plugin));
237     SocketContext ctx;
238     plugin.name = "abc7.so";
239     plugin.bufferSizeHint = 0;
240     plugin.sha256 = "ASDFAADSF";
241     plugin.context = &ctx;
242     pluginService_->AddPluginInfo(plugin);
243     EXPECT_TRUE(pluginService_->GetPluginInfo("abc7.so", plugin));
244 }
245 
246 /**
247  * @tc.name: Service
248  * @tc.desc: RemovePluginSessionCtx  test.
249  * @tc.type: FUNC
250  */
HWTEST_F(UnitTestPluginService, RemovePluginSessionCtx, TestSize.Level1)251 HWTEST_F(UnitTestPluginService, RemovePluginSessionCtx, TestSize.Level1)
252 {
253     PluginInfo plugin;
254     SocketContext ctx;
255     plugin.name = "abc8.so";
256     plugin.bufferSizeHint = 0;
257     plugin.sha256 = "ASDFAADSF";
258     plugin.context = &ctx;
259     pluginService_->AddPluginInfo(plugin);
260     EXPECT_TRUE(pluginService_->RemovePluginSessionCtx("abc8.so"));
261 }
262 
263 /**
264  * @tc.name: Service
265  * @tc.desc: Remove the specified plugin.
266  * @tc.type: FUNC
267  */
HWTEST_F(UnitTestPluginService, RemovePluginInfo, TestSize.Level1)268 HWTEST_F(UnitTestPluginService, RemovePluginInfo, TestSize.Level1)
269 {
270     UnregisterPluginRequest request;
271     PluginInfo pi;
272     pi.id = 0;
273     pi.name = "abc9.so";
274     pi.path = "abc9.so";
275     pi.sha256 = "asdfasdf";
276     ASSERT_FALSE(pluginService_->RemovePluginInfo(pi));
277     pluginService_->AddPluginInfo(pi);
278     pi.id = pluginService_->GetPluginIdByName("abc9.so");
279     EXPECT_TRUE(pluginService_->RemovePluginInfo(pi));
280 }
281 
282 /**
283  * @tc.name: Service
284  * @tc.desc: Setting report results.
285  * @tc.type: FUNC
286  */
HWTEST_F(UnitTestPluginService, AppendResult, TestSize.Level1)287 HWTEST_F(UnitTestPluginService, AppendResult, TestSize.Level1)
288 {
289     NotifyResultRequest nrr;
290     nrr.set_request_id(1);
291     nrr.set_command_id(1);
292     ASSERT_TRUE(pluginService_->AppendResult(nrr));
293 }
294 
295 /**
296  * @tc.name: Service
297  * @tc.desc: Get plugin status.
298  * @tc.type: FUNC
299  */
HWTEST_F(UnitTestPluginService, GetPluginStatus, TestSize.Level1)300 HWTEST_F(UnitTestPluginService, GetPluginStatus, TestSize.Level1)
301 {
302     auto status = pluginService_->GetPluginStatus();
303     ASSERT_TRUE(status.size() == 0);
304 }
305 
306 /**
307  * @tc.name: Service
308  * @tc.desc: Gets the plugin with the specified name.
309  * @tc.type: FUNC
310  */
HWTEST_F(UnitTestPluginService, GetPluginIdByName, TestSize.Level1)311 HWTEST_F(UnitTestPluginService, GetPluginIdByName, TestSize.Level1)
312 {
313     ASSERT_TRUE(pluginService_->GetPluginIdByName("abc.so") == 0);
314 }
315 
316 /**
317  * @tc.name: Service
318  * @tc.desc: Set plugin registration information.
319  * @tc.type: FUNC
320  */
HWTEST_F(UnitTestPluginService, AddPluginInfo2, TestSize.Level1)321 HWTEST_F(UnitTestPluginService, AddPluginInfo2, TestSize.Level1)
322 {
323     RegisterPluginRequest request;
324     RegisterPluginResponse response;
325     PluginInfo plugin;
326 
327     request.set_request_id(2);
328     request.set_path("mem.so");
329     request.set_sha256("asdfasdfasdfasfd");
330     request.set_name("mem.so");
331     ASSERT_TRUE(response.status() != ResponseStatus::OK);
332     pluginId_ = response.plugin_id();
333 
334     plugin.name = "mem.so";
335     plugin.bufferSizeHint = 0;
336     plugin.sha256 = "";
337     EXPECT_TRUE(pluginService_->AddPluginInfo(plugin));
338 }
339 
340 /**
341  * @tc.name: Service
342  * @tc.desc: Set plugin configuration information.
343  * @tc.type: FUNC
344  */
HWTEST_F(UnitTestPluginService, CreatePluginSession12, TestSize.Level1)345 HWTEST_F(UnitTestPluginService, CreatePluginSession12, TestSize.Level1)
346 {
347     ProfilerPluginConfig ppc;
348     ppc.set_name("mem.so");
349     ppc.set_plugin_sha256("ASDFAADSF");
350     ppc.set_sample_interval(SAMPLE_INTERVAL);
351 
352     ASSERT_FALSE(pluginService_->CreatePluginSession(ppc, std::make_shared<ProfilerDataRepeater>(QUEUE_MAX_SIZE)));
353 }
354 
355 /**
356  * @tc.name: Service
357  * @tc.desc: Set session configuration.
358  * @tc.type: FUNC
359  */
HWTEST_F(UnitTestPluginService, CreatePluginSession22, TestSize.Level1)360 HWTEST_F(UnitTestPluginService, CreatePluginSession22, TestSize.Level1)
361 {
362     ProfilerPluginConfig ppc;
363     ppc.set_name("mem.so");
364     ppc.set_plugin_sha256("ASDFAADSF");
365     ppc.set_sample_interval(SAMPLE_INTERVAL);
366 
367     ProfilerSessionConfig::BufferConfig bc;
368     bc.set_pages(1);
369     bc.set_policy(ProfilerSessionConfig_BufferConfig_Policy_RECYCLE);
370 
371     ASSERT_FALSE(pluginService_->CreatePluginSession(ppc, bc, std::make_shared<ProfilerDataRepeater>(QUEUE_MAX_SIZE)));
372 }
373 
374 /**
375  * @tc.name: Service
376  * @tc.desc: Start plugin session.
377  * @tc.type: FUNC
378  */
HWTEST_F(UnitTestPluginService, StartPluginSession2, TestSize.Level1)379 HWTEST_F(UnitTestPluginService, StartPluginSession2, TestSize.Level1)
380 {
381     ProfilerPluginConfig ppc;
382     ppc.set_name("mem.so");
383     ppc.set_plugin_sha256("ASDFAADSF");
384     ppc.set_sample_interval(SAMPLE_INTERVAL);
385 
386     ASSERT_FALSE(pluginService_->StartPluginSession(ppc));
387 }
388 
389 /**
390  * @tc.name: Service
391  * @tc.desc: Stop plugin session.
392  * @tc.type: FUNC
393  */
HWTEST_F(UnitTestPluginService, StopPluginSession2, TestSize.Level1)394 HWTEST_F(UnitTestPluginService, StopPluginSession2, TestSize.Level1)
395 {
396     ASSERT_FALSE(pluginService_->StopPluginSession("mem.so"));
397 }
398 
399 /**
400  * @tc.name: Service
401  * @tc.desc: Destroy receiving test.
402  * @tc.type: FUNC
403  */
HWTEST_F(UnitTestPluginService, DestroyPluginSession2, TestSize.Level1)404 HWTEST_F(UnitTestPluginService, DestroyPluginSession2, TestSize.Level1)
405 {
406     ASSERT_FALSE(pluginService_->DestroyPluginSession("mem.so"));
407 }
408 
409 /**
410  * @tc.name: Service
411  * @tc.desc: Remove the specified plugin.
412  * @tc.type: FUNC
413  */
HWTEST_F(UnitTestPluginService, RemovePluginInfo2, TestSize.Level1)414 HWTEST_F(UnitTestPluginService, RemovePluginInfo2, TestSize.Level1)
415 {
416     UnregisterPluginRequest request;
417     PluginInfo pi;
418     pi.id = 0;
419     pi.name = "mem.so";
420     pi.path = "mem.so";
421     pi.sha256 = "asdfasdf";
422     ASSERT_FALSE(pluginService_->RemovePluginInfo(pi));
423 }
424 
425 /**
426  * @tc.name: Service
427  * @tc.desc: Setting report results.
428  * @tc.type: FUNC
429  */
HWTEST_F(UnitTestPluginService, AppendResult2, TestSize.Level1)430 HWTEST_F(UnitTestPluginService, AppendResult2, TestSize.Level1)
431 {
432     NotifyResultRequest nrr;
433     nrr.set_request_id(2);
434     nrr.set_command_id(2);
435     ASSERT_TRUE(pluginService_->AppendResult(nrr));
436 }
437 
438 /**
439  * @tc.name: Service
440  * @tc.desc: Get plugin status.
441  * @tc.type: FUNC
442  */
HWTEST_F(UnitTestPluginService, GetPluginStatus2, TestSize.Level1)443 HWTEST_F(UnitTestPluginService, GetPluginStatus2, TestSize.Level1)
444 {
445     auto status = pluginService_->GetPluginStatus();
446     ASSERT_TRUE(status.size() == 0);
447 }
448 
449 /**
450  * @tc.name: Service
451  * @tc.desc: Gets the plugin with the specified name.
452  * @tc.type: FUNC
453  */
HWTEST_F(UnitTestPluginService, GetPluginIdByName2, TestSize.Level1)454 HWTEST_F(UnitTestPluginService, GetPluginIdByName2, TestSize.Level1)
455 {
456     ASSERT_TRUE(pluginService_->GetPluginIdByName("mem.so") == 0);
457 }
458 
459 /**
460  * @tc.name: Service
461  * @tc.desc: Set plugin registration information.
462  * @tc.type: FUNC
463  */
HWTEST_F(UnitTestPluginService, AddPluginInfo3, TestSize.Level1)464 HWTEST_F(UnitTestPluginService, AddPluginInfo3, TestSize.Level1)
465 {
466     RegisterPluginRequest request;
467     RegisterPluginResponse response;
468     PluginInfo plugin;
469 
470     request.set_request_id(3);
471     request.set_path("cpu.so");
472     request.set_sha256("asdfasdfasdfasfd");
473     request.set_name("cpu.so");
474     ASSERT_TRUE(response.status() != ResponseStatus::OK);
475     pluginId_ = response.plugin_id();
476 
477     plugin.name = "cpu.so";
478     plugin.bufferSizeHint = 0;
479     plugin.sha256 = "";
480     EXPECT_TRUE(pluginService_->AddPluginInfo(plugin));
481 }
482 
483 /**
484  * @tc.name: Service
485  * @tc.desc: Set plugin configuration information.
486  * @tc.type: FUNC
487  */
HWTEST_F(UnitTestPluginService, CreatePluginSession13, TestSize.Level1)488 HWTEST_F(UnitTestPluginService, CreatePluginSession13, TestSize.Level1)
489 {
490     ProfilerPluginConfig ppc;
491     ppc.set_name("cpu.so");
492     ppc.set_plugin_sha256("ASDFAADSF");
493     ppc.set_sample_interval(SAMPLE_INTERVAL);
494 
495     ASSERT_FALSE(pluginService_->CreatePluginSession(ppc, std::make_shared<ProfilerDataRepeater>(QUEUE_MAX_SIZE)));
496 }
497 
498 /**
499  * @tc.name: Service
500  * @tc.desc: Set session configuration.
501  * @tc.type: FUNC
502  */
HWTEST_F(UnitTestPluginService, CreatePluginSession23, TestSize.Level1)503 HWTEST_F(UnitTestPluginService, CreatePluginSession23, TestSize.Level1)
504 {
505     ProfilerPluginConfig ppc;
506     ppc.set_name("cpu.so");
507     ppc.set_plugin_sha256("ASDFAADSF");
508     ppc.set_sample_interval(SAMPLE_INTERVAL);
509 
510     ProfilerSessionConfig::BufferConfig bc;
511     bc.set_pages(1);
512     bc.set_policy(ProfilerSessionConfig_BufferConfig_Policy_RECYCLE);
513 
514     ASSERT_FALSE(pluginService_->CreatePluginSession(ppc, bc, std::make_shared<ProfilerDataRepeater>(QUEUE_MAX_SIZE)));
515 }
516 
517 /**
518  * @tc.name: Service
519  * @tc.desc: Start plugin session.
520  * @tc.type: FUNC
521  */
HWTEST_F(UnitTestPluginService, StartPluginSession3, TestSize.Level1)522 HWTEST_F(UnitTestPluginService, StartPluginSession3, TestSize.Level1)
523 {
524     ProfilerPluginConfig ppc;
525     ppc.set_name("cpu.so");
526     ppc.set_plugin_sha256("ASDFAADSF");
527     ppc.set_sample_interval(SAMPLE_INTERVAL);
528 
529     ASSERT_FALSE(pluginService_->StartPluginSession(ppc));
530 }
531 
532 /**
533  * @tc.name: Service
534  * @tc.desc: Stop plugin session.
535  * @tc.type: FUNC
536  */
HWTEST_F(UnitTestPluginService, StopPluginSession3, TestSize.Level1)537 HWTEST_F(UnitTestPluginService, StopPluginSession3, TestSize.Level1)
538 {
539     ASSERT_FALSE(pluginService_->StopPluginSession("cpu.so"));
540 }
541 
542 /**
543  * @tc.name: Service
544  * @tc.desc: Destroy receiving test.
545  * @tc.type: FUNC
546  */
HWTEST_F(UnitTestPluginService, DestroyPluginSession3, TestSize.Level1)547 HWTEST_F(UnitTestPluginService, DestroyPluginSession3, TestSize.Level1)
548 {
549     ASSERT_FALSE(pluginService_->DestroyPluginSession("cpu.so"));
550 }
551 
552 /**
553  * @tc.name: Service
554  * @tc.desc: Remove the specified plugin.
555  * @tc.type: FUNC
556  */
HWTEST_F(UnitTestPluginService, RemovePluginInfo3, TestSize.Level1)557 HWTEST_F(UnitTestPluginService, RemovePluginInfo3, TestSize.Level1)
558 {
559     UnregisterPluginRequest request;
560     PluginInfo pi;
561     pi.id = 0;
562     pi.name = "cpu.so";
563     pi.path = "cpu.so";
564     pi.sha256 = "asdfasdf";
565     ASSERT_FALSE(pluginService_->RemovePluginInfo(pi));
566 }
567 
568 /**
569  * @tc.name: Service
570  * @tc.desc: Setting report results.
571  * @tc.type: FUNC
572  */
HWTEST_F(UnitTestPluginService, AppendResult3, TestSize.Level1)573 HWTEST_F(UnitTestPluginService, AppendResult3, TestSize.Level1)
574 {
575     NotifyResultRequest nrr;
576     nrr.set_request_id(3);
577     nrr.set_command_id(3);
578     ASSERT_TRUE(pluginService_->AppendResult(nrr));
579 }
580 
581 /**
582  * @tc.name: Service
583  * @tc.desc: Get plugin status.
584  * @tc.type: FUNC
585  */
HWTEST_F(UnitTestPluginService, GetPluginStatus3, TestSize.Level1)586 HWTEST_F(UnitTestPluginService, GetPluginStatus3, TestSize.Level1)
587 {
588     auto status = pluginService_->GetPluginStatus();
589     ASSERT_TRUE(status.size() == 0);
590 }
591 
592 /**
593  * @tc.name: Service
594  * @tc.desc: Gets the plugin with the specified name.
595  * @tc.type: FUNC
596  */
HWTEST_F(UnitTestPluginService, GetPluginIdByName3, TestSize.Level1)597 HWTEST_F(UnitTestPluginService, GetPluginIdByName3, TestSize.Level1)
598 {
599     ASSERT_TRUE(pluginService_->GetPluginIdByName("cpu.so") == 0);
600 }
601 
602 /**
603  * @tc.name: Service
604  * @tc.desc: Set plugin registration information.
605  * @tc.type: FUNC
606  */
HWTEST_F(UnitTestPluginService, AddPluginInfo4, TestSize.Level1)607 HWTEST_F(UnitTestPluginService, AddPluginInfo4, TestSize.Level1)
608 {
609     RegisterPluginRequest request;
610     RegisterPluginResponse response;
611     PluginInfo plugin;
612 
613     request.set_request_id(4);
614     request.set_path("stream.so");
615     request.set_sha256("asdfasdfasdfasfd");
616     request.set_name("stream.so");
617     ASSERT_TRUE(response.status() != ResponseStatus::OK);
618     pluginId_ = response.plugin_id();
619 
620     plugin.name = "stream.so";
621     plugin.bufferSizeHint = 0;
622     plugin.sha256 = "";
623     EXPECT_TRUE(pluginService_->AddPluginInfo(plugin));
624     plugin.bufferSizeHint = 10;
625     plugin.isStandaloneFileData = true;
626     plugin.outFileName = "test-file.bin";
627     plugin.pluginVersion = "1.02";
628     EXPECT_TRUE(pluginService_->AddPluginInfo(plugin));
629 }
630 
631 /**
632  * @tc.name: Service
633  * @tc.desc: Set plugin configuration information.
634  * @tc.type: FUNC
635  */
HWTEST_F(UnitTestPluginService, CreatePluginSession14, TestSize.Level1)636 HWTEST_F(UnitTestPluginService, CreatePluginSession14, TestSize.Level1)
637 {
638     ProfilerPluginConfig ppc;
639     ppc.set_name("stream.so");
640     ppc.set_plugin_sha256("ASDFAADSF");
641     ppc.set_sample_interval(SAMPLE_INTERVAL);
642 
643     ASSERT_FALSE(pluginService_->CreatePluginSession(ppc, std::make_shared<ProfilerDataRepeater>(QUEUE_MAX_SIZE)));
644 }
645 
646 /**
647  * @tc.name: Service
648  * @tc.desc: Set session configuration.
649  * @tc.type: FUNC
650  */
HWTEST_F(UnitTestPluginService, CreatePluginSession24, TestSize.Level1)651 HWTEST_F(UnitTestPluginService, CreatePluginSession24, TestSize.Level1)
652 {
653     ProfilerPluginConfig ppc;
654     ppc.set_name("stream.so");
655     ppc.set_plugin_sha256("ASDFAADSF");
656     ppc.set_sample_interval(SAMPLE_INTERVAL);
657 
658     ProfilerSessionConfig::BufferConfig bc;
659     bc.set_pages(1);
660     bc.set_policy(ProfilerSessionConfig_BufferConfig_Policy_RECYCLE);
661 
662     ASSERT_FALSE(pluginService_->CreatePluginSession(ppc, bc, std::make_shared<ProfilerDataRepeater>(QUEUE_MAX_SIZE)));
663 }
664 
665 /**
666  * @tc.name: Service
667  * @tc.desc: Start plugin session.
668  * @tc.type: FUNC
669  */
HWTEST_F(UnitTestPluginService, StartPluginSession4, TestSize.Level1)670 HWTEST_F(UnitTestPluginService, StartPluginSession4, TestSize.Level1)
671 {
672     ProfilerPluginConfig ppc;
673     ppc.set_name("stream.so");
674     ppc.set_plugin_sha256("ASDFAADSF");
675     ppc.set_sample_interval(SAMPLE_INTERVAL);
676 
677     ASSERT_FALSE(pluginService_->StartPluginSession(ppc));
678 }
679 
680 /**
681  * @tc.name: Service
682  * @tc.desc: Stop plugin session.
683  * @tc.type: FUNC
684  */
HWTEST_F(UnitTestPluginService, StopPluginSession4, TestSize.Level1)685 HWTEST_F(UnitTestPluginService, StopPluginSession4, TestSize.Level1)
686 {
687     ASSERT_FALSE(pluginService_->StopPluginSession("stream.so"));
688 }
689 
690 /**
691  * @tc.name: Service
692  * @tc.desc: Destroy receiving test.
693  * @tc.type: FUNC
694  */
HWTEST_F(UnitTestPluginService, DestroyPluginSession4, TestSize.Level1)695 HWTEST_F(UnitTestPluginService, DestroyPluginSession4, TestSize.Level1)
696 {
697     ASSERT_FALSE(pluginService_->DestroyPluginSession("stream.so"));
698 }
699 
700 /**
701  * @tc.name: Service
702  * @tc.desc: Remove the specified plugin.
703  * @tc.type: FUNC
704  */
HWTEST_F(UnitTestPluginService, RemovePluginInfo4, TestSize.Level1)705 HWTEST_F(UnitTestPluginService, RemovePluginInfo4, TestSize.Level1)
706 {
707     UnregisterPluginRequest request;
708     PluginInfo pi;
709     pi.id = 0;
710     pi.name = "stream.so";
711     pi.path = "stream.so";
712     pi.sha256 = "asdfasdf";
713     ASSERT_FALSE(pluginService_->RemovePluginInfo(pi));
714 }
715 
716 /**
717  * @tc.name: Service
718  * @tc.desc: Setting report results.
719  * @tc.type: FUNC
720  */
HWTEST_F(UnitTestPluginService, AppendResult4, TestSize.Level1)721 HWTEST_F(UnitTestPluginService, AppendResult4, TestSize.Level1)
722 {
723     NotifyResultRequest nrr;
724     nrr.set_request_id(4);
725     nrr.set_command_id(4);
726     ASSERT_TRUE(pluginService_->AppendResult(nrr));
727 }
728 
729 /**
730  * @tc.name: Service
731  * @tc.desc: Get plugin status.
732  * @tc.type: FUNC
733  */
HWTEST_F(UnitTestPluginService, GetPluginStatus4, TestSize.Level1)734 HWTEST_F(UnitTestPluginService, GetPluginStatus4, TestSize.Level1)
735 {
736     auto status = pluginService_->GetPluginStatus();
737     ASSERT_TRUE(status.size() == 0);
738 }
739 
740 /**
741  * @tc.name: Service
742  * @tc.desc: Gets the plugin with the specified name.
743  * @tc.type: FUNC
744  */
HWTEST_F(UnitTestPluginService, GetPluginIdByName4, TestSize.Level1)745 HWTEST_F(UnitTestPluginService, GetPluginIdByName4, TestSize.Level1)
746 {
747     ASSERT_TRUE(pluginService_->GetPluginIdByName("stream.so") == 0);
748 }
749 
750 /**
751  * @tc.name: Service
752  * @tc.desc: Set plugin registration information.
753  * @tc.type: FUNC
754  */
HWTEST_F(UnitTestPluginService, AddPluginInfo5, TestSize.Level1)755 HWTEST_F(UnitTestPluginService, AddPluginInfo5, TestSize.Level1)
756 {
757     RegisterPluginRequest request;
758     RegisterPluginResponse response;
759     PluginInfo plugin;
760 
761     request.set_request_id(5);
762     request.set_path("sample.so");
763     request.set_sha256("asdfasdfasdfasfd");
764     request.set_name("sample.so");
765     ASSERT_TRUE(response.status() != ResponseStatus::OK);
766     pluginId_ = response.plugin_id();
767 
768     plugin.name = "sample.so";
769     plugin.bufferSizeHint = 0;
770     plugin.sha256 = "";
771     EXPECT_TRUE(pluginService_->AddPluginInfo(plugin));
772 }
773 
774 /**
775  * @tc.name: Service
776  * @tc.desc: Set plugin configuration information.
777  * @tc.type: FUNC
778  */
HWTEST_F(UnitTestPluginService, CreatePluginSession15, TestSize.Level1)779 HWTEST_F(UnitTestPluginService, CreatePluginSession15, TestSize.Level1)
780 {
781     ProfilerPluginConfig ppc;
782     ppc.set_name("sample.so");
783     ppc.set_plugin_sha256("ASDFAADSF");
784     ppc.set_sample_interval(SAMPLE_INTERVAL);
785 
786     ASSERT_FALSE(pluginService_->CreatePluginSession(ppc, std::make_shared<ProfilerDataRepeater>(QUEUE_MAX_SIZE)));
787 }
788 
789 /**
790  * @tc.name: Service
791  * @tc.desc: Set session configuration.
792  * @tc.type: FUNC
793  */
HWTEST_F(UnitTestPluginService, CreatePluginSession25, TestSize.Level1)794 HWTEST_F(UnitTestPluginService, CreatePluginSession25, TestSize.Level1)
795 {
796     ProfilerPluginConfig ppc;
797     ppc.set_name("sample.so");
798     ppc.set_plugin_sha256("ASDFAADSF");
799     ppc.set_sample_interval(SAMPLE_INTERVAL);
800 
801     ProfilerSessionConfig::BufferConfig bc;
802     bc.set_pages(1);
803     bc.set_policy(ProfilerSessionConfig_BufferConfig_Policy_RECYCLE);
804 
805     ASSERT_FALSE(pluginService_->CreatePluginSession(ppc, bc, std::make_shared<ProfilerDataRepeater>(QUEUE_MAX_SIZE)));
806 }
807 
808 /**
809  * @tc.name: Service
810  * @tc.desc: Start plugin session.
811  * @tc.type: FUNC
812  */
HWTEST_F(UnitTestPluginService, StartPluginSession5, TestSize.Level1)813 HWTEST_F(UnitTestPluginService, StartPluginSession5, TestSize.Level1)
814 {
815     ProfilerPluginConfig ppc;
816     ppc.set_name("sample.so");
817     ppc.set_plugin_sha256("ASDFAADSF");
818     ppc.set_sample_interval(SAMPLE_INTERVAL);
819 
820     ASSERT_FALSE(pluginService_->StartPluginSession(ppc));
821 }
822 
823 /**
824  * @tc.name: Service
825  * @tc.desc: Stop plugin session.
826  * @tc.type: FUNC
827  */
HWTEST_F(UnitTestPluginService, StopPluginSession5, TestSize.Level1)828 HWTEST_F(UnitTestPluginService, StopPluginSession5, TestSize.Level1)
829 {
830     ASSERT_FALSE(pluginService_->StopPluginSession("sample.so"));
831 }
832 
833 /**
834  * @tc.name: Service
835  * @tc.desc: Destroy receiving test.
836  * @tc.type: FUNC
837  */
HWTEST_F(UnitTestPluginService, DestroyPluginSession5, TestSize.Level1)838 HWTEST_F(UnitTestPluginService, DestroyPluginSession5, TestSize.Level1)
839 {
840     ASSERT_FALSE(pluginService_->DestroyPluginSession("sample.so"));
841 }
842 
843 /**
844  * @tc.name: Service
845  * @tc.desc: Remove the specified plugin.
846  * @tc.type: FUNC
847  */
HWTEST_F(UnitTestPluginService, RemovePluginInfo5, TestSize.Level1)848 HWTEST_F(UnitTestPluginService, RemovePluginInfo5, TestSize.Level1)
849 {
850     UnregisterPluginRequest request;
851     PluginInfo pi;
852     pi.id = 0;
853     pi.name = "sample.so";
854     pi.path = "sample.so";
855     pi.sha256 = "asdfasdf";
856     ASSERT_FALSE(pluginService_->RemovePluginInfo(pi));
857 }
858 
859 /**
860  * @tc.name: Service
861  * @tc.desc: Setting report results.
862  * @tc.type: FUNC
863  */
HWTEST_F(UnitTestPluginService, AppendResult5, TestSize.Level1)864 HWTEST_F(UnitTestPluginService, AppendResult5, TestSize.Level1)
865 {
866     NotifyResultRequest nrr;
867     nrr.set_request_id(5);
868     nrr.set_command_id(5);
869     ASSERT_TRUE(pluginService_->AppendResult(nrr));
870 }
871 
872 /**
873  * @tc.name: Service
874  * @tc.desc: Get plugin status.
875  * @tc.type: FUNC
876  */
HWTEST_F(UnitTestPluginService, GetPluginStatus5, TestSize.Level1)877 HWTEST_F(UnitTestPluginService, GetPluginStatus5, TestSize.Level1)
878 {
879     auto status = pluginService_->GetPluginStatus();
880     ASSERT_TRUE(status.size() == 0);
881 }
882 
883 /**
884  * @tc.name: Service
885  * @tc.desc: Gets the plugin with the specified name.
886  * @tc.type: FUNC
887  */
HWTEST_F(UnitTestPluginService, GetPluginIdByName5, TestSize.Level1)888 HWTEST_F(UnitTestPluginService, GetPluginIdByName5, TestSize.Level1)
889 {
890     ASSERT_TRUE(pluginService_->GetPluginIdByName("sample.so") == 0);
891 }
892 
893 /**
894  * @tc.name: Service
895  * @tc.desc: test function RegisterPlugin.
896  * @tc.type: FUNC
897  */
HWTEST_F(UnitTestPluginService, PluginServiceImpl_RegisterPlugin, TestSize.Level1)898 HWTEST_F(UnitTestPluginService, PluginServiceImpl_RegisterPlugin, TestSize.Level1)
899 {
900     RegisterPluginRequest request;
901     RegisterPluginResponse response;
902     SocketContext ctx;
903 
904     request.set_request_id(5);
905     request.set_path("sample2.so");
906     request.set_sha256("");
907     request.set_name("sample2.so");
908     request.set_buffer_size_hint(0);
909     EXPECT_TRUE(pluginServiceImp_->RegisterPlugin(ctx, request, response));
910     request.set_sha256("abcdsfdsfad");
911     EXPECT_FALSE(pluginServiceImp_->RegisterPlugin(ctx, request, response));
912     UnregisterPluginRequest unRequest;
913     UnregisterPluginResponse unResponse;
914     uint32_t plugId = pluginService_->GetPluginIdByName("sample2.so");
915     unRequest.set_plugin_id(plugId);
916     EXPECT_TRUE(pluginServiceImp_->UnregisterPlugin(ctx, unRequest, unResponse));
917 }
918 
919 /**
920  * @tc.name: Service
921  * @tc.desc: test function UnregisterPlugin
922  * @tc.type: FUNC
923  */
HWTEST_F(UnitTestPluginService, PluginServiceImpl_UnregisterPlugin, TestSize.Level1)924 HWTEST_F(UnitTestPluginService, PluginServiceImpl_UnregisterPlugin, TestSize.Level1)
925 {
926     UnregisterPluginRequest request;
927     UnregisterPluginResponse response;
928     SocketContext ctx;
929     request.set_plugin_id(1);
930     EXPECT_FALSE(pluginServiceImp_->UnregisterPlugin(ctx, request, response));
931 
932     GetCommandRequest gcRequest;
933     GetCommandResponse gcResponse;
934     EXPECT_FALSE(pluginServiceImp_->GetCommand(ctx, gcRequest, gcResponse));
935 
936     NotifyResultRequest nResRequest;
937     NotifyResultResponse nResResponse;
938     EXPECT_TRUE(pluginServiceImp_->NotifyResult(ctx, nResRequest, nResResponse));
939 }
940 /**
941  * @tc.name: BuildCreateSessionCmd
942  * @tc.desc: build create session command
943  * @tc.type: FUNC
944  */
HWTEST_F(UnitTestPluginService, pluginCommandBuilder, TestSize.Level1)945 HWTEST_F(UnitTestPluginService, pluginCommandBuilder, TestSize.Level1)
946 {
947     ProfilerPluginConfig ppc;
948     ppc.set_name("abc.so");
949     ppc.set_plugin_sha256("ASDFAADSF");
950     ppc.set_sample_interval(SAMPLE_INTERVAL);
951     const uint32_t pluginId = 1;
952     EXPECT_TRUE(commandBuilder_->BuildCreateSessionCmd(ppc, BUFFER_SIZE) != nullptr);
953     EXPECT_TRUE(commandBuilder_->BuildStartSessionCmd(ppc, pluginId) != nullptr);
954     EXPECT_TRUE(commandBuilder_->BuildRefreshSessionCmd(pluginId) != nullptr);
955     EXPECT_TRUE(commandBuilder_->BuildStopSessionCmd(pluginId) != nullptr);
956     EXPECT_TRUE(commandBuilder_->BuildDestroySessionCmd(pluginId) != nullptr);
957     EXPECT_FALSE(commandBuilder_->GetedCommandResponse(0));
958     EXPECT_TRUE(commandBuilder_->GetedCommandResponse(1));
959 }
960 
961 /**
962  * @tc.name: PluginSessionManager
963  * @tc.desc: test plugin session manager checkBufferConfig
964  * @tc.type: FUNC
965  */
HWTEST_F(UnitTestPluginService, PluginSessionManager_Check, TestSize.Level1)966 HWTEST_F(UnitTestPluginService, PluginSessionManager_Check, TestSize.Level1)
967 {
968     PluginInfo plugin;
969     SocketContext ctx;
970     plugin.name = "abc_check.so";
971     plugin.bufferSizeHint = 0;
972     plugin.sha256 = "asdfasdfasdfasfd";
973     plugin.context = &ctx;
974     EXPECT_TRUE(pluginService_->AddPluginInfo(plugin));
975     ProfilerSessionConfig::BufferConfig bc;
976     bc.set_pages(1);
977     bc.set_policy(ProfilerSessionConfig_BufferConfig_Policy_RECYCLE);
978     EXPECT_TRUE(pluginSessionMgr_->CheckBufferConfig(bc));
979     ProfilerPluginConfig ppc;
980     ppc.set_name("abc_check.so");
981     ppc.set_plugin_sha256("asdfasdfasdfasfd");
982     EXPECT_TRUE(pluginSessionMgr_->CheckPluginSha256(ppc));
983 }
984 /**
985  * @tc.name: PluginSessionManager
986  * @tc.desc: test plugin session manager by creating sesssion
987  * @tc.type: FUNC
988  */
HWTEST_F(UnitTestPluginService, PluginSessionManager_CreateSession, TestSize.Level1)989 HWTEST_F(UnitTestPluginService, PluginSessionManager_CreateSession, TestSize.Level1)
990 {
991     PluginInfo plugin;
992     plugin.name = "testsample.so";
993     plugin.bufferSizeHint = 0;
994     plugin.sha256 = "ASDFAADSF";
995     plugin.context = (SocketContext*)pluginClient_->unixSocketClient_.get();
996     EXPECT_TRUE(pluginService_->AddPluginInfo(plugin));
997     ProfilerPluginConfig ppc;
998     ppc.set_name("testsample.so");
999     ppc.set_plugin_sha256("ASDFAADSF");
1000     ppc.set_sample_interval(SAMPLE_INTERVAL);
1001 
1002     ProfilerSessionConfig::BufferConfig bc;
1003     bc.set_pages(1);
1004     bc.set_policy(ProfilerSessionConfig_BufferConfig_Policy_RECYCLE);
1005     ProfilerSessionConfig psc;
1006     psc.set_session_mode(ProfilerSessionConfig::OFFLINE);
1007     std::vector<string> names = {"testsample.so"};
1008     pluginService_->SetProfilerSessionConfig(std::make_shared<ProfilerSessionConfig>(psc), names);
1009     EXPECT_TRUE(pluginSessionMgr_->CreatePluginSession(
1010                     ppc, bc, std::make_shared<ProfilerDataRepeater>(QUEUE_MAX_SIZE)) != nullptr);
1011 }
1012 /**
1013  * @tc.name: PluginSessionManager
1014  * @tc.desc: test plugin session manager by creating a lot of sesssions
1015  * @tc.type: FUNC
1016  */
HWTEST_F(UnitTestPluginService, PluginSessionManager_CreateSessions, TestSize.Level1)1017 HWTEST_F(UnitTestPluginService, PluginSessionManager_CreateSessions, TestSize.Level1)
1018 {
1019     PluginInfo plugin;
1020     plugin.name = "testsample1.so";
1021     plugin.bufferSizeHint = 0;
1022     plugin.sha256 = "ASDFAADSF";
1023     plugin.context = (SocketContext*)pluginClient_->unixSocketClient_.get();
1024     EXPECT_TRUE(pluginService_->AddPluginInfo(plugin));
1025     ProfilerPluginConfig ppc;
1026     ppc.set_name("testsample1.so");
1027     ppc.set_plugin_sha256("ASDFAADSF");
1028     ppc.set_sample_interval(SAMPLE_INTERVAL);
1029 
1030     ProfilerSessionConfig::BufferConfig bc;
1031     bc.set_pages(1);
1032     bc.set_policy(ProfilerSessionConfig_BufferConfig_Policy_RECYCLE);
1033     std::vector<ProfilerPluginConfig> vecConfig;
1034     std::vector<ProfilerSessionConfig::BufferConfig> vecBuf;
1035     vecConfig.push_back(ppc);
1036     vecBuf.push_back(bc);
1037     ProfilerSessionConfig psc;
1038     psc.set_session_mode(ProfilerSessionConfig::OFFLINE);
1039     std::vector<string> names = {"testsample1.so"};
1040     pluginService_->SetProfilerSessionConfig(std::make_shared<ProfilerSessionConfig>(psc), names);
1041     EXPECT_TRUE(pluginSessionMgr_->CreatePluginSessions(vecConfig, vecBuf,
1042                                                         std::make_shared<ProfilerDataRepeater>(QUEUE_MAX_SIZE)));
1043     std::vector<std::string> nameList{"testsample.so", "testsample1.so"};
1044     EXPECT_TRUE(pluginSessionMgr_->InvalidatePluginSessions(nameList));
1045     std::vector<PluginSession::State> vecRet = pluginSessionMgr_->GetStatus(nameList);
1046     EXPECT_TRUE(vecRet.size() != 0);
1047     EXPECT_TRUE(pluginSessionMgr_->RefreshPluginSession());
1048 }
1049 
1050 /**
1051  * @tc.name: plugin service
1052  * @tc.desc: test createpluginsession online
1053  * @tc.type: FUNC
1054  */
HWTEST_F(UnitTestPluginService, PluginService_CreatePluginSession_Online, TestSize.Level1)1055 HWTEST_F(UnitTestPluginService, PluginService_CreatePluginSession_Online, TestSize.Level1)
1056 {
1057     ProfilerPluginConfig ppc;
1058     ppc.set_name("abconline.so");
1059     ppc.set_plugin_sha256("ASDFAADSF");
1060     ppc.set_sample_interval(SAMPLE_INTERVAL);
1061     ProfilerSessionConfig::BufferConfig bc;
1062     bc.set_pages(1);
1063     bc.set_policy(ProfilerSessionConfig_BufferConfig_Policy_RECYCLE);
1064 
1065     PluginInfo plugin;
1066     plugin.name = "abconline.so";
1067     plugin.bufferSizeHint = 0;
1068     plugin.sha256 = "ASDFAADSF";
1069     plugin.context = (SocketContext*)pluginClient_->unixSocketClient_.get();
1070     EXPECT_TRUE(pluginService_->AddPluginInfo(plugin));
1071     ProfilerSessionConfig psc;
1072     psc.set_session_mode(ProfilerSessionConfig::ONLINE);
1073     std::vector<string> names = {"abconline.so"};
1074     pluginService_->SetProfilerSessionConfig(std::make_shared<ProfilerSessionConfig>(psc), names);
1075     EXPECT_TRUE(pluginService_->CreatePluginSession(ppc, bc, std::make_shared<ProfilerDataRepeater>(QUEUE_MAX_SIZE)));
1076     uint32_t pluginId = pluginService_->GetPluginIdByName("abconline.so");
1077     PluginContextPtr pluginCtx = pluginService_->GetPluginContextById(pluginId);
1078     pluginCtx->profilerPluginState.set_state(ProfilerPluginState::LOADED);
1079     pluginService_->ReadShareMemoryOnline(*pluginCtx);
1080     NotifyResultRequest nrr;
1081     nrr.set_request_id(5);
1082     nrr.set_command_id(5);
1083     PluginResult* result = nrr.add_result();
1084     result->set_plugin_id(pluginId);
1085     result->set_out_file_name("/data/local/tmp/testonline.trace");
1086     result->set_data("test plugin result!");
1087     EXPECT_TRUE(pluginService_->AppendResult(nrr));
1088     plugin.id = pluginId;
1089     EXPECT_TRUE(pluginService_->RemovePluginInfo(plugin));
1090 }
1091 } // namespace