From 34f6a5433037072c1718c8ba7196246215990c91 Mon Sep 17 00:00:00 2001 From: Fischer Moseley <42497969+fischermoseley@users.noreply.github.com> Date: Thu, 28 Dec 2023 15:30:55 -0800 Subject: [PATCH] fix integer bounds, move to self-hosted runner --- .github/workflows/run_tests.yml | 12 +++++++----- src/manta/io_core.py | 22 ++++++++++++++++++++++ src/manta/utils.py | 2 +- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 331fb58..4964dbb 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -2,12 +2,14 @@ name: run_tests on: [push] jobs: all: - runs-on: ubuntu-latest + runs-on: self-hosted steps: - uses: actions/checkout@v3 - name: Install Manta from Source run: | + ls -lah + pwd python -m pip install -U pip # omitting the following commmand causes the version of setuptools @@ -19,13 +21,13 @@ jobs: python -m pip install ".[dev]" + - name: Run tests + run: | # export tool paths export VIVADO=/tools/Xilinx/Vivado/2023.1/bin/vivado export YOSYS=/tools/oss-cad-suite/bin/yosys - export NEXTPNR_ICE40=/tools/oss-cad-suite/bin/nextpnr_ice40 + export NEXTPNR_ICE40=/tools/oss-cad-suite/bin/nextpnr-ice40 export ICEPACK=/tools/oss-cad-suite/bin/icepack export ICEPROG=/tools/oss-cad-suite/bin/iceprog - - - name: Run tests - run: make test \ No newline at end of file + make test \ No newline at end of file diff --git a/src/manta/io_core.py b/src/manta/io_core.py index 97d869f..c12096a 100644 --- a/src/manta/io_core.py +++ b/src/manta/io_core.py @@ -237,6 +237,28 @@ class IOCore(Elaboratable): return self.max_addr def set_probe(self, probe_name, value): + # check that probe is an output probe + if probe_name not in self.config["outputs"]: + raise ValueError(f"Output probe '{probe_name}' not found.") + + # check that value is an integer + if not isinstance(value, int): + raise ValueError("Value must be an integer.") + + # get the width of the probe, make sure value isn't too large for the probe + attrs = self.config["outputs"][probe_name] + if isinstance(attrs, int): + width = attrs + + if isinstance(attrs, dict): + width = attrs["width"] + + if value > 0 and value > 2**width - 1: + raise ValueError("Unsigned integer too large.") + + if value < 0 and value < -(2 ** (width - 1)): + raise ValueError("Signed integer too large.") + # set value in buffer addrs = self.mmap[probe_name + "_buf"]["addrs"] datas = value_to_words(value, len(addrs)) diff --git a/src/manta/utils.py b/src/manta/utils.py index a40fa0a..068501d 100644 --- a/src/manta/utils.py +++ b/src/manta/utils.py @@ -13,7 +13,7 @@ def words_to_value(data): if d > 0 and d > 2**16 - 1: raise ValueError("Unsigned integer too large.") - if d < 0 and d < -(2**15 - 1): + if d < 0 and d < -(2**15): raise ValueError("Signed integer too large.") return int("".join([f"{i:016b}" for i in data[::-1]]), 2)