Skip to content

Commit

Permalink
Make emulate()'s stop_when parameter mandatory (#27)
Browse files Browse the repository at this point in the history
stop_when is now a required argument. This ensures that any infinite
loops are explicitly expressed within calling code instead of implicit.
  • Loading branch information
NathanY3G committed Jun 2, 2021
1 parent 093a213 commit 23f61a9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pioemu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__version__ = "0.1.0"
__version__ = "0.22.0"

from .conditions import clock_cycles_reached
from .emulation import emulate
Expand Down
5 changes: 3 additions & 2 deletions pioemu/emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
def emulate(
opcodes,
*,
stop_when,
initial_state=State(),
stop_when=None,
shift_osr_right=True,
side_set_base=0,
side_set_count=0,
):
stop_when = stop_when or (lambda state: False)
if stop_when is None:
raise ValueError("emulate() missing value for keyword argument: 'stop_when'")

if shift_osr_right:
instruction_decoder = InstructionDecoder(shift_right)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "rp2040-pio-emulator"
version = "0.21.0"
version = "0.22.0"
description = "RP2040 emulator for the testing and debugging of PIO programs"
authors = ["Nathan Young"]
license = "Apache-2.0"
Expand Down
7 changes: 6 additions & 1 deletion tests/test_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@
from .support import emulate_single_instruction


def test_stop_when_requires_value():
with pytest.raises(ValueError):
next(emulate([0x0000], stop_when=None))


def test_emulation_stops_when_unsupported_opcode_is_reached():
with pytest.raises(StopIteration):
next(emulate([0xE0E0]))
next(emulate([0xE0E0], stop_when=lambda _: False))


@pytest.mark.parametrize(
Expand Down

0 comments on commit 23f61a9

Please sign in to comment.