-
Notifications
You must be signed in to change notification settings - Fork 836
Add initial script to generate relaxed atomics spec test #8220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+154
−0
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0c37e1b
Add script to generate spec test
stevenfontanella 4f65e35
Generate tests with binary templates, add more in-depth test
stevenfontanella 83b2358
Cleanup
stevenfontanella cabf236
Fix section length calculation
stevenfontanella 39fa146
Add some comments
stevenfontanella 65d951c
Fix mask for ordering and memidx
stevenfontanella e718222
Add text tests including correct handling of i32 and i64 memories
stevenfontanella 9c1509b
Merge branch 'main' into generate-spec-test
stevenfontanella 5fd89b7
Add comment
stevenfontanella 8b14835
Add comment to script output
stevenfontanella a7e04db
Add comment that the test is auto-generated
stevenfontanella File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import enum | ||
| from dataclasses import dataclass | ||
| from enum import Enum | ||
|
|
||
| # Workaround for python <3.10, escape characters can't appear in f-strings. | ||
| # Although we require 3.10 in some places, the formatter complains without this. | ||
| newline = "\n" | ||
|
|
||
|
|
||
| def indent(s): | ||
| return "\n".join(f" {line}" if line else "" for line in s.split("\n")) | ||
|
|
||
|
|
||
| class ValueType(Enum): | ||
| i32 = enum.auto() | ||
| i64 = enum.auto() | ||
|
|
||
|
|
||
| class Ordering(Enum): | ||
| seqcst = 0 | ||
| acqrel = 1 | ||
|
|
||
|
|
||
| @dataclass | ||
| class Template: | ||
| str: str | ||
| value_type: object | ||
| args: int | ||
|
|
||
|
|
||
| templates = [ | ||
| Template(str="(drop (i32.atomic.load %(memarg)s%(args)s))", value_type=ValueType.i32, args=1), | ||
| Template(str="(drop (i64.atomic.load %(memarg)s%(args)s))", value_type=ValueType.i64, args=1), | ||
| Template(str="(i32.atomic.store %(memarg)s%(args)s)", value_type=ValueType.i32, args=2), | ||
| Template(str="(i64.atomic.store %(memarg)s%(args)s)", value_type=ValueType.i64, args=2), | ||
| ] | ||
|
|
||
|
|
||
| def statement(template, mem_idx: str | None, ordering: Ordering | None): | ||
| """Return a statement exercising the op in `template` e.g. (i32.atomic.store 1 acqrel (i64.const 42) (i32.const 42))""" | ||
| memargs = [] | ||
| if mem_idx is not None: | ||
| memargs.append(mem_idx) | ||
| if ordering is not None: | ||
| memargs.append(ordering.name) | ||
|
|
||
| memarg_str = " ".join(memargs) + " " if memargs else "" | ||
| idx_type = ValueType.i64 if mem_idx == "1" else ValueType.i32 if mem_idx == "0" else ValueType.i32 | ||
|
|
||
| # The first argument (the memory location) must match the memory that we're indexing. Other arguments match the op (e.g. i32 for i32.atomic.load). | ||
| args = [f"({idx_type.name}.const 42)"] + [f"({template.value_type.name}.const 42)" for _ in range(template.args - 1)] | ||
| return template.str % {"memarg": memarg_str, "args": " ".join(args)} | ||
|
|
||
|
|
||
| def func(): | ||
| """Return a func exercising all ops in `templates` e.g. | ||
| (func $test-all-ops | ||
| (drop (i32.atomic.load (i32.const 42))) | ||
| (drop (i32.atomic.load acqrel (i32.const 42))) | ||
| ... | ||
| ) | ||
| """ | ||
| statements = [statement(template, mem_idx, ordering) for template in templates for mem_idx in [None, "0", "1"] for ordering in [None, Ordering.acqrel, Ordering.seqcst]] | ||
| return f''';; Memory index must come before memory ordering if present. | ||
| ;; Both immediates are optional; an ommitted memory ordering will be treated as seqcst. | ||
| (func $test-all-ops | ||
| {indent(newline.join(statements))} | ||
| )''' | ||
|
|
||
|
|
||
| def text_test(): | ||
| """Return a (module ...) that exercises all ops in `templates`.""" | ||
| return f'''(module | ||
| (memory i32 1 1) | ||
| (memory i64 1 1) | ||
|
|
||
| {indent(func())} | ||
| )''' | ||
|
|
||
|
|
||
| def invalid_text_test(): | ||
| return '''(assert_invalid (module | ||
| (memory 1 1 shared) | ||
|
|
||
| (func $i32load (drop (i32.load acqrel (i32.const 51)))) | ||
| ) "Can't set memory ordering for non-atomic i32.load")''' | ||
|
|
||
|
|
||
| def main(): | ||
| print(";; Generated by scripts/test/generate-atomic-spec-test.py. Do not edit manually.") | ||
| print() | ||
| print(text_test()) | ||
| print() | ||
| print(invalid_text_test()) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| ;; Generated by scripts/test/generate-atomic-spec-test.py. Do not edit manually. | ||
|
|
||
| (module | ||
| (memory i32 1 1) | ||
| (memory i64 1 1) | ||
|
|
||
| ;; Memory index must come before memory ordering if present. | ||
| ;; Both immediates are optional; an ommitted memory ordering will be treated as seqcst. | ||
| (func $test-all-ops | ||
| (drop (i32.atomic.load (i32.const 42))) | ||
| (drop (i32.atomic.load acqrel (i32.const 42))) | ||
| (drop (i32.atomic.load seqcst (i32.const 42))) | ||
| (drop (i32.atomic.load 0 (i32.const 42))) | ||
| (drop (i32.atomic.load 0 acqrel (i32.const 42))) | ||
| (drop (i32.atomic.load 0 seqcst (i32.const 42))) | ||
| (drop (i32.atomic.load 1 (i64.const 42))) | ||
| (drop (i32.atomic.load 1 acqrel (i64.const 42))) | ||
| (drop (i32.atomic.load 1 seqcst (i64.const 42))) | ||
| (drop (i64.atomic.load (i32.const 42))) | ||
| (drop (i64.atomic.load acqrel (i32.const 42))) | ||
| (drop (i64.atomic.load seqcst (i32.const 42))) | ||
| (drop (i64.atomic.load 0 (i32.const 42))) | ||
| (drop (i64.atomic.load 0 acqrel (i32.const 42))) | ||
| (drop (i64.atomic.load 0 seqcst (i32.const 42))) | ||
| (drop (i64.atomic.load 1 (i64.const 42))) | ||
| (drop (i64.atomic.load 1 acqrel (i64.const 42))) | ||
| (drop (i64.atomic.load 1 seqcst (i64.const 42))) | ||
| (i32.atomic.store (i32.const 42) (i32.const 42)) | ||
| (i32.atomic.store acqrel (i32.const 42) (i32.const 42)) | ||
| (i32.atomic.store seqcst (i32.const 42) (i32.const 42)) | ||
| (i32.atomic.store 0 (i32.const 42) (i32.const 42)) | ||
| (i32.atomic.store 0 acqrel (i32.const 42) (i32.const 42)) | ||
| (i32.atomic.store 0 seqcst (i32.const 42) (i32.const 42)) | ||
| (i32.atomic.store 1 (i64.const 42) (i32.const 42)) | ||
| (i32.atomic.store 1 acqrel (i64.const 42) (i32.const 42)) | ||
| (i32.atomic.store 1 seqcst (i64.const 42) (i32.const 42)) | ||
| (i64.atomic.store (i32.const 42) (i64.const 42)) | ||
| (i64.atomic.store acqrel (i32.const 42) (i64.const 42)) | ||
| (i64.atomic.store seqcst (i32.const 42) (i64.const 42)) | ||
| (i64.atomic.store 0 (i32.const 42) (i64.const 42)) | ||
| (i64.atomic.store 0 acqrel (i32.const 42) (i64.const 42)) | ||
| (i64.atomic.store 0 seqcst (i32.const 42) (i64.const 42)) | ||
| (i64.atomic.store 1 (i64.const 42) (i64.const 42)) | ||
| (i64.atomic.store 1 acqrel (i64.const 42) (i64.const 42)) | ||
| (i64.atomic.store 1 seqcst (i64.const 42) (i64.const 42)) | ||
| ) | ||
| ) | ||
|
|
||
| (assert_invalid (module | ||
| (memory 1 1 shared) | ||
|
|
||
| (func $i32load (drop (i32.load acqrel (i32.const 51)))) | ||
| ) "Can't set memory ordering for non-atomic i32.load") | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.