Subject: memtest (was Re: G3 Update, XFree and NetWork question)
To: None <port-macppc@NetBSD.org>
From: Donald Lee <MacPPC@caution.icompute.com>
List: port-macppc
Date: 08/08/2003 09:33:39
BTW - you want to run this with a value just less than what causes horrible
page swapping.  That value will be somewhat less than the actual physical
memory in the machine....  You can use systat to watch it run.

-dgl-

>Hello all,
>
>I've a working NetBSD on a 7500 with a G3 Update...
>I even have compiled a kernel myself to put that cache on...
>It works but somehow I've got the feeling that the system is more unstable
>now...
>
>NetBSD itself crashed only one time(some assertion failed), but GCC fails
>often with a segfault.
>It could be my RAM too, is there some tool for NetBSD to check it?

FYA (For Your Amusement...) the following is a very crude memory test tool.

Just run this program with a single parameter - the amount of physical memory
on your machine.  It's not very precise, due to the way VM works, but
statistically, I find that it touches enough of the physical memory that
it makes a reasonable test.

I see that running this on NetBSD runs me up against ulimits - and I see
that I have some difficulty raising the memory limits so that I can run
a single copy of the program that will hit all of physmem, even as root....

Multiple copies work fine, though. (to test 256 Meg, run the prog twice,
with 128M each)

Enjoy,

-dgl-


#include <stdio.h>
//#include <malloc.h>

#define MEG (1024*1024)

static long testme(char *chunk, long val);

main(int argc, char **argv, char **envp)
	{
	long zero = 0, ones = 0xffffffff, left = 0xaaaaaaaa, right=0x55555555;
	long errs = 0, iter = 0;
	int i;
	char *chunk;
	char *buf;
	long megs;


	megs = 1;
	if (argc > 1) megs = atoi(argv[1]);

	printf("using %d megs bufsiz\n", megs);
	buf = (char *)malloc(megs * MEG);
	if (!buf) {
                printf("Malloc failed\n");
                exit(1);
	}
	
	while(1)
		{
		printf("Iteration %d, %d errors\n", iter, errs);
		for (i = 0 ; i < megs ; i++)
			{
			chunk = &buf[i*MEG];
			errs += testme(chunk,zero);
			errs += testme(chunk,ones);
			errs += testme(chunk,left);
			errs += testme(chunk,right);
			}
		iter++;
		fflush(NULL);
		}
	}

static long
testme(char *chunk, long val)
	{
	long i, errs = 0;
	long *buf;

	buf = (long *)chunk;
	for (i = 0 ; i < (MEG/sizeof(long)) ; i++)
		{
		buf[i] = val;
		}
	for (i = 0 ; i < (MEG/sizeof(long)) ; i++)
		{
		if (buf[i] != val)
			{
			errs++;
			printf("Got an error at %d - old=%x = new=%x\n",
				i, val, buf[i]);
			}
		}
	return(errs);
	}