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:
pca006132 2022-01-25 15:15:57 +08:00 committed by Sébastien Bourdeauducq
parent 4132c450a5
commit 9d43762695
8 changed files with 27 additions and 19 deletions

View File

@ -50,9 +50,22 @@ class EmbeddingMap:
self.str_forward_map = {} self.str_forward_map = {}
self.str_reverse_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): def preallocate_runtime_exception_names(self, names):
for i, name in enumerate(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 assert exn_id == i
def store_str(self, s): def store_str(self, s):
@ -754,12 +767,6 @@ class Stitcher:
self.functions = {} self.functions = {}
self.embedding_map = EmbeddingMap() self.embedding_map = EmbeddingMap()
self.embedding_map.preallocate_runtime_exception_names(["runtimeerror",
"RTIOUnderflow",
"RTIOOverflow",
"RTIODestinationUnreachable",
"DMAError",
"I2CError"])
self.value_map = defaultdict(lambda: []) self.value_map = defaultdict(lambda: [])
self.definitely_changed = False self.definitely_changed = False

View File

@ -10,7 +10,7 @@ string and infers types for it using a trivial :module:`prelude`.
import os import os
from pythonparser import source, diagnostic, parse_buffer from pythonparser import source, diagnostic, parse_buffer
from . import prelude, types, transforms, analyses, validators from . import prelude, types, transforms, analyses, validators, embedding
class Source: class Source:
def __init__(self, source_buffer, engine=None): def __init__(self, source_buffer, engine=None):
@ -18,7 +18,7 @@ class Source:
self.engine = diagnostic.Engine(all_errors_are_fatal=True) self.engine = diagnostic.Engine(all_errors_are_fatal=True)
else: else:
self.engine = engine self.engine = engine
self.embedding_map = None self.embedding_map = embedding.EmbeddingMap()
self.name, _ = os.path.splitext(os.path.basename(source_buffer.name)) self.name, _ = os.path.splitext(os.path.basename(source_buffer.name))
asttyped_rewriter = transforms.ASTTypedRewriter(engine=engine, asttyped_rewriter = transforms.ASTTypedRewriter(engine=engine,

View File

@ -2814,14 +2814,15 @@ class ARTIQIRGenerator(algorithm.Visitor):
format_string += ")" format_string += ")"
elif builtins.is_exception(value.type): 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__")) name = self.append(ir.GetAttr(value, "#__name__"))
message = self.append(ir.GetAttr(value, "#__message__"))
param1 = self.append(ir.GetAttr(value, "#__param0__")) param1 = self.append(ir.GetAttr(value, "#__param0__"))
param2 = self.append(ir.GetAttr(value, "#__param1__")) param2 = self.append(ir.GetAttr(value, "#__param1__"))
param3 = self.append(ir.GetAttr(value, "#__param2__")) param3 = self.append(ir.GetAttr(value, "#__param2__"))
format_string += "%.*s(%.*s, %lld, %lld, %lld)" format_string += "%ld(%lld, %lld, %lld)"
args += [name, message, param1, param2, param3] args += [name, param1, param2, param3]
else: else:
assert False assert False

View File

@ -8,7 +8,7 @@ def catch(f):
except Exception as e: except Exception as e:
print(e) print(e)
# CHECK-L: ZeroDivisionError # CHECK-L: 8(0, 0, 0)
catch(lambda: 1/0) catch(lambda: 1/0)
# CHECK-L: IndexError # CHECK-L: 9(10, 1, 0)
catch(lambda: [1.0][10]) catch(lambda: [1.0][10])

View File

@ -10,7 +10,7 @@ def catch(f):
except IndexError as ie: except IndexError as ie:
print(ie) print(ie)
# CHECK-L: ZeroDivisionError # CHECK-L: 8(0, 0, 0)
catch(lambda: 1/0) catch(lambda: 1/0)
# CHECK-L: IndexError # CHECK-L: 9(10, 1, 0)
catch(lambda: [1.0][10]) catch(lambda: [1.0][10])

View File

@ -3,7 +3,7 @@
# REQUIRES: exceptions # REQUIRES: exceptions
def f(): def f():
# CHECK-L: Uncaught 0:ZeroDivisionError # CHECK-L: Uncaught 8
# CHECK-L: at input.py:${LINE:+1}: # CHECK-L: at input.py:${LINE:+1}:
1/0 1/0

View File

@ -9,7 +9,7 @@ def g():
try: try:
f() f()
except Exception as e: except Exception as e:
# CHECK-L: Uncaught 0:ZeroDivisionError # CHECK-L: Uncaught 8
# CHECK-L: at input.py:${LINE:+1}: # CHECK-L: at input.py:${LINE:+1}:
raise e raise e

View File

@ -2,6 +2,6 @@
# RUN: OutputCheck %s --file-to-check=%t # RUN: OutputCheck %s --file-to-check=%t
# REQUIRES: exceptions # 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}: # CHECK-L: at input.py:${LINE:+1}:
1/0 1/0