• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 "hiperf_libreport_test.h"
17 #include "debug_logger.h"
18 #include "hiperf_libreport.h"
19 #include "subcommand_dump.h"
20 #include "subcommand_report.h"
21 #include "utilities.h"
22 
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Developtools {
27 namespace HiPerf {
28 constexpr const char *PERF_DATA_INPUT_PATH =
29     "/data/test/resource/testdata/report/perf.data.libreport";
30 #ifdef __arm__
31 constexpr const char *PERF_DISABLE_UNWIND_DATA_INPUT_PATH =
32     "/data/test/resource/testdata/report/perf.disable.unwind.hiperf_example_cmd.data";
33 #else
34 constexpr const char *PERF_DISABLE_UNWIND_DATA_INPUT_PATH =
35     "/data/test/resource/testdata/report/perf.disable.unwind.hiperf_example_cmd_64.data";
36 #endif
37 constexpr const char *PERF_DISABLE_UNWIND_SYMBOL_INPUT_PATH = "/data/test/resource/testdata/report";
38 constexpr const char *PERF_DATA_ERROR_FORMAT_INPUT_PATH =
39     "/data/test/resource/testdata/report/perf.data.error.format.libreport";
40 constexpr const char *REPORT_OUTPUT_PATH = "./report.txt";
41 constexpr const char *REPORT_JSON_OUTPUT_PATH = "./perf.json";
42 
43 constexpr const char *ILLEGAL_PATH = "/proc/illegal";
44 
45 constexpr const char *TEST_ELF32 = "/data/test/resource/testdata/report/buildid_test_elf_32";
46 constexpr const char *BUILDID_TEST_ELF32 = "8e5a30338be326934ff93c998dcd0d22fe345870";
47 
48 constexpr const char *TEST_ELF64 = "/data/test/resource/testdata/report/buildid_test_elf_64";
49 constexpr const char *BUILDID_TEST_ELF64 = "24c55dccc5baaaa140da0083207abcb8d523e248";
50 
51 constexpr const char *TEST_ELF_BROKEN = "/data/test/resource/testdata/report/elf32_test_broken";
52 
53 class HiperfLibReportTest : public testing::Test {
54 public:
55     static void SetUpTestCase(void);
56     static void TearDownTestCase(void);
57     void SetUp();
58     void TearDown();
59     void DefaultReportContentCheck(const std::string &) const;
60     void DefaultDumpContentCheck(const std::string &) const;
61     void DefaultJsonContentCheck(const std::string &) const;
62     void UnwindJsonContentCheck(const std::string &, bool haveUnwind) const;
63     void DefaultSymbolsBuildIdContentCheck(const std::string &) const;
64 };
65 
DefaultSymbolsBuildIdContentCheck(const std::string & content) const66 void HiperfLibReportTest::DefaultSymbolsBuildIdContentCheck(const std::string &content) const
67 {
68     constexpr const char *buildIdList =
69         "[/system/lib/libhilogutil.so,c32713a57e92190404f8e46e19346a08],"
70         "[/system/lib/libhilog_os_adapter.z.so,6fb456cf373eb617e129c89b6f5982d9],"
71         "[/system/lib/libhilog.so,07daae0a6ed91e8ba56a0c76d6a3ac4a],[/system/lib/"
72         "libc++.so,38fdac430dfe95b261aa33d3d7cf553415686ba6],"
73         "[/system/lib/libutils.z.so,f24970cefc3e5fac09fe07168f9353f9],"
74         "[/system/bin/ld-musl-arm.so.1,],[/system/lib/libmpi.so,],"
75         "[/system/lib/libhi_osal.so,],[/system/lib/libhi3516cv500_vo.so,],[/system/"
76         "lib/libhi3516cv500_vdec.so,],[/system/lib/libhi3516cv500_sys.so,],[/system/lib/"
77         "libhi3516cv500_chnl.so,],[/system/lib/libffi.z.so,3b0380999b8469ed9b1ebd252d6cb08f],[/"
78         "system/lib/libdsoftbus_trans_direct_channel_sdk.z.so,f3c136104d821facf3573b7c34f36097],[/"
79         "system/lib/libipc_core.z.so,5a11ea1cacdad9d160eb8101f5a89e68],[/system/lib/"
80         "libtel_core_service.z.so,9dbeadf74de1d9cc83c25fbce88203ed],[/system/lib/"
81         "libace_napi_quickjs.z.so,99850793579d24a88d20931ab40147c0],[/system/lib/"
82         "libace_engine_qjs.z.so,34dfa8cbdeb49bb797ad306cc6a3e418],[/system/lib/"
83         "libvsync_client.z.so,4d6c9ae5004f39e16a4cd6194a2c1f80],[/system/lib/"
84         "libace.z.so,b8d9d3bb0184ba917e8d05d471e8387a],[/system/lib/"
85         "libeventhandler.z.so,b1e08a8a6eabe33363f721b14393b06b],[/system/bin/"
86         "hilogd,b11a9f3700884ded33879f81914e3aa2],[/system/bin/"
87         "wifi_hal_service,6beba486dcdf5debb5c9248bc5cdf5f0],[/data/local/tmp/"
88         "hiperf,32aa1e9c5f35d49e16fa1b6e86db130c],[/system/bin/"
89         "hiview,419493d9ccef1df5dedfa4a144249e49],[/system/lib/"
90         "libhiviewbase.z.so,349d82d4f1d2dc21c039156afbe470ad],[/system/lib/"
91         "libvsync_module.z.so,b8ad1b79c5816a6540a08d21ff88ac66],[[kernel.kallsyms],"
92         "ec918ed092bf1820cfdd9dbad43b19fbe0695472],[/vendor/modules/"
93         "hi_mipi_rx.ko,df9b94ace268f6ea6e43bb29a2e4d0e48cb5847d],[/vendor/modules/"
94         "hi3516cv500_hdmi.ko,0968b8fa34aa7f26dc5b953785933aeb62b3d5d5],[/vendor/modules/"
95         "hifb.ko,939f84e15d744af033284c1e6a6cd047ed3a5da9],[/vendor/modules/"
96         "hi3516cv500_vo_dev.ko,d391f542c407edb116fc16f45d25cc5fbee9f287],[/vendor/modules/"
97         "hi3516cv500_tde.ko,417a56e829c0773c5ed2303bf33ab51a50c414d7],[/vendor/modules/"
98         "hi3516cv500_sys.ko,221223701496c08e458bc7b98f17cb5f8ec54e7c],[/vendor/modules/"
99         "hi3516cv500_base.ko,20fc3ae721d798ba72fd62a78bc7c3c9a4007446],[/vendor/modules/"
100         "sys_config.ko,8f245b1e73775567c74574f912a96a26d1cb02c8],[/vendor/modules/"
101         "hi_proc.ko,789cbddace68515aea94aa2b7f0cbf2b81d48c9f],[/vendor/modules/"
102         "hi_irq.ko,3048ea5e3ed49489a876fe9ad4fcdbe73820f751],[/vendor/modules/"
103         "hi_osal.ko,3f7b2c2f0030a13dbd01c58f5b52eb0a1dd427af]";
104 
105     ASSERT_TRUE(content.size() >= 2u);
106     ASSERT_EQ(content.front(), '[');
107     ASSERT_EQ(content.back(), ']');
108     std::vector<std::string> fileBuildPairs = StringSplit(content, "[");
109     for (std::string &pair : fileBuildPairs) {
110         std::vector<std::string> buildIdPair = StringSplit(pair, ",");
111         ASSERT_EQ(buildIdPair.size(), 2u);
112     }
113     EXPECT_STREQ(content.c_str(), buildIdList);
114 }
115 
DefaultJsonContentCheck(const std::string & content) const116 void HiperfLibReportTest::DefaultJsonContentCheck(const std::string &content) const
117 {
118     /*
119         json must have { xxx  } format
120     */
121     ASSERT_TRUE(content.size() >= 2); // 2: args size
122     ASSERT_EQ(content.front(), '{');
123     ASSERT_EQ(content.back(), '}');
124 }
125 
UnwindJsonContentCheck(const std::string & content,bool haveUnwind) const126 void HiperfLibReportTest::UnwindJsonContentCheck(const std::string &content, bool haveUnwind) const
127 {
128     ASSERT_TRUE(content.size() >= 2); // 2: args size
129     ASSERT_EQ(content.front(), '{');
130     ASSERT_EQ(content.back(), '}');
131 #ifdef __arm__
132     ASSERT_EQ(content.find("{\"symbol\":6511,\"counts\":[3,548767,2923570]}") != std::string::npos,
133               haveUnwind);
134 #else
135     ASSERT_EQ(content.find("{\"symbol\":76,\"counts\":[0,0,147027]}") != std::string::npos,
136               haveUnwind);
137 #endif
138 }
139 
DefaultReportContentCheck(const std::string & content) const140 void HiperfLibReportTest::DefaultReportContentCheck(const std::string &content) const
141 {
142     /*
143 <<Hiperf Report>>
144 hostname: localhost
145 osrelease: 5.10.57
146 arch: armv7l
147 cpudesc: ARMv7 Processor rev 5 (v7l)
148 cmdline: ./hiperf --verbose record -d 1 -a
149 hiperf_record_time: Thu Jan  1 00:38:40 1970
150 Samples Count: 1000
151 Record Count: 3329
152 Event Count: 174434595
153     */
154 
155     // we found 198 times in report.txt
156     size_t kernelKallsymsCount = 198;
157 
158     EXPECT_EQ(content.find("hostname: localhost") != std::string::npos, true);
159     EXPECT_EQ(content.find("osrelease: 5.10.57") != std::string::npos, true);
160     EXPECT_EQ(content.find("arch: armv7l") != std::string::npos, true);
161     EXPECT_EQ(content.find("cpudesc: ARMv7 Processor rev 5 (v7l)") != std::string::npos, true);
162     EXPECT_EQ(content.find("hiperf_record_time: Thu Jan  1 00:38:40 1970") != std::string::npos,
163               true);
164     EXPECT_EQ(content.find("cmdline: ./hiperf --verbose record -d 1 -a") != std::string::npos,
165               true);
166 
167     EXPECT_EQ(content.find("Event: hw-cpu-cycles (type 0 id 0)") != std::string::npos, true);
168     EXPECT_EQ(content.find("Samples Count: 1000") != std::string::npos, true);
169     EXPECT_EQ(content.find("Event Count: 174434595") != std::string::npos, true);
170     EXPECT_EQ(SubStringCount(content, "[kernel.kallsyms]"), kernelKallsymsCount);
171 }
172 
DefaultDumpContentCheck(const std::string & content) const173 void HiperfLibReportTest::DefaultDumpContentCheck(const std::string &content) const
174 {
175     /*
176 magic: PERFILE2
177 header_size: 104
178 attr_size: 136
179 attrs[file section]: offset 112, size 136
180 data[file section]: offset 248, size 368316
181 event_types[file section]: offset 0, size 0
182 adds_features[]: 0x1DD8 0x0 0x0 0x5
183 feature: hostname
184 feature: osrelease
185 feature: arch
186 feature: nrcpus
187 feature: cpudesc
188 feature: total_mem
189 feature: cmdline
190 feature: event_desc
191 feature: hiperf_files_symbol
192 feature: hiperf_record_time
193 attr 1:
194   event_attr:
195     type 0, size 120, config 0
196     sample_freq 4000
197     sample_type (0x103e7)
198     sample_type names: ip,tid,time,callchain,id,cpu,period,stream_id,identifier
199     read_format (0x7)
200     disabled 1, inherit 1, pinned 0, exclusive 0
201     exclude_user 0, exclude_kernel 0, exclude_hv 0, exclude_idle 0
202     mmap 1, mmap2 1, comm 1, comm_exec 0, freq 1
203     inherit_stat 0, enable_on_exec 0, task 0, use_clockid 0
204     watermark 0, precise_ip 0, mmap_data 1, clockid 0
205     sample_id_all 0, exclude_host 0, exclude_guest 0
206     branch_sample_type 0x0
207     exclude_callchain_kernel 0, exclude_callchain_user 0
208     sample_regs_user 0x0
209     sample_stack_user 0x0
210   ids: 12
211     */
212 
213     size_t symbolsCount = 39;
214     size_t buildIdCount = 32;
215     size_t sampleCount = 1000;
216     size_t featureCount = 10;
217 
218     EXPECT_EQ(content.find("magic: PERFILE2") != std::string::npos, true);
219     EXPECT_EQ(SubStringCount(content, "fileid:"), symbolsCount);
220     EXPECT_EQ(SubStringCount(content, "buildId:"), buildIdCount);
221     EXPECT_EQ(SubStringCount(content, "record sample:"), sampleCount);
222     EXPECT_EQ(SubStringCount(content, "feature:"), featureCount);
223 }
SetUpTestCase()224 void HiperfLibReportTest::SetUpTestCase() {}
225 
TearDownTestCase()226 void HiperfLibReportTest::TearDownTestCase()
227 {
228     DebugLogger::GetInstance()->Reset();
229 }
230 
SetUp()231 void HiperfLibReportTest::SetUp() {}
232 
TearDown()233 void HiperfLibReportTest::TearDown() {}
234 
235 HWTEST_F(HiperfLibReportTest, Test_EchoLoopBackNumber, TestSize.Level0)
236 {
237     const char *result = EchoLoopBack("123");
238     EXPECT_EQ(result, "123");
239 }
240 
241 HWTEST_F(HiperfLibReportTest, Test_EchoLoopBackString, TestSize.Level0)
242 {
243     const char *result = EchoLoopBack("test");
244     EXPECT_EQ(result, "test");
245 }
246 
247 HWTEST_F(HiperfLibReportTest, Test_EchoLoopBackStringNumber, TestSize.Level1)
248 {
249     const char *result = EchoLoopBack("test123");
250     EXPECT_EQ(result, "test123");
251 }
252 HWTEST_F(HiperfLibReportTest, Test_EchoLoopBackEmpty, TestSize.Level2)
253 {
254     const char *result = EchoLoopBack("");
255     EXPECT_EQ(result, "");
256 }
257 
258 HWTEST_F(HiperfLibReportTest, Test_EchoLoopBackNull, TestSize.Level2)
259 {
260     const char *result = EchoLoopBack(nullptr);
261     EXPECT_EQ(result, nullptr);
262 }
263 
264 #ifdef HIPERF_DEBUG
265 HWTEST_F(HiperfLibReportTest, Test_SetDebug_Enable, TestSize.Level1)
266 {
267     EXPECT_EQ(SetDebug(true), 0);
268     EXPECT_EQ(DebugLogger::logDisabled_, false);
269 }
270 
271 HWTEST_F(HiperfLibReportTest, Test_SetDebug_Disable, TestSize.Level2)
272 {
273     EXPECT_EQ(SetDebug(false), 0);
274     EXPECT_EQ(DebugLogger::logDisabled_, true);
275 }
276 #endif
277 
278 HWTEST_F(HiperfLibReportTest, Test_Report_Success, TestSize.Level1)
279 {
280     unlink(REPORT_OUTPUT_PATH);
281     EXPECT_NE(access(REPORT_OUTPUT_PATH, F_OK), 0);
282 
283     StdoutRecord stdoutRecord;
284     stdoutRecord.Start();
285     EXPECT_EQ(::Report(PERF_DATA_INPUT_PATH, REPORT_OUTPUT_PATH, ""), 0);
286     std::string stringOut = stdoutRecord.Stop();
287     EXPECT_EQ(stringOut.find("report done") != std::string::npos, true);
288     std::string content;
289     EXPECT_EQ(ReadFileToString(REPORT_OUTPUT_PATH, content), true);
290     DefaultReportContentCheck(content);
291 }
292 
293 HWTEST_F(HiperfLibReportTest, Test_Report_Source_Null, TestSize.Level2)
294 {
295     unlink(REPORT_OUTPUT_PATH);
296     EXPECT_NE(access(REPORT_OUTPUT_PATH, F_OK), 0);
297     EXPECT_NE(::Report(nullptr, REPORT_OUTPUT_PATH, ""), 0);
298     EXPECT_NE(access(REPORT_OUTPUT_PATH, F_OK), 0);
299 }
300 
301 HWTEST_F(HiperfLibReportTest, Test_Report_Target_Null, TestSize.Level3)
302 {
303     unlink(REPORT_OUTPUT_PATH);
304     EXPECT_NE(access(REPORT_OUTPUT_PATH, F_OK), 0);
305     EXPECT_NE(::Report(PERF_DATA_INPUT_PATH, nullptr, ""), 0);
306     EXPECT_NE(access(REPORT_OUTPUT_PATH, F_OK), 0);
307 }
308 
309 HWTEST_F(HiperfLibReportTest, Test_Report_Both_Null, TestSize.Level2)
310 {
311     unlink(REPORT_OUTPUT_PATH);
312     EXPECT_NE(access(REPORT_OUTPUT_PATH, F_OK), 0);
313     EXPECT_NE(::Report(nullptr, nullptr, ""), 0);
314     EXPECT_NE(access(REPORT_OUTPUT_PATH, F_OK), 0);
315 }
316 
317 HWTEST_F(HiperfLibReportTest, Test_Report_Parameter_Illegal, TestSize.Level3)
318 {
319     unlink(REPORT_OUTPUT_PATH);
320     EXPECT_NE(access(REPORT_OUTPUT_PATH, F_OK), 0);
321     EXPECT_NE(::Report(ILLEGAL_PATH, ILLEGAL_PATH, ""), 0);
322     EXPECT_NE(access(REPORT_OUTPUT_PATH, F_OK), 0);
323     EXPECT_NE(access(ILLEGAL_PATH, F_OK), 0);
324 }
325 
326 HWTEST_F(HiperfLibReportTest, Test_Report_Parameter_Empty, TestSize.Level2)
327 {
328     unlink(REPORT_OUTPUT_PATH);
329     EXPECT_NE(access(REPORT_OUTPUT_PATH, F_OK), 0);
330     EXPECT_NE(::Report("", "", ""), 0);
331     EXPECT_NE(access(REPORT_OUTPUT_PATH, F_OK), 0);
332     EXPECT_NE(access(ILLEGAL_PATH, F_OK), 0);
333 }
334 
335 HWTEST_F(HiperfLibReportTest, Test_Dump_IllegalPath, TestSize.Level3)
336 {
337     StdoutRecord stdoutRecord;
338     stdoutRecord.Start();
339     EXPECT_NE(::Dump(ILLEGAL_PATH), 0);
340 }
341 
342 HWTEST_F(HiperfLibReportTest, Test_ReportJson_Success, TestSize.Level0)
343 {
344     unlink(REPORT_JSON_OUTPUT_PATH);
345     EXPECT_NE(access(REPORT_JSON_OUTPUT_PATH, F_OK), 0);
346 
347     EXPECT_EQ(::ReportJson(PERF_DATA_INPUT_PATH, REPORT_JSON_OUTPUT_PATH), 0);
348     EXPECT_EQ(access(REPORT_JSON_OUTPUT_PATH, F_OK), 0);
349     std::string content;
350     EXPECT_EQ(ReadFileToString(REPORT_JSON_OUTPUT_PATH, content), true);
351     DefaultJsonContentCheck(content);
352 }
353 
354 HWTEST_F(HiperfLibReportTest, Test_ReportJson_ErrorFormat, TestSize.Level3)
355 {
356     unlink(REPORT_JSON_OUTPUT_PATH);
357     EXPECT_NE(access(REPORT_JSON_OUTPUT_PATH, F_OK), 0);
358 
359     EXPECT_NE(::ReportJson(PERF_DATA_ERROR_FORMAT_INPUT_PATH, REPORT_JSON_OUTPUT_PATH), 0);
360     if (access(REPORT_JSON_OUTPUT_PATH, F_OK) == 0) {
361         std::string content;
362         EXPECT_EQ(ReadFileToString(REPORT_JSON_OUTPUT_PATH, content), true);
363 
364         // have file but no content
365         EXPECT_EQ(content.empty(), true);
366     }
367 }
368 
369 HWTEST_F(HiperfLibReportTest, Test_ReportJson_IllegalPath, TestSize.Level3)
370 {
371     unlink(REPORT_JSON_OUTPUT_PATH);
372     EXPECT_NE(access(REPORT_JSON_OUTPUT_PATH, F_OK), 0);
373 
374     EXPECT_NE(::ReportJson(ILLEGAL_PATH, ILLEGAL_PATH), 0);
375     EXPECT_NE(access(REPORT_JSON_OUTPUT_PATH, F_OK), 0);
376     EXPECT_NE(access(ILLEGAL_PATH, F_OK), 0);
377 }
378 
379 HWTEST_F(HiperfLibReportTest, Test_ReportJson_Nullptr, TestSize.Level1)
380 {
381     unlink(REPORT_JSON_OUTPUT_PATH);
382     EXPECT_NE(access(REPORT_JSON_OUTPUT_PATH, F_OK), 0);
383 
384     EXPECT_NE(::ReportJson(nullptr, nullptr), 0);
385     EXPECT_NE(access(REPORT_JSON_OUTPUT_PATH, F_OK), 0);
386 }
387 
388 HWTEST_F(HiperfLibReportTest, Test_ReportJson_Empty, TestSize.Level1)
389 {
390     unlink(REPORT_JSON_OUTPUT_PATH);
391     EXPECT_NE(access(REPORT_JSON_OUTPUT_PATH, F_OK), 0);
392 
393     EXPECT_NE(::ReportJson("", ""), 0);
394     EXPECT_NE(access(REPORT_JSON_OUTPUT_PATH, F_OK), 0);
395 }
396 
397 HWTEST_F(HiperfLibReportTest, Test_ReportGetSymbolFiles_Success, TestSize.Level0)
398 {
399     const char *result = ReportGetSymbolFiles(PERF_DATA_INPUT_PATH);
400     ASSERT_NE(result, nullptr);
401     DefaultSymbolsBuildIdContentCheck(result);
402 }
403 
404 HWTEST_F(HiperfLibReportTest, Test_ReportGetSymbolFiles_ErrorFormat, TestSize.Level3)
405 {
406     const char *result = ReportGetSymbolFiles(PERF_DATA_ERROR_FORMAT_INPUT_PATH);
407     ASSERT_NE(result, nullptr);
408     EXPECT_EQ(result[0], '\0');
409 }
410 
411 HWTEST_F(HiperfLibReportTest, Test_ReportGetSymbolFiles_IllegalPath, TestSize.Level3)
412 {
413     const char *result = ReportGetSymbolFiles(ILLEGAL_PATH);
414     ASSERT_NE(result, nullptr);
415     EXPECT_EQ(result[0], '\0');
416 }
417 
418 HWTEST_F(HiperfLibReportTest, Test_ReportGetSymbolFiles_Nullptr, TestSize.Level2)
419 {
420     const char *result = ReportGetSymbolFiles(nullptr);
421     ASSERT_NE(result, nullptr);
422     EXPECT_EQ(result[0], '\0');
423 }
424 
425 HWTEST_F(HiperfLibReportTest, Test_ReportGetSymbolFiles_Empty, TestSize.Level1)
426 {
427     const char *result = ReportGetSymbolFiles("");
428     ASSERT_NE(result, nullptr);
429     EXPECT_EQ(result[0], '\0');
430 }
431 
432 HWTEST_F(HiperfLibReportTest, Test_ReportGetBuildId_32_Success, TestSize.Level1)
433 {
434     const char *result = ReportGetBuildId(TEST_ELF32);
435     ASSERT_NE(result, nullptr);
436     EXPECT_STREQ(result, BUILDID_TEST_ELF32);
437 }
438 
439 HWTEST_F(HiperfLibReportTest, Test_ReportGetBuildId_64_Success, TestSize.Level1)
440 {
441     const char *result = ReportGetBuildId(TEST_ELF64);
442     ASSERT_NE(result, nullptr);
443     EXPECT_STREQ(result, BUILDID_TEST_ELF64);
444 }
445 
446 HWTEST_F(HiperfLibReportTest, Test_ReportGetBuildId_Empty, TestSize.Level1)
447 {
448     const char *result = ReportGetBuildId("");
449     ASSERT_NE(result, nullptr);
450     EXPECT_STREQ(result, "");
451 }
452 
453 HWTEST_F(HiperfLibReportTest, Test_ReportGetBuildId_Nullptr, TestSize.Level2)
454 {
455     const char *result = ReportGetBuildId(TEST_ELF_BROKEN);
456     ASSERT_NE(result, nullptr);
457     EXPECT_STREQ(result, "");
458 }
459 
460 HWTEST_F(HiperfLibReportTest, Test_ReportGetBuildId_IllegalPath, TestSize.Level3)
461 {
462     const char *result = ReportGetBuildId(ILLEGAL_PATH);
463     ASSERT_NE(result, nullptr);
464     EXPECT_STREQ(result, "");
465 }
466 
467 HWTEST_F(HiperfLibReportTest, Test_ReportUnwindJson_Success, TestSize.Level0)
468 {
469     unlink(REPORT_JSON_OUTPUT_PATH);
470     EXPECT_NE(access(REPORT_JSON_OUTPUT_PATH, F_OK), 0);
471 
472     EXPECT_EQ(::ReportUnwindJson(PERF_DISABLE_UNWIND_DATA_INPUT_PATH, REPORT_JSON_OUTPUT_PATH,
473                                  PERF_DISABLE_UNWIND_SYMBOL_INPUT_PATH),
474               0);
475     EXPECT_EQ(access(REPORT_JSON_OUTPUT_PATH, F_OK), 0);
476     std::string content;
477     EXPECT_EQ(ReadFileToString(REPORT_JSON_OUTPUT_PATH, content), true);
478     UnwindJsonContentCheck(content, true);
479 }
480 
481 HWTEST_F(HiperfLibReportTest, Test_ReportUnwindJson_NoSymbols_Failed, TestSize.Level3)
482 {
483     unlink(REPORT_JSON_OUTPUT_PATH);
484     EXPECT_NE(access(REPORT_JSON_OUTPUT_PATH, F_OK), 0);
485 
486     EXPECT_EQ(
487         ::ReportUnwindJson(PERF_DISABLE_UNWIND_DATA_INPUT_PATH, REPORT_JSON_OUTPUT_PATH, nullptr),
488         0);
489     EXPECT_EQ(access(REPORT_JSON_OUTPUT_PATH, F_OK), 0);
490     std::string content;
491     EXPECT_EQ(ReadFileToString(REPORT_JSON_OUTPUT_PATH, content), true);
492     UnwindJsonContentCheck(content, false);
493 }
494 
495 HWTEST_F(HiperfLibReportTest, Test_ReportUnwindJson_ErrorFormat, TestSize.Level2)
496 {
497     unlink(REPORT_JSON_OUTPUT_PATH);
498     EXPECT_NE(access(REPORT_JSON_OUTPUT_PATH, F_OK), 0);
499 
500     EXPECT_NE(::ReportUnwindJson(PERF_DATA_ERROR_FORMAT_INPUT_PATH, REPORT_JSON_OUTPUT_PATH,
501                                  PERF_DISABLE_UNWIND_SYMBOL_INPUT_PATH),
502               0);
503     if (access(REPORT_JSON_OUTPUT_PATH, F_OK) == 0) {
504         std::string content;
505         EXPECT_EQ(ReadFileToString(REPORT_JSON_OUTPUT_PATH, content), true);
506 
507         // have file but no content
508         EXPECT_EQ(content.empty(), true);
509     }
510 }
511 
512 HWTEST_F(HiperfLibReportTest, Test_ReportUnwindJson_IllegalPath, TestSize.Level3)
513 {
514     unlink(REPORT_JSON_OUTPUT_PATH);
515     EXPECT_NE(access(REPORT_JSON_OUTPUT_PATH, F_OK), 0);
516 
517     EXPECT_NE(::ReportUnwindJson(ILLEGAL_PATH, ILLEGAL_PATH, ILLEGAL_PATH), 0);
518     EXPECT_NE(access(REPORT_JSON_OUTPUT_PATH, F_OK), 0);
519     EXPECT_NE(access(ILLEGAL_PATH, F_OK), 0);
520 }
521 
522 HWTEST_F(HiperfLibReportTest, Test_ReportUnwindJson_Nullptr, TestSize.Level2)
523 {
524     unlink(REPORT_JSON_OUTPUT_PATH);
525     EXPECT_NE(access(REPORT_JSON_OUTPUT_PATH, F_OK), 0);
526 
527     EXPECT_NE(::ReportUnwindJson(nullptr, nullptr, nullptr), 0);
528     EXPECT_NE(access(REPORT_JSON_OUTPUT_PATH, F_OK), 0);
529 }
530 
531 HWTEST_F(HiperfLibReportTest, Test_ReportUnwindJson_Empty, TestSize.Level1)
532 {
533     unlink(REPORT_JSON_OUTPUT_PATH);
534     EXPECT_NE(access(REPORT_JSON_OUTPUT_PATH, F_OK), 0);
535 
536     EXPECT_NE(::ReportUnwindJson("", "", ""), 0);
537     EXPECT_NE(access(REPORT_JSON_OUTPUT_PATH, F_OK), 0);
538 }
539 } // namespace HiPerf
540 } // namespace Developtools
541 } // namespace OHOS
542