1 #
  2 # Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
  3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4 #
  5 # This code is free software; you can redistribute it and/or modify it
  6 # under the terms of the GNU General Public License version 2 only, as
  7 # published by the Free Software Foundation.  Oracle designates this
  8 # particular file as subject to the "Classpath" exception as provided
  9 # by Oracle in the LICENSE file that accompanied this code.
 10 #
 11 # This code is distributed in the hope that it will be useful, but WITHOUT
 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14 # version 2 for more details (a copy is included in the LICENSE file that
 15 # accompanied this code).
 16 #
 17 # You should have received a copy of the GNU General Public License version
 18 # 2 along with this work; if not, write to the Free Software Foundation,
 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20 #
 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22 # or visit www.oracle.com if you need additional information or have any
 23 # questions.
 24 #
 25 
 26 ################################################################################
 27 # Setup libraries and functionalities needed to test the JDK.
 28 ################################################################################
 29 
 30 # Minimum supported versions
 31 JTREG_MINIMUM_VERSION=7.1.1
 32 GTEST_MINIMUM_VERSION=1.13.0
 33 
 34 ###############################################################################
 35 #
 36 # Setup and check for gtest framework source files
 37 #
 38 AC_DEFUN_ONCE([LIB_TESTS_SETUP_GTEST],
 39 [
 40   AC_ARG_WITH(gtest, [AS_HELP_STRING([--with-gtest],
 41       [specify prefix directory for the gtest framework])])
 42 
 43   if test "x${with_gtest}" != x; then
 44     AC_MSG_CHECKING([for gtest])
 45     if test "x${with_gtest}" = xno; then
 46       AC_MSG_RESULT([no, disabled])
 47     elif test "x${with_gtest}" = xyes; then
 48       AC_MSG_RESULT([no, error])
 49       AC_MSG_ERROR([--with-gtest must have a value])
 50     else
 51       if ! test -s "${with_gtest}/googletest/include/gtest/gtest.h"; then
 52         AC_MSG_RESULT([no])
 53         AC_MSG_ERROR([Can't find 'googletest/include/gtest/gtest.h' under ${with_gtest} given with the --with-gtest option.])
 54       elif ! test -s "${with_gtest}/googlemock/include/gmock/gmock.h"; then
 55         AC_MSG_RESULT([no])
 56         AC_MSG_ERROR([Can't find 'googlemock/include/gmock/gmock.h' under ${with_gtest} given with the --with-gtest option.])
 57       else
 58         GTEST_FRAMEWORK_SRC=$with_gtest
 59         AC_MSG_RESULT([$GTEST_FRAMEWORK_SRC])
 60         UTIL_FIXUP_PATH([GTEST_FRAMEWORK_SRC])
 61 
 62         # Verify that the version is the required one.
 63         # This is a simplified version of TOOLCHAIN_CHECK_COMPILER_VERSION
 64         gtest_version="`$GREP GOOGLETEST_VERSION $GTEST_FRAMEWORK_SRC/CMakeLists.txt | $SED -E -e 's/set\(GOOGLETEST_VERSION (.*)\)/\1/'`"
 65         comparable_actual_version=`$AWK -F. '{ printf("%05d%05d%05d%05d\n", [$]1, [$]2, [$]3, [$]4) }' <<< "$gtest_version"`
 66         comparable_minimum_version=`$AWK -F. '{ printf("%05d%05d%05d%05d\n", [$]1, [$]2, [$]3, [$]4) }' <<< "$GTEST_MINIMUM_VERSION"`
 67         if test $comparable_actual_version -lt $comparable_minimum_version ; then
 68           AC_MSG_ERROR([gtest version is too old, at least version $GTEST_MINIMUM_VERSION is required])
 69         fi
 70       fi
 71     fi
 72   fi
 73 
 74   AC_SUBST(GTEST_FRAMEWORK_SRC)
 75 ])
 76 
 77 ###############################################################################
 78 #
 79 # Setup and check the Java Microbenchmark Harness
 80 #
 81 AC_DEFUN_ONCE([LIB_TESTS_SETUP_JMH],
 82 [
 83   AC_ARG_WITH(jmh, [AS_HELP_STRING([--with-jmh],
 84       [Java Microbenchmark Harness for building the OpenJDK Microbenchmark Suite])])
 85 
 86   AC_MSG_CHECKING([for jmh (Java Microbenchmark Harness)])
 87   if test "x$with_jmh" = xno || test "x$with_jmh" = x; then
 88     AC_MSG_RESULT([no, disabled])
 89   elif test "x$with_jmh" = xyes; then
 90     AC_MSG_RESULT([no, error])
 91     AC_MSG_ERROR([--with-jmh requires a directory containing all jars needed by JMH])
 92   else
 93     # Path specified
 94     JMH_HOME="$with_jmh"
 95     if test ! -d [$JMH_HOME]; then
 96       AC_MSG_RESULT([no, error])
 97       AC_MSG_ERROR([$JMH_HOME does not exist or is not a directory])
 98     fi
 99     AC_MSG_RESULT([yes, $JMH_HOME])
100 
101     UTIL_FIXUP_PATH([JMH_HOME])
102 
103     jar_names="jmh-core jmh-generator-annprocess jopt-simple commons-math3"
104     for jar in $jar_names; do
105       found_jar_files=$($ECHO $(ls $JMH_HOME/$jar-*.jar 2> /dev/null))
106 
107       if test "x$found_jar_files" = x; then
108         AC_MSG_ERROR([--with-jmh does not contain $jar-*.jar])
109       elif ! test -e "$found_jar_files"; then
110         AC_MSG_ERROR([--with-jmh contain multiple $jar-*.jar: $found_jar_files])
111       fi
112 
113       found_jar_var_name=found_${jar//-/_}
114       eval $found_jar_var_name='"'$found_jar_files'"'
115     done
116 
117     JMH_CORE_JAR=$found_jmh_core
118     JMH_GENERATOR_JAR=$found_jmh_generator_annprocess
119     JMH_JOPT_SIMPLE_JAR=$found_jopt_simple
120     JMH_COMMONS_MATH_JAR=$found_commons_math3
121 
122 
123     if [ [[ "$JMH_CORE_JAR" =~ jmh-core-(.*)\.jar$ ]] ] ; then
124       JMH_VERSION=${BASH_REMATCH[[1]]}
125     else
126       JMH_VERSION=unknown
127     fi
128 
129     AC_MSG_NOTICE([JMH core version: $JMH_VERSION])
130   fi
131 
132   AC_SUBST(JMH_CORE_JAR)
133   AC_SUBST(JMH_GENERATOR_JAR)
134   AC_SUBST(JMH_JOPT_SIMPLE_JAR)
135   AC_SUBST(JMH_COMMONS_MATH_JAR)
136   AC_SUBST(JMH_VERSION)
137 ])
138 
139 # Setup the JTReg Regression Test Harness.
140 AC_DEFUN_ONCE([LIB_TESTS_SETUP_JTREG],
141 [
142   AC_ARG_WITH(jtreg, [AS_HELP_STRING([--with-jtreg],
143       [Regression Test Harness @<:@probed@:>@])])
144 
145   if test "x$with_jtreg" = xno; then
146     # jtreg disabled
147     AC_MSG_CHECKING([for jtreg test harness])
148     AC_MSG_RESULT([no, disabled])
149   elif test "x$with_jtreg" != xyes && test "x$with_jtreg" != x; then
150     if test -d "$with_jtreg"; then
151       # An explicit path is specified, use it.
152       JT_HOME="$with_jtreg"
153     else
154       case "$with_jtreg" in
155         *.zip )
156           JTREG_SUPPORT_DIR=$CONFIGURESUPPORT_OUTPUTDIR/jtreg
157           $RM -rf $JTREG_SUPPORT_DIR
158           $MKDIR -p $JTREG_SUPPORT_DIR
159           $UNZIP -qq -d $JTREG_SUPPORT_DIR $with_jtreg
160 
161           # Try to find jtreg to determine JT_HOME path
162           JTREG_PATH=`$FIND $JTREG_SUPPORT_DIR | $GREP "/bin/jtreg"`
163           if test "x$JTREG_PATH" != x; then
164             JT_HOME=$($DIRNAME $($DIRNAME $JTREG_PATH))
165           fi
166           ;;
167         * )
168           ;;
169       esac
170     fi
171     UTIL_FIXUP_PATH([JT_HOME])
172     if test ! -d "$JT_HOME"; then
173       AC_MSG_ERROR([jtreg home directory from --with-jtreg=$with_jtreg does not exist])
174     fi
175 
176     if test ! -e "$JT_HOME/lib/jtreg.jar"; then
177       AC_MSG_ERROR([jtreg home directory from --with-jtreg=$with_jtreg is not a valid jtreg home])
178     fi
179 
180     AC_MSG_CHECKING([for jtreg test harness])
181     AC_MSG_RESULT([$JT_HOME])
182   else
183     # Try to locate jtreg using the JT_HOME environment variable
184     if test "x$JT_HOME" != x; then
185       # JT_HOME set in environment, use it
186       if test ! -d "$JT_HOME"; then
187         AC_MSG_WARN([Ignoring JT_HOME pointing to invalid directory: $JT_HOME])
188         JT_HOME=
189       else
190         if test ! -e "$JT_HOME/lib/jtreg.jar"; then
191           AC_MSG_WARN([Ignoring JT_HOME which is not a valid jtreg home: $JT_HOME])
192           JT_HOME=
193         else
194           AC_MSG_NOTICE([Located jtreg using JT_HOME from environment])
195         fi
196       fi
197     fi
198 
199     if test "x$JT_HOME" = x; then
200       # JT_HOME is not set in environment, or was deemed invalid.
201       # Try to find jtreg on path
202       UTIL_LOOKUP_PROGS(JTREGEXE, jtreg)
203       if test "x$JTREGEXE" != x; then
204         # That's good, now try to derive JT_HOME
205         JT_HOME=`(cd $($DIRNAME $JTREGEXE)/.. && pwd)`
206         if test ! -e "$JT_HOME/lib/jtreg.jar"; then
207           AC_MSG_WARN([Ignoring jtreg from path since a valid jtreg home cannot be found])
208           JT_HOME=
209         else
210           AC_MSG_NOTICE([Located jtreg using jtreg executable in path])
211         fi
212       fi
213     fi
214 
215     AC_MSG_CHECKING([for jtreg test harness])
216     if test "x$JT_HOME" != x; then
217       AC_MSG_RESULT([$JT_HOME])
218     else
219       AC_MSG_RESULT([no, not found])
220 
221       if test "x$with_jtreg" = xyes; then
222         AC_MSG_ERROR([--with-jtreg was specified, but no jtreg found.])
223       fi
224     fi
225   fi
226 
227   UTIL_FIXUP_PATH(JT_HOME)
228   AC_SUBST(JT_HOME)
229 
230   # Verify jtreg version
231   if test "x$JT_HOME" != x; then
232     AC_MSG_CHECKING([jtreg version number])
233     # jtreg -version looks like this: "jtreg 6.1+1-19"
234     # Extract actual version part ("6.1" in this case)
235     jtreg_version_full=`$JAVA -jar $JT_HOME/lib/jtreg.jar -version | $HEAD -n 1 | $CUT -d ' ' -f 2`
236     jtreg_version=${jtreg_version_full/%+*}
237     AC_MSG_RESULT([$jtreg_version])
238 
239     # This is a simplified version of TOOLCHAIN_CHECK_COMPILER_VERSION
240     comparable_actual_version=`$AWK -F. '{ printf("%05d%05d%05d%05d\n", [$]1, [$]2, [$]3, [$]4) }' <<< "$jtreg_version"`
241     comparable_minimum_version=`$AWK -F. '{ printf("%05d%05d%05d%05d\n", [$]1, [$]2, [$]3, [$]4) }' <<< "$JTREG_MINIMUM_VERSION"`
242     if test $comparable_actual_version -lt $comparable_minimum_version ; then
243       AC_MSG_ERROR([jtreg version is too old, at least version $JTREG_MINIMUM_VERSION is required])
244     fi
245   fi
246 ])
247 
248 # Setup the JIB dependency resolver
249 AC_DEFUN_ONCE([LIB_TESTS_SETUP_JIB],
250 [
251   AC_ARG_WITH(jib, [AS_HELP_STRING([--with-jib],
252       [Jib dependency management tool @<:@not used@:>@])])
253 
254   if test "x$with_jib" = xno || test "x$with_jib" = x; then
255     # jib disabled
256     AC_MSG_CHECKING([for jib])
257     AC_MSG_RESULT(no)
258   elif test "x$with_jib" = xyes; then
259     AC_MSG_ERROR([Must supply a value to --with-jib])
260   else
261     JIB_HOME="${with_jib}"
262     AC_MSG_CHECKING([for jib])
263     AC_MSG_RESULT(${JIB_HOME})
264     if test ! -d "${JIB_HOME}"; then
265       AC_MSG_ERROR([--with-jib must be a directory])
266     fi
267     JIB_JAR=$(ls ${JIB_HOME}/lib/jib-*.jar)
268     if test ! -f "${JIB_JAR}"; then
269       AC_MSG_ERROR([Could not find jib jar file in ${JIB_HOME}])
270     fi
271   fi
272 
273   AC_SUBST(JIB_HOME)
274 ])
275 
276 ################################################################################
277 #
278 # Check if building of the jtreg failure handler should be enabled.
279 #
280 AC_DEFUN_ONCE([LIB_TESTS_ENABLE_DISABLE_FAILURE_HANDLER],
281 [
282   if test "x$BUILD_ENV" = "xci"; then
283     BUILD_FAILURE_HANDLER_DEFAULT=auto
284   else
285     BUILD_FAILURE_HANDLER_DEFAULT=false
286   fi
287 
288   UTIL_ARG_ENABLE(NAME: jtreg-failure-handler, DEFAULT: $BUILD_FAILURE_HANDLER_DEFAULT,
289       RESULT: BUILD_FAILURE_HANDLER,
290       DESC: [enable building of the jtreg failure handler],
291       DEFAULT_DESC: [enabled if jtreg is present and build env is CI],
292       CHECKING_MSG: [if the jtreg failure handler should be built],
293       CHECK_AVAILABLE: [
294         AC_MSG_CHECKING([if the jtreg failure handler is available])
295         if test "x$JT_HOME" != "x"; then
296           AC_MSG_RESULT([yes])
297         else
298           AVAILABLE=false
299           AC_MSG_RESULT([no (jtreg not present)])
300         fi
301       ])
302   AC_SUBST(BUILD_FAILURE_HANDLER)
303 ])