From 3cb0976367205aff969a6eda1c3b601e40c7f24e Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Mon, 13 Jun 2022 17:03:19 -0700 Subject: UnitTests: Use hermes.s as part of an actual test Before, the file just existed as the source code for HermesBinary.cpp, but we can test that things assemble correctly too (compare DSPTestBinary.cpp and DSPTestText.cpp). A bit of jank is needed due to MSVC limitations (see https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/compiler-error-c2026?view=msvc-170). --- Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp') diff --git a/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp b/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp index dd3c96e194..ecd543d168 100644 --- a/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp +++ b/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp @@ -8,6 +8,7 @@ #include "DSPTestBinary.h" #include "DSPTestText.h" #include "HermesBinary.h" +#include "HermesText.h" #include @@ -129,6 +130,11 @@ 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)); @@ -143,12 +149,3 @@ 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. -*/ -- cgit v1.2.3 From dd66dac5c166e2e4fb9195a914f10cdd2f9eb3c4 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Mon, 13 Jun 2022 17:05:24 -0700 Subject: UnitTests: Fix typo in DSPAssemblyTest --- Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp') diff --git a/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp b/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp index ecd543d168..fabdc73c3c 100644 --- a/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp +++ b/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp @@ -12,7 +12,7 @@ #include -static bool RoundTrippableDissassemble(const std::vector& code, std::string& text) +static bool RoundTrippableDisassemble(const std::vector& code, std::string& text) { DSP::AssemblerSettings settings; settings.ext_separator = '\''; @@ -32,7 +32,7 @@ static bool RoundTrip(const std::vector& code1) { std::vector code2; std::string text; - if (!RoundTrippableDissassemble(code1, text)) + if (!RoundTrippableDisassemble(code1, text)) { printf("RoundTrip: Disassembly failed.\n"); return false; @@ -63,7 +63,7 @@ static bool SuperTrip(const char* asm_code) } printf("First assembly: %i words\n", (int)code1.size()); - if (!RoundTrippableDissassemble(code1, text)) + if (!RoundTrippableDisassemble(code1, text)) { printf("SuperTrip: Disassembly failed\n"); return false; -- cgit v1.2.3 From d8803a129849f087e670a4f29892e769190f6b77 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Mon, 13 Jun 2022 17:23:23 -0700 Subject: UnitTests: Use fmt::print in DSPAssemblyTest --- Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp') diff --git a/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp b/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp index fabdc73c3c..c9d21bb9a0 100644 --- a/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp +++ b/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp @@ -1,6 +1,8 @@ // Copyright 2017 Dolphin Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include + #include "Common/FileUtil.h" #include "Core/DSP/DSPCodeUtil.h" #include "Core/DSP/DSPDisassembler.h" @@ -34,18 +36,18 @@ static bool RoundTrip(const std::vector& code1) std::string 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("{}", text); } return true; } @@ -58,25 +60,25 @@ 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 (!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; } return true; -- cgit v1.2.3 From 6a2ec825a225d07208d61aeeaf62c3c5525745f0 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Mon, 13 Jun 2022 19:00:15 -0700 Subject: UnitTests: Fail DSPAssemblyTest if the assembled code doesn't match the expected result This reveals that both HermesText and HermesBinary fail. HermesBinary would have failed on master, too, if this had been implemented. --- Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp') diff --git a/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp b/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp index c9d21bb9a0..17e4d70b3d 100644 --- a/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp +++ b/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp @@ -46,8 +46,8 @@ static bool RoundTrip(const std::vector& code1) } if (!DSP::Compare(code1, code2)) { - DSP::Disassemble(code1, true, text); - fmt::print("{}", text); + fmt::print("RoundTrip: Assembled code does not match input code\n"); + return false; } return true; } @@ -81,6 +81,12 @@ static bool SuperTrip(const char* asm_code) 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; } -- cgit v1.2.3 From d52528a6f0f3c06d38d31447bf861d8773f9bb1b Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Mon, 13 Jun 2022 19:52:40 -0700 Subject: UnitTests: Add tests for assembling DSP code to expected binary We already have the data for this, so this seems like a useful thing to do. However, neither of the new tests currently pass... --- Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp') diff --git a/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp b/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp index 17e4d70b3d..8f99fd83d3 100644 --- a/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp +++ b/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp @@ -90,6 +90,29 @@ static bool SuperTrip(const char* asm_code) return true; } +// Assembles asm_code, and verifies that it matches code1. +static bool AssembleAndCompare(const char* asm_code, const std::vector& code1) +{ + std::vector 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; +} + // Let's start out easy - a trivial instruction.. TEST(DSPAssembly, TrivialInstruction) { @@ -148,6 +171,11 @@ 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)); @@ -157,3 +185,8 @@ TEST(DSPAssembly, DSPTestBinary) { ASSERT_TRUE(RoundTrip(s_dsp_test_bin)); } + +TEST(DSPAssembly, DSPTestAssemble) +{ + ASSERT_TRUE(AssembleAndCompare(s_dsp_test_text, s_dsp_test_bin)); +} -- cgit v1.2.3 From dec48ed7de1e9710dc2aad5690e3a32b8ee8ed13 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Tue, 14 Jun 2022 13:07:14 -0700 Subject: UnitTests: Remove unused include from DSPAssemblyTest --- Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp') diff --git a/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp b/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp index 8f99fd83d3..44e4cde30e 100644 --- a/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp +++ b/Source/UnitTests/Core/DSP/DSPAssemblyTest.cpp @@ -3,7 +3,6 @@ #include -#include "Common/FileUtil.h" #include "Core/DSP/DSPCodeUtil.h" #include "Core/DSP/DSPDisassembler.h" -- cgit v1.2.3