From 57ec756f5be51729330b1a15b2c89cd6eacfde23 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 11 Mar 2017 20:33:58 -0500 Subject: [PATCH] Started speccing out a unit test for Atari ROM analysis. --- .../Clock Signal.xcodeproj/project.pbxproj | 8 +++ .../AtariStaticAnalyserTests.mm | 69 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 OSBindings/Mac/Clock SignalTests/AtariStaticAnalyserTests.mm diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index e4c35ff0d..e6c185ad8 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -86,6 +86,8 @@ 4B8FE2221DA19FB20090D3CE /* MachinePanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B8FE2211DA19FB20090D3CE /* MachinePanel.swift */; }; 4B8FE2271DA1DE2D0090D3CE /* NSBundle+DataResource.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B8FE2261DA1DE2D0090D3CE /* NSBundle+DataResource.m */; }; 4B8FE2291DA1EDDF0090D3CE /* ElectronOptionsPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B8FE2281DA1EDDF0090D3CE /* ElectronOptionsPanel.swift */; }; + 4B924E991E74D22700B76AF1 /* AtariStaticAnalyserTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4B924E981E74D22700B76AF1 /* AtariStaticAnalyserTests.mm */; }; + 4B9252CE1E74D28200B76AF1 /* Atari ROMs in Resources */ = {isa = PBXBuildFile; fileRef = 4B9252CD1E74D28200B76AF1 /* Atari ROMs */; }; 4B92EACA1B7C112B00246143 /* 6502TimingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B92EAC91B7C112B00246143 /* 6502TimingTests.swift */; }; 4B96F7221D75119A0058BB2D /* Tape.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B96F7201D75119A0058BB2D /* Tape.cpp */; }; 4B9CCDA11DA279CA0098B625 /* Vic20OptionsPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B9CCDA01DA279CA0098B625 /* Vic20OptionsPanel.swift */; }; @@ -571,6 +573,8 @@ 4B8FE2251DA1DE2D0090D3CE /* NSBundle+DataResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSBundle+DataResource.h"; sourceTree = ""; }; 4B8FE2261DA1DE2D0090D3CE /* NSBundle+DataResource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSBundle+DataResource.m"; sourceTree = ""; }; 4B8FE2281DA1EDDF0090D3CE /* ElectronOptionsPanel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ElectronOptionsPanel.swift; sourceTree = ""; }; + 4B924E981E74D22700B76AF1 /* AtariStaticAnalyserTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AtariStaticAnalyserTests.mm; sourceTree = ""; }; + 4B9252CD1E74D28200B76AF1 /* Atari ROMs */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "Atari ROMs"; sourceTree = ""; }; 4B92EAC91B7C112B00246143 /* 6502TimingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 6502TimingTests.swift; sourceTree = ""; }; 4B96F7201D75119A0058BB2D /* Tape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Tape.cpp; path = ../../StaticAnalyser/Acorn/Tape.cpp; sourceTree = ""; }; 4B96F7211D75119A0058BB2D /* Tape.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Tape.hpp; path = ../../StaticAnalyser/Acorn/Tape.hpp; sourceTree = ""; }; @@ -1010,6 +1014,7 @@ 4B1414631B588A1100E04248 /* Test Binaries */ = { isa = PBXGroup; children = ( + 4B9252CD1E74D28200B76AF1 /* Atari ROMs */, 4B44EBF61DC9883B00A7820C /* 6502_functional_test.bin */, 4B44EBF41DC987AE00A7820C /* AllSuiteA.bin */, 4B44EBF81DC9898E00A7820C /* BCDTEST_beeb */, @@ -1722,6 +1727,7 @@ isa = PBXGroup; children = ( 4B5073091DDFCFDF00C48FBD /* ArrayBuilderTests.mm */, + 4B924E981E74D22700B76AF1 /* AtariStaticAnalyserTests.mm */, 4BB2A9AE1E13367E001A5C23 /* CRCTests.mm */, 4B121F941E05E66800BFDA12 /* PCMPatchedTrackTests.mm */, 4B121F9A1E06293F00BFDA12 /* PCMSegmentEventSourceTests.mm */, @@ -2225,6 +2231,7 @@ 4BB299661B587D8400A49093 /* inszx in Resources */, 4BB299101B587D8400A49093 /* asoz in Resources */, 4BB2998B1B587D8400A49093 /* lseiy in Resources */, + 4B9252CE1E74D28200B76AF1 /* Atari ROMs in Resources */, 4BB2997D1B587D8400A49093 /* ldxay in Resources */, 4BB299D71B587D8400A49093 /* staax in Resources */, 4BB2990C1B587D8400A49093 /* asoax in Resources */, @@ -2496,6 +2503,7 @@ 4B1E85811D176468001EF87D /* 6532Tests.swift in Sources */, 4BC9E1EE1D23449A003FCEE4 /* 6502InterruptTests.swift in Sources */, 4BEF6AAA1D35CE9E00E73575 /* DigitalPhaseLockedLoopBridge.mm in Sources */, + 4B924E991E74D22700B76AF1 /* AtariStaticAnalyserTests.mm in Sources */, 4B50730A1DDFCFDF00C48FBD /* ArrayBuilderTests.mm in Sources */, 4B2AF8691E513FC20027EE29 /* TIATests.mm in Sources */, 4B3BA0CE1D318B44005DD7A7 /* C1540Bridge.mm in Sources */, diff --git a/OSBindings/Mac/Clock SignalTests/AtariStaticAnalyserTests.mm b/OSBindings/Mac/Clock SignalTests/AtariStaticAnalyserTests.mm new file mode 100644 index 000000000..1d5b096e7 --- /dev/null +++ b/OSBindings/Mac/Clock SignalTests/AtariStaticAnalyserTests.mm @@ -0,0 +1,69 @@ +// +// AtariStaticAnalyserTests.m +// Clock Signal +// +// Created by Thomas Harte on 11/03/2017. +// Copyright © 2017 Thomas Harte. All rights reserved. +// + +#import + +#import +#include "../../../StaticAnalyser/StaticAnalyser.hpp" + +@interface AtariROMRecord : NSObject +@property(nonatomic, readonly) StaticAnalyser::Atari2600PagingModel pagingModel; +@property(nonatomic, readonly) BOOL usesSuperchip; ++ (instancetype)recordWithPagingModel:(StaticAnalyser::Atari2600PagingModel)pagingModel usesSuperchip:(BOOL)usesSuperchip; +@end + +@implementation AtariROMRecord ++ (instancetype)recordWithPagingModel:(StaticAnalyser::Atari2600PagingModel)pagingModel usesSuperchip:(BOOL)usesSuperchip +{ + AtariROMRecord *record = [[AtariROMRecord alloc] init]; + record->_pagingModel = pagingModel; + record->_usesSuperchip = usesSuperchip; + return record; +} +@end + +static NSDictionary *romRecordsBySHA1 = @{ +}; + +@interface AtariStaticAnalyserTests : XCTestCase +@end + +@implementation AtariStaticAnalyserTests + +- (AtariROMRecord *)romRecordForSHA1:(NSString *)sha1 +{ + return romRecordsBySHA1[sha1]; +} + +- (void)testAtariROMS +{ + NSString *basePath = [[[NSBundle bundleForClass:[self class]] resourcePath] stringByAppendingPathComponent:@"Atari ROMs"]; + for(NSString *testFile in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:basePath error:nil]) + { + NSString *fullPath = [basePath stringByAppendingPathComponent:testFile]; + + // get a SHA1 for the file + NSData *fileData = [NSData dataWithContentsOfFile:fullPath]; + uint8_t sha1Bytes[CC_SHA1_DIGEST_LENGTH]; + CC_SHA1([fileData bytes], (CC_LONG)[fileData length], sha1Bytes); + NSMutableString *sha1 = [[NSMutableString alloc] init]; + for(int c = 0; c < CC_SHA1_DIGEST_LENGTH; c++) [sha1 appendFormat:@"%02x", sha1Bytes[c]]; + + // get an analysis of the file + std::list targets = StaticAnalyser::GetTargets([fullPath UTF8String]); + + AtariROMRecord *romRecord = [self romRecordForSHA1:sha1]; + if(!romRecord) + { + NSLog(@"No record for %@ with SHA1 %@", testFile, sha1); + continue; + } + } +} + +@end