|
@@ -0,0 +1,91 @@
|
|
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
17
|
+ */
|
|
18
|
+
|
|
19
|
+FILE_LICENCE ( GPL2_OR_LATER );
|
|
20
|
+
|
|
21
|
+/** @file
|
|
22
|
+ *
|
|
23
|
+ * Byte-order swapping test functions
|
|
24
|
+ *
|
|
25
|
+ */
|
|
26
|
+
|
|
27
|
+/* Forcibly enable assertions */
|
|
28
|
+#undef NDEBUG
|
|
29
|
+
|
|
30
|
+#include <stdint.h>
|
|
31
|
+#include <assert.h>
|
|
32
|
+#include <byteswap.h>
|
|
33
|
+#include <ipxe/test.h>
|
|
34
|
+
|
|
35
|
+/* Provide global functions to allow inspection of generated assembly code */
|
|
36
|
+
|
|
37
|
+uint16_t test_bswap16 ( uint16_t x ) {
|
|
38
|
+ return __bswap_16 ( x );
|
|
39
|
+}
|
|
40
|
+
|
|
41
|
+uint32_t test_bswap32 ( uint32_t x ) {
|
|
42
|
+ return __bswap_32 ( x );
|
|
43
|
+}
|
|
44
|
+
|
|
45
|
+uint64_t test_bswap64 ( uint64_t x ) {
|
|
46
|
+ return __bswap_64 ( x );
|
|
47
|
+}
|
|
48
|
+
|
|
49
|
+void test_bswap16s ( uint16_t *x ) {
|
|
50
|
+ __bswap_16s ( x );
|
|
51
|
+}
|
|
52
|
+
|
|
53
|
+void test_bswap32s ( uint32_t *x ) {
|
|
54
|
+ __bswap_32s ( x );
|
|
55
|
+}
|
|
56
|
+
|
|
57
|
+void test_bswap64s ( uint64_t *x ) {
|
|
58
|
+ __bswap_64s ( x );
|
|
59
|
+}
|
|
60
|
+
|
|
61
|
+/**
|
|
62
|
+ * Perform byte-order swapping
|
|
63
|
+ *
|
|
64
|
+ */
|
|
65
|
+static void byteswap_test_exec ( void ) {
|
|
66
|
+ uint16_t test16;
|
|
67
|
+ uint32_t test32;
|
|
68
|
+ uint64_t test64;
|
|
69
|
+
|
|
70
|
+ ok ( test_bswap16 ( 0x1234 ) == 0x3412 );
|
|
71
|
+ ok ( test_bswap32 ( 0x12345678UL ) == 0x78563412UL );
|
|
72
|
+ ok ( test_bswap64 ( 0x123456789abcdef0ULL ) == 0xf0debc9a78563412ULL );
|
|
73
|
+
|
|
74
|
+ test16 = 0xabcd;
|
|
75
|
+ test_bswap16s ( &test16 );
|
|
76
|
+ ok ( test16 == 0xcdab );
|
|
77
|
+
|
|
78
|
+ test32 = 0xabcdef01UL;
|
|
79
|
+ test_bswap32s ( &test32 );
|
|
80
|
+ ok ( test32 == 0x01efcdabUL );
|
|
81
|
+
|
|
82
|
+ test64 = 0xabcdef0123456789ULL;
|
|
83
|
+ test_bswap64s ( &test64 );
|
|
84
|
+ ok ( test64 == 0x8967452301efcdabULL );
|
|
85
|
+}
|
|
86
|
+
|
|
87
|
+/** Byte-order swapping self-test */
|
|
88
|
+struct self_test byteswap_test __self_test = {
|
|
89
|
+ .name = "byteswap",
|
|
90
|
+ .exec = byteswap_test_exec,
|
|
91
|
+};
|