From 610c85a354af0e3d3d63c382a269b151de0d90bb Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 25 Nov 2021 04:11:20 -0500 Subject: [PATCH] Correct test logic. All tests now pass. --- .../Clock SignalTests/AmigaBlitterTests.mm | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/OSBindings/Mac/Clock SignalTests/AmigaBlitterTests.mm b/OSBindings/Mac/Clock SignalTests/AmigaBlitterTests.mm index 8fe6216bf..2a2be3375 100644 --- a/OSBindings/Mac/Clock SignalTests/AmigaBlitterTests.mm +++ b/OSBindings/Mac/Clock SignalTests/AmigaBlitterTests.mm @@ -10,6 +10,7 @@ #include "Blitter.hpp" +#include #include namespace Amiga { @@ -37,14 +38,29 @@ using WriteVector = std::vector>; @implementation AmigaBlitterTests -- (BOOL)verifyWrites:(WriteVector &)writes blitter:(Amiga::Blitter &)blitter ram:(uint16_t *)ram { +- (BOOL)verifyWrites:(WriteVector &)writes blitter:(Amiga::Blitter &)blitter ram:(uint16_t *)ram approximateLocation:(NSInteger)approximateLocation { // Run for however much time the Blitter wants. while(blitter.get_status() & 0x4000) { blitter.advance_dma(); } + // Some blits will write the same address twice + // (e.g. by virtue of an appropriate modulo), but + // this unit test is currently able to verify the + // final result only. So count number of accesses per + // address up front in order only to count the + // final ones below. + std::unordered_map access_counts; for(const auto &write: writes) { - XCTAssertEqual(ram[write.first >> 1], write.second, @"Didn't find %04x at address %08x; found %04x instead", write.second, write.first, ram[write.first >> 1]); + ++access_counts[write.first]; + } + + for(const auto &write: writes) { + auto &count = access_counts[write.first]; + --count; + if(count) continue; + + XCTAssertEqual(ram[write.first >> 1], write.second, @"Didn't find %04x at address %08x; found %04x instead, somewhere before line %ld", write.second, write.first, ram[write.first >> 1], (long)approximateLocation); // For now, indicate only the first failure. if(ram[write.first >> 1] != write.second) { @@ -80,7 +96,9 @@ using WriteVector = std::vector>; WriteVector writes; BOOL hasFailed = NO; + NSInteger arrayEntry = -1; for(NSArray *const event in trace) { + ++arrayEntry; if(hasFailed) break; NSString *const type = event[0]; @@ -106,7 +124,7 @@ using WriteVector = std::vector>; // Hackaround for testing my magical all-at-once Blitter is here. if(state == State::LoggingWrites) { - if(![self verifyWrites:writes blitter:blitter ram:ram]) { + if(![self verifyWrites:writes blitter:blitter ram:ram approximateLocation:arrayEntry]) { hasFailed = YES; break; } @@ -209,7 +227,7 @@ using WriteVector = std::vector>; // Check the final set of writes. if(!hasFailed) { - [self verifyWrites:writes blitter:blitter ram:ram]; + [self verifyWrites:writes blitter:blitter ram:ram approximateLocation:-1]; } }