Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 'eb --show-system-info' on Apple M1 system #4015

Merged
merged 1 commit into from May 30, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 15 additions & 5 deletions easybuild/tools/systemtools.py
Expand Up @@ -94,6 +94,7 @@
# Vendor constants
AMD = 'AMD'
APM = 'Applied Micro'
APPLE = 'Apple'
ARM = 'ARM'
BROADCOM = 'Broadcom'
CAVIUM = 'Cavium'
Expand Down Expand Up @@ -123,7 +124,7 @@

CPU_ARCHITECTURES = [AARCH32, AARCH64, POWER, RISCV32, RISCV64, X86_64]
CPU_FAMILIES = [AMD, ARM, INTEL, POWER, POWER_LE, RISCV]
CPU_VENDORS = [AMD, APM, ARM, BROADCOM, CAVIUM, DEC, IBM, INTEL, MARVELL, MOTOROLA, NVIDIA, QUALCOMM]
CPU_VENDORS = [AMD, APM, APPLE, ARM, BROADCOM, CAVIUM, DEC, IBM, INTEL, MARVELL, MOTOROLA, NVIDIA, QUALCOMM]
# ARM implementer IDs (i.e., the hexadeximal keys) taken from ARMv8-A Architecture Reference Manual
# (ARM DDI 0487A.j, Section G6.2.102, Page G6-4493)
VENDOR_IDS = {
Expand Down Expand Up @@ -384,11 +385,18 @@ def get_cpu_vendor():

elif os_type == DARWIN:
cmd = "sysctl -n machdep.cpu.vendor"
out, ec = run_cmd(cmd, force_in_dry_run=True, trace=False, stream_output=False)
out, ec = run_cmd(cmd, force_in_dry_run=True, trace=False, stream_output=False, log_ok=False)
out = out.strip()
if ec == 0 and out in VENDOR_IDS:
vendor = VENDOR_IDS[out]
_log.debug("Determined CPU vendor on DARWIN as being '%s' via cmd '%s" % (vendor, cmd))
else:
cmd = "sysctl -n machdep.cpu.brand_string"
out, ec = run_cmd(cmd, force_in_dry_run=True, trace=False, stream_output=False, log_ok=False)
out = out.strip().split(' ')[0]
if ec == 0 and out in CPU_VENDORS:
vendor = out
_log.debug("Determined CPU vendor on DARWIN as being '%s' via cmd '%s" % (vendor, cmd))

if vendor is None:
vendor = UNKNOWN
Expand Down Expand Up @@ -533,9 +541,11 @@ def get_cpu_speed():
cmd = "sysctl -n hw.cpufrequency_max"
_log.debug("Trying to determine CPU frequency on Darwin via cmd '%s'" % cmd)
out, ec = run_cmd(cmd, force_in_dry_run=True, trace=False, stream_output=False)
if ec == 0:
out = out.strip()
cpu_freq = None
if ec == 0 and out:
# returns clock frequency in cycles/sec, but we want MHz
cpu_freq = float(out.strip()) // (1000 ** 2)
cpu_freq = float(out) // (1000 ** 2)

else:
raise SystemToolsException("Could not determine CPU clock frequency (OS: %s)." % os_type)
Expand Down Expand Up @@ -578,7 +588,7 @@ def get_cpu_features():
for feature_set in ['extfeatures', 'features', 'leaf7_features']:
cmd = "sysctl -n machdep.cpu.%s" % feature_set
_log.debug("Trying to determine CPU features on Darwin via cmd '%s'", cmd)
out, ec = run_cmd(cmd, force_in_dry_run=True, trace=False, stream_output=False)
out, ec = run_cmd(cmd, force_in_dry_run=True, trace=False, stream_output=False, log_ok=False)
if ec == 0:
cpu_feat.extend(out.strip().lower().split())

Expand Down
15 changes: 9 additions & 6 deletions test/framework/systemtools.py
Expand Up @@ -495,7 +495,7 @@ def test_cpu_features_native(self):
"""Test getting CPU features."""
cpu_feat = get_cpu_features()
self.assertTrue(isinstance(cpu_feat, list))
self.assertTrue(len(cpu_feat) > 0)
self.assertTrue(len(cpu_feat) >= 0)
self.assertTrue(all(isinstance(x, string_type) for x in cpu_feat))

def test_cpu_features_linux(self):
Expand Down Expand Up @@ -1016,8 +1016,10 @@ def test_check_linked_shared_libs(self):
self.assertEqual(check_linked_shared_libs(txt_path, **pattern_named_args), None)
self.assertEqual(check_linked_shared_libs(broken_symlink_path, **pattern_named_args), None)
for path in (bin_ls_path, lib_path):
error_msg = "Check on linked libs should pass for %s with %s" % (path, pattern_named_args)
self.assertTrue(check_linked_shared_libs(path, **pattern_named_args), error_msg)
# path may not exist, especially for library paths obtained via 'otool -L' on macOS
if os.path.exists(path):
error_msg = "Check on linked libs should pass for %s with %s" % (path, pattern_named_args)
self.assertTrue(check_linked_shared_libs(path, **pattern_named_args), error_msg)

# also test with input that should result in failing check
test_pattern_named_args = [
Expand Down Expand Up @@ -1050,17 +1052,18 @@ def test_locate_solib(self):

def test_find_library_path(self):
"""Test find_library_path function (Linux and Darwin only)."""
if get_os_type() == LINUX:
os_type = get_os_type()
if os_type == LINUX:
libname = 'libc.so.6'
elif get_os_type() == DARWIN:
elif os_type == DARWIN:
libname = 'libSystem.dylib'
else:
libname = None

if libname:
lib_path = find_library_path(libname)
self.assertEqual(os.path.basename(lib_path), libname)
self.assertTrue(os.path.exists(lib_path), "%s should exist" % libname)
self.assertTrue(os.path.exists(lib_path) or os_type == DARWIN, "%s should exist" % libname)


def suite():
Expand Down