summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Grandi <agrandi@google.com>2022-09-09 12:16:22 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-10-10 17:34:59 +0000
commitcb8c0d8c265e962b46cfa826f3a3510ddda60f51 (patch)
tree5716c60906f58b58bc61c3eca97efc5ed6f0073a
parentdd5e0caa2145441b688fee0bac1edd452e96fccc (diff)
downloadchrome-ec-cb8c0d8c265e962b46cfa826f3a3510ddda60f51.tar.gz
test_util: Add assertion inside weakly-linked run_test()
The weakly-linked definition of run_test() should never be executed. When it does, it's usually a symptom of an issue with the build of the real test. Add an assertion to make the error condition easier to detect and resolve. BUG=b:243700149 TEST=Run host test with bad definition of run_test() =>Error message is printed on console. BRANCH=none LOW_COVERAGE_REASON=New function is only called from invalid builds. Signed-off-by: Andrea Grandi <agrandi@google.com> Change-Id: Iaf6c8377618944efc5ad4d4557ed4c231c09be09 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3887968 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Bobby Casey <bobbycasey@google.com> Reviewed-by: Tom Hughes <tomhughes@chromium.org>
-rw-r--r--common/test_util.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/common/test_util.c b/common/test_util.c
index f15b99f302..659476fc17 100644
--- a/common/test_util.c
+++ b/common/test_util.c
@@ -11,6 +11,7 @@
#include <stdlib.h>
#endif
+#include <assert.h>
#include "console.h"
#include "hooks.h"
#include "host_command.h"
@@ -31,6 +32,15 @@ int __test_error_count;
/* Weak reference function as an entry point for unit test */
test_mockable void run_test(int argc, const char **argv)
{
+ /* This function should always be replaced by a real implementation of
+ * run_test().
+ * If this assertion is failing, it means your test was not linked
+ * correctly. Check the signature of run_test() defined in your test
+ * matches the one above.
+ */
+ ccprintf("%s:%d: ASSERTION failed: ran weakly linked fallback test\n",
+ __FILE__, __LINE__);
+ assert(0);
}
/* Default mock test init */