Use rng in tests to verify that results arnt just a coincidence

This commit is contained in:
meepingsnesroms
2018-07-20 16:43:22 -07:00
parent 622c079b6b
commit 19971cdad7
2 changed files with 50 additions and 5 deletions

View File

@@ -3,6 +3,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <time.h>
#include "../m68k/m68k.h"
#include "../emulator.h"
@@ -63,6 +64,24 @@ static void logApiCalls(){
}
}
static int64_t randomRange(int64_t start, int64_t end){
static bool seedRng = true;
int64_t result;
if(seedRng){
srand(time(NULL));
seedRng = false;
}
result = rand();
result <<= 32;
result |= rand();
result %= llabs(end - start) + 1;
result += start;
return result;
}
/*
static uint32_t scanForPrivateFunctionAddress(const char* name){
//this is not 100% accurate, it scans memory for a function
@@ -361,14 +380,21 @@ void sandboxTest(uint32_t test){
//since the sandbox can interrupt any running function(including ADC ones) this safeguard is needed
if(ads7846BitsToNextControl == 0){
uint32_t point;
int16_t x;
int16_t y;
int16_t osX;
int16_t osY;
input_t oldInput = palmInput;
palmInput.touchscreenTouched = true;
palmInput.touchscreenX = randomRange(0, 159);
palmInput.touchscreenY = randomRange(0, 219);
//PrvBBGetXY on self dumped ROM
callFunction(false, 0x100827CE, NULL, "v(L)", &point);
x = point >> 16;
y = point & 0xFFFF;
debugLog("Sandbox: Touch position is x:%d, y:%d\n", x, y);
osX = point >> 16;
osY = point & 0xFFFF;
debugLog("Sandbox: Real touch position is x:%d, y:%d\n", palmInput.touchscreenX, palmInput.touchscreenY);
debugLog("Sandbox: OS reported touch position is x:%d, y:%d\n", osX, osY);
palmInput = oldInput;
}
else{
debugLog("Sandbox: Unsafe to read touch position.\n");

19
tests/rngTouchTest.txt Normal file
View File

@@ -0,0 +1,19 @@
Sandbox: Test 1 started(printed 1 times)
SPI2 transfer, ENABLE:true, XCH:true, IRQ:false, IRQEN:false, BITCOUNT:5(printed 1 times)
SPI2 transfer, before:0x001B, after:0x0360, PC:0x1008119E(printed 1 times)
Accessed ADS7846 Ch:5, 8 bits, Diff Mode, Power Save:1, PC:0x10081208.(printed 1 times)
SPI2 transfer, ENABLE:true, XCH:true, IRQ:false, IRQEN:false, BITCOUNT:12(printed 1 times)
SPI2 transfer, before:0x0213, after:0x3059, PC:0x10081208(printed 1 times)
Accessed ADS7846 Ch:1, 8 bits, Diff Mode, Power Save:1, PC:0x10081208.(printed 1 times)
SPI2 transfer, ENABLE:true, XCH:true, IRQ:false, IRQEN:false, BITCOUNT:12(printed 1 times)
SPI2 transfer, before:0x021B, after:0xB017, PC:0x10081208(printed 1 times)
SPI2 transfer, ENABLE:true, XCH:true, IRQ:false, IRQEN:false, BITCOUNT:3(printed 1 times)
SPI2 transfer, before:0x0004, after:0x0020, PC:0x1008124C(printed 1 times)
Sandbox: Real touch position is x:108, y:211(printed 1 times)
Sandbox: OS reported touch position is x:89, y:23(printed 1 times)
Sandbox: Test 1 finished(printed 1 times)
Results:
X Inaccuracy -19
Y Inaccuracy +15(y seems to be inverted)(219 - 211 = 8)(23 - 8 = 15)
This is before the touch calibration screen.