summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2022-10-03 15:08:44 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-10-12 01:10:14 +0000
commit4ab534c3ce1cfda9153e1fa488f5476b1ab62a5d (patch)
treee0f3d44b6cb6b8dcf541f0bfe987761b87bbfdcc
parentdfb84c6f6419e9f1f48a0497833f648955901014 (diff)
downloadchrome-ec-4ab534c3ce1cfda9153e1fa488f5476b1ab62a5d.tar.gz
include/common: Use noreturn attribute in test and non-test build
In the test build, the "test_mockable_noreturn" helper adds the "__attribute__((weak))" attribute to allow overriding functions. It should still keep the "noreturn" attribute to be consistent with the non-test build. Otherwise, a function declared with "noreturn" that calls one of the functions that uses "test_mockable_noreturn" will fail to compile with: error: function declared 'noreturn' should not return [-Werror,-Winvalid-noreturn] BRANCH=none BUG=b:234181908 TEST=./util/compare_build.sh -b all => MATCH Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I6ebfc78b7b07e19f9305a22fbfeccf62b4000667 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3933258 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
-rw-r--r--include/common.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/include/common.h b/include/common.h
index bc35a054ae..746b185226 100644
--- a/include/common.h
+++ b/include/common.h
@@ -252,8 +252,18 @@
#define test_mockable __attribute__((weak))
#define test_mockable_static __attribute__((weak))
#define test_mockable_static_inline __attribute__((weak))
+/*
+ * Tests implemented with ztest add mock implementations that actually return,
+ * so they should not be marked "noreturn". See
+ * test/drivers/default/src/panic_output.c.
+ */
+#ifdef CONFIG_ZTEST
#define test_mockable_noreturn __attribute__((weak))
#define test_mockable_static_noreturn __attribute__((weak))
+#else
+#define test_mockable_noreturn noreturn __attribute__((weak))
+#define test_mockable_static_noreturn noreturn __attribute__((weak))
+#endif
#define test_export_static
#else
#define test_mockable