1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-23 03:32:32 +00:00
CLK/OSBindings/Mac/Clock SignalTests/68000DecoderTests.mm

91 lines
2.2 KiB
Plaintext
Raw Normal View History

//
// m68kDecoderTests.m
// Clock Signal
//
// Created by Thomas Harte on 18/04/2022.
// Copyright 2022 Thomas Harte. All rights reserved.
//
#import <XCTest/XCTest.h>
#include "../../../InstructionSets/M68k/Decoder.hpp"
using namespace InstructionSet::M68k;
2022-04-27 00:32:39 +00:00
@interface M68000DecoderTests : XCTestCase
@end
2022-10-26 01:27:01 +00:00
namespace {
template <Model model> void generate() {
printf("{\n");
Predecoder<model> decoder;
for(int instr = 0; instr < 65536; instr++) {
printf("\t\"%04x\": \"", instr);
const auto found = decoder.decode(uint16_t(instr));
printf("%s\"", found.to_string(instr).c_str());
if(instr != 0xffff) printf(",");
printf("\n");
}
printf("}\n");
}
2022-10-26 01:27:01 +00:00
template <Model model> void test(NSString *filename, Class cls) {
NSData *const testData =
[NSData dataWithContentsOfURL:
2022-10-26 01:27:01 +00:00
[[NSBundle bundleForClass:cls]
URLForResource:filename
withExtension:@"json"
subdirectory:@"68000 Decoding"]];
NSDictionary<NSString *, NSString *> *const decodings = [NSJSONSerialization JSONObjectWithData:testData options:0 error:nil];
XCTAssertNotNil(decodings);
2022-10-26 02:33:25 +00:00
NSMutableArray<NSString *> *failures = [[NSMutableArray alloc] init];
2022-10-26 01:27:01 +00:00
Predecoder<model> decoder;
for(int instr = 0; instr < 65536; instr++) {
NSString *const instrName = [NSString stringWithFormat:@"%04x", instr];
NSString *const expected = decodings[instrName];
XCTAssertNotNil(expected);
const auto found = decoder.decode(uint16_t(instr));
// Test that all appropriate table entries are present for this operation.
if(found.operation != Operation::Undefined) {
operand_flags<model>(found.operation);
operand_size(found.operation);
}
NSString *const instruction = [NSString stringWithUTF8String:found.to_string(instr).c_str()];
2022-10-26 02:33:25 +00:00
if(![instruction isEqualToString:expected]) {
[failures addObject:[NSString stringWithFormat:@"%@ should decode as %@; got %@", instrName, expected, instruction]];
}
}
XCTAssertEqual([failures count], 0);
if([failures count]) {
NSLog(@"%@", failures);
}
}
2022-10-26 01:27:01 +00:00
}
@implementation M68000DecoderTests
- (void)test68000 {
test<Model::M68000>(@"68000ops", [self class]);
}
2022-10-27 14:52:26 +00:00
- (void)test68010 {
test<Model::M68010>(@"68010ops", [self class]);
}
2022-10-26 01:27:01 +00:00
- (void)test68020 {
2022-10-28 17:17:35 +00:00
test<Model::M68020>(@"68020ops", [self class]);
2022-10-26 01:27:01 +00:00
}
@end