-
Notifications
You must be signed in to change notification settings - Fork 4
Support for .rs files in kmir run #1081
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
34fe7e8
Added option to run with .rs in kmir run
mariaKt cfb16c8
Error message when input is not provided.
mariaKt 0132f79
Used single positional argument for input, --smir and --bin are flags.
mariaKt b5a8584
Updated documentation.
mariaKt 533ecc2
Code quality fixes
mariaKt 6a9f8f2
Rename ui tests script that uses prove, add script that uses run.
mariaKt 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
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
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
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,85 @@ | ||
| """Run stable-mir-ui tests using kmir run (LLVM backend). | ||
|
|
||
| For each test in passing.tsv, compiles the .rs file to SMIR JSON, | ||
| runs it with the LLVM backend, and checks that execution reaches #EndProgram. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import tempfile | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from kmir.cargo import cargo_get_smir_json | ||
| from kmir.kmir import KMIR | ||
| from kmir.smir import SMIRInfo | ||
|
|
||
| THIS_DIR = Path(__file__).resolve().parent | ||
| REPO_ROOT = THIS_DIR.parents[3] | ||
| PASSING_TSV = REPO_ROOT / 'deps' / 'stable-mir-json' / 'tests' / 'ui' / 'passing.tsv' | ||
| SKIP_FILE = THIS_DIR / 'data' / 'stable-mir-ui' / 'skip.txt' | ||
| PASSING_TESTS: tuple[str, ...] = tuple( | ||
| line.split('\t', maxsplit=1)[0] for line in PASSING_TSV.read_text().splitlines() if line.strip() | ||
| ) | ||
| SKIP_ENTRIES: frozenset[str] = ( | ||
| frozenset(line for line in SKIP_FILE.read_text().splitlines() if line.strip()) | ||
| if SKIP_FILE.is_file() | ||
| else frozenset() | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(scope='session') | ||
| def rust_dir_root() -> Path: | ||
| rust_dir_root_raw = os.environ.get('RUST_DIR_ROOT') | ||
| if not rust_dir_root_raw: | ||
| pytest.fail( | ||
| 'RUST_DIR_ROOT is required. Example: RUST_DIR_ROOT=/path/to/rust ./run-ui-tests.sh', | ||
| pytrace=False, | ||
| ) | ||
|
|
||
| rust_dir_root = Path(rust_dir_root_raw).expanduser().resolve() | ||
| if not rust_dir_root.is_dir(): | ||
| pytest.fail(f'RUST_DIR_ROOT is not a directory: {rust_dir_root}', pytrace=False) | ||
|
|
||
| return rust_dir_root | ||
|
|
||
|
|
||
| @pytest.mark.timeout(300) | ||
| @pytest.mark.parametrize('test_rel_path', PASSING_TESTS, ids=PASSING_TESTS) | ||
| def test_stable_mir_ui_exec(test_rel_path: str, rust_dir_root: Path, update_skip_mode: bool, tmp_path: Path) -> None: | ||
| if (test_rel_path in SKIP_ENTRIES) != update_skip_mode: | ||
| pytest.skip() | ||
|
|
||
| rs_file = rust_dir_root / test_rel_path | ||
|
|
||
| try: | ||
| smir_data = cargo_get_smir_json(rs_file, save_smir=False) | ||
| smir_info = SMIRInfo(smir_data) | ||
| except Exception: | ||
| if update_skip_mode: | ||
| pytest.xfail('Compilation error') | ||
| raise | ||
|
|
||
| try: | ||
| with tempfile.TemporaryDirectory() as target_dir: | ||
| kmir = KMIR.from_kompiled_kore(smir_info, target_dir=Path(target_dir), symbolic=False) | ||
| result = kmir.run_smir(smir_info) | ||
| result_pretty = kmir.kore_to_pretty(result) | ||
| except Exception: | ||
| if update_skip_mode: | ||
| pytest.xfail('Execution error') | ||
| raise | ||
|
|
||
| reached_end = '#EndProgram ~> .K' in result_pretty | ||
|
|
||
| if update_skip_mode: | ||
| if not reached_end: | ||
| pytest.xfail('Did not reach #EndProgram') | ||
| return | ||
|
|
||
| if not reached_end: | ||
| output_file = tmp_path / 'show.txt' | ||
| output_file.write_text(result_pretty) | ||
| raise AssertionError(f'Execution did not reach #EndProgram. See: {output_file}') |
File renamed without changes.
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally, I was thinking a run would always invoke a Rust program from the default entry point (typically
main), but I tested this on sum-to-n-functions.rs and it works with start symbol of either "main" or "test_sum_to_n" which is actually quite nice. I wasn't sure what would happen if it was pointed to "sum_to_n" (since that takes arguments which we would have to somehow instantiate) but it failed with a nice error