diff options
Diffstat (limited to 'Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp')
| -rw-r--r-- | Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp | 81 |
1 files changed, 59 insertions, 22 deletions
diff --git a/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp b/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp index dd3c96e194..44e4cde30e 100644 --- a/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp +++ b/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp @@ -1,17 +1,19 @@ // Copyright 2017 Dolphin Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include "Common/FileUtil.h" +#include <fmt/format.h> + #include "Core/DSP/DSPCodeUtil.h" #include "Core/DSP/DSPDisassembler.h" #include "DSPTestBinary.h" #include "DSPTestText.h" #include "HermesBinary.h" +#include "HermesText.h" #include <gtest/gtest.h> -static bool RoundTrippableDissassemble(const std::vector<u16>& code, std::string& text) +static bool RoundTrippableDisassemble(const std::vector<u16>& code, std::string& text) { DSP::AssemblerSettings settings; settings.ext_separator = '\''; @@ -31,20 +33,20 @@ static bool RoundTrip(const std::vector<u16>& code1) { std::vector<u16> code2; std::string text; - if (!RoundTrippableDissassemble(code1, text)) + if (!RoundTrippableDisassemble(code1, text)) { - printf("RoundTrip: Disassembly failed.\n"); + fmt::print("RoundTrip: Disassembly failed.\n"); return false; } if (!DSP::Assemble(text, code2)) { - printf("RoundTrip: Assembly failed.\n"); + fmt::print("RoundTrip: Assembly failed.\n"); return false; } if (!DSP::Compare(code1, code2)) { - DSP::Disassemble(code1, true, text); - printf("%s", text.c_str()); + fmt::print("RoundTrip: Assembled code does not match input code\n"); + return false; } return true; } @@ -57,25 +59,54 @@ static bool SuperTrip(const char* asm_code) std::string text; if (!DSP::Assemble(asm_code, code1)) { - printf("SuperTrip: First assembly failed\n"); + fmt::print("SuperTrip: First assembly failed\n"); return false; } - printf("First assembly: %i words\n", (int)code1.size()); + fmt::print("First assembly: {} words\n", code1.size()); - if (!RoundTrippableDissassemble(code1, text)) + if (!RoundTrippableDisassemble(code1, text)) { - printf("SuperTrip: Disassembly failed\n"); + fmt::print("SuperTrip: Disassembly failed\n"); return false; } else { - printf("Disassembly:\n"); - printf("%s", text.c_str()); + fmt::print("Disassembly:\n"); + fmt::print("{}", text); } if (!DSP::Assemble(text, code2)) { - printf("SuperTrip: Second assembly failed\n"); + fmt::print("SuperTrip: Second assembly failed\n"); + return false; + } + + if (!DSP::Compare(code1, code2)) + { + fmt::print("SuperTrip: Assembled code does not match between passes\n"); + return false; + } + return true; +} + +// Assembles asm_code, and verifies that it matches code1. +static bool AssembleAndCompare(const char* asm_code, const std::vector<u16>& code1) +{ + std::vector<u16> code2; + if (!DSP::Assemble(asm_code, code2)) + { + fmt::print("AssembleAndCompare: Assembly failed\n"); + return false; + } + + fmt::print("AssembleAndCompare: Produced {} words; padding to {} words\n", code2.size(), + code1.size()); + while (code2.size() < code1.size()) + code2.push_back(0); + + if (!DSP::Compare(code1, code2)) + { + fmt::print("AssembleAndCompare: Assembled code does not match expected code\n"); return false; } return true; @@ -129,11 +160,21 @@ TEST(DSPAssembly, ExtendedInstructions) " ADDAXL'MV $ACC1, $AX1.L : $AX1.H, $AC1.M\n")); } +TEST(DSPAssembly, HermesText) +{ + ASSERT_TRUE(SuperTrip(s_hermes_text)); +} + TEST(DSPAssembly, HermesBinary) { ASSERT_TRUE(RoundTrip(s_hermes_bin)); } +TEST(DSPAssembly, HermesAssemble) +{ + ASSERT_TRUE(AssembleAndCompare(s_hermes_text, s_hermes_bin)); +} + TEST(DSPAssembly, DSPTestText) { ASSERT_TRUE(SuperTrip(s_dsp_test_text)); @@ -144,11 +185,7 @@ TEST(DSPAssembly, DSPTestBinary) ASSERT_TRUE(RoundTrip(s_dsp_test_bin)); } -/* - -if (File::ReadFileToString("C:/devkitPro/examples/wii/asndlib/dsptest/dsp_test.ds", &dsp_test)) - SuperTrip(dsp_test.c_str()); - -//.File::ReadFileToString("C:/devkitPro/trunk/libogc/libasnd/dsp_mixer/dsp_mixer.s", &dsp_test); -// This is CLOSE to working. Sorry about the local path btw. This is preliminary code. -*/ +TEST(DSPAssembly, DSPTestAssemble) +{ + ASSERT_TRUE(AssembleAndCompare(s_dsp_test_text, s_dsp_test_bin)); +} |
