X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/d033ccb0afa4d9b32c20bce2dd073650d3439479..7eb850ef0e437323e2d84157ddc2e6e82af57bbc:/src/memtest.c diff --git a/src/memtest.c b/src/memtest.c index 01569d05..88c7213a 100644 --- a/src/memtest.c +++ b/src/memtest.c @@ -16,11 +16,11 @@ #endif #ifdef MEMTEST_32BIT -#define ULONG_ONEZERO 0xaaaaaaaaaaaaaaaaUL -#define ULONG_ZEROONE 0x5555555555555555UL -#else #define ULONG_ONEZERO 0xaaaaaaaaUL #define ULONG_ZEROONE 0x55555555UL +#else +#define ULONG_ONEZERO 0xaaaaaaaaaaaaaaaaUL +#define ULONG_ZEROONE 0x5555555555555555UL #endif static struct winsize ws; @@ -47,7 +47,7 @@ void memtest_progress_end(void) { } void memtest_progress_step(size_t curr, size_t size, char c) { - size_t chars = (curr*progress_full)/size, j; + size_t chars = ((unsigned long long)curr*progress_full)/size, j; for (j = 0; j < chars-progress_printed; j++) { printf("%c",c); @@ -56,6 +56,33 @@ void memtest_progress_step(size_t curr, size_t size, char c) { fflush(stdout); } +/* Test that addressing is fine. Every location is populated with its own + * address, and finally verified. This test is very fast but may detect + * ASAP big issues with the memory subsystem. */ +void memtest_addressing(unsigned long *l, size_t bytes) { + unsigned long words = bytes/sizeof(unsigned long); + unsigned long j, *p; + + /* Fill */ + p = l; + for (j = 0; j < words; j++) { + *p = (unsigned long)p; + p++; + if ((j & 0xffff) == 0) memtest_progress_step(j,words*2,'A'); + } + /* Test */ + p = l; + for (j = 0; j < words; j++) { + if (*p != (unsigned long)p) { + printf("\n*** MEMORY ADDRESSING ERROR: %p contains %lu\n", + (void*) p, *p); + exit(1); + } + p++; + if ((j & 0xffff) == 0) memtest_progress_step(j+words,words*2,'A'); + } +} + /* Fill words stepping a single page at every write, so we continue to * touch all the pages in the smallest amount of time reducing the * effectiveness of caches, and making it hard for the OS to transfer @@ -105,13 +132,13 @@ void memtest_fill_value(unsigned long *l, size_t bytes, unsigned long v1, v = (off & 1) ? v2 : v1; for (w = 0; w < iwords; w++) { #ifdef MEMTEST_32BIT - *l1 = *l2 = ((unsigned long) (rand()&0xffff)) | - (((unsigned long) (rand()&0xffff)) << 16); + *l1 = *l2 = ((unsigned long) v) | + (((unsigned long) v) << 16); #else - *l1 = *l2 = ((unsigned long) (rand()&0xffff)) | - (((unsigned long) (rand()&0xffff)) << 16) | - (((unsigned long) (rand()&0xffff)) << 32) | - (((unsigned long) (rand()&0xffff)) << 48); + *l1 = *l2 = ((unsigned long) v) | + (((unsigned long) v) << 16) | + (((unsigned long) v) << 32) | + (((unsigned long) v) << 48); #endif l1 += step; l2 += step; @@ -162,6 +189,11 @@ void memtest_test(size_t megabytes, int passes) { } while (pass != passes) { pass++; + + memtest_progress_start("Addressing test",pass); + memtest_addressing(m,bytes); + memtest_progress_end(); + memtest_progress_start("Random fill",pass); memtest_fill_random(m,bytes); memtest_progress_end();