From 4f6d8ca42115d3c39cbc6a476414df0be629f51e Mon Sep 17 00:00:00 2001 From: Jeremy Bettis Date: Thu, 6 Oct 2022 13:10:56 -0600 Subject: 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 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3935720 Commit-Queue: Jeremy Bettis Auto-Submit: Jeremy Bettis Commit-Queue: Tristan Honscheid Tested-by: Jeremy Bettis Reviewed-by: Tristan Honscheid Code-Coverage: Zoss --- builtin/assert.h | 8 +++----- chip/host/reboot.h | 4 ++-- chip/host/system.c | 7 +++++++ common/extpower_gpio.c | 2 +- common/panic_output.c | 7 ++++++- include/charge_manager.h | 2 +- include/chipset.h | 2 +- include/common.h | 2 +- include/extpower.h | 2 +- include/mkbp_fifo.h | 2 +- include/panic.h | 33 ++++++++++++++++----------------- include/system.h | 7 ++----- 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 -#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. -- cgit v1.2.1