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

Add Smoke tests for build & packaging #2397

Merged
merged 9 commits into from
Feb 5, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions test/functional/buildAndPackage/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0"?>

<!--
# 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.
-->

<project name="Functional Build And Packaging Tests" default="build" basedir=".">
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<description>
AdoptOpenJDK Functional tests
</description>
<import file="${TEST_ROOT}/functional/build.xml"/>

<!-- set global properties for this build -->
<property name="DEST" value="${BUILD_ROOT}/functional/buildAndPackage"/>

<!--Properties for this particular build-->
<property name="src" location="./src"/>
<property name="build" location="./bin"/>

<target name="init">
<mkdir dir="${DEST}"/>
<mkdir dir="${build}"/>
</target>

<target name="compile" depends="init" description="Using java ${JDK_VERSION} to compile the source ">
<echo>Ant version is ${ant.version}</echo>
<echo>============COMPILER SETTINGS============</echo>
<echo>===fork: yes</echo>
<echo>===executable: ${compiler.javac}</echo>
<echo>===debug: on</echo>
<echo>===destdir: ${DEST}</echo>
<javac srcdir="${src}" destdir="${build}" debug="true" fork="true" executable="${compiler.javac}"
includeAntRuntime="false" encoding="ISO-8859-1">
<src path="${src}"/>
<classpath>
<pathelement location="${LIB_DIR}/testng.jar"/>
</classpath>
</javac>
</target>

<target name="dist" depends="compile,dist_functional" description="generate the distribution">
<jar jarfile="${DEST}/BuildAndPackagingTests.jar" filesonly="true">
<fileset dir="${build}"/>
<fileset dir="${src}/../" includes="*.properties,*.xml"/>
</jar>
<copy todir="${DEST}">
<fileset dir="${src}/../" includes="*.xml"/>
<fileset dir="${src}/../" includes="*.mk"/>
</copy>
</target>

<target name="clean" depends="dist" description="clean up">
<!-- Delete the ${build} directory trees -->
<delete dir="${build}"/>
</target>

<target name="build">
<antcall target="clean" inheritall="true"/>
</target>
</project>
74 changes: 74 additions & 0 deletions test/functional/buildAndPackage/playlist.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?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>Adopt_HS_FeatureTests</testCaseName>
<command>
$(JAVA_COMMAND) $(JVM_OPTIONS) -cp \
$(Q)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(TEST_RESROOT)$(D)BuildAndPackagingTests.jar$(Q) org.testng.TestNG \
$(Q)$(TEST_RESROOT)$(D)testng.xml$(Q) -d $(REPORTDIR) -testnames CommonFeatureTests,HotspotFeatureTests -groups $(TEST_GROUP) \
-excludegroups $(DEFAULT_EXCLUDE); $(TEST_STATUS)
</command>
<levels>
<level>extended</level>
</levels>
<groups>
<group>functional</group>
</groups>
<impls>
<impl>hotspot</impl>
</impls>
<vendors>
<vendor>adoptopenjdk</vendor>
</vendors>
</test>
<test>
<testCaseName>Adopt_J9_FeatureTests</testCaseName>
<command>
$(JAVA_COMMAND) $(JVM_OPTIONS) -cp \
$(Q)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(TEST_RESROOT)$(D)BuildAndPackagingTests.jar$(Q) org.testng.TestNG \
$(Q)$(TEST_RESROOT)$(D)testng.xml$(Q) -d $(REPORTDIR) -testnames CommonFeatureTests -groups $(TEST_GROUP) \
-excludegroups $(DEFAULT_EXCLUDE); $(TEST_STATUS)
</command>
<levels>
<level>extended</level>
</levels>
<groups>
<group>functional</group>
</groups>
<impls>
<impl>openj9</impl>
</impls>
</test>
<test>
<testCaseName>CudaEnabledTest</testCaseName>
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) -cp $(Q)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(TEST_RESROOT)$(D)BuildAndPackagingTests.jar$(Q) org.testng.TestNG $(Q)$(TEST_RESROOT)$(D)testng.xml$(Q) -d $(REPORTDIR) -testnames CudaEnabledTest -groups $(TEST_GROUP) -excludegroups $(DEFAULT_EXCLUDE); \
$(TEST_STATUS)</command>
<levels>
<level>extended</level>
</levels>
<groups>
<group>functional</group>
</groups>
<platformRequirements>os.linux</platformRequirements>
<impls>
<impl>openj9</impl>
</impls>
<vendors>
<vendor>adoptopenjdk</vendor>
</vendors>
</test>
</playlist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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.
*/

package net.adoptopenjdk.test;

import org.testng.annotations.Test;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Set;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static net.adoptopenjdk.test.JdkPlatform.OperatingSystem;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

/**
* Freetype needs to be bundled on Windows and macOS but should not be present on Linux or AIX.
*
* @see <a href="https://github.com/AdoptOpenJDK/openjdk-build/issues/2133">AdoptOpenJDK enhancement request</a>
*/
@Test(groups = {"level.extended"})
public class BundledFreetypeTest {

private static final Logger LOGGER = Logger.getLogger(BundledFreetypeTest.class.getName());

private final JdkPlatform jdkPlatform = new JdkPlatform();

@Test
public void freetypeOnlyBundledOnWindowsAndMacOS() throws IOException {
String testJdkHome = System.getenv("TEST_JDK_HOME");
if (testJdkHome == null) {
throw new AssertionError("TEST_JDK_HOME is not set");
}

Pattern freetypePattern = Pattern.compile("(.*)?libfreetype\\.(dll|dylib|so)$");
Set<String> freetypeFiles = Files.walk(Paths.get(testJdkHome))
.map(Path::toString)
.filter(name -> freetypePattern.matcher(name).matches())
.collect(Collectors.toSet());

if (jdkPlatform.runsOn(OperatingSystem.MACOS) || jdkPlatform.runsOn(OperatingSystem.WINDOWS)) {
assertTrue(freetypeFiles.size() > 0, "Expected libfreetype to be bundled but is not.");
} else {
LOGGER.info("Found freetype-related files: " + freetypeFiles.toString());
assertEquals(freetypeFiles.size(), 0, "Expected libfreetype not to be bundled but it is.");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package net.adoptopenjdk.test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.testng.log4testng.Logger;

/*
* Tests if the Cuda functionality is enabled in this build.
* Fit for OpenJ9 builds on Windows, xLinux and pLinux.
*/
@Test(groups={ "level.extended" })
public class CudaEnabledTest {

private static Logger logger = Logger.getLogger(CudaEnabledTest.class);

public int getJDKVersion() {
String javaVersion = System.getProperty("java.version");
if (javaVersion.startsWith("1.")) {
javaVersion = javaVersion.substring(2);
}
int dotIndex = javaVersion.indexOf('.');
int dashIndex = javaVersion.indexOf('-');
try {
return Integer.parseInt(javaVersion.substring(0, dotIndex > -1 ? dotIndex : dashIndex > -1 ? dashIndex : javaVersion.length()));
} catch (NumberFormatException e) {
System.out.println("Cannot determine System.getProperty('java.version')=" + javaVersion + "\n");
return -1;
}
}

@Test
public void testIfCudaIsEnabled() {

logger.info("Starting test to see if CUDA functionality is enabled in this build.");

//Stage 1: Find the location of the j9prt lib file.
String prtLibDirectory = System.getProperty("java.home");
String jreSubdir = "";
if((new File(prtLibDirectory + "/jre")).exists()) {
jreSubdir = "/jre";
}
if("Linux".contains(System.getProperty("os.name").split(" ")[0])) {
if(getJDKVersion() == 8) {
prtLibDirectory += jreSubdir + "/lib/amd64/compressedrefs";
} else {
prtLibDirectory += "/lib/compressedrefs";
}
}
//windows
if("Windows".contains(System.getProperty("os.name").split(" ")[0])) {
if(getJDKVersion() == 8) {
//jdk8 32:
prtLibDirectory += jreSubdir + "/bin/compressedrefs";
if(!(new File(prtLibDirectory)).exists()) {
//In case of a 32-bit build, or a non-cr build.
prtLibDirectory = System.getProperty("java.home") + jreSubdir + "/bin/default";
}
} else {
prtLibDirectory += "/bin/compressedrefs";
}
}

File prtDirObject = new File(prtLibDirectory);
Assert.assertTrue(prtDirObject.exists(), "Can't find the predicted location of the j9prt lib file. Expected location: " + prtLibDirectory);

String[] prtLibDirectoryFiles = prtDirObject.list();
String prtFile = null;
for(int x = 0 ; x < prtLibDirectoryFiles.length ; x++) {
if(prtLibDirectoryFiles[x].contains("j9prt")) {
prtFile = prtLibDirectory + "/" + prtLibDirectoryFiles[x];
break;
}
}
Assert.assertNotNull(prtFile,"Can't find the j9prt lib file in " + prtLibDirectory);
Assert.assertTrue((new File (prtFile)).exists(), "Found the prt file, but it doesn't exist. Tautology bug.");
Assert.assertTrue((new File (prtFile)).canRead(), "Found the prt file, but it can't be read. Likely a permissions bug.");

//Stage 2: Iterate through the j9prt lib file to find "cudart".
//If we find it, then cuda functionality is enabled on this build.
try {
BufferedReader prtFileReader = new BufferedReader(new FileReader(prtFile));
String oneLine = "";
while ((oneLine = prtFileReader.readLine()) != null) {
if(oneLine.contains("cudart")) {
logger.info("Test completed successfully.");
return; //Success!
}
}
prtFileReader.close();
} catch (FileNotFoundException e) {
Assert.fail("A file that exists could not be found. This should never happen.");
} catch (Exception e) {
throw new Error(e);
}
Assert.fail("Cuda should be enabled on this build, but we found no evidence that this was the case.");
}

}
Loading