diff --git a/reframe/frontend/autodetect.py b/reframe/frontend/autodetect.py index 4a1d6d55b8..ea037be5db 100644 --- a/reframe/frontend/autodetect.py +++ b/reframe/frontend/autodetect.py @@ -183,17 +183,29 @@ def detect_topology(): getlogger().debug( f'> found topology file {topo_file!r}; loading...' ) - part.processor._info = _load_info( - topo_file, _subschema('#/defs/processor_info') - ) - found_procinfo = True + try: + part.processor._info = _load_info( + topo_file, _subschema('#/defs/processor_info') + ) + found_procinfo = True + except json.decoder.JSONDecodeError as e: + getlogger().debug( + f'> could not load {topo_file!r}: {e}: ignoring...' + ) if not found_devinfo and os.path.exists(dev_file): getlogger().debug( f'> found devices file {dev_file!r}; loading...' ) - part._devices = _load_info(dev_file, _subschema('#/defs/devices')) - found_devinfo = True + try: + part._devices = _load_info( + dev_file, _subschema('#/defs/devices') + ) + found_devinfo = True + except json.decoder.JSONDecodeError as e: + getlogger().debug( + f'> could not load {dev_file!r}: {e}: ignoring...' + ) if found_procinfo and found_devinfo: continue diff --git a/unittests/test_autodetect.py b/unittests/test_autodetect.py index 9d21f5c504..4e33f3278c 100644 --- a/unittests/test_autodetect.py +++ b/unittests/test_autodetect.py @@ -33,8 +33,32 @@ def exec_ctx(make_exec_ctx_g, tmp_path, monkeypatch): yield from make_exec_ctx_g() +@pytest.fixture +def invalid_topo_exec_ctx(make_exec_ctx_g, tmp_path, monkeypatch): + # Monkey-patch HOME, since topology is always written there + monkeypatch.setenv('HOME', str(tmp_path)) + + # Create invalid processor and devices files + meta_prefix = tmp_path / '.reframe' / 'topology' / 'generic-default' + os.makedirs(meta_prefix) + with open(meta_prefix / 'processor.json', 'w') as fp: + fp.write('{') + + with open(meta_prefix / 'devices.json', 'w') as fp: + fp.write('{') + + yield from make_exec_ctx_g() + + def test_autotect(exec_ctx): detect_topology() part = runtime().system.partitions[0] assert part.processor.info == cpuinfo() assert part.devices == [{'type': 'gpu', 'arch': 'a100', 'num_devices': 8}] + + +def test_autotect_with_invalid_files(invalid_topo_exec_ctx): + detect_topology() + part = runtime().system.partitions[0] + assert part.processor.info == cpuinfo() + assert part.devices == []