Re: help with next generation bkbits please

From: Larry McVoy
Date: Mon Sep 20 2004 - 20:27:47 EST


Forgot memory scrubber, here it is.

#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>

#define unless(x) if (!(x))
#define u32 unsigned int
#define status(s) write(1, s, 1); newline = 1;

int newline;
void doit(u32 bs);

int
main(int ac, char **av)
{
if (ac != 2) {
printf("Usage: %s amount_in_MB\n", av[0]);
exit(0);
}
doit(atoi(av[1])<<20);
return (0);
}

void
bad(u32 *start, u32 *p, u32 want)
{
u32 off = (char*)p - (char*)start;
u32 got = *p;

if (newline) printf("\n");
newline = 0;
printf("WANT=0x%08x GOT=0x%08x DIFF=0x%08x OFF=0x%08x ADDR=%p\n",
want, got, want - got, off, (void*)p);
}

void
doit(u32 bs)
{
u32 *buf = malloc(bs);
u32 *end;
u32 *p;
u32 off;

fprintf(stderr, "Scrub %u bytes\n", bs);
unless (buf) {
perror("malloc");
exit(1);
}
end = (u32*)((char*)buf + bs);
bzero(buf, bs);
unless (sizeof(int) == 4) {
fprintf(stderr, "Expected 4 byte ints\n");
exit(1);
}
for (off = 0, p = buf; p < end; *p++ = off, off += 4);
for (;;) {
for (off = 0, p = buf; p < end; off += 4) {
if (*p != off) bad(buf, p, off);
*p++ = 0xdeadbeef;
}
status("d");
for (off = 0, p = buf; p < end; off += 4) {
if (*p != 0xdeadbeef) bad(buf, p, 0xdeadbeef);
*p++ = 0x50505050;
}
status("5");
for (off = 0, p = buf; p < end; off += 4) {
if (*p != 0x50505050) bad(buf, p, 0x50505050);
*p++ = 0x0a0a0a0a;
}
status("a");
for (off = 0, p = buf; p < end; off += 4) {
if (*p != 0x0a0a0a0a) bad(buf, p, 0x0a0a0a0a);
*p++ = 0x55555555;
}
status("-");
for (off = 0, p = buf; p < end; off += 4) {
if (*p != 0x55555555) bad(buf, p, 0x55555555);
*p++ = 0xaaaaaaaa;
}
status("A");
for (off = 0, p = buf; p < end; off += 4) {
if (*p != 0xaaaaaaaa) bad(buf, p, 0xaaaaaaaa);
*p++ = 0x0;
}
status("0");
for (off = 0, p = buf; p < end; off += 4) {
if (*p != 0x0) bad(buf, p, 0);
*p++ = 0xffffffff;
}
status("f");
for (off = 0, p = buf; p < end; off += 4) {
if (*p != 0xffffffff) bad(buf, p, 0xffffffff);
*p++ = off;
}
status("o");
}
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/