diff --git a/cmdline/util.c b/cmdline/util.c index de789666..4a52fa8b 100644 --- a/cmdline/util.c +++ b/cmdline/util.c @@ -68,9 +68,39 @@ void* malloc_nofail_test(size_t size) return ptr; } +/** + * Fast memory test. + * + * It's similat at raid_mtest_vector() but faster because + * we have a lot of buffers to verify. + */ +static int fast_mtest_vector(int n, size_t size, void** vv) +{ + int i, j; + + /* test with all the bits */ + for (i = 0; i < 8; ++i) { + unsigned char value = 1 << i; + + /* fill first */ + memset(vv[0], value, size); + + /* copy to the next */ + for (j = 1; j < n; ++j) + memcpy(vv[j], vv[j-1], size); + + /* compare with the previous */ + for (j = 1; j <= n; ++j) + if (memcmp(vv[j % n], vv[j-1], size) != 0) + return -1; + } + + return 0; +} + void mtest_vector(int n, size_t size, void** vv) { - if (raid_mtest_vector(n, size, vv) != 0) { + if (fast_mtest_vector(n, size, vv) != 0) { /* LCOV_EXCL_START */ log_fatal("DANGER! Your RAM memory is broken! DO NOT PROCEED UNTIL FIXED!\n"); log_fatal("Try running a memory test like http://www.memtest86.com/\n");