diff options
| author | Peter Jones <pjones@redhat.com> | 2021-03-09 11:56:31 -0500 |
|---|---|---|
| committer | Peter Jones <pjones@redhat.com> | 2021-03-10 15:54:20 -0500 |
| commit | bbdfa72a0a5f8d5a8dd4a47e67195504a22ece5b (patch) | |
| tree | df55ee07b51932f866a25967b18536dc29321073 /include/test.h | |
| parent | 9beca885c29c77bb901547321a5ce6fd3c9c8ee3 (diff) | |
| download | efi-boot-shim-bbdfa72a0a5f8d5a8dd4a47e67195504a22ece5b.tar.gz efi-boot-shim-bbdfa72a0a5f8d5a8dd4a47e67195504a22ece5b.zip | |
Add some test cases, and make "make test" actually work.
Note the one test case I'm not 100% sure about. Someone let me know.
Signed-off-by: Peter Jones <pjones@redhat.com>
Diffstat (limited to 'include/test.h')
| -rw-r--r-- | include/test.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/include/test.h b/include/test.h index 8a970fd2..4441f969 100644 --- a/include/test.h +++ b/include/test.h @@ -63,6 +63,53 @@ extern int debug; assert(cond); \ }) +#define assert_true_return(a, status, fmt, ...) \ + ({ \ + 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; \ + } \ + }) +#define assert_nonzero_return(a, ...) assert_true_return(a, ##__VA_ARGS__) + +#define assert_false_return(a, status, fmt, ...) \ + ({ \ + 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; \ + } \ + }) +#define assert_zero_return(a, ...) assert_false_return(a, ##__VA_ARGS__) + +#define assert_positive_return(a, status, fmt, ...) \ + ({ \ + 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; \ + } \ + }) + +#define assert_negative_return(a, status, fmt, ...) \ + ({ \ + 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; \ + } \ + }) + #define assert_equal_return(a, b, status, fmt, ...) \ ({ \ if (!((a) == (b))) { \ |
