Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Apr 10, 2024
1 parent ef1fb86 commit 6723a13
Show file tree
Hide file tree
Showing 3 changed files with 1,323 additions and 2 deletions.
85 changes: 83 additions & 2 deletions tests/c/instruction_checks/r4000allegrex_disasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,84 @@ typedef struct TestEntry {

const TestEntry entries[] = {
{ 0x00801017, NULL, "clo $v0, $a0" },
{ 0x00801016, NULL, "clz $v0, $a0" },
{ 0x00C7001C, NULL, "madd $a2, $a3" },
{ 0x00C7001D, NULL, "maddu $a2, $a3" },
{ 0x00C7002E, NULL, "msub $a2, $a3" },
{ 0x00C7002F, NULL, "msubu $a2, $a3" },
{ 0x0085102C, NULL, "max $v0, $a0, $a1" },
{ 0x0085102D, NULL, "min $v0, $a0, $a1" },
{ 0x0085100B, NULL, "movn $v0, $a0, $a1" },
{ 0x0085100A, NULL, "movz $v0, $a0, $a1" },
{ 0x7C822080, NULL, "ext $v0, $a0, 2, 5" },
{ 0x7C8221C0, NULL, "ext $v0, $a0, 7, 5" },
{ 0x7C823084, NULL, "ins $v0, $a0, 2, 5" },
{ 0x7C8259C4, NULL, "ins $v0, $a0, 7, 5" },
{ 0x7C041420, NULL, "seb $v0, $a0" },
{ 0x7C041620, NULL, "seh $v0, $a0" },
{ 0x7C041520, NULL, "bitrev $v0, $a0" },
{ 0x00241182, NULL, "rotr $v0, $a0, 6" },
{ 0x002414C2, NULL, "rotr $v0, $a0, 19" },
{ 0x00A41046, NULL, "rotrv $v0, $a0, $a1" },
{ 0x7C0410A0, NULL, "wsbh $v0, $a0" },
{ 0x7C0410E0, NULL, "wsbw $v0, $a0" },

{ 0xBC840000, NULL, "cache IXIN, 0x0($a0)" },
{ 0xBC860000, NULL, "cache IXUN, 0x0($a0)" },
{ 0xBC880000, NULL, "cache IHIN, 0x0($a0)" },
{ 0xBC8A0000, NULL, "cache IF, 0x0($a0)" },
{ 0xBC8B0000, NULL, "cache IFL, 0x0($a0)" },
{ 0xBC940000, NULL, "cache DXWBIN, 0x0($a0)" },
{ 0xBC960000, NULL, "cache DXUN, 0x0($a0)" },
{ 0xBC980000, NULL, "cache DCDEX, 0x0($a0)" },
{ 0xBC990000, NULL, "cache DHIN, 0x0($a0)" },
{ 0xBC9A0000, NULL, "cache DHWB, 0x0($a0)" },
{ 0xBC9B0000, NULL, "cache DHWBIN, 0x0($a0)" },
{ 0xBC9C0000, NULL, "cache DCDEXL, 0x0($a0)" },
{ 0xBC9E0000, NULL, "cache DF, 0x0($a0)" },
{ 0xBC9F0000, NULL, "cache DFL, 0x0($a0)" },

{ 0x0000000F, NULL, "sync" },
{ 0xC0820000, NULL, "ll $v0, 0x0($a0)" },
{ 0xE0850000, NULL, "sc $a1, 0x0($a0)" },

{ 0xBC800000, NULL, "cache 0x00, 0x0($a0)" },
{ 0xBC810000, NULL, "cache 0x01, 0x0($a0)" },
{ 0xBC820000, NULL, "cache 0x02, 0x0($a0)" },
{ 0xBC830000, NULL, "cache 0x03, 0x0($a0)" },
{ 0xBC840000, NULL, "cache IXIN, 0x0($a0)" },
{ 0xBC850000, NULL, "cache 0x05, 0x0($a0)" },
{ 0xBC860000, NULL, "cache IXUN, 0x0($a0)" },
{ 0xBC870000, NULL, "cache 0x07, 0x0($a0)" },
{ 0xBC880000, NULL, "cache IHIN, 0x0($a0)" },
{ 0xBC890000, NULL, "cache 0x09, 0x0($a0)" },
{ 0xBC8A0000, NULL, "cache IF, 0x0($a0)" },
{ 0xBC8B0000, NULL, "cache IFL, 0x0($a0)" },
{ 0xBC8C0000, NULL, "cache 0x0C, 0x0($a0)" },
{ 0xBC8D0000, NULL, "cache 0x0D, 0x0($a0)" },
{ 0xBC8E0000, NULL, "cache 0x0E, 0x0($a0)" },
{ 0xBC8F0000, NULL, "cache 0x0F, 0x0($a0)" },
{ 0xBC900000, NULL, "cache 0x10, 0x0($a0)" },
{ 0xBC910000, NULL, "cache 0x11, 0x0($a0)" },
{ 0xBC920000, NULL, "cache 0x12, 0x0($a0)" },
{ 0xBC930000, NULL, "cache 0x13, 0x0($a0)" },
{ 0xBC940000, NULL, "cache DXWBIN, 0x0($a0)" },
{ 0xBC950000, NULL, "cache 0x15, 0x0($a0)" },
{ 0xBC960000, NULL, "cache DXUN, 0x0($a0)" },
{ 0xBC970000, NULL, "cache 0x17, 0x0($a0)" },
{ 0xBC980000, NULL, "cache DCDEX, 0x0($a0)" },
{ 0xBC990000, NULL, "cache DHIN, 0x0($a0)" },
{ 0xBC9A0000, NULL, "cache DHWB, 0x0($a0)" },
{ 0xBC9B0000, NULL, "cache DHWBIN, 0x0($a0)" },
{ 0xBC9C0000, NULL, "cache DCDEXL, 0x0($a0)" },
{ 0xBC9D0000, NULL, "cache 0x1D, 0x0($a0)" },
{ 0xBC9E0000, NULL, "cache DF, 0x0($a0)" },
{ 0xBC9F0000, NULL, "cache DFL, 0x0($a0)" },

{ 0x70000000, NULL, "sleep" },
{ 0x000002A8, NULL, "mfie $v0" },
{ 0x000002B4, NULL, "mfie $zero" },
{ 0x000002C0, NULL, "mtie $a0" },
};

int main() {
Expand All @@ -45,17 +123,20 @@ int main() {
RabbitizerInstruction_disassemble(&instr, buffer, entry->immOverride, immOverrideLength, 0);

if (entry->expectedStr == NULL) {
printf("Word '0x%08X' doesn't have a expected str, got '%s'\n", entry->word, buffer);
fprintf(stderr, "Word '0x%08X' doesn't have a expected str, got '%s'\n", entry->word, buffer);
fprintf(stderr, " InstrIdType: '%s'\n", RabInstrIdType_getName(instr.instrIdType));
errorCount++;
} else if (strcmp(buffer, entry->expectedStr) != 0) {
fprintf(stderr, "Error on word '0x%08X'. Expected '%s', got '%s'\n", entry->word, entry->expectedStr, buffer);
fprintf(stderr, " <InstrIdType: %s>\n", RabInstrIdType_getName(instr.instrIdType));
fprintf(stderr, " InstrIdType: '%s'\n", RabInstrIdType_getName(instr.instrIdType));
errorCount++;
}

free(buffer);
RabbitizerInstructionR4000Allegrex_destroy(&instr);
}

fprintf(stderr, "%i errors out of %zu entries\n", errorCount, ARRAY_COUNT(entries));

return errorCount;
}
Loading

0 comments on commit 6723a13

Please sign in to comment.