cmd: add memtester code

Enable memtester by config CONFIG_CMD_MEMTESTER=y

Change-Id: I02c873a8b3be5ee3c9a1cf347b7e3e75cb5336f0
Signed-off-by: Tang Yun ping <typ@rock-chips.com>
This commit is contained in:
Tang Yun ping 2018-08-02 14:59:46 +08:00 committed by Kever Yang
parent 7b1b253904
commit 133266d48d
9 changed files with 930 additions and 0 deletions

View File

@ -1106,6 +1106,11 @@ config CMD_ETHSW
endmenu
config CMD_MEMTESTER
bool "Enable memtester for ddr"
help
This enables memtester for ddr.
menu "Misc commands"
config CMD_BMP

View File

@ -86,6 +86,7 @@ obj-$(CONFIG_CMD_LOG) += log.o
obj-$(CONFIG_ID_EEPROM) += mac.o
obj-$(CONFIG_CMD_MD5SUM) += md5sum.o
obj-$(CONFIG_CMD_MEMORY) += mem.o
obj-$(CONFIG_CMD_MEMTESTER) += memtester/
obj-$(CONFIG_CMD_IO) += io.o
obj-$(CONFIG_CMD_MFSL) += mfsl.o
obj-$(CONFIG_CMD_MII) += mii.o

2
cmd/memtester/Makefile Normal file
View File

@ -0,0 +1,2 @@
obj-$(CONFIG_CMD_MEMTESTER) += tests.o
obj-$(CONFIG_CMD_MEMTESTER) += memtester.o

234
cmd/memtester/memtester.c Normal file
View File

@ -0,0 +1,234 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* memtester version 4
*
* Very simple but very effective user-space memory tester.
* Originally by Simon Kirby <sim@stormix.com> <sim@neato.org>
* Version 2 by Charles Cazabon <charlesc-memtester@pyropus.ca>
* Version 3 not publicly released.
* Version 4 rewrite:
* Copyright (C) 2004-2012 Charles Cazabon <charlesc-memtester@pyropus.ca>
* Licensed under the terms of the GNU General Public License version 2 (only).
* See the file COPYING for details.
*
*/
#define __version__ "4.3.0"
#include <common.h>
#include <console.h>
#include "sizes.h"
#include "types.h"
#include "tests.h"
#define EXIT_FAIL_NONSTARTER 0x01
#define EXIT_FAIL_ADDRESSLINES 0x02
#define EXIT_FAIL_OTHERTEST 0x04
DECLARE_GLOBAL_DATA_PTR;
/* reserved sp size 1MB */
#define RESERVED_SP_SIZE 0x100000
struct test tests[] = {
{"Random Value", test_random_value},
{"Compare XOR", test_xor_comparison},
{"Compare SUB", test_sub_comparison},
{"Compare MUL", test_mul_comparison},
{"Compare DIV", test_div_comparison},
{"Compare OR", test_or_comparison},
{"Compare AND", test_and_comparison},
{"Sequential Increment", test_seqinc_comparison},
{"Solid Bits", test_solidbits_comparison},
{"Block Sequential", test_blockseq_comparison},
{"Checkerboard", test_checkerboard_comparison},
{"Bit Spread", test_bitspread_comparison},
{"Bit Flip", test_bitflip_comparison},
{"Walking Ones", test_walkbits1_comparison},
{"Walking Zeroes", test_walkbits0_comparison},
#ifdef TEST_NARROW_WRITES
{"8-bit Writes", test_8bit_wide_random},
{"16-bit Writes", test_16bit_wide_random},
#endif
{NULL, NULL}
};
int use_phys;
off_t physaddrbase;
static int do_memtester(cmd_tbl_t *cmdtp, int flag, int argc,
char *const argv[])
{
ul loop, i, j;
ul buf_start;
ul start_adr[2], length[2];
ulv * bufa[2], *bufb[2];
ul count[2];
ul bufsize = 0;
ul loops = 0;
ul testenable = 0;
int exit_code = 0;
int abort = 0;
printf("memtester version " __version__ " (%d-bit)\n", UL_LEN);
printf("Copyright (C) 2001-2012 Charles Cazabon.\n");
printf("Licensed under the GNU General Public License version 2 (only).\n");
printf("\n");
start_adr[0] = (size_t)gd->bd->bi_dram[0].start;
if (gd->bd->bi_dram[1].start) {
length[0] = (size_t)gd->bd->bi_dram[0].size;
start_adr[1] = (size_t)gd->bd->bi_dram[1].start;
length[1] = gd->start_addr_sp - RESERVED_SP_SIZE - start_adr[1];
length[1] &= ~0xfff;
} else {
length[0] = gd->start_addr_sp - RESERVED_SP_SIZE - start_adr[0];
length[0] &= ~0xfff;
start_adr[1] = 0;
length[1] = 0;
}
printf("available memory for test:\n");
printf(" start end length\n");
printf(" 0x%08lx - 0x%08lx 0x%08lx\n",
start_adr[0], start_adr[0] + length[0], length[0]);
if (start_adr[1])
printf(" 0x%08lx - 0x%08lx 0x%08lx\n",
start_adr[1], start_adr[1] + length[1], length[1]);
if (argc < 2)
return CMD_RET_USAGE;
if (strict_strtoul(argv[1], 0, &buf_start) < 0)
return CMD_RET_USAGE;
if (argc > 2)
if (strict_strtoul(argv[2], 0, &bufsize) < 0)
return CMD_RET_USAGE;
if (argc > 3)
if (strict_strtoul(argv[3], 0, &testenable) < 0)
return CMD_RET_USAGE;
if (argc > 4)
if (strict_strtoul(argv[4], 0, &loops) < 0)
return CMD_RET_USAGE;
if (!bufsize) {
/* test all memory */
for (i = 0; i < 2; i++) {
bufa[i] = (ulv *)start_adr[i];
bufb[i] = (ulv *)(start_adr[i] + length[i] / 2);
count[i] = length[i] / 2 / sizeof(ul);
}
} else {
bufa[0] = (ulv *)buf_start;
bufb[0] = (ulv *)(buf_start + bufsize / 2);
count[0] = bufsize / 2 / sizeof(ul);
bufa[1] = 0;
if (start_adr[1]) {
if (buf_start < start_adr[0] ||
(buf_start >= start_adr[0] + length[0] &&
buf_start < start_adr[1]) ||
((buf_start + bufsize >
start_adr[0] + length[0]) &&
buf_start + bufsize < start_adr[1]) ||
(buf_start + bufsize >
start_adr[1] + length[1])) {
printf("unavailable memory space\n");
return CMD_RET_FAILURE;
}
} else {
if (buf_start < start_adr[0] ||
(buf_start + bufsize >
start_adr[0] + length[0])) {
printf("unavailable memory space\n");
return CMD_RET_FAILURE;
}
}
}
for (loop = 1; ((!loops) || loop <= loops); loop++) {
for (j = 0; j < 2; j++) {
if (!bufa[j])
continue;
printf("testing:0x%lx - 0x%lx\n", (ul)bufa[j],
(ul)bufa[j] + count[j] * 2 * sizeof(ul));
printf("Loop %lu", loop);
if (loops)
printf("/%lu", loops);
printf(":\n");
printf(" %-20s: ", "Stuck Address");
if (!test_stuck_address(bufa[j], count[j] * 2))
printf("ok\n");
else
exit_code |= EXIT_FAIL_ADDRESSLINES;
for (i = 0;; i++) {
if (!tests[i].name)
break;
/* If using a custom testenable, only run this
* test if the bit corresponding to this test
* was set by the user.
*/
if (testenable && (!((1 << i) & testenable)))
continue;
printf(" %-20s: ", tests[i].name);
if (!tests[i].fp(bufa[j], bufb[j], count[j]))
printf("ok\n");
else
exit_code |= EXIT_FAIL_OTHERTEST;
if (ctrlc()) {
abort = 1;
break;
}
}
printf("\n");
if (abort)
break;
}
if (abort)
break;
}
if (exit_code & EXIT_FAIL_NONSTARTER)
printf("Fail: EXIT_FAIL_NONSTARTER\n");
if (exit_code & EXIT_FAIL_ADDRESSLINES)
printf("Fail: EXIT_FAIL_ADDRESSLINES\n");
if (exit_code & EXIT_FAIL_OTHERTEST)
printf("Fail: EXIT_FAIL_OTHERTEST\n");
printf("Done.\n");
return 0;
}
U_BOOT_CMD(memtester, 5, 1, do_memtester,
"do memtester",
"[start length [testenable [loop]]]\n"
"start: start address, should be 4k align\n"
"length: test length, should be 4k align, if 0 testing full space\n"
"testenable[option]: enable pattern by set bit to 1, null or 0"
" enable all pattern\n"
" bit0: Random Value\n"
" bit1: Compare XOR\n"
" bit2: Compare SUB\n"
" bit3: Compare MUL\n"
" bit4: Compare DIV\n"
" bit5: Compare OR\n"
" bit6: Compare AND\n"
" bit7: Sequential Increment\n"
" bit8: Solid Bits\n"
" bit9: Block Sequential\n"
" bit10: Checkerboard\n"
" bit11: Bit Spread\n"
" bit12: Bit Flip\n"
" bit13: Walking Ones\n"
" bit14: Walking Zeroes\n"
" bit15: 8-bit Writes\n"
" bit16: 16-bit Writes\n"
" example: testenable=0x1000,enable Bit Flip only\n"
"loop[option]: testing loop, if 0 or null endless loop\n"
"example:\n"
" memtester 0x200000 0x1000000: start address: 0x200000 length:"
"0x1000000, enable all pattern, endless loop\n"
" memtester 0x200000 0x1000000 0x1000 100: start address:0x200000"
" length:0x1000000, Bit Flip only, loop 100 times\n"
" memtester 0 0: testing full space\n");

22
cmd/memtester/memtester.h Normal file
View File

@ -0,0 +1,22 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Very simple (yet, for some reason, very effective) memory tester.
* Originally by Simon Kirby <sim@stormix.com> <sim@neato.org>
* Version 2 by Charles Cazabon <charlesc-memtester@pyropus.ca>
* Version 3 not publicly released.
* Version 4 rewrite:
* Copyright (C) 2004-2012 Charles Cazabon <charlesc-memtester@pyropus.ca>
* Licensed under the terms of the GNU General Public License version 2 (only).
* See the file COPYING for details.
*
* This file contains the declarations for external variables from the main file.
* See other comments in that file.
*
*/
#include <linux/types.h>
/* extern declarations. */
extern int use_phys;
extern off_t physaddrbase;

40
cmd/memtester/sizes.h Normal file
View File

@ -0,0 +1,40 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Very simple but very effective user-space memory tester.
* Originally by Simon Kirby <sim@stormix.com> <sim@neato.org>
* Version 2 by Charles Cazabon <charlesc-memtester@pyropus.ca>
* Version 3 not publicly released.
* Version 4 rewrite:
* Copyright (C) 2004-2012 Charles Cazabon <charlesc-memtester@pyropus.ca>
* Licensed under the terms of the GNU General Public License version 2 (only).
* See the file COPYING for details.
*
* This file contains some macro definitions for handling 32/64 bit platforms.
*
*/
#ifndef __MEMTESTER_SIZES_H
#define __MEMTESTER_SIZES_H
#include <common.h>
#define rand32() ((unsigned int)rand() | ((unsigned int)rand() << 16))
#ifndef CONFIG_ARM64
#define rand_ul() rand32()
#define UL_ONEBITS 0xffffffff
#define UL_LEN 32
#define CHECKERBOARD1 0x55555555
#define CHECKERBOARD2 0xaaaaaaaa
#define UL_BYTE(x) ((x | x << 8 | x << 16 | x << 24))
#else
#define rand64() (((ul)rand32()) << 32 | ((ul)rand32()))
#define rand_ul() rand64()
#define UL_ONEBITS 0xffffffffffffffffUL
#define UL_LEN 64
#define CHECKERBOARD1 0x5555555555555555
#define CHECKERBOARD2 0xaaaaaaaaaaaaaaaa
#define UL_BYTE(x) (((ul)x | (ul)x << 8 | (ul)x << 16 | (ul)x << 24 | \
(ul)x << 32 | (ul)x << 40 | (ul)x << 48 | (ul)x << 56))
#endif
#endif /* __MEMTESTER_SIZES_H */

541
cmd/memtester/tests.c Normal file
View File

@ -0,0 +1,541 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Very simple but very effective user-space memory tester.
* Originally by Simon Kirby <sim@stormix.com> <sim@neato.org>
* Version 2 by Charles Cazabon <charlesc-memtester@pyropus.ca>
* Version 3 not publicly released.
* Version 4 rewrite:
* Copyright (C) 2004-2012 Charles Cazabon <charlesc-memtester@pyropus.ca>
* Licensed under the terms of the GNU General Public License version 2 (only).
* See the file COPYING for details.
*
* This file contains the functions for the actual tests, called from the
* main routine in memtester.c. See other comments in that file.
*
*/
#include "memtester.h"
#include "sizes.h"
#include "types.h"
union {
unsigned char bytes[UL_LEN / 8];
ul val;
} mword8;
union {
unsigned short u16s[UL_LEN / 16];
ul val;
} mword16;
char progress[] = "-\\|/";
#define PROGRESSLEN 4
#define PROGRESSOFTEN 2500
#define ONE 0x00000001L
#define fflush(n)
/* Function definitions. */
int compare_regions(ulv *bufa, ulv *bufb, size_t count)
{
int r = 0;
size_t i;
ulv *p1 = bufa;
ulv *p2 = bufb;
off_t physaddr;
for (i = 0; i < count; i++, p1++, p2++) {
if (*p1 != *p2) {
if (use_phys) {
physaddr = physaddrbase + (i * sizeof(ul));
fprintf(stderr,
"FAILURE: 0x%08lx != 0x%08lx at physical address "
"0x%08lx.\n",
(ul)*p1, (ul)*p2, physaddr);
} else {
fprintf(stderr,
"FAILURE: 0x%08lx != 0x%08lx at offset 0x%08lx.\n",
(ul)*p1, (ul)*p2,
(ul)(i * sizeof(ul)));
}
/* printf("Skipping to next test..."); */
r = -1;
}
}
return r;
}
int test_stuck_address(ulv *bufa, size_t count)
{
ulv *p1 = bufa;
unsigned int j;
size_t i;
off_t physaddr;
printf(" ");
fflush(stdout);
for (j = 0; j < 16; j++) {
printf("\b\b\b\b\b\b\b\b\b\b\b");
p1 = (ulv *)bufa;
printf("setting %3u", j);
fflush(stdout);
for (i = 0; i < count; i++) {
*p1 = ((j + i) % 2) == 0 ? (ul)p1 : ~((ul)p1);
*p1++;
}
printf("\b\b\b\b\b\b\b\b\b\b\b");
printf("testing %3u", j);
fflush(stdout);
p1 = (ulv *)bufa;
for (i = 0; i < count; i++, p1++) {
if (*p1 !=
(((j + i) % 2) == 0 ? (ul)p1 : ~((ul)p1))) {
if (use_phys) {
physaddr =
physaddrbase + (i * sizeof(ul));
fprintf(stderr,
"FAILURE: possible bad address line at physical "
"address 0x%08lx.\n", physaddr);
} else {
fprintf(stderr,
"FAILURE: possible bad address line at offset "
"0x%08lx.\n",
(ul)(i * sizeof(ul)));
}
printf("Skipping to next test...\n");
fflush(stdout);
return -1;
}
}
}
printf("\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b");
fflush(stdout);
return 0;
}
int test_random_value(ulv *bufa, ulv *bufb, size_t count)
{
ulv *p1 = bufa;
ulv *p2 = bufb;
ul j = 0;
size_t i;
putc(' ');
fflush(stdout);
for (i = 0; i < count; i++) {
*p1++ = *p2++ = rand_ul();
if (!(i % PROGRESSOFTEN)) {
putc('\b');
putc(progress[++j % PROGRESSLEN]);
fflush(stdout);
}
}
printf("\b \b");
fflush(stdout);
return compare_regions(bufa, bufb, count);
}
int test_xor_comparison(ulv *bufa, ulv *bufb, size_t count)
{
ulv *p1 = bufa;
ulv *p2 = bufb;
size_t i;
ul q = rand_ul();
for (i = 0; i < count; i++) {
*p1++ ^= q;
*p2++ ^= q;
}
return compare_regions(bufa, bufb, count);
}
int test_sub_comparison(ulv *bufa, ulv *bufb, size_t count)
{
ulv *p1 = bufa;
ulv *p2 = bufb;
size_t i;
ul q = rand_ul();
for (i = 0; i < count; i++) {
*p1++ -= q;
*p2++ -= q;
}
return compare_regions(bufa, bufb, count);
}
int test_mul_comparison(ulv *bufa, ulv *bufb, size_t count)
{
ulv *p1 = bufa;
ulv *p2 = bufb;
size_t i;
ul q = rand_ul();
for (i = 0; i < count; i++) {
*p1++ *= q;
*p2++ *= q;
}
return compare_regions(bufa, bufb, count);
}
int test_div_comparison(ulv *bufa, ulv *bufb, size_t count)
{
ulv *p1 = bufa;
ulv *p2 = bufb;
size_t i;
ul q = rand_ul();
for (i = 0; i < count; i++) {
if (!q)
q++;
*p1++ /= q;
*p2++ /= q;
}
return compare_regions(bufa, bufb, count);
}
int test_or_comparison(ulv *bufa, ulv *bufb, size_t count)
{
ulv *p1 = bufa;
ulv *p2 = bufb;
size_t i;
ul q = rand_ul();
for (i = 0; i < count; i++) {
*p1++ |= q;
*p2++ |= q;
}
return compare_regions(bufa, bufb, count);
}
int test_and_comparison(ulv *bufa, ulv *bufb, size_t count)
{
ulv *p1 = bufa;
ulv *p2 = bufb;
size_t i;
ul q = rand_ul();
for (i = 0; i < count; i++) {
*p1++ &= q;
*p2++ &= q;
}
return compare_regions(bufa, bufb, count);
}
int test_seqinc_comparison(ulv *bufa, ulv *bufb, size_t count)
{
ulv *p1 = bufa;
ulv *p2 = bufb;
size_t i;
ul q = rand_ul();
for (i = 0; i < count; i++)
*p1++ = *p2++ = (i + q);
return compare_regions(bufa, bufb, count);
}
int test_solidbits_comparison(ulv *bufa, ulv *bufb, size_t count)
{
ulv *p1 = bufa;
ulv *p2 = bufb;
unsigned int j;
ul q;
size_t i;
printf(" ");
fflush(stdout);
for (j = 0; j < 64; j++) {
printf("\b\b\b\b\b\b\b\b\b\b\b");
q = (j % 2) == 0 ? UL_ONEBITS : 0;
printf("setting %3u", j);
fflush(stdout);
p1 = (ulv *)bufa;
p2 = (ulv *)bufb;
for (i = 0; i < count; i++)
*p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
printf("\b\b\b\b\b\b\b\b\b\b\b");
printf("testing %3u", j);
fflush(stdout);
if (compare_regions(bufa, bufb, count))
return -1;
}
printf("\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b");
fflush(stdout);
return 0;
}
int test_checkerboard_comparison(ulv *bufa, ulv *bufb, size_t count)
{
ulv *p1 = bufa;
ulv *p2 = bufb;
unsigned int j;
ul q;
size_t i;
printf(" ");
fflush(stdout);
for (j = 0; j < 64; j++) {
printf("\b\b\b\b\b\b\b\b\b\b\b");
q = (j % 2) == 0 ? CHECKERBOARD1 : CHECKERBOARD2;
printf("setting %3u", j);
fflush(stdout);
p1 = (ulv *)bufa;
p2 = (ulv *)bufb;
for (i = 0; i < count; i++)
*p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
printf("\b\b\b\b\b\b\b\b\b\b\b");
printf("testing %3u", j);
fflush(stdout);
if (compare_regions(bufa, bufb, count))
return -1;
}
printf("\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b");
fflush(stdout);
return 0;
}
int test_blockseq_comparison(ulv *bufa, ulv *bufb, size_t count)
{
ulv *p1 = bufa;
ulv *p2 = bufb;
unsigned int j;
size_t i;
printf(" ");
fflush(stdout);
for (j = 0; j < 256; j++) {
printf("\b\b\b\b\b\b\b\b\b\b\b");
p1 = (ulv *)bufa;
p2 = (ulv *)bufb;
printf("setting %3u", j);
fflush(stdout);
for (i = 0; i < count; i++)
*p1++ = *p2++ = (ul)UL_BYTE(j);
printf("\b\b\b\b\b\b\b\b\b\b\b");
printf("testing %3u", j);
fflush(stdout);
if (compare_regions(bufa, bufb, count))
return -1;
}
printf("\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b");
fflush(stdout);
return 0;
}
int test_walkbits0_comparison(ulv *bufa, ulv *bufb, size_t count)
{
ulv *p1 = bufa;
ulv *p2 = bufb;
unsigned int j;
size_t i;
printf(" ");
fflush(stdout);
for (j = 0; j < UL_LEN * 2; j++) {
printf("\b\b\b\b\b\b\b\b\b\b\b");
p1 = (ulv *)bufa;
p2 = (ulv *)bufb;
printf("setting %3u", j);
fflush(stdout);
for (i = 0; i < count; i++) {
if (j < UL_LEN) { /* Walk it up. */
*p1++ = *p2++ = ONE << j;
} else { /* Walk it back down. */
*p1++ = *p2++ = ONE << (UL_LEN * 2 - j - 1);
}
}
printf("\b\b\b\b\b\b\b\b\b\b\b");
printf("testing %3u", j);
fflush(stdout);
if (compare_regions(bufa, bufb, count))
return -1;
}
printf("\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b");
fflush(stdout);
return 0;
}
int test_walkbits1_comparison(ulv *bufa, ulv *bufb, size_t count)
{
ulv *p1 = bufa;
ulv *p2 = bufb;
unsigned int j;
size_t i;
printf(" ");
fflush(stdout);
for (j = 0; j < UL_LEN * 2; j++) {
printf("\b\b\b\b\b\b\b\b\b\b\b");
p1 = (ulv *)bufa;
p2 = (ulv *)bufb;
printf("setting %3u", j);
fflush(stdout);
for (i = 0; i < count; i++) {
if (j < UL_LEN) { /* Walk it up. */
*p1++ = *p2++ = UL_ONEBITS ^ (ONE << j);
} else { /* Walk it back down. */
*p1++ = *p2++ =
UL_ONEBITS ^ (ONE << (UL_LEN * 2 - j - 1));
}
}
printf("\b\b\b\b\b\b\b\b\b\b\b");
printf("testing %3u", j);
fflush(stdout);
if (compare_regions(bufa, bufb, count))
return -1;
}
printf("\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b");
fflush(stdout);
return 0;
}
int test_bitspread_comparison(ulv *bufa, ulv *bufb, size_t count)
{
ulv *p1 = bufa;
ulv *p2 = bufb;
unsigned int j;
size_t i;
printf(" ");
fflush(stdout);
for (j = 0; j < UL_LEN * 2; j++) {
printf("\b\b\b\b\b\b\b\b\b\b\b");
p1 = (ulv *)bufa;
p2 = (ulv *)bufb;
printf("setting %3u", j);
fflush(stdout);
for (i = 0; i < count; i++) {
if (j < UL_LEN) { /* Walk it up. */
*p1++ = *p2++ = (i % 2 == 0)
? (ONE << j) | (ONE << (j + 2))
: UL_ONEBITS ^ ((ONE << j)
| (ONE << (j + 2)));
} else { /* Walk it back down. */
*p1++ = *p2++ = (i % 2 == 0)
? (ONE << (UL_LEN * 2 - 1 - j)) | (ONE <<
(UL_LEN *
2 + 1 -
j))
: UL_ONEBITS ^ (ONE << (UL_LEN * 2 - 1 - j)
| (ONE <<
(UL_LEN * 2 + 1 - j)));
}
}
printf("\b\b\b\b\b\b\b\b\b\b\b");
printf("testing %3u", j);
fflush(stdout);
if (compare_regions(bufa, bufb, count))
return -1;
}
printf("\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b");
fflush(stdout);
return 0;
}
int test_bitflip_comparison(ulv *bufa, ulv *bufb, size_t count)
{
ulv *p1 = bufa;
ulv *p2 = bufb;
unsigned int j, k;
ul q;
size_t i;
printf(" ");
fflush(stdout);
for (k = 0; k < UL_LEN; k++) {
q = ONE << k;
for (j = 0; j < 8; j++) {
printf("\b\b\b\b\b\b\b\b\b\b\b");
q = ~q;
printf("setting %3u", k * 8 + j);
fflush(stdout);
p1 = (ulv *)bufa;
p2 = (ulv *)bufb;
for (i = 0; i < count; i++)
*p1++ = *p2++ = (i % 2) == 0 ? q : ~q;
printf("\b\b\b\b\b\b\b\b\b\b\b");
printf("testing %3u", k * 8 + j);
fflush(stdout);
if (compare_regions(bufa, bufb, count))
return -1;
}
}
printf("\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b");
fflush(stdout);
return 0;
}
#ifdef TEST_NARROW_WRITES
int test_8bit_wide_random(ulv *bufa, ulv *bufb, size_t count)
{
u8v *p1, *t;
ulv *p2;
int attempt;
unsigned int b, j = 0;
size_t i;
putc(' ');
fflush(stdout);
for (attempt = 0; attempt < 2; attempt++) {
if (attempt & 1) {
p1 = (u8v *)bufa;
p2 = bufb;
} else {
p1 = (u8v *)bufb;
p2 = bufa;
}
for (i = 0; i < count; i++) {
t = mword8.bytes;
*p2++ = mword8.val = rand_ul();
for (b = 0; b < UL_LEN / 8; b++)
*p1++ = *t++;
if (!(i % PROGRESSOFTEN)) {
putc('\b');
putc(progress[++j % PROGRESSLEN]);
fflush(stdout);
}
}
if (compare_regions(bufa, bufb, count))
return -1;
}
printf("\b \b");
fflush(stdout);
return 0;
}
int test_16bit_wide_random(ulv *bufa, ulv *bufb, size_t count)
{
u16v *p1, *t;
ulv *p2;
int attempt;
unsigned int b, j = 0;
size_t i;
putc(' ');
fflush(stdout);
for (attempt = 0; attempt < 2; attempt++) {
if (attempt & 1) {
p1 = (u16v *)bufa;
p2 = bufb;
} else {
p1 = (u16v *)bufb;
p2 = bufa;
}
for (i = 0; i < count; i++) {
t = mword16.u16s;
*p2++ = mword16.val = rand_ul();
for (b = 0; b < UL_LEN / 16; b++)
*p1++ = *t++;
if (!(i % PROGRESSOFTEN)) {
putc('\b');
putc(progress[++j % PROGRESSLEN]);
fflush(stdout);
}
}
if (compare_regions(bufa, bufb, count))
return -1;
}
printf("\b \b");
fflush(stdout);
return 0;
}
#endif

56
cmd/memtester/tests.h Normal file
View File

@ -0,0 +1,56 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Very simple yet very effective memory tester.
* Originally by Simon Kirby <sim@stormix.com> <sim@neato.org>
* Version 2 by Charles Cazabon <charlesc-memtester@pyropus.ca>
* Version 3 not publicly released.
* Version 4 rewrite:
* Copyright (C) 2004-2012 Charles Cazabon <charlesc-memtester@pyropus.ca>
* Licensed under the terms of the GNU General Public License version 2 (only).
* See the file COPYING for details.
*
* This file contains the declarations for the functions for the actual tests,
* called from the main routine in memtester.c. See other comments in that
* file.
*
*/
/* Function declaration. */
int test_stuck_address(ulv *bufa, size_t count);
int test_random_value(ulv *bufa,
ulv *bufb, size_t count);
int test_xor_comparison(ulv *bufa,
ulv *bufb, size_t count);
int test_sub_comparison(ulv *bufa,
ulv *bufb, size_t count);
int test_mul_comparison(ulv *bufa,
ulv *bufb, size_t count);
int test_div_comparison(ulv *bufa,
ulv *bufb, size_t count);
int test_or_comparison(ulv *bufa,
ulv *bufb, size_t count);
int test_and_comparison(ulv *bufa,
ulv *bufb, size_t count);
int test_seqinc_comparison(ulv *bufa,
ulv *bufb, size_t count);
int test_solidbits_comparison(ulv *bufa,
ulv *bufb, size_t count);
int test_checkerboard_comparison(ulv *bufa,
ulv *bufb, size_t count);
int test_blockseq_comparison(ulv *bufa,
ulv *bufb, size_t count);
int test_walkbits0_comparison(ulv *bufa,
ulv *bufb, size_t count);
int test_walkbits1_comparison(ulv *bufa,
ulv *bufb, size_t count);
int test_bitspread_comparison(ulv *bufa,
ulv *bufb, size_t count);
int test_bitflip_comparison(ulv *bufa,
ulv *bufb, size_t count);
#ifdef TEST_NARROW_WRITES
int test_8bit_wide_random(ulv *bufa,
ulv *bufb, size_t count);
int test_16bit_wide_random(ulv *bufa,
ulv *bufb, size_t count);
#endif

29
cmd/memtester/types.h Normal file
View File

@ -0,0 +1,29 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Very simple but very effective user-space memory tester.
* Originally by Simon Kirby <sim@stormix.com> <sim@neato.org>
* Version 2 by Charles Cazabon <charlesc-memtester@pyropus.ca>
* Version 3 not publicly released.
* Version 4 rewrite:
* Copyright (C) 2004-2010 Charles Cazabon <charlesc-memtester@pyropus.ca>
* Licensed under the terms of the GNU General Public License version 2 (only).
* See the file COPYING for details.
*
* This file contains typedefs, structure, and union definitions.
*
*/
#ifndef __MEMTESTER_TYPES_H
#define __MEMTESTER_TYPES_H
typedef unsigned long ul;
typedef unsigned long long ull;
typedef unsigned long volatile ulv;
typedef unsigned char volatile u8v;
typedef unsigned short volatile u16v;
struct test {
char *name;
int (*fp)(ulv *bufa, ulv *bufb, size_t count);
};
#endif /* __MEMTESTER_TYPES_H */