Skip to content

Commit e6ff4a6

Browse files
committed
Support user specified OS label
- supported os: rhel, ubuntu, sles - add logic in machine detection code - add logic in TKG makeGen to support user specified os - add tkg tests fixes adoptium#417 Signed-off-by: renfeiw <[email protected]>
1 parent 7c2fe16 commit e6ff4a6

File tree

10 files changed

+164
-41
lines changed

10 files changed

+164
-41
lines changed

.github/workflows/testTKG.yml

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
TEST_JDK_HOME: ${{ env.JAVA_HOME }}
4444
TEST_OPTIONS: ${{ env.TKG_TEST_OPTIONS }}
4545
run: |
46+
sudo apt-get install ant-contrib -y
4647
cd scripts/testTKG
4748
python testRunner.py $TEST_OPTIONS
4849

envSettings.mk

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ ifneq ($(AUTO_DETECT), false)
2525

2626
export MICROARCH:=$(DETECTED_MICRO_ARCH)
2727

28+
export OS_LABEL:=$(DETECTED_OS_LABEL)
29+
2830
ifndef JDK_VERSION
2931
export JDK_VERSION:=$(DETECTED_JDK_VERSION)
3032
else
@@ -63,6 +65,10 @@ else
6365
export MICROARCH:=$(DETECTED_MICROARCH)
6466
$(info Warning: No MICROARCH has been exported. Use auto detected MICROARCH=$(MICROARCH).)
6567
endif
68+
ifndef OS_LABEL
69+
export OS_LABEL:=$(DETECTED_OS_LABEL)
70+
$(info Warning: No OS_LABEL has been exported. Use auto detected OS_LABEL=$(OS_LABEL).)
71+
endif
6672
ifndef JDK_VERSION
6773
export JDK_VERSION:=$(DETECTED_JDK_VERSION)
6874
$(info Warning: No JDK_VERSION has been exported. Use auto detected JDK_VERSION=$(JDK_VERSION).)

examples/platformRequirements/playlist.xml

+15-8
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,7 @@
5959
<platformRequirements>os.osx,bits.64,arch.x86</platformRequirements>
6060
</test>
6161

62-
<test>
63-
<testCaseName>test_os_osx</testCaseName>
64-
<command>echo "test os.osx"; \
65-
$(TEST_STATUS)</command>
66-
<platformRequirements>os.osx</platformRequirements>
67-
</test>
68-
69-
<test>
62+
<test>
7063
<testCaseName>test_osx_x86-64_win_x86_aix_ppc-64</testCaseName>
7164
<command>echo "test osx_x86-64 or win_x86 or aix_ppc-64"; \
7265
$(TEST_STATUS)</command>
@@ -76,4 +69,18 @@
7669
<platformRequirements>os.aix,arch.ppc,bits.64</platformRequirements>
7770
</platformRequirementsList>
7871
</test>
72+
73+
<test>
74+
<testCaseName>test_os_linux_ubuntu20plus</testCaseName>
75+
<command>echo "test os.linux.ubuntu.20+"; \
76+
$(TEST_STATUS)</command>
77+
<platformRequirements>os.linux.ubuntu.20+</platformRequirements>
78+
</test>
79+
80+
<test>
81+
<testCaseName>test_os_linux_ubuntu22</testCaseName>
82+
<command>echo "test os.linux.ubuntu.22"; \
83+
$(TEST_STATUS)</command>
84+
<platformRequirements>os.linux.ubuntu.22</platformRequirements>
85+
</test>
7986
</playlist>

makeGen.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ autoconfig:
4242
perl scripts$(D)configure.pl
4343

4444
autogen: autoconfig
45-
${TEST_JDK_HOME}/bin/java -cp $(Q)$(TKG_JAR)$(P)$(JSON_SIMPLE)$(Q) org.testKitGen.MainRunner --mode=$(MODE) --spec=$(SPEC) --microArch=$(MICROARCH) --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)
45+
${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)
4646

4747
AUTOGEN_FILES = $(wildcard $(CURRENT_DIR)$(D)jvmTest.mk)
4848
AUTOGEN_FILES += $(wildcard $(CURRENT_DIR)$(D)machineConfigure.mk)

scripts/testTKG/testRunner.py

+32-5
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
def main():
2929
global verbose
3030
ap = argparse.ArgumentParser()
31-
ap.add_argument('-l','--testList', nargs='+', required=False, default=ALL_TESTS, help="space separated test list")
31+
ap.add_argument('-t','--test', nargs='+', required=False, default=ALL_TESTS, help="space separated test list")
3232
ap.add_argument('-v','--verbose', nargs='?', required=False, const=True, default=False, help="print test output")
3333
args = vars(ap.parse_args())
34-
testList = args['testList']
34+
test_list = args['test']
3535
verbose = args['verbose']
3636

3737
rt = True
3838

39-
for test in testList:
39+
for test in test_list:
4040
if f"test_{test}" in globals():
4141
rt &= globals()[f"test_{test}"]()
4242

@@ -138,8 +138,6 @@ def test_platformRequirements():
138138
printError("Could not parse spec from output.")
139139
return False
140140

141-
print(spec)
142-
143141
passed = set()
144142
skipped = set()
145143

@@ -175,6 +173,35 @@ def test_platformRequirements():
175173
else:
176174
skipped.add('test_osx_x86-64_win_x86_aix_ppc-64_0')
177175

176+
os_label = re.search(r"set OS_LABEL to (.*)", stdout)
177+
if os_label is not None:
178+
os_label = os_label.group(1)
179+
# os_label example: ubuntu.22
180+
if os_label.startswith("ubuntu"):
181+
label_str = os_label.split(".")
182+
try:
183+
ver = int(label_str[1],10)
184+
except ValueError as ve:
185+
#value error to convert to integer
186+
skipped.add('test_os_linux_ubuntu20plus_0')
187+
skipped.add('test_os_linux_ubuntu22_0')
188+
189+
if ver >= 22:
190+
passed.add('test_os_linux_ubuntu22_0')
191+
else:
192+
skipped.add('test_os_linux_ubuntu22_0')
193+
194+
if ver >= 20:
195+
passed.add('test_os_linux_ubuntu20plus_0')
196+
else:
197+
skipped.add('test_os_linux_ubuntu20plus_0')
198+
else:
199+
skipped.add('test_os_linux_ubuntu20plus_0')
200+
skipped.add('test_os_linux_ubuntu22_0')
201+
else:
202+
skipped.add('test_os_linux_ubuntu20plus_0')
203+
skipped.add('test_os_linux_ubuntu22_0')
204+
178205
rt &= checkResult(result, passed, set(), set(), skipped)
179206
return rt
180207

settings.mk

+6
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,12 @@ setup_%: testEnvSetup
380380
@$(ECHO) set JAVA_HOME to $(JAVA_HOME)
381381
@$(ECHO) set SPEC to $(SPEC)
382382
@$(ECHO) set TEST_FLAG to $(TEST_FLAG)
383+
@if [ $(MICROARCH) ]; then \
384+
$(ECHO) set MICROARCH to $(MICROARCH); \
385+
fi
386+
@if [ $(OS_LABEL) ]; then \
387+
$(ECHO) set OS_LABEL to $(OS_LABEL); \
388+
fi
383389

384390
@$(MKTREE) $(Q)$(TESTOUTPUT)$(Q)
385391
@$(ECHO) Running $(TESTTARGET) ...

src/org/openj9/envInfo/EnvDetector.java

+24-17
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,24 @@ private static void getJavaInfo() {
5858
String testFlag = envDetection.getTestFlag();
5959
int javaVersionInfo = envDetection.getJDKVersion();
6060
String releaseInfo = envDetection.getReleaseInfo();
61-
String microArch = machineInfo.getInfoMap().get("microArch").output;
6261
if (SPECInfo == null || javaVersionInfo == -1 || javaImplInfo == null) {
6362
System.exit(1);
6463
}
65-
String MICROARCHvalue = "DETECTED_MICRO_ARCH=" + microArch + "\n";
66-
String SPECvalue = "DETECTED_SPEC=" + SPECInfo + "\n";
67-
String JDKVERSIONvalue = "DETECTED_JDK_VERSION=" + javaVersionInfo + "\n";
68-
String JDKIMPLvalue = "DETECTED_JDK_IMPL=" + javaImplInfo + "\n";
69-
String JDKVENDORvalue = "DETECTED_JDK_VENDOR=" + vendorInfo + "\n";
70-
String JavaVersionValue = "DETECTED_JAVA_VERSION=" + javaVersion + "\n";
71-
String ReleaseValue = "DETECTED_RELEASE_INFO=" + releaseInfo + "\n";
72-
String TESTFLAGvalue = "DETECTED_TEST_FLAG=" + testFlag + "\n";
64+
String MICRO_ARCH = "";
65+
if (machineInfo.getInfoMap().containsKey("microArch")) {
66+
MICRO_ARCH = "DETECTED_MICRO_ARCH=" + machineInfo.getInfoMap().get("microArch").output + "\n";
67+
}
68+
String OS_LABEL = "";
69+
if (machineInfo.getInfoMap().containsKey("osLabel")) {
70+
OS_LABEL = "DETECTED_OS_LABEL=" + machineInfo.getInfoMap().get("osLabel").output + "\n";
71+
}
72+
String SPEC = "DETECTED_SPEC=" + SPECInfo + "\n";
73+
String JDK_VERSION = "DETECTED_JDK_VERSION=" + javaVersionInfo + "\n";
74+
String JDK_IMPL = "DETECTED_JDK_IMPL=" + javaImplInfo + "\n";
75+
String JDK_VENDOR = "DETECTED_JDK_VENDOR=" + vendorInfo + "\n";
76+
String JAVA_VERSION = "DETECTED_JAVA_VERSION=" + javaVersion + "\n";
77+
String RELEASE_INFO = "DETECTED_RELEASE_INFO=" + releaseInfo + "\n";
78+
String TEST_FLAG = "DETECTED_TEST_FLAG=" + testFlag + "\n";
7379

7480
/**
7581
* autoGenEnv.mk file will be created to store auto detected java info.
@@ -80,16 +86,17 @@ private static void getJavaInfo() {
8086
output.write("########################################################\n");
8187
output.write("# This is an auto generated file. Please do NOT modify!\n");
8288
output.write("########################################################\n");
83-
output.write(SPECvalue);
84-
output.write(MICROARCHvalue);
85-
output.write(JDKVERSIONvalue);
86-
output.write(JDKIMPLvalue);
87-
output.write(JDKVENDORvalue);
88-
output.write(TESTFLAGvalue);
89+
output.write(SPEC);
90+
output.write(MICRO_ARCH);
91+
output.write(OS_LABEL);
92+
output.write(JDK_VERSION);
93+
output.write(JDK_IMPL);
94+
output.write(JDK_VENDOR);
95+
output.write(TEST_FLAG);
8996
output.close();
9097
output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("AQACert.log")));
91-
output.write(JavaVersionValue);
92-
output.write(ReleaseValue);
98+
output.write(JAVA_VERSION);
99+
output.write(RELEASE_INFO);
93100
output.close();
94101
} catch (IOException e) {
95102
e.printStackTrace();

src/org/openj9/envInfo/MachineInfo.java

+32-10
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,23 @@
1818
import java.nio.file.*;
1919
import java.util.Map;
2020
import java.util.HashMap;
21+
import java.util.List;
2122
import java.lang.management.ManagementFactory;
2223
import java.util.regex.Matcher;
2324
import java.util.regex.Pattern;
2425
import java.util.ArrayList;
26+
import java.util.Collections;
27+
2528
import com.sun.management.OperatingSystemMXBean;
2629

2730
public class MachineInfo {
2831
public static final String[] UNAME_CMD = new String[] {"uname", "-a"};
2932
public static final String[] SYS_ARCH_CMD = new String[] {"uname", "-m"};
3033
public static final String[] PROC_ARCH_CMD = new String[] {"uname", "-p"};
34+
public static final String[] LINUX_OS_CMD = new String[] {"bash", "-c", "cat /etc/os-release"};
35+
public static final String[] LINUX_OS_NAME_CMD = new String[] {"bash", "-c", "grep '^NAME' /etc/os-release | awk -F'=' ' gsub(/\"/,\"\") { print $2}'"};
36+
public static final String[] LINUX_OS_VERSION_CMD = new String[] {"bash", "-c", "grep '^VERSION_ID' /etc/os-release | awk -F'=' ' gsub(/\"/,\"\") { print $2}'"};
37+
3138
public static final String[] MICRO_ARCH_CMD = new String[] {"bash", "-c", "cat /proc/cpuinfo | grep 'model name' | uniq"};
3239
public static final String[] ULIMIT_CMD = new String[] {"bash", "-c", "ulimit -a"};
3340

@@ -60,9 +67,12 @@ public class MachineInfo {
6067

6168

6269
private Map<String, Info> infoMap;
63-
70+
private CmdExecutor ce;
71+
6472
public MachineInfo() {
6573
this.infoMap = new HashMap<String, Info>();
74+
this.ce = CmdExecutor.getInstance();
75+
6676
}
6777

6878
public Map<String, Info> getInfoMap() {
@@ -75,6 +85,7 @@ private void putInfo(Info info) {
7585

7686
public void checkInfo() {
7787
getSysInfo();
88+
getOsLabel();
7889
getPrerequisiteInfo();
7990
getRuntimeInfo();
8091
getPhysicalMemoryInfo();
@@ -86,9 +97,10 @@ public void checkInfo() {
8697
public String toString() {
8798
StringBuilder sb = new StringBuilder();
8899
String newline = "";
89-
for (Map.Entry<String, Info> pair : infoMap.entrySet()) {
90-
String name = pair.getKey();
91-
Info info = pair.getValue();
100+
List<String> keys = new ArrayList<>(infoMap.keySet());
101+
Collections.sort(keys);
102+
for (String name : keys) {
103+
Info info = infoMap.get(name);
92104
String output = info.output != null ? info.output : "";
93105
if (output.contains("\n")) {
94106
output = "\n" + output;
@@ -170,7 +182,6 @@ private void validateInfo() {
170182
}
171183

172184
private void getSysInfo() {
173-
CmdExecutor ce = CmdExecutor.getInstance();
174185
putInfo(new Info("uname", UNAME_CMD, ce.execute(UNAME_CMD), null));
175186
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
176187
putInfo(new Info("cpuCores", CPU_CORES_CMD, ce.execute(CPU_CORES_CMD_MAC), null));
@@ -182,18 +193,30 @@ private void getSysInfo() {
182193
putInfo(new Info("sysArch", SYS_ARCH_CMD, ce.execute(SYS_ARCH_CMD), null));
183194
putInfo(new Info("procArch", PROC_ARCH_CMD, ce.execute(PROC_ARCH_CMD), null));
184195
String microArchOutput = ce.execute(MICRO_ARCH_CMD);
185-
String microArch = "";
186196
if (microArchOutput.toLowerCase().contains("skylake")) {
187-
microArch = "skylake";
197+
String microArch = "skylake";
198+
putInfo(new Info("microArch", MICRO_ARCH_CMD, microArch, null));
188199
}
189-
putInfo(new Info("microArch", MICRO_ARCH_CMD, microArch, null));
190200
putInfo(new Info("sysOS", SYS_OS_CMD, ce.execute(SYS_OS_CMD), null));
191201
putInfo(new Info("ulimit", ULIMIT_CMD, ce.execute(ULIMIT_CMD), null));
192202
putInfo(new Info("docker", CHECK_DOCKER_CMD, ce.execute(CHECK_DOCKER_CMD), null));
193203
}
194204

205+
private void getOsLabel() {
206+
if (System.getProperty("os.name").toLowerCase().contains("linux")) {
207+
String osName = ce.execute(LINUX_OS_NAME_CMD).toLowerCase();
208+
if (osName.contains("red hat enterprise linux")) {
209+
osName = "rhel";
210+
}
211+
String fullOsVersion = ce.execute(LINUX_OS_VERSION_CMD);
212+
String[] osVersions = fullOsVersion.split("\\.");
213+
String osLabel = osName + "." + osVersions[0];
214+
putInfo(new Info("osLabel", LINUX_OS_CMD, osLabel, null));
215+
putInfo(new Info("osInfo", LINUX_OS_CMD, ce.execute(LINUX_OS_CMD), null));
216+
}
217+
}
218+
195219
private void getPrerequisiteInfo() {
196-
CmdExecutor ce = CmdExecutor.getInstance();
197220
putInfo(new Info("antVersion", ANT_VERSION_CMD, ce.execute(ANT_VERSION_CMD), "1.9.6"));
198221
/* required version is 4.1, but some exception applies, do not verify for now*/
199222
putInfo(new Info("makeVersion", MAKE_VERSION_CMD, ce.execute(MAKE_VERSION_CMD), null));
@@ -221,7 +244,6 @@ private void getPhysicalMemoryInfo() {
221244
}
222245

223246
private void getOtherInfo() {
224-
CmdExecutor ce = CmdExecutor.getInstance();
225247
putInfo(new Info("gcc version", GCC_VERSION_CMD, ce.execute(GCC_VERSION_CMD), null));
226248
putInfo(new Info("xlc version", XLC_VERSION_CMD, ce.execute(XLC_VERSION_CMD), null));
227249
putInfo(new Info("gdb version", GDB_VERSION_CMD, ce.execute(GDB_VERSION_CMD), null));

src/org/testKitGen/Arguments.java

+9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ enum Mode {
2727
private Mode mode = Mode.GEN_TESTS;
2828
private String spec = "";
2929
private String microArch = "";
30+
private String osLabel = "";
3031
private String plat = "";
3132
private String jdkVersion = "";
3233
private String impl = "";
@@ -74,6 +75,8 @@ enum Mode {
7475
+ " --TRSSURL=<serverURL> Specify the TRSS server URL for mode parallelList\n"
7576
+ " Defaults to " + Constants.TRSS_URL + "\n"
7677
+ " --microArch=<microArch> Specify micro-architecture\n"
78+
+ " Defaults to \"\"\n"
79+
+ " --osLabel=<osLabel> Specify OS Label\n"
7780
+ " Defaults to \"\"\n";
7881

7982

@@ -99,6 +102,10 @@ public String getMicroArch() {
99102
return microArch;
100103
}
101104

105+
public String getOsLabel() {
106+
return osLabel;
107+
}
108+
102109
public String getPlat() {
103110
return plat;
104111
}
@@ -217,6 +224,8 @@ public void parse(String[] args) {
217224
plat = spec2Plat(spec);
218225
} else if (arglc.startsWith("--microarch=")) {
219226
microArch = arglc.substring(arg.indexOf("=") + 1);
227+
} else if (arglc.startsWith("--oslabel=")) {
228+
osLabel = arglc.substring(arg.indexOf("=") + 1);
220229
} else if (arglc.startsWith("--jdkversion=")) {
221230
jdkVersion = arglc.substring(arg.indexOf("=") + 1);
222231
} else if (arglc.startsWith("--impl=")) {

0 commit comments

Comments
 (0)