4 * This is intended to test the softmmu code and ensure we properly
5 * behave across normal and unaligned accesses across several pages.
6 * We are not replicating memory tests for stuck bits and other
7 * hardware level failures but looking for issues with different size
16 #define TEST_SIZE (4096 * 4) /* 4 pages */
18 static uint8_t test_data
[TEST_SIZE
];
20 static void pdot(int count
)
22 if (count
% 128 == 0) {
29 * Fill the data with ascending value bytes. As x86 is a LE machine we
30 * write in ascending order and then read and high byte should either
31 * be zero or higher than the lower bytes.
34 static void init_test_data_u8(void)
36 uint8_t count
= 0, *ptr
= &test_data
[0];
39 ml_printf("Filling test area with u8:");
40 for (i
= 0; i
< TEST_SIZE
; i
++) {
47 static void init_test_data_u16(int offset
)
50 uint16_t word
, *ptr
= (uint16_t *) &test_data
[0];
51 const int max
= (TEST_SIZE
- offset
) / sizeof(word
);
54 ml_printf("Filling test area with u16 (offset %d):", offset
);
57 for (i
= 0; i
< offset
; i
++) {
61 ptr
= (uint16_t *) &test_data
[offset
];
62 for (i
= 0; i
< max
; i
++) {
66 word
= (high
<< 8) | low
;
73 static void init_test_data_u32(int offset
)
76 uint32_t word
, *ptr
= (uint32_t *) &test_data
[0];
77 const int max
= (TEST_SIZE
- offset
) / sizeof(word
);
80 ml_printf("Filling test area with u32 (offset %d):", offset
);
83 for (i
= 0; i
< offset
; i
++) {
87 ptr
= (uint32_t *) &test_data
[offset
];
88 for (i
= 0; i
< max
; i
++) {
89 uint8_t b1
, b2
, b3
, b4
;
94 word
= (b1
<< 24) | (b2
<< 16) | (b3
<< 8) | b4
;
102 static int read_test_data_u16(int offset
)
104 uint16_t word
, *ptr
= (uint16_t *)&test_data
[offset
];
106 const int max
= (TEST_SIZE
- offset
) / sizeof(word
);
108 ml_printf("Reading u16 from %#lx (offset %d):", ptr
, offset
);
110 for (i
= 0; i
< max
; i
++) {
113 high
= (word
>> 8) & 0xff;
115 if (high
< low
&& high
!= 0) {
116 ml_printf("Error %d < %d\n", high
, low
);
127 static int read_test_data_u32(int offset
)
129 uint32_t word
, *ptr
= (uint32_t *)&test_data
[offset
];
131 const int max
= (TEST_SIZE
- offset
) / sizeof(word
);
133 ml_printf("Reading u32 from %#lx (offset %d):", ptr
, offset
);
135 for (i
= 0; i
< max
; i
++) {
136 uint8_t b1
, b2
, b3
, b4
;
139 b1
= word
>> 24 & 0xff;
140 b2
= word
>> 16 & 0xff;
141 b3
= word
>> 8 & 0xff;
144 if ((b1
< b2
&& b1
!= 0) ||
145 (b2
< b3
&& b2
!= 0) ||
146 (b3
< b4
&& b3
!= 0)) {
147 ml_printf("Error %d, %d, %d, %d", b1
, b2
, b3
, b4
);
157 static int read_test_data_u64(int offset
)
159 uint64_t word
, *ptr
= (uint64_t *)&test_data
[offset
];
161 const int max
= (TEST_SIZE
- offset
) / sizeof(word
);
163 ml_printf("Reading u64 from %#lx (offset %d):", ptr
, offset
);
165 for (i
= 0; i
< max
; i
++) {
166 uint8_t b1
, b2
, b3
, b4
, b5
, b6
, b7
, b8
;
169 b1
= ((uint64_t) (word
>> 56)) & 0xff;
170 b2
= ((uint64_t) (word
>> 48)) & 0xff;
171 b3
= ((uint64_t) (word
>> 40)) & 0xff;
172 b4
= (word
>> 32) & 0xff;
173 b5
= (word
>> 24) & 0xff;
174 b6
= (word
>> 16) & 0xff;
175 b7
= (word
>> 8) & 0xff;
176 b8
= (word
>> 0) & 0xff;
178 if ((b1
< b2
&& b1
!= 0) ||
179 (b2
< b3
&& b2
!= 0) ||
180 (b3
< b4
&& b3
!= 0) ||
181 (b4
< b5
&& b4
!= 0) ||
182 (b5
< b6
&& b5
!= 0) ||
183 (b6
< b7
&& b6
!= 0) ||
184 (b7
< b8
&& b7
!= 0)) {
185 ml_printf("Error %d, %d, %d, %d, %d, %d, %d, %d",
186 b1
, b2
, b3
, b4
, b5
, b6
, b7
, b8
);
196 /* Read the test data and verify at various offsets */
202 while (r
== 0 && off
< 8) {
203 r
= read_test_data_u16(off
);
204 r
|= read_test_data_u32(off
);
205 r
|= read_test_data_u64(off
);
223 for (i
= 0; i
< 8; i
++) {
224 init_test_data_u16(i
);
232 for (i
= 0; i
< 8; i
++) {
233 init_test_data_u32(i
);
241 ml_printf("Test complete: %s\n", r
== 0 ? "PASSED" : "FAILED");