]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/dpdk/app/test/test_byteorder.c
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / dpdk / app / test / test_byteorder.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
3 */
4
5 #include <stdio.h>
6 #include <stdint.h>
7 #include <unistd.h>
8 #include <inttypes.h>
9
10 #include <rte_byteorder.h>
11
12 #include "test.h"
13
14 static volatile uint16_t u16 = 0x1337;
15 static volatile uint32_t u32 = 0xdeadbeefUL;
16 static volatile uint64_t u64 = 0xdeadcafebabefaceULL;
17
18 /*
19 * Byteorder functions
20 * ===================
21 *
22 * - check that optimized byte swap functions are working for each
23 * size (16, 32, 64 bits)
24 */
25
26 static int
27 test_byteorder(void)
28 {
29 uint16_t res_u16;
30 uint32_t res_u32;
31 uint64_t res_u64;
32
33 res_u16 = rte_bswap16(u16);
34 printf("%"PRIx16" -> %"PRIx16"\n", u16, res_u16);
35 if (res_u16 != 0x3713)
36 return -1;
37
38 res_u32 = rte_bswap32(u32);
39 printf("%"PRIx32" -> %"PRIx32"\n", u32, res_u32);
40 if (res_u32 != 0xefbeaddeUL)
41 return -1;
42
43 res_u64 = rte_bswap64(u64);
44 printf("%"PRIx64" -> %"PRIx64"\n", u64, res_u64);
45 if (res_u64 != 0xcefabebafecaaddeULL)
46 return -1;
47
48 res_u16 = rte_bswap16(0x1337);
49 printf("const %"PRIx16" -> %"PRIx16"\n", 0x1337, res_u16);
50 if (res_u16 != 0x3713)
51 return -1;
52
53 res_u32 = rte_bswap32(0xdeadbeefUL);
54 printf("const %"PRIx32" -> %"PRIx32"\n", (uint32_t) 0xdeadbeef, res_u32);
55 if (res_u32 != 0xefbeaddeUL)
56 return -1;
57
58 res_u64 = rte_bswap64(0xdeadcafebabefaceULL);
59 printf("const %"PRIx64" -> %"PRIx64"\n", (uint64_t) 0xdeadcafebabefaceULL, res_u64);
60 if (res_u64 != 0xcefabebafecaaddeULL)
61 return -1;
62
63 return 0;
64 }
65
66 REGISTER_TEST_COMMAND(byteorder_autotest, test_byteorder);