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