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 #include "gtest/gtest.h"
19 #include "pw_trace/trace.h"
20
21 namespace {
22
TraceFunction()23 void TraceFunction() { PW_TRACE_FUNCTION(); }
TraceFunctionGroup()24 void TraceFunctionGroup() { PW_TRACE_FUNCTION("FunctionGroup"); }
25
26 const char kSomeData[] = "SOME DATA";
27
28 } // namespace
29
TEST(BasicTrace,Instant)30 TEST(BasicTrace, Instant) { PW_TRACE_INSTANT("Test"); }
31
TEST(BasicTrace,InstantGroup)32 TEST(BasicTrace, InstantGroup) { PW_TRACE_INSTANT("Test", "group"); }
33
TEST(BasicTrace,Duration)34 TEST(BasicTrace, Duration) {
35 PW_TRACE_START("Test");
36 PW_TRACE_END("Test");
37 }
38
TEST(BasicTrace,DurationGroup)39 TEST(BasicTrace, DurationGroup) {
40 PW_TRACE_START("Parent", "group");
41 PW_TRACE_START("Child", "group");
42 PW_TRACE_END("child", "group");
43 PW_TRACE_START("Other Child", "group");
44 PW_TRACE_END("Other Child", "group");
45 PW_TRACE_END("Parent", "group");
46 }
47
TEST(BasicTrace,Async)48 TEST(BasicTrace, Async) {
49 uint32_t trace_id = 1;
50 PW_TRACE_START("label for start", "group", trace_id);
51 PW_TRACE_INSTANT("label for step", "group", trace_id);
52 PW_TRACE_END("label for end", "group", trace_id);
53 }
54
TEST(BasicTrace,Scope)55 TEST(BasicTrace, Scope) { PW_TRACE_SCOPE("scoped trace"); }
56
TEST(BasicTrace,ScopeGroup)57 TEST(BasicTrace, ScopeGroup) {
58 PW_TRACE_SCOPE("scoped group trace", "group");
59 { PW_TRACE_SCOPE("sub scoped group trace", "group"); }
60 }
61
TEST(BasicTrace,Function)62 TEST(BasicTrace, Function) { TraceFunction(); }
63
TEST(BasicTrace,FunctionGroup)64 TEST(BasicTrace, FunctionGroup) { TraceFunctionGroup(); }
65
TEST(BasicTrace,InstantData)66 TEST(BasicTrace, InstantData) {
67 PW_TRACE_INSTANT_DATA("Test", "s", kSomeData, sizeof(kSomeData));
68 }
69
TEST(BasicTrace,InstantGroupData)70 TEST(BasicTrace, InstantGroupData) {
71 PW_TRACE_INSTANT_DATA("Test", "Group", "s", kSomeData, sizeof(kSomeData));
72 }
73
TEST(BasicTrace,DurationData)74 TEST(BasicTrace, DurationData) {
75 PW_TRACE_START_DATA("Test", "s", kSomeData, sizeof(kSomeData));
76 PW_TRACE_END_DATA("Test", "s", kSomeData, sizeof(kSomeData));
77 }
78
TEST(BasicTrace,DurationGroupData)79 TEST(BasicTrace, DurationGroupData) {
80 PW_TRACE_START_DATA("Parent", "group", "s", kSomeData, sizeof(kSomeData));
81 PW_TRACE_START_DATA("Child", "group", "s", kSomeData, sizeof(kSomeData));
82 PW_TRACE_END_DATA("child", "group", "s", kSomeData, sizeof(kSomeData));
83 PW_TRACE_START_DATA(
84 "Other Child", "group", "s", kSomeData, sizeof(kSomeData));
85 PW_TRACE_END_DATA("Other Child", "group", "s", kSomeData, sizeof(kSomeData));
86 PW_TRACE_END_DATA("Parent", "group", "s", kSomeData, sizeof(kSomeData));
87 }
88
TEST(BasicTrace,AsyncData)89 TEST(BasicTrace, AsyncData) {
90 uint32_t trace_id = 1;
91 PW_TRACE_START_DATA(
92 "label for start", "group", trace_id, "s", kSomeData, sizeof(kSomeData));
93 PW_TRACE_INSTANT_DATA(
94 "label for step", "group", trace_id, "s", kSomeData, sizeof(kSomeData));
95 PW_TRACE_END_DATA(
96 "label for end", "group", trace_id, "s", kSomeData, sizeof(kSomeData));
97 }
98