MemTesterNX: A userspace utility for testing memory faults and stability based on [memtester](https://pyropus.ca/software/memtester/)
This commit is contained in:
275
Source/MemTesterNX/source/main.c
Normal file
275
Source/MemTesterNX/source/main.c
Normal file
@@ -0,0 +1,275 @@
|
||||
/*
|
||||
* 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-2020 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.5.1-full"
|
||||
|
||||
// Include the most common headers from the C standard library
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "types.h"
|
||||
#include "sizes.h"
|
||||
#include "tests.h"
|
||||
#include <switch.h>
|
||||
|
||||
PadState pad;
|
||||
unsigned short dividend;
|
||||
|
||||
void waitForAnyKey() {
|
||||
while (appletMainLoop())
|
||||
{
|
||||
padUpdate(&pad);
|
||||
|
||||
u64 kDown = padGetButtonsDown(&pad);
|
||||
|
||||
if (kDown)
|
||||
break;
|
||||
|
||||
consoleUpdate(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void ShowErr(const char* err, const char* details, Result rc) {
|
||||
AppletStorage errStor;
|
||||
LibAppletArgs args;
|
||||
AppletHolder currentApplet;
|
||||
|
||||
appletCreateLibraryApplet(¤tApplet, AppletId_LibraryAppletError, LibAppletMode_AllForeground);
|
||||
libappletArgsCreate(&args, 1);
|
||||
libappletArgsPush(&args, ¤tApplet);
|
||||
appletCreateStorage(&errStor, 0x1018);
|
||||
u8 argBuf[0x1018] = {0};
|
||||
argBuf[0] = 1;
|
||||
|
||||
*(u64*)&argBuf[8] = (((rc & 0x1ffu) + 2000) | (((rc >> 9) & 0x1fff & 0x1fffll) << 32));
|
||||
strcpy((char*) &argBuf[24], err);
|
||||
strcpy((char*) &argBuf[0x818], details);
|
||||
appletStorageWrite(&errStor, 0, argBuf, 0x1018);
|
||||
appletHolderPushInData(¤tApplet, &errStor);
|
||||
|
||||
appletHolderStart(¤tApplet);
|
||||
appletHolderJoin(¤tApplet);
|
||||
appletHolderClose(¤tApplet);
|
||||
appletHolderRequestExit(¤tApplet);
|
||||
}
|
||||
|
||||
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 memtester_pagesize(void) {
|
||||
printf("using pagesize of 4096\n");
|
||||
return 4096;
|
||||
}
|
||||
|
||||
/* Global vars - so tests have access to this information */
|
||||
int use_phys = 0;
|
||||
off_t physaddrbase = 0;
|
||||
|
||||
// Main program entrypoint
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if(appletGetAppletType() != AppletType_Application) {
|
||||
ShowErr("Running in applet mode\nMemTesterNX requires full memory mode.\nPlease launch hbmenu by holding R on an APP (e.g. a game) NOT an applet (e.g. Gallery)", "", 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
appletReportUserIsActive();
|
||||
|
||||
consoleInit(NULL);
|
||||
|
||||
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
|
||||
|
||||
padInitializeDefault(&pad);
|
||||
|
||||
ul loop, i;
|
||||
unsigned short div, maxdiv = 0;
|
||||
size_t pagesize, wantraw, wantbytes[4], wantbytes_orig, bufsize[4], halflen, count;
|
||||
ptrdiff_t pagesizemask;
|
||||
void volatile *buf[4], *aligned[4];
|
||||
ulv *bufa, *bufb;
|
||||
int memshift;
|
||||
ul testmask = 0;
|
||||
ull totalmem = 0;
|
||||
|
||||
printf("MemTesterNX version " __version__ " (%d-bit)\n", UL_LEN);
|
||||
printf("Based on memtester. Copyright (C) 2001-2020 Charles Cazabon.\n");
|
||||
printf("Licensed under the GNU General Public License version 2 (only).\n\n");
|
||||
printf("4.5.1-full supports full RAM test (up to 8GB for devkit).\n");
|
||||
printf("It will looping forever until an error shows up or you manually exit to HOME screen.\n\n");
|
||||
printf("Press A: long test\nPress B: fast test\nPress any other key: exit\n\n");
|
||||
|
||||
while (appletMainLoop())
|
||||
{
|
||||
padUpdate(&pad);
|
||||
|
||||
u64 kDown = padGetButtonsDown(&pad);
|
||||
|
||||
if (kDown & HidNpadButton_A)
|
||||
{
|
||||
dividend = 1;
|
||||
break;
|
||||
}
|
||||
else if (kDown & HidNpadButton_B)
|
||||
{
|
||||
dividend = 4;
|
||||
break;
|
||||
}
|
||||
else if (kDown)
|
||||
{
|
||||
consoleExit(NULL);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
consoleUpdate(NULL);
|
||||
}
|
||||
|
||||
pagesize = memtester_pagesize();
|
||||
pagesizemask = (ptrdiff_t) ~(pagesize - 1);
|
||||
printf("pagesizemask is 0x%tx\n", pagesizemask);
|
||||
consoleUpdate(NULL);
|
||||
|
||||
memshift = 20; /* megabytes */
|
||||
wantraw = 2048;
|
||||
|
||||
wantbytes_orig = ((size_t) wantraw << memshift);
|
||||
|
||||
// Allocate as much RAM as possible.
|
||||
for(div = 0; div <= 3; div++)
|
||||
{
|
||||
|
||||
buf[div] = NULL;
|
||||
wantbytes[div] = wantbytes_orig;
|
||||
|
||||
while (!buf[div] && wantbytes[div]) {
|
||||
buf[div] = (void volatile *) malloc(wantbytes[div]);
|
||||
if (!buf[div])
|
||||
wantbytes[div] -= pagesize;
|
||||
}
|
||||
|
||||
bufsize[div] = wantbytes[div];
|
||||
printf("Alloc %d: got %lluMB (%llu bytes)\n", div+1, (ull) wantbytes[div] >> 20, (ull) wantbytes[div]);
|
||||
consoleUpdate(NULL);
|
||||
|
||||
/* 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[div] % pagesize) {
|
||||
/* printf("aligning to page -- was 0x%tx\n", buf); */
|
||||
aligned[div] = (void volatile *) ((size_t) buf[div] & pagesizemask) + pagesize;
|
||||
/* printf(" now 0x%tx -- lost %d bytes\n", aligned,
|
||||
* (size_t) aligned - (size_t) buf);
|
||||
*/
|
||||
bufsize[div] -= ((size_t) aligned[div] - (size_t) buf[div]);
|
||||
} else {
|
||||
aligned[div] = buf[div];
|
||||
}
|
||||
|
||||
totalmem += wantbytes[div];
|
||||
|
||||
if((wantbytes[div] >> 20) < 2047)
|
||||
{
|
||||
maxdiv = div;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\nTotal RAM allocated: %lldMB\n\n", totalmem >> 20);
|
||||
consoleUpdate(NULL);
|
||||
|
||||
for(loop=1;;loop++)
|
||||
{
|
||||
printf("Loop %lu:\n", loop);
|
||||
|
||||
for(div=0; div<=maxdiv; div++)
|
||||
{
|
||||
printf("Alloc %d:\n", div+1);
|
||||
printf(" %-20s: ", "Stuck Address");
|
||||
consoleUpdate(NULL);
|
||||
|
||||
halflen = bufsize[div] / 2;
|
||||
count = halflen / sizeof(ul);
|
||||
bufa = (ulv *) aligned[div];
|
||||
bufb = (ulv *) ((size_t) aligned[div] + halflen);
|
||||
|
||||
if (!test_stuck_address(aligned[div], bufsize[div] / sizeof(ul))) {
|
||||
printf("ok\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Alloc %d: Error!\nPress any key to exit.\n", div+1);
|
||||
waitForAnyKey();
|
||||
consoleExit(NULL);
|
||||
return 0;
|
||||
}
|
||||
consoleUpdate(NULL);
|
||||
for (i=0;;i++) {
|
||||
if (!tests[i].name) break;
|
||||
/* If using a custom testmask, only run this test if the
|
||||
bit corresponding to this test was set by the user.
|
||||
*/
|
||||
if (testmask && (!((1 << i) & testmask))) {
|
||||
continue;
|
||||
}
|
||||
printf(" %-20s: ", tests[i].name);
|
||||
if (!tests[i].fp(bufa, bufb, count)) {
|
||||
printf("ok\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Alloc %d: Error!\nPress any key to exit.\n", div+1);
|
||||
waitForAnyKey();
|
||||
consoleExit(NULL);
|
||||
return 0;
|
||||
}
|
||||
consoleUpdate(NULL);
|
||||
/* clear buffer */
|
||||
memset((void *) buf[div], 255, wantbytes[div]);
|
||||
}
|
||||
printf("\n");
|
||||
consoleUpdate(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
// Deinitialize and clean up resources used by the console (important!)
|
||||
consoleExit(NULL);
|
||||
return 0;
|
||||
}
|
||||
22
Source/MemTesterNX/source/memtester.h
Executable file
22
Source/MemTesterNX/source/memtester.h
Executable file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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-2020 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 <sys/types.h>
|
||||
|
||||
/* extern declarations. */
|
||||
|
||||
extern int use_phys;
|
||||
extern off_t physaddrbase;
|
||||
|
||||
38
Source/MemTesterNX/source/sizes.h
Executable file
38
Source/MemTesterNX/source/sizes.h
Executable file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#define rand32() ((unsigned int) rand() | ( (unsigned int) rand() << 16))
|
||||
|
||||
#if (ULONG_MAX == 4294967295UL)
|
||||
#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))
|
||||
#elif (ULONG_MAX == 18446744073709551615ULL)
|
||||
#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))
|
||||
#else
|
||||
#error long on this platform is not 32 or 64 bits
|
||||
#endif
|
||||
|
||||
|
||||
513
Source/MemTesterNX/source/tests.c
Executable file
513
Source/MemTesterNX/source/tests.c
Executable file
@@ -0,0 +1,513 @@
|
||||
/*
|
||||
* 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-2020 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 <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "tests.h"
|
||||
#include "types.h"
|
||||
#include "sizes.h"
|
||||
#include "memtester.h"
|
||||
#include <switch.h>
|
||||
|
||||
extern unsigned short dividend;
|
||||
|
||||
char progress[] = "-\\|/";
|
||||
#define PROGRESSLEN 4
|
||||
#define PROGRESSOFTEN 2000000
|
||||
#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) {
|
||||
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));
|
||||
printf("FAILURE: 0x%08lx != 0x%08lx at physical address 0x%08lx.\n", (ul) *p1, (ul) *p2, physaddr);
|
||||
} else {
|
||||
printf("FAILURE: 0x%08lx != 0x%08lx at offset 0x%08lx.\n", (ul) *p1, (ul) *p2, (ul) (i * sizeof(ul)));
|
||||
}
|
||||
consoleUpdate(NULL);
|
||||
/* 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(" ");
|
||||
for (j = 0; j < (16 / dividend) ; j++) {
|
||||
printf("\b\b\b\b\b\b\b\b\b\b\b");
|
||||
p1 = (ulv *) bufa;
|
||||
printf("setting %3u", j);
|
||||
consoleUpdate(NULL);
|
||||
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);
|
||||
consoleUpdate(NULL);
|
||||
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));
|
||||
printf("FAILURE: possible bad address line at physical address 0x%08lx.\n", physaddr);
|
||||
} else {
|
||||
printf("FAILURE: possible bad address line at offset 0x%08lx.\n", (ul) (i * sizeof(ul)));
|
||||
}
|
||||
printf("Skipping to next test...\n");
|
||||
consoleUpdate(NULL);
|
||||
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");
|
||||
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(' ');
|
||||
for (i = 0; i < count; i++) {
|
||||
*p1++ = *p2++ = rand_ul();
|
||||
if (!(i % PROGRESSOFTEN)) {
|
||||
putchar('\b');
|
||||
putchar(progress[++j % PROGRESSLEN]);
|
||||
consoleUpdate(NULL);
|
||||
}
|
||||
}
|
||||
printf("\b \b");
|
||||
consoleUpdate(NULL);
|
||||
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(" ");
|
||||
for (j = 0; j < (64 / dividend / dividend); j++) {
|
||||
printf("\b\b\b\b\b\b\b\b\b\b\b");
|
||||
q = (j % 2) == 0 ? UL_ONEBITS : 0;
|
||||
printf("setting %3u", j);
|
||||
consoleUpdate(NULL);
|
||||
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);
|
||||
consoleUpdate(NULL);
|
||||
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");
|
||||
consoleUpdate(NULL);
|
||||
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(" ");
|
||||
for (j = 0; j < (64 / dividend / dividend); j++) {
|
||||
printf("\b\b\b\b\b\b\b\b\b\b\b");
|
||||
q = (j % 2) == 0 ? CHECKERBOARD1 : CHECKERBOARD2;
|
||||
printf("setting %3u", j);
|
||||
consoleUpdate(NULL);
|
||||
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);
|
||||
consoleUpdate(NULL);
|
||||
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");
|
||||
consoleUpdate(NULL);
|
||||
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(" ");
|
||||
for (j = 0; j < (64 / dividend / dividend) ; j++) {
|
||||
printf("\b\b\b\b\b\b\b\b\b\b\b");
|
||||
p1 = (ulv *) bufa;
|
||||
p2 = (ulv *) bufb;
|
||||
printf("setting %3u", j);
|
||||
consoleUpdate(NULL);
|
||||
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);
|
||||
consoleUpdate(NULL);
|
||||
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");
|
||||
consoleUpdate(NULL);
|
||||
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(" ");
|
||||
for (j = 0; j < (UL_LEN * 2 / dividend / dividend); j++) {
|
||||
printf("\b\b\b\b\b\b\b\b\b\b\b");
|
||||
p1 = (ulv *) bufa;
|
||||
p2 = (ulv *) bufb;
|
||||
printf("setting %3u", j);
|
||||
consoleUpdate(NULL);
|
||||
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);
|
||||
consoleUpdate(NULL);
|
||||
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");
|
||||
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(" ");
|
||||
for (j = 0; j < (UL_LEN * 2 / dividend / dividend); j++) {
|
||||
printf("\b\b\b\b\b\b\b\b\b\b\b");
|
||||
p1 = (ulv *) bufa;
|
||||
p2 = (ulv *) bufb;
|
||||
printf("setting %3u", j);
|
||||
consoleUpdate(NULL);
|
||||
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);
|
||||
consoleUpdate(NULL);
|
||||
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");
|
||||
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(" ");
|
||||
for (j = 0; j < (UL_LEN * 2 / dividend / dividend); j++) {
|
||||
printf("\b\b\b\b\b\b\b\b\b\b\b");
|
||||
p1 = (ulv *) bufa;
|
||||
p2 = (ulv *) bufb;
|
||||
printf("setting %3u", j);
|
||||
consoleUpdate(NULL);
|
||||
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);
|
||||
consoleUpdate(NULL);
|
||||
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");
|
||||
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(" ");
|
||||
for (k = 0; k < (UL_LEN / dividend / dividend); 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);
|
||||
consoleUpdate(NULL);
|
||||
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);
|
||||
consoleUpdate(NULL);
|
||||
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");
|
||||
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;
|
||||
|
||||
putchar(' ');
|
||||
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)) {
|
||||
putchar('\b');
|
||||
putchar(progress[++j % PROGRESSLEN]);
|
||||
consoleUpdate(NULL);
|
||||
}
|
||||
}
|
||||
if (compare_regions(bufa, bufb, count)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
printf("\b \b");
|
||||
consoleUpdate(NULL);
|
||||
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;
|
||||
|
||||
putchar( ' ' );
|
||||
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)) {
|
||||
putchar('\b');
|
||||
putchar(progress[++j % PROGRESSLEN]);
|
||||
consoleUpdate(NULL);
|
||||
}
|
||||
}
|
||||
if (compare_regions(bufa, bufb, count)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
printf("\b \b");
|
||||
consoleUpdate(NULL);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
39
Source/MemTesterNX/source/tests.h
Executable file
39
Source/MemTesterNX/source/tests.h
Executable file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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-2020 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(unsigned long volatile *bufa, size_t count);
|
||||
int test_random_value(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
|
||||
int test_xor_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
|
||||
int test_sub_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
|
||||
int test_mul_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
|
||||
int test_div_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
|
||||
int test_or_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
|
||||
int test_and_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
|
||||
int test_seqinc_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
|
||||
int test_solidbits_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
|
||||
int test_checkerboard_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
|
||||
int test_blockseq_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
|
||||
int test_walkbits0_comparison(unsigned long volatile *bufa, unsigned long volatile *bufb, size_t count);
|
||||
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
|
||||
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
|
||||
|
||||
26
Source/MemTesterNX/source/types.h
Executable file
26
Source/MemTesterNX/source/types.h
Executable file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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-2020 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sizes.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)();
|
||||
};
|
||||
Reference in New Issue
Block a user