From d52528a6f0f3c06d38d31447bf861d8773f9bb1b Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Mon, 13 Jun 2022 19:52:40 -0700 Subject: [PATCH] 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(+) 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)); +}