1 // SPDX-License-Identifier: GPL-2.0
7 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
8 #define cpu_to_be32(x) bswap_32(x)
9 #define be32_to_cpu(x) bswap_32(x)
10 #define be16_to_cpup(x) bswap_16(*x)
11 #define cpu_to_be64(x) bswap_64(x)
13 #define cpu_to_be32(x) (x)
14 #define be32_to_cpu(x) (x)
15 #define be16_to_cpup(x) (*x)
16 #define cpu_to_be64(x) (x)
23 long input[VPHN_REGISTER_COUNT];
24 u32 expected[VPHN_ASSOC_BUFSIZE];
41 "vphn: 1 x 16-bit value",
56 "vphn: 2 x 16-bit values",
72 "vphn: 3 x 16-bit values",
89 "vphn: 4 x 16-bit values",
107 /* Parsing the next 16-bit value out of the next 64-bit input
110 "vphn: 5 x 16-bit values",
129 /* Parse at most 6 x 64-bit input values */
130 "vphn: 24 x 16-bit values",
168 "vphn: 1 x 32-bit value",
183 "vphn: 2 x 32-bit values",
199 /* Parsing the next 32-bit value out of the next 64-bit input
202 "vphn: 3 x 32-bit values",
219 /* Parse at most 6 x 64-bit input values */
220 "vphn: 12 x 32-bit values",
246 "vphn: 16-bit value followed by 32-bit value",
262 "vphn: 32-bit value followed by 16-bit value",
278 /* Parse a 32-bit value split accross two consecutives 64-bit
281 "vphn: 16-bit value followed by 2 x 32-bit values",
300 /* The lower bits in 0x0001ffff don't get mixed up with the
303 "vphn: 32-bit value has all ones in 16 lower bits",
320 /* The following input doesn't follow the specification.
322 "vphn: last 32-bit value is truncated",
348 "vphn: garbage after terminator",
366 static int test_one(struct test *test)
368 __be32 output[VPHN_ASSOC_BUFSIZE] = { 0 };
371 vphn_unpack_associativity(test->input, output);
373 len = be32_to_cpu(output[0]);
374 if (len != test->expected[0]) {
375 printf("expected %d elements, got %d\n", test->expected[0],
380 for (i = 1; i < len; i++) {
381 u32 val = be32_to_cpu(output[i]);
382 if (val != test->expected[i]) {
383 printf("element #%d is 0x%x, should be 0x%x\n", i, val,
392 static int test_vphn(void)
394 static struct test *test;
396 for (test = all_tests; test->descr; test++) {
399 ret = test_one(test);
400 test_finish(test->descr, ret);
408 int main(int argc, char **argv)
410 return test_harness(test_vphn, "test-vphn");