Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions reframe/frontend/autodetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions unittests/test_autodetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == []