Commit 30896e71 authored by Thanassis Tsiodras's avatar Thanassis Tsiodras

Significantly improving the output of the memory checking parts

parent 9b9479c9
......@@ -18,28 +18,29 @@ void memcheck()
0x55AA55AA,
};
#ifdef CHECK_WRAPAROUNDS_WITH_PRIME_SIZED_WINDOWS
// Prime numbers used to check for potential address space overlaps
// (read comments in the code below that uses this)
unsigned primes[] = { 3, 7, 31, 127 };
unsigned cnt = 0;
#endif
// Counters used in loops below.
int i = 0;
unsigned cnt = 0;
// Detect available memory by repeated allocations.
// Start at 512K.
size_t space = 512*1024;
void *p = malloc(space);
printf("[MEMCHECK] Detecting memory available");
printf("[MEMCHECK] Detecting available memory... ");
fflush(stdout);
while(p) {
free(p);
printf(".");
fflush(stdout);
space += 1024*1024; // test memory increases in 1MB increments
p = malloc(space);
}
space -= 1024*1024;
printf("\n[MEMCHECK] Memory available: %dK\n", space/1024);
printf("%dK\n", space/1024);
// Now that we know the amount of memory available, reserve it all.
p = malloc(space);
......@@ -49,6 +50,7 @@ void memcheck()
exit(1);
}
#ifdef CHECK_WRAPAROUNDS_WITH_PRIME_SIZED_WINDOWS
// How can we make sure that RTEMS doesn't mis-identify our available
// memory and doesn't return 'windowed' areas? (i.e. we think we have
// e.g. 128KB, but in fact, the last 64KB 'mirror' back to the first
......@@ -107,54 +109,81 @@ void memcheck()
}
}
puts("");
#endif
// Write all over the memory using alternating bit values; this verifies
// proper memory operations, by stressing (electrically) the circuits.
for(i=0; i<sizeof(patterns)/sizeof(patterns[0]); i++) {
printf("[MEMCHECK] Checking memory with pattern: 0x%08x...\n",
(unsigned) patterns[i]);
unsigned pattern = patterns[i];
uint32_t *pw = p;
unsigned words = space/4;
printf("[MEMCHECK] Writing memory pattern 0x%08x ", pattern);
fflush(stdout);
// Writing the pattern
while(words--) {
*pw++ = patterns[i];
*pw++ = pattern;
if ((words & 0xFFFFFF) == 0xFFFFFF) {
printf("\b\b\b\b\b\b%5.2f%%", 100.0*((space/4.0)-words)/(space/4.0));
fflush(stdout);
}
}
printf("\b\b\b\b\b\b\b%5.2f%%\n", 100.0);
pw = p;
words = space/4;
// Verifying the pattern
printf("[MEMCHECK] Reading memory, checking for 0x%08x ", pattern);
fflush(stdout);
while(words--) {
if (*pw != patterns[i]) {
if (*pw != pattern) {
printf(
"[MEMCHECK] Failed with pattern 0x%x at offset 0x%x\n",
(unsigned)patterns[i], (unsigned)pw);
"\n[MEMCHECK] Failed with pattern 0x%x at offset 0x%x\n",
pattern, (unsigned)pw);
fflush(stdout);
exit(1);
}
if ((words & 0xFFFFFF) == 0xFFFFFF) {
printf("\b\b\b\b\b\b%5.2f%%", 100.0*((space/4.0)-words)/(space/4.0));
fflush(stdout);
}
pw++;
}
printf("\b\b\b\b\b\b\b%5.2f%%\n", 100.0);
}
// A simple final run storing big numbers consecutively.
printf("[MEMCHECK] Checking memory by writing 32-bit numbers from 0 up to %d...\n", space/4);
printf("[MEMCHECK] Writing 32-bit numbers from 0 up to %d ", space/4);
{
uint32_t *pw = p;
unsigned words = space/4;
while(words--) {
*pw++ = words;
if ((words & 0xFFFFFF) == 0xFFFFFF) {
printf("\b\b\b\b\b\b%5.2f%%", 100.0*((space/4.0)-words)/(space/4.0));
fflush(stdout);
}
}
printf("\b\b\b\b\b\b\b%5.2f%%\n", 100.0);
printf("[MEMCHECK] Reading 32-bit numbers from 0 up to %d ", space/4);
pw = p;
words = space/4;
// Verifying the big numbers
while(words--) {
if (*pw != words) {
printf(
"[MEMCHECK] Failed with big value 0x%x at offset 0x%x\n",
"\n[MEMCHECK] Failed with big value 0x%x at offset 0x%x\n",
words, (unsigned)pw);
fflush(stdout);
exit(1);
}
pw++;
if ((words & 0xFFFFFF) == 0xFFFFFF) {
printf("\b\b\b\b\b\b%5.2f%%", 100.0*((space/4.0)-words)/(space/4.0));
fflush(stdout);
}
}
printf("\b\b\b\b\b\b\b%5.2f%%\n", 100.0);
}
free(p);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment