Repository navigation
NeXus hint: version-neutral (libNeXus before McCode#2895, HDF5 after) #406
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
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| """The --verbose NeXus compile hint must warn when the configured flags name | ||
| the wrong library for the in-use McCode libc: NeXus before mccode-dev/McCode#2895, | ||
| HDF5 after (the change the libc made at v3.10.1), regardless of whether the | ||
| flags use gcc/clang '-l' syntax or MSVC '.lib' filenames. See #405. | ||
| """ | ||
| import pytest | ||
|
|
||
| from mccode_antlr.translators.c import CTargetVisitor | ||
|
|
||
|
|
||
| class FakeRegistry: | ||
| def __init__(self, name, version): | ||
| self.name = name | ||
| self.version = version | ||
|
|
||
|
|
||
| class FakeSource: | ||
| def __init__(self, registries): | ||
| self.registries = registries | ||
|
|
||
|
|
||
| def visitor_with_registries(*registries): | ||
| visitor = CTargetVisitor.__new__(CTargetVisitor) | ||
| visitor.source = FakeSource(list(registries)) | ||
| return visitor | ||
|
|
||
|
|
||
| @pytest.mark.parametrize('version, boundary, expected', [ | ||
| ('3.10.0', '3.10.1', True), | ||
| ('3.10.1', '3.10.1', False), | ||
| ('3.11.0', '3.10.1', False), | ||
| ('3.5.19', '3.5.20', True), | ||
| ('3.5.20', '3.5.20', False), | ||
| ]) | ||
| def test_libc_before_compares_the_libc_registrys_own_version(version, boundary, expected): | ||
| visitor = visitor_with_registries(FakeRegistry('libc', version), FakeRegistry('mcstas', '9.9.9')) | ||
| assert visitor._libc_before(boundary) is expected | ||
|
|
||
|
|
||
| def test_libc_before_is_false_when_no_libc_registry_is_present(): | ||
| visitor = visitor_with_registries(FakeRegistry('mcstas', '9.9.9')) | ||
| assert visitor._libc_before('3.10.1') is False | ||
|
|
||
|
|
||
| INSTR = """DEFINE INSTRUMENT quiet(dummy=0) | ||
| TRACE | ||
| COMPONENT origin = Arm() AT (0, 0, 0) ABSOLUTE | ||
| END | ||
| """ | ||
|
|
||
|
|
||
| def build_with_libc_version(libc_version, caplog): | ||
| from mccode_antlr import Flavor | ||
| from mccode_antlr.loader import parse_mcstas_instr | ||
|
|
||
| caplog.set_level('INFO', logger='mccode_antlr') | ||
| instr = parse_mcstas_instr(INSTR) | ||
| for reg in instr.registries: | ||
| if reg.name == 'libc': | ||
| reg.version = libc_version | ||
| config = dict(default_main=True, enable_trace=False, portable=False, | ||
| include_runtime=True, embed_instrument_file=False) | ||
| CTargetVisitor(instr, flavor=Flavor.MCSTAS, config=config, verbose=True).contents() | ||
|
|
||
|
|
||
| def run_with_flags(nexus_flags, libc_version, caplog): | ||
| from mccode_antlr.config import config | ||
|
|
||
| config.set({'flags': {'nexus': nexus_flags}}) | ||
| try: | ||
| build_with_libc_version(libc_version, caplog) | ||
| finally: | ||
| config.sources.pop(0) | ||
| # ignore unrelated warnings, e.g. registry.py's "specified more than once" from | ||
| # overwriting the real libc registry's version for this test | ||
| return [r.getMessage() for r in caplog.records | ||
| if r.levelname == 'WARNING' and r.name == 'mccode_antlr.translators.c'] | ||
|
|
||
|
|
||
| # gcc/clang (Linux, macOS) spell the library as a '-l' linker flag; MSVC (Windows) | ||
| # names the .lib file directly -- the hint must not assume either syntax, only that | ||
| # the library's name ('NeXus' or 'hdf5') appears somewhere in the configured flags. | ||
| @pytest.mark.parametrize('nexus_flags', [ | ||
| '-DUSE_NEXUS -lNeXus', # Linux/macOS, pre-#2895 McCode | ||
| '/DUSE_NEXUS NeXus.lib', # Windows, pre-#2895 McCode | ||
| ]) | ||
| def test_hint_warns_when_post_2895_libc_is_paired_with_nexus_flags(nexus_flags, caplog): | ||
| warnings = run_with_flags(nexus_flags, '3.10.1', caplog) | ||
| assert any('HDF5' in m for m in warnings), warnings | ||
|
|
||
|
|
||
| @pytest.mark.parametrize('hdf5_flags', [ | ||
| '-DUSE_NEXUS -lhdf5', # Linux/macOS, post-#2895 McCode | ||
| '/DUSE_NEXUS hdf5.lib', # Windows, post-#2895 McCode | ||
| ]) | ||
| def test_hint_is_quiet_when_post_2895_libc_is_paired_with_hdf5_flags(hdf5_flags, caplog): | ||
| warnings = run_with_flags(hdf5_flags, '3.10.1', caplog) | ||
| assert warnings == [] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize('nexus_flags', [ | ||
| '-DUSE_NEXUS -lNeXus', # Linux/macOS, pre-#2895 McCode | ||
| '/DUSE_NEXUS NeXus.lib', # Windows, pre-#2895 McCode | ||
| ]) | ||
| def test_hint_is_quiet_when_pre_2895_libc_is_paired_with_nexus_flags(nexus_flags, caplog): | ||
| warnings = run_with_flags(nexus_flags, '3.10.0', caplog) | ||
| assert warnings == [] |
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.