Remove Source/{Unittests,TestSuite}.

These directories have been unused for several years and without any automated
way of running the tests, they are pretty much useless.

While they might be useful as a reference, in their present state they should
not be kept in the repository.
This commit is contained in:
Pierre Bourdon
2014-02-23 16:21:01 +01:00
parent 4a569c4449
commit 0f89060cf3
61 changed files with 2 additions and 6021 deletions

View File

@ -1,348 +0,0 @@
#include "DSPJitTester.h"
void nx_dr()
{
DSPJitTester tester(0x8000, 0x0004);
tester.AddTestData(DSP_REG_AR0);
tester.AddTestData(DSP_REG_WR0);
tester.TestAll();
tester.Report();
}
void nx_ir()
{
DSPJitTester tester(0x8000, 0x0008);
tester.AddTestData(DSP_REG_AR0);
tester.AddTestData(DSP_REG_WR0);
tester.TestAll();
tester.Report();
}
void nx_nr()
{
DSPJitTester tester(0x8000, 0x000c);
tester.AddTestData(DSP_REG_AR0);
tester.AddTestData(DSP_REG_WR0);
tester.AddTestData(DSP_REG_IX0);
tester.TestAll(true);
tester.Report();
}
void nx_mv()
{
DSPJitTester tester(0x8000, 0x0010);
tester.AddTestData(DSP_REG_ACL0);
tester.AddTestData(DSP_REG_AXL0);
tester.TestAll(true);
tester.Report();
}
void dar()
{
DSPJitTester tester(0x0004);
tester.AddTestData(DSP_REG_AR0);
tester.AddTestData(DSP_REG_WR0);
tester.TestAll();
tester.Report();
}
void iar()
{
DSPJitTester tester(0x0008);
tester.AddTestData(DSP_REG_AR0);
tester.AddTestData(DSP_REG_WR0);
tester.TestAll();
tester.Report();
}
void subarn()
{
DSPJitTester tester(0x000c);
tester.AddTestData(DSP_REG_AR0);
tester.AddTestData(DSP_REG_WR0);
tester.AddTestData(DSP_REG_IX0);
tester.TestAll();
tester.Report();
}
void addarn()
{
DSPJitTester tester(0x0010);
tester.AddTestData(DSP_REG_AR0);
tester.AddTestData(DSP_REG_WR0);
tester.AddTestData(DSP_REG_IX0);
tester.TestAll();
tester.Report();
}
void sbclr()
{
DSPJitTester tester(0x1200);
tester.AddTestData(DSP_REG_SR);
tester.TestAll();
tester.Report();
}
void sbset()
{
DSPJitTester tester(0x1300);
tester.AddTestData(DSP_REG_SR);
tester.TestAll();
tester.Report();
}
void nx_s()
{
DSPJitTester tester(0x8000, 0x0020);
tester.AddTestData(DSP_REG_AR0);
tester.AddTestData(DSP_REG_WR0);
tester.AddTestData(DSP_REG_ACL0);
tester.TestAll(true);
tester.Report();
}
void nx_sn()
{
DSPJitTester tester(0x8000, 0x0024);
tester.AddTestData(DSP_REG_AR0);
tester.AddTestData(DSP_REG_WR0);
tester.AddTestData(DSP_REG_IX0);
tester.AddTestData(DSP_REG_ACL0);
tester.TestAll(true);
tester.Report();
}
void nx_l()
{
DSPJitTester tester(0x8000, 0x0040);
tester.AddTestData(DSP_REG_AR0);
tester.AddTestData(DSP_REG_WR0);
tester.AddTestData(DSP_REG_AXL0);
tester.TestAll(true);
tester.Report();
}
void set16_l()
{
DSPJitTester tester(0x8e00, 0x0070);
tester.AddTestData(DSP_REG_SR, 0);
tester.AddTestData(DSP_REG_SR, SR_40_MODE_BIT);
tester.AddTestData(DSP_REG_AR0);
tester.AddTestData(DSP_REG_WR0);
tester.AddTestData(DSP_REG_ACM0);
tester.TestAll(true);
tester.Report();
}
void nx_ln()
{
DSPJitTester tester(0x8000, 0x0044);
tester.AddTestData(DSP_REG_AR0);
tester.AddTestData(DSP_REG_WR0);
tester.AddTestData(DSP_REG_IX0);
tester.AddTestData(DSP_REG_AXL0);
tester.TestAll(true);
tester.Report();
}
void nx_ls()
{
DSPJitTester tester1(0x8000, 0x0080);
tester1.AddTestData(DSP_REG_ACM0);
tester1.AddTestData(DSP_REG_AR0);
tester1.AddTestData(DSP_REG_WR0);
tester1.TestAll(true);
tester1.Report();
DSPJitTester tester2(0x8000, 0x0080);
tester2.AddTestData(DSP_REG_ACM0);
tester2.AddTestData(DSP_REG_AR3);
tester2.AddTestData(DSP_REG_WR3);
tester2.TestAll(true);
tester2.Report();
}
void nx_lsn()
{
DSPJitTester tester1(0x8000, 0x0084);
tester1.AddTestData(DSP_REG_ACM0);
tester1.AddTestData(DSP_REG_AR0);
tester1.AddTestData(DSP_REG_WR0);
tester1.AddTestData(DSP_REG_IX0);
tester1.TestAll(true);
tester1.Report();
DSPJitTester tester2(0x8000, 0x0084);
tester2.AddTestData(DSP_REG_ACM0);
tester2.AddTestData(DSP_REG_AR3);
tester2.AddTestData(DSP_REG_WR3);
tester2.TestAll(true);
tester2.Report();
}
void nx_lsm()
{
DSPJitTester tester1(0x8000, 0x0088);
tester1.AddTestData(DSP_REG_ACM0);
tester1.AddTestData(DSP_REG_AR0);
tester1.AddTestData(DSP_REG_WR0);
tester1.TestAll(true);
tester1.Report();
DSPJitTester tester2(0x8000, 0x0088);
tester2.AddTestData(DSP_REG_ACM0);
tester2.AddTestData(DSP_REG_AR3);
tester2.AddTestData(DSP_REG_WR3);
tester2.AddTestData(DSP_REG_IX3);
tester2.TestAll(true);
tester2.Report();
}
void nx_lsnm()
{
DSPJitTester tester1(0x8000, 0x008c);
tester1.AddTestData(DSP_REG_ACM0);
tester1.AddTestData(DSP_REG_AR0);
tester1.AddTestData(DSP_REG_WR0);
tester1.AddTestData(DSP_REG_IX0);
tester1.TestAll(true);
tester1.Report();
DSPJitTester tester2(0x8000, 0x008c);
tester2.AddTestData(DSP_REG_ACM0);
tester2.AddTestData(DSP_REG_AR3);
tester2.AddTestData(DSP_REG_WR3);
tester2.AddTestData(DSP_REG_IX3);
tester2.TestAll(true);
tester2.Report();
}
void nx_sl()
{
DSPJitTester tester1(0x8000, 0x0082);
tester1.AddTestData(DSP_REG_ACM0);
tester1.AddTestData(DSP_REG_AR0);
tester1.AddTestData(DSP_REG_WR0);
tester1.TestAll(true);
tester1.Report();
DSPJitTester tester2(0x8000, 0x0082);
tester2.AddTestData(DSP_REG_ACM0);
tester2.AddTestData(DSP_REG_AR3);
tester2.AddTestData(DSP_REG_WR3);
tester2.TestAll(true);
tester2.Report();
}
void nx_sln()
{
DSPJitTester tester1(0x8000, 0x0086);
tester1.AddTestData(DSP_REG_ACM0);
tester1.AddTestData(DSP_REG_AR0);
tester1.AddTestData(DSP_REG_WR0);
tester1.AddTestData(DSP_REG_IX0);
tester1.TestAll(true);
tester1.Report();
DSPJitTester tester2(0x8000, 0x0086);
tester2.AddTestData(DSP_REG_ACM0);
tester2.AddTestData(DSP_REG_AR3);
tester2.AddTestData(DSP_REG_WR3);
tester2.TestAll(true);
tester2.Report();
}
void nx_slm()
{
DSPJitTester tester1(0x8000, 0x008a);
tester1.AddTestData(DSP_REG_ACM0);
tester1.AddTestData(DSP_REG_AR0);
tester1.AddTestData(DSP_REG_WR0);
tester1.TestAll(true);
tester1.Report();
DSPJitTester tester2(0x8000, 0x008a);
tester2.AddTestData(DSP_REG_ACM0);
tester2.AddTestData(DSP_REG_AR3);
tester2.AddTestData(DSP_REG_WR3);
tester2.AddTestData(DSP_REG_IX3);
tester2.TestAll(true);
tester2.Report();
}
void nx_slnm()
{
DSPJitTester tester1(0x8000, 0x008e);
tester1.AddTestData(DSP_REG_ACM0);
tester1.AddTestData(DSP_REG_AR0);
tester1.AddTestData(DSP_REG_WR0);
tester1.AddTestData(DSP_REG_IX0);
tester1.TestAll(true);
tester1.Report();
DSPJitTester tester2(0x8000, 0x008e);
tester2.AddTestData(DSP_REG_ACM0);
tester2.AddTestData(DSP_REG_AR3);
tester2.AddTestData(DSP_REG_WR3);
tester2.AddTestData(DSP_REG_IX3);
tester2.TestAll(true);
tester2.Report();
}
void nx_ld()
{
DSPJitTester tester1(0x8000, 0x00c0);
tester1.AddTestData(DSP_REG_AXL0,0xdead);
tester1.AddTestData(DSP_REG_AXL1,0xbeef);
tester1.AddTestData(DSP_REG_AR0);
tester1.AddTestData(DSP_REG_WR0);
tester1.AddTestData(DSP_REG_IX0);
tester1.TestAll(true);
tester1.Report();
DSPJitTester tester2(0x8000, 0x00c0);
tester2.AddTestData(DSP_REG_AXL0,0xdead);
tester2.AddTestData(DSP_REG_AXL1,0xbeef);
tester2.AddTestData(DSP_REG_AR3);
tester2.AddTestData(DSP_REG_WR3);
tester2.AddTestData(DSP_REG_IX3);
tester2.TestAll(true);
tester2.Report();
}
void AudioJitTests()
{
DSPJitTester::Initialize();
dar();
iar();
subarn();
addarn();
sbclr();
sbset();
nx_ir();
nx_dr();
nx_nr();
nx_mv();
set16_l();
nx_s();
nx_sn();
nx_l();
nx_ln();
nx_ls();
nx_lsn();
nx_lsm();
nx_lsnm();
nx_sl();
nx_sln();
nx_slm();
nx_slnm();
nx_ld();
}
//required to be able to link against DSPCore
void DSPHost_UpdateDebugger() { }
void DSPHost_CodeLoaded(unsigned const char*, int) { }
void DSPHost_InterruptRequest() { }
bool DSPHost_OnThread() { return false; }
void DSPHost_WriteHostMemory(unsigned char, unsigned int) { }
unsigned char DSPHost_ReadHostMemory(unsigned int) { return 0; }

View File

@ -1,6 +0,0 @@
set(SRCS AudioJitTests.cpp
DSPJitTester.cpp
UnitTests.cpp)
add_executable(tester ${SRCS})
target_link_libraries(tester core)

View File

@ -1,310 +0,0 @@
#include "DSPJitTester.h"
DSPJitTester::DSPJitTester(u16 opcode, u16 opcode_ext, bool verbose, bool only_failed)
: be_verbose(verbose), failed_only(only_failed), run_count(0), fail_count(0)
{
instruction = opcode | opcode_ext;
opcode_template = GetOpTemplate(instruction);
sprintf(instruction_name, "%s", opcode_template->name);
if (opcode_template->extended)
sprintf(&instruction_name[strlen(instruction_name)], "'%s",
extOpTable[instruction & (((instruction >> 12) == 0x3) ? 0x7F : 0xFF)]->name);
}
bool DSPJitTester::Test(SDSP dsp_settings)
{
if (be_verbose && !failed_only)
{
printf("Running %s: ", instruction_name);
DumpRegs(dsp_settings);
}
last_input_dsp = dsp_settings;
last_int_dsp = RunInterpreter(dsp_settings);
last_jit_dsp = RunJit(dsp_settings);
run_count++;
bool success = AreEqual(last_int_dsp, last_jit_dsp);
if (!success)
fail_count++;
return success;
}
SDSP DSPJitTester::RunInterpreter(SDSP dsp_settings)
{
ResetInterpreter();
memcpy(&g_dsp, &dsp_settings, sizeof(SDSP));
ExecuteInstruction(instruction);
return g_dsp;
}
SDSP DSPJitTester::RunJit(SDSP dsp_settings)
{
ResetJit();
memcpy(&g_dsp, &dsp_settings, sizeof(SDSP));
const u8* code = jit.GetCodePtr();
jit.ABI_PushAllCalleeSavedRegsAndAdjustStack();
jit.EmitInstruction(instruction);
jit.ABI_PopAllCalleeSavedRegsAndAdjustStack();
jit.RET();
((void(*)())code)();
return g_dsp;
}
void DSPJitTester::ResetInterpreter()
{
for (int i=0; i < WRITEBACKLOGSIZE; i++)
writeBackLogIdx[i] = -1;
}
void DSPJitTester::ResetJit()
{
jit.ClearCodeSpace();
}
static u16 GetRegister(SDSP const &dsp, int reg) {
switch(reg) {
case DSP_REG_AR0:
case DSP_REG_AR1:
case DSP_REG_AR2:
case DSP_REG_AR3:
return dsp.r.ar[reg - DSP_REG_AR0];
case DSP_REG_IX0:
case DSP_REG_IX1:
case DSP_REG_IX2:
case DSP_REG_IX3:
return dsp.r.ix[reg - DSP_REG_IX0];
case DSP_REG_WR0:
case DSP_REG_WR1:
case DSP_REG_WR2:
case DSP_REG_WR3:
return dsp.r.wr[reg - DSP_REG_WR0];
case DSP_REG_ST0:
case DSP_REG_ST1:
case DSP_REG_ST2:
case DSP_REG_ST3:
return dsp.r.st[reg - DSP_REG_ST0];
case DSP_REG_ACH0:
case DSP_REG_ACH1:
return dsp.r.ac[reg - DSP_REG_ACH0].h;
case DSP_REG_CR: return dsp.r.cr;
case DSP_REG_SR: return dsp.r.sr;
case DSP_REG_PRODL: return dsp.r.prod.l;
case DSP_REG_PRODM: return dsp.r.prod.m;
case DSP_REG_PRODH: return dsp.r.prod.h;
case DSP_REG_PRODM2: return dsp.r.prod.m2;
case DSP_REG_AXL0:
case DSP_REG_AXL1:
return dsp.r.ax[reg - DSP_REG_AXL0].l;
case DSP_REG_AXH0:
case DSP_REG_AXH1:
return dsp.r.ax[reg - DSP_REG_AXH0].h;
case DSP_REG_ACL0:
case DSP_REG_ACL1:
return dsp.r.ac[reg - DSP_REG_ACL0].l;
case DSP_REG_ACM0:
case DSP_REG_ACM1:
return dsp.r.ac[reg - DSP_REG_ACM0].m;
default:
_assert_msg_(DSP_CORE, 0, "cannot happen");
return 0;
}
}
static void SetRegister(SDSP &dsp, int reg, u16 val) {
switch(reg) {
case DSP_REG_AR0:
case DSP_REG_AR1:
case DSP_REG_AR2:
case DSP_REG_AR3:
dsp.r.ar[reg - DSP_REG_AR0] = val; break;
case DSP_REG_IX0:
case DSP_REG_IX1:
case DSP_REG_IX2:
case DSP_REG_IX3:
dsp.r.ix[reg - DSP_REG_IX0] = val; break;
case DSP_REG_WR0:
case DSP_REG_WR1:
case DSP_REG_WR2:
case DSP_REG_WR3:
dsp.r.wr[reg - DSP_REG_WR0] = val; break;
case DSP_REG_ST0:
case DSP_REG_ST1:
case DSP_REG_ST2:
case DSP_REG_ST3:
dsp.r.st[reg - DSP_REG_ST0] = val; break;
case DSP_REG_ACH0:
case DSP_REG_ACH1:
dsp.r.ac[reg - DSP_REG_ACH0].h = val; break;
case DSP_REG_CR: dsp.r.cr = val; break;
case DSP_REG_SR: dsp.r.sr = val; break;
case DSP_REG_PRODL: dsp.r.prod.l = val; break;
case DSP_REG_PRODM: dsp.r.prod.m = val; break;
case DSP_REG_PRODH: dsp.r.prod.h = val; break;
case DSP_REG_PRODM2: dsp.r.prod.m2 = val; break;
case DSP_REG_AXL0:
case DSP_REG_AXL1:
dsp.r.ax[reg - DSP_REG_AXL0].l = val; break;
case DSP_REG_AXH0:
case DSP_REG_AXH1:
dsp.r.ax[reg - DSP_REG_AXH0].h = val; break;
case DSP_REG_ACL0:
case DSP_REG_ACL1:
dsp.r.ac[reg - DSP_REG_ACL0].l = val; break;
case DSP_REG_ACM0:
case DSP_REG_ACM1:
dsp.r.ac[reg - DSP_REG_ACM0].m = val; break;
default:
_assert_msg_(DSP_CORE, 0, "cannot happen");
}
}
bool DSPJitTester::AreEqual(SDSP& int_dsp, SDSP& jit_dsp)
{
bool equal = true;
for (int i = 0; i < DSP_REG_NUM; i++)
{
if (GetRegister(int_dsp,i) != GetRegister(jit_dsp, i))
{
if (equal)
{
if (failed_only)
{
printf("%s ", instruction_name);
DumpRegs(last_input_dsp);
}
if (be_verbose || failed_only)
printf("failed\n");
}
equal = false;
if (be_verbose || failed_only)
printf("\t%s: int = 0x%04x, jit = 0x%04x\n", regnames[i].name, GetRegister(int_dsp,i), GetRegister(jit_dsp, i));
}
}
//TODO: more sophisticated checks?
if (!int_dsp.iram || !jit_dsp.iram)
{
if (be_verbose)
printf("(IRAM null)");
}
else if (memcmp(int_dsp.iram, jit_dsp.iram, DSP_IRAM_BYTE_SIZE))
{
printf("\tIRAM: different\n");
equal = false;
}
if (!int_dsp.dram || !jit_dsp.dram)
{
if (be_verbose)
printf("(DRAM null)");
}
else if (memcmp(int_dsp.dram, jit_dsp.dram, DSP_DRAM_BYTE_SIZE))
{
printf("\tDRAM: different\n");
equal = false;
}
if (equal && be_verbose && !failed_only)
printf("passed\n");
return equal;
}
void DSPJitTester::Report()
{
printf("%s (0x%04x): Ran %d times, Failed %d times.\n", instruction_name, instruction, run_count, fail_count);
}
void DSPJitTester::DumpJittedCode()
{
ResetJit();
const u8* code = jit.GetCodePtr();
jit.EmitInstruction(instruction);
size_t code_size = jit.GetCodePtr() - code;
printf("%s emitted: ", instruction_name);
for (size_t i = 0; i < code_size; i++)
printf("%02x ", code[i]);
printf("\n");
}
void DSPJitTester::DumpRegs(SDSP& dsp)
{
for (int i = 0; i < DSP_REG_NUM; i++)
if (GetRegister(dsp,i))
printf("%s=0x%04x ", regnames[i].name, GetRegister(dsp,i));
}
void DSPJitTester::Initialize()
{
//init int
InitInstructionTable();
}
int DSPJitTester::TestOne(TestDataIterator it, SDSP& dsp)
{
int failed = 0;
if (it != test_values.end())
{
u8 reg = it->first;
TestData& data = it->second;
it++;
for (TestData::size_type i = 0; i < data.size(); i++)
{
SetRegister(dsp, reg, data.at(i));
failed += TestOne(it, dsp);
}
}
else
{
if (!Test(dsp))
failed++;
}
return failed;
}
int DSPJitTester::TestAll(bool verbose_fail)
{
int failed = 0;
SDSP dsp;
memset(&dsp, 0, sizeof(SDSP));
//from DSPCore_Init
dsp.irom = (u16*)AllocateMemoryPages(DSP_IROM_BYTE_SIZE);
dsp.iram = (u16*)AllocateMemoryPages(DSP_IRAM_BYTE_SIZE);
dsp.dram = (u16*)AllocateMemoryPages(DSP_DRAM_BYTE_SIZE);
dsp.coef = (u16*)AllocateMemoryPages(DSP_COEF_BYTE_SIZE);
// Fill roms with distinct patterns.
for (int i = 0; i < DSP_IROM_SIZE; i++)
dsp.irom[i] = (i & 0x3fff) | 0x4000;
for (int i = 0; i < DSP_COEF_SIZE; i++)
dsp.coef[i] = (i & 0x3fff) | 0x8000;
for (int i = 0; i < DSP_DRAM_SIZE; i++)
dsp.dram[i] = (i & 0x3fff) | 0xc000;
// Fill IRAM with HALT opcodes.
for (int i = 0; i < DSP_IRAM_SIZE; i++)
dsp.iram[i] = 0x0021; // HALT opcode
bool verbose = failed_only;
failed_only = verbose_fail;
failed += TestOne(test_values.begin(), dsp);
failed_only = verbose;
FreeMemoryPages(dsp.irom, DSP_IROM_BYTE_SIZE);
FreeMemoryPages(dsp.iram, DSP_IRAM_BYTE_SIZE);
FreeMemoryPages(dsp.dram, DSP_DRAM_BYTE_SIZE);
FreeMemoryPages(dsp.coef, DSP_COEF_BYTE_SIZE);
return failed;
}
void DSPJitTester::AddTestData(u8 reg)
{
AddTestData(reg, 0);
AddTestData(reg, 1);
AddTestData(reg, 0x1fff);
AddTestData(reg, 0x2000);
AddTestData(reg, 0x2001);
AddTestData(reg, 0x7fff);
AddTestData(reg, 0x8000);
AddTestData(reg, 0x8001);
AddTestData(reg, 0xfffe);
AddTestData(reg, 0xffff);
}
void DSPJitTester::AddTestData(u8 reg, u16 value)
{
if (reg < DSP_REG_NUM)
test_values[reg].push_back(value);
}

View File

@ -1,115 +0,0 @@
// How to use the DSPJitTester:
//
// == Before running ==
// Make sure to call Initialize to set initial stuff required by int and jit:
// DSPJitTester::Initialize();
//
// == Creation of a testcase ==
// Create a testcase for a normal operation:
// DSPJitTester tester(0x0004); //taken from DSPTables.cpp, opcodes[]
//
// Create a testcase for an extended operation:
// DSPJitTester tester(0x8000, 0x0004); //NX from opcodes, DR from opcodes_ext
//
// By default, no messages are written.
// To log all operations, set verbose to true:
// DSPJitTester tester(0x8000, 0x0004, true);
//
// You can also choose to only print failing tests:
// DSPJitTester tester(0x8000, 0x0004, verbosity_setting, true);
// verbose = true will give the same output as verbose,
// while verbose = false will only (really!) print failing tests.
//
// == Setting up values ==
// You can set the tester up with values for each DSP register:
// tester.AddTestData(DSP_REG_ACC0, 1);
// tester.AddTestData(DSP_REG_ACC0, 2);
// tester.AddTestData(DSP_REG_ACC0, 3);
//
// You can also choose to have a few predefined values added for a register:
// tester.AddTestData(DSP_REG_ACC0); //see the method body for the values added
//
// == Running the tests ==
// After setup, you can either run JIT against the interpreter
// using all predefined register values, pass your own set of
// registers or run either of the two independently from each other.
//
// int failed_tests = tester.TestAll(); //run jit against int, using values from AddTestData
// int failed_tests = tester.TestAll(true); //override the value for only_failed to show failure
//
// SDSP dsp = GetCustomSetOfRegisters();
// bool success = tester.Test(dsp); //run jit against int, using a custom set of register values
//
// SDSP result = tester.RunInterpreter(dsp); //run int alone
// SDSP result = tester.RunJit(dsp); //run jit alone
//
// == Examining results ==
// When either verbose or only_failed is set to true, the tester will automatically report
// failure to stdout, along with input registers and the differences in output registers.
//
// tester.Report(); //display a small report afterwards
//
// SDSP int = tester.GetLastInterpreterDSP(); //examine the DSP set left after running int
// SDSP jit = tester.GetLastJitDSP(); //same for jit
//
// int tests_run = tester.GetRunCount();
// int tests_failed = tester.GetFailCount();
// const char* tested_instruction = tester.GetInstructionName();
// printf("%s ran %d tests and failed %d times\n", tested_instruction, tests_run, tests_failed);
//
// tester.DumpJittedCode(); //prints the code bytes produced by jit (examine with udcli/udis86 or similar)
#ifndef __DSP_JIT_TESTER_
#define __DSP_JIT_TESTER_
#include "DSP/DSPCore.h"
#include "DSP/DSPInterpreter.h"
#include <map>
#include <vector>
typedef std::vector<u16> TestData;
typedef std::map<u8, TestData> TestDataList;
typedef TestDataList::iterator TestDataIterator;
#define DSP_REG_NUM 32
class DSPJitTester
{
UDSPInstruction instruction;
const DSPOPCTemplate *opcode_template;
DSPEmitter jit;
SDSP last_int_dsp;
SDSP last_jit_dsp;
SDSP last_input_dsp;
bool be_verbose;
bool failed_only;
int run_count;
int fail_count;
char instruction_name[16];
TestDataList test_values;
bool AreEqual(SDSP&, SDSP&);
int TestOne(TestDataIterator, SDSP&);
void DumpRegs(SDSP&);
public:
DSPJitTester(u16 opcode, u16 opcode_ext = 0, bool verbose = false, bool only_failed = false);
bool Test(SDSP);
int TestAll() { return TestAll(failed_only); }
int TestAll(bool verbose_fail);
void AddTestData(u8 reg);
void AddTestData(u8 reg, u16 value);
SDSP RunInterpreter(SDSP);
SDSP RunJit(SDSP);
void ResetInterpreter();
void ResetJit();
inline SDSP GetLastInterpreterDSP() { return last_int_dsp; }
inline SDSP GetLastJitDSP() { return last_jit_dsp; }
inline int GetRunCount() { return run_count; }
inline int GetFailCount() { return fail_count; }
inline const char* GetInstructionName() { return instruction_name; }
void Report();
void DumpJittedCode();
static void Initialize();
};
#endif

View File

@ -1,145 +0,0 @@
// Copyright (C) 2003 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include <cmath>
#include <iostream>
#include "StringUtil.h"
#include "MathUtil.h"
#include "PowerPC/PowerPC.h"
#include "HW/SI_DeviceGCController.h"
void AudioJitTests();
using namespace std;
int fail_count = 0;
#define EXPECT_TRUE(a) \
if (!a) { \
cout << "FAIL (" << __FUNCTION__ << "): " << #a << " is false" << endl; \
cout << "Value: " << a << endl << "Expected: true" << endl; \
fail_count++; \
}
#define EXPECT_FALSE(a) \
if (a) { \
cout << "FAIL (" << __FUNCTION__ << "): " << #a << " is true" << endl; \
cout << "Value: " << a << endl << "Expected: false" << endl; \
fail_count++; \
}
#define EXPECT_EQ(a, b) \
if ((a) != (b)) { \
cout << "FAIL (" << __FUNCTION__ << "): " << #a << " is not equal to " << #b << endl; \
cout << "Actual: " << a << endl << "Expected: " << b << endl; \
fail_count++; \
}
void CoreTests()
{
}
void MathTests()
{
// Tests that our fp classifier is correct.
EXPECT_EQ(MathUtil::ClassifyDouble(1.0), MathUtil::PPC_FPCLASS_PN);
EXPECT_EQ(MathUtil::ClassifyDouble(-1.0), MathUtil::PPC_FPCLASS_NN);
EXPECT_EQ(MathUtil::ClassifyDouble(1235223.0), MathUtil::PPC_FPCLASS_PN);
EXPECT_EQ(MathUtil::ClassifyDouble(-1263221.0), MathUtil::PPC_FPCLASS_NN);
EXPECT_EQ(MathUtil::ClassifyDouble(1.0E-308), MathUtil::PPC_FPCLASS_PD);
EXPECT_EQ(MathUtil::ClassifyDouble(-1.0E-308), MathUtil::PPC_FPCLASS_ND);
EXPECT_EQ(MathUtil::ClassifyDouble(0.0), MathUtil::PPC_FPCLASS_PZ);
EXPECT_EQ(MathUtil::ClassifyDouble(-0.0), MathUtil::PPC_FPCLASS_NZ);
EXPECT_EQ(MathUtil::ClassifyDouble(HUGE_VAL), MathUtil::PPC_FPCLASS_PINF); // weird #define for infinity
EXPECT_EQ(MathUtil::ClassifyDouble(-HUGE_VAL), MathUtil::PPC_FPCLASS_NINF);
EXPECT_EQ(MathUtil::ClassifyDouble(sqrt(-1.0)), MathUtil::PPC_FPCLASS_QNAN);
// Float version
EXPECT_EQ(MathUtil::ClassifyFloat(1.0f), MathUtil::PPC_FPCLASS_PN);
EXPECT_EQ(MathUtil::ClassifyFloat(-1.0f), MathUtil::PPC_FPCLASS_NN);
EXPECT_EQ(MathUtil::ClassifyFloat(1235223.0f), MathUtil::PPC_FPCLASS_PN);
EXPECT_EQ(MathUtil::ClassifyFloat(-1263221.0f), MathUtil::PPC_FPCLASS_NN);
EXPECT_EQ(MathUtil::ClassifyFloat(1.0E-43f), MathUtil::PPC_FPCLASS_PD);
EXPECT_EQ(MathUtil::ClassifyFloat(-1.0E-43f), MathUtil::PPC_FPCLASS_ND);
EXPECT_EQ(MathUtil::ClassifyFloat(0.0f), MathUtil::PPC_FPCLASS_PZ);
EXPECT_EQ(MathUtil::ClassifyFloat(-0.0f), MathUtil::PPC_FPCLASS_NZ);
EXPECT_EQ(MathUtil::ClassifyFloat((float)HUGE_VAL), MathUtil::PPC_FPCLASS_PINF); // weird #define for infinity
EXPECT_EQ(MathUtil::ClassifyFloat((float)-HUGE_VAL), MathUtil::PPC_FPCLASS_NINF);
EXPECT_EQ(MathUtil::ClassifyFloat(sqrtf(-1.0f)), MathUtil::PPC_FPCLASS_QNAN);
EXPECT_FALSE(MathUtil::IsNAN(1.0));
EXPECT_TRUE(MathUtil::IsNAN(sqrt(-1.0)));
EXPECT_FALSE(MathUtil::IsSNAN(sqrt(-1.0)));
// EXPECT_TRUE(MathUtil::IsQNAN(sqrt(-1.0))); // Hmm...
EXPECT_EQ(pow2(2.0), 4.0);
EXPECT_EQ(pow2(-2.0), 4.0);
}
void StringTests()
{
EXPECT_EQ(StripSpaces(" abc "), "abc");
EXPECT_EQ(StripQuotes("\"abc\""), "abc");
EXPECT_EQ(StripQuotes("\"abc\" "), "\"abc\" ");
EXPECT_EQ(TabsToSpaces(4, "a\tb"), "a b");
EXPECT_EQ(ThousandSeparate(1234567, 15), " 1,234,567");
int i = 7;
EXPECT_EQ(false, TryParse("FF", &i));
EXPECT_EQ(7, i);
EXPECT_EQ(true, TryParse("22", &i));
EXPECT_EQ(22, i);
std::vector<std::string> strs;
SplitString("blah,foo,bar", ',', strs);
EXPECT_EQ(3, strs.size());
EXPECT_EQ("bar", strs[2]);
std::string path, fname, ext;
SplitPath("C:/some/path/test.jpg", &path, &fname, &ext);
EXPECT_EQ("C:/some/path/", path);
EXPECT_EQ("test", fname);
EXPECT_EQ(".jpg", ext);
SplitPath("C:/so.me/path/", &path, &fname, &ext);
EXPECT_EQ("C:/so.me/path/", path);
EXPECT_EQ("", fname);
EXPECT_EQ("", ext);
SplitPath("test.file.jpg", &path, &fname, &ext);
EXPECT_EQ("", path);
EXPECT_EQ("test.file", fname);
EXPECT_EQ(".jpg", ext);
}
int main(int argc, char* argv[])
{
AudioJitTests();
CoreTests();
MathTests();
StringTests();
if (fail_count == 0)
{
printf("All tests passed.\n");
}
return 0;
}

View File

@ -1,217 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{40C636FA-B5BF-4D67-ABC8-376B524A7551}</ProjectGuid>
<RootNamespace>UnitTests</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>false</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Platform)\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
<PostBuildEventUseInBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</PostBuildEventUseInBuild>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>
<PostBuildEventUseInBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</PostBuildEventUseInBuild>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Platform)\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<PostBuildEventUseInBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</PostBuildEventUseInBuild>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
<PostBuildEventUseInBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</PostBuildEventUseInBuild>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>../Core/Core;../Core/Common;../Core/InputCommon;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalDependencies>Iphlpapi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
</Link>
<PostBuildEvent>
<Command>xcopy "$(TargetPath)" "$(SolutionDir)..\Binary\$(Platform)\" /e /s /y /d</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>../Core/Core;../Core/Common;../Core/InputCommon;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalDependencies>Iphlpapi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX64</TargetMachine>
</Link>
<PostBuildEvent>
<Command>xcopy "$(TargetPath)" "$(SolutionDir)..\Binary\$(Platform)\" /e /s /y /d</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>../Core/Core;../Core/Common;../Core/InputCommon;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalDependencies>Iphlpapi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX86</TargetMachine>
</Link>
<PostBuildEvent>
<Command>xcopy "$(TargetPath)" "$(SolutionDir)..\Binary\$(Platform)\" /e /s /y /d</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<AdditionalOptions>/MP %(AdditionalOptions)</AdditionalOptions>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>../Core/Core;../Core/Common;../Core/InputCommon;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<AdditionalDependencies>Iphlpapi.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX64</TargetMachine>
</Link>
<PostBuildEvent>
<Command>xcopy "$(TargetPath)" "$(SolutionDir)..\Binary\$(Platform)\" /e /s /y /d</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="AudioJitTests.cpp" />
<ClCompile Include="DSPJitTester.cpp" />
<ClCompile Include="UnitTests.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="DSPJitTester.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Externals\Bochs_disasm\Bochs_disasm.vcxproj">
<Project>{cd3d4c3c-1027-4d33-b047-aec7b56d0bf6}</Project>
</ProjectReference>
<ProjectReference Include="..\Core\Common\Common.vcxproj">
<Project>{c87a4178-44f6-49b2-b7aa-c79af1b8c534}</Project>
</ProjectReference>
<ProjectReference Include="..\Core\Core\Core.vcxproj">
<Project>{8c60e805-0da5-4e25-8f84-038db504bb0d}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Audio">
<UniqueIdentifier>{cde9a42c-90d9-4bc9-9182-3fcc0cf9f7a4}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="AudioJitTests.cpp">
<Filter>Audio</Filter>
</ClCompile>
<ClCompile Include="DSPJitTester.cpp">
<Filter>Audio</Filter>
</ClCompile>
<ClCompile Include="UnitTests.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="DSPJitTester.h">
<Filter>Audio</Filter>
</ClInclude>
</ItemGroup>
</Project>