| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
import argparse |
| 21 |
import os |
| 22 |
import shutil |
| 23 |
import subprocess |
| 24 |
import sys |
| 25 |
import tempfile |
| 26 |
from pathlib import Path |
| 27 |
|
| 28 |
ROOT = Path(__file__).resolve().parent.parent |
| 29 |
|
| 30 |
CMAKE = os.environ.get("CMAKE", "cmake") |
| 31 |
CTEST = os.environ.get("CTEST", "ctest") |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
MUTATIONS = [ |
| 38 |
{ |
| 39 |
"name": "PCM FIFO accepts one byte too many", |
| 40 |
"file": "src/vera_pcm.c", |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
"find": "if (fifo_cnt < sizeof(fifo) - 1) {", |
| 45 |
"into": "if (fifo_cnt <= sizeof(fifo) - 1) {", |
| 46 |
"count": 1, |
| 47 |
"caught_by": ["vera_pcm"], |
| 48 |
}, |
| 49 |
{ |
| 50 |
"name": "PCM almost-empty boundary is off by one", |
| 51 |
"file": "src/vera_pcm.c", |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
"find": "return fifo_cnt < 1024;", |
| 56 |
"into": "return fifo_cnt <= 1024;", |
| 57 |
"count": 1, |
| 58 |
"caught_by": ["vera_pcm"], |
| 59 |
}, |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
{ |
| 66 |
"name": "VERA debug reads report a constant", |
| 67 |
"file": "src/video.c", |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
"find": "if (debugOn) return video_get_dc_value(i);", |
| 73 |
"into": "if (debugOn) return 0;", |
| 74 |
"count": 1, |
| 75 |
"caught_by": ["vera_debug_read"], |
| 76 |
}, |
| 77 |
{ |
| 78 |
"name": "VERA DCSEL is truncated to four bits", |
| 79 |
"file": "src/video.c", |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
"find": "io_dcsel = (value >> 1) & 0x3f;", |
| 84 |
"into": "io_dcsel = (value >> 1) & 0x0f;", |
| 85 |
"count": 1, |
| 86 |
"caught_by": ["vera_regbank"], |
| 87 |
}, |
| 88 |
{ |
| 89 |
"name": "VERA address increment uses a power-of-two step", |
| 90 |
"file": "src/video.c", |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
"find": "\t40, -40,", |
| 95 |
"into": "\t48, -48,", |
| 96 |
"count": 1, |
| 97 |
"caught_by": ["vera_video"], |
| 98 |
}, |
| 99 |
{ |
| 100 |
"name": "VERA reads the increment from the wrong bits of ADDRx_H", |
| 101 |
"file": "src/video.c", |
| 102 |
|
| 103 |
|
| 104 |
"find": "io_inc[io_addrsel] = value >> 3;", |
| 105 |
"into": "io_inc[io_addrsel] = value >> 4;", |
| 106 |
"count": 1, |
| 107 |
"caught_by": ["vera_video"], |
| 108 |
}, |
| 109 |
{ |
| 110 |
"name": "PSG sawtooth loses its pulse-width shaping", |
| 111 |
"file": "src/vera_psg.c", |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
"find": "case WF_SAWTOOTH: v = (ch->phase >> 11) ^ ((ch->pw ^ 0x3f) & 0x3f); break;", |
| 116 |
"into": "case WF_SAWTOOTH: v = (ch->phase >> 11); break;", |
| 117 |
"count": 1, |
| 118 |
"caught_by": ["vera_psg"], |
| 119 |
}, |
| 120 |
{ |
| 121 |
"name": "PSG voices keep running while silenced", |
| 122 |
"file": "src/vera_psg.c", |
| 123 |
|
| 124 |
|
| 125 |
"find": "uint32_t new_phase = (ch->left || ch->right) ? ((ch->phase + ch->freq) & 0x1FFFF) : 0;", |
| 126 |
"into": "uint32_t new_phase = ((ch->phase + ch->freq) & 0x1FFFF);", |
| 127 |
"count": 1, |
| 128 |
"caught_by": ["vera_psg"], |
| 129 |
}, |
| 130 |
{ |
| 131 |
"name": "PSG noise LFSR loses a tap", |
| 132 |
"file": "src/vera_psg.c", |
| 133 |
|
| 134 |
|
| 135 |
"find": "(((noise_state >> 1) ^ (noise_state >> 2) ^ (noise_state >> 4) ^ (noise_state >> 15)) & 1)", |
| 136 |
"into": "(((noise_state >> 1) ^ (noise_state >> 2) ^ (noise_state >> 15)) & 1)", |
| 137 |
"count": 1, |
| 138 |
"caught_by": ["vera_psg"], |
| 139 |
}, |
| 140 |
{ |
| 141 |
"name": "PSG waveform is decoded from the wrong bits", |
| 142 |
"file": "src/vera_psg.c", |
| 143 |
|
| 144 |
|
| 145 |
"find": "channels[ch].waveform = val >> 6;", |
| 146 |
"into": "channels[ch].waveform = (val >> 5) & 3;", |
| 147 |
"count": 1, |
| 148 |
"caught_by": ["vera_psg"], |
| 149 |
}, |
| 150 |
{ |
| 151 |
"name": "VERA ISR clears on a written zero", |
| 152 |
"file": "src/video.c", |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
"find": "isr &= value ^ 0xff;", |
| 158 |
"into": "isr &= value;", |
| 159 |
"count": 1, |
| 160 |
"caught_by": ["vera_irq"], |
| 161 |
}, |
| 162 |
{ |
| 163 |
"name": "VERA IEN stores a fifth enable bit", |
| 164 |
"file": "src/video.c", |
| 165 |
|
| 166 |
|
| 167 |
"find": "ien = value & 0xF;", |
| 168 |
"into": "ien = value & 0x1F;", |
| 169 |
"count": 1, |
| 170 |
"caught_by": ["vera_irq"], |
| 171 |
}, |
| 172 |
{ |
| 173 |
"name": "VERA IRQLINE bit 8 comes from the wrong IEN bit", |
| 174 |
"file": "src/video.c", |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
"find": "irq_line = (irq_line & 0xFF) | ((value >> 7) << 8);", |
| 179 |
"into": "irq_line = (irq_line & 0xFF) | (((value >> 6) & 1) << 8);", |
| 180 |
"count": 1, |
| 181 |
"caught_by": ["vera_irq"], |
| 182 |
}, |
| 183 |
{ |
| 184 |
"name": "VERA ISR bit 3 latches instead of following the FIFO", |
| 185 |
"file": "src/video.c", |
| 186 |
|
| 187 |
|
| 188 |
"find": "case 0x07: return isr | (pcm_is_fifo_almost_empty() ? 8 : 0);", |
| 189 |
"into": "case 0x07: return isr;", |
| 190 |
"count": 1, |
| 191 |
"caught_by": ["vera_irq"], |
| 192 |
}, |
| 193 |
{ |
| 194 |
"name": "VERA asserts IRQ regardless of the enables", |
| 195 |
"file": "src/video.c", |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
"find": "return (tmp_isr & ien) != 0;", |
| 200 |
"into": "return tmp_isr != 0;", |
| 201 |
"count": 1, |
| 202 |
"caught_by": ["vera_irq"], |
| 203 |
}, |
| 204 |
{ |
| 205 |
"name": "VERA IEN bit 6 reports a stored bit, not the scanline", |
| 206 |
"file": "src/video.c", |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
"find": "((scanline & 0x100) >> 2)", |
| 211 |
"into": "0", |
| 212 |
"count": 1, |
| 213 |
"caught_by": ["vera_irq"], |
| 214 |
}, |
| 215 |
{ |
| 216 |
"name": "VERA collision nibble accumulates across frames", |
| 217 |
"file": "src/video.c", |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
"find": "isr = (isr & 0xf) | sprite_line_collisions;", |
| 222 |
"into": "isr = isr | sprite_line_collisions;", |
| 223 |
"count": 1, |
| 224 |
"caught_by": ["vera_irq"], |
| 225 |
}, |
| 226 |
{ |
| 227 |
"name": "VERA sprite collision mask is read from the wrong nibble", |
| 228 |
"file": "src/video.c", |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
"find": "props->sprite_collision_mask = sprite_data[sprite][6] & 0xf0;", |
| 233 |
"into": "props->sprite_collision_mask = (sprite_data[sprite][6] & 0x0f) << 4;", |
| 234 |
"count": 1, |
| 235 |
"caught_by": ["vera_irq"], |
| 236 |
}, |
| 237 |
{ |
| 238 |
"name": "VERA sprites collide where their masks differ", |
| 239 |
"file": "src/video.c", |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
"find": "sprite_line_collisions |= sprite_line_mask[line_x] & props->sprite_collision_mask;", |
| 245 |
"into": "sprite_line_collisions |= sprite_line_mask[line_x] & ~props->sprite_collision_mask;", |
| 246 |
"count": 1, |
| 247 |
"caught_by": ["vera_irq"], |
| 248 |
}, |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
{ |
| 255 |
"name": "direct-page cycle penalty is never cleared", |
| 256 |
"file": "src/cpu/fake6502.c", |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
"find": "\n penaltyd = 0;\n", |
| 261 |
"into": "\n", |
| 262 |
"count": 1, |
| 263 |
"caught_by": ["cpu_smoke"], |
| 264 |
}, |
| 265 |
{ |
| 266 |
"name": "page-cross penalty is dropped", |
| 267 |
"file": "src/cpu/fake6502.c", |
| 268 |
"find": "if (penaltyop && penaltyaddr) clockticks6502++;", |
| 269 |
"into": "if (0) clockticks6502++;", |
| 270 |
"count": 2, |
| 271 |
|
| 272 |
|
| 273 |
"caught_by": ["cpu_loadstore"], |
| 274 |
}, |
| 275 |
{ |
| 276 |
"name": "decimal mode costs no extra cycle", |
| 277 |
"file": "src/cpu/instructions.h", |
| 278 |
"find": "clockticks6502 += (uint32_t)(!regs.is65c816);", |
| 279 |
"into": "clockticks6502 += (uint32_t)(0);", |
| 280 |
"count": 2, |
| 281 |
"caught_by": ["cpu_decimal"], |
| 282 |
}, |
| 283 |
{ |
| 284 |
"name": "VIA is not told a read is for the debugger", |
| 285 |
"file": "src/memory.c", |
| 286 |
"find": "return via1_read(address & 0xf, debugOn);", |
| 287 |
"into": "return via1_read(address & 0xf, false);", |
| 288 |
"count": 1, |
| 289 |
"caught_by": ["debugon_contract"], |
| 290 |
}, |
| 291 |
{ |
| 292 |
"name": "a debug read of slow I/O costs cycles", |
| 293 |
"file": "src/memory.c", |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
"find": "if (!debugOn && address >= 0x9fa0) {\n\t\t// slow IO5-7 range\n\t\tclockticks6502 += 3;\n\t}\n\tif (address >= 0x9f00 && address < 0x9f10) {\n\t\treturn via1_read", |
| 299 |
"into": "if (address >= 0x9fa0) {\n\t\t// slow IO5-7 range\n\t\tclockticks6502 += 3;\n\t}\n\tif (address >= 0x9f00 && address < 0x9f10) {\n\t\treturn via1_read", |
| 300 |
"count": 1, |
| 301 |
"caught_by": ["debugon_contract"], |
| 302 |
}, |
| 303 |
{ |
| 304 |
"name": "a watchpoint swallows the store", |
| 305 |
"file": "src/memory.c", |
| 306 |
"find": "\t\tDEBUGBreakOnWatchpoint();\n\t}", |
| 307 |
"into": "\t\tDEBUGBreakOnWatchpoint();\n\t\treturn;\n\t}", |
| 308 |
"count": 1, |
| 309 |
"caught_by": ["watchpoint_purity"], |
| 310 |
}, |
| 311 |
{ |
| 312 |
"name": "the overflow flag is never set", |
| 313 |
"file": "src/cpu/support.h", |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
"find": "if (((n) ^ (m)) & ((n) ^ (o)) & 0x80) setoverflow();", |
| 318 |
"into": "if (((n) ^ (m)) & ((n) ^ (o)) & 0x00) setoverflow();", |
| 319 |
"count": 1, |
| 320 |
"caught_by": ["cpu_adc_sbc", "klaus"], |
| 321 |
}, |
| 322 |
{ |
| 323 |
"name": "zero page indexing does not wrap inside page zero", |
| 324 |
"file": "src/cpu/support.h", |
| 325 |
"find": "((uint16_t) ((uint8_t) (regs.dp & 0x00FF)) + (offset & 0xFF))", |
| 326 |
"into": "((uint16_t) ((uint8_t) (regs.dp & 0x00FF)) + offset)", |
| 327 |
"count": 1, |
| 328 |
"caught_by": ["cpu_loadstore", "klaus"], |
| 329 |
}, |
| 330 |
|
| 331 |
|
| 332 |
{ |
| 333 |
"name": "the negative flag is never set", |
| 334 |
"file": "src/cpu/support.h", |
| 335 |
"find": "else if ((n) & 0x0080) setsign();", |
| 336 |
"into": "else if ((n) & 0x0000) setsign();", |
| 337 |
"count": 1, |
| 338 |
"requires": "tests/pt/wdc65c02.bin", |
| 339 |
"caught_by": ["processor_tests", "klaus"], |
| 340 |
}, |
| 341 |
{ |
| 342 |
"name": "the zero flag is set from the wrong width", |
| 343 |
"file": "src/cpu/support.h", |
| 344 |
"find": "else if ((n) & 0x00FF) clearzero();", |
| 345 |
"into": "else if ((n) & 0x000F) clearzero();", |
| 346 |
"count": 1, |
| 347 |
"requires": "tests/pt/wdc65c02.bin", |
| 348 |
"caught_by": ["processor_tests", "klaus"], |
| 349 |
}, |
| 350 |
{ |
| 351 |
|
| 352 |
"name": "a taken branch costs no extra cycle", |
| 353 |
"file": "src/cpu/instructions.h", |
| 354 |
"find": "clockticks6502++;", |
| 355 |
"into": "clockticks6502 += 0;", |
| 356 |
"count": 1, |
| 357 |
"requires": "tests/pt/wdc65c02.bin", |
| 358 |
"caught_by": ["processor_tests"], |
| 359 |
}, |
| 360 |
|
| 361 |
|
| 362 |
{ |
| 363 |
"name": "indirect addressing ignores the data bank", |
| 364 |
"file": "src/cpu/modes.h", |
| 365 |
"find": "ea = addr_with_db((uint16_t)read6502(direct_page_add(eahelp), 0)", |
| 366 |
"into": "ea = ((uint16_t)read6502(direct_page_add(eahelp), 0)", |
| 367 |
"count": 2, |
| 368 |
"requires": "tests/pt/816-emu.bin", |
| 369 |
"caught_by": ["processor_tests_816_emu"], |
| 370 |
}, |
| 371 |
{ |
| 372 |
"name": "the new stack instructions wrap inside page one", |
| 373 |
"file": "src/cpu/instructions.h", |
| 374 |
"find": "regs.dp = pull16_long();", |
| 375 |
"into": "regs.dp = pull16();", |
| 376 |
"count": 1, |
| 377 |
"requires": "tests/pt/816-emu.bin", |
| 378 |
"caught_by": ["processor_tests_816_emu"], |
| 379 |
}, |
| 380 |
{ |
| 381 |
"name": "a 16-bit operand costs no extra cycle", |
| 382 |
"file": "src/cpu/support.h", |
| 383 |
"find": "(penaltym = addressing_is_acc ? 0 : (uint8_t)(n))", |
| 384 |
"into": "(penaltym = addressing_is_acc ? 0 : (uint8_t)((n) & 0x00))", |
| 385 |
"count": 1, |
| 386 |
"requires": "tests/pt/816-native.bin", |
| 387 |
"caught_by": ["processor_tests_816_native"], |
| 388 |
}, |
| 389 |
{ |
| 390 |
"name": "BIT reads the wrong half of a 16-bit operand", |
| 391 |
"file": "src/cpu/instructions.h", |
| 392 |
"find": "uint16_t top = memory_16bit() ? (uint16_t)(value >> 8) : value;", |
| 393 |
"into": "uint16_t top = value;", |
| 394 |
"count": 1, |
| 395 |
"requires": "tests/pt/816-native.bin", |
| 396 |
"caught_by": ["processor_tests_816_native"], |
| 397 |
}, |
| 398 |
{ |
| 399 |
|
| 400 |
|
| 401 |
"name": "the 65C02 decimal SBC algorithm is used on the 65C816", |
| 402 |
"file": "src/cpu/instructions.h", |
| 403 |
"find": " int16_t adjusted;\n if (regs.is65c816) {", |
| 404 |
"into": " int16_t adjusted;\n if (0) {", |
| 405 |
"count": 1, |
| 406 |
"requires": "tests/pt/816-emu.bin", |
| 407 |
"caught_by": ["processor_tests_816_emu"], |
| 408 |
}, |
| 409 |
{ |
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
"name": "a documented cycle count is changed", |
| 415 |
"file": "src/cpu/65c02.opcodes", |
| 416 |
"find": "wai imp 3 $cb", |
| 417 |
"into": "wai imp 4 $cb", |
| 418 |
"count": 1, |
| 419 |
"caught_by": ["opcode_spec"], |
| 420 |
}, |
| 421 |
{ |
| 422 |
"name": "VERA reset keeps the pending sprite collisions", |
| 423 |
"file": "src/video.c", |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
"find": "\tsprite_line_collisions = 0;\n\n\tvga_scan_pos_x = 0;", |
| 428 |
"into": "\tvga_scan_pos_x = 0;", |
| 429 |
"count": 1, |
| 430 |
"caught_by": ["vera_reset"], |
| 431 |
}, |
| 432 |
{ |
| 433 |
"name": "VERA sprite z-depth is ignored", |
| 434 |
"file": "src/video.c", |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
"find": "props->sprite_zdepth = (sprite_data[sprite][6] >> 2) & 3;", |
| 440 |
"into": "props->sprite_zdepth = 1;", |
| 441 |
"count": 1, |
| 442 |
"caught_by": ["vera_reset"], |
| 443 |
}, |
| 444 |
{ |
| 445 |
"name": "VERA layer map base is shifted one bit short", |
| 446 |
"file": "src/video.c", |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
"find": "props->map_base = reg_layer[layer][1] << 9;", |
| 451 |
"into": "props->map_base = reg_layer[layer][1] << 8;", |
| 452 |
"count": 1, |
| 453 |
"caught_by": ["vera_layer"], |
| 454 |
}, |
| 455 |
{ |
| 456 |
"name": "VERA tile base takes in the two size bits", |
| 457 |
"file": "src/video.c", |
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
"find": "props->tile_base = (reg_layer[layer][2] & 0xFC) << 9;", |
| 462 |
"into": "props->tile_base = (reg_layer[layer][2] & 0xFF) << 9;", |
| 463 |
"count": 1, |
| 464 |
"caught_by": ["vera_layer"], |
| 465 |
}, |
| 466 |
{ |
| 467 |
"name": "VERA map width starts at 16 tiles", |
| 468 |
"file": "src/video.c", |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
"find": "props->mapw_log2 = 5 + ((reg_layer[layer][0] >> 4) & 3);", |
| 473 |
"into": "props->mapw_log2 = 4 + ((reg_layer[layer][0] >> 4) & 3);", |
| 474 |
"count": 1, |
| 475 |
"caught_by": ["vera_layer"], |
| 476 |
}, |
| 477 |
{ |
| 478 |
"name": "VERA layer 1 registers are written to layer 0", |
| 479 |
"file": "src/video.c", |
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
"find": "reg_layer[1][reg - 0x14] = value;", |
| 484 |
"into": "reg_layer[0][reg - 0x14] = value;", |
| 485 |
"count": 1, |
| 486 |
"caught_by": ["vera_layer"], |
| 487 |
}, |
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
{ |
| 493 |
"name": "VERA layer row does not wrap at the layer height", |
| 494 |
"file": "src/video.c", |
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
"find": "return (y + props->vscroll) & (props->layerh_max);", |
| 499 |
"into": "return y + props->vscroll;", |
| 500 |
"count": 1, |
| 501 |
"caught_by": ["vera_layer_rows"], |
| 502 |
}, |
| 503 |
{ |
| 504 |
"name": "VERA map height starts at 16 tiles", |
| 505 |
"file": "src/video.c", |
| 506 |
|
| 507 |
|
| 508 |
"find": "props->maph_log2 = 5 + ((reg_layer[layer][0] >> 6) & 3);", |
| 509 |
"into": "props->maph_log2 = 4 + ((reg_layer[layer][0] >> 6) & 3);", |
| 510 |
"count": 1, |
| 511 |
"caught_by": ["vera_layer_rows"], |
| 512 |
}, |
| 513 |
{ |
| 514 |
"name": "VERA tile height is read from the tile width bit", |
| 515 |
"file": "src/video.c", |
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
"find": "props->tileh_log2 = 3 + ((reg_layer[layer][2] >> 1) & 1);", |
| 520 |
"into": "props->tileh_log2 = 3 + (reg_layer[layer][2] & 1);", |
| 521 |
"count": 1, |
| 522 |
"caught_by": ["vera_layer_rows"], |
| 523 |
}, |
| 524 |
{ |
| 525 |
"name": "VERA default palette entry is wrong", |
| 526 |
"file": "src/video.c", |
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
"find": "0x08f,0xbbb,", |
| 532 |
"into": "0x08f,0xbbc,", |
| 533 |
"count": 1, |
| 534 |
"caught_by": ["vera_palette"], |
| 535 |
}, |
| 536 |
{ |
| 537 |
"name": "VIA IER reads back without bit 7", |
| 538 |
"file": "src/via.c", |
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
"find": "return via->registers[14] | 0x80;", |
| 543 |
"into": "return via->registers[14];", |
| 544 |
"count": 1, |
| 545 |
"caught_by": ["via_irq"], |
| 546 |
}, |
| 547 |
{ |
| 548 |
"name": "VIA IER set and clear are the wrong way round", |
| 549 |
"file": "src/via.c", |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
"find": "if (value & 0x80) {", |
| 554 |
"into": "if (!(value & 0x80)) {", |
| 555 |
"count": 1, |
| 556 |
"caught_by": ["via_irq"], |
| 557 |
}, |
| 558 |
{ |
| 559 |
"name": "VIA IFR bit 7 ignores the enables", |
| 560 |
"file": "src/via.c", |
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
"find": "irq = (ifr & via->registers[14]) != 0;", |
| 565 |
"into": "irq = ifr != 0;", |
| 566 |
"count": 1, |
| 567 |
"caught_by": ["via_irq"], |
| 568 |
}, |
| 569 |
{ |
| 570 |
"name": "VIA debug read of T1C-L acknowledges the timer", |
| 571 |
"file": "src/via.c", |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
"find": "if (!debug) via->registers[13] &= ~0x40;", |
| 576 |
"into": "via->registers[13] &= ~0x40;", |
| 577 |
"count": 1, |
| 578 |
"caught_by": ["via_irq"], |
| 579 |
}, |
| 580 |
{ |
| 581 |
"name": "VIA T1 one-shot and free-run are swapped", |
| 582 |
"file": "src/via.c", |
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
"find": "if (!(acr & 0x40)) via->timer_running[0] = false;", |
| 587 |
"into": "if (acr & 0x40) via->timer_running[0] = false;", |
| 588 |
"count": 1, |
| 589 |
"caught_by": ["via_timers"], |
| 590 |
}, |
| 591 |
{ |
| 592 |
"name": "VIA T1 loads its low byte from the write, not the latch", |
| 593 |
"file": "src/via.c", |
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
"find": "via->timer_count[0] = ((unsigned)value << 8) | via->registers[6];", |
| 599 |
"into": "via->timer_count[0] = ((unsigned)value << 8) | value;", |
| 600 |
"count": 1, |
| 601 |
"caught_by": ["via_timers"], |
| 602 |
}, |
| 603 |
{ |
| 604 |
"name": "VIA T2 counts the clock in pulse mode", |
| 605 |
"file": "src/via.c", |
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
"find": "tclk = (acr & 0x20) ? via->pb6_pulse_counts : clocks;", |
| 611 |
"into": "tclk = clocks;", |
| 612 |
"count": 1, |
| 613 |
"caught_by": ["via_timers"], |
| 614 |
}, |
| 615 |
{ |
| 616 |
"name": "VIA T2 re-arms itself after timing out", |
| 617 |
"file": "src/via.c", |
| 618 |
|
| 619 |
|
| 620 |
"find": "\t\t\tifr |= 0x20;\n\t\t\tvia->timer_running[1] = false;", |
| 621 |
"into": "\t\t\tifr |= 0x20;", |
| 622 |
"count": 1, |
| 623 |
"caught_by": ["via_timers"], |
| 624 |
}, |
| 625 |
{ |
| 626 |
"name": "banked RAM window is 4K instead of 8K", |
| 627 |
"file": "src/memory.c", |
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
"find": "return BRAM[(ramBank << 13) + address - 0xa000];", |
| 632 |
"into": "return BRAM[(ramBank << 12) + address - 0xa000];", |
| 633 |
"count": 1, |
| 634 |
"caught_by": ["memory_banking"], |
| 635 |
}, |
| 636 |
{ |
| 637 |
"name": "banked RAM writes ignore the bank", |
| 638 |
"file": "src/memory.c", |
| 639 |
|
| 640 |
|
| 641 |
"find": "BRAM[(memory_get_ram_bank() << 13) + address - 0xa000] = value;", |
| 642 |
"into": "BRAM[address - 0xa000] = value;", |
| 643 |
"count": 1, |
| 644 |
"caught_by": ["memory_banking"], |
| 645 |
}, |
| 646 |
{ |
| 647 |
"name": "the RAM bank register is masked to the installed banks", |
| 648 |
"file": "src/memory.c", |
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
"find": "case 0:\n\t\t\tmemory_set_ram_bank(value);", |
| 653 |
"into": "case 0:\n\t\t\tmemory_set_ram_bank(value & 0x3f);", |
| 654 |
"count": 1, |
| 655 |
"caught_by": ["memory_banking"], |
| 656 |
}, |
| 657 |
{ |
| 658 |
"name": "an uninstalled RAM bank reads as zero", |
| 659 |
"file": "src/memory.c", |
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
"find": "\t\t\treturn (address >> 8) & 0xff; // open bus read\n\t\t}\n\t} else { // banked ROM", |
| 664 |
"into": "\t\t\treturn 0;\n\t\t}\n\t} else { // banked ROM", |
| 665 |
"count": 1, |
| 666 |
"caught_by": ["memory_banking"], |
| 667 |
}, |
| 668 |
{ |
| 669 |
"name": "a debug write charges the slow-I/O cycles", |
| 670 |
"file": "src/memory.c", |
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
"find": "\t\t\t// slow IO2 range\n\t\t\tif (!debugOn) {\n\t\t\t\tclockticks6502 += 3;\n\t\t\t}\n\t\t\tif ((address & 0x01) == 0) { // YM reg (partially decoded)", |
| 675 |
"into": "\t\t\t// slow IO2 range\n\t\t\tclockticks6502 += 3;\n\t\t\tif ((address & 0x01) == 0) { // YM reg (partially decoded)", |
| 676 |
"count": 1, |
| 677 |
"caught_by": ["debug_write_path"], |
| 678 |
}, |
| 679 |
{ |
| 680 |
"name": "a program write to slow I/O is free", |
| 681 |
"file": "src/memory.c", |
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
"find": "\t\tif (!debugOn && address >= 0x9fa0) {\n\t\t\t// slow IO5-7 range\n\t\t\tclockticks6502 += 3;\n\t\t}\n\t\tif (address >= 0x9f00 && address < 0x9f10) {\n\t\t\tvia1_write", |
| 686 |
"into": "\t\tif (false && address >= 0x9fa0) {\n\t\t\t// slow IO5-7 range\n\t\t\tclockticks6502 += 3;\n\t\t}\n\t\tif (address >= 0x9f00 && address < 0x9f10) {\n\t\t\tvia1_write", |
| 687 |
"count": 1, |
| 688 |
"caught_by": ["debug_write_path"], |
| 689 |
}, |
| 690 |
{ |
| 691 |
"name": "a debug write reports a watchpoint", |
| 692 |
"file": "src/memory.c", |
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
"find": "if (!debugOn && debug_wp_count() > 0 && bank == 0 && debug_wp_check_write(address, value)) {", |
| 697 |
"into": "if (debug_wp_count() > 0 && bank == 0 && debug_wp_check_write(address, value)) {", |
| 698 |
"count": 1, |
| 699 |
"caught_by": ["debug_write_path"], |
| 700 |
}, |
| 701 |
] |
| 702 |
|
| 703 |
|
| 704 |
def run(cmd, **kw): |
| 705 |
return subprocess.run(cmd, cwd=ROOT, capture_output=True, text=True, **kw) |
| 706 |
|
| 707 |
|
| 708 |
def build(build_dir, passes=1): |
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
out = "" |
| 719 |
for _ in range(passes): |
| 720 |
r = run([CMAKE, "--build", build_dir, "--target", "unit_tests"]) |
| 721 |
out += r.stdout + r.stderr |
| 722 |
if r.returncode != 0: |
| 723 |
return False, out |
| 724 |
return True, out |
| 725 |
|
| 726 |
|
| 727 |
def tests_fail(build_dir, names): |
| 728 |
|
| 729 |
for name in names: |
| 730 |
r = run([CTEST, "--test-dir", build_dir, "-R", f"^{name}$"]) |
| 731 |
if r.returncode == 0: |
| 732 |
return False, name |
| 733 |
return True, None |
| 734 |
|
| 735 |
|
| 736 |
def main(): |
| 737 |
ap = argparse.ArgumentParser() |
| 738 |
ap.add_argument("--build-dir", default="build") |
| 739 |
ap.add_argument("--only", help="run just the mutation whose name contains this") |
| 740 |
args = ap.parse_args() |
| 741 |
|
| 742 |
ok, out = build(args.build_dir) |
| 743 |
if not ok: |
| 744 |
print("the tree does not build before any mutation:\n" + out[-2000:]) |
| 745 |
return 2 |
| 746 |
|
| 747 |
survived = [] |
| 748 |
not_applicable = [] |
| 749 |
for m in MUTATIONS: |
| 750 |
if args.only and args.only not in m["name"]: |
| 751 |
continue |
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
need = m.get("requires") |
| 756 |
if need and not (ROOT / need).exists(): |
| 757 |
print(f"n/a {m['name']}\n needs {need}, which is not present") |
| 758 |
not_applicable.append(m["name"]) |
| 759 |
continue |
| 760 |
|
| 761 |
path = ROOT / m["file"] |
| 762 |
|
| 763 |
|
| 764 |
original = path.read_text(encoding="utf-8") |
| 765 |
|
| 766 |
want = m.get("count", 1) |
| 767 |
count = original.count(m["find"]) |
| 768 |
if count != want: |
| 769 |
print(f"SKIP {m['name']}\n pattern matches {count} times in " |
| 770 |
f"{m['file']}, expected {want} -- the source has moved on") |
| 771 |
survived.append(m["name"] + " (pattern stale)") |
| 772 |
continue |
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
GENERATED = ("src/cpu/tables.h", "src/cpu/mnemonics.h") |
| 777 |
|
| 778 |
backup = Path(tempfile.gettempdir()) / (path.name + ".mutation_backup") |
| 779 |
shutil.copy2(path, backup) |
| 780 |
gen_backups = {} |
| 781 |
for rel in GENERATED: |
| 782 |
gen = ROOT / rel |
| 783 |
if gen.exists(): |
| 784 |
gen_backups[gen] = Path(tempfile.gettempdir()) / (gen.name + ".mutation_backup") |
| 785 |
shutil.copy2(gen, gen_backups[gen]) |
| 786 |
try: |
| 787 |
path.write_text(original.replace(m["find"], m["into"]), |
| 788 |
encoding="utf-8") |
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
if path.suffix == ".opcodes": |
| 803 |
for gen in gen_backups: |
| 804 |
gen.unlink(missing_ok=True) |
| 805 |
|
| 806 |
built, out = build(args.build_dir, passes=2) |
| 807 |
if not built: |
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
first = next((l for l in out.splitlines() |
| 812 |
if "error" in l.lower()), "") |
| 813 |
print(f"SKIP {m['name']}\n does not compile: {first.strip()[:120]}") |
| 814 |
survived.append(m["name"] + " (did not compile)") |
| 815 |
continue |
| 816 |
|
| 817 |
caught, missed = tests_fail(args.build_dir, m["caught_by"]) |
| 818 |
if caught: |
| 819 |
print(f"caught {m['name']}") |
| 820 |
else: |
| 821 |
print(f"SURVIVED {m['name']}\n" |
| 822 |
f" {missed} still passed with this broken") |
| 823 |
survived.append(m["name"]) |
| 824 |
finally: |
| 825 |
shutil.copy2(backup, path) |
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
os.utime(path, None) |
| 831 |
backup.unlink(missing_ok=True) |
| 832 |
for gen, saved in gen_backups.items(): |
| 833 |
shutil.copy2(saved, gen) |
| 834 |
os.utime(gen, None) |
| 835 |
saved.unlink(missing_ok=True) |
| 836 |
|
| 837 |
|
| 838 |
ok, _ = build(args.build_dir, passes=2) |
| 839 |
if not ok: |
| 840 |
print("the tree does not build after restoring the sources") |
| 841 |
return 2 |
| 842 |
|
| 843 |
total = len([m for m in MUTATIONS |
| 844 |
if not args.only or args.only in m["name"]]) |
| 845 |
total -= len(not_applicable) |
| 846 |
print(f"\n{total - len(survived)}/{total} mutations caught") |
| 847 |
if not_applicable: |
| 848 |
print(f"{len(not_applicable)} not applicable here (missing fixtures)") |
| 849 |
if survived: |
| 850 |
print("survived:") |
| 851 |
for s in survived: |
| 852 |
print(f" {s}") |
| 853 |
return 1 |
| 854 |
return 0 |
| 855 |
|
| 856 |
|
| 857 |
if __name__ == "__main__": |
| 858 |
sys.exit(main()) |