From b4b3980ffb5ed956514b88d892849b3946c844ab Mon Sep 17 00:00:00 2001 From: ram Date: Fri, 10 Jan 2025 08:14:42 +0000 Subject: [PATCH] Add test case for passing strings into kernel invokation breaks --- nac3artiq/demo/module.elf | Bin 1452 -> 1508 bytes nac3artiq/demo/test_cache.py | 80 ++++------------------------------- 2 files changed, 8 insertions(+), 72 deletions(-) diff --git a/nac3artiq/demo/module.elf b/nac3artiq/demo/module.elf index 21483fee269ff20d20e0f85f9b79e0e5a29d7a53..31643eb11c2133f5caae3dcd7babbf4a123b0836 100644 GIT binary patch delta 559 zcmZ9Jze~eF6vyw9Tx;wVf)OjEZ7L~lV%4P}PAWS12WS^p1t}tqf-Ts=t>Fz_9CUCH z9Q_B}92^uJDkv%xx;iMh#qYaz>Vr?-&wKas?l#lQv`g|Xo>?vYNFf*{Af6B~#e+2@ zZsy!KIEMHt=WZiyi0^|*UtL-ql=mA#ba0+ptzz6O%PP6DICYKEAkdbWMo9^@lO(Cq ziVW6HVD-Q!qCQ^;`2#+#VtInLp?QujknFG=9_`nUcfrykoyk4=mfmT0kTPG)FY+V) zJp7koYy!Wx47)sR=m{-0M*JjG+L!Iqqpg)jT+_Q9xg}W4AeVQvGRvnqCvy2T zQ=uIvbonl(MooBTK-}7(8+beqvq{fRsLbQiuM;U=ZI=ovQs#YWT}3J0OxdQonpJGJ H(a!$|{tR5a delta 546 zcmZ9JJxjw-6o&6ja&5285N)wSkW|_+A`VU>6r6-oiod``aBy%{>L4gMHk?601qBBO ze?pfIZXycqR_NG4e?fiUYv|yChx2vMM@~kir&6z`yV>&AQeP`YjDkc;!BjmjCp)d$ z2RM%GzG_=YJF-DsyhM$hKgZd3V?AYgE{nO=$DP)W(p_D+K0;j_hn`}t25u&kNh;eq zPA_1Mz!=dor$eqV(}(6FcR&M*JnDUU^8<;zXb;Oyg?1f$sfb%W5d18GPWB$o3?Ti#7sUXUNcBZu;ZJoh3^u_iG* kT~Ag_-SU7Wa5E1~Xx#6V6XbXwcO#eUo5&k`@@f`-0gAF&#Q*>R diff --git a/nac3artiq/demo/test_cache.py b/nac3artiq/demo/test_cache.py index 75d226c..101b11c 100644 --- a/nac3artiq/demo/test_cache.py +++ b/nac3artiq/demo/test_cache.py @@ -1,84 +1,20 @@ from min_artiq import * from numpy import int32 -# Simulate CacheError from ARTIQ -class CacheError(Exception): - pass - @nac3 -class _Cache: +class StringListTest: core: KernelInvariant[Core] - # Properly declare core_cache as a KernelInvariant - core_cache: KernelInvariant[dict[str, list[int32]]] def __init__(self): self.core = Core() - self.core_cache = {} - def build(self): - # Simplified version of EnvExperiment.build() - # Core and core_cache are already set in __init__ - pass + @kernel + def test_string_and_list(self, key: str, value: list[int32]): + print_int32(int32(42)) - @kernel - def get(self, key: str) -> list[int32]: - return self.core_cache.get(key, []) - - @kernel - def put(self, key: str, value: list[int32]): - self.core_cache[key] = value - - @kernel - def get_put(self, key: str, value: list[int32]): - self.get(key) - self.put(key, value) - -class CacheTest: - def create(self, cls): - return cls() - - def assertEqual(self, a, b): - assert a == b, f"Expected {a} to equal {b}" - - def assertRaises(self, exc_type): - class RaiseContext: - def __init__(self, test_case, expected_exc): - self.test_case = test_case - self.expected_exc = expected_exc - def __enter__(self): - return self - def __exit__(self, exc_type, exc_val, exc_tb): - if exc_type is None: - raise AssertionError(f"Expected {self.expected_exc}") - if not issubclass(exc_type, self.expected_exc): - raise AssertionError(f"Expected {self.expected_exc}, got {exc_type}") - return True - return RaiseContext(self, exc_type) - - def test_get_empty(self): - exp = self.create(_Cache) - self.assertEqual(exp.get("x1"), []) - - def test_put_get(self): - exp = self.create(_Cache) - exp.put("x2", [int32(1), int32(2), int32(3)]) - self.assertEqual(exp.get("x2"), [int32(1), int32(2), int32(3)]) - - def test_replace(self): - exp = self.create(_Cache) - exp.put("x3", [int32(1), int32(2), int32(3)]) - exp.put("x3", [int32(1), int32(2), int32(3), int32(4), int32(5)]) - self.assertEqual(exp.get("x3"), [int32(1), int32(2), int32(3), int32(4), int32(5)]) - - def test_borrow(self): - exp = self.create(_Cache) - exp.put("x4", [int32(1), int32(2), int32(3)]) - with self.assertRaises(CacheError): - exp.get_put("x4", []) +def test_params(): + exp = StringListTest() + exp.test_string_and_list("x4", []) if __name__ == "__main__": - test = CacheTest() - test.test_get_empty() - test.test_put_get() - test.test_replace() - test.test_borrow() + test_params()