#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/overflow.h>
#include <linux/vmalloc.h>
#define DEFINE_TEST_ARRAY(t) \
static const struct test_ ## t { \
} t ## _tests[] __initconst
DEFINE_TEST_ARRAY(u8) = {
{0, 0, 0, 0, 0, false, false, false},
{1, 1, 2, 0, 1, false, false, false},
{0, 1, 1, U8_MAX, 0, false, true, false},
{1, 0, 1, 1, 0, false, false, false},
{0, U8_MAX, U8_MAX, 1, 0, false, true, false},
{U8_MAX, 0, U8_MAX, U8_MAX, 0, false, false, false},
{1, U8_MAX, 0, 2, U8_MAX, true, true, false},
{U8_MAX, 1, 0, U8_MAX-1, U8_MAX, true, false, false},
{U8_MAX, U8_MAX, U8_MAX-1, 0, 1, true, false, true},
{U8_MAX, U8_MAX-1, U8_MAX-2, 1, 2, true, false, true},
{U8_MAX-1, U8_MAX, U8_MAX-2, U8_MAX, 2, true, true, true},
{1U << 3, 1U << 3, 1U << 4, 0, 1U << 6, false, false, false},
{1U << 4, 1U << 4, 1U << 5, 0, 0, false, false, true},
{1U << 4, 1U << 3, 3*(1U << 3), 1U << 3, 1U << 7, false, false, false},
{1U << 7, 1U << 7, 0, 0, 0, true, false, true},
{48, 32, 80, 16, 0, false, false, true},
{128, 128, 0, 0, 0, true, false, true},
{123, 234, 101, 145, 110, true, true, true},
DEFINE_TEST_ARRAY(u16) = {
{0, 0, 0, 0, 0, false, false, false},
{1, 1, 2, 0, 1, false, false, false},
{0, 1, 1, U16_MAX, 0, false, true, false},
{1, 0, 1, 1, 0, false, false, false},
{0, U16_MAX, U16_MAX, 1, 0, false, true, false},
{U16_MAX, 0, U16_MAX, U16_MAX, 0, false, false, false},
{1, U16_MAX, 0, 2, U16_MAX, true, true, false},
{U16_MAX, 1, 0, U16_MAX-1, U16_MAX, true, false, false},
{U16_MAX, U16_MAX, U16_MAX-1, 0, 1, true, false, true},
{U16_MAX, U16_MAX-1, U16_MAX-2, 1, 2, true, false, true},
{U16_MAX-1, U16_MAX, U16_MAX-2, U16_MAX, 2, true, true, true},
{1U << 7, 1U << 7, 1U << 8, 0, 1U << 14, false, false, false},
{1U << 8, 1U << 8, 1U << 9, 0, 0, false, false, true},
{1U << 8, 1U << 7, 3*(1U << 7), 1U << 7, 1U << 15, false, false, false},
{1U << 15, 1U << 15, 0, 0, 0, true, false, true},
{123, 234, 357, 65425, 28782, false, true, false},
{1234, 2345, 3579, 64425, 10146, false, true, true},
DEFINE_TEST_ARRAY(u32) = {
{0, 0, 0, 0, 0, false, false, false},
{1, 1, 2, 0, 1, false, false, false},
{0, 1, 1, U32_MAX, 0, false, true, false},
{1, 0, 1, 1, 0, false, false, false},
{0, U32_MAX, U32_MAX, 1, 0, false, true, false},
{U32_MAX, 0, U32_MAX, U32_MAX, 0, false, false, false},
{1, U32_MAX, 0, 2, U32_MAX, true, true, false},
{U32_MAX, 1, 0, U32_MAX-1, U32_MAX, true, false, false},
{U32_MAX, U32_MAX, U32_MAX-1, 0, 1, true, false, true},
{U32_MAX, U32_MAX-1, U32_MAX-2, 1, 2, true, false, true},
{U32_MAX-1, U32_MAX, U32_MAX-2, U32_MAX, 2, true, true, true},
{1U << 15, 1U << 15, 1U << 16, 0, 1U << 30, false, false, false},
{1U << 16, 1U << 16, 1U << 17, 0, 0, false, false, true},
{1U << 16, 1U << 15, 3*(1U << 15), 1U << 15, 1U << 31, false, false, false},
{1U << 31, 1U << 31, 0, 0, 0, true, false, true},
{-2U, 1U, -1U, -3U, -2U, false, false, false},
{-4U, 5U, 1U, -9U, -20U, true, false, true},
DEFINE_TEST_ARRAY(u64) = {