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() ...@@ -18,28 +18,29 @@ void memcheck()
0x55AA55AA, 0x55AA55AA,
}; };
#ifdef CHECK_WRAPAROUNDS_WITH_PRIME_SIZED_WINDOWS
// Prime numbers used to check for potential address space overlaps // Prime numbers used to check for potential address space overlaps
// (read comments in the code below that uses this) // (read comments in the code below that uses this)
unsigned primes[] = { 3, 7, 31, 127 }; unsigned primes[] = { 3, 7, 31, 127 };
unsigned cnt = 0;
#endif
// Counters used in loops below. // Counters used in loops below.
int i = 0; int i = 0;
unsigned cnt = 0;
// Detect available memory by repeated allocations. // Detect available memory by repeated allocations.
// Start at 512K. // Start at 512K.
size_t space = 512*1024; size_t space = 512*1024;
void *p = malloc(space); void *p = malloc(space);
printf("[MEMCHECK] Detecting memory available"); printf("[MEMCHECK] Detecting available memory... ");
fflush(stdout);
while(p) { while(p) {
free(p); free(p);
printf(".");
fflush(stdout);
space += 1024*1024; // test memory increases in 1MB increments space += 1024*1024; // test memory increases in 1MB increments
p = malloc(space); p = malloc(space);
} }
space -= 1024*1024; 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. // Now that we know the amount of memory available, reserve it all.
p = malloc(space); p = malloc(space);
...@@ -49,6 +50,7 @@ void memcheck() ...@@ -49,6 +50,7 @@ void memcheck()
exit(1); exit(1);
} }
#ifdef CHECK_WRAPAROUNDS_WITH_PRIME_SIZED_WINDOWS
// How can we make sure that RTEMS doesn't mis-identify our available // 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 // 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 // e.g. 128KB, but in fact, the last 64KB 'mirror' back to the first
...@@ -107,54 +109,81 @@ void memcheck() ...@@ -107,54 +109,81 @@ void memcheck()
} }
} }
puts(""); puts("");
#endif
// Write all over the memory using alternating bit values; this verifies // Write all over the memory using alternating bit values; this verifies
// proper memory operations, by stressing (electrically) the circuits. // proper memory operations, by stressing (electrically) the circuits.
for(i=0; i<sizeof(patterns)/sizeof(patterns[0]); i++) { for(i=0; i<sizeof(patterns)/sizeof(patterns[0]); i++) {
printf("[MEMCHECK] Checking memory with pattern: 0x%08x...\n", unsigned pattern = patterns[i];
(unsigned) patterns[i]);
uint32_t *pw = p; uint32_t *pw = p;
unsigned words = space/4; unsigned words = space/4;
printf("[MEMCHECK] Writing memory pattern 0x%08x ", pattern);
fflush(stdout);
// Writing the pattern // Writing the pattern
while(words--) { 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; pw = p;
words = space/4; words = space/4;
// Verifying the pattern // Verifying the pattern
printf("[MEMCHECK] Reading memory, checking for 0x%08x ", pattern);
fflush(stdout);
while(words--) { while(words--) {
if (*pw != patterns[i]) { if (*pw != pattern) {
printf( printf(
"[MEMCHECK] Failed with pattern 0x%x at offset 0x%x\n", "\n[MEMCHECK] Failed with pattern 0x%x at offset 0x%x\n",
(unsigned)patterns[i], (unsigned)pw); pattern, (unsigned)pw);
fflush(stdout); fflush(stdout);
exit(1); 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++; pw++;
} }
printf("\b\b\b\b\b\b\b%5.2f%%\n", 100.0);
} }
// A simple final run storing big numbers consecutively. // 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; uint32_t *pw = p;
unsigned words = space/4; unsigned words = space/4;
while(words--) { while(words--) {
*pw++ = 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; pw = p;
words = space/4; words = space/4;
// Verifying the big numbers // Verifying the big numbers
while(words--) { while(words--) {
if (*pw != words) { if (*pw != words) {
printf( 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); words, (unsigned)pw);
fflush(stdout); fflush(stdout);
exit(1); exit(1);
} }
pw++; 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); 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