• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "report_json_file_test.h"
17 
18 #include <bitset>
19 #include <memory>
20 
21 using namespace testing::ext;
22 using namespace std;
23 using namespace OHOS::HiviewDFX;
24 using namespace ::testing;
25 namespace OHOS {
26 namespace Developtools {
27 namespace HiPerf {
28 class ReportJsonFileTest : public testing::Test {
29 public:
30     static void SetUpTestCase(void);
31     static void TearDownTestCase(void);
32     void SetUp();
33     void TearDown();
34     std::unique_ptr<ReportJsonFile> PrepairReportJson(const VirtualRuntime &virtualRuntime) const;
35 };
36 
SetUpTestCase()37 void ReportJsonFileTest::SetUpTestCase() {}
38 
TearDownTestCase()39 void ReportJsonFileTest::TearDownTestCase() {}
40 
SetUp()41 void ReportJsonFileTest::SetUp() {}
42 
TearDown()43 void ReportJsonFileTest::TearDown() {}
44 
45 /*
46 this func give a report json object which have
47 1 conifg with name "eventName" and ids is  1,2,3
48     1 process : pid 1
49     2 thread : tid is 3 and 4
50     3 lib : liba , libb and libc
51     5 func :
52         funca1 in liba
53         funca2 in liba
54         funcb1 in libb
55         funcc1 in libc
56 
57     2 callstack
58         in thread id 3:
59             funca1 - liba count 10
60             funca2 - liba count 0
61         in thread id 4:
62             funcc1 - libc count 20
63             funcb1 - libb count 0
64 */
PrepairReportJson(const VirtualRuntime & virtualRuntime) const65 std::unique_ptr<ReportJsonFile> ReportJsonFileTest::PrepairReportJson(
66     const VirtualRuntime &virtualRuntime) const
67 {
68     std::unique_ptr<ReportJsonFile> json =
69         std::make_unique<ReportJsonFile>(nullptr, virtualRuntime);
70     std::vector<CallFrame> frames = {
71         {0x1u, 0x1u, "funca1", "liba"},
72         {0x2u, 0x1u, "funca2", "liba"},
73         {0x3u, 0x1u, "funcb1", "libb"},
74     };
75     std::vector<CallFrame> frames2 = {
76         {0x1u, 0x1u, "funcc1", "libc"},
77         {0x2u, 0x1u, "funcb1", "libb"},
78     };
79     std::vector<uint64_t> ids = {1, 2, 3};
80     json->reportConfigItems_.emplace(
81         ids, ReportConfigItem(json->reportConfigItems_.size(), "eventName"));
82     json->libList_ = {"liba", "libb", "libc"};
83     json->functionList_ = {
84         functionKey(0, "funca1"),
85         functionKey(0, "funca2"),
86         functionKey(1, "funcb1"),
87         functionKey(2, "funcc1"),
88     };
89     // id , pid , tid , event count
90     uint64_t id = 1;
91     uint64_t eventCount = 10;
92     uint64_t eventCount2 = 20;
93     int pid = 2;
94     int tid = 3;
95     int tid2 = 4;
96     json->UpdateReportCallStack(id, pid, tid, eventCount, frames);
97     json->UpdateReportCallStack(id, pid, tid2, eventCount2, frames2);
98 
99     return json;
100 }
101 
102 /**
103  * @tc.name: OutputJsonKey
104  * @tc.desc:
105  * @tc.type: FUNC
106  */
107 HWTEST_F(ReportJsonFileTest, OutputJsonKey, TestSize.Level1)
108 {
109     StdoutRecord output;
110 
111     // no name
112     output.Start();
113     OutputJsonKey(stdout, std::string());
114     EXPECT_STREQ(output.Stop().c_str(), "");
115 
116     output.Start();
117     OutputJsonKey(stdout, "");
118     EXPECT_STREQ(output.Stop().c_str(), "");
119 
120     // have name
121     output.Start();
122     OutputJsonKey(stdout, "keyname");
123     EXPECT_STREQ(output.Stop().c_str(), "\"keyname\":");
124 
125     output.Start();
126     OutputJsonKey(stdout, static_cast<int>(1));
127     EXPECT_STREQ(output.Stop().c_str(), "\"1\":");
128 
129     output.Start();
130     OutputJsonKey(stdout, static_cast<long>(1));
131     EXPECT_STREQ(output.Stop().c_str(), "\"1\":");
132 
133     output.Start();
134     OutputJsonKey(stdout, static_cast<size_t>(2));
135     EXPECT_STREQ(output.Stop().c_str(), "\"2\":");
136 
137     output.Start();
138 
139     OutputJsonKey(stdout, std::string("keyname"));
140     EXPECT_STREQ(output.Stop().c_str(), "\"keyname\":");
141 }
142 
143 /**
144  * @tc.name: OutputJsonValue
145  * @tc.desc:
146  * @tc.type: FUNC
147  */
148 HWTEST_F(ReportJsonFileTest, OutputJsonValue, TestSize.Level1)
149 {
150     StdoutRecord output;
151 
152     output.Start();
153     OutputJsonValue(stdout, std::string("value"));
154     EXPECT_STREQ(output.Stop().c_str(), "\"value\"");
155 
156     output.Start();
157     OutputJsonValue(stdout, int(1));
158     EXPECT_STREQ(output.Stop().c_str(), "1");
159 
160     output.Start();
161     OutputJsonValue(stdout, uint64_t(1));
162     EXPECT_STREQ(output.Stop().c_str(), "1");
163 
164     output.Start();
165     OutputJsonValue(stdout, bool(true));
166     EXPECT_STREQ(output.Stop().c_str(), "1");
167 
168     output.Start();
169     OutputJsonValue(stdout, size_t(1));
170     EXPECT_STREQ(output.Stop().c_str(), "1");
171 
172     output.Start();
173     OutputJsonValue(stdout, "value");
174     EXPECT_STREQ(output.Stop().c_str(), "\"value\"");
175 
176     output.Start();
177     OutputJsonValue(stdout, "value", false);
178     EXPECT_STREQ(output.Stop().c_str(), ",\"value\"");
179 }
180 
181 /**
182  * @tc.name: OutputJsonPair
183  * @tc.desc:
184  * @tc.type: FUNC
185  */
186 HWTEST_F(ReportJsonFileTest, OutputJsonPair, TestSize.Level1)
187 {
188     StdoutRecord output;
189     output.Start();
190     OutputJsonValue(stdout, std::string("value"));
191     EXPECT_STREQ(output.Stop().c_str(), "\"value\"");
192 }
193 
194 /**
195  * @tc.name: OutputJsonVectorList
196  * @tc.desc:
197  * @tc.type: FUNC
198  */
199 HWTEST_F(ReportJsonFileTest, OutputJsonVectorList, TestSize.Level1)
200 {
201     StdoutRecord output;
202 
203     output.Start();
204     OutputJsonVectorList<int>(stdout, "listname", {1, 2, 3}, true);
205     EXPECT_STREQ(output.Stop().c_str(), "\"listname\":[1,2,3]");
206 
207     output.Start();
208     OutputJsonVectorList<std::string>(stdout, "listname", {"1", "2", "3"}, true);
209     EXPECT_STREQ(output.Stop().c_str(), "\"listname\":[\"1\",\"2\",\"3\"]");
210 }
211 
212 /**
213  * @tc.name: OutputJsonMapList
214  * @tc.desc:
215  * @tc.type: FUNC
216  */
217 HWTEST_F(ReportJsonFileTest, OutputJsonMapList, TestSize.Level1)
218 {
219     StdoutRecord output;
220     std::map<int, int> map = {
221         {1, 2},
222         {3, 4},
223         {5, 6},
224     };
225 
226     output.Start();
227     OutputJsonMapList(stdout, "map", map, true);
228     EXPECT_STREQ(output.Stop().c_str(), "\"map\":[2,4,6]");
229 
230     std::map<std::string, std::string> map2 = {
231         {"1", "2"},
232         {"3", "4"},
233         {"5", "6"},
234     };
235 
236     output.Start();
237     OutputJsonMapList(stdout, "map2", map2, true);
238     EXPECT_STREQ(output.Stop().c_str(), "\"map2\":[\"2\",\"4\",\"6\"]");
239 }
240 
241 /**
242  * @tc.name: OutputJsonMap
243  * @tc.desc:
244  * @tc.type: FUNC
245  */
246 HWTEST_F(ReportJsonFileTest, OutputJsonMap, TestSize.Level1)
247 {
248     StdoutRecord output;
249     std::map<int, int> map = {
250         {1, 2},
251         {3, 4},
252         {5, 6},
253     };
254 
255     output.Start();
256     OutputJsonMap(stdout, "map", map, true);
257     EXPECT_STREQ(output.Stop().c_str(), "\"map\":{\"1\":2,\"3\":4,\"5\":6}");
258 
259     std::map<std::string, std::string> map2 = {
260         {"1", "2"},
261         {"3", "4"},
262         {"5", "6"},
263     };
264 
265     output.Start();
266     OutputJsonMap(stdout, "map2", map2, true);
267     EXPECT_STREQ(output.Stop().c_str(), "\"map2\":{\"1\":\"2\",\"3\":\"4\",\"5\":\"6\"}");
268 }
269 
270 /**
271  * @tc.name: GetOrCreateMapItem
272  * @tc.desc:
273  * @tc.type: FUNC
274  */
275 HWTEST_F(ReportJsonFileTest, GetOrCreateMapItem, TestSize.Level1)
276 {
277     std::map<int, int> map = {
278         {1, 2},
279         {3, 4},
280         {5, 6},
281     };
282 
283     EXPECT_EQ(GetOrCreateMapItem(map, 1), 2);
284     EXPECT_EQ(GetOrCreateMapItem(map, 2), 2);
285     EXPECT_EQ(GetOrCreateMapItem(map, 3), 4);
286     EXPECT_EQ(GetOrCreateMapItem(map, 4), 4);
287 }
288 
289 /**
290  * @tc.name: ReportFuncItem
291  * @tc.desc:
292  * @tc.type: FUNC
293  */
294 HWTEST_F(ReportJsonFileTest, ReportFuncItem, TestSize.Level1)
295 {
296     StdoutRecord output;
297     ReportFuncItem func(1);
298     func.sampleCount_ = 2;
299     func.eventCount_ = 3;
300     func.subTreeEventCount_ = 4;
301 
302     output.Start();
303     func.OutputJson(stdout);
304 
305     EXPECT_STREQ(output.Stop().c_str(), "{\"symbol\":1,\"counts\":[2,3,4]}");
306 }
307 
308 /**
309  * @tc.name: ReportCallNodeItem
310  * @tc.desc:
311  * @tc.type: FUNC
312  */
313 HWTEST_F(ReportJsonFileTest, ReportCallNodeItem, TestSize.Level1)
314 {
315     StdoutRecord output;
316     /*
317     2 / 12
318         4 / 10
319             6 / 6
320     */
321 
322     ReportCallNodeItem callnode(1);
323     callnode.selfEventCount_ = 2;
324     callnode.subTreeEventCount_ = 12;
325 
326     output.Start();
327     callnode.OutputJson(stdout);
328 
329     EXPECT_STREQ(output.Stop().c_str(),
330                  "{\"selfEvents\":2,\"subEvents\":12,\"symbol\":1,\"callStack\":[]}");
331 
332     ReportCallNodeItem &callnode2 = GetOrCreateMapItem(callnode.childrenMap, 2);
333     callnode2.selfEventCount_ = 4;
334     callnode2.subTreeEventCount_ = 10;
335     output.Start();
336     callnode.OutputJson(stdout);
337     EXPECT_STREQ(output.Stop().c_str(),
338                  "{\"selfEvents\":2,\"subEvents\":12,\"symbol\":1,\"callStack\":[{\"selfEvents\":4,"
339                  "\"subEvents\":10,\"symbol\":2,\"callStack\":[]}]}");
340 
341     ReportCallNodeItem &callnode3 = GetOrCreateMapItem(callnode2.childrenMap, 3);
342     callnode3.selfEventCount_ = 6;
343     callnode3.subTreeEventCount_ = 6;
344     output.Start();
345     callnode.OutputJson(stdout);
346 
347     EXPECT_STREQ(output.Stop().c_str(),
348                  "{\"selfEvents\":2,\"subEvents\":12,\"symbol\":1,\"callStack\":[{\"selfEvents\":4,"
349                  "\"subEvents\":10,\"symbol\":2,\"callStack\":[{\"selfEvents\":6,\"subEvents\":6,"
350                  "\"symbol\":3,\"callStack\":[]}]}]}");
351 }
352 
353 /**
354  * @tc.name: ReportCallNodeItem
355  * @tc.desc:
356  * @tc.type: FUNC
357  */
358 HWTEST_F(ReportJsonFileTest, UpdateChildrenEventCount, TestSize.Level1)
359 {
360     StdoutRecord output;
361     /*
362     2 / 12
363         4 / 10
364             6 / 6
365     */
366 
367     ReportCallNodeItem callnode(1);
368     callnode.selfEventCount_ = 2;
369     callnode.subTreeEventCount_ = 0;
370 
371     ReportCallNodeItem &callnode2 = GetOrCreateMapItem(callnode.childrenMap, 2);
372     callnode2.selfEventCount_ = 4;
373     callnode2.subTreeEventCount_ = 0;
374 
375     ReportCallNodeItem &callnode3 = GetOrCreateMapItem(callnode2.childrenMap, 3);
376     callnode3.selfEventCount_ = 6;
377     callnode3.subTreeEventCount_ = 0;
378 
379     output.Start();
380     callnode.UpdateChildrenEventCount();
381     callnode.OutputJson(stdout);
382 
383     EXPECT_STREQ(output.Stop().c_str(),
384                  "{\"selfEvents\":2,\"subEvents\":12,\"symbol\":1,\"callStack\":[{\"selfEvents\":4,"
385                  "\"subEvents\":10,\"symbol\":2,\"callStack\":[{\"selfEvents\":6,\"subEvents\":6,"
386                  "\"symbol\":3,\"callStack\":[]}]}]}");
387 }
388 
389 /**
390  * @tc.name: ReportLibItem
391  * @tc.desc:
392  * @tc.type: FUNC
393  */
394 HWTEST_F(ReportJsonFileTest, ReportLibItem, TestSize.Level1)
395 {
396     StdoutRecord output;
397     ReportLibItem lib;
398     lib.libId_ = 1;
399     lib.eventCount_ = 2;
400 
401     ReportFuncItem &func = GetOrCreateMapItem(lib.funcs_, 1);
402     func.sampleCount_ = 2;
403     func.eventCount_ = 3;
404     func.subTreeEventCount_ = 4;
405 
406     output.Start();
407     lib.OutputJson(stdout);
408 
409     EXPECT_STREQ(
410         output.Stop().c_str(),
411         "{\"fileId\":1,\"eventCount\":2,\"functions\":[{\"symbol\":1,\"counts\":[2,3,4]}]}");
412 }
413 
414 /**
415  * @tc.name: ReportThreadItem
416  * @tc.desc:
417  * @tc.type: FUNC
418  */
419 HWTEST_F(ReportJsonFileTest, ReportThreadItem, TestSize.Level1)
420 {
421     StdoutRecord output;
422     ReportThreadItem thread(1);
423     thread.tid_ = 2;
424     thread.eventCount_ = 3;
425     thread.sampleCount_ = 4;
426 
427     output.Start();
428     thread.OutputJson(stdout);
429 
430     EXPECT_STREQ(output.Stop().c_str(),
431                  "{\"tid\":2,\"eventCount\":3,\"sampleCount\":4,\"libs\":[],\"CallOrder\":{"
432                  "\"selfEvents\":0,\"subEvents\":0,\"symbol\":-1,\"callStack\":[]},\"CalledOrder\":"
433                  "{\"selfEvents\":0,\"subEvents\":0,\"symbol\":-1,\"callStack\":[]}}");
434 }
435 
436 /**
437  * @tc.name: ReportProcessItem
438  * @tc.desc:
439  * @tc.type: FUNC
440  */
441 HWTEST_F(ReportJsonFileTest, ReportProcessItem, TestSize.Level1)
442 {
443     StdoutRecord output;
444     ReportProcessItem process(1);
445     process.pid_ = 2;
446     process.eventCount_ = 3;
447 
448     output.Start();
449     process.OutputJson(stdout);
450 
451     EXPECT_STREQ(output.Stop().c_str(), "{\"pid\":2,\"eventCount\":3,\"threads\":[]}");
452 }
453 
454 /**
455  * @tc.name: ReportConfigItem
456  * @tc.desc:
457  * @tc.type: FUNC
458  */
459 HWTEST_F(ReportJsonFileTest, ReportConfigItem, TestSize.Level1)
460 {
461     StdoutRecord output;
462     ReportConfigItem config(1, "configname");
463     config.eventCount_ = 3;
464 
465     output.Start();
466     config.OutputJson(stdout);
467 
468     EXPECT_STREQ(output.Stop().c_str(),
469                  "{\"eventConfigName\":\"configname\",\"eventCount\":3,\"processes\":[]}");
470 }
471 
472 /**
473  * @tc.name: UpdateReportSample
474  * @tc.desc:
475  * @tc.type: FUNC
476  */
477 HWTEST_F(ReportJsonFileTest, UpdateReportSample, TestSize.Level1)
478 {
479     StdoutRecord output;
480     VirtualRuntime virtualRuntime;
481     ReportJsonFile json(nullptr, virtualRuntime);
482     std::vector<uint64_t> ids = {1, 2, 3};
483     json.reportConfigItems_.emplace(ids, ReportConfigItem(1, "eventName"));
484     // id , pid , tid , event count
485     json.UpdateReportSample(1, 2, 3, 4);
486     auto configIt = json.reportConfigItems_.begin();
487 
488     EXPECT_EQ(configIt->second.eventCount_, 4u);
489     ASSERT_EQ(configIt->second.processes_.size(), 1u);
490     EXPECT_EQ(configIt->second.processes_.at(2).pid_, 2);
491     EXPECT_EQ(configIt->second.processes_.at(2).eventCount_, 4u);
492     ASSERT_EQ(configIt->second.processes_.at(2).threads_.size(), 1u);
493     EXPECT_EQ(configIt->second.processes_.at(2).threads_.at(3).tid_, 3);
494     EXPECT_EQ(configIt->second.processes_.at(2).threads_.at(3).eventCount_, 4u);
495     EXPECT_EQ(configIt->second.processes_.at(2).threads_.at(3).sampleCount_, 1u);
496     EXPECT_EQ(json.sampleCount_, 1u);
497 }
498 
499 /**
500  * @tc.name: UpdateReportCallStack
501  * @tc.desc:
502  * @tc.type: FUNC
503  */
504 HWTEST_F(ReportJsonFileTest, UpdateReportCallStack, TestSize.Level1)
505 {
506     StdoutRecord output;
507     VirtualRuntime virtualRuntime;
508     std::unique_ptr<ReportJsonFile> json = PrepairReportJson(virtualRuntime);
509 
510     // check
511     auto configIt = json->reportConfigItems_.begin();
512 
513     // this should not update here
514     EXPECT_EQ(configIt->second.eventCount_, 0u);
515     ASSERT_EQ(configIt->second.processes_.size(), 1u);
516     ASSERT_EQ(configIt->second.processes_.begin()->second.threads_.size(), 2u);
517     ReportProcessItem &process = configIt->second.processes_.begin()->second;
518     ReportThreadItem &thread = process.threads_.begin()->second;
519     // only liba and libb
520     ASSERT_EQ(thread.libs_.size(), 2u);
521     ReportLibItem &lib = thread.libs_.begin()->second;
522     // we have to function , a1 and a2 in liba
523     ASSERT_EQ(lib.libId_, 0);
524     ASSERT_EQ(lib.funcs_.size(), 2u);
525 
526     // chec func count
527     ReportFuncItem &funca1 = lib.funcs_.at(0);
528     ReportFuncItem &funca2 = lib.funcs_.at(1);
529 
530     // only fist one have count
531     ASSERT_EQ(funca1.eventCount_, 10u);
532     ASSERT_EQ(funca1.subTreeEventCount_, 10u);
533     ASSERT_EQ(funca2.eventCount_, 0u);
534     ASSERT_EQ(funca2.subTreeEventCount_, 10u);
535 }
536 
537 /**
538  * @tc.name: UpdateCallNodeEventCount
539  * @tc.desc:
540  * @tc.type: FUNC
541  */
542 HWTEST_F(ReportJsonFileTest, UpdateCallNodeEventCount, TestSize.Level1)
543 {
544     StdoutRecord output;
545     VirtualRuntime virtualRuntime;
546     std::unique_ptr<ReportJsonFile> json = PrepairReportJson(virtualRuntime);
547 
548     auto configIt = json->reportConfigItems_.begin();
549     ReportProcessItem &process = configIt->second.processes_.begin()->second;
550     ReportThreadItem &thread = process.threads_.begin()->second;
551     ReportLibItem &lib = thread.libs_.begin()->second;
552 
553     ReportFuncItem &funca1 = lib.funcs_.at(0);
554     ReportFuncItem &funca2 = lib.funcs_.at(1);
555 
556     // only fist one have count
557     EXPECT_EQ(funca1.eventCount_, 10u);
558     EXPECT_EQ(funca1.subTreeEventCount_, 10u);
559     EXPECT_EQ(funca2.eventCount_, 0u);
560     EXPECT_EQ(funca2.subTreeEventCount_, 10u);
561     EXPECT_EQ(thread.callNode.subTreeEventCount_, 0u);
562     EXPECT_EQ(thread.callNodeReverse.subTreeEventCount_, 0u);
563 
564     json->UpdateCallNodeEventCount();
565     EXPECT_EQ(thread.callNode.subTreeEventCount_, 10u);
566     EXPECT_EQ(thread.callNodeReverse.subTreeEventCount_, 10u);
567 }
568 
569 /**
570  * @tc.name: ProcessSymbolsFiles
571  * @tc.desc:
572  * @tc.type: FUNC
573  */
574 HWTEST_F(ReportJsonFileTest, ProcessSymbolsFiles, TestSize.Level1)
575 {
576     VirtualRuntime virtualRuntime;
577     std::unique_ptr<ReportJsonFile> json =
578         std::make_unique<ReportJsonFile>(nullptr, virtualRuntime);
579     std::vector<std::unique_ptr<SymbolsFile>> symbolsFiles;
580 
581     std::string userSymbol = "user_symbol";
582     std::unique_ptr<SymbolsFile> user = SymbolsFile::CreateSymbolsFile(SYMBOL_ELF_FILE);
583     user->symbols_.emplace_back(0x1, 1u, "first_user_func", user->filePath_);
584     user->symbols_.emplace_back(0x2, 1u, "second_user_func", user->filePath_);
585     user->filePath_ = userSymbol;
586     symbolsFiles.emplace_back(std::move(user));
587 
588     std::string userSymbol2 = "user_symbol2";
589     std::unique_ptr<SymbolsFile> user2 = SymbolsFile::CreateSymbolsFile(SYMBOL_ELF_FILE);
590     user2->symbols_.emplace_back(0x1, 1u, "first_user2_func", user2->filePath_);
591     user2->symbols_.emplace_back(0x2, 1u, "second_user2_func", user2->filePath_);
592     user2->symbols_.emplace_back(0x3, 1u, "third_user2_func", user2->filePath_);
593     user2->filePath_ = userSymbol2;
594     symbolsFiles.emplace_back(std::move(user2));
595 
596     json->ProcessSymbolsFiles(symbolsFiles);
597     EXPECT_EQ(json->libList_.size(), 2u);
598     EXPECT_EQ(json->functionList_.size(), 5u);
599     EXPECT_EQ(json->functionMap_.size(), 5u);
600 }
601 
602 /**
603  * @tc.name: GetFuncionID
604  * @tc.desc:
605  * @tc.type: FUNC
606  */
607 HWTEST_F(ReportJsonFileTest, GetFuncionID, TestSize.Level1)
608 {
609     StdoutRecord output;
610     VirtualRuntime virtualRuntime;
611     std::unique_ptr<ReportJsonFile> json = PrepairReportJson(virtualRuntime);
612     /*
613         3 lib : liba , libb and libc
614         5 func :
615             funca1 in liba
616             funca2 in liba
617             funcb1 in libb
618             funcc1 in libc
619     */
620     EXPECT_EQ(json->GetFuncionID(0, "funca1"), 0);
621     EXPECT_EQ(json->GetFuncionID(0, "funca2"), 1);
622     EXPECT_EQ(json->GetFuncionID(0, "funca3"), 4);
623     EXPECT_EQ(json->GetFuncionID(0, "funcb1"), 5);
624     EXPECT_EQ(json->GetFuncionID(1, "funcb1"), 2);
625     EXPECT_EQ(json->GetFuncionID(2, "funcc1"), 3);
626 }
627 
628 /**
629  * @tc.name: GetLibID
630  * @tc.desc:
631  * @tc.type: FUNC
632  */
633 HWTEST_F(ReportJsonFileTest, GetLibID, TestSize.Level1)
634 {
635     StdoutRecord output;
636     VirtualRuntime virtualRuntime;
637     std::unique_ptr<ReportJsonFile> json = PrepairReportJson(virtualRuntime);
638     /*
639         3 lib : liba , libb and libc
640         5 func :
641             funca1 in liba
642             funca2 in liba
643             funcb1 in libb
644             funcc1 in libc
645     */
646     EXPECT_EQ(json->GetLibID("liba"), 0);
647     EXPECT_EQ(json->GetLibID("libb"), 1);
648     EXPECT_EQ(json->GetLibID("libc"), 2);
649     EXPECT_EQ(json->GetLibID("libd"), -1);
650     EXPECT_EQ(json->GetLibID(""), -1);
651 }
652 
653 /**
654  * @tc.name: GetConfigIndex
655  * @tc.desc:
656  * @tc.type: FUNC
657  */
658 HWTEST_F(ReportJsonFileTest, GetConfigIndex, TestSize.Level1)
659 {
660     StdoutRecord output;
661     VirtualRuntime virtualRuntime;
662     std::unique_ptr<ReportJsonFile> json = PrepairReportJson(virtualRuntime);
663 
664     std::vector<uint64_t> ids = {4, 5};
665     json->reportConfigItems_.emplace(
666         ids, ReportConfigItem(json->reportConfigItems_.size(), "eventName2"));
667 
668     EXPECT_EQ(json->GetConfigIndex(1), 0u);
669     EXPECT_EQ(json->GetConfigIndex(2), 0u);
670     EXPECT_EQ(json->GetConfigIndex(3), 0u);
671     EXPECT_EQ(json->GetConfigIndex(4), 1u);
672     EXPECT_EQ(json->GetConfigIndex(5), 1u);
673     EXPECT_EQ(json->GetConfigIndex(6), 0u);
674 }
675 
676 /**
677  * @tc.name: GetConfigName
678  * @tc.desc:
679  * @tc.type: FUNC
680  */
681 HWTEST_F(ReportJsonFileTest, GetConfigName, TestSize.Level1)
682 {
683     StdoutRecord output;
684     VirtualRuntime virtualRuntime;
685     std::unique_ptr<ReportJsonFile> json = PrepairReportJson(virtualRuntime);
686 
687     std::vector<uint64_t> ids = {4, 5};
688     json->reportConfigItems_.emplace(
689         ids, ReportConfigItem(json->reportConfigItems_.size(), "eventName2"));
690 
691     EXPECT_STREQ(json->GetConfigName(1).c_str(), "eventName");
692     EXPECT_STREQ(json->GetConfigName(2).c_str(), "eventName");
693     EXPECT_STREQ(json->GetConfigName(3).c_str(), "eventName");
694     EXPECT_STREQ(json->GetConfigName(4).c_str(), "eventName2");
695     EXPECT_STREQ(json->GetConfigName(5).c_str(), "eventName2");
696     EXPECT_STREQ(json->GetConfigName(6).c_str(), "eventName");
697 }
698 
699 /**
700  * @tc.name: GetConfig
701  * @tc.desc:
702  * @tc.type: FUNC
703  */
704 HWTEST_F(ReportJsonFileTest, GetConfig, TestSize.Level1)
705 {
706     StdoutRecord output;
707     VirtualRuntime virtualRuntime;
708     std::unique_ptr<ReportJsonFile> json = PrepairReportJson(virtualRuntime);
709 
710     std::vector<uint64_t> ids = {4, 5};
711     json->reportConfigItems_.emplace(
712         ids, ReportConfigItem(json->reportConfigItems_.size(), "eventName2"));
713 
714     EXPECT_EQ(json->GetConfig(1).index_, 0);
715     EXPECT_EQ(json->GetConfig(2).index_, 0);
716     EXPECT_EQ(json->GetConfig(3).index_, 0);
717     EXPECT_EQ(json->GetConfig(4).index_, 1);
718     EXPECT_EQ(json->GetConfig(5).index_, 1);
719     EXPECT_EQ(json->GetConfig(6).index_, 0);
720 }
721 } // namespace HiPerf
722 } // namespace Developtools
723 } // namespace OHOS
724