static uint32_t mem_test_alt(vu_long *buf, uint32_t start_addr, uint32_t end_addr,
vu_long *dummy)
{
vu_long *addr;
ulong errs = 0;
ulong val, readback;
unsigned int j;
vu_long offset;
vu_long test_offset;
vu_long pattern;
vu_long temp;
vu_long anti_pattern;
vu_long num_words;
static const ulong bitpattern[] = {
0x00000001, /* single bit */
0x00000003, /* two adjacent bits */
0x00000007, /* three adjacent bits */
0x0000000F, /* four adjacent bits */
0x00000005, /* two non-adjacent bits */
0x00000015, /* three non-adjacent bits */
0x00000055, /* four non-adjacent bits */
0xaaaaaaaa, /* alternating 1/0 */
};
num_words = (end_addr - start_addr) / sizeof(uint32_t);
LOG_I("%s:%d: buf=0x%.8lx, length = 0x%.8lx\n", __func__, __LINE__, buf, num_words);
/*
* Data line test: write a pattern to the first
* location, write the 1's complement to a 'parking'
* address (changes the state of the data bus so a
* floating bus doesn't give a false OK), and then
* read the value back. Note that we read it back
* into a variable because the next time we read it,
* it might be right (been there, tough to explain to
* the quality guys why it prints a failure when the
* "is" and "should be" are obviously the same in the
* error message).
*
* Rather than exhaustively testing, we test some
* patterns by shifting '1' bits through a field of
* '0's and '0' bits through a field of '1's (i.e.
* pattern and ~pattern).
*/
addr = buf;
for (j = 0; j < sizeof(bitpattern) / sizeof(bitpattern[0]); j++) {
val = bitpattern[j];
LOG_I("pattern = 0x%.8lx\n", val);
for (; val != 0; val <<= 1) {
*addr = val;
*dummy = ~val; /* clear the test data off the bus */
readback = *addr;
if (readback != val) {
LOG_I("FAILURE (data line): "
"expected %08lx, actual %08lx\n",
val, readback);
errs++;
}
*addr = ~val;
*dummy = val;
readback = *addr;
if (readback != ~val) {
LOG_I("FAILURE (data line): "
"Is %08lx, should be %08lx\n",
readback, ~val);
errs++;
}
}
}
/*
* Based on code whose Original Author and Copyright
* information follows: Copyright (c) 1998 by Michael
* Barr. This software is placed into the public
* domain and may be used for any purpose. However,
* this notice must not be changed or removed and no
* warranty is either expressed or implied by its
* publication or distribution.
*/
/*
* Address line test
*
* Description: Test the address bus wiring in a
* memory region by performing a walking
* 1's test on the relevant bits of the
* address and checking for aliasing.
* This test will find single-bit
* address failures such as stuck-high,
* stuck-low, and shorted pins. The base
* address and size of the region are
* selected by the caller.
*
* Notes: For best results, the selected base
* address should have enough LSB 0's to
* guarantee single address bit changes.
* For example, to test a 64-Kbyte
* region, select a base address on a
* 64-Kbyte boundary. Also, select the
* region size as a power-of-two if at
* all possible.
*
* Returns: 0 if the test succeeds, 1 if the test fails.
*/
pattern = (vu_long) 0xaaaaaaaa;
anti_pattern = (vu_long) 0x55555555;
LOG_I("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words);
/*
* Write the default pattern at each of the
* power-of-two offsets.
*/
for (offset = 1; offset < num_words; offset <<= 1)
addr[offset] = pattern;
/*
* Check for address bits stuck high.
*/
test_offset = 0;
addr[test_offset] = anti_pattern;
for (offset = 1; offset < num_words; offset <<= 1) {
temp = addr[offset];
if (temp != pattern) {
LOG_I("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
" expected 0x%.8lx, actual 0x%.8lx\n",
start_addr + offset*sizeof(uint32_t),
pattern, temp);
errs++;
}
}
addr[test_offset] = pattern;
/* if watchdog enable, need feed wdt */
/*
* Check for addr bits stuck low or shorted.
*/
for (test_offset = 1; test_offset < num_words; test_offset <<= 1) {
addr[test_offset] = anti_pattern;
for (offset = 1; offset < num_words; offset <<= 1) {
temp = addr[offset];
if ((temp != pattern) && (offset != test_offset)) {
LOG_I("\nFAILURE: Address bit stuck low or"
" shorted @ 0x%.8lx: expected 0x%.8lx,"
" actual 0x%.8lx\n",
start_addr + offset*sizeof(uint32_t),
pattern, temp);
errs++;
}
}
addr[test_offset] = pattern;
}
/*
* Description: Test the integrity of a physical
* memory device by performing an
* increment/decrement test over the
* entire region. In the process every
* storage bit in the device is tested
* as a zero and a one. The base address
* and the size of the region are
* selected by the caller.
*
* Returns: 0 if the test succeeds, 1 if the test fails.
*/
/*
* Fill memory with a known pattern.
*/
for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
/* if watchdog enable, need feed wdt */
addr[offset] = pattern;
}
/*
* Check each location and invert it for the second pass.
*/
for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
/* if watchdog enable, need feed wdt */
temp = addr[offset];
if (temp != pattern) {
LOG_I("\nFAILURE (read/write) @ 0x%.8lx:"
" expected 0x%.8lx, actual 0x%.8lx)\n",
start_addr + offset*sizeof(uint32_t),
pattern, temp);
errs++;
}
anti_pattern = ~pattern;
addr[offset] = anti_pattern;
}
/*
* Check each location for the inverted pattern and zero it.
*/
for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
/* if watchdog enable, need feed wdt */
anti_pattern = ~pattern;
temp = addr[offset];
if (temp != anti_pattern) {
LOG_I("\nFAILURE (read/write): @ 0x%.8lx:"
" expected 0x%.8lx, actual 0x%.8lx)\n",
start_addr + offset*sizeof(uint32_t),
anti_pattern, temp);
errs++;
}
addr[offset] = 0;
}
return errs;
}
TEST_F(phy_mem, 001_mem_bitflip_test)
{
uint32_t scratch_space;
ulong start, end;
uint32_t *dummy = &scratch_space;
uint32_t count = 0;
int32_t errs = 0;
PARSE_PARAS();
EXPECT_EQ(argc, 2);
start = 0x100000;
end = 0x160000;
LOG_I("Testing bitflip %08lx ... %08lx:\n", start, end);
errs = mem_test_alt((vu_long *)start, start, end, dummy);
count += errs;
EXPECT_EQ(errs, 0x0);
errs = mem_test_bitflip((vu_long *)start, start, end);
count += errs;
LOG_I("Tested with %d errors.\n", count);
EXPECT_EQ(errs, 0x0);
} 分析这段代码的作用,以及为何在运行到第一个“*addr=val;”语句时会出现死机