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