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