int err = 0; \
unsigned i; \
\
- pr_info("%-3s: %zu arithmetic tests\n", #t, \
- ARRAY_SIZE(t ## _tests)); \
for (i = 0; i < ARRAY_SIZE(t ## _tests); ++i) \
err |= do_test_ ## t(&t ## _tests[i]); \
+ pr_info("%zu %s arithmetic tests finished\n", \
+ ARRAY_SIZE(t ## _tests), #t); \
return err; \
}
static int __init test_overflow_shift(void)
{
int err = 0;
+ int count = 0;
/* Args are: value, shift, type, expected result, overflow expected */
#define TEST_ONE_SHIFT(a, s, t, expect, of) ({ \
pr_warn("got %llu\n", (u64)__d); \
__failed = 1; \
} \
- if (!__failed) \
- pr_info("ok: (%s)(%s << %s) == %s\n", #t, #a, #s, \
- of ? "overflow" : #expect); \
+ count++; \
__failed; \
})
err |= TEST_ONE_SHIFT(0, 31, s32, 0, false);
err |= TEST_ONE_SHIFT(0, 63, s64, 0, false);
+ pr_info("%d shift tests finished\n", count);
+
+#undef TEST_ONE_SHIFT
+
return err;
}
free ## want_arg (free_func, arg, ptr); \
return 1; \
} \
- pr_info(#func " detected saturation\n"); \
return 0; \
}
DEFINE_TEST_ALLOC(kmalloc_node, kfree, 0, 1, 1);
DEFINE_TEST_ALLOC(kzalloc, kfree, 0, 1, 0);
DEFINE_TEST_ALLOC(kzalloc_node, kfree, 0, 1, 1);
-DEFINE_TEST_ALLOC(vmalloc, vfree, 0, 0, 0);
-DEFINE_TEST_ALLOC(vmalloc_node, vfree, 0, 0, 1);
-DEFINE_TEST_ALLOC(vzalloc, vfree, 0, 0, 0);
-DEFINE_TEST_ALLOC(vzalloc_node, vfree, 0, 0, 1);
+DEFINE_TEST_ALLOC(__vmalloc, vfree, 0, 1, 0);
DEFINE_TEST_ALLOC(kvmalloc, kvfree, 0, 1, 0);
DEFINE_TEST_ALLOC(kvmalloc_node, kvfree, 0, 1, 1);
DEFINE_TEST_ALLOC(kvzalloc, kvfree, 0, 1, 0);
{
const char device_name[] = "overflow-test";
struct device *dev;
+ int count = 0;
int err = 0;
+#define check_allocation_overflow(alloc) ({ \
+ count++; \
+ test_ ## alloc(dev); \
+})
+
/* Create dummy device for devm_kmalloc()-family tests. */
dev = root_device_register(device_name);
if (IS_ERR(dev)) {
return 1;
}
- err |= test_kmalloc(NULL);
- err |= test_kmalloc_node(NULL);
- err |= test_kzalloc(NULL);
- err |= test_kzalloc_node(NULL);
- err |= test_kvmalloc(NULL);
- err |= test_kvmalloc_node(NULL);
- err |= test_kvzalloc(NULL);
- err |= test_kvzalloc_node(NULL);
- err |= test_vmalloc(NULL);
- err |= test_vmalloc_node(NULL);
- err |= test_vzalloc(NULL);
- err |= test_vzalloc_node(NULL);
- err |= test_devm_kmalloc(dev);
- err |= test_devm_kzalloc(dev);
+ err |= check_allocation_overflow(kmalloc);
+ err |= check_allocation_overflow(kmalloc_node);
+ err |= check_allocation_overflow(kzalloc);
+ err |= check_allocation_overflow(kzalloc_node);
+ err |= check_allocation_overflow(__vmalloc);
+ err |= check_allocation_overflow(kvmalloc);
+ err |= check_allocation_overflow(kvmalloc_node);
+ err |= check_allocation_overflow(kvzalloc);
+ err |= check_allocation_overflow(kvzalloc_node);
+ err |= check_allocation_overflow(devm_kmalloc);
+ err |= check_allocation_overflow(devm_kzalloc);
device_unregister(dev);
+ pr_info("%d allocation overflow tests finished\n", count);
+
+#undef check_allocation_overflow
+
return err;
}