SUMMARY: memory testing program

2007-12-24 21:26:00

Thanks for the help. Things that were recommended:

1 - I liked this most, but it doesn't work on my Sun clone / autoclient. :-(
- one might use sum instead of wc, or kmem instead of mem.

# while true; do
> wc -c /dev/mem &
> wc -c /dev/mem &
> wc -c /dev/mem &
> wc -c /dev/mem &
> sleep 10 &
> done

2 - Sun VTS available from www.sun.com.
- downloaded, but not used yet.

3 - prom memory test ... seems not to be available on the clone proms. :-(

4 - eeprom: setenv diag-switch=true
- on this box, it displays memory banks / sizes, but does not test. :-(

5 - ftp://playground.sun.com/pub/memtool.
- downloaded, but not tested yet.

Thanks for all your help. The only reason I have not tested any of the tools
yet as I was having too much fun abusing my system with a small test program
I was writing. Interesting learning exercise; I've attached that code below.
Using it never revealed the problem, so it might not be sufficient ... or
as someone suggested it could be a sporadic CPU problem. Hope not.

Thanks again,
Don

#define __EXTENSIONS__

#include <malloc.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>

#define MAXLONGLONG (((unsigned long) (-1)) >> 1)
#define MINLONGLONG (((unsigned long) (-1)) ^ MAXLONGLONG)

void *malloc_and_lock(size_t *size)
{
void *ptr, *res;
size_t min;

min = sysconf(_SC_PAGESIZE);
*size = min * 100*1024; /* 100k mem pages */

if((res = alloca(min)) == NULL) /* reserve stack for printf */
return(NULL);

while(*size > min)
{
if((ptr = valloc(*size)) != NULL) /* valloc OK */
{
if(mlock(ptr, *size) == 0) /* mlock OK */
return(ptr); /* frees res */
else
free(ptr);
}

*size >>= 1; /* valloc() or mlock() failed */
/* reduce size and try again */
}

return(NULL); /* frees res */
}

int main()
{
long long *check, msb, not_msb;
void *ptr;
size_t size, i, nel, sum = 0;

while(1)
{
if((ptr = malloc_and_lock(&size)) == NULL)
break;

sum += size;

printf("largest locakable block is %d bytes\n", size);
fflush(stdout);

nel = size / sizeof(*check);
printf("%d long longs\n", nel);
fflush(stdout);

check = ptr;
not_msb = MAXLONGLONG; /* odd parity, all but MSB on */
msb = MINLONGLONG; /* odd parity, only MSB on */

for(i = 0; i < nel; ++i)
{
check[i] = 0; /* even parity, all bits on */
check[i] = -1; /* even parity, all bits off */

check[i] = not_msb; /* odd parity */
check[i] = msb;
if((i & 4095) == 0)
printf("%d\r", i);
}

printf("done \n");
fflush(stdout);
}

printf("checked %d bytes of RAM\n", sum);
fflush(stdout);
return(0); /* unlocks and frees mem */
}

Comments

Got something to say?

You must be logged in to post a comment.