[parisc-linux] Re: shm cache flush bug?

Thomas Bogendoerfer tsbogend@alpha.franken.de
Sun, 30 Sep 2001 16:45:01 +0200


On Sun, Sep 30, 2001 at 02:39:28PM +0200, Thomas Bogendoerfer wrote:
> [...]

forgot my test program.

Thomas.


#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>

#define SHMSIZE 32768*32

int main (int argc, char *argv[])
{
	int keyid;
	unsigned char *buf;
	int i;

	if ((keyid = shmget (IPC_PRIVATE, SHMSIZE, (SHM_R|SHM_W|IPC_CREAT))) == -1) {
		perror ("shmget");
		exit (1);
	}

	if ((buf = shmat (keyid, NULL, 0)) == ((void *)-1)) {
		perror ("shmat buf");
		exit (1);
	}

	printf ("filling buffer (%p)\n",buf);
	for (i = 0; i < SHMSIZE; i++) {
		buf[i] = i & 255;
		if (*(volatile unsigned char *)&buf[i] != (i & 255)) {
			printf ("failed at %d\n",i);
			exit (1);
		}
	}
	printf ("read back from original buffer (%p)\n",buf);
	for (i = 0; i < SHMSIZE; i++) {
		if (*(volatile unsigned char *)&buf[i] != (i & 255)) {
			printf ("failed at %d: is %02x should be %02x\n",i,*(volatile unsigned char *)&buf[i],i&255);
		}
	}
	shmdt (buf);
	shmctl (keyid, IPC_RMID, NULL);
	printf ("TEST passed\n");
	return 0;
}


-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessary a
good idea.                                 [ Alexander Viro on linux-kernel ]