Skip to content

Commit

Permalink
Support defining a range of jdk versions
Browse files Browse the repository at this point in the history
- update parser logic
- add testcase/example for jdk version
- add testcase/example for disable jdk version

Fixes: adoptium#390

Signed-off-by: renfeiw <renfeiw@ca.ibm.com>
  • Loading branch information
renfeiw committed Jan 30, 2023
1 parent fbdb987 commit 352134c
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 11 deletions.
92 changes: 92 additions & 0 deletions examples/jdkVersion/playlist.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-->
<playlist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../TKG/playlist.xsd">
<test>
<testCaseName>test_ver_11</testCaseName>
<command>echo "test for version 11"; \
$(TEST_STATUS)</command>
<versions>
<version>11</version>
</versions>
</test>

<test>
<testCaseName>test_ver_17plus</testCaseName>
<command>echo "test for version 17+"; \
$(TEST_STATUS)</command>
<versions>
<version>17+</version>
</versions>
</test>

<test>
<testCaseName>test_ver_8to11</testCaseName>
<command>echo "test for version 8 to 11"; \
$(TEST_STATUS)</command>
<versions>
<version>[8, 11]</version>
</versions>
</test>

<test>
<testCaseName>test_ver_8to11and17plus</testCaseName>
<command>echo "test for version 8 to 11 and 17+"; \
$(TEST_STATUS)</command>
<versions>
<version>[8, 11]</version>
<version>17+</version>
</versions>
</test>

<test>
<testCaseName>test_disable_ver_11</testCaseName>
<disables>
<disable>
<comment>disable version 11</comment>
<version>11</version>
</disable>
</disables>
<command>echo "test for version 11"; \
$(TEST_STATUS)</command>
</test>

<test>
<testCaseName>test_disable_ver_11to17</testCaseName>
<disables>
<disable>
<comment>disable version 11 to 17</comment>
<version>[11, 17]</version>
</disable>
</disables>
<command>echo "disable test for version 11 to 17"; \
$(TEST_STATUS)</command>
</test>

<test>
<testCaseName>test_disable_ver_8and17plus</testCaseName>
<disables>
<disable>
<comment>disable version 8 and 17+</comment>
<version>8</version>
</disable>
<disable>
<comment>disable ver11</comment>
<version>17+</version>
</disable>
</disables>
<command>echo "disable test for version 8 and 17+"; \
$(TEST_STATUS)</command>
</test>
</playlist>
69 changes: 64 additions & 5 deletions scripts/testTKG/testRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
MAKE_COMPILE = "make compile"
DYNAMIC_COMPILE = "export DYNAMIC_COMPILE=true"
EXPORT_BUILDLIST = "export BUILD_LIST"
ALL_TESTS = ["base","level","hierarchy","platformRequirements"]
ALL_TESTS = ["base","level","hierarchy","platformRequirements", "jdkVersion"]
verbose = False

def main():
global verbose
ap = argparse.ArgumentParser()
ap.add_argument('-l','--testList', nargs='+', required=False, default=ALL_TESTS, help="space separated test list")
ap.add_argument('-v','--verbose', nargs='?', required=False, const=True, default=False, help="print test output")
args = vars(ap.parse_args())
testList = args['testList']
verbose = args['verbose']

rt = True

Expand Down Expand Up @@ -134,6 +138,8 @@ def test_platformRequirements():
printError("Could not parse spec from output.")
return False

print(spec)

passed = set()
skipped = set()

Expand All @@ -154,7 +160,7 @@ def test_platformRequirements():
else:
skipped.add('test_os_osx_0')

if 'osx_x86-64' == spec:
if 'osx_x86-64' in spec:
passed.add('test_osx_x86-64_0')
else:
skipped.add('test_osx_x86-64_0')
Expand All @@ -164,14 +170,62 @@ def test_platformRequirements():
else:
skipped.add('test_arch_x86_390_0')

if 'osx_x86-64' == spec or 'win_x86' == spec or 'aix_ppc-64' == spec:
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')

rt &= checkResult(result, passed, set(), set(), skipped)
return rt

def test_jdkVersion():
rt = True
printTestheader("jdkVersion")

buildList = "TKG/examples/jdkVersion"
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()
verStr = re.search(r"set JDK_VERSION to (.*)", stdout)

if verStr is not None:
try:
ver = int(verStr.group(1))
except ValueError:
print("\tTest Skipped! JDK_VERSION is not integer.")
return True
else:
printError("Could not parse JDK_VERSION from output.")
return False

passed = set()
disabled = set()

if 8 <= ver < 11:
passed.add('test_ver_8to11_0')
passed.add('test_ver_8to11and17plus_0')
passed.add('test_disable_ver_11_0')
passed.add('test_disable_ver_11to17_0')
disabled.add('test_disable_ver_8and17plus_0')
elif ver == 11:
passed.add('test_ver_11_0')
passed.add('test_ver_8to11_0')
passed.add('test_ver_8to11and17plus_0')
disabled.add('test_disable_ver_11_0')
disabled.add('test_disable_ver_11to17_0')
passed.add('test_disable_ver_8and17plus_0')
elif ver >= 17:
passed.add('test_ver_17plus_0')
passed.add('test_ver_8to11and17plus_0')
passed.add('test_disable_ver_11_0')
disabled.add('test_disable_ver_11to17_0')
disabled.add('test_disable_ver_8and17plus_0')

rt &= checkResult(result, passed, set(), disabled, set())
return rt

def printTestheader(msg):
print(f"---------------------------------\nRun test: {msg}")

Expand Down Expand Up @@ -200,20 +254,25 @@ def checkTestDetail(group, detailBlock, expected):
return rt

def checkResult(result, passed, failed, disabled, skipped):
global verbose
rt = True
stdout = result.stdout.decode()
stderr = result.stderr.decode()
if len(failed) == 0 ^ result.returncode != 0:
printError(f"test exit code: {result.returncode} is not expected")

summary = re.search(r"TEST TARGETS SUMMARY\n\+{74}\n(.*)TOTAL: (\d+) EXECUTED: (\d+) PASSED: (\d+) FAILED: (\d+) DISABLED: (\d+) SKIPPED: (\d+)\n(.*)\+{74}", stdout, flags=re.DOTALL)
if summary is None:
printError("test not completed")

if verbose is True:
stdout = textwrap.indent(stdout, '\t')
stderr = textwrap.indent(stderr, '\t')
print(f"\tstdout:\n{stdout}\n\n")
print(f"\tstderr:\n{stderr}\n\n")

if summary is None:
printError("test not completed")
return False

# print(summary.group())
testDetail = summary.group(1)
totalNum = int(summary.group(2))
Expand Down
25 changes: 19 additions & 6 deletions src/org/testKitGen/TestInfoParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,23 +193,36 @@ public TestInfo parse() {
}

private boolean checkJavaVersion(String version) {
boolean rt = false;
if (version.equalsIgnoreCase(arg.getJdkVersion())) {
rt = true;
return true;
} else {
try {
Pattern pattern = Pattern.compile("^(.*)\\+$");
Pattern pattern = Pattern.compile("^\\[(.*),(.*)\\]$");
Matcher matcher = pattern.matcher(version);
if (matcher.matches()) {
String start = matcher.group(1).trim();
String end = matcher.group(2).trim();
int currentVersion = Integer.parseInt(arg.getJdkVersion());
System.out.println(Integer.parseInt(start) + " " + Integer.parseInt(end) + " . " + currentVersion);

if (currentVersion >= Integer.parseInt(start)
&& currentVersion <= Integer.parseInt(end)) {
return true;
}
}

pattern = Pattern.compile("^(.*)\\+$");
matcher = pattern.matcher(version);
if (matcher.matches()) {
if (Integer.parseInt(matcher.group(1)) <= Integer.parseInt(arg.getJdkVersion())) {
rt = true;
return true;
}
}
} catch (NumberFormatException e) {
// Nothing to do
System.out.println("Warning: jdk version is not an integer, couldn't parse it.");
}
}
return rt;
return false;
}

private void parseDisableInfo(TestInfo ti) {
Expand Down

0 comments on commit 352134c

Please sign in to comment.