forked from EESSI/software-layer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
82 lines (58 loc) · 3.05 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import os
import pytest
import re
import eessi_software_subdir_for_host
from eessi_software_subdir_for_host import find_best_target
def prep_tmpdir(tmpdir, subdirs):
for subdir in subdirs:
os.makedirs(os.path.join(tmpdir, 'software', subdir), exist_ok=True)
def test_prefix_does_not_exist(capsys, tmpdir):
"""Test whether non-existing prefix results in error."""
with pytest.raises(SystemExit):
find_best_target(tmpdir)
captured = capsys.readouterr()
assert captured.out == ''
assert re.match('^ERROR: Specified prefix ".*/software" does not exist!$', captured.err)
def test_no_targets(tmpdir, capsys):
"""Test case where no compatible targets are found for host CPU."""
prep_tmpdir(tmpdir, [''])
with pytest.raises(SystemExit):
find_best_target(tmpdir)
captured = capsys.readouterr()
assert captured.out == ''
assert re.match('^ERROR: No targets found for .*', captured.err)
def test_broadwell_host(tmpdir, capsys, monkeypatch):
"""Test selecting of target on a Broadwell host."""
def broadwell_host_triple():
return ('x86_64', 'intel', 'broadwell')
monkeypatch.setattr(eessi_software_subdir_for_host, 'det_host_triple', broadwell_host_triple)
# if generic is there, that's always a match
prep_tmpdir(tmpdir, ['x86_64/generic'])
assert find_best_target(tmpdir) == 'x86_64/generic'
# targets from other CPU familues have no impact on target picked for Intel host CPU
prep_tmpdir(tmpdir, ['x86_64/amd/zen2', 'aarch64/graviton2', 'ppc64le/power9'])
assert find_best_target(tmpdir) == 'x86_64/generic'
# incompatible targets are not picked
prep_tmpdir(tmpdir, ['x86_64/intel/skylake', 'x86_64/intel/cascadelake'])
assert find_best_target(tmpdir) == 'x86_64/generic'
# compatible targets are picked if no better match is available
prep_tmpdir(tmpdir, ['x86_64/intel/nehalem'])
assert find_best_target(tmpdir) == 'x86_64/intel/nehalem'
prep_tmpdir(tmpdir, ['x86_64/intel/ivybridge'])
assert find_best_target(tmpdir) == 'x86_64/intel/ivybridge'
# unknown targets don't cause trouble (only warning)
prep_tmpdir(tmpdir, ['x86_64/intel/no_such_intel_cpu'])
assert find_best_target(tmpdir) == 'x86_64/intel/ivybridge'
captured = capsys.readouterr()
assert captured.out == ''
assert captured.err == 'WARNING: Ignoring unknown target "no_such_intel_cpu"\n'
# older targets have to no impact on best target (sandybridge < ivybridge)
prep_tmpdir(tmpdir, ['x86_64/intel/sandybridge'])
assert find_best_target(tmpdir) == 'x86_64/intel/ivybridge'
prep_tmpdir(tmpdir, ['x86_64/intel/haswell'])
assert find_best_target(tmpdir) == 'x86_64/intel/haswell'
expected = ['cascadelake', 'haswell', 'ivybridge', 'nehalem', 'no_such_intel_cpu', 'sandybridge', 'skylake']
assert sorted(os.listdir(os.path.join(tmpdir, 'software', 'x86_64', 'intel'))) == expected
# exact match, no better target than this
prep_tmpdir(tmpdir, ['x86_64/intel/broadwell'])
assert find_best_target(tmpdir) == 'x86_64/intel/broadwell'