Repository navigation
test(converter): exercise real LLVM region reports (DEV-85) #22
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
7 commits
Select commit
Hold shift + click to select a range
223ca1e
Add LLVM region compatibility regression test
developjik 6bf493c
Create test-converter-llvm.py
developjik 6fe0fc7
Update README.md
developjik 0974e94
Update test-converter-llvm.py
developjik add0b09
Add converter-llvm-evidence to coverage paths
developjik 169f949
Update test-converter-llvm.py
developjik be56709
Update test-converter-llvm.py
developjik 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| #!/usr/bin/env python3 | ||
| """Compile a tiny real LLVM coverage case, including same-line/multiline regions.""" | ||
| from pathlib import Path | ||
| import os | ||
| import subprocess | ||
| import tempfile | ||
| import shutil | ||
|
|
||
| checker = Path(__file__).with_name('check-converter-coverage.py') | ||
| with tempfile.TemporaryDirectory(prefix='converter-llvm-') as folder: | ||
| root = Path(folder) | ||
| source = root / 'src-tauri/src/converter/mod.rs' | ||
| source.parent.mkdir(parents=True) | ||
| source.write_text('''pub fn choose(x: bool) -> i32 { | ||
| let base = if x { 1 } else { 2 }; | ||
| let mut total = 0; | ||
| for n in 0..3 { total += n; } | ||
| if x { | ||
| total += base; | ||
| } else { | ||
| total -= base; | ||
| } | ||
| total | ||
| } | ||
| #[cfg(test)] | ||
| mod tests { | ||
| #[test] | ||
| fn both_paths() { assert_eq!(super::choose(true), 4); assert_eq!(super::choose(false), 1); } | ||
| } | ||
| ''') | ||
| (root / 'Cargo.toml').write_text('''[package] | ||
| name = "llvm-gate-fixture" | ||
| version = "0.0.0" | ||
| edition = "2024" | ||
| [lib] | ||
| path = "src-tauri/src/converter/mod.rs" | ||
| [workspace] | ||
| ''') | ||
| (root / 'scripts').mkdir() | ||
| target = root / 'scripts/check-converter-coverage.py' | ||
| target.write_text(checker.read_text()) | ||
| # Do not inherit the parent crate's instrumentation directories. | ||
| env = {k:v for k,v in os.environ.items() if not k.startswith(('CARGO_LLVM_COV_', 'LLVM_PROFILE_FILE', 'CARGO_TARGET_DIR', 'RUSTFLAGS', 'RUSTDOCFLAGS'))} | ||
| evidence = checker.parent.parent / 'converter-llvm-evidence' | ||
| evidence.mkdir(exist_ok=True) | ||
| shutil.copy(source, evidence / 'fixture.rs') | ||
| subprocess.run(['cargo','+stable','llvm-cov','--lcov','--output-path','coverage.lcov'],cwd=root,env=env,check=True) | ||
| subprocess.run(['cargo','+stable','llvm-cov','report','--json','--output-path','coverage.json'],cwd=root,env=env,check=True) | ||
| for name in ['coverage.lcov', 'coverage.json']: | ||
| shutil.copy(root / name, evidence / name) | ||
| shutil.copy(checker, evidence / 'check-converter-coverage.py') | ||
| (evidence / 'replay.py').write_text("""from pathlib import Path | ||
| import json, subprocess, tempfile | ||
| here = Path(__file__).resolve().parent | ||
| with tempfile.TemporaryDirectory() as folder: | ||
| root = Path(folder) | ||
| target = root / 'src-tauri/src/converter/mod.rs' | ||
| target.parent.mkdir(parents=True) | ||
| target.write_bytes((here / 'fixture.rs').read_bytes()) | ||
| (root / 'scripts').mkdir() | ||
| gate = root / 'scripts/check-converter-coverage.py' | ||
| gate.write_bytes((here / gate.name).read_bytes()) | ||
| data = json.loads((here / 'coverage.json').read_text()) | ||
| original = next(item['filename'] for run in data['data'] for item in run['files'] if item['filename'].endswith('/src-tauri/src/converter/mod.rs')) | ||
| # Preserve raw evidence; rewrite only temporary replay copies. | ||
| lcov = (here / 'coverage.lcov').read_text().replace(original, str(target)) | ||
| (root / 'coverage.lcov').write_text(lcov) | ||
| fixture_record = next(record for record in lcov.split('end_of_record') if str(target) in record) | ||
| hits = {int(line[3:].split(',')[0]):int(line.split(',')[1]) for line in fixture_record.splitlines() if line.startswith('DA:')} | ||
| assert all(hits.get(line,0)>0 for line in [1,2,3,4,5,6,8,10,11]), hits | ||
| for run in data['data']: | ||
| for item in run['files']: | ||
| if item['filename'] == original: item['filename'] = str(target) | ||
| (root / 'coverage.json').write_text(json.dumps(data)) | ||
| subprocess.run(['python3', str(gate), str(root / 'coverage.lcov'), str(root / 'coverage.json')], check=True) | ||
|
devin-ai-integration[bot] marked this conversation as resolved.
Resolved
|
||
| """) | ||
| subprocess.run(['python3', str(evidence / 'replay.py')], check=True) | ||
| # Explicit source-line oracle, independent of the format bridge. | ||
| records = (root / 'coverage.lcov').read_text().split('end_of_record') | ||
| record = next(record for record in records if str(source) in record) | ||
| measured = {int(line[3:].split(',')[0]): int(line.split(',')[1]) for line in record.splitlines() if line.startswith('DA:')} | ||
| assert all(measured.get(line, 0) > 0 for line in [1, 2, 3, 4, 5, 6, 8, 10, 11]), measured | ||
| subprocess.run(['python3',str(target),'coverage.lcov','coverage.json'],cwd=root,check=True) | ||
|
developjik marked this conversation as resolved.
Resolved
|
||
| print('Real LLVM region/LCOV compatibility passed') | ||
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.