diff options
| author | Peter Jones <pjones@redhat.com> | 2021-03-10 10:46:32 -0500 |
|---|---|---|
| committer | Peter Jones <pjones@redhat.com> | 2021-03-10 15:54:20 -0500 |
| commit | 8d006f5c70b19d6e7f35f83e61880deb45b05977 (patch) | |
| tree | 793f054f495e4e13d35cbdd3363613ce29fc5ecd /include/test.h | |
| parent | 1bc4bf063adf57a17e5d6d8dc6399f03080a0566 (diff) | |
| download | efi-boot-shim-8d006f5c70b19d6e7f35f83e61880deb45b05977.tar.gz efi-boot-shim-8d006f5c70b19d6e7f35f83e61880deb45b05977.zip | |
Test our strncmp vs known failing ones as well
Signed-off-by: Peter Jones <pjones@redhat.com>
Diffstat (limited to 'include/test.h')
| -rw-r--r-- | include/test.h | 87 |
1 files changed, 73 insertions, 14 deletions
diff --git a/include/test.h b/include/test.h index 4441f969..92d1314e 100644 --- a/include/test.h +++ b/include/test.h @@ -63,73 +63,132 @@ extern int debug; assert(cond); \ }) -#define assert_true_return(a, status, fmt, ...) \ +#define assert_true_as_expr(a, status, fmt, ...) \ ({ \ + int rc_ = 0; \ if (!(a)) { \ printf("%s:%d:got %lld, expected nonzero " fmt, \ __func__, __LINE__, (long long)(a), \ ##__VA_ARGS__); \ printf("%s:%d:Assertion `%s' failed.\n", __func__, \ __LINE__, __stringify(!(a))); \ - return status; \ + rc_ = status; \ } \ + rc_; \ }) -#define assert_nonzero_return(a, ...) assert_true_return(a, ##__VA_ARGS__) +#define assert_nonzero_as_expr(a, ...) assert_true_as_expr(a, ##__VA_ARGS__) -#define assert_false_return(a, status, fmt, ...) \ +#define assert_false_as_expr(a, status, fmt, ...) \ ({ \ + int rc_ = 0; \ if (a) { \ printf("%s:%d:got %lld, expected zero " fmt, __func__, \ __LINE__, (long long)(a), ##__VA_ARGS__); \ printf("%s:%d:Assertion `%s' failed.\n", __func__, \ __LINE__, __stringify(a)); \ - return status; \ + rc_ = status; \ } \ + rc_; \ }) -#define assert_zero_return(a, ...) assert_false_return(a, ##__VA_ARGS__) +#define assert_zero_as_expr(a, ...) assert_false_as_expr(a, ##__VA_ARGS__) -#define assert_positive_return(a, status, fmt, ...) \ +#define assert_positive_as_expr(a, status, fmt, ...) \ ({ \ + int rc_ = 0; \ if ((a) <= 0) { \ printf("%s:%d:got %lld, expected > 0 " fmt, __func__, \ __LINE__, (long long)(a), ##__VA_ARGS__); \ printf("%s:%d:Assertion `%s' failed.\n", __func__, \ __LINE__, __stringify((a) <= 0)); \ - return status; \ + rc_ = status; \ } \ + rc_; \ }) -#define assert_negative_return(a, status, fmt, ...) \ +#define assert_negative_as_expr(a, status, fmt, ...) \ ({ \ + int rc_ = 0; \ if ((a) >= 0) { \ printf("%s:%d:got %lld, expected < 0 " fmt, __func__, \ __LINE__, (long long)(a), ##__VA_ARGS__); \ printf("%s:%d:Assertion `%s' failed.\n", __func__, \ __LINE__, __stringify((a) >= 0)); \ - return status; \ + rc_ = status; \ } \ + rc_; \ }) -#define assert_equal_return(a, b, status, fmt, ...) \ +#define assert_equal_as_expr(a, b, status, fmt, ...) \ ({ \ + int rc_ = 0; \ if (!((a) == (b))) { \ printf("%s:%d:" fmt, __func__, __LINE__, (a), (b), \ ##__VA_ARGS__); \ printf("%s:%d:Assertion `%s' failed.\n", __func__, \ __LINE__, __stringify(a == b)); \ - return status; \ + rc_ = status; \ } \ + rc_; \ }) -#define assert_return(cond, status, fmt, ...) \ +#define assert_as_expr(cond, status, fmt, ...) \ ({ \ + int rc_ = 0; \ if (!(cond)) { \ printf("%s:%d:" fmt, __func__, __LINE__, \ ##__VA_ARGS__); \ printf("%s:%d:Assertion `%s' failed.\n", __func__, \ __LINE__, __stringify(cond)); \ - return status; \ + rc_ = status; \ } \ + rc_; \ + }) + +#define assert_true_return(a, status, fmt, ...) \ + ({ \ + int rc_ = assert_true_as_expr(a, status, fmt, ##__VA_ARGS__); \ + if (rc_ != 0) \ + return rc_; \ + }) +#define assert_nonzero_return(a, ...) assert_true_return(a, ##__VA_ARGS__) + +#define assert_false_return(a, status, fmt, ...) \ + ({ \ + int rc_ = assert_false_as_expr(a, status, fmt, ##__VA_ARGS__); \ + if (rc_ != 0) \ + return rc_; \ + }) +#define assert_zero_return(a, ...) assert_false_return(a, ##__VA_ARGS__) + +#define assert_positive_return(a, status, fmt, ...) \ + ({ \ + int rc_ = assert_positive_as_expr(a, status, fmt, \ + ##__VA_ARGS__); \ + if (rc_ != 0) \ + return rc_; \ + }) + +#define assert_negative_return(a, status, fmt, ...) \ + ({ \ + int rc_ = assert_negative_as_expr(a, status, fmt, \ + ##__VA_ARGS__); \ + if (rc_ != 0) \ + return rc_; \ + }) + +#define assert_equal_return(a, b, status, fmt, ...) \ + ({ \ + int rc_ = assert_equal_as_expr(a, b, status, fmt, \ + ##__VA_ARGS__); \ + if (rc_ != 0) \ + return rc_; \ + }) + +#define assert_return(cond, status, fmt, ...) \ + ({ \ + int rc_ = assert_as_expr(cond, status, fmt, ##__VA_ARGS__); \ + if (rc_ != 0) \ + return rc_; \ }) #define assert_goto(cond, label, fmt, ...) \ |
