[infiniband] Use "%d" as format specifier for LIDs
[ipxe.git] / src / tests / memset_test.c
1 /*
2 * Copyright (C) 2015 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 (at your option) 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 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26 /** @file
27 *
28 * memset() self-tests
29 *
30 */
31
32 /* Forcibly enable assertions */
33 #undef NDEBUG
34
35 #include <string.h>
36 #include <ipxe/test.h>
37
38 /* Provide global functions to allow inspection of generated code */
39
40 void memset_zero_0 ( void *dest ) { memset ( dest, 0, 0 ); }
41 void memset_zero_1 ( void *dest ) { memset ( dest, 0, 1 ); }
42 void memset_zero_2 ( void *dest ) { memset ( dest, 0, 2 ); }
43 void memset_zero_3 ( void *dest ) { memset ( dest, 0, 3 ); }
44 void memset_zero_4 ( void *dest ) { memset ( dest, 0, 4 ); }
45 void memset_zero_5 ( void *dest ) { memset ( dest, 0, 5 ); }
46 void memset_zero_6 ( void *dest ) { memset ( dest, 0, 6 ); }
47 void memset_zero_7 ( void *dest ) { memset ( dest, 0, 7 ); }
48 void memset_zero_8 ( void *dest ) { memset ( dest, 0, 8 ); }
49 void memset_zero_9 ( void *dest ) { memset ( dest, 0, 9 ); }
50 void memset_zero_10 ( void *dest ) { memset ( dest, 0, 10 ); }
51 void memset_zero_11 ( void *dest ) { memset ( dest, 0, 11 ); }
52 void memset_zero_12 ( void *dest ) { memset ( dest, 0, 12 ); }
53 void memset_zero_13 ( void *dest ) { memset ( dest, 0, 13 ); }
54 void memset_zero_14 ( void *dest ) { memset ( dest, 0, 14 ); }
55 void memset_zero_15 ( void *dest ) { memset ( dest, 0, 15 ); }
56 void memset_zero_16 ( void *dest ) { memset ( dest, 0, 16 ); }
57 void memset_zero_17 ( void *dest ) { memset ( dest, 0, 17 ); }
58 void memset_zero_18 ( void *dest ) { memset ( dest, 0, 18 ); }
59 void memset_zero_19 ( void *dest ) { memset ( dest, 0, 19 ); }
60 void memset_zero_20 ( void *dest ) { memset ( dest, 0, 20 ); }
61 void memset_zero_21 ( void *dest ) { memset ( dest, 0, 21 ); }
62 void memset_zero_22 ( void *dest ) { memset ( dest, 0, 22 ); }
63 void memset_zero_23 ( void *dest ) { memset ( dest, 0, 23 ); }
64 void memset_zero_24 ( void *dest ) { memset ( dest, 0, 24 ); }
65 void memset_zero_25 ( void *dest ) { memset ( dest, 0, 25 ); }
66 void memset_zero_26 ( void *dest ) { memset ( dest, 0, 26 ); }
67 void memset_zero_27 ( void *dest ) { memset ( dest, 0, 27 ); }
68 void memset_zero_28 ( void *dest ) { memset ( dest, 0, 28 ); }
69 void memset_zero_29 ( void *dest ) { memset ( dest, 0, 29 ); }
70 void memset_zero_30 ( void *dest ) { memset ( dest, 0, 30 ); }
71 void memset_zero_31 ( void *dest ) { memset ( dest, 0, 31 ); }
72
73 /**
74 * Force a call to the variable-length implementation of memset()
75 *
76 * @v dest Destination address
77 * @v fill Fill pattern
78 * @v len Length of data
79 * @ret dest Destination address
80 */
81 __attribute__ (( noinline )) void * memset_var ( void *dest, unsigned int fill,
82 size_t len ) {
83 return memset ( dest, fill, len );
84 }
85
86 /**
87 * Perform a constant-length memset() test
88 *
89 * @v len Length of data
90 */
91 #define MEMSET_TEST_CONSTANT( len ) do { \
92 uint8_t dest_const[ 1 + len + 1 ]; \
93 uint8_t dest_var[ 1 + len + 1 ]; \
94 static uint8_t zero[len]; \
95 unsigned int i; \
96 \
97 for ( i = 0 ; i < sizeof ( dest_const ) ; i++ ) \
98 dest_const[i] = 0xaa; \
99 memset ( ( dest_const + 1 ), 0, len ); \
100 ok ( dest_const[0] == 0xaa ); \
101 ok ( dest_const[ sizeof ( dest_const ) - 1 ] == 0xaa ); \
102 ok ( memcmp ( ( dest_const + 1 ), zero, len ) == 0 ); \
103 \
104 for ( i = 0 ; i < sizeof ( dest_var ) ; i++ ) \
105 dest_var[i] = 0xbb; \
106 memset_var ( ( dest_var + 1 ), 0, len ); \
107 ok ( dest_var[0] == 0xbb ); \
108 ok ( dest_var[ sizeof ( dest_var ) - 1 ] == 0xbb ); \
109 ok ( memcmp ( ( dest_var + 1 ), zero, len ) == 0 ); \
110 } while ( 0 )
111
112 /**
113 * Perform memset() self-tests
114 *
115 */
116 static void memset_test_exec ( void ) {
117
118 /* Constant-length tests */
119 MEMSET_TEST_CONSTANT ( 0 );
120 MEMSET_TEST_CONSTANT ( 1 );
121 MEMSET_TEST_CONSTANT ( 2 );
122 MEMSET_TEST_CONSTANT ( 3 );
123 MEMSET_TEST_CONSTANT ( 4 );
124 MEMSET_TEST_CONSTANT ( 5 );
125 MEMSET_TEST_CONSTANT ( 6 );
126 MEMSET_TEST_CONSTANT ( 7 );
127 MEMSET_TEST_CONSTANT ( 8 );
128 MEMSET_TEST_CONSTANT ( 9 );
129 MEMSET_TEST_CONSTANT ( 10 );
130 MEMSET_TEST_CONSTANT ( 11 );
131 MEMSET_TEST_CONSTANT ( 12 );
132 MEMSET_TEST_CONSTANT ( 13 );
133 MEMSET_TEST_CONSTANT ( 14 );
134 MEMSET_TEST_CONSTANT ( 15 );
135 MEMSET_TEST_CONSTANT ( 16 );
136 MEMSET_TEST_CONSTANT ( 17 );
137 MEMSET_TEST_CONSTANT ( 18 );
138 MEMSET_TEST_CONSTANT ( 19 );
139 MEMSET_TEST_CONSTANT ( 20 );
140 MEMSET_TEST_CONSTANT ( 21 );
141 MEMSET_TEST_CONSTANT ( 22 );
142 MEMSET_TEST_CONSTANT ( 23 );
143 MEMSET_TEST_CONSTANT ( 24 );
144 MEMSET_TEST_CONSTANT ( 25 );
145 MEMSET_TEST_CONSTANT ( 26 );
146 MEMSET_TEST_CONSTANT ( 27 );
147 MEMSET_TEST_CONSTANT ( 28 );
148 MEMSET_TEST_CONSTANT ( 29 );
149 MEMSET_TEST_CONSTANT ( 30 );
150 MEMSET_TEST_CONSTANT ( 31 );
151 }
152
153 /** memset() self-test */
154 struct self_test memset_test __self_test = {
155 .name = "memset",
156 .exec = memset_test_exec,
157 };