Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <stdio.h>
0003 #include <byteswap.h>
0004 #include "utils.h"
0005 #include "subunit.h"
0006 
0007 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
0008 #define cpu_to_be32(x)      bswap_32(x)
0009 #define be32_to_cpu(x)      bswap_32(x)
0010 #define be16_to_cpup(x)     bswap_16(*x)
0011 #define cpu_to_be64(x)      bswap_64(x)
0012 #else
0013 #define cpu_to_be32(x)      (x)
0014 #define be32_to_cpu(x)      (x)
0015 #define be16_to_cpup(x)     (*x)
0016 #define cpu_to_be64(x)      (x)
0017 #endif
0018 
0019 #include "vphn.c"
0020 
0021 static struct test {
0022     char *descr;
0023     long input[VPHN_REGISTER_COUNT];
0024     u32 expected[VPHN_ASSOC_BUFSIZE];
0025 } all_tests[] = {
0026     {
0027         "vphn: no data",
0028         {
0029             0xffffffffffffffff,
0030             0xffffffffffffffff,
0031             0xffffffffffffffff,
0032             0xffffffffffffffff,
0033             0xffffffffffffffff,
0034             0xffffffffffffffff,
0035         },
0036         {
0037             0x00000000
0038         }
0039     },
0040     {
0041         "vphn: 1 x 16-bit value",
0042         {
0043             0x8001ffffffffffff,
0044             0xffffffffffffffff,
0045             0xffffffffffffffff,
0046             0xffffffffffffffff,
0047             0xffffffffffffffff,
0048             0xffffffffffffffff,
0049         },
0050         {
0051             0x00000001,
0052             0x00000001
0053         }
0054     },
0055     {
0056         "vphn: 2 x 16-bit values",
0057         {
0058             0x80018002ffffffff,
0059             0xffffffffffffffff,
0060             0xffffffffffffffff,
0061             0xffffffffffffffff,
0062             0xffffffffffffffff,
0063             0xffffffffffffffff,
0064         },
0065         {
0066             0x00000002,
0067             0x00000001,
0068             0x00000002
0069         }
0070     },
0071     {
0072         "vphn: 3 x 16-bit values",
0073         {
0074             0x800180028003ffff,
0075             0xffffffffffffffff,
0076             0xffffffffffffffff,
0077             0xffffffffffffffff,
0078             0xffffffffffffffff,
0079             0xffffffffffffffff,
0080         },
0081         {
0082             0x00000003,
0083             0x00000001,
0084             0x00000002,
0085             0x00000003
0086         }
0087     },
0088     {
0089         "vphn: 4 x 16-bit values",
0090         {
0091             0x8001800280038004,
0092             0xffffffffffffffff,
0093             0xffffffffffffffff,
0094             0xffffffffffffffff,
0095             0xffffffffffffffff,
0096             0xffffffffffffffff,
0097         },
0098         {
0099             0x00000004,
0100             0x00000001,
0101             0x00000002,
0102             0x00000003,
0103             0x00000004
0104         }
0105     },
0106     {
0107         /* Parsing the next 16-bit value out of the next 64-bit input
0108          * value.
0109          */
0110         "vphn: 5 x 16-bit values",
0111         {
0112             0x8001800280038004,
0113             0x8005ffffffffffff,
0114             0xffffffffffffffff,
0115             0xffffffffffffffff,
0116             0xffffffffffffffff,
0117             0xffffffffffffffff,
0118         },
0119         {
0120             0x00000005,
0121             0x00000001,
0122             0x00000002,
0123             0x00000003,
0124             0x00000004,
0125             0x00000005
0126         }
0127     },
0128     {
0129         /* Parse at most 6 x 64-bit input values */
0130         "vphn: 24 x 16-bit values",
0131         {
0132             0x8001800280038004,
0133             0x8005800680078008,
0134             0x8009800a800b800c,
0135             0x800d800e800f8010,
0136             0x8011801280138014,
0137             0x8015801680178018
0138         },
0139         {
0140             0x00000018,
0141             0x00000001,
0142             0x00000002,
0143             0x00000003,
0144             0x00000004,
0145             0x00000005,
0146             0x00000006,
0147             0x00000007,
0148             0x00000008,
0149             0x00000009,
0150             0x0000000a,
0151             0x0000000b,
0152             0x0000000c,
0153             0x0000000d,
0154             0x0000000e,
0155             0x0000000f,
0156             0x00000010,
0157             0x00000011,
0158             0x00000012,
0159             0x00000013,
0160             0x00000014,
0161             0x00000015,
0162             0x00000016,
0163             0x00000017,
0164             0x00000018
0165         }
0166     },
0167     {
0168         "vphn: 1 x 32-bit value",
0169         {
0170             0x00000001ffffffff,
0171             0xffffffffffffffff,
0172             0xffffffffffffffff,
0173             0xffffffffffffffff,
0174             0xffffffffffffffff,
0175             0xffffffffffffffff
0176         },
0177         {
0178             0x00000001,
0179             0x00000001
0180         }
0181     },
0182     {
0183         "vphn: 2 x 32-bit values",
0184         {
0185             0x0000000100000002,
0186             0xffffffffffffffff,
0187             0xffffffffffffffff,
0188             0xffffffffffffffff,
0189             0xffffffffffffffff,
0190             0xffffffffffffffff
0191         },
0192         {
0193             0x00000002,
0194             0x00000001,
0195             0x00000002
0196         }
0197     },
0198     {
0199         /* Parsing the next 32-bit value out of the next 64-bit input
0200          * value.
0201          */
0202         "vphn: 3 x 32-bit values",
0203         {
0204             0x0000000100000002,
0205             0x00000003ffffffff,
0206             0xffffffffffffffff,
0207             0xffffffffffffffff,
0208             0xffffffffffffffff,
0209             0xffffffffffffffff
0210         },
0211         {
0212             0x00000003,
0213             0x00000001,
0214             0x00000002,
0215             0x00000003
0216         }
0217     },
0218     {
0219         /* Parse at most 6 x 64-bit input values */
0220         "vphn: 12 x 32-bit values",
0221         {
0222             0x0000000100000002,
0223             0x0000000300000004,
0224             0x0000000500000006,
0225             0x0000000700000008,
0226             0x000000090000000a,
0227             0x0000000b0000000c
0228         },
0229         {
0230             0x0000000c,
0231             0x00000001,
0232             0x00000002,
0233             0x00000003,
0234             0x00000004,
0235             0x00000005,
0236             0x00000006,
0237             0x00000007,
0238             0x00000008,
0239             0x00000009,
0240             0x0000000a,
0241             0x0000000b,
0242             0x0000000c
0243         }
0244     },
0245     {
0246         "vphn: 16-bit value followed by 32-bit value",
0247         {
0248             0x800100000002ffff,
0249             0xffffffffffffffff,
0250             0xffffffffffffffff,
0251             0xffffffffffffffff,
0252             0xffffffffffffffff,
0253             0xffffffffffffffff
0254         },
0255         {
0256             0x00000002,
0257             0x00000001,
0258             0x00000002
0259         }
0260     },
0261     {
0262         "vphn: 32-bit value followed by 16-bit value",
0263         {
0264             0x000000018002ffff,
0265             0xffffffffffffffff,
0266             0xffffffffffffffff,
0267             0xffffffffffffffff,
0268             0xffffffffffffffff,
0269             0xffffffffffffffff
0270         },
0271         {
0272             0x00000002,
0273             0x00000001,
0274             0x00000002
0275         }
0276     },
0277     {
0278         /* Parse a 32-bit value split accross two consecutives 64-bit
0279          * input values.
0280          */
0281         "vphn: 16-bit value followed by 2 x 32-bit values",
0282         {
0283             0x8001000000020000,
0284             0x0003ffffffffffff,
0285             0xffffffffffffffff,
0286             0xffffffffffffffff,
0287             0xffffffffffffffff,
0288             0xffffffffffffffff
0289         },
0290         {
0291             0x00000003,
0292             0x00000001,
0293             0x00000002,
0294             0x00000003,
0295             0x00000004,
0296             0x00000005
0297         }
0298     },
0299     {
0300         /* The lower bits in 0x0001ffff don't get mixed up with the
0301          * 0xffff terminator.
0302          */
0303         "vphn: 32-bit value has all ones in 16 lower bits",
0304         {
0305             0x0001ffff80028003,
0306             0xffffffffffffffff,
0307             0xffffffffffffffff,
0308             0xffffffffffffffff,
0309             0xffffffffffffffff,
0310             0xffffffffffffffff
0311         },
0312         {
0313             0x00000003,
0314             0x0001ffff,
0315             0x00000002,
0316             0x00000003
0317         }
0318     },
0319     {
0320         /* The following input doesn't follow the specification.
0321          */
0322         "vphn: last 32-bit value is truncated",
0323         {
0324             0x0000000100000002,
0325             0x0000000300000004,
0326             0x0000000500000006,
0327             0x0000000700000008,
0328             0x000000090000000a,
0329             0x0000000b800c2bad
0330         },
0331         {
0332             0x0000000c,
0333             0x00000001,
0334             0x00000002,
0335             0x00000003,
0336             0x00000004,
0337             0x00000005,
0338             0x00000006,
0339             0x00000007,
0340             0x00000008,
0341             0x00000009,
0342             0x0000000a,
0343             0x0000000b,
0344             0x0000000c
0345         }
0346     },
0347     {
0348         "vphn: garbage after terminator",
0349         {
0350             0xffff2bad2bad2bad,
0351             0x2bad2bad2bad2bad,
0352             0x2bad2bad2bad2bad,
0353             0x2bad2bad2bad2bad,
0354             0x2bad2bad2bad2bad,
0355             0x2bad2bad2bad2bad
0356         },
0357         {
0358             0x00000000
0359         }
0360     },
0361     {
0362         NULL
0363     }
0364 };
0365 
0366 static int test_one(struct test *test)
0367 {
0368     __be32 output[VPHN_ASSOC_BUFSIZE] = { 0 };
0369     int i, len;
0370 
0371     vphn_unpack_associativity(test->input, output);
0372 
0373     len = be32_to_cpu(output[0]);
0374     if (len != test->expected[0]) {
0375         printf("expected %d elements, got %d\n", test->expected[0],
0376                len);
0377         return 1;
0378     }
0379 
0380     for (i = 1; i < len; i++) {
0381         u32 val = be32_to_cpu(output[i]);
0382         if (val != test->expected[i]) {
0383             printf("element #%d is 0x%x, should be 0x%x\n", i, val,
0384                    test->expected[i]);
0385             return 1;
0386         }
0387     }
0388 
0389     return 0;
0390 }
0391 
0392 static int test_vphn(void)
0393 {
0394     static struct test *test;
0395 
0396     for (test = all_tests; test->descr; test++) {
0397         int ret;
0398 
0399         ret = test_one(test);
0400         test_finish(test->descr, ret);
0401         if (ret)
0402             return ret;
0403     }
0404 
0405     return 0;
0406 }
0407 
0408 int main(int argc, char **argv)
0409 {
0410     return test_harness(test_vphn, "test-vphn");
0411 }