aboutsummaryrefslogtreecommitdiff
path: root/pw_trace
diff options
context:
space:
mode:
authorErik Gilling <konkers@google.com>2022-11-03 21:12:14 +0000
committerCQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-11-03 21:12:14 +0000
commit1b782192f195e17f3967db1a24f5f83a5e87f86f (patch)
tree7b7304db36b6dba3da1b1357b008647512c9b68d /pw_trace
parent3c1d40c80e7ae3f1edacb295958be0735b9464d1 (diff)
downloadpigweed-1b782192f195e17f3967db1a24f5f83a5e87f86f.tar.gz
pw_trace: Fix backends that don't support all trace macros
Bug: b/256681191 Change-Id: Idaee79768fba4d0d95da6ce9e114e3135987cc7a Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/116791 Pigweed-Auto-Submit: Erik Gilling <konkers@google.com> Reviewed-by: Ted Pudlik <tpudlik@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com> Reviewed-by: Rob Oliver <rgoliver@google.com>
Diffstat (limited to 'pw_trace')
-rw-r--r--pw_trace/BUILD.bazel24
-rw-r--r--pw_trace/BUILD.gn28
-rw-r--r--pw_trace/public/pw_trace/internal/trace_internal.h22
-rw-r--r--pw_trace/pw_trace_zero/public_overrides/pw_trace_backend/trace_backend.h20
4 files changed, 90 insertions, 4 deletions
diff --git a/pw_trace/BUILD.bazel b/pw_trace/BUILD.bazel
index 38b2188cf..4ecf9f64e 100644
--- a/pw_trace/BUILD.bazel
+++ b/pw_trace/BUILD.bazel
@@ -107,6 +107,25 @@ pw_cc_test(
],
)
+pw_cc_test(
+ name = "trace_zero_facade_test",
+ srcs = [
+ "pw_trace_zero/public_overrides/pw_trace_backend/trace_backend.h",
+ "trace_backend_compile_test.cc",
+ "trace_backend_compile_test_c.c",
+ ],
+ includes = [
+ "pw_trace_zero",
+ "pw_trace_zero/public_overrides",
+ ],
+ deps = [
+ ":facade",
+ ":pw_trace",
+ "//pw_preprocessor",
+ "//pw_unit_test",
+ ],
+)
+
pw_cc_library(
name = "trace_null_test",
srcs = [
@@ -127,7 +146,10 @@ pw_cc_library(
srcs = ["example/sample_app.cc"],
hdrs = ["example/public/pw_trace/example/sample_app.h"],
includes = ["example/public"],
- deps = ["//pw_trace"],
+ deps = [
+ "//pw_ring_buffer",
+ "//pw_trace",
+ ],
)
pw_cc_binary(
diff --git a/pw_trace/BUILD.gn b/pw_trace/BUILD.gn
index a62d1af46..64e7a78b7 100644
--- a/pw_trace/BUILD.gn
+++ b/pw_trace/BUILD.gn
@@ -16,6 +16,7 @@ import("//build_overrides/pigweed.gni")
import("$dir_pw_build/facade.gni")
import("$dir_pw_docgen/docs.gni")
+import("$dir_pw_unit_test/facade_test.gni")
import("$dir_pw_unit_test/test.gni")
import("backend.gni")
@@ -53,6 +54,7 @@ pw_test_group("tests") {
tests = [
":trace_facade_test",
":trace_null_test",
+ ":trace_zero_backend_test",
]
if (pw_trace_BACKEND != "") {
tests += [ ":trace_backend_compile_test" ]
@@ -88,6 +90,32 @@ pw_test("trace_backend_compile_test") {
]
}
+config("zero_config") {
+ include_dirs = [ "pw_trace_zero/public_overrides" ]
+ visibility = [ ":*" ]
+}
+
+pw_source_set("zero") {
+ public_configs = [
+ ":default_config",
+ ":zero_config",
+ ]
+ public = [ "pw_trace_zero/public_overrides/pw_trace_backend/trace_backend.h" ]
+}
+
+pw_facade_test("trace_zero_backend_test") {
+ build_args = {
+ pw_trace_BACKEND = ":zero"
+ }
+
+ deps = [ ":pw_trace" ]
+
+ sources = [
+ "trace_backend_compile_test.cc",
+ "trace_backend_compile_test_c.c",
+ ]
+}
+
pw_test("trace_null_test") {
sources = [
"trace_null_test.cc",
diff --git a/pw_trace/public/pw_trace/internal/trace_internal.h b/pw_trace/public/pw_trace/internal/trace_internal.h
index 9355b49ca..f6262eec4 100644
--- a/pw_trace/public/pw_trace/internal/trace_internal.h
+++ b/pw_trace/public/pw_trace/internal/trace_internal.h
@@ -49,9 +49,12 @@
// Default: behaviour for unimplemented trace event types
#ifndef _PW_TRACE_DISABLED
-#define _PW_TRACE_DISABLED(...) \
- do { \
- } while (0)
+static inline void _pw_trace_disabled(int x, ...) { (void)x; }
+// `_PW_TRACE_DISABLED` must be called with at least one arg.
+#define _PW_TRACE_DISABLED(...) \
+ do { \
+ _pw_trace_disabled(0, ##__VA_ARGS__); \
+ } while (false)
#endif // _PW_TRACE_DISABLED
// Default: label used for PW_TRACE_FUNCTION trace events
@@ -270,6 +273,11 @@
_PW_TRACE_SCOPE_ARGS2(PW_TRACE_FLAGS, PW_TRACE_FUNCTION_LABEL)
#define _PW_TRACE_FUNCTION_FLAGS_ARGS1(flag) \
_PW_TRACE_SCOPE_ARGS2(flag, PW_TRACE_FUNCTION_LABEL)
+#else // PW_TRACE_TYPE_DURATION_GROUP_END
+#define _PW_TRACE_SCOPE_ARGS2(...) _PW_TRACE_DISABLED(__VA_ARGS__)
+#define _PW_TRACE_FUNCTION_ARGS0() // No need to/can't call _PW_TRACE_DISABLED
+ // with zero args.
+#define _PW_TRACE_FUNCTION_FLAGS_ARGS1(...) _PW_TRACE_DISABLED(__VA_ARGS__)
#endif // defined(PW_TRACE_TYPE_DURATION_START) &&
// defined(PW_TRACE_TYPE_DURATION_END)
@@ -296,6 +304,10 @@
_PW_TRACE_SCOPE_ARGS3(PW_TRACE_FLAGS, PW_TRACE_FUNCTION_LABEL, group)
#define _PW_TRACE_FUNCTION_FLAGS_ARGS2(flag, group) \
_PW_TRACE_SCOPE_ARGS3(flag, PW_TRACE_FUNCTION_LABEL, group)
+#else // PW_TRACE_TYPE_DURATION_GROUP_END
+#define _PW_TRACE_SCOPE_ARGS3(...) _PW_TRACE_DISABLED(__VA_ARGS__)
+#define _PW_TRACE_FUNCTION_ARGS1(...) _PW_TRACE_DISABLED(__VA_ARGS__)
+#define _PW_TRACE_FUNCTION_FLAGS_ARGS2(...) _PW_TRACE_DISABLED(__VA_ARGS__)
#endif // defined(PW_TRACE_TYPE_DURATION_GROUP_START) &&
// defined(PW_TRACE_TYPE_DURATION_GROUP_END)
@@ -322,6 +334,10 @@
PW_TRACE_FLAGS, PW_TRACE_FUNCTION_LABEL, group, trace_id)
#define _PW_TRACE_FUNCTION_FLAGS_ARGS3(flag, group, trace_id) \
_PW_TRACE_SCOPE_ARGS4(flag, PW_TRACE_FUNCTION_LABEL, group, trace_id)
+#else // PW_TRACE_TYPE_DURATION_GROUP_END
+#define _PW_TRACE_SCOPE_ARGS4(...) _PW_TRACE_DISABLED(__VA_ARGS__)
+#define _PW_TRACE_FUNCTION_ARGS2(...) _PW_TRACE_DISABLED(__VA_ARGS__)
+#define _PW_TRACE_FUNCTION_FLAGS_ARGS3(...) _PW_TRACE_DISABLED(__VA_ARGS__)
#endif // defined(PW_TRACE_TYPE_ASYNC_START) &&
// defined(PW_TRACE_TYPE_ASYNC_END)
diff --git a/pw_trace/pw_trace_zero/public_overrides/pw_trace_backend/trace_backend.h b/pw_trace/pw_trace_zero/public_overrides/pw_trace_backend/trace_backend.h
new file mode 100644
index 000000000..a79d49b99
--- /dev/null
+++ b/pw_trace/pw_trace_zero/public_overrides/pw_trace_backend/trace_backend.h
@@ -0,0 +1,20 @@
+// Copyright 2022 The Pigweed Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+//==============================================================================
+//
+#pragma once
+
+// No backend is included so that all backend macros are left undefined. This
+// is primarily used to test that `trace.h` compiles without warnings when
+// using a backend that does not implement certain macros.