summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Jones <pjones@redhat.com>2021-07-02 14:56:10 -0400
committerPeter Jones <pjones@redhat.com>2021-07-20 09:44:25 -0400
commitfea0a3fd026f1f4ec82a513269764b8349ffd4a5 (patch)
tree402a890daa3ff890da8ae862df51aefeafd0fb06
parent8600b635624c52f24459c82848ae5907992571c7 (diff)
downloadefi-boot-shim-fea0a3fd026f1f4ec82a513269764b8349ffd4a5.tar.gz
efi-boot-shim-fea0a3fd026f1f4ec82a513269764b8349ffd4a5.zip
test.h: add assert_not_equal_*()
This test helper was conspicuously missing, so this patch just adds it at the obvious place. Signed-off-by: Peter Jones <pjones@redhat.com>
-rw-r--r--include/test.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/include/test.h b/include/test.h
index 9a4fdb1b..49a27a94 100644
--- a/include/test.h
+++ b/include/test.h
@@ -146,6 +146,19 @@ extern int debug;
rc_; \
})
+#define assert_not_equal_as_expr(a, b, status, fmt, ...) \
+ ({ \
+ __typeof__(status) rc_ = (__typeof__(status))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)); \
+ rc_ = status; \
+ } \
+ rc_; \
+ })
+
#define assert_as_expr(cond, status, fmt, ...) \
({ \
__typeof__(status) rc_ = (__typeof__(status))0; \
@@ -201,6 +214,14 @@ extern int debug;
return rc_; \
})
+#define assert_not_equal_return(a, b, status, fmt, ...) \
+ ({ \
+ __typeof__(status) rc_ = assert_not_equal_as_expr( \
+ a, b, status, fmt, ##__VA_ARGS__); \
+ if (rc_ != 0) \
+ return rc_; \
+ })
+
#define assert_return(cond, status, fmt, ...) \
({ \
__typeof__(status) rc_ = \
@@ -231,6 +252,41 @@ extern int debug;
} \
})
+#define assert_not_equal_goto(a, b, label, fmt, ...) \
+ ({ \
+ 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)); \
+ goto label; \
+ } \
+ })
+
+#define assert_true_goto(a, label, fmt, ...) \
+ ({ \
+ if (!(a)) { \
+ printf("%s:%d:" fmt, __func__, __LINE__, (a), \
+ ##__VA_ARGS__); \
+ printf("%s:%d:Assertion `%s' failed.\n", __func__, \
+ __LINE__, __stringify(!(a))); \
+ goto label; \
+ } \
+ })
+#define assert_nonzero_goto(a, ...) assert_true_goto(a, ##__VA_ARGS__)
+
+#define assert_false_goto(a, label, fmt, ...) \
+ ({ \
+ if (a) { \
+ printf("%s:%d:" fmt, __func__, __LINE__, (a), \
+ ##__VA_ARGS__); \
+ printf("%s:%d:Assertion `%s' failed.\n", __func__, \
+ __LINE__, __stringify(a)); \
+ goto label; \
+ } \
+ })
+#define assert_zero_goto(a, ...) assert_false_goto(a, ##__VA_ARGS__)
+
#define assert_negative_goto(a, label, fmt, ...) \
({ \
int rc_ = assert_negative_as_expr(a, -1, fmt, ##__VA_ARGS__); \