From 72b91a8fb764ae1669a9e76fb58ec9964b189fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Boczar?= Date: Wed, 25 Mar 2020 11:49:46 +0100 Subject: [PATCH] test: add timeout_generator --- test/common.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/common.py b/test/common.py index fab3a70..e8873c8 100644 --- a/test/common.py +++ b/test/common.py @@ -24,6 +24,15 @@ def seed_to_data(seed, random=True, nbits=32): return data +@passive +def timeout_generator(ticks): + # raise exception after given timeout effectively stopping simulation + # because of @passive, simulation can end even if this generator is still running + for _ in range(ticks): + yield + raise TimeoutError("Timeout after %d ticks" % ticks) + + class DRAMMemory: def __init__(self, width, depth, init=[]): self.width = width