diff options
Diffstat (limited to 'lib/test_overflow.c')
-rw-r--r-- | lib/test_overflow.c | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/lib/test_overflow.c b/lib/test_overflow.c index af01e46500be..fa87e283b149 100644 --- a/lib/test_overflow.c +++ b/lib/test_overflow.c | |||
@@ -211,35 +211,31 @@ DEFINE_TEST_ARRAY(s64) = { | |||
211 | {0, -S64_MAX, -S64_MAX, S64_MAX, 0, false, false, false}, | 211 | {0, -S64_MAX, -S64_MAX, S64_MAX, 0, false, false, false}, |
212 | }; | 212 | }; |
213 | 213 | ||
214 | #define check_one_op(t, fmt, op, sym, a, b, r, of) do { \ | ||
215 | t _r; \ | ||
216 | bool _of; \ | ||
217 | \ | ||
218 | _of = check_ ## op ## _overflow(a, b, &_r); \ | ||
219 | if (_of != of) { \ | ||
220 | pr_warn("expected "fmt" "sym" "fmt \ | ||
221 | " to%s overflow (type %s)\n", \ | ||
222 | a, b, of ? "" : " not", #t); \ | ||
223 | } \ | ||
224 | if (_r != r) { \ | ||
225 | pr_warn("expected "fmt" "sym" "fmt" == " \ | ||
226 | fmt", got "fmt" (type %s)\n", \ | ||
227 | a, b, r, _r, #t); \ | ||
228 | } \ | ||
229 | } while (0) | ||
230 | |||
214 | #define DEFINE_TEST_FUNC(t, fmt) \ | 231 | #define DEFINE_TEST_FUNC(t, fmt) \ |
215 | static void __init do_test_ ## t(const struct test_ ## t *p) \ | 232 | static void __init do_test_ ## t(const struct test_ ## t *p) \ |
216 | { \ | 233 | { \ |
217 | t r; \ | 234 | check_one_op(t, fmt, add, "+", p->a, p->b, p->sum, p->s_of); \ |
218 | bool of; \ | 235 | check_one_op(t, fmt, add, "+", p->b, p->a, p->sum, p->s_of); \ |
219 | \ | 236 | check_one_op(t, fmt, sub, "-", p->a, p->b, p->diff, p->d_of); \ |
220 | of = check_add_overflow(p->a, p->b, &r); \ | 237 | check_one_op(t, fmt, mul, "*", p->a, p->b, p->prod, p->p_of); \ |
221 | if (of != p->s_of) \ | 238 | check_one_op(t, fmt, mul, "*", p->b, p->a, p->prod, p->p_of); \ |
222 | pr_warn("expected "fmt" + "fmt" to%s overflow (type %s)\n", \ | ||
223 | p->a, p->b, p->s_of ? "" : " not", #t); \ | ||
224 | if (r != p->sum) \ | ||
225 | pr_warn("expected "fmt" + "fmt" == "fmt", got "fmt" (type %s)\n", \ | ||
226 | p->a, p->b, p->sum, r, #t); \ | ||
227 | \ | ||
228 | of = check_sub_overflow(p->a, p->b, &r); \ | ||
229 | if (of != p->d_of) \ | ||
230 | pr_warn("expected "fmt" - "fmt" to%s overflow (type %s)\n", \ | ||
231 | p->a, p->b, p->s_of ? "" : " not", #t); \ | ||
232 | if (r != p->diff) \ | ||
233 | pr_warn("expected "fmt" - "fmt" == "fmt", got "fmt" (type %s)\n", \ | ||
234 | p->a, p->b, p->diff, r, #t); \ | ||
235 | \ | ||
236 | of = check_mul_overflow(p->a, p->b, &r); \ | ||
237 | if (of != p->p_of) \ | ||
238 | pr_warn("expected "fmt" * "fmt" to%s overflow (type %s)\n", \ | ||
239 | p->a, p->b, p->p_of ? "" : " not", #t); \ | ||
240 | if (r != p->prod) \ | ||
241 | pr_warn("expected "fmt" * "fmt" == "fmt", got "fmt" (type %s)\n", \ | ||
242 | p->a, p->b, p->prod, r, #t); \ | ||
243 | } \ | 239 | } \ |
244 | \ | 240 | \ |
245 | static void __init test_ ## t ## _overflow(void) { \ | 241 | static void __init test_ ## t ## _overflow(void) { \ |