1 // Copyright 2020 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 // https://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, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 //
15 // This is a simple test that ensures a provided trace backend compiles.
16
17 #define PW_TRACE_MODULE_NAME "TST"
18
19 #include "pw_trace/trace.h"
20
21 #ifdef __cplusplus
22 #error "This file must be compiled as plain C to verify C compilation works."
23 #endif // __cplusplus
24
BasicTraceTestPlainC(void)25 void BasicTraceTestPlainC(void) {
26 PW_TRACE_INSTANT("Test");
27
28 PW_TRACE_START("Test");
29 PW_TRACE_END("Test");
30
31 PW_TRACE_START("Parent", "group");
32 PW_TRACE_START("Child", "group");
33 PW_TRACE_END("Child", "group");
34 PW_TRACE_INSTANT("Test", "group");
35 PW_TRACE_START("Other Child", "group");
36 PW_TRACE_END("Other Child", "group");
37 PW_TRACE_END("Parent", "group");
38
39 PW_TRACE_START("label for start", "group", 1);
40 PW_TRACE_INSTANT("label for step", "group", 1);
41 PW_TRACE_END("label for end", "group", 1);
42
43 const char kSomeData[] = "SOME DATA";
44 PW_TRACE_INSTANT_DATA("Test", "s", kSomeData, sizeof(kSomeData));
45
46 PW_TRACE_START_DATA("Parent", "group", "s", kSomeData, sizeof(kSomeData));
47 PW_TRACE_START_DATA("Child", "group", "s", kSomeData, sizeof(kSomeData));
48 PW_TRACE_END_DATA("child", "group", "s", kSomeData, sizeof(kSomeData));
49 PW_TRACE_INSTANT_DATA("Test", "group", "s", kSomeData, sizeof(kSomeData));
50 PW_TRACE_START_DATA(
51 "Other Child", "group", "s", kSomeData, sizeof(kSomeData));
52 PW_TRACE_END_DATA("Other Child", "group", "s", kSomeData, sizeof(kSomeData));
53 PW_TRACE_END_DATA("Parent", "group", "s", kSomeData, sizeof(kSomeData));
54
55 uint32_t trace_id = 1;
56 PW_TRACE_START_DATA(
57 "label for start", "group", trace_id, "s", kSomeData, sizeof(kSomeData));
58 PW_TRACE_INSTANT_DATA(
59 "label for step", "group", trace_id, "s", kSomeData, sizeof(kSomeData));
60 PW_TRACE_END_DATA(
61 "label for end", "group", trace_id, "s", kSomeData, sizeof(kSomeData));
62 }
63