/* Some memory testing code Copyright (C) 2005 Kasper Dupont This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or with permission from the author any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* This code is nowhere near complete. * * The memory test algorithm is based on random bitpatterns with the * property, that all bits are pairwise independent. Fully random * patterns are too expensive to generate and too problematic to * verify. Pairwise independence provide a good probability to detect * certain kinds of errors. * * If just one pair of bits have consistently bad interaction 100 runs * would miss it with only negligible probability. In reality errors * are harder to find. In my first test an error showed up onlyt twice * in 10000 runs. * * I'd like to improve this code and in particular put it in a kernel * module so I can guarantee the data not to be swapped out and tell * where the error is to stop using the bad memory. * */ #include #include #include #include #include #include struct seed { uint32_t hi; uint16_t lo; uint16_t in; }; int parity(uint32_t x) { x^=x>>16; x^=x>>8; x^=x>>4; x^=x>>2; x^=x>>1; return x&1; } void init(uint16_t *p,uint16_t lo, uint16_t in) { int i; for (i=0;i<2048;++i) p[i]=parity(i&lo)?~in:in; } #define MB 1000 #define PAGES (MB*256) int main() { struct seed s1,s2; int fd; int p,i,errors=0; uint16_t page[4][2048]; static uint8_t mem[4096*PAGES]; fd=open("/dev/urandom",O_RDONLY); read(fd,&s1,8); init(page[0],s1.lo,s1.in); init(page[1],s1.lo,~s1.in); printf("Testing %d MB\n",MB); for (i=0;i