diff options
author | Jack Rosenthal <jrosenth@chromium.org> | 2019-10-21 14:32:07 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-10-22 22:58:48 +0000 |
commit | ab18c5ac746d3f332700fd13ed390359a3611a93 (patch) | |
tree | 0fc6f3fbe68e0ecf094e5286a1e1d1ab8b9bd452 /include/common.h | |
parent | f38ece9f9d731951a38c0bb88a1ec6578bfad30c (diff) | |
download | chrome-ec-ab18c5ac746d3f332700fd13ed390359a3611a93.tar.gz |
common: add __test_only attribute
For functions which should only be used in test builds, this lets us
add __test_only to the prototype, causing an error if used outside of
tests.
Example error output:
test.c: In function ‘main’:
test.c:17:5: error: call to ‘foo’ declared with attribute error:
This function should only be used by tests
foo();
^~~~~
This will not cause errors if the usage is guarded by a disabled
IS_ENABLED (or any other form of optimized-away branch).
BUG=none
BRANCH=none
TEST=see above
Change-Id: I64115fd9e7940de9b10063a46548e8d00033d1d3
Signed-off-by: Jack Rosenthal <jrosenth@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1872962
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Raul E Rangel <rrangel@chromium.org>
Diffstat (limited to 'include/common.h')
-rw-r--r-- | include/common.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/include/common.h b/include/common.h index c1f9d6ffb5..99e9ad91c9 100644 --- a/include/common.h +++ b/include/common.h @@ -262,6 +262,19 @@ enum ec_error_list { #endif /* + * Attribute to define functions to only be used in test code, causing + * a compiler error if used without TEST_BUILD defined. + * + * Example usage (add to prototype in header): + * __test_only void foo(void); + */ +#ifdef TEST_BUILD +#define __test_only +#else +#define __test_only __error("This function should only be used by tests") +#endif + +/* * Weak symbol markers * * These macros are used to annotate weak definitions, their declarations, and |