Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / tests / byteswap_test.c
1 /*
2  * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  */
19
20 FILE_LICENCE ( GPL2_OR_LATER );
21
22 /** @file
23  *
24  * Byte-order swapping test functions
25  *
26  */
27
28 /* Forcibly enable assertions */
29 #undef NDEBUG
30
31 #include <stdint.h>
32 #include <assert.h>
33 #include <byteswap.h>
34 #include <ipxe/test.h>
35
36 /* Provide global functions to allow inspection of generated assembly code */
37
38 uint16_t test_bswap16 ( uint16_t x ) {
39         return __bswap_16 ( x );
40 }
41
42 uint32_t test_bswap32 ( uint32_t x ) {
43         return __bswap_32 ( x );
44 }
45
46 uint64_t test_bswap64 ( uint64_t x ) {
47         return __bswap_64 ( x );
48 }
49
50 void test_bswap16s ( uint16_t *x ) {
51         __bswap_16s ( x );
52 }
53
54 void test_bswap32s ( uint32_t *x ) {
55         __bswap_32s ( x );
56 }
57
58 void test_bswap64s ( uint64_t *x ) {
59         __bswap_64s ( x );
60 }
61
62 /**
63  * Perform byte-order swapping
64  *
65  */
66 static void byteswap_test_exec ( void ) {
67         uint16_t test16;
68         uint32_t test32;
69         uint64_t test64;
70
71         ok ( test_bswap16 ( 0x1234 ) == 0x3412 );
72         ok ( test_bswap32 ( 0x12345678UL ) == 0x78563412UL );
73         ok ( test_bswap64 ( 0x123456789abcdef0ULL ) == 0xf0debc9a78563412ULL );
74
75         test16 = 0xabcd;
76         test_bswap16s ( &test16 );
77         ok ( test16 == 0xcdab );
78
79         test32 = 0xabcdef01UL;
80         test_bswap32s ( &test32 );
81         ok ( test32 == 0x01efcdabUL );
82
83         test64 = 0xabcdef0123456789ULL;
84         test_bswap64s ( &test64 );
85         ok ( test64 == 0x8967452301efcdabULL );
86 }
87
88 /** Byte-order swapping self-test */
89 struct self_test byteswap_test __self_test = {
90         .name = "byteswap",
91         .exec = byteswap_test_exec,
92 };