Back to home page

LXR

 
 

    


0001 #include <linux/init.h>
0002 #include <linux/kernel.h>
0003 #include <linux/module.h>
0004 
0005 #define for_each_test(i, test)  \
0006     for (i = 0; i < ARRAY_SIZE(test); i++)
0007 
0008 struct test_fail {
0009     const char *str;
0010     unsigned int base;
0011 };
0012 
0013 #define DEFINE_TEST_FAIL(test)  \
0014     const struct test_fail test[] __initconst
0015 
0016 #define DECLARE_TEST_OK(type, test_type)    \
0017     test_type {             \
0018         const char *str;        \
0019         unsigned int base;      \
0020         type expected_res;      \
0021     }
0022 
0023 #define DEFINE_TEST_OK(type, test)  \
0024     const type test[] __initconst
0025 
0026 #define TEST_FAIL(fn, type, fmt, test)                  \
0027 {                                   \
0028     unsigned int i;                         \
0029                                     \
0030     for_each_test(i, test) {                    \
0031         const struct test_fail *t = &test[i];           \
0032         type tmp;                       \
0033         int rv;                         \
0034                                     \
0035         tmp = 0;                        \
0036         rv = fn(t->str, t->base, &tmp);             \
0037         if (rv >= 0) {                      \
0038             WARN(1, "str '%s', base %u, expected -E, got %d/" fmt "\n", \
0039                 t->str, t->base, rv, tmp);      \
0040             continue;                   \
0041         }                           \
0042     }                               \
0043 }
0044 
0045 #define TEST_OK(fn, type, fmt, test)                    \
0046 {                                   \
0047     unsigned int i;                         \
0048                                     \
0049     for_each_test(i, test) {                    \
0050         const typeof(test[0]) *t = &test[i];            \
0051         type res;                       \
0052         int rv;                         \
0053                                     \
0054         rv = fn(t->str, t->base, &res);             \
0055         if (rv != 0) {                      \
0056             WARN(1, "str '%s', base %u, expected 0/" fmt ", got %d\n",  \
0057                 t->str, t->base, t->expected_res, rv);  \
0058             continue;                   \
0059         }                           \
0060         if (res != t->expected_res) {               \
0061             WARN(1, "str '%s', base %u, expected " fmt ", got " fmt "\n",   \
0062                 t->str, t->base, t->expected_res, res); \
0063             continue;                   \
0064         }                           \
0065     }                               \
0066 }
0067 
0068 static void __init test_kstrtoull_ok(void)
0069 {
0070     DECLARE_TEST_OK(unsigned long long, struct test_ull);
0071     static DEFINE_TEST_OK(struct test_ull, test_ull_ok) = {
0072         {"0",   10, 0ULL},
0073         {"1",   10, 1ULL},
0074         {"127", 10, 127ULL},
0075         {"128", 10, 128ULL},
0076         {"129", 10, 129ULL},
0077         {"255", 10, 255ULL},
0078         {"256", 10, 256ULL},
0079         {"257", 10, 257ULL},
0080         {"32767",   10, 32767ULL},
0081         {"32768",   10, 32768ULL},
0082         {"32769",   10, 32769ULL},
0083         {"65535",   10, 65535ULL},
0084         {"65536",   10, 65536ULL},
0085         {"65537",   10, 65537ULL},
0086         {"2147483647",  10, 2147483647ULL},
0087         {"2147483648",  10, 2147483648ULL},
0088         {"2147483649",  10, 2147483649ULL},
0089         {"4294967295",  10, 4294967295ULL},
0090         {"4294967296",  10, 4294967296ULL},
0091         {"4294967297",  10, 4294967297ULL},
0092         {"9223372036854775807", 10, 9223372036854775807ULL},
0093         {"9223372036854775808", 10, 9223372036854775808ULL},
0094         {"9223372036854775809", 10, 9223372036854775809ULL},
0095         {"18446744073709551614",    10, 18446744073709551614ULL},
0096         {"18446744073709551615",    10, 18446744073709551615ULL},
0097 
0098         {"00",      8,  00ULL},
0099         {"01",      8,  01ULL},
0100         {"0177",    8,  0177ULL},
0101         {"0200",    8,  0200ULL},
0102         {"0201",    8,  0201ULL},
0103         {"0377",    8,  0377ULL},
0104         {"0400",    8,  0400ULL},
0105         {"0401",    8,  0401ULL},
0106         {"077777",  8,  077777ULL},
0107         {"0100000", 8,  0100000ULL},
0108         {"0100001", 8,  0100001ULL},
0109         {"0177777", 8,  0177777ULL},
0110         {"0200000", 8,  0200000ULL},
0111         {"0200001", 8,  0200001ULL},
0112         {"017777777777",    8,  017777777777ULL},
0113         {"020000000000",    8,  020000000000ULL},
0114         {"020000000001",    8,  020000000001ULL},
0115         {"037777777777",    8,  037777777777ULL},
0116         {"040000000000",    8,  040000000000ULL},
0117         {"040000000001",    8,  040000000001ULL},
0118         {"0777777777777777777777",  8,  0777777777777777777777ULL},
0119         {"01000000000000000000000", 8,  01000000000000000000000ULL},
0120         {"01000000000000000000001", 8,  01000000000000000000001ULL},
0121         {"01777777777777777777776", 8,  01777777777777777777776ULL},
0122         {"01777777777777777777777", 8,  01777777777777777777777ULL},
0123 
0124         {"0x0",     16, 0x0ULL},
0125         {"0x1",     16, 0x1ULL},
0126         {"0x7f",    16, 0x7fULL},
0127         {"0x80",    16, 0x80ULL},
0128         {"0x81",    16, 0x81ULL},
0129         {"0xff",    16, 0xffULL},
0130         {"0x100",   16, 0x100ULL},
0131         {"0x101",   16, 0x101ULL},
0132         {"0x7fff",  16, 0x7fffULL},
0133         {"0x8000",  16, 0x8000ULL},
0134         {"0x8001",  16, 0x8001ULL},
0135         {"0xffff",  16, 0xffffULL},
0136         {"0x10000", 16, 0x10000ULL},
0137         {"0x10001", 16, 0x10001ULL},
0138         {"0x7fffffff",  16, 0x7fffffffULL},
0139         {"0x80000000",  16, 0x80000000ULL},
0140         {"0x80000001",  16, 0x80000001ULL},
0141         {"0xffffffff",  16, 0xffffffffULL},
0142         {"0x100000000", 16, 0x100000000ULL},
0143         {"0x100000001", 16, 0x100000001ULL},
0144         {"0x7fffffffffffffff",  16, 0x7fffffffffffffffULL},
0145         {"0x8000000000000000",  16, 0x8000000000000000ULL},
0146         {"0x8000000000000001",  16, 0x8000000000000001ULL},
0147         {"0xfffffffffffffffe",  16, 0xfffffffffffffffeULL},
0148         {"0xffffffffffffffff",  16, 0xffffffffffffffffULL},
0149 
0150         {"0\n", 0,  0ULL},
0151     };
0152     TEST_OK(kstrtoull, unsigned long long, "%llu", test_ull_ok);
0153 }
0154 
0155 static void __init test_kstrtoull_fail(void)
0156 {
0157     static DEFINE_TEST_FAIL(test_ull_fail) = {
0158         {"",    0},
0159         {"",    8},
0160         {"",    10},
0161         {"",    16},
0162         {"\n",  0},
0163         {"\n",  8},
0164         {"\n",  10},
0165         {"\n",  16},
0166         {"\n0", 0},
0167         {"\n0", 8},
0168         {"\n0", 10},
0169         {"\n0", 16},
0170         {"+",   0},
0171         {"+",   8},
0172         {"+",   10},
0173         {"+",   16},
0174         {"-",   0},
0175         {"-",   8},
0176         {"-",   10},
0177         {"-",   16},
0178         {"0x",  0},
0179         {"0x",  16},
0180         {"0X",  0},
0181         {"0X",  16},
0182         {"0 ",  0},
0183         {"1+",  0},
0184         {"1-",  0},
0185         {" 2",  0},
0186         /* base autodetection */
0187         {"0x0z",    0},
0188         {"0z",      0},
0189         {"a",       0},
0190         /* digit >= base */
0191         {"2",   2},
0192         {"8",   8},
0193         {"a",   10},
0194         {"A",   10},
0195         {"g",   16},
0196         {"G",   16},
0197         /* overflow */
0198         {"10000000000000000000000000000000000000000000000000000000000000000",   2},
0199         {"2000000000000000000000",  8},
0200         {"18446744073709551616",    10},
0201         {"10000000000000000",   16},
0202         /* negative */
0203         {"-0", 0},
0204         {"-0", 8},
0205         {"-0", 10},
0206         {"-0", 16},
0207         {"-1", 0},
0208         {"-1", 8},
0209         {"-1", 10},
0210         {"-1", 16},
0211         /* sign is first character if any */
0212         {"-+1", 0},
0213         {"-+1", 8},
0214         {"-+1", 10},
0215         {"-+1", 16},
0216         /* nothing after \n */
0217         {"0\n0", 0},
0218         {"0\n0", 8},
0219         {"0\n0", 10},
0220         {"0\n0", 16},
0221         {"0\n+", 0},
0222         {"0\n+", 8},
0223         {"0\n+", 10},
0224         {"0\n+", 16},
0225         {"0\n-", 0},
0226         {"0\n-", 8},
0227         {"0\n-", 10},
0228         {"0\n-", 16},
0229         {"0\n ", 0},
0230         {"0\n ", 8},
0231         {"0\n ", 10},
0232         {"0\n ", 16},
0233     };
0234     TEST_FAIL(kstrtoull, unsigned long long, "%llu", test_ull_fail);
0235 }
0236 
0237 static void __init test_kstrtoll_ok(void)
0238 {
0239     DECLARE_TEST_OK(long long, struct test_ll);
0240     static DEFINE_TEST_OK(struct test_ll, test_ll_ok) = {
0241         {"0",   10, 0LL},
0242         {"1",   10, 1LL},
0243         {"127", 10, 127LL},
0244         {"128", 10, 128LL},
0245         {"129", 10, 129LL},
0246         {"255", 10, 255LL},
0247         {"256", 10, 256LL},
0248         {"257", 10, 257LL},
0249         {"32767",   10, 32767LL},
0250         {"32768",   10, 32768LL},
0251         {"32769",   10, 32769LL},
0252         {"65535",   10, 65535LL},
0253         {"65536",   10, 65536LL},
0254         {"65537",   10, 65537LL},
0255         {"2147483647",  10, 2147483647LL},
0256         {"2147483648",  10, 2147483648LL},
0257         {"2147483649",  10, 2147483649LL},
0258         {"4294967295",  10, 4294967295LL},
0259         {"4294967296",  10, 4294967296LL},
0260         {"4294967297",  10, 4294967297LL},
0261         {"9223372036854775807", 10, 9223372036854775807LL},
0262 
0263         {"-0",  10, 0LL},
0264         {"-1",  10, -1LL},
0265         {"-2",  10, -2LL},
0266         {"-9223372036854775808",    10, LLONG_MIN},
0267     };
0268     TEST_OK(kstrtoll, long long, "%lld", test_ll_ok);
0269 }
0270 
0271 static void __init test_kstrtoll_fail(void)
0272 {
0273     static DEFINE_TEST_FAIL(test_ll_fail) = {
0274         {"9223372036854775808", 10},
0275         {"9223372036854775809", 10},
0276         {"18446744073709551614",    10},
0277         {"18446744073709551615",    10},
0278         {"-9223372036854775809",    10},
0279         {"-18446744073709551614",   10},
0280         {"-18446744073709551615",   10},
0281         /* sign is first character if any */
0282         {"-+1", 0},
0283         {"-+1", 8},
0284         {"-+1", 10},
0285         {"-+1", 16},
0286     };
0287     TEST_FAIL(kstrtoll, long long, "%lld", test_ll_fail);
0288 }
0289 
0290 static void __init test_kstrtou64_ok(void)
0291 {
0292     DECLARE_TEST_OK(u64, struct test_u64);
0293     static DEFINE_TEST_OK(struct test_u64, test_u64_ok) = {
0294         {"0",   10, 0},
0295         {"1",   10, 1},
0296         {"126", 10, 126},
0297         {"127", 10, 127},
0298         {"128", 10, 128},
0299         {"129", 10, 129},
0300         {"254", 10, 254},
0301         {"255", 10, 255},
0302         {"256", 10, 256},
0303         {"257", 10, 257},
0304         {"32766",   10, 32766},
0305         {"32767",   10, 32767},
0306         {"32768",   10, 32768},
0307         {"32769",   10, 32769},
0308         {"65534",   10, 65534},
0309         {"65535",   10, 65535},
0310         {"65536",   10, 65536},
0311         {"65537",   10, 65537},
0312         {"2147483646",  10, 2147483646},
0313         {"2147483647",  10, 2147483647},
0314         {"2147483648",  10, 2147483648ULL},
0315         {"2147483649",  10, 2147483649ULL},
0316         {"4294967294",  10, 4294967294ULL},
0317         {"4294967295",  10, 4294967295ULL},
0318         {"4294967296",  10, 4294967296ULL},
0319         {"4294967297",  10, 4294967297ULL},
0320         {"9223372036854775806", 10, 9223372036854775806ULL},
0321         {"9223372036854775807", 10, 9223372036854775807ULL},
0322         {"9223372036854775808", 10, 9223372036854775808ULL},
0323         {"9223372036854775809", 10, 9223372036854775809ULL},
0324         {"18446744073709551614",    10, 18446744073709551614ULL},
0325         {"18446744073709551615",    10, 18446744073709551615ULL},
0326     };
0327     TEST_OK(kstrtou64, u64, "%llu", test_u64_ok);
0328 }
0329 
0330 static void __init test_kstrtou64_fail(void)
0331 {
0332     static DEFINE_TEST_FAIL(test_u64_fail) = {
0333         {"-2",  10},
0334         {"-1",  10},
0335         {"18446744073709551616",    10},
0336         {"18446744073709551617",    10},
0337     };
0338     TEST_FAIL(kstrtou64, u64, "%llu", test_u64_fail);
0339 }
0340 
0341 static void __init test_kstrtos64_ok(void)
0342 {
0343     DECLARE_TEST_OK(s64, struct test_s64);
0344     static DEFINE_TEST_OK(struct test_s64, test_s64_ok) = {
0345         {"-128",    10, -128},
0346         {"-127",    10, -127},
0347         {"-1",  10, -1},
0348         {"0",   10, 0},
0349         {"1",   10, 1},
0350         {"126", 10, 126},
0351         {"127", 10, 127},
0352         {"128", 10, 128},
0353         {"129", 10, 129},
0354         {"254", 10, 254},
0355         {"255", 10, 255},
0356         {"256", 10, 256},
0357         {"257", 10, 257},
0358         {"32766",   10, 32766},
0359         {"32767",   10, 32767},
0360         {"32768",   10, 32768},
0361         {"32769",   10, 32769},
0362         {"65534",   10, 65534},
0363         {"65535",   10, 65535},
0364         {"65536",   10, 65536},
0365         {"65537",   10, 65537},
0366         {"2147483646",  10, 2147483646},
0367         {"2147483647",  10, 2147483647},
0368         {"2147483648",  10, 2147483648LL},
0369         {"2147483649",  10, 2147483649LL},
0370         {"4294967294",  10, 4294967294LL},
0371         {"4294967295",  10, 4294967295LL},
0372         {"4294967296",  10, 4294967296LL},
0373         {"4294967297",  10, 4294967297LL},
0374         {"9223372036854775806", 10, 9223372036854775806LL},
0375         {"9223372036854775807", 10, 9223372036854775807LL},
0376     };
0377     TEST_OK(kstrtos64, s64, "%lld", test_s64_ok);
0378 }
0379 
0380 static void __init test_kstrtos64_fail(void)
0381 {
0382     static DEFINE_TEST_FAIL(test_s64_fail) = {
0383         {"9223372036854775808", 10},
0384         {"9223372036854775809", 10},
0385         {"18446744073709551614",    10},
0386         {"18446744073709551615",    10},
0387         {"18446744073709551616",    10},
0388         {"18446744073709551617",    10},
0389     };
0390     TEST_FAIL(kstrtos64, s64, "%lld", test_s64_fail);
0391 }
0392 
0393 static void __init test_kstrtou32_ok(void)
0394 {
0395     DECLARE_TEST_OK(u32, struct test_u32);
0396     static DEFINE_TEST_OK(struct test_u32, test_u32_ok) = {
0397         {"0",   10, 0},
0398         {"1",   10, 1},
0399         {"126", 10, 126},
0400         {"127", 10, 127},
0401         {"128", 10, 128},
0402         {"129", 10, 129},
0403         {"254", 10, 254},
0404         {"255", 10, 255},
0405         {"256", 10, 256},
0406         {"257", 10, 257},
0407         {"32766",   10, 32766},
0408         {"32767",   10, 32767},
0409         {"32768",   10, 32768},
0410         {"32769",   10, 32769},
0411         {"65534",   10, 65534},
0412         {"65535",   10, 65535},
0413         {"65536",   10, 65536},
0414         {"65537",   10, 65537},
0415         {"2147483646",  10, 2147483646},
0416         {"2147483647",  10, 2147483647},
0417         {"2147483648",  10, 2147483648U},
0418         {"2147483649",  10, 2147483649U},
0419         {"4294967294",  10, 4294967294U},
0420         {"4294967295",  10, 4294967295U},
0421     };
0422     TEST_OK(kstrtou32, u32, "%u", test_u32_ok);
0423 }
0424 
0425 static void __init test_kstrtou32_fail(void)
0426 {
0427     static DEFINE_TEST_FAIL(test_u32_fail) = {
0428         {"-2",  10},
0429         {"-1",  10},
0430         {"4294967296",  10},
0431         {"4294967297",  10},
0432         {"9223372036854775806", 10},
0433         {"9223372036854775807", 10},
0434         {"9223372036854775808", 10},
0435         {"9223372036854775809", 10},
0436         {"18446744073709551614",    10},
0437         {"18446744073709551615",    10},
0438         {"18446744073709551616",    10},
0439         {"18446744073709551617",    10},
0440     };
0441     TEST_FAIL(kstrtou32, u32, "%u", test_u32_fail);
0442 }
0443 
0444 static void __init test_kstrtos32_ok(void)
0445 {
0446     DECLARE_TEST_OK(s32, struct test_s32);
0447     static DEFINE_TEST_OK(struct test_s32, test_s32_ok) = {
0448         {"-128",    10, -128},
0449         {"-127",    10, -127},
0450         {"-1",  10, -1},
0451         {"0",   10, 0},
0452         {"1",   10, 1},
0453         {"126", 10, 126},
0454         {"127", 10, 127},
0455         {"128", 10, 128},
0456         {"129", 10, 129},
0457         {"254", 10, 254},
0458         {"255", 10, 255},
0459         {"256", 10, 256},
0460         {"257", 10, 257},
0461         {"32766",   10, 32766},
0462         {"32767",   10, 32767},
0463         {"32768",   10, 32768},
0464         {"32769",   10, 32769},
0465         {"65534",   10, 65534},
0466         {"65535",   10, 65535},
0467         {"65536",   10, 65536},
0468         {"65537",   10, 65537},
0469         {"2147483646",  10, 2147483646},
0470         {"2147483647",  10, 2147483647},
0471     };
0472     TEST_OK(kstrtos32, s32, "%d", test_s32_ok);
0473 }
0474 
0475 static void __init test_kstrtos32_fail(void)
0476 {
0477     static DEFINE_TEST_FAIL(test_s32_fail) = {
0478         {"2147483648",  10},
0479         {"2147483649",  10},
0480         {"4294967294",  10},
0481         {"4294967295",  10},
0482         {"4294967296",  10},
0483         {"4294967297",  10},
0484         {"9223372036854775806", 10},
0485         {"9223372036854775807", 10},
0486         {"9223372036854775808", 10},
0487         {"9223372036854775809", 10},
0488         {"18446744073709551614",    10},
0489         {"18446744073709551615",    10},
0490         {"18446744073709551616",    10},
0491         {"18446744073709551617",    10},
0492     };
0493     TEST_FAIL(kstrtos32, s32, "%d", test_s32_fail);
0494 }
0495 
0496 static void __init test_kstrtou16_ok(void)
0497 {
0498     DECLARE_TEST_OK(u16, struct test_u16);
0499     static DEFINE_TEST_OK(struct test_u16, test_u16_ok) = {
0500         {"0",   10, 0},
0501         {"1",   10, 1},
0502         {"126", 10, 126},
0503         {"127", 10, 127},
0504         {"128", 10, 128},
0505         {"129", 10, 129},
0506         {"254", 10, 254},
0507         {"255", 10, 255},
0508         {"256", 10, 256},
0509         {"257", 10, 257},
0510         {"32766",   10, 32766},
0511         {"32767",   10, 32767},
0512         {"32768",   10, 32768},
0513         {"32769",   10, 32769},
0514         {"65534",   10, 65534},
0515         {"65535",   10, 65535},
0516     };
0517     TEST_OK(kstrtou16, u16, "%hu", test_u16_ok);
0518 }
0519 
0520 static void __init test_kstrtou16_fail(void)
0521 {
0522     static DEFINE_TEST_FAIL(test_u16_fail) = {
0523         {"-2",  10},
0524         {"-1",  10},
0525         {"65536",   10},
0526         {"65537",   10},
0527         {"2147483646",  10},
0528         {"2147483647",  10},
0529         {"2147483648",  10},
0530         {"2147483649",  10},
0531         {"4294967294",  10},
0532         {"4294967295",  10},
0533         {"4294967296",  10},
0534         {"4294967297",  10},
0535         {"9223372036854775806", 10},
0536         {"9223372036854775807", 10},
0537         {"9223372036854775808", 10},
0538         {"9223372036854775809", 10},
0539         {"18446744073709551614",    10},
0540         {"18446744073709551615",    10},
0541         {"18446744073709551616",    10},
0542         {"18446744073709551617",    10},
0543     };
0544     TEST_FAIL(kstrtou16, u16, "%hu", test_u16_fail);
0545 }
0546 
0547 static void __init test_kstrtos16_ok(void)
0548 {
0549     DECLARE_TEST_OK(s16, struct test_s16);
0550     static DEFINE_TEST_OK(struct test_s16, test_s16_ok) = {
0551         {"-130",    10, -130},
0552         {"-129",    10, -129},
0553         {"-128",    10, -128},
0554         {"-127",    10, -127},
0555         {"-1",  10, -1},
0556         {"0",   10, 0},
0557         {"1",   10, 1},
0558         {"126", 10, 126},
0559         {"127", 10, 127},
0560         {"128", 10, 128},
0561         {"129", 10, 129},
0562         {"254", 10, 254},
0563         {"255", 10, 255},
0564         {"256", 10, 256},
0565         {"257", 10, 257},
0566         {"32766",   10, 32766},
0567         {"32767",   10, 32767},
0568     };
0569     TEST_OK(kstrtos16, s16, "%hd", test_s16_ok);
0570 }
0571 
0572 static void __init test_kstrtos16_fail(void)
0573 {
0574     static DEFINE_TEST_FAIL(test_s16_fail) = {
0575         {"32768",   10},
0576         {"32769",   10},
0577         {"65534",   10},
0578         {"65535",   10},
0579         {"65536",   10},
0580         {"65537",   10},
0581         {"2147483646",  10},
0582         {"2147483647",  10},
0583         {"2147483648",  10},
0584         {"2147483649",  10},
0585         {"4294967294",  10},
0586         {"4294967295",  10},
0587         {"4294967296",  10},
0588         {"4294967297",  10},
0589         {"9223372036854775806", 10},
0590         {"9223372036854775807", 10},
0591         {"9223372036854775808", 10},
0592         {"9223372036854775809", 10},
0593         {"18446744073709551614",    10},
0594         {"18446744073709551615",    10},
0595         {"18446744073709551616",    10},
0596         {"18446744073709551617",    10},
0597     };
0598     TEST_FAIL(kstrtos16, s16, "%hd", test_s16_fail);
0599 }
0600 
0601 static void __init test_kstrtou8_ok(void)
0602 {
0603     DECLARE_TEST_OK(u8, struct test_u8);
0604     static DEFINE_TEST_OK(struct test_u8, test_u8_ok) = {
0605         {"0",   10, 0},
0606         {"1",   10, 1},
0607         {"126", 10, 126},
0608         {"127", 10, 127},
0609         {"128", 10, 128},
0610         {"129", 10, 129},
0611         {"254", 10, 254},
0612         {"255", 10, 255},
0613     };
0614     TEST_OK(kstrtou8, u8, "%hhu", test_u8_ok);
0615 }
0616 
0617 static void __init test_kstrtou8_fail(void)
0618 {
0619     static DEFINE_TEST_FAIL(test_u8_fail) = {
0620         {"-2",  10},
0621         {"-1",  10},
0622         {"256", 10},
0623         {"257", 10},
0624         {"32766",   10},
0625         {"32767",   10},
0626         {"32768",   10},
0627         {"32769",   10},
0628         {"65534",   10},
0629         {"65535",   10},
0630         {"65536",   10},
0631         {"65537",   10},
0632         {"2147483646",  10},
0633         {"2147483647",  10},
0634         {"2147483648",  10},
0635         {"2147483649",  10},
0636         {"4294967294",  10},
0637         {"4294967295",  10},
0638         {"4294967296",  10},
0639         {"4294967297",  10},
0640         {"9223372036854775806", 10},
0641         {"9223372036854775807", 10},
0642         {"9223372036854775808", 10},
0643         {"9223372036854775809", 10},
0644         {"18446744073709551614",    10},
0645         {"18446744073709551615",    10},
0646         {"18446744073709551616",    10},
0647         {"18446744073709551617",    10},
0648     };
0649     TEST_FAIL(kstrtou8, u8, "%hhu", test_u8_fail);
0650 }
0651 
0652 static void __init test_kstrtos8_ok(void)
0653 {
0654     DECLARE_TEST_OK(s8, struct test_s8);
0655     static DEFINE_TEST_OK(struct test_s8, test_s8_ok) = {
0656         {"-128",    10, -128},
0657         {"-127",    10, -127},
0658         {"-1",  10, -1},
0659         {"0",   10, 0},
0660         {"1",   10, 1},
0661         {"126", 10, 126},
0662         {"127", 10, 127},
0663     };
0664     TEST_OK(kstrtos8, s8, "%hhd", test_s8_ok);
0665 }
0666 
0667 static void __init test_kstrtos8_fail(void)
0668 {
0669     static DEFINE_TEST_FAIL(test_s8_fail) = {
0670         {"-130",    10},
0671         {"-129",    10},
0672         {"128", 10},
0673         {"129", 10},
0674         {"254", 10},
0675         {"255", 10},
0676         {"256", 10},
0677         {"257", 10},
0678         {"32766",   10},
0679         {"32767",   10},
0680         {"32768",   10},
0681         {"32769",   10},
0682         {"65534",   10},
0683         {"65535",   10},
0684         {"65536",   10},
0685         {"65537",   10},
0686         {"2147483646",  10},
0687         {"2147483647",  10},
0688         {"2147483648",  10},
0689         {"2147483649",  10},
0690         {"4294967294",  10},
0691         {"4294967295",  10},
0692         {"4294967296",  10},
0693         {"4294967297",  10},
0694         {"9223372036854775806", 10},
0695         {"9223372036854775807", 10},
0696         {"9223372036854775808", 10},
0697         {"9223372036854775809", 10},
0698         {"18446744073709551614",    10},
0699         {"18446744073709551615",    10},
0700         {"18446744073709551616",    10},
0701         {"18446744073709551617",    10},
0702     };
0703     TEST_FAIL(kstrtos8, s8, "%hhd", test_s8_fail);
0704 }
0705 
0706 static int __init test_kstrtox_init(void)
0707 {
0708     test_kstrtoull_ok();
0709     test_kstrtoull_fail();
0710     test_kstrtoll_ok();
0711     test_kstrtoll_fail();
0712 
0713     test_kstrtou64_ok();
0714     test_kstrtou64_fail();
0715     test_kstrtos64_ok();
0716     test_kstrtos64_fail();
0717 
0718     test_kstrtou32_ok();
0719     test_kstrtou32_fail();
0720     test_kstrtos32_ok();
0721     test_kstrtos32_fail();
0722 
0723     test_kstrtou16_ok();
0724     test_kstrtou16_fail();
0725     test_kstrtos16_ok();
0726     test_kstrtos16_fail();
0727 
0728     test_kstrtou8_ok();
0729     test_kstrtou8_fail();
0730     test_kstrtos8_ok();
0731     test_kstrtos8_fail();
0732     return -EINVAL;
0733 }
0734 module_init(test_kstrtox_init);
0735 MODULE_LICENSE("Dual BSD/GPL");