Skip to content

Commit

Permalink
Match names more precisely in update_lit_checks.py (#6190)
Browse files Browse the repository at this point in the history
Previously the lit test update script interpreted module names as the names of
import items and export names as the names of export items, but it is more
precise to use the actual identifiers of the imported or exported items as the
names instead.

Update update_lit_checks.py to use a more correct regex to match names and to
correctly use the identifiers of import and export items as their names. In some
cases this can improve the readability of test output.
  • Loading branch information
tlively authored Jan 2, 2024
1 parent 98cef80 commit 95ed4f3
Show file tree
Hide file tree
Showing 39 changed files with 392 additions and 278 deletions.
20 changes: 14 additions & 6 deletions scripts/update_lit_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@
CHECK_PREFIX_RE = re.compile(r'.*--check-prefix[= ](\S+).*')
MODULE_RE = re.compile(r'^\(module.*$', re.MULTILINE)

ALL_ITEMS = '|'.join(['type', 'import', 'global', 'memory', 'data', 'table',
'elem', 'tag', 'export', 'start', 'func'])
DECL_ITEMS = '|'.join(['type', 'global', 'memory', 'data', 'table',
'elem', 'tag', 'start', 'func'])
IMPORT_ITEM = r'import\s*"[^"]*"\s*"[^"]*"\s*\((?:' + DECL_ITEMS + ')'
EXPORT_ITEM = r'export\s*"[^"]*"\s*\((?:' + DECL_ITEMS + ')'
ALL_ITEMS = DECL_ITEMS + '|' + IMPORT_ITEM + '|' + EXPORT_ITEM

# Regular names as well as the "declare" in (elem declare ... to get declarative
# segments included in the output.
ITEM_NAME = r'\$[^\s()]*|"[^\s()]*"|declare'
ITEM_NAME = r'\$[^\s()]*|\$"[^"]*"|declare'

# FIXME: This does not handle nested string contents. For example,
# (data (i32.const 10) "hello(")
Expand All @@ -55,6 +58,11 @@
FUZZ_EXEC_FUNC = re.compile(r'^\[fuzz-exec\] calling (?P<name>\S*)$')


def indentKindName(match):
# Return the indent, kind, and name from an ITEM_RE match
return (match[1], match[2].split()[0], match[3])


def warn(msg):
print(f'warning: {msg}', file=sys.stderr)

Expand Down Expand Up @@ -141,7 +149,7 @@ def parse_output_modules(text):
for module in split_modules(text):
items = []
for match in ITEM_RE.finditer(module):
kind, name = match[2], match[3]
_, kind, name = indentKindName(match)
end = find_end(module, match.end(1))
lines = module[match.start():end].split('\n')
items.append(((kind, name), lines))
Expand Down Expand Up @@ -247,7 +255,7 @@ def update_test(args, test, lines, tmp):
for line in lines:
match = ITEM_RE.match(line)
if match:
kind, name = match[2], match[3]
_, kind, name = indentKindName(match)
named_items.append((kind, name))

script = script_name
Expand Down Expand Up @@ -286,7 +294,7 @@ def pad(line):
output_lines.append(line)
continue

indent, kind, name = match.groups()
indent, kind, name = indentKindName(match)

for prefix, items in output.items():
# If the output for this prefix contains an item with this
Expand Down
9 changes: 6 additions & 3 deletions test/lit/basic/empty_imported_table.wast
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
;; RUN: cat %t.bin.nodebug.wast | filecheck %s --check-prefix=CHECK-BIN-NODEBUG

(module
;; CHECK-TEXT: (import "env" "table" (table $timport$0 0 0 funcref))
;; CHECK-BIN: (import "env" "table" (table $timport$0 0 0 funcref))
;; CHECK-BIN-NODEBUG: (import "env" "table" (table $timport$0 0 0 funcref))
(import "env" "table" (table 0 0 funcref))
;; CHECK-TEXT: (import "env" "table" (table $timport$0 0 0 funcref))

;; CHECK-TEXT: (memory $0 0)
;; CHECK-BIN: (import "env" "table" (table $timport$0 0 0 funcref))

;; CHECK-BIN: (memory $0 0)
;; CHECK-BIN-NODEBUG: (import "env" "table" (table $timport$0 0 0 funcref))

;; CHECK-BIN-NODEBUG: (memory $0 0)
(memory $0 0)
)
19 changes: 12 additions & 7 deletions test/lit/basic/export-import.wast
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,26 @@
;; CHECK-BIN: (type $v (func))
(type $v (func))
;; CHECK-TEXT: (import "env" "test2" (global $test2 i32))
;; CHECK-BIN: (import "env" "test2" (global $test2 i32))
;; CHECK-BIN-NODEBUG: (type $0 (func))

;; CHECK-BIN-NODEBUG: (import "env" "test2" (global $gimport$0 i32))
(import "env" "test1" (func $test1))
;; CHECK-TEXT: (import "env" "test1" (func $test1 (type $v)))
;; CHECK-BIN: (import "env" "test2" (global $test2 i32))

;; CHECK-BIN: (import "env" "test1" (func $test1 (type $v)))
;; CHECK-BIN-NODEBUG: (import "env" "test1" (func $fimport$0 (type $0)))
(import "env" "test1" (func $test1))
(import "env" "test2" (global $test2 i32))
;; CHECK-TEXT: (export "test1" (func $test1))
;; CHECK-BIN: (export "test1" (func $test1))
;; CHECK-BIN-NODEBUG: (export "test1" (func $fimport$0))
(export "test1" (func $test1))
;; CHECK-TEXT: (export "test2" (global $test2))
;; CHECK-BIN: (export "test2" (global $test2))
;; CHECK-BIN-NODEBUG: (export "test2" (global $gimport$0))
(export "test2" (global $test2))
)
;; CHECK-BIN-NODEBUG: (type $0 (func))

;; CHECK-BIN-NODEBUG: (import "env" "test2" (global $gimport$0 i32))

;; CHECK-BIN-NODEBUG: (import "env" "test1" (func $fimport$0 (type $0)))

;; CHECK-BIN-NODEBUG: (export "test1" (func $fimport$0))

;; CHECK-BIN-NODEBUG: (export "test2" (global $gimport$0))
3 changes: 2 additions & 1 deletion test/lit/basic/hello_world.wat
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
(memory $0 256 256)
;; CHECK-TEXT: (export "add" (func $add))
;; CHECK-BIN: (export "add" (func $add))
;; CHECK-BIN-NODEBUG: (export "add" (func $0))
(export "add" (func $add))
;; CHECK-TEXT: (func $add (type $i32_i32_=>_i32) (param $x i32) (param $y i32) (result i32)
;; CHECK-TEXT-NEXT: (i32.add
Expand All @@ -42,6 +41,8 @@
)
)
)
;; CHECK-BIN-NODEBUG: (export "add" (func $0))

;; CHECK-BIN-NODEBUG: (func $0 (type $0) (param $0 i32) (param $1 i32) (result i32)
;; CHECK-BIN-NODEBUG-NEXT: (i32.add
;; CHECK-BIN-NODEBUG-NEXT: (local.get $0)
Expand Down
11 changes: 7 additions & 4 deletions test/lit/basic/imported_memory.wast
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
(module
;; CHECK-TEXT: (import "env" "memory" (memory $0 256 256))
;; CHECK-BIN: (import "env" "memory" (memory $0 256 256))
;; CHECK-BIN-NODEBUG: (import "env" "memory" (memory $mimport$0 256 256))
(import "env" "memory" (memory $0 256 256))
;; CHECK-TEXT: (import "env" "table" (table $timport$0 256 256 funcref))
;; CHECK-BIN: (import "env" "table" (table $timport$0 256 256 funcref))
;; CHECK-BIN-NODEBUG: (import "env" "table" (table $timport$0 256 256 funcref))
(import "env" "table" (table 256 256 funcref))
)
;; CHECK-TEXT: (import "env" "table" (table $timport$0 256 256 funcref))

;; CHECK-BIN: (import "env" "table" (table $timport$0 256 256 funcref))

;; CHECK-BIN-NODEBUG: (import "env" "memory" (memory $mimport$0 256 256))

;; CHECK-BIN-NODEBUG: (import "env" "table" (table $timport$0 256 256 funcref))
11 changes: 7 additions & 4 deletions test/lit/basic/imported_memory_growth.wast
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
(module
;; CHECK-TEXT: (import "env" "memory" (memory $0 256))
;; CHECK-BIN: (import "env" "memory" (memory $0 256))
;; CHECK-BIN-NODEBUG: (import "env" "memory" (memory $mimport$0 256))
(import "env" "memory" (memory $0 256))
;; CHECK-TEXT: (import "env" "table" (table $timport$0 256 funcref))
;; CHECK-BIN: (import "env" "table" (table $timport$0 256 funcref))
;; CHECK-BIN-NODEBUG: (import "env" "table" (table $timport$0 256 funcref))
(import "env" "table" (table 256 funcref))
)
;; CHECK-TEXT: (import "env" "table" (table $timport$0 256 funcref))

;; CHECK-BIN: (import "env" "table" (table $timport$0 256 funcref))

;; CHECK-BIN-NODEBUG: (import "env" "memory" (memory $mimport$0 256))

;; CHECK-BIN-NODEBUG: (import "env" "table" (table $timport$0 256 funcref))
3 changes: 2 additions & 1 deletion test/lit/basic/memory-import.wast
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
(type $0 (func (result i32)))
;; CHECK-TEXT: (import "env" "memory" (memory $0 1 1))
;; CHECK-BIN: (import "env" "memory" (memory $0 1 1))
;; CHECK-BIN-NODEBUG: (import "env" "memory" (memory $mimport$0 1 1))
(import "env" "memory" (memory $0 1 1))

;; CHECK-TEXT: (func $foo (type $0) (result i32)
Expand All @@ -35,6 +34,8 @@
)
)
)
;; CHECK-BIN-NODEBUG: (import "env" "memory" (memory $mimport$0 1 1))

;; CHECK-BIN-NODEBUG: (func $0 (type $0) (result i32)
;; CHECK-BIN-NODEBUG-NEXT: (i32.load offset=13
;; CHECK-BIN-NODEBUG-NEXT: (i32.const 37)
Expand Down
3 changes: 2 additions & 1 deletion test/lit/basic/memory-import64.wast
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
(type $0 (func (result i32)))
;; CHECK-TEXT: (import "env" "memory" (memory $0 i64 1 1))
;; CHECK-BIN: (import "env" "memory" (memory $0 i64 1 1))
;; CHECK-BIN-NODEBUG: (import "env" "memory" (memory $mimport$0 i64 1 1))
(import "env" "memory" (memory $0 i64 1 1))

;; CHECK-TEXT: (func $foo (type $0) (result i32)
Expand All @@ -35,6 +34,8 @@
)
)
)
;; CHECK-BIN-NODEBUG: (import "env" "memory" (memory $mimport$0 i64 1 1))

;; CHECK-BIN-NODEBUG: (func $0 (type $0) (result i32)
;; CHECK-BIN-NODEBUG-NEXT: (i32.load offset=13
;; CHECK-BIN-NODEBUG-NEXT: (i64.const 37)
Expand Down
3 changes: 2 additions & 1 deletion test/lit/basic/min.wast
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
(memory $0 256 256)
;; CHECK-TEXT: (export "floats" (func $floats))
;; CHECK-BIN: (export "floats" (func $floats))
;; CHECK-BIN-NODEBUG: (export "floats" (func $0))
(export "floats" (func $floats))

;; CHECK-TEXT: (func $floats (type $0) (param $f f32) (result f32)
Expand Down Expand Up @@ -183,6 +182,8 @@
)
)
)
;; CHECK-BIN-NODEBUG: (export "floats" (func $0))

;; CHECK-BIN-NODEBUG: (func $0 (type $0) (param $0 f32) (result f32)
;; CHECK-BIN-NODEBUG-NEXT: (local $1 f32)
;; CHECK-BIN-NODEBUG-NEXT: (f32.add
Expand Down
11 changes: 6 additions & 5 deletions test/lit/basic/multi-memories-basics.wast
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
(type $none_=>_i32 (func (result i32)))
;; CHECK-TEXT: (import "env" "memory" (memory $importedMemory 1 1))
;; CHECK-BIN: (import "env" "memory" (memory $importedMemory 1 1))
;; CHECK-BIN-NODEBUG: (type $0 (func))

;; CHECK-BIN-NODEBUG: (type $1 (func (result i32)))

;; CHECK-BIN-NODEBUG: (import "env" "memory" (memory $mimport$0 1 1))
(import "env" "memory" (memory $importedMemory 1 1))
;; CHECK-TEXT: (memory $memory1 1 500)
;; CHECK-BIN: (memory $memory1 1 500)
Expand Down Expand Up @@ -367,6 +362,12 @@
)
)
)
;; CHECK-BIN-NODEBUG: (type $0 (func))

;; CHECK-BIN-NODEBUG: (type $1 (func (result i32)))

;; CHECK-BIN-NODEBUG: (import "env" "memory" (memory $mimport$0 1 1))

;; CHECK-BIN-NODEBUG: (memory $0 1 500)

;; CHECK-BIN-NODEBUG: (memory $1 1 800)
Expand Down
7 changes: 4 additions & 3 deletions test/lit/basic/multi-table.wast
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
;; CHECK-BIN: (global $g2 i32 (i32.const 0))
(global $g2 i32 (i32.const 0))

;; CHECK-BIN-NODEBUG: (type $0 (func))

;; CHECK-BIN-NODEBUG: (import "a" "b" (table $timport$0 1 10 funcref))
(import "a" "b" (table $t1 1 10 funcref))
;; CHECK-TEXT: (table $t2 3 3 funcref)
;; CHECK-BIN: (table $t2 3 3 funcref)
Expand Down Expand Up @@ -116,6 +113,10 @@
;; CHECK-BIN-NEXT: )
(func $h)
)
;; CHECK-BIN-NODEBUG: (type $0 (func))

;; CHECK-BIN-NODEBUG: (import "a" "b" (table $timport$0 1 10 funcref))

;; CHECK-BIN-NODEBUG: (global $global$0 (ref null $0) (ref.func $0))

;; CHECK-BIN-NODEBUG: (global $global$1 i32 (i32.const 0))
Expand Down
3 changes: 2 additions & 1 deletion test/lit/basic/mutable-global.wast
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
(type $0 (func))
;; CHECK-TEXT: (import "env" "global-mut" (global $global-mut (mut i32)))
;; CHECK-BIN: (import "env" "global-mut" (global $global-mut (mut i32)))
;; CHECK-BIN-NODEBUG: (import "env" "global-mut" (global $gimport$0 (mut i32)))
(import "env" "global-mut" (global $global-mut (mut i32)))

;; CHECK-TEXT: (func $foo (type $0)
Expand Down Expand Up @@ -44,6 +43,8 @@
)
)
)
;; CHECK-BIN-NODEBUG: (import "env" "global-mut" (global $gimport$0 (mut i32)))

;; CHECK-BIN-NODEBUG: (func $0 (type $0)
;; CHECK-BIN-NODEBUG-NEXT: (global.set $gimport$0
;; CHECK-BIN-NODEBUG-NEXT: (i32.add
Expand Down
25 changes: 14 additions & 11 deletions test/lit/basic/newsyntax.wast
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,13 @@
;; RUN: cat %t.bin.nodebug.wast | filecheck %s --check-prefix=CHECK-BIN-NODEBUG

(module
(import "env" "table" (table 9 9 funcref))

;; CHECK-TEXT: (type $0 (func))

;; CHECK-TEXT: (type $1 (func (param i32 f64) (result i32)))

;; CHECK-TEXT: (import "env" "table" (table $timport$0 9 9 funcref))
;; CHECK-BIN: (type $0 (func))

;; CHECK-BIN: (type $1 (func (param i32 f64) (result i32)))

;; CHECK-BIN: (import "env" "table" (table $timport$0 9 9 funcref))
;; CHECK-BIN-NODEBUG: (type $0 (func))

;; CHECK-BIN-NODEBUG: (type $1 (func (param i32 f64) (result i32)))

;; CHECK-BIN-NODEBUG: (import "env" "table" (table $timport$0 9 9 funcref))
(import "env" "table" (table 9 9 funcref))

;; CHECK-TEXT: (export "call_indirect" (func $call_indirect))

Expand All @@ -41,6 +32,12 @@
;; CHECK-TEXT-NEXT: (i32.const 1)
;; CHECK-TEXT-NEXT: )
;; CHECK-TEXT-NEXT: )
;; CHECK-BIN: (type $0 (func))

;; CHECK-BIN: (type $1 (func (param i32 f64) (result i32)))

;; CHECK-BIN: (import "env" "table" (table $timport$0 9 9 funcref))

;; CHECK-BIN: (export "call_indirect" (func $call_indirect))

;; CHECK-BIN: (func $call_indirect (type $0)
Expand All @@ -62,6 +59,12 @@
(call_indirect (i32.const 1))
)
)
;; CHECK-BIN-NODEBUG: (type $0 (func))

;; CHECK-BIN-NODEBUG: (type $1 (func (param i32 f64) (result i32)))

;; CHECK-BIN-NODEBUG: (import "env" "table" (table $timport$0 9 9 funcref))

;; CHECK-BIN-NODEBUG: (export "call_indirect" (func $0))

;; CHECK-BIN-NODEBUG: (func $0 (type $0)
Expand Down
33 changes: 18 additions & 15 deletions test/lit/basic/polymorphic_stack.wast
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,13 @@

;; CHECK-BIN: (type $FUNCSIG$ii (func (param i32) (result i32)))
(type $FUNCSIG$ii (func (param i32) (result i32)))
(import "env" "table" (table 9 9 funcref))

;; CHECK-TEXT: (type $2 (func))

;; CHECK-TEXT: (type $3 (func (param i32)))

;; CHECK-TEXT: (import "env" "table" (table $timport$0 9 9 funcref))
;; CHECK-BIN: (type $2 (func))

;; CHECK-BIN: (type $3 (func (param i32)))

;; CHECK-BIN: (import "env" "table" (table $timport$0 9 9 funcref))
;; CHECK-BIN-NODEBUG: (type $0 (func (result i32)))

;; CHECK-BIN-NODEBUG: (type $1 (func (param i32) (result i32)))

;; CHECK-BIN-NODEBUG: (type $2 (func))

;; CHECK-BIN-NODEBUG: (type $3 (func (param i32)))

;; CHECK-BIN-NODEBUG: (import "env" "table" (table $timport$0 9 9 funcref))
(import "env" "table" (table 9 9 funcref))

;; CHECK-TEXT: (func $break-and-binary (type $0) (result i32)
;; CHECK-TEXT-NEXT: (block $x (result i32)
Expand All @@ -53,6 +40,12 @@
;; CHECK-TEXT-NEXT: )
;; CHECK-TEXT-NEXT: )
;; CHECK-TEXT-NEXT: )
;; CHECK-BIN: (type $2 (func))

;; CHECK-BIN: (type $3 (func (param i32)))

;; CHECK-BIN: (import "env" "table" (table $timport$0 9 9 funcref))

;; CHECK-BIN: (func $break-and-binary (type $0) (result i32)
;; CHECK-BIN-NEXT: (block $label$1 (result i32)
;; CHECK-BIN-NEXT: (unreachable)
Expand Down Expand Up @@ -371,6 +364,16 @@
)
)
)
;; CHECK-BIN-NODEBUG: (type $0 (func (result i32)))

;; CHECK-BIN-NODEBUG: (type $1 (func (param i32) (result i32)))

;; CHECK-BIN-NODEBUG: (type $2 (func))

;; CHECK-BIN-NODEBUG: (type $3 (func (param i32)))

;; CHECK-BIN-NODEBUG: (import "env" "table" (table $timport$0 9 9 funcref))

;; CHECK-BIN-NODEBUG: (func $0 (type $0) (result i32)
;; CHECK-BIN-NODEBUG-NEXT: (block $label$1 (result i32)
;; CHECK-BIN-NODEBUG-NEXT: (unreachable)
Expand Down
Loading

0 comments on commit 95ed4f3

Please sign in to comment.