1 /*
2 * Copyright (c) 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 <trace/trace_marker.h>
17
18 #include <fcntl.h>
19 #include <stdbool.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <test.h>
23 #include <unistd.h>
24
25 #define BUFFER_LEN 1000000
26 static const int count = 10;
27
28 /**
29 * @tc.name : trace_marker
30 * @tc.desc : The stress test of trace_marker.
31 * @tc.level : Level 0
32 */
trace_marker_stresstest_0010(void)33 static void trace_marker_stresstest_0010(void)
34 {
35 int pidChild = 0;
36 int pidCParent = 0;
37 int pidCChild = 0;
38
39 pid_t fpid;
40 fpid = fork();
41 if (fpid < 0) {
42 printf("error in fork! \n");
43 } else if (fpid == 0) {
44 int pidChild = getpid();
45 int traceCount = 0;
46 bool trace_async_sucess = false;
47 char buf[BUFFER_LEN] = {0};
48
49 while (traceCount <= 5000) {
50 snprintf(buf, BUFFER_LEN, "%d", traceCount);
51 system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
52 trace_marker_async_begin("Trace_Marker_Async_Begin", buf, 1);
53 trace_marker_async_end("Trace_Marker_Async_End", buf, 1);
54 system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
55 printf("trace_marker_async_begin has been running times is:%d\n", traceCount);
56 traceCount++;
57 }
58 exit(pidChild);
59 } else {
60 pid_t pidCChild;
61 int traceCount = 0;
62 char buf[BUFFER_LEN] = {0};
63
64 // start process again
65 pidCChild = fork();
66 if (pidCChild < 0) {
67 t_printf("error in fork!");
68 } else if (pidCChild == 0) {
69 while (traceCount <= 5000) {
70 snprintf(buf, BUFFER_LEN, "%d", traceCount);
71 system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
72 trace_marker_begin("Trace_Marker", buf);
73 trace_marker_end();
74 system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
75 printf("trace_marker_begin has been running times is:%d\n", traceCount);
76 traceCount++;
77 }
78 exit(pidCChild);
79 } else {
80 pidCParent = getpid();
81 int traceCount = 0;
82
83 while (traceCount <= 5000) {
84 system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
85 trace_marker_count("traceCount", traceCount);
86 system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
87 printf("trace_marker_count has been running times is:%d\n", traceCount);
88 traceCount++;
89 }
90 exit(pidCParent);
91 }
92 }
93 }
94
main(void)95 int main(void)
96 {
97 trace_marker_stresstest_0010();
98
99 return t_status;
100 }
101