Skip to content

Commit fa2c92a

Browse files
authored
Merge branch 'master' into feat/perf-syntax
2 parents b7f926d + 7364e80 commit fa2c92a

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

reframe/frontend/autodetect.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,29 @@ def detect_topology():
183183
getlogger().debug(
184184
f'> found topology file {topo_file!r}; loading...'
185185
)
186-
part.processor._info = _load_info(
187-
topo_file, _subschema('#/defs/processor_info')
188-
)
189-
found_procinfo = True
186+
try:
187+
part.processor._info = _load_info(
188+
topo_file, _subschema('#/defs/processor_info')
189+
)
190+
found_procinfo = True
191+
except json.decoder.JSONDecodeError as e:
192+
getlogger().debug(
193+
f'> could not load {topo_file!r}: {e}: ignoring...'
194+
)
190195

191196
if not found_devinfo and os.path.exists(dev_file):
192197
getlogger().debug(
193198
f'> found devices file {dev_file!r}; loading...'
194199
)
195-
part._devices = _load_info(dev_file, _subschema('#/defs/devices'))
196-
found_devinfo = True
200+
try:
201+
part._devices = _load_info(
202+
dev_file, _subschema('#/defs/devices')
203+
)
204+
found_devinfo = True
205+
except json.decoder.JSONDecodeError as e:
206+
getlogger().debug(
207+
f'> could not load {dev_file!r}: {e}: ignoring...'
208+
)
197209

198210
if found_procinfo and found_devinfo:
199211
continue

unittests/test_autodetect.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,32 @@ def exec_ctx(make_exec_ctx_g, tmp_path, monkeypatch):
3333
yield from make_exec_ctx_g()
3434

3535

36+
@pytest.fixture
37+
def invalid_topo_exec_ctx(make_exec_ctx_g, tmp_path, monkeypatch):
38+
# Monkey-patch HOME, since topology is always written there
39+
monkeypatch.setenv('HOME', str(tmp_path))
40+
41+
# Create invalid processor and devices files
42+
meta_prefix = tmp_path / '.reframe' / 'topology' / 'generic-default'
43+
os.makedirs(meta_prefix)
44+
with open(meta_prefix / 'processor.json', 'w') as fp:
45+
fp.write('{')
46+
47+
with open(meta_prefix / 'devices.json', 'w') as fp:
48+
fp.write('{')
49+
50+
yield from make_exec_ctx_g()
51+
52+
3653
def test_autotect(exec_ctx):
3754
detect_topology()
3855
part = runtime().system.partitions[0]
3956
assert part.processor.info == cpuinfo()
4057
assert part.devices == [{'type': 'gpu', 'arch': 'a100', 'num_devices': 8}]
58+
59+
60+
def test_autotect_with_invalid_files(invalid_topo_exec_ctx):
61+
detect_topology()
62+
part = runtime().system.partitions[0]
63+
assert part.processor.info == cpuinfo()
64+
assert part.devices == []

0 commit comments

Comments
 (0)