diff options
author | Bobby Casey <bobbycasey@google.com> | 2022-10-27 19:51:23 -0400 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-12-02 18:26:23 +0000 |
commit | 922f944f7a247468397a738a255bd7b6fcdb8364 (patch) | |
tree | c930258096ac2ef3fff118689929dee6af533d77 | |
parent | 5f4b3e9ba4ffb0587ed8bb274af5a86c11aafcd0 (diff) | |
download | chrome-ec-922f944f7a247468397a738a255bd7b6fcdb8364.tar.gz |
test_util: Enable test comparisons using complex types
Tests comparing complex types must define
TEST_OPERATOR_INHIBIT_PRINT_EVAL prior to any standard comparison.
The format string may be populated with any string. For example:
TEST_EQ(foo, bar, "");
BUG=b:226561385
BRANCH=none
TEST=make BOARD=bloonchipper tests
TEST=make runhosttest
Signed-off-by: Bobby Casey <bobbycasey@google.com>
Change-Id: I82f7457b95939870980bc082593e42581585eec3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3993972
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Commit-Queue: Andrea Grandi <agrandi@google.com>
Reviewed-by: Andrea Grandi <agrandi@google.com>
-rw-r--r-- | include/test_util.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/include/test_util.h b/include/test_util.h index efdee22cc6..e3a9f27ebc 100644 --- a/include/test_util.h +++ b/include/test_util.h @@ -55,6 +55,17 @@ extern "C" { #define __auto_type auto #endif +/* Tests comparing complex types that cannot be easily formatted for printing + * may define TEST_OPERATOR_INHIBIT_PRINT_EVAL to inhibit printing of the + * compared values on failure. + */ +#ifdef TEST_OPERATOR_INHIBIT_PRINT_EVAL +#define TEST_OPERATOR_PRINT_EVAL(fmt, op, _a, _b) +#else +#define TEST_OPERATOR_PRINT_EVAL(fmt, op, _a, _b) \ + ccprintf("\t\tEVAL: " fmt " " #op " " fmt "\n", _a, _b) +#endif + #define TEST_OPERATOR(a, b, op, fmt) \ do { \ __auto_type _a = (a); \ @@ -62,8 +73,7 @@ extern "C" { if (!(_a op _b)) { \ ccprintf("%s:%d: ASSERTION failed: %s " #op " %s\n", \ __FILE__, __LINE__, #a, #b); \ - ccprintf("\t\tEVAL: " fmt " " #op " " fmt "\n", _a, \ - _b); \ + TEST_OPERATOR_PRINT_EVAL(fmt, op, _a, _b); \ task_dump_trace(); \ return EC_ERROR_UNKNOWN; \ } else { \ |