summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Bettis <jbettis@google.com>2022-10-06 13:10:56 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-10-07 21:37:33 +0000
commit4f6d8ca42115d3c39cbc6a476414df0be629f51e (patch)
treed1dac4da26ff4ba3dbe6450a48f2c7d8337acb44
parent08c3a7dbd3592e5fdcf73d314b98d990d0f0a075 (diff)
downloadchrome-ec-4f6d8ca42115d3c39cbc6a476414df0be629f51e.tar.gz
ec: Don't declare forward decls as weak
If a function in a header is marked as weak (test_mockable), that tells the linker that it is ok for the symbol to be missing. We never want that. If a function implementation is marked as weak, that tells the linker it is ok to use a non-weak symbol instead of this one. This is what we want when we are trying to override functions. Remove all test_mockables from headers, except for one inline function that I wasn't sure what to do with. BRANCH=None BUG=None TEST=make -j$(nproc) runhosttests buildall && zmake build -a && \ ./twister -v -i --clobber LOW_COVERAGE_REASON=Added stub get_ap_reset_stats() for tests that don't care about that function, and it's always unused. Change-Id: Ic00a897131c93ef134544f26a8e368ce1f78a5de Signed-off-by: Jeremy Bettis <jbettis@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3935720 Commit-Queue: Jeremy Bettis <jbettis@chromium.org> Auto-Submit: Jeremy Bettis <jbettis@chromium.org> Commit-Queue: Tristan Honscheid <honscheid@google.com> Tested-by: Jeremy Bettis <jbettis@chromium.org> Reviewed-by: Tristan Honscheid <honscheid@google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r--builtin/assert.h8
-rw-r--r--chip/host/reboot.h4
-rw-r--r--chip/host/system.c7
-rw-r--r--common/extpower_gpio.c2
-rw-r--r--common/panic_output.c7
-rw-r--r--include/charge_manager.h2
-rw-r--r--include/chipset.h2
-rw-r--r--include/common.h2
-rw-r--r--include/extpower.h2
-rw-r--r--include/mkbp_fifo.h2
-rw-r--r--include/panic.h33
-rw-r--r--include/system.h7
12 files changed, 42 insertions, 36 deletions
diff --git a/builtin/assert.h b/builtin/assert.h
index b667a0d2a2..2e943f7615 100644
--- a/builtin/assert.h
+++ b/builtin/assert.h
@@ -11,8 +11,6 @@
/* Include CONFIG definitions for EC sources. */
#ifndef THIRD_PARTY
#include "common.h"
-#else
-#define test_mockable_noreturn noreturn
#endif
#ifdef __cplusplus
@@ -23,7 +21,7 @@ extern "C" {
#ifdef CONFIG_DEBUG_ASSERT_REBOOTS
#ifdef CONFIG_DEBUG_ASSERT_BRIEF
-test_mockable_noreturn void panic_assert_fail(const char *fname, int linenum);
+noreturn void panic_assert_fail(const char *fname, int linenum);
#define ASSERT(cond) \
do { \
if (!(cond)) \
@@ -32,8 +30,8 @@ test_mockable_noreturn void panic_assert_fail(const char *fname, int linenum);
#else /* !CONFIG_DEBUG_ASSERT_BRIEF */
-test_mockable_noreturn void panic_assert_fail(const char *msg, const char *func,
- const char *fname, int linenum);
+noreturn void panic_assert_fail(const char *msg, const char *func,
+ const char *fname, int linenum);
#define ASSERT(cond) \
do { \
if (!(cond)) \
diff --git a/chip/host/reboot.h b/chip/host/reboot.h
index 1541e42334..e382db0adf 100644
--- a/chip/host/reboot.h
+++ b/chip/host/reboot.h
@@ -10,10 +10,10 @@
#include <stdnoreturn.h>
-#ifndef TEST_FUZZ
+#if !(defined(TEST_FUZZ) || defined(CONFIG_ZTEST))
noreturn
#endif
void
emulator_reboot(void);
-#endif
+#endif /* __CROS_EC_REBOOT_H */
diff --git a/chip/host/system.c b/chip/host/system.c
index 4a480faf77..ae650e3f9f 100644
--- a/chip/host/system.c
+++ b/chip/host/system.c
@@ -280,3 +280,10 @@ void system_pre_init(void)
*(uintptr_t *)(__host_flash + CONFIG_RW_MEM_OFF + 4) =
(uintptr_t)__rw_jump_resetvec;
}
+
+test_mockable enum ec_error_list
+get_ap_reset_stats(struct ap_reset_log_entry *reset_log_entries,
+ size_t num_reset_log_entries, uint32_t *resets_since_ec_boot)
+{
+ return EC_ERROR_INVAL;
+}
diff --git a/common/extpower_gpio.c b/common/extpower_gpio.c
index 8b41ec2075..bfb9349e0e 100644
--- a/common/extpower_gpio.c
+++ b/common/extpower_gpio.c
@@ -14,7 +14,7 @@
static int debounced_extpower_presence;
-int extpower_is_present(void)
+test_mockable int extpower_is_present(void)
{
return debounced_extpower_presence;
}
diff --git a/common/panic_output.c b/common/panic_output.c
index e5a184be27..27c7e1e202 100644
--- a/common/panic_output.c
+++ b/common/panic_output.c
@@ -121,7 +121,12 @@ void panic_reboot(void)
}
/* Complete the processing of a panic, after the initial message is shown */
-test_mockable_static_noreturn void complete_panic(int linenum)
+test_mockable_static
+#if !(defined(TEST_FUZZ) || defined(CONFIG_ZTEST))
+ noreturn
+#endif
+ void
+ complete_panic(int linenum)
{
if (IS_ENABLED(CONFIG_SOFTWARE_PANIC))
software_panic(PANIC_SW_ASSERT, linenum);
diff --git a/include/charge_manager.h b/include/charge_manager.h
index ccef9d8814..459673a630 100644
--- a/include/charge_manager.h
+++ b/include/charge_manager.h
@@ -223,7 +223,7 @@ int charge_manager_get_selected_charge_port(void);
*
* @return Power limit (uW).
*/
-test_mockable int charge_manager_get_power_limit_uw(void);
+int charge_manager_get_power_limit_uw(void);
/**
* Get the charger current (mA) value.
diff --git a/include/chipset.h b/include/chipset.h
index 1a5c5a0d2f..a3b3a94206 100644
--- a/include/chipset.h
+++ b/include/chipset.h
@@ -258,7 +258,7 @@ void report_ap_reset(enum chipset_shutdown_reason reason);
* @param num_reset_log_entries Number of items in reset_log_entries.
* @param resets_since_ec_boot Number of AP resets since EC boot.
*/
-test_mockable enum ec_error_list
+enum ec_error_list
get_ap_reset_stats(struct ap_reset_log_entry *reset_log_entries,
size_t num_reset_log_entries,
uint32_t *resets_since_ec_boot);
diff --git a/include/common.h b/include/common.h
index 7334fe3aed..bc35a054ae 100644
--- a/include/common.h
+++ b/include/common.h
@@ -246,7 +246,7 @@
/*
* Define test_mockable and test_mockable_static for mocking
- * functions.
+ * functions. Don't use test_mockable in .h files.
*/
#ifdef TEST_BUILD
#define test_mockable __attribute__((weak))
diff --git a/include/extpower.h b/include/extpower.h
index 08bec3f0bc..4740e6033d 100644
--- a/include/extpower.h
+++ b/include/extpower.h
@@ -21,7 +21,7 @@ __override_proto void board_check_extpower(void);
/**
* Return non-zero if external power is present.
*/
-test_mockable int extpower_is_present(void);
+int extpower_is_present(void);
/**
* Interrupt handler for external power GPIOs.
diff --git a/include/mkbp_fifo.h b/include/mkbp_fifo.h
index 408980a10b..cd27b1c8d5 100644
--- a/include/mkbp_fifo.h
+++ b/include/mkbp_fifo.h
@@ -38,7 +38,7 @@ void mkbp_clear_fifo(void);
* @param buffp Pointer to the event data to enqueue.
* @return EC_SUCCESS if entry added, EC_ERROR_OVERFLOW if FIFO is full.
*/
-test_mockable int mkbp_fifo_add(uint8_t event_type, const uint8_t *buffp);
+int mkbp_fifo_add(uint8_t event_type, const uint8_t *buffp);
/**
* Remove an element from the common MKBP FIFO.
diff --git a/include/panic.h b/include/panic.h
index 9a1a78844e..7f2cb9a813 100644
--- a/include/panic.h
+++ b/include/panic.h
@@ -15,19 +15,6 @@
#include "software_panic.h"
-/*
- * Define these helpers if needed. While normally they would be derived from
- * common.h, we cannot include that header here because this file is also used
- * in the ectool and the build breaks.
- */
-#ifndef test_mockable_noreturn
-#if defined(TEST_BUILD) || defined(CONFIG_ZTEST)
-#define test_mockable_noreturn __attribute__((weak))
-#else
-#define test_mockable_noreturn noreturn
-#endif
-#endif /* test_mockable_noreturn */
-
#ifdef __cplusplus
extern "C" {
#endif
@@ -210,10 +197,18 @@ void panic_data_ccprint(const struct panic_data *pdata);
* @param linenum Line number where assertion happened
*/
#ifdef CONFIG_DEBUG_ASSERT_BRIEF
-test_mockable_noreturn void panic_assert_fail(const char *fname, int linenum);
+#if !(defined(TEST_FUZZ) || defined(CONFIG_ZTEST))
+noreturn
+#endif
+ void
+ panic_assert_fail(const char *fname, int linenum);
#else
-test_mockable_noreturn void panic_assert_fail(const char *msg, const char *func,
- const char *fname, int linenum);
+#if !(defined(TEST_FUZZ) || defined(CONFIG_ZTEST))
+noreturn
+#endif
+ void
+ panic_assert_fail(const char *msg, const char *func, const char *fname,
+ int linenum);
#endif
/**
@@ -241,7 +236,11 @@ noreturn
* Store a panic log and halt the system for a software-related reason, such as
* stack overflow or assertion failure.
*/
-test_mockable_noreturn void software_panic(uint32_t reason, uint32_t info);
+#if !(defined(TEST_FUZZ) || defined(CONFIG_ZTEST))
+noreturn
+#endif
+ void
+ software_panic(uint32_t reason, uint32_t info);
/**
* Log a panic in the panic log, but don't halt the system. Normally
diff --git a/include/system.h b/include/system.h
index 41c52e9c52..ed811e9626 100644
--- a/include/system.h
+++ b/include/system.h
@@ -372,17 +372,14 @@ const char *system_get_build_info(void);
*
* @param flags Reset flags; see SYSTEM_RESET_* above.
*/
-#if (defined(TEST_FUZZ) || defined(CONFIG_ZTEST))
-test_mockable
-#else
+#if !(defined(TEST_FUZZ) || defined(CONFIG_ZTEST))
#if defined(__cplusplus) && !defined(__clang__)
[[noreturn]]
#else
noreturn
#endif
#endif
- void
- system_reset(int flags);
+ void system_reset(int flags);
/**
* Set a scratchpad register to the specified value.