From ac284974d385c401d0d719d9908fefcb9365c6ad Mon Sep 17 00:00:00 2001 From: s3lph Date: Thu, 10 Feb 2022 10:12:29 +0100 Subject: [PATCH] Add cycle limit to CI emulator test --- Makefile | 3 ++- src/emu6502.c | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 509b228..38dae5b 100644 --- a/Makefile +++ b/Makefile @@ -25,5 +25,6 @@ emu6502: memtest6502 gcc -D_END=$$(cat tmp/memtest4k-f000-ascii.map | grep ^done, | cut -d, -f2 | tr -d ' ,') -o out/emu6502 src/emu6502.c src/fake6502.c test: memtest6502 - gcc -DNOLIMIT -D_END=$$(cat tmp/memtest4k-f000-ascii.map | grep ^done, | cut -d, -f2 | tr -d ' ,') -o out/emu6502 src/emu6502.c src/fake6502.c + # Run the emulator, but terminate after 10M instructions + gcc -D_LIMIT=10000000 -D_END=$$(cat tmp/memtest4k-f000-ascii.map | grep ^done, | cut -d, -f2 | tr -d ' ,') -o out/emu6502 src/emu6502.c src/fake6502.c out/emu6502 | tail -30 diff --git a/src/emu6502.c b/src/emu6502.c index 5719bb2..e47a762 100644 --- a/src/emu6502.c +++ b/src/emu6502.c @@ -84,7 +84,12 @@ int main() { reset6502(); signal(SIGINT, intv); while (1) { -#ifndef NOLIMIT +#ifdef _LIMIT + if (instructions >= _LIMIT) { + dprintf(2, "Prematurely terminated after %d instructions (limit exceeded)", instructions); + exit(2); + } +#else usleep(1); #endif step6502();