Skip to content
Merged
15 changes: 12 additions & 3 deletions easybuild/tools/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
from easybuild.tools.toolchain.compiler import DEFAULT_OPT_LEVEL, OPTARCH_MAP_CHAR, OPTARCH_SEP, Compiler
from easybuild.tools.toolchain.toolchain import SYSTEM_TOOLCHAIN_NAME
from easybuild.tools.repository.repository import avail_repositories
from easybuild.tools.systemtools import check_python_version, get_cpu_architecture, get_cpu_family, get_cpu_features
from easybuild.tools.systemtools import get_system_info
from easybuild.tools.systemtools import UNKNOWN, check_python_version, get_cpu_architecture, get_cpu_family
from easybuild.tools.systemtools import get_cpu_features, get_system_info
from easybuild.tools.version import this_is_easybuild


Expand Down Expand Up @@ -1153,6 +1153,7 @@ def show_system_info(self):
"""Show system information."""
system_info = get_system_info()
cpu_features = get_cpu_features()
cpu_arch_name = system_info['cpu_arch_name']
lines = [
"System information (%s):" % system_info['hostname'],
'',
Expand All @@ -1166,6 +1167,13 @@ def show_system_info(self):
" -> vendor: %s" % system_info['cpu_vendor'],
" -> architecture: %s" % get_cpu_architecture(),
" -> family: %s" % get_cpu_family(),
]
if cpu_arch_name == UNKNOWN:
lines.append(" -> arch name: UNKNOWN (archspec is not installed?)")
else:
lines.append(" -> arch name: %s" % cpu_arch_name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a small inconsistency... if here you mean exactly this, then without archspec it will still be printed, but UNKNOWN, and in test_show_system_info there is no reason to check for HAVE_ARCHSPEC, since the pattern will always be there

otherwise this should be if cpu_arch_name != UNKNOWN, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should hint that archspec is not installed when cpu_arch__name == UNKNOWN?


lines.extend([
" -> model: %s" % system_info['cpu_model'],
" -> speed: %s" % system_info['cpu_speed'],
" -> cores: %s" % system_info['core_count'],
Expand All @@ -1175,7 +1183,8 @@ def show_system_info(self):
" -> glibc version: %s" % system_info['glibc_version'],
" -> Python binary: %s" % sys.executable,
" -> Python version: %s" % sys.version.split(' ')[0],
]
])

return '\n'.join(lines)

def show_config(self):
Expand Down
25 changes: 25 additions & 0 deletions easybuild/tools/systemtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@
_log.debug("Failed to import 'distro' Python module: %s", err)
HAVE_DISTRO = False

try:
from archspec.cpu import host as archspec_cpu_host
HAVE_ARCHSPEC = True
except ImportError as err:
_log.debug("Failed to import 'archspec' Python module: %s", err)
HAVE_ARCHSPEC = False



# Architecture constants
AARCH32 = 'AArch32'
Expand Down Expand Up @@ -344,6 +352,22 @@ def get_cpu_family():
return family


def get_cpu_arch_name():
"""
Determine CPU architecture name via archspec (if available).
"""
cpu_arch_name = None
if HAVE_ARCHSPEC:
res = archspec_cpu_host()
if res:
cpu_arch_name = res.name

if cpu_arch_name is None:
cpu_arch_name = UNKNOWN

return cpu_arch_name


def get_cpu_model():
"""
Determine CPU model, e.g., Intel(R) Core(TM) i5-2540M CPU @ 2.60GHz
Expand Down Expand Up @@ -746,6 +770,7 @@ def get_system_info():
return {
'core_count': get_avail_core_count(),
'total_memory': get_total_memory(),
'cpu_arch_name': get_cpu_arch_name(),
'cpu_model': get_cpu_model(),
'cpu_speed': get_cpu_speed(),
'cpu_vendor': get_cpu_vendor(),
Expand Down
8 changes: 7 additions & 1 deletion easybuild/tools/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from easybuild.tools.jenkins import aggregate_xml_in_dirs
from easybuild.tools.parallelbuild import build_easyconfigs_in_parallel
from easybuild.tools.robot import resolve_dependencies
from easybuild.tools.systemtools import get_system_info
from easybuild.tools.systemtools import UNKNOWN, get_system_info
from easybuild.tools.version import FRAMEWORK_VERSION, EASYBLOCKS_VERSION


Expand Down Expand Up @@ -256,6 +256,11 @@ def post_easyconfigs_pr_test_report(pr_nr, test_report, msg, init_session_state,

# post comment to report test result
system_info = init_session_state['system_info']

# also mention CPU architecture name, but only if it's known
if system_info['cpu_arch_name'] != UNKNOWN:
system_info['cpu_model'] += " (%s)" % system_info['cpu_arch_name']

short_system_info = "%(hostname)s - %(os_type)s %(os_name)s %(os_version)s, %(cpu_model)s, Python %(pyver)s" % {
'cpu_model': system_info['cpu_model'],
'hostname': system_info['hostname'],
Expand All @@ -264,6 +269,7 @@ def post_easyconfigs_pr_test_report(pr_nr, test_report, msg, init_session_state,
'os_version': system_info['os_version'],
'pyver': system_info['python_version'].split(' ')[0],
}

comment_lines = [
"Test report by @%s" % user,
('**FAILED**', '**SUCCESS**')[success],
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ GC3Pie
python-graph-dot
python-hglib
requests

archspec; python_version >= '2.7'
7 changes: 7 additions & 0 deletions test/framework/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
from easybuild.tools.py2vs3 import URLError, reload, sort_looseversions
from easybuild.tools.toolchain.utilities import TC_CONST_PREFIX
from easybuild.tools.run import run_cmd
from easybuild.tools.systemtools import HAVE_ARCHSPEC
from easybuild.tools.version import VERSION
from test.framework.utilities import EnhancedTestCase, TestLoaderFiltered, init_config

Expand Down Expand Up @@ -4562,6 +4563,12 @@ def test_show_system_info(self):
"^ -> Python binary: .*/[pP]ython[0-9]?",
"^ -> Python version: [0-9.]+",
]

if HAVE_ARCHSPEC:
patterns.append(r"^ -> arch name: \w+$")
else:
patterns.append(r"^ -> arch name: UNKNOWN \(archspec is not installed\?\)$")

for pattern in patterns:
regex = re.compile(pattern, re.M)
self.assertTrue(regex.search(txt), "Pattern '%s' found in: %s" % (regex.pattern, txt))
Expand Down
33 changes: 31 additions & 2 deletions test/framework/systemtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
from easybuild.tools.systemtools import CPU_VENDORS, AMD, APM, ARM, CAVIUM, IBM, INTEL
from easybuild.tools.systemtools import MAX_FREQ_FP, PROC_CPUINFO_FP, PROC_MEMINFO_FP
from easybuild.tools.systemtools import check_python_version, pick_dep_version
from easybuild.tools.systemtools import det_parallelism, get_avail_core_count, get_cpu_architecture, get_cpu_family
from easybuild.tools.systemtools import get_cpu_features, get_cpu_model, get_cpu_speed, get_cpu_vendor
from easybuild.tools.systemtools import det_parallelism, get_avail_core_count, get_cpu_arch_name, get_cpu_architecture
from easybuild.tools.systemtools import get_cpu_family, get_cpu_features, get_cpu_model, get_cpu_speed, get_cpu_vendor
from easybuild.tools.systemtools import get_gcc_version, get_glibc_version, get_os_type, get_os_name, get_os_version
from easybuild.tools.systemtools import get_platform_name, get_shared_lib_ext, get_system_info, get_total_memory

Expand Down Expand Up @@ -338,6 +338,11 @@ def setUp(self):
self.orig_platform_uname = st.platform.uname
self.orig_get_tool_version = st.get_tool_version
self.orig_sys_version_info = st.sys.version_info
self.orig_HAVE_ARCHSPEC = st.HAVE_ARCHSPEC
if hasattr(st, 'archspec_cpu_host'):
self.orig_archspec_cpu_host = st.archspec_cpu_host
else:
self.orig_archspec_cpu_host = None

def tearDown(self):
"""Cleanup after systemtools test."""
Expand All @@ -349,6 +354,9 @@ def tearDown(self):
st.platform.uname = self.orig_platform_uname
st.get_tool_version = self.orig_get_tool_version
st.sys.version_info = self.orig_sys_version_info
st.HAVE_ARCHSPEC = self.orig_HAVE_ARCHSPEC
if self.orig_archspec_cpu_host is not None:
st.archspec_cpu_host = self.orig_archspec_cpu_host
super(SystemToolsTest, self).tearDown()

def test_avail_core_count_native(self):
Expand Down Expand Up @@ -529,6 +537,27 @@ def test_cpu_architecture(self):
MACHINE_NAME = name
self.assertEqual(get_cpu_architecture(), machine_names[name])

def test_cpu_arch_name_native(self):
"""Test getting CPU arch name."""
arch_name = get_cpu_arch_name()
self.assertTrue(isinstance(arch_name, string_type))

def test_cpu_arch_name(self):
"""Test getting CPU arch name."""

class MicroArch(object):
def __init__(self, name):
self.name = name

st.HAVE_ARCHSPEC = True
st.archspec_cpu_host = lambda: MicroArch('haswell')
arch_name = get_cpu_arch_name()
self.assertEqual(arch_name, 'haswell')

st.archspec_cpu_host = lambda: None
arch_name = get_cpu_arch_name()
self.assertEqual(arch_name, 'UNKNOWN')

def test_cpu_vendor_native(self):
"""Test getting CPU vendor."""
cpu_vendor = get_cpu_vendor()
Expand Down