forked from M-Labs/artiq
test: fixed lit tests
Note that because we changed exception representation from using string names as exception identifier into using integer IDs, we need to initialize the embedding map in order to allocate the integer IDs. Also, we can no longer print the exception names and messages from the kernel, we will need the host to map exception IDs to names, and may need the host to map string IDs to actual strings (messages can be static strings in the firmware, or strings stored in the host only). We now check for exception IDs for lit tests, which are fixed because we preallocated all builtin exceptions.
This commit is contained in:
parent
4132c450a5
commit
9d43762695
|
@ -50,9 +50,22 @@ class EmbeddingMap:
|
|||
self.str_forward_map = {}
|
||||
self.str_reverse_map = {}
|
||||
|
||||
self.preallocate_runtime_exception_names(["RuntimeError",
|
||||
"RTIOUnderflow",
|
||||
"RTIOOverflow",
|
||||
"RTIODestinationUnreachable",
|
||||
"DMAError",
|
||||
"I2CError",
|
||||
"CacheError",
|
||||
"SPIError",
|
||||
"0:ZeroDivisionError",
|
||||
"0:IndexError"])
|
||||
|
||||
def preallocate_runtime_exception_names(self, names):
|
||||
for i, name in enumerate(names):
|
||||
exn_id = self.store_str("0:artiq.coredevice.exceptions." + name)
|
||||
if ":" not in name:
|
||||
name = "0:artiq.coredevice.exceptions." + name
|
||||
exn_id = self.store_str(name)
|
||||
assert exn_id == i
|
||||
|
||||
def store_str(self, s):
|
||||
|
@ -754,12 +767,6 @@ class Stitcher:
|
|||
self.functions = {}
|
||||
|
||||
self.embedding_map = EmbeddingMap()
|
||||
self.embedding_map.preallocate_runtime_exception_names(["runtimeerror",
|
||||
"RTIOUnderflow",
|
||||
"RTIOOverflow",
|
||||
"RTIODestinationUnreachable",
|
||||
"DMAError",
|
||||
"I2CError"])
|
||||
self.value_map = defaultdict(lambda: [])
|
||||
self.definitely_changed = False
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ string and infers types for it using a trivial :module:`prelude`.
|
|||
|
||||
import os
|
||||
from pythonparser import source, diagnostic, parse_buffer
|
||||
from . import prelude, types, transforms, analyses, validators
|
||||
from . import prelude, types, transforms, analyses, validators, embedding
|
||||
|
||||
class Source:
|
||||
def __init__(self, source_buffer, engine=None):
|
||||
|
@ -18,7 +18,7 @@ class Source:
|
|||
self.engine = diagnostic.Engine(all_errors_are_fatal=True)
|
||||
else:
|
||||
self.engine = engine
|
||||
self.embedding_map = None
|
||||
self.embedding_map = embedding.EmbeddingMap()
|
||||
self.name, _ = os.path.splitext(os.path.basename(source_buffer.name))
|
||||
|
||||
asttyped_rewriter = transforms.ASTTypedRewriter(engine=engine,
|
||||
|
|
|
@ -2814,14 +2814,15 @@ class ARTIQIRGenerator(algorithm.Visitor):
|
|||
|
||||
format_string += ")"
|
||||
elif builtins.is_exception(value.type):
|
||||
# message may not be an actual string...
|
||||
# so we cannot really print it
|
||||
name = self.append(ir.GetAttr(value, "#__name__"))
|
||||
message = self.append(ir.GetAttr(value, "#__message__"))
|
||||
param1 = self.append(ir.GetAttr(value, "#__param0__"))
|
||||
param2 = self.append(ir.GetAttr(value, "#__param1__"))
|
||||
param3 = self.append(ir.GetAttr(value, "#__param2__"))
|
||||
|
||||
format_string += "%.*s(%.*s, %lld, %lld, %lld)"
|
||||
args += [name, message, param1, param2, param3]
|
||||
format_string += "%ld(%lld, %lld, %lld)"
|
||||
args += [name, param1, param2, param3]
|
||||
else:
|
||||
assert False
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ def catch(f):
|
|||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
# CHECK-L: ZeroDivisionError
|
||||
# CHECK-L: 8(0, 0, 0)
|
||||
catch(lambda: 1/0)
|
||||
# CHECK-L: IndexError
|
||||
# CHECK-L: 9(10, 1, 0)
|
||||
catch(lambda: [1.0][10])
|
||||
|
|
|
@ -10,7 +10,7 @@ def catch(f):
|
|||
except IndexError as ie:
|
||||
print(ie)
|
||||
|
||||
# CHECK-L: ZeroDivisionError
|
||||
# CHECK-L: 8(0, 0, 0)
|
||||
catch(lambda: 1/0)
|
||||
# CHECK-L: IndexError
|
||||
# CHECK-L: 9(10, 1, 0)
|
||||
catch(lambda: [1.0][10])
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# REQUIRES: exceptions
|
||||
|
||||
def f():
|
||||
# CHECK-L: Uncaught 0:ZeroDivisionError
|
||||
# CHECK-L: Uncaught 8
|
||||
# CHECK-L: at input.py:${LINE:+1}:
|
||||
1/0
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ def g():
|
|||
try:
|
||||
f()
|
||||
except Exception as e:
|
||||
# CHECK-L: Uncaught 0:ZeroDivisionError
|
||||
# CHECK-L: Uncaught 8
|
||||
# CHECK-L: at input.py:${LINE:+1}:
|
||||
raise e
|
||||
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
# RUN: OutputCheck %s --file-to-check=%t
|
||||
# REQUIRES: exceptions
|
||||
|
||||
# CHECK-L: Uncaught 0:ZeroDivisionError: cannot divide by zero (0, 0, 0)
|
||||
# CHECK-L: Uncaught 8: cannot divide by zero (0, 0, 0)
|
||||
# CHECK-L: at input.py:${LINE:+1}:
|
||||
1/0
|
||||
|
|
Loading…
Reference in New Issue