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