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