From d57a4cf290b53c683e07d4abd8e75448222bcda6 Mon Sep 17 00:00:00 2001 From: Jean-Noel Avila Date: Wed, 30 May 2018 16:11:49 +0200 Subject: [PATCH 1/7] make extra-libs.sh executable --- extra-libs.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 extra-libs.sh diff --git a/extra-libs.sh b/extra-libs.sh old mode 100644 new mode 100755 From c1acc5cb69419794402a75269fc988c86b091c0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Avila?= Date: Wed, 23 Sep 2020 21:35:58 +0200 Subject: [PATCH 2/7] bump to version 4.5.0 from pyropus.ca --- CHANGELOG | 9 +++++++++ Makefile | 5 +++-- README | 17 ++++++++++++++++- find-systype.sh | 0 make-compile.sh | 0 make-load.sh | 0 make-makelib.sh | 0 memtester.8 | 4 ++-- memtester.c | 21 ++++++++++++++++++--- memtester.h | 2 +- tests.c | 12 +++++++++++- tests.h | 2 +- types.h | 12 +----------- warn-auto.sh | 0 14 files changed, 62 insertions(+), 22 deletions(-) mode change 100644 => 100755 find-systype.sh mode change 100644 => 100755 make-compile.sh mode change 100644 => 100755 make-load.sh mode change 100644 => 100755 make-makelib.sh mode change 100644 => 100755 warn-auto.sh diff --git a/CHANGELOG b/CHANGELOG index 5f1cec1..c5edd58 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,12 @@ +Version 4.5.0 +20 September 2020 + -add note to README about problems with HP/UX prior to v.11. Change code + so that buffer still gets aligned even if you comment out the use of mlock() + on such a platform. Thanks: Keith Monahan. + -fix clear-buffer using incorrect param, causing spurious test failures. + Thanks: Debin Dong. + -fix shell-ism in Makefile. Thanks: Fabrice Fontaine. + Version 4.3.0 9 June 2012 -add ability to mmap a device other than /dev/mem, enabling easier testing diff --git a/Makefile b/Makefile index a271bf5..123f7bc 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ # Makefile for memtester by Charles Cazabon. # # Copyright (C) 1999 Simon Kirby. -# Copyright (C) 1999-2009 Charles Cazabon. +# Copyright (C) 1999-2020 Charles Cazabon. # Licensed under the GNU General Public License version 2. See the file # COPYING for details. # @@ -25,8 +25,9 @@ INSTALLPATH = /usr/local all: memtester install: all - mkdir -m 755 -p $(INSTALLPATH)/{bin,man/man8} + mkdir -m 755 -p $(INSTALLPATH)/bin install -m 755 memtester $(INSTALLPATH)/bin/ + mkdir -m 755 -p $(INSTALLPATH)/man/man8 gzip -c memtester.8 >memtester.8.gz ; install -m 644 memtester.8.gz $(INSTALLPATH)/man/man8/ auto-ccld.sh: \ diff --git a/README b/README index 44003b1..fc8f423 100644 --- a/README +++ b/README @@ -8,7 +8,7 @@ Version 2 Copyright 1999 Charles Cazabon. Version 3 not publicly released. Version 4 rewrite: - Copyright 2004-2012 Charles Cazabon. + Copyright 2004-2020 Charles Cazabon. Licensed under the terms of the GNU General Public License version 2 (only). See the file COPYING for details. @@ -124,3 +124,18 @@ directed to me at . Read BUGS to report bugs found in memtester. + Platform Compatibility Notes + + As mentioned, memtester v4 was tested with a wide variety of Unix- and + Unix-like systems. However, at least two issues with ancient HP/UX + versions have come up since. + + HP/UX versions prior to v11 do not support mlock() and will fail with an + invalid syscall error at runtime. If you're building on HP/UX v10.20 or + similar, change `int do_mlock = 1` around line 128 of memtester.c to + `int do_mlock = 0` and rebuild. + They also are missing strtoull() from C99. To fix this build error, + add `#define strtoull __strtoull` to the top of memtester.c; this should + at least work with a GCC toolchain. + + diff --git a/find-systype.sh b/find-systype.sh old mode 100644 new mode 100755 diff --git a/make-compile.sh b/make-compile.sh old mode 100644 new mode 100755 diff --git a/make-load.sh b/make-load.sh old mode 100644 new mode 100755 diff --git a/make-makelib.sh b/make-makelib.sh old mode 100644 new mode 100755 diff --git a/memtester.8 b/memtester.8 index fd80bc7..cf460b8 100644 --- a/memtester.8 +++ b/memtester.8 @@ -1,4 +1,4 @@ -.TH memtester "8" "June 2012" "memtester 4" "Maintenance Commands" +.TH memtester "8" "September 2020" "memtester 4" "Maintenance Commands" .SH NAME memtester \- stress test to find memory subsystem faults. .SH SYNOPSIS @@ -97,7 +97,7 @@ Written by Charles Cazabon. Report bugs to . .PP .SH COPYRIGHT -Copyright \(co 2001-2012 Charles Cazabon +Copyright \(co 2001-2020 Charles Cazabon .br This is free software; see the file COPYING for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff --git a/memtester.c b/memtester.c index 3db2ad4..46a427b 100644 --- a/memtester.c +++ b/memtester.c @@ -6,13 +6,13 @@ * Version 2 by Charles Cazabon * Version 3 not publicly released. * Version 4 rewrite: - * Copyright (C) 2004-2012 Charles Cazabon + * Copyright (C) 2004-2020 Charles Cazabon * Licensed under the terms of the GNU General Public License version 2 (only). * See the file COPYING for details. * */ -#define __version__ "4.3.0" +#define __version__ "4.5.0" #include #include @@ -128,7 +128,7 @@ int main(int argc, char **argv) { ul testmask = 0; printf("memtester version " __version__ " (%d-bit)\n", UL_LEN); - printf("Copyright (C) 2001-2012 Charles Cazabon.\n"); + printf("Copyright (C) 2001-2020 Charles Cazabon.\n"); printf("Licensed under the GNU General Public License version 2 (only).\n"); printf("\n"); check_posix_system(); @@ -359,6 +359,19 @@ int main(int argc, char **argv) { if (!do_mlock) fprintf(stderr, "Continuing with unlocked memory; testing " "will be slower and less reliable.\n"); + /* Do alighnment here as well, as some cases won't trigger above if you + define out the use of mlock() (cough HP/UX 10 cough). */ + if ((size_t) buf % pagesize) { + /* printf("aligning to page -- was 0x%tx\n", buf); */ + aligned = (void volatile *) ((size_t) buf & pagesizemask) + pagesize; + /* printf(" now 0x%tx -- lost %d bytes\n", aligned, + * (size_t) aligned - (size_t) buf); + */ + bufsize -= ((size_t) aligned - (size_t) buf); + } else { + aligned = buf; + } + halflen = bufsize / 2; count = halflen / sizeof(ul); bufa = (ulv *) aligned; @@ -392,6 +405,8 @@ int main(int argc, char **argv) { exit_code |= EXIT_FAIL_OTHERTEST; } fflush(stdout); + /* clear buffer */ + memset((void *) buf, 255, wantbytes); } printf("\n"); fflush(stdout); diff --git a/memtester.h b/memtester.h index 229bca3..2116eb8 100644 --- a/memtester.h +++ b/memtester.h @@ -4,7 +4,7 @@ * Version 2 by Charles Cazabon * Version 3 not publicly released. * Version 4 rewrite: - * Copyright (C) 2004-2012 Charles Cazabon + * Copyright (C) 2004-2020 Charles Cazabon * Licensed under the terms of the GNU General Public License version 2 (only). * See the file COPYING for details. * diff --git a/tests.c b/tests.c index be1b350..4970350 100644 --- a/tests.c +++ b/tests.c @@ -4,7 +4,7 @@ * Version 2 by Charles Cazabon * Version 3 not publicly released. * Version 4 rewrite: - * Copyright (C) 2004-2012 Charles Cazabon + * Copyright (C) 2004-2020 Charles Cazabon * Licensed under the terms of the GNU General Public License version 2 (only). * See the file COPYING for details. * @@ -27,6 +27,16 @@ char progress[] = "-\\|/"; #define PROGRESSOFTEN 2500 #define ONE 0x00000001L +union { + unsigned char bytes[UL_LEN/8]; + ul val; +} mword8; + +union { + unsigned short u16s[UL_LEN/16]; + ul val; +} mword16; + /* Function definitions. */ int compare_regions(ulv *bufa, ulv *bufb, size_t count) { diff --git a/tests.h b/tests.h index eccd47c..e8b2f5f 100644 --- a/tests.h +++ b/tests.h @@ -4,7 +4,7 @@ * Version 2 by Charles Cazabon * Version 3 not publicly released. * Version 4 rewrite: - * Copyright (C) 2004-2012 Charles Cazabon + * Copyright (C) 2004-2020 Charles Cazabon * Licensed under the terms of the GNU General Public License version 2 (only). * See the file COPYING for details. * diff --git a/types.h b/types.h index ad7ce73..4cb41c3 100644 --- a/types.h +++ b/types.h @@ -4,7 +4,7 @@ * Version 2 by Charles Cazabon * Version 3 not publicly released. * Version 4 rewrite: - * Copyright (C) 2004-2010 Charles Cazabon + * Copyright (C) 2004-2020 Charles Cazabon * Licensed under the terms of the GNU General Public License version 2 (only). * See the file COPYING for details. * @@ -24,13 +24,3 @@ struct test { char *name; int (*fp)(); }; - -union { - unsigned char bytes[UL_LEN/8]; - ul val; -} mword8; - -union { - unsigned short u16s[UL_LEN/16]; - ul val; -} mword16; diff --git a/warn-auto.sh b/warn-auto.sh old mode 100644 new mode 100755 From 8b52e4d08d9b11d31c25a56417fcb96ab92fa77e Mon Sep 17 00:00:00 2001 From: Luca Ceresoli Date: Thu, 27 Jan 2022 09:51:38 +0100 Subject: [PATCH 3/7] bump to version 4.5.1 from pyropus.ca Apply diff between the 4.5.0 and the 4.5.1 downloaded tarballs. As the changelog states, this is a documentation-only update. Signed-off-by: Luca Ceresoli --- CHANGELOG | 8 +++++++- README | 9 ++++++++- memtester.c | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c5edd58..e2a359e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +Version 4.5.1 +30 May 2021 + -documentation-only update. + -add note to README about build problem with Tru64, with workaround. + Thanks: VĂ­ctor Ostorga. + Version 4.5.0 20 September 2020 -add note to README about problems with HP/UX prior to v.11. Change code @@ -23,7 +29,7 @@ Version 4.2.2 mlock; BSDs use this to indicate the lock failed due to being over a system or process limit, much like ENOMEM. - Version 4.2.1 +Version 4.2.1 3 October 2010 -fix offsets/addresses were not being reported correctly in test failure messages. Thanks: Anton Sergeev. diff --git a/README b/README index fc8f423..364e808 100644 --- a/README +++ b/README @@ -128,7 +128,7 @@ As mentioned, memtester v4 was tested with a wide variety of Unix- and Unix-like systems. However, at least two issues with ancient HP/UX - versions have come up since. + versions, and one with Tru64, have come up since. HP/UX versions prior to v11 do not support mlock() and will fail with an invalid syscall error at runtime. If you're building on HP/UX v10.20 or @@ -138,4 +138,11 @@ add `#define strtoull __strtoull` to the top of memtester.c; this should at least work with a GCC toolchain. + Tru64 is missing strtoull() from C99. To fix this build error when using + cc, add `#define strtoull strtoul` to the top of memtester.c; this is + safe because long on Tru64 is 64-bits. This build problem could be dealt + with automatically, but I don't particularly want to invest the necessary + time, because Tru64 went out of support in 2012. In addition, I no longer + have access to a build machine for testing on this platform. + diff --git a/memtester.c b/memtester.c index 46a427b..44d331e 100644 --- a/memtester.c +++ b/memtester.c @@ -12,7 +12,7 @@ * */ -#define __version__ "4.5.0" +#define __version__ "4.5.1" #include #include From 7804803b5590473752ddd3da1d040b05fd89a4f3 Mon Sep 17 00:00:00 2001 From: Luca Ceresoli Date: Tue, 15 Feb 2022 22:15:33 +0100 Subject: [PATCH 4/7] Remove trailing whitespace Cleanup sources by removing all spaces at line end and multiple empty lines at end of .h and .c files. Signed-off-by: Luca Ceresoli --- memtester.c | 16 ++++++++-------- memtester.h | 1 - sizes.h | 2 -- tests.c | 18 +++++++++--------- tests.h | 5 ++--- 5 files changed, 19 insertions(+), 23 deletions(-) diff --git a/memtester.c b/memtester.c index 44d331e..833641e 100644 --- a/memtester.c +++ b/memtester.c @@ -49,7 +49,7 @@ struct test tests[] = { { "Bit Flip", test_bitflip_comparison }, { "Walking Ones", test_walkbits1_comparison }, { "Walking Zeroes", test_walkbits0_comparison }, -#ifdef TEST_NARROW_WRITES +#ifdef TEST_NARROW_WRITES { "8-bit Writes", test_8bit_wide_random }, { "16-bit Writes", test_16bit_wide_random }, #endif @@ -135,7 +135,7 @@ int main(int argc, char **argv) { pagesize = memtester_pagesize(); pagesizemask = (ptrdiff_t) ~(pagesize - 1); printf("pagesizemask is 0x%tx\n", pagesizemask); - + /* If MEMTESTER_TEST_MASK is set, we use its value as a mask of which tests we run. */ @@ -143,7 +143,7 @@ int main(int argc, char **argv) { errno = 0; testmask = strtoul(env_testmask, 0, 0); if (errno) { - fprintf(stderr, "error parsing MEMTESTER_TEST_MASK %s: %s\n", + fprintf(stderr, "error parsing MEMTESTER_TEST_MASK %s: %s\n", env_testmask, strerror(errno)); usage(argv[0]); /* doesn't return */ } @@ -179,12 +179,12 @@ int main(int argc, char **argv) { break; case 'd': if (stat(optarg,&statbuf)) { - fprintf(stderr, "can not use %s as device: %s\n", optarg, + fprintf(stderr, "can not use %s as device: %s\n", optarg, strerror(errno)); usage(argv[0]); /* doesn't return */ } else { if (!S_ISCHR(statbuf.st_mode)) { - fprintf(stderr, "can not mmap non-char device %s\n", + fprintf(stderr, "can not mmap non-char device %s\n", optarg); usage(argv[0]); /* doesn't return */ } else { @@ -192,18 +192,18 @@ int main(int argc, char **argv) { device_specified = 1; } } - break; + break; default: /* '?' */ usage(argv[0]); /* doesn't return */ } } if (device_specified && !use_phys) { - fprintf(stderr, + fprintf(stderr, "for mem device, physaddrbase (-p) must be specified\n"); usage(argv[0]); /* doesn't return */ } - + if (optind >= argc) { fprintf(stderr, "need memory argument, in MB\n"); usage(argv[0]); /* doesn't return */ diff --git a/memtester.h b/memtester.h index 2116eb8..688e241 100644 --- a/memtester.h +++ b/memtester.h @@ -19,4 +19,3 @@ extern int use_phys; extern off_t physaddrbase; - diff --git a/sizes.h b/sizes.h index cd1c3ad..4d9d8e4 100644 --- a/sizes.h +++ b/sizes.h @@ -34,5 +34,3 @@ #else #error long on this platform is not 32 or 64 bits #endif - - diff --git a/tests.c b/tests.c index 4970350..72de6f1 100644 --- a/tests.c +++ b/tests.c @@ -50,13 +50,13 @@ int compare_regions(ulv *bufa, ulv *bufb, size_t count) { if (*p1 != *p2) { if (use_phys) { physaddr = physaddrbase + (i * sizeof(ul)); - fprintf(stderr, + fprintf(stderr, "FAILURE: 0x%08lx != 0x%08lx at physical address " - "0x%08lx.\n", + "0x%08lx.\n", (ul) *p1, (ul) *p2, physaddr); } else { - fprintf(stderr, - "FAILURE: 0x%08lx != 0x%08lx at offset 0x%08lx.\n", + 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..."); */ @@ -91,14 +91,14 @@ int test_stuck_address(ulv *bufa, size_t count) { if (*p1 != (((j + i) % 2) == 0 ? (ul) p1 : ~((ul) p1))) { if (use_phys) { physaddr = physaddrbase + (i * sizeof(ul)); - fprintf(stderr, + fprintf(stderr, "FAILURE: possible bad address line at physical " - "address 0x%08lx.\n", + "address 0x%08lx.\n", physaddr); } else { - fprintf(stderr, + fprintf(stderr, "FAILURE: possible bad address line at offset " - "0x%08lx.\n", + "0x%08lx.\n", (ul) (i * sizeof(ul))); } printf("Skipping to next test...\n"); @@ -456,7 +456,7 @@ int test_bitflip_comparison(ulv *bufa, ulv *bufb, size_t count) { return 0; } -#ifdef TEST_NARROW_WRITES +#ifdef TEST_NARROW_WRITES int test_8bit_wide_random(ulv* bufa, ulv* bufb, size_t count) { u8v *p1, *t; ulv *p2; diff --git a/tests.h b/tests.h index e8b2f5f..67c7b29 100644 --- a/tests.h +++ b/tests.h @@ -9,7 +9,7 @@ * 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 + * called from the main routine in memtester.c. See other comments in that * file. * */ @@ -32,8 +32,7 @@ int test_walkbits0_comparison(unsigned long volatile *bufa, unsigned long volati int test_walkbits1_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); int test_bitspread_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); int test_bitflip_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); -#ifdef TEST_NARROW_WRITES +#ifdef TEST_NARROW_WRITES int test_8bit_wide_random(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); int test_16bit_wide_random(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count); #endif - From 026768d9e5fa344cd115596d70e3b24a1b1387ae Mon Sep 17 00:00:00 2001 From: Luca Ceresoli Date: Wed, 16 Feb 2022 16:41:11 +0100 Subject: [PATCH 5/7] Suppress progress output if stdout is not a tty The progress output based on '\b' to update the screen is very nice when memtester is run interactively. However it is annoying when its output is redirected, for example to save it to a log file or to parse it. Automatically disable the progress reports when stdout is not a tty, detected by isatty(). As this involves adding an if() is all places where progress is shown, it would add more duplicated code to the existing one. To avoid it, move all the status-reporting output code to a new file, output.c, and use these new calls everywhere progress status is shown. Signed-off-by: Luca Ceresoli --- Makefile | 4 +- memtester.c | 4 ++ output.c | 89 ++++++++++++++++++++++++++++++ output.h | 22 ++++++++ tests.c | 156 +++++++++++++++------------------------------------- 5 files changed, 161 insertions(+), 114 deletions(-) create mode 100644 output.c create mode 100644 output.h diff --git a/Makefile b/Makefile index 123f7bc..5756ecd 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ CC = $(shell head -n 1 conf-cc) LD = $(shell head -n 1 conf-ld) -SOURCES = memtester.c tests.c +SOURCES = memtester.c tests.c output.c OBJECTS = $(SOURCES:.c=.o) HEADERS = memtester.h TARGETS = *.o compile load auto-ccld.sh find-systype make-compile make-load systype extra-libs @@ -76,7 +76,7 @@ clean: memtester: \ $(OBJECTS) memtester.c tests.h tests.c tests.h conf-cc Makefile load extra-libs - ./load memtester tests.o `cat extra-libs` + ./load memtester tests.o output.o `cat extra-libs` memtester.o: memtester.c tests.h conf-cc Makefile compile ./compile memtester.c diff --git a/memtester.c b/memtester.c index 833641e..fa64b91 100644 --- a/memtester.c +++ b/memtester.c @@ -28,6 +28,7 @@ #include "types.h" #include "sizes.h" #include "tests.h" +#include "output.h" #define EXIT_FAIL_NONSTARTER 0x01 #define EXIT_FAIL_ADDRESSLINES 0x02 @@ -127,6 +128,8 @@ int main(int argc, char **argv) { char *env_testmask = 0; ul testmask = 0; + out_initialize(); + printf("memtester version " __version__ " (%d-bit)\n", UL_LEN); printf("Copyright (C) 2001-2020 Charles Cazabon.\n"); printf("Licensed under the GNU General Public License version 2 (only).\n"); @@ -399,6 +402,7 @@ int main(int argc, char **argv) { continue; } printf(" %-20s: ", tests[i].name); + fflush(stdout); if (!tests[i].fp(bufa, bufb, count)) { printf("ok\n"); } else { diff --git a/output.c b/output.c new file mode 100644 index 0000000..a55c491 --- /dev/null +++ b/output.c @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2022 Luca Ceresoli + * + * Output routines to conditionally show testing status. + * + * out_initialize() must be called at program startup and disabled status + * output if stdout is not a tty. The other functions print test progress, + * but only if on a tty. + */ + +#include +#include + +#include "output.h" + +static int show_progress = 1; +static int wheel_pos; + +void out_initialize() +{ + show_progress = isatty(STDOUT_FILENO); +} + +void out_test_start() +{ + if (show_progress) { + printf(" "); + fflush(stdout); + } +} + +void out_test_setting(unsigned int j) +{ + if (show_progress) { + printf("\b\b\b\b\b\b\b\b\b\b\b"); + printf("setting %3u", j); + fflush(stdout); + } +} + +void out_test_testing(unsigned int j) +{ + if (show_progress) { + printf("\b\b\b\b\b\b\b\b\b\b\b"); + printf("testing %3u", j); + fflush(stdout); + } +} + +void out_test_end() +{ + if (show_progress) { + 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); + } +} + +void out_wheel_start() +{ + if (show_progress) { + putchar(' '); + fflush(stdout); + wheel_pos = 0; + } +} + +void out_wheel_advance(unsigned int i) +{ + static const unsigned int wheel_often = 2500; + static const unsigned int n_chars = 4; + char wheel_char[4] = {'-', '\\', '|', '/'}; + + if (show_progress) { + if (!(i % wheel_often)) { + putchar('\b'); + putchar(wheel_char[++wheel_pos % n_chars]); + fflush(stdout); + } + } +} + +void out_wheel_end() +{ + if (show_progress) { + printf("\b \b"); + fflush(stdout); + } +} diff --git a/output.h b/output.h new file mode 100644 index 0000000..8648272 --- /dev/null +++ b/output.h @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2022 Luca Ceresoli + * + * Output routines to conditionally show testing status. + */ + +#ifndef _OUTPUT_H_ +#define _OUTPUT_H_ + +void out_initialize(); + +void out_test_start(); +void out_test_setting(); +void out_test_testing(); +void out_test_end(); + +void out_wheel_start(); +void out_wheel_advance(); +void out_wheel_end(); + +#endif // _OUTPUT_H_ diff --git a/tests.c b/tests.c index 72de6f1..735c3d7 100644 --- a/tests.c +++ b/tests.c @@ -21,10 +21,8 @@ #include "types.h" #include "sizes.h" #include "memtester.h" +#include "output.h" -char progress[] = "-\\|/"; -#define PROGRESSLEN 4 -#define PROGRESSOFTEN 2500 #define ONE 0x00000001L union { @@ -72,20 +70,15 @@ int test_stuck_address(ulv *bufa, size_t count) { size_t i; off_t physaddr; - printf(" "); - fflush(stdout); + out_test_start(); 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); + out_test_setting(j); 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); + out_test_testing(j); p1 = (ulv *) bufa; for (i = 0; i < count; i++, p1++) { if (*p1 != (((j + i) % 2) == 0 ? (ul) p1 : ~((ul) p1))) { @@ -107,29 +100,21 @@ int test_stuck_address(ulv *bufa, size_t count) { } } } - 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); + out_test_end(); 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; - putchar(' '); - fflush(stdout); + out_wheel_start(); for (i = 0; i < count; i++) { *p1++ = *p2++ = rand_ul(); - if (!(i % PROGRESSOFTEN)) { - putchar('\b'); - putchar(progress[++j % PROGRESSLEN]); - fflush(stdout); - } + out_wheel_advance(i); } - printf("\b \b"); - fflush(stdout); + out_wheel_end(); return compare_regions(bufa, bufb, count); } @@ -233,27 +218,21 @@ int test_solidbits_comparison(ulv *bufa, ulv *bufb, size_t count) { ul q; size_t i; - printf(" "); - fflush(stdout); + out_test_start(); 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); + out_test_setting(j); 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); + out_test_testing(j); 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); + out_test_end(); return 0; } @@ -264,27 +243,21 @@ int test_checkerboard_comparison(ulv *bufa, ulv *bufb, size_t count) { ul q; size_t i; - printf(" "); - fflush(stdout); + out_test_start(); 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); + out_test_setting(j); 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); + out_test_testing(j); 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); + out_test_end(); return 0; } @@ -294,26 +267,20 @@ int test_blockseq_comparison(ulv *bufa, ulv *bufb, size_t count) { unsigned int j; size_t i; - printf(" "); - fflush(stdout); + out_test_start(); 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); + out_test_setting(j); 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); + out_test_testing(j); 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); + out_test_end(); return 0; } @@ -323,14 +290,11 @@ int test_walkbits0_comparison(ulv *bufa, ulv *bufb, size_t count) { unsigned int j; size_t i; - printf(" "); - fflush(stdout); + out_test_start(); 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); + out_test_setting(j); for (i = 0; i < count; i++) { if (j < UL_LEN) { /* Walk it up. */ *p1++ = *p2++ = ONE << j; @@ -338,15 +302,12 @@ int test_walkbits0_comparison(ulv *bufa, ulv *bufb, size_t count) { *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); + out_test_testing(j); 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); + out_test_end(); return 0; } @@ -356,14 +317,11 @@ int test_walkbits1_comparison(ulv *bufa, ulv *bufb, size_t count) { unsigned int j; size_t i; - printf(" "); - fflush(stdout); + out_test_start(); 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); + out_test_setting(j); for (i = 0; i < count; i++) { if (j < UL_LEN) { /* Walk it up. */ *p1++ = *p2++ = UL_ONEBITS ^ (ONE << j); @@ -371,15 +329,12 @@ int test_walkbits1_comparison(ulv *bufa, ulv *bufb, size_t count) { *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); + out_test_testing(j); 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); + out_test_end(); return 0; } @@ -389,14 +344,11 @@ int test_bitspread_comparison(ulv *bufa, ulv *bufb, size_t count) { unsigned int j; size_t i; - printf(" "); - fflush(stdout); + out_test_start(); 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); + out_test_setting(j); for (i = 0; i < count; i++) { if (j < UL_LEN) { /* Walk it up. */ *p1++ = *p2++ = (i % 2 == 0) @@ -410,15 +362,12 @@ int test_bitspread_comparison(ulv *bufa, ulv *bufb, size_t count) { | (ONE << (UL_LEN * 2 + 1 - j))); } } - printf("\b\b\b\b\b\b\b\b\b\b\b"); - printf("testing %3u", j); - fflush(stdout); + out_test_testing(j); 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); + out_test_end(); return 0; } @@ -429,30 +378,25 @@ int test_bitflip_comparison(ulv *bufa, ulv *bufb, size_t count) { ul q; size_t i; - printf(" "); - fflush(stdout); + out_test_start(); 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); + out_test_setting(k * 8 + j); 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); + out_test_testing(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); + out_test_end(); return 0; } @@ -461,11 +405,10 @@ int test_8bit_wide_random(ulv* bufa, ulv* bufb, size_t count) { u8v *p1, *t; ulv *p2; int attempt; - unsigned int b, j = 0; + unsigned int b; size_t i; - putchar(' '); - fflush(stdout); + out_wheel_start(); for (attempt = 0; attempt < 2; attempt++) { if (attempt & 1) { p1 = (u8v *) bufa; @@ -480,18 +423,13 @@ int test_8bit_wide_random(ulv* bufa, ulv* bufb, size_t count) { for (b=0; b < UL_LEN/8; b++) { *p1++ = *t++; } - if (!(i % PROGRESSOFTEN)) { - putchar('\b'); - putchar(progress[++j % PROGRESSLEN]); - fflush(stdout); - } + out_wheel_advance(i); } if (compare_regions(bufa, bufb, count)) { return -1; } } - printf("\b \b"); - fflush(stdout); + out_wheel_end(); return 0; } @@ -499,11 +437,10 @@ int test_16bit_wide_random(ulv* bufa, ulv* bufb, size_t count) { u16v *p1, *t; ulv *p2; int attempt; - unsigned int b, j = 0; + unsigned int b; size_t i; - putchar( ' ' ); - fflush( stdout ); + out_wheel_start(); for (attempt = 0; attempt < 2; attempt++) { if (attempt & 1) { p1 = (u16v *) bufa; @@ -518,18 +455,13 @@ int test_16bit_wide_random(ulv* bufa, ulv* bufb, size_t count) { for (b = 0; b < UL_LEN/16; b++) { *p1++ = *t++; } - if (!(i % PROGRESSOFTEN)) { - putchar('\b'); - putchar(progress[++j % PROGRESSLEN]); - fflush(stdout); - } + out_wheel_advance(i); } if (compare_regions(bufa, bufb, count)) { return -1; } } - printf("\b \b"); - fflush(stdout); + out_wheel_end(); return 0; } #endif From 867cc211b68677f8c99239a33096492362f95262 Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Fri, 11 Mar 2022 15:12:56 -0800 Subject: [PATCH 6/7] Support uncached physical addresses Added the option 'u' to request memtester to work on physical addresses but with uncached memory semantices (removing O_SYNC from the open flags). Signed-off-by: Florian Fainelli --- memtester.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/memtester.c b/memtester.c index 44d331e..df6620e 100644 --- a/memtester.c +++ b/memtester.c @@ -102,7 +102,7 @@ off_t physaddrbase = 0; /* Function definitions */ void usage(char *me) { fprintf(stderr, "\n" - "Usage: %s [-p physaddrbase [-d device]] [B|K|M|G] [loops]\n", + "Usage: %s [-p physaddrbase [-d device] [-u]] [B|K|M|G] [loops]\n", me); exit(EXIT_FAIL_NONSTARTER); } @@ -126,6 +126,7 @@ int main(int argc, char **argv) { int device_specified = 0; char *env_testmask = 0; ul testmask = 0; + int o_flags = O_RDWR | O_SYNC; printf("memtester version " __version__ " (%d-bit)\n", UL_LEN); printf("Copyright (C) 2001-2020 Charles Cazabon.\n"); @@ -150,7 +151,7 @@ int main(int argc, char **argv) { printf("using testmask 0x%lx\n", testmask); } - while ((opt = getopt(argc, argv, "p:d:")) != -1) { + while ((opt = getopt(argc, argv, "p:d:u")) != -1) { switch (opt) { case 'p': errno = 0; @@ -193,6 +194,9 @@ int main(int argc, char **argv) { } } break; + case 'u': + o_flags &= ~O_SYNC; + break; default: /* '?' */ usage(argv[0]); /* doesn't return */ } @@ -271,7 +275,7 @@ int main(int argc, char **argv) { buf = NULL; if (use_phys) { - memfd = open(device_name, O_RDWR | O_SYNC); + memfd = open(device_name, o_flags); if (memfd == -1) { fprintf(stderr, "failed to open %s for physical memory: %s\n", device_name, strerror(errno)); From 67494854ca00ae51690ba0be8e109e2f3e8ff144 Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Fri, 11 Mar 2022 15:15:25 -0800 Subject: [PATCH 7/7] Add .gitignore file Ignore objects and binaries built. Signed-off-by: Florian Fainelli --- .gitignore | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..003cb70 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +*.o +auto-ccld.sh +compile +extra-libs +find-systype +load +make-compile +make-load +memtester +systype