• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gtest/gtest.h>
17 
18 #include "file_utils.h"
19 #include "flow_controller.h"
20 #include "ftrace_fs_ops.h"
21 
22 namespace {
23 using FTRACE_NS::FlowController;
24 using FTRACE_NS::FtraceFsOps;
25 using testing::ext::TestSize;
26 
27 constexpr uint32_t BUFFER_SIZE_KB = 256;
28 constexpr uint32_t FLUSH_INTERVAL_MS = 100;
29 constexpr uint32_t FLUSH_THRESHOLD_KB = 1024;
30 constexpr uint32_t TRACE_PERIOD_MS = 500;
31 using WriterStructPtr = std::unique_ptr<WriterStruct>::pointer;
32 using ConstVoidPtr = std::unique_ptr<const void>::pointer;
33 
34 long WriteFunc(WriterStructPtr writer, ConstVoidPtr data, size_t size);
35 bool FlushFunc(WriterStructPtr writer);
36 
37 class FtraceFsOpsTest : public ::testing::Test {
38 protected:
SetUpTestCase()39     static void SetUpTestCase()
40     {
41         // start tracing sched_switch event
42         FlowController controller;
43         TracePluginConfig config;
44 
45         // set writer
46         WriterStruct writer = {WriteFunc, FlushFunc};
47         controller.SetWriter(static_cast<WriterStructPtr>(&writer));
48         // stop capture firstly
49         controller.StopCapture();
50         // set config
51         config.add_ftrace_events("sched/sched_switch");
52         config.add_hitrace_categories("ability");
53         config.add_hitrace_categories("ace");
54         config.set_buffer_size_kb(BUFFER_SIZE_KB);
55         config.set_flush_interval_ms(FLUSH_INTERVAL_MS);
56         config.set_flush_threshold_kb(FLUSH_THRESHOLD_KB);
57         config.set_parse_ksyms(true);
58         config.set_clock("global");
59         config.set_trace_period_ms(TRACE_PERIOD_MS);
60         config.set_raw_data_prefix("/data/local/tmp/raw_trace_");
61         std::vector<uint8_t> configData(config.ByteSizeLong());
62         config.SerializeToArray(configData.data(), configData.size());
63         controller.LoadConfig(configData.data(), configData.size());
64         controller.StartCapture();
65         sleep(1);
66         controller.StopCapture();
67     }
68 
SetUp()69     void SetUp() override {}
TearDown()70     void TearDown() override {}
71 };
72 
WriteFunc(WriterStructPtr writer,ConstVoidPtr data,size_t size)73 long WriteFunc(WriterStructPtr writer, ConstVoidPtr data, size_t size)
74 {
75     if (writer == nullptr || data == nullptr || size <= 0) {
76         return -1;
77     }
78 
79     return 0;
80 }
81 
FlushFunc(WriterStructPtr writer)82 bool FlushFunc(WriterStructPtr writer)
83 {
84     if (writer == nullptr) {
85         return false;
86     }
87     return true;
88 }
89 
90 /*
91  * @tc.name: GetFtraceRoot
92  * @tc.desc: test FtraceFsOps::GetFtraceRoot with normal case.
93  * @tc.type: FUNC
94  */
95 HWTEST_F(FtraceFsOpsTest, GetFtraceRoot, TestSize.Level1)
96 {
97     std::string path = FtraceFsOps::GetInstance().GetFtraceRoot();
98     ASSERT_STRNE(path.c_str(), "");
99     EXPECT_TRUE((strcmp(path.c_str(), "/sys/kernel/tracing") || strcmp(path.c_str(), "/sys/kernel/debug/tracing")));
100 }
101 
102 /*
103  * @tc.name: GetKernelSymbols
104  * @tc.desc: test FtraceFsOps::GetKernelSymbols with normal case.
105  * @tc.type: FUNC
106  */
107 HWTEST_F(FtraceFsOpsTest, GetKernelSymbols, TestSize.Level1)
108 {
109     std::string content = FtraceFsOps::GetInstance().GetKernelSymbols();
110     EXPECT_STRNE(content.c_str(), "");
111 }
112 
113 /*
114  * @tc.name: GetPrintkFormatsNormal
115  * @tc.desc: test FtraceFsOps::GetPrintkFormats with normal case.
116  * @tc.type: FUNC
117  */
118 HWTEST_F(FtraceFsOpsTest, GetPrintkFormatsNormal, TestSize.Level1)
119 {
120     std::string content = FtraceFsOps::GetInstance().GetPrintkFormats();
121     EXPECT_STRNE(content.c_str(), "");
122 }
123 
124 /*
125  * @tc.name: GetPrintkFormatsFalse
126  * @tc.desc: test FtraceFsOps::GetPrintkFormats with false case.
127  * @tc.type: FUNC
128  */
129 HWTEST_F(FtraceFsOpsTest, GetPrintkFormatsFalse, TestSize.Level1)
130 {
131     FtraceFsOps ftraceFsOps;
132     ftraceFsOps.SetFtraceRoot("");
133     std::string content = ftraceFsOps.GetPrintkFormats();
134     EXPECT_STREQ(content.c_str(), "");
135 
136     ftraceFsOps.SetFtraceRoot("/test_path");
137     content = ftraceFsOps.GetPrintkFormats();
138     EXPECT_STREQ(content.c_str(), "");
139 }
140 
141 /*
142  * @tc.name: GetProcessCommNormal
143  * @tc.desc: test FtraceFsOps::GetProcessComm with normal case.
144  * @tc.type: FUNC
145  */
146 HWTEST_F(FtraceFsOpsTest, GetProcessCommNormal, TestSize.Level1)
147 {
148     int32_t pid = getpid();
149     std::string content = FtraceFsOps::GetInstance().GetProcessComm(pid);
150     EXPECT_STRNE(content.c_str(), "");
151 }
152 
153 /*
154  * @tc.name: GetProcessCommFalse
155  * @tc.desc: test FtraceFsOps::GetProcessComm with false case.
156  * @tc.type: FUNC
157  */
158 HWTEST_F(FtraceFsOpsTest, GetProcessCommFalse, TestSize.Level1)
159 {
160     std::string content = FtraceFsOps::GetInstance().GetProcessComm(-1);
161     EXPECT_STREQ(content.c_str(), "");
162 }
163 
164 /*
165  * @tc.name: GetThreadCommNormal
166  * @tc.desc: test FtraceFsOps::GetThreadComm with normal case.
167  * @tc.type: FUNC
168  */
169 HWTEST_F(FtraceFsOpsTest, GetThreadCommNormal, TestSize.Level1)
170 {
171     int32_t pid = getpid();
172     std::string content = FtraceFsOps::GetInstance().GetThreadComm(pid, pid);
173     EXPECT_STRNE(content.c_str(), "");
174 }
175 
176 /*
177  * @tc.name: GetThreadCommFalse
178  * @tc.desc: test FtraceFsOps::GetThreadComm with false case.
179  * @tc.type: FUNC
180  */
181 HWTEST_F(FtraceFsOpsTest, GetThreadCommFalse, TestSize.Level1)
182 {
183     FtraceFsOps ftraceFsOps;
184     std::string content = ftraceFsOps.GetThreadComm(-1, -1);
185     EXPECT_STREQ(content.c_str(), "");
186 
187     int32_t pid = getpid();
188     content = ftraceFsOps.GetThreadComm(pid, -1);
189     EXPECT_STREQ(content.c_str(), "");
190 
191     content = ftraceFsOps.GetThreadComm(-1, pid);
192     EXPECT_STREQ(content.c_str(), "");
193 }
194 
195 /*
196  * @tc.name: GetSavedCmdLinesNormal
197  * @tc.desc: test FtraceFsOps::GetSavedCmdLines with normal case.
198  * @tc.type: FUNC
199  */
200 HWTEST_F(FtraceFsOpsTest, GetSavedCmdLinesNormal, TestSize.Level1)
201 {
202     std::string content = FtraceFsOps::GetInstance().GetSavedCmdLines();
203     EXPECT_STRNE(content.c_str(), "");
204 }
205 
206 /*
207  * @tc.name: GetSavedCmdLinesFalse
208  * @tc.desc: test FtraceFsOps::GetSavedCmdLines with false case.
209  * @tc.type: FUNC
210  */
211 HWTEST_F(FtraceFsOpsTest, GetSavedCmdLinesFalse, TestSize.Level1)
212 {
213     FtraceFsOps ftraceFsOps;
214     ftraceFsOps.SetFtraceRoot("");
215     std::string content = ftraceFsOps.GetSavedCmdLines();
216     EXPECT_STREQ(content.c_str(), "");
217 
218     ftraceFsOps.SetFtraceRoot("/test_path");
219     content = ftraceFsOps.GetSavedCmdLines();
220     EXPECT_STREQ(content.c_str(), "");
221 }
222 
223 /*
224  * @tc.name: GetSavedTgidsNormal
225  * @tc.desc: test FtraceFsOps::GetSavedTgids with normal case.
226  * @tc.type: FUNC
227  */
228 HWTEST_F(FtraceFsOpsTest, GetSavedTgidsNormal, TestSize.Level1)
229 {
230     std::string content = FtraceFsOps::GetInstance().GetSavedTgids();
231     EXPECT_STRNE(content.c_str(), "");
232 }
233 
234 /*
235  * @tc.name: GetSavedTgidsFalse
236  * @tc.desc: test FtraceFsOps::GetSavedTgids with false case.
237  * @tc.type: FUNC
238  */
239 HWTEST_F(FtraceFsOpsTest, GetSavedTgidsFalse, TestSize.Level1)
240 {
241     FtraceFsOps ftraceFsOps;
242     ftraceFsOps.SetFtraceRoot("");
243     std::string content = ftraceFsOps.GetSavedTgids();
244     EXPECT_STREQ(content.c_str(), "");
245 
246     ftraceFsOps.SetFtraceRoot("/test_path");
247     content = ftraceFsOps.GetSavedTgids();
248     EXPECT_STREQ(content.c_str(), "");
249 }
250 
251 /*
252  * @tc.name: GetPerCpuStatsNormal
253  * @tc.desc: test FtraceFsOps::GetPerCpuStats with normal case.
254  * @tc.type: FUNC
255  */
256 HWTEST_F(FtraceFsOpsTest, GetPerCpuStatsNormal, TestSize.Level1)
257 {
258     if (!FtraceFsOps::GetInstance().IsHmKernel()) {
259         std::string content = FtraceFsOps::GetInstance().GetPerCpuStats(0);
260         EXPECT_STRNE(content.c_str(), "");
261     }
262 }
263 
264 /*
265  * @tc.name: GetPerCpuStatsFalse
266  * @tc.desc: test FtraceFsOps::GetPerCpuStats with false case.
267  * @tc.type: FUNC
268  */
269 HWTEST_F(FtraceFsOpsTest, GetPerCpuStatsFalse, TestSize.Level1)
270 {
271     if (!FtraceFsOps::GetInstance().IsHmKernel()) {
272         FtraceFsOps ftraceFsOps;
273         std::string content = ftraceFsOps.GetPerCpuStats(-1);
274         EXPECT_STREQ(content.c_str(), "");
275 
276         ftraceFsOps.SetFtraceRoot("");
277         content = ftraceFsOps.GetPerCpuStats(0);
278         EXPECT_STREQ(content.c_str(), "");
279 
280         ftraceFsOps.SetFtraceRoot("/test_path");
281         content = ftraceFsOps.GetPerCpuStats(0);
282         EXPECT_STREQ(content.c_str(), "");
283     }
284 }
285 
286 /*
287  * @tc.name: GetRawTracePath
288  * @tc.desc: test FtraceFsOps::GetRawTracePath with normal case.
289  * @tc.type: FUNC
290  */
291 HWTEST_F(FtraceFsOpsTest, GetRawTracePath, TestSize.Level1)
292 {
293     std::string content = FtraceFsOps::GetInstance().GetRawTracePath(0);
294     EXPECT_STRNE(content.c_str(), "");
295 }
296 
297 /*
298  * @tc.name: GetPageHeaderFormatNormal
299  * @tc.desc: test FtraceFsOps::GetPageHeaderFormat with normal case.
300  * @tc.type: FUNC
301  */
302 HWTEST_F(FtraceFsOpsTest, GetPageHeaderFormatNormal, TestSize.Level1)
303 {
304     if (!FtraceFsOps::GetInstance().IsHmKernel()) {
305         std::string content = FtraceFsOps::GetInstance().GetPageHeaderFormat();
306         EXPECT_STRNE(content.c_str(), "");
307     }
308 }
309 
310 /*
311  * @tc.name: GetPageHeaderFormatFalse
312  * @tc.desc: test FtraceFsOps::GetPageHeaderFormat with false case.
313  * @tc.type: FUNC
314  */
315 HWTEST_F(FtraceFsOpsTest, GetPageHeaderFormatFalse, TestSize.Level1)
316 {
317     FtraceFsOps ftraceFsOps;
318     ftraceFsOps.SetFtraceRoot("");
319     std::string content = ftraceFsOps.GetPageHeaderFormat();
320     EXPECT_STREQ(content.c_str(), "");
321 
322     ftraceFsOps.SetFtraceRoot("/test_path");
323     content = ftraceFsOps.GetPageHeaderFormat();
324     EXPECT_STREQ(content.c_str(), "");
325 }
326 
327 /*
328  * @tc.name: GetEventDataFormatNormal
329  * @tc.desc: test FtraceFsOps::GetEventDataFormat with normal case.
330  * @tc.type: FUNC
331  */
332 HWTEST_F(FtraceFsOpsTest, GetEventDataFormatNormal, TestSize.Level1)
333 {
334     std::string content = FtraceFsOps::GetInstance().GetEventDataFormat("irq", "softirq_entry");
335     EXPECT_STRNE(content.c_str(), "");
336 }
337 
338 /*
339  * @tc.name: GetEventDataFormatFalse
340  * @tc.desc: test FtraceFsOps::GetEventDataFormat with false case.
341  * @tc.type: FUNC
342  */
343 HWTEST_F(FtraceFsOpsTest, GetEventDataFormatFalse, TestSize.Level1)
344 {
345     FtraceFsOps ftraceFsOps;
346     std::string content = ftraceFsOps.GetEventDataFormat("test_type", "test_name");
347     EXPECT_STREQ(content.c_str(), "");
348 
349     ftraceFsOps.SetFtraceRoot("");
350     content = ftraceFsOps.GetEventDataFormat("irq", "softirq_entry");
351     EXPECT_STREQ(content.c_str(), "");
352 
353     ftraceFsOps.SetFtraceRoot("/test_path");
354     content = ftraceFsOps.GetEventDataFormat("irq", "softirq_entry");
355     EXPECT_STREQ(content.c_str(), "");
356 }
357 
358 /*
359  * @tc.name: GetPlatformEventsNormal
360  * @tc.desc: test FtraceFsOps::GetPlatformEvents with normal case.
361  * @tc.type: FUNC
362  */
363 HWTEST_F(FtraceFsOpsTest, GetPlatformEventsNormal, TestSize.Level1)
364 {
365     std::vector<std::pair<std::string, std::string>> event = FtraceFsOps::GetInstance().GetPlatformEvents();
366     EXPECT_GT(event.size(), static_cast<size_t>(0));
367 }
368 
369 /*
370  * @tc.name: GetPlatformEventsFalse
371  * @tc.desc: test FtraceFsOps::GetPlatformEvents with false case.
372  * @tc.type: FUNC
373  */
374 HWTEST_F(FtraceFsOpsTest, GetPlatformEventsFalse, TestSize.Level1)
375 {
376     FtraceFsOps ftraceFsOps;
377     ftraceFsOps.SetFtraceRoot("");
378     std::vector<std::pair<std::string, std::string>> event = ftraceFsOps.GetPlatformEvents();
379     EXPECT_EQ(event.size(), static_cast<size_t>(0));
380 
381     ftraceFsOps.SetFtraceRoot("/test_path");
382     event = ftraceFsOps.GetPlatformEvents();
383     EXPECT_EQ(event.size(), static_cast<size_t>(0));
384 }
385 
386 /*
387  * @tc.name: ClearTraceBufferNormal
388  * @tc.desc: test FtraceFsOps::ClearTraceBuffer with normal case.
389  * @tc.type: FUNC
390  */
391 HWTEST_F(FtraceFsOpsTest, ClearTraceBufferNormal, TestSize.Level1)
392 {
393     EXPECT_TRUE(FtraceFsOps::GetInstance().ClearTraceBuffer());
394 }
395 
396 /*
397  * @tc.name: ClearTraceBufferFalse
398  * @tc.desc: test FtraceFsOps::ClearTraceBuffer with false case.
399  * @tc.type: FUNC
400  */
401 HWTEST_F(FtraceFsOpsTest, ClearTraceBufferFalse, TestSize.Level1)
402 {
403     FtraceFsOps ftraceFsOps;
404     ftraceFsOps.SetFtraceRoot("");
405     EXPECT_FALSE(ftraceFsOps.ClearTraceBuffer());
406 
407     ftraceFsOps.SetFtraceRoot("/test_path");
408     EXPECT_FALSE(ftraceFsOps.ClearTraceBuffer());
409 }
410 
411 /*
412  * @tc.name: SetRecordCmdOptionNormal
413  * @tc.desc: test FtraceFsOps::SetRecordCmdOption with normal case.
414  * @tc.type: FUNC
415  */
416 HWTEST_F(FtraceFsOpsTest, SetRecordCmdOptionNormal, TestSize.Level1)
417 {
418     if (!FtraceFsOps::GetInstance().IsHmKernel()) {
419         EXPECT_TRUE(FtraceFsOps::GetInstance().SetRecordCmdOption(true));
420         std::string path = FtraceFsOps::GetInstance().ftraceRoot_ + "/options/record-cmd";
421         std::string content = FileUtils::ReadFile(path);
422         EXPECT_STREQ(content.c_str(), "1\n");
423         EXPECT_TRUE(FtraceFsOps::GetInstance().SetRecordCmdOption(false));
424         content = FileUtils::ReadFile(path);
425         EXPECT_STREQ(content.c_str(), "0\n");
426     }
427 }
428 
429 /*
430  * @tc.name: SetRecordCmdOptionFalse
431  * @tc.desc: test FtraceFsOps::SetRecordCmdOption with false case.
432  * @tc.type: FUNC
433  */
434 HWTEST_F(FtraceFsOpsTest, SetRecordCmdOptionFalse, TestSize.Level1)
435 {
436     FtraceFsOps ftraceFsOps;
437     ftraceFsOps.SetFtraceRoot("");
438     EXPECT_FALSE(ftraceFsOps.SetRecordCmdOption(true));
439     EXPECT_FALSE(ftraceFsOps.SetRecordCmdOption(false));
440 
441     ftraceFsOps.SetFtraceRoot("/test_path");
442     EXPECT_FALSE(ftraceFsOps.SetRecordCmdOption(true));
443     EXPECT_FALSE(ftraceFsOps.SetRecordCmdOption(false));
444 }
445 
446 /*
447  * @tc.name: SetRecordTgidOptionNormal
448  * @tc.desc: test FtraceFsOps::SetRecordTgidOption with normal case.
449  * @tc.type: FUNC
450  */
451 HWTEST_F(FtraceFsOpsTest, SetRecordTgidOptionNormal, TestSize.Level1)
452 {
453     if (!FtraceFsOps::GetInstance().IsHmKernel()) {
454         EXPECT_TRUE(FtraceFsOps::GetInstance().SetRecordTgidOption(true));
455         std::string path = FtraceFsOps::GetInstance().ftraceRoot_ + "/options/record-tgid";
456         std::string content = FileUtils::ReadFile(path);
457         EXPECT_STREQ(content.c_str(), "1\n");
458 
459         EXPECT_TRUE(FtraceFsOps::GetInstance().SetRecordTgidOption(false));
460         content = FileUtils::ReadFile(path);
461         EXPECT_STREQ(content.c_str(), "0\n");
462     }
463 }
464 
465 /*
466  * @tc.name: SetRecordTgidOptionFalse
467  * @tc.desc: test FtraceFsOps::SetRecordTgidOption with false case.
468  * @tc.type: FUNC
469  */
470 HWTEST_F(FtraceFsOpsTest, SetRecordTgidOptionFalse, TestSize.Level1)
471 {
472     FtraceFsOps ftraceFsOps;
473     ftraceFsOps.SetFtraceRoot("");
474     EXPECT_FALSE(ftraceFsOps.SetRecordTgidOption(true));
475     EXPECT_FALSE(ftraceFsOps.SetRecordTgidOption(false));
476 
477     ftraceFsOps.SetFtraceRoot("/test_path");
478     EXPECT_FALSE(ftraceFsOps.SetRecordTgidOption(true));
479     EXPECT_FALSE(ftraceFsOps.SetRecordTgidOption(false));
480 }
481 
482 /*
483  * @tc.name: SetBufferSizeKbNormal
484  * @tc.desc: test FtraceFsOps::SetBufferSizeKb with normal case.
485  * @tc.type: FUNC
486  */
487 HWTEST_F(FtraceFsOpsTest, SetBufferSizeKbNormal, TestSize.Level1)
488 {
489     EXPECT_TRUE(FtraceFsOps::GetInstance().SetBufferSizeKb(1024));
490     std::string path = FtraceFsOps::GetInstance().ftraceRoot_ + "/buffer_size_kb";
491     std::string content = FileUtils::ReadFile(path);
492 #ifdef __aarch64__
493     EXPECT_STREQ(content.c_str(), "1024\n");
494 #endif
495 }
496 
497 /*
498  * @tc.name: SetBufferSizeKbFalse
499  * @tc.desc: test FtraceFsOps::SetBufferSizeKb with false case.
500  * @tc.type: FUNC
501  */
502 HWTEST_F(FtraceFsOpsTest, SetBufferSizeKbFalse, TestSize.Level1)
503 {
504     FtraceFsOps ftraceFsOps;
505     ftraceFsOps.SetFtraceRoot("");
506     EXPECT_FALSE(ftraceFsOps.SetBufferSizeKb(1024));
507 
508     ftraceFsOps.SetFtraceRoot("/test_path");
509     EXPECT_FALSE(ftraceFsOps.SetBufferSizeKb(1024));
510 }
511 
512 /*
513  * @tc.name: SetTraceClockNormal
514  * @tc.desc: test FtraceFsOps::SetTraceClock with normal case.
515  * @tc.type: FUNC
516  */
517 HWTEST_F(FtraceFsOpsTest, SetTraceClockNormal, TestSize.Level1)
518 {
519     EXPECT_TRUE(FtraceFsOps::GetInstance().SetTraceClock("boot"));
520     std::string path = FtraceFsOps::GetInstance().ftraceRoot_ + "/trace_clock";
521     std::string content = FileUtils::ReadFile(path);
522     EXPECT_STRNE(content.c_str(), "");
523 }
524 
525 /*
526  * @tc.name: SetTraceClockFalse
527  * @tc.desc: test FtraceFsOps::SetTraceClock with false case.
528  * @tc.type: FUNC
529  */
530 HWTEST_F(FtraceFsOpsTest, SetTraceClockFalse, TestSize.Level1)
531 {
532     FtraceFsOps ftraceFsOps;
533     ftraceFsOps.SetFtraceRoot("");
534     EXPECT_FALSE(ftraceFsOps.SetTraceClock("uptime"));
535 
536     ftraceFsOps.SetFtraceRoot("/test_path");
537     EXPECT_FALSE(ftraceFsOps.SetTraceClock("uptime"));
538 }
539 
540 /*
541  * @tc.name: GetTraceClock
542  * @tc.desc: test FtraceFsOps::GetTraceClock with normal case.
543  * @tc.type: FUNC
544  */
545 HWTEST_F(FtraceFsOpsTest, GetTraceClock, TestSize.Level1)
546 {
547     std::string content = FtraceFsOps::GetInstance().GetTraceClock();
548     EXPECT_STRNE(content.c_str(), "");
549 }
550 
551 /*
552  * @tc.name: AppendSetEventNormal
553  * @tc.desc: test FtraceFsOps::AppendSetEvent with normal case.
554  * @tc.type: FUNC
555  */
556 HWTEST_F(FtraceFsOpsTest, AppendSetEventNormal, TestSize.Level1)
557 {
558     if (!FtraceFsOps::GetInstance().IsHmKernel()) {
559         EXPECT_TRUE(FtraceFsOps::GetInstance().ClearSetEvent());
560         EXPECT_TRUE(FtraceFsOps::GetInstance().AppendSetEvent("sched", "sched_switch"));
561     }
562     std::string path = FtraceFsOps::GetInstance().ftraceRoot_ + "/set_event";
563     std::string content = FileUtils::ReadFile(path);
564     EXPECT_STRNE(content.c_str(), "");
565 }
566 
567 /*
568  * @tc.name: AppendSetEventFalse
569  * @tc.desc: test FtraceFsOps::AppendSetEvent with false case.
570  * @tc.type: FUNC
571  */
572 HWTEST_F(FtraceFsOpsTest, AppendSetEventFalse, TestSize.Level1)
573 {
574     FtraceFsOps ftraceFsOps;
575     ftraceFsOps.SetFtraceRoot("");
576     EXPECT_FALSE(ftraceFsOps.AppendSetEvent("sched", "sched_switch"));
577 
578     ftraceFsOps.SetFtraceRoot("/test_path");
579     EXPECT_FALSE(ftraceFsOps.AppendSetEvent("sched", "sched_switch"));
580 }
581 
582 /*
583  * @tc.name: EnableEventNormal
584  * @tc.desc: test FtraceFsOps::EnableEvent with normal case.
585  * @tc.type: FUNC
586  */
587 HWTEST_F(FtraceFsOpsTest, EnableEventNormal, TestSize.Level1)
588 {
589     EXPECT_TRUE(FtraceFsOps::GetInstance().EnableEvent("sched", "sched_switch"));
590     std::string path = FtraceFsOps::GetInstance().ftraceRoot_ + "/events/sched/sched_switch/enable";
591     std::string content = FileUtils::ReadFile(path);
592     EXPECT_STREQ(content.c_str(), "1\n");
593 }
594 
595 /*
596  * @tc.name: EnableEventFalse
597  * @tc.desc: test FtraceFsOps::EnableEvent with false case.
598  * @tc.type: FUNC
599  */
600 HWTEST_F(FtraceFsOpsTest, EnableEventFalse, TestSize.Level1)
601 {
602     FtraceFsOps ftraceFsOps;
603     ftraceFsOps.SetFtraceRoot("");
604     EXPECT_FALSE(ftraceFsOps.EnableEvent("sched", "sched_switch"));
605 
606     ftraceFsOps.SetFtraceRoot("/test_path");
607     EXPECT_FALSE(ftraceFsOps.EnableEvent("sched", "sched_switch"));
608 }
609 
610 /*
611  * @tc.name: DisableEventNormal
612  * @tc.desc: test FtraceFsOps::DisableEvent with normal case.
613  * @tc.type: FUNC
614  */
615 HWTEST_F(FtraceFsOpsTest, DisableEventNormal, TestSize.Level1)
616 {
617     EXPECT_TRUE(FtraceFsOps::GetInstance().DisableEvent("sched", "sched_switch"));
618     std::string path = FtraceFsOps::GetInstance().ftraceRoot_ + "/events/sched/sched_switch/enable";
619     std::string content = FileUtils::ReadFile(path);
620     EXPECT_STREQ(content.c_str(), "0\n");
621 }
622 
623 /*
624  * @tc.name: DisableEventFalse
625  * @tc.desc: test FtraceFsOps::DisableEvent with false case.
626  * @tc.type: FUNC
627  */
628 HWTEST_F(FtraceFsOpsTest, DisableEventFalse, TestSize.Level1)
629 {
630     FtraceFsOps ftraceFsOps;
631     ftraceFsOps.SetFtraceRoot("");
632     EXPECT_FALSE(ftraceFsOps.DisableEvent("sched", "sched_switch"));
633 
634     ftraceFsOps.SetFtraceRoot("/test_path");
635     EXPECT_FALSE(ftraceFsOps.DisableEvent("sched", "sched_switch"));
636 }
637 
638 /*
639  * @tc.name: EnableTracingNormal
640  * @tc.desc: test FtraceFsOps::EnableTracing with normal case.
641  * @tc.type: FUNC
642  */
643 HWTEST_F(FtraceFsOpsTest, EnableTracingNormal, TestSize.Level1)
644 {
645     EXPECT_TRUE(FtraceFsOps::GetInstance().EnableTracing());
646     std::string path = FtraceFsOps::GetInstance().ftraceRoot_ + "/tracing_on";
647     std::string content = FileUtils::ReadFile(path);
648     EXPECT_STREQ(content.c_str(), "1\n");
649 }
650 
651 /*
652  * @tc.name: EnableTracingFalse
653  * @tc.desc: test FtraceFsOps::EnableTracing with false case.
654  * @tc.type: FUNC
655  */
656 HWTEST_F(FtraceFsOpsTest, EnableTracingFalse, TestSize.Level1)
657 {
658     FtraceFsOps ftraceFsOps;
659     ftraceFsOps.SetFtraceRoot("");
660     EXPECT_FALSE(ftraceFsOps.EnableTracing());
661 
662     ftraceFsOps.SetFtraceRoot("/test_path");
663     EXPECT_FALSE(ftraceFsOps.EnableTracing());
664 }
665 
666 /*
667  * @tc.name: DisableTracingNormal
668  * @tc.desc: test FtraceFsOps::DisableTracing with normal case.
669  * @tc.type: FUNC
670  */
671 HWTEST_F(FtraceFsOpsTest, DisableTracingNormal, TestSize.Level1)
672 {
673     EXPECT_TRUE(FtraceFsOps::GetInstance().DisableTracing());
674     std::string path = FtraceFsOps::GetInstance().ftraceRoot_ + "/tracing_on";
675     std::string content = FileUtils::ReadFile(path);
676     EXPECT_STREQ(content.c_str(), "0\n");
677 }
678 
679 /*
680  * @tc.name: DisableTracingFalse
681  * @tc.desc: test FtraceFsOps::DisableTracing with false case.
682  * @tc.type: FUNC
683  */
684 HWTEST_F(FtraceFsOpsTest, DisableTracingFalse, TestSize.Level1)
685 {
686     FtraceFsOps ftraceFsOps;
687     ftraceFsOps.SetFtraceRoot("");
688     EXPECT_FALSE(ftraceFsOps.DisableTracing());
689 
690     ftraceFsOps.SetFtraceRoot("/test_path");
691     EXPECT_FALSE(ftraceFsOps.DisableTracing());
692 }
693 } // namespace