/* kmemtest - a memory tester to run as a kernel thread under Linux 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 ChangeLog: 14 jul 2005 - Fixed race condition and prints results on exit */ #include #include #include #include #include #include #include #include #include #include #include #ifndef MB #define MB 42 #endif #define PAGES (MB*256) struct page *p[PAGES]; struct seed { uint32_t hi; uint16_t lo; uint16_t in; } s1, s2; uint16_t page[4][2048]; void kmemtest_cleanup(void) { int i; for (i=0;i>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; } static DECLARE_COMPLETION(kmemtest_exited); static atomic_t kmemtest_quit = ATOMIC_INIT(0); int kmemtest_thread(void *arg) { int i,pass=0,errors=0; struct task_struct *curtask = current; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) sigset_t blocked; daemonize("kmemtest"); sigemptyset(&blocked); sigprocmask(SIG_SETMASK, &blocked, NULL); #else daemonize(); #endif set_user_nice(curtask, 19); while(1) { snprintf(curtask->comm,15,"kmemtest %d",++pass); get_random_bytes(&s2,8); init(page[2],s2.lo,s2.in); init(page[3],s2.lo,~s2.in); for (i=0;i= si.totalram) return -ENOMEM; memset(p,0,sizeof(p)); init(page[0],s1.lo,s1.in); init(page[1],s1.lo,~s1.in); for (i=0;i