From ba9d8d5a2eff41e35a132ec4219663f79116a949 Mon Sep 17 00:00:00 2001 From: Anna Babu Palathingal Date: Fri, 1 Dec 2023 16:58:54 -0500 Subject: [PATCH] Added code to detect micro architecture - zlinux version detection - add tests resolves: https://github.com/adoptium/TKG/issues/471 Signed-off-by: Anna Babu Palathingal --- examples/platformRequirements/playlist.xml | 53 +++++ makeGen.mk | 2 +- scripts/testTKG/test_platformRequirements.py | 229 +++++++++++-------- src/org/openj9/envInfo/MachineInfo.java | 30 ++- 4 files changed, 209 insertions(+), 105 deletions(-) diff --git a/examples/platformRequirements/playlist.xml b/examples/platformRequirements/playlist.xml index 514369e1..49a53a40 100644 --- a/examples/platformRequirements/playlist.xml +++ b/examples/platformRequirements/playlist.xml @@ -37,8 +37,61 @@ ^arch.x86 + + + test_microarchitecture_detection_skylake + echo "test microarchitecture detection for skylake"; \ + $(TEST_STATUS) + + skylake + + + + + test_microarchitecture_detection_z15 + echo "test microarchitecture detection for z15"; \ + $(TEST_STATUS) + + z15 + + + + + test_microarchitecture_detection_z14 + echo "test microarchitecture detection for z14"; \ + $(TEST_STATUS) + + z14 + + + + test_microarchitecture_detection_z13s + echo "test microarchitecture detection for z13s"; \ + $(TEST_STATUS) + + z13s + + + + test_microarchitecture_detection_z13_and_above + echo "test microarchitecture detection for z13 and above"; \ + $(TEST_STATUS) + + z13+ + + + + + test_microarchitecture_detection_z13 + echo "test microarchitecture detection for z13"; \ + $(TEST_STATUS) + + z13 + + + test_bits_64 echo "test bits.64"; \ $(TEST_STATUS) diff --git a/makeGen.mk b/makeGen.mk index 1b3fec2e..49e811ea 100644 --- a/makeGen.mk +++ b/makeGen.mk @@ -42,7 +42,7 @@ autoconfig: perl scripts$(D)configure.pl autogen: autoconfig - ${TEST_JDK_HOME}/bin/java -cp $(Q)$(TKG_JAR)$(P)$(JSON_SIMPLE)$(Q) org.testKitGen.MainRunner --mode=$(MODE) --spec=$(SPEC) --microArch=$(MICROARCH) --osLabel=$(Q)$(OS_LABEL)$(Q) --jdkVersion=$(JDK_VERSION) --impl=$(JDK_IMPL) --vendor=$(Q)$(JDK_VENDOR)$(Q) --buildList=${BUILD_LIST} --iterations=$(TKG_ITERATIONS) --aotIterations=$(AOT_ITERATIONS) --testFlag=$(TEST_FLAG) --testTarget=$(TESTTARGET) --testList=$(TESTLIST) --numOfMachines=$(NUM_MACHINES) --testTime=$(TEST_TIME) --TRSSURL=$(TRSS_URL) $(OPTS) + ${TEST_JDK_HOME}/bin/java -cp $(Q)$(TKG_JAR)$(P)$(JSON_SIMPLE)$(Q) org.testKitGen.MainRunner --mode=$(MODE) --spec=$(SPEC) --microArch=$(Q)$(MICROARCH)$(Q) --osLabel=$(Q)$(OS_LABEL)$(Q) --jdkVersion=$(JDK_VERSION) --impl=$(JDK_IMPL) --vendor=$(Q)$(JDK_VENDOR)$(Q) --buildList=${BUILD_LIST} --iterations=$(TKG_ITERATIONS) --aotIterations=$(AOT_ITERATIONS) --testFlag=$(TEST_FLAG) --testTarget=$(TESTTARGET) --testList=$(TESTLIST) --numOfMachines=$(NUM_MACHINES) --testTime=$(TEST_TIME) --TRSSURL=$(TRSS_URL) $(OPTS) AUTOGEN_FILES = $(wildcard $(CURRENT_DIR)$(D)jvmTest.mk) AUTOGEN_FILES += $(wildcard $(CURRENT_DIR)$(D)machineConfigure.mk) diff --git a/scripts/testTKG/test_platformRequirements.py b/scripts/testTKG/test_platformRequirements.py index 62e0bc65..1f6272e7 100644 --- a/scripts/testTKG/test_platformRequirements.py +++ b/scripts/testTKG/test_platformRequirements.py @@ -16,105 +16,134 @@ from utils import * def run_test(): - rt = True - printTestheader("platformRequirements") - - buildList = "TKG/examples/platformRequirements" - command = "make _all" - print(f"\t{command}") - result = subprocess.run(f"{EXPORT_BUILDLIST}={buildList}; {CD_TKG}; {MAKE_CLEAN}; {MAKE_COMPILE}; {command}", stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True, check=False) - - stdout = result.stdout.decode() - specStr = re.search(r"set SPEC to (.*)", stdout) - - if specStr is not None: - spec = specStr.group(1) - else: - printError("Could not parse spec from output.") - return False - - passed = set() - skipped = set() - - if 'linux' in spec: - skipped.add('test_not_linux_arch_x86_0') - else: - if 'x86' in spec: - passed.add('test_not_linux_arch_x86_0') - else: - skipped.add('test_not_linux_arch_x86_0') - - if 'x86' in spec: - passed.add('test_arch_x86_0') - skipped.add('test_arch_nonx86_0') - else: - passed.add('test_arch_nonx86_0') - skipped.add('test_arch_x86_0') - - if '64' in spec: - passed.add('test_bits_64_0') - else: - skipped.add('test_bits_64_0') - - if 'osx' in spec: - passed.add('test_os_osx_0') - else: - skipped.add('test_os_osx_0') - - if 'osx_x86-64' in spec: - passed.add('test_osx_x86-64_0') - else: - skipped.add('test_osx_x86-64_0') - - if 'x86' in spec or '390' in spec: - passed.add('test_arch_x86_390_0') - else: - skipped.add('test_arch_x86_390_0') - - if 'osx_x86-64' in spec or ('win_x86' in spec and 'win_x86-64' not in spec) or 'aix_ppc-64' in spec: - passed.add('test_osx_x86-64_win_x86_aix_ppc-64_0') - else: - skipped.add('test_osx_x86-64_win_x86_aix_ppc-64_0') - - os_label = re.search(r"set OS_LABEL to (.*)", stdout) - if os_label is not None: - os_label = os_label.group(1) - label_str = os_label.split(".") - # os_label example: ubuntu.22 - try: - ver = int(label_str[1],10) - if label_str[0] == "ubuntu": - if ver >= 22: - passed.add('test_os_linux_ubuntu22_0') - if ver >= 20: - passed.add('test_os_linux_ubuntu20plus_0') - passed.add('test_os_linux_ubuntu20plus_rhel8plus_0') - if ver < 20: - passed.add('test_not_os_linux_ubuntu20plus_0') - - if label_str[0] == "rhel": - if ver >= 8: - passed.add('test_os_linux_ubuntu20plus_rhel8plus_0') - except ValueError as ve: - print ("warning: os version value failed to convert to an integer") - passed.add('test_not_os_linux_ubuntu20plus_0') - else: - passed.add('test_not_os_linux_ubuntu20plus_0') - - if 'test_os_linux_ubuntu20plus_0' not in passed: - skipped.add('test_os_linux_ubuntu20plus_0') - - if 'test_os_linux_ubuntu22_0' not in passed: - skipped.add('test_os_linux_ubuntu22_0') - - if 'test_os_linux_ubuntu20plus_rhel8plus_0' not in passed: - skipped.add('test_os_linux_ubuntu20plus_rhel8plus_0') - - if 'test_not_os_linux_ubuntu20plus_0' not in passed: - skipped.add('test_not_os_linux_ubuntu20plus_0') - - rt &= checkResult(result, passed, set(), set(), skipped) - return rt + rt = True + printTestheader("platformRequirements") + + buildList = "TKG/examples/platformRequirements" + command = "make _all" + print(f"\t{command}") + result = subprocess.run(f"{EXPORT_BUILDLIST}={buildList}; {CD_TKG}; {MAKE_CLEAN}; {MAKE_COMPILE}; {command}", stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True, check=False) + + stdout = result.stdout.decode() + specStr = re.search(r"set SPEC to (.*)", stdout) + + if specStr is not None: + spec = specStr.group(1) + else: + printError("Could not parse spec from output.") + return False + + passed = set() + skipped = set() + + if 'linux' in spec: + skipped.add('test_not_linux_arch_x86_0') + else: + if 'x86' in spec: + passed.add('test_not_linux_arch_x86_0') + else: + skipped.add('test_not_linux_arch_x86_0') + + if 'x86' in spec: + passed.add('test_arch_x86_0') + skipped.add('test_arch_nonx86_0') + else: + passed.add('test_arch_nonx86_0') + skipped.add('test_arch_x86_0') + + if '64' in spec: + passed.add('test_bits_64_0') + else: + skipped.add('test_bits_64_0') + + if 'osx' in spec: + passed.add('test_os_osx_0') + else: + skipped.add('test_os_osx_0') + + if 'osx_x86-64' in spec: + passed.add('test_osx_x86-64_0') + else: + skipped.add('test_osx_x86-64_0') + + if 'x86' in spec or '390' in spec: + passed.add('test_arch_x86_390_0') + else: + skipped.add('test_arch_x86_390_0') + + if 'osx_x86-64' in spec or ('win_x86' in spec and 'win_x86-64' not in spec) or 'aix_ppc-64' in spec: + passed.add('test_osx_x86-64_win_x86_aix_ppc-64_0') + else: + skipped.add('test_osx_x86-64_win_x86_aix_ppc-64_0') + + os_label = re.search(r"set OS_LABEL to (.*)", stdout) + if os_label is not None: + os_label = os_label.group(1) + label_str = os_label.split(".") + # os_label example: ubuntu.22 + try: + ver = int(label_str[1],10) + if label_str[0] == "ubuntu": + if ver >= 22: + passed.add('test_os_linux_ubuntu22_0') + if ver >= 20: + passed.add('test_os_linux_ubuntu20plus_0') + passed.add('test_os_linux_ubuntu20plus_rhel8plus_0') + if ver < 20: + passed.add('test_not_os_linux_ubuntu20plus_0') + + if label_str[0] == "rhel": + if ver >= 8: + passed.add('test_os_linux_ubuntu20plus_rhel8plus_0') + except ValueError as ve: + print ("warning: os version value failed to convert to an integer") + passed.add('test_not_os_linux_ubuntu20plus_0') + else: + passed.add('test_not_os_linux_ubuntu20plus_0') + + if 'test_os_linux_ubuntu20plus_0' not in passed: + skipped.add('test_os_linux_ubuntu20plus_0') + + if 'test_os_linux_ubuntu22_0' not in passed: + skipped.add('test_os_linux_ubuntu22_0') + + if 'test_os_linux_ubuntu20plus_rhel8plus_0' not in passed: + skipped.add('test_os_linux_ubuntu20plus_rhel8plus_0') + + if 'test_not_os_linux_ubuntu20plus_0' not in passed: + skipped.add('test_not_os_linux_ubuntu20plus_0') + + micro_arch = re.search(r"set MICROARCH to (.*)", stdout) + print("Output:", stdout) + if micro_arch is not None: + micro_arch = micro_arch.group(1) + label_str = os_label.split(".") + # micro_arch example: skylake + try: + if label_str[0] == "skylake": + passed.add('test_microarchitecture_detection_skylake_0') + elif label_str[0] == "z15": + passed.add('test_microarchitecture_detection_z15') + passed.add('test_microarchitecture_detection_z13_and_above_0') + elif label_str[0] == "z14": + passed.add('test_microarchitecture_detection_z14') + passed.add('test_microarchitecture_detection_z13_and_above_0') + elif label_str[0] == "z13s": + passed.add('test_microarchitecture_detection_z13s_0') + passed.add('test_microarchitecture_detection_z13_and_above_0') + elif label_str[0] == "z13+": + passed.add('test_microarchitecture_detection_z13_and_above_0') + elif label_str[0] == "z13": + passed.add('test_microarchitecture_detection_z13_0') + else: + skipped.add('test_microarchitecture_not_supported_0') + + except ValueError as ve: + print("warning: os version value failed to convert to an integer") + skipped.add('test_microarchitecture_not_supported_0') + + rt &= checkResult(result, passed, set(), set(), skipped) + return rt if __name__ == "__main__": - run_test() \ No newline at end of file + run_test() \ No newline at end of file diff --git a/src/org/openj9/envInfo/MachineInfo.java b/src/org/openj9/envInfo/MachineInfo.java index 94151154..bbc37348 100644 --- a/src/org/openj9/envInfo/MachineInfo.java +++ b/src/org/openj9/envInfo/MachineInfo.java @@ -38,7 +38,8 @@ public class MachineInfo { public static final String[] LINUX_OS_NAME_CMD = new String[] {"bash", "-c", "grep '^NAME' /etc/os-release | awk -F'=' ' gsub(/\"/,\"\") { print $2}'"}; public static final String[] LINUX_OS_VERSION_CMD = new String[] {"bash", "-c", "grep '^VERSION_ID' /etc/os-release | awk -F'=' ' gsub(/\"/,\"\") { print $2}'"}; - public static final String[] MICRO_ARCH_CMD = new String[] {"bash", "-c", "cat /proc/cpuinfo | grep 'model name' | uniq"}; + public static final String[] MICRO_ARCH_CMD = new String[] {"bash", "-c", "cat /proc/cpuinfo | grep -E 'machine|model name' | uniq"}; + public static final String[] ULIMIT_CMD = new String[] {"bash", "-c", "ulimit -a"}; public static final String[] INSTALLED_MEM_CMD = new String[] {"bash", "-c", "grep MemTotal /proc/meminfo | awk '{print $2}"}; @@ -201,10 +202,31 @@ private void getSysInfo() { putInfo(new Info("sysArch", SYS_ARCH_CMD, ce.execute(SYS_ARCH_CMD), null)); putInfo(new Info("procArch", PROC_ARCH_CMD, ce.execute(PROC_ARCH_CMD), null)); String microArchOutput = ce.execute(MICRO_ARCH_CMD); + String microArch = ""; + // Check for specific machine versions and set the microArch accordingly if (microArchOutput.toLowerCase().contains("skylake")) { - String microArch = "skylake"; - putInfo(new Info("microArch", MICRO_ARCH_CMD, microArch, null)); - } + microArch = "skylake"; + } else if (microArchOutput.contains("8562")) { + microArch = "IBM z15 T02"; + } else if (microArchOutput.contains("8561")) { + microArch = "IBM z15 T01"; + } else if (microArchOutput.contains("3907")) { + microArch = "IBM z14 ZR1"; + } else if (microArchOutput.contains("3906")) { + microArch = "IBM z14"; + } else if (microArchOutput.contains("2965")) { + microArch = "IBM z13s"; + } else if (microArchOutput.contains("2964")) { + microArch= "IBM z13"; + } + else { + System.out.println("Unfamiliar microArch detected in TKG. It will not be added in TKG microArch!"); + System.out.println("microArchOutput: " + microArchOutput); + } + + if (!microArch.isEmpty()) { + putInfo(new Info("microArch", MICRO_ARCH_CMD, microArchOutput, null)); + } putInfo(new Info("sysOS", SYS_OS_CMD, ce.execute(SYS_OS_CMD), null)); putInfo(new Info("ulimit", ULIMIT_CMD, ce.execute(ULIMIT_CMD), null)); putInfo(new Info("docker", CHECK_DOCKER_CMD, ce.execute(CHECK_DOCKER_CMD), null));