1 #
  2 # Copyright (c) 2018, 2025, 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.5.2
 32 GTEST_MINIMUM_VERSION=1.14.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 '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   # Specify a JDK for running jtreg. Defaults to the BOOT_JDK.
231   AC_ARG_WITH(jtreg-jdk, [AS_HELP_STRING([--with-jdk],
232     [path to JDK for running jtreg @<:@BOOT_JDK@:>@])])
233 
234   AC_MSG_CHECKING([for jtreg jdk])
235   if test "x${with_jtreg_jdk}" != x; then
236     if test "x${with_jtreg_jdk}" = xno; then
237       AC_MSG_RESULT([no, jtreg jdk not specified])
238     elif test "x${with_jtreg_jdk}" = xyes; then
239       AC_MSG_RESULT([not specified])
240       AC_MSG_ERROR([--with-jtreg-jdk needs a value])
241     else
242       JTREG_JDK="${with_jtreg_jdk}"
243       AC_MSG_RESULT([$JTREG_JDK])
244       UTIL_FIXUP_PATH(JTREG_JDK)
245       if test ! -f "$JTREG_JDK/bin/java"; then
246         AC_MSG_ERROR([Could not find jtreg java at $JTREG_JDK/bin/java])
247       fi
248     fi
249   else
250     JTREG_JDK="${BOOT_JDK}"
251     AC_MSG_RESULT([no, using BOOT_JDK])
252   fi
253 
254   UTIL_FIXUP_PATH(JTREG_JDK)
255   AC_SUBST([JTREG_JDK])
256   # For use in the configure script
257   JTREG_JAVA="$FIXPATH $JTREG_JDK/bin/java"
258 
259   # Verify jtreg version
260   if test "x$JT_HOME" != x; then
261     AC_MSG_CHECKING([jtreg jar existence])
262     if test ! -f "$JT_HOME/lib/jtreg.jar"; then
263       AC_MSG_ERROR([Could not find jtreg jar at $JT_HOME/lib/jtreg.jar])
264     fi
265 
266     AC_MSG_CHECKING([jtreg version number])
267     # jtreg -version looks like this: "jtreg 6.1+1-19"
268     # Extract actual version part ("6.1" in this case)
269     jtreg_version_full=$($JTREG_JAVA -jar $JT_HOME/lib/jtreg.jar -version | $HEAD -n 1 | $CUT -d ' ' -f 2)
270 
271     jtreg_version=${jtreg_version_full/%+*}
272     AC_MSG_RESULT([$jtreg_version])
273 
274     # This is a simplified version of TOOLCHAIN_CHECK_COMPILER_VERSION
275     comparable_actual_version=`$AWK -F. '{ printf("%05d%05d%05d%05d\n", [$]1, [$]2, [$]3, [$]4) }' <<< "$jtreg_version"`
276     comparable_minimum_version=`$AWK -F. '{ printf("%05d%05d%05d%05d\n", [$]1, [$]2, [$]3, [$]4) }' <<< "$JTREG_MINIMUM_VERSION"`
277     if test $comparable_actual_version -lt $comparable_minimum_version ; then
278       AC_MSG_ERROR([jtreg version is too old, at least version $JTREG_MINIMUM_VERSION is required])
279     fi
280   fi
281 ])
282 
283 # Setup the JIB dependency resolver
284 AC_DEFUN_ONCE([LIB_TESTS_SETUP_JIB],
285 [
286   AC_ARG_WITH(jib, [AS_HELP_STRING([--with-jib],
287       [Jib dependency management tool @<:@not used@:>@])])
288 
289   if test "x$with_jib" = xno || test "x$with_jib" = x; then
290     # jib disabled
291     AC_MSG_CHECKING([for jib])
292     AC_MSG_RESULT(no)
293   elif test "x$with_jib" = xyes; then
294     AC_MSG_ERROR([Must supply a value to --with-jib])
295   else
296     JIB_HOME="${with_jib}"
297     AC_MSG_CHECKING([for jib])
298     AC_MSG_RESULT(${JIB_HOME})
299     if test ! -d "${JIB_HOME}"; then
300       AC_MSG_ERROR([--with-jib must be a directory])
301     fi
302     JIB_JAR=$(ls ${JIB_HOME}/lib/jib-*.jar)
303     if test ! -f "${JIB_JAR}"; then
304       AC_MSG_ERROR([Could not find jib jar file in ${JIB_HOME}])
305     fi
306   fi
307 
308   AC_SUBST(JIB_HOME)
309 ])
310 
311 # Setup the tidy html checker
312 AC_DEFUN_ONCE([LIB_TESTS_SETUP_TIDY],
313 [
314   UTIL_LOOKUP_PROGS(TIDY, tidy)
315 
316   if test "x$TIDY" != x; then
317     AC_MSG_CHECKING([if tidy is working properly])
318     tidy_output=`$TIDY --version 2>&1`
319     if ! $ECHO "$tidy_output" | $GREP -q "HTML Tidy" 2>&1 > /dev/null; then
320       AC_MSG_RESULT([no])
321       AC_MSG_NOTICE([$TIDY is not a valid tidy executable and will be ignored. Output from --version: $tidy_output])
322       TIDY=
323     elif ! $ECHO "$tidy_output" | $GREP -q "version" 2>&1 > /dev/null; then
324       AC_MSG_RESULT([no])
325       AC_MSG_NOTICE([$TIDY is missing a proper version number and will be ignored. Output from --version: $tidy_output])
326       TIDY=
327     else
328       AC_MSG_RESULT([yes])
329       AC_MSG_CHECKING([for tidy version])
330       tidy_version=`$ECHO $tidy_output | $SED -e 's/.*version //g'`
331       AC_MSG_RESULT([$tidy_version])
332     fi
333   fi
334   AC_SUBST(TIDY)
335 ])
336 
337 ################################################################################
338 #
339 # Check if building of the jtreg failure handler should be enabled.
340 #
341 AC_DEFUN_ONCE([LIB_TESTS_ENABLE_DISABLE_FAILURE_HANDLER],
342 [
343   if test "x$BUILD_ENV" = "xci"; then
344     BUILD_FAILURE_HANDLER_DEFAULT=auto
345   else
346     BUILD_FAILURE_HANDLER_DEFAULT=false
347   fi
348 
349   UTIL_ARG_ENABLE(NAME: jtreg-failure-handler, DEFAULT: $BUILD_FAILURE_HANDLER_DEFAULT,
350       RESULT: BUILD_FAILURE_HANDLER,
351       DESC: [enable building of the jtreg failure handler],
352       DEFAULT_DESC: [enabled if jtreg is present and build env is CI],
353       CHECKING_MSG: [if the jtreg failure handler should be built],
354       CHECK_AVAILABLE: [
355         AC_MSG_CHECKING([if the jtreg failure handler is available])
356         if test "x$JT_HOME" != "x"; then
357           AC_MSG_RESULT([yes])
358         else
359           AVAILABLE=false
360           AC_MSG_RESULT([no (jtreg not present)])
361         fi
362       ])
363   AC_SUBST(BUILD_FAILURE_HANDLER)
364 ])
365 
366 AC_DEFUN_ONCE([LIB_TESTS_ENABLE_DISABLE_JTREG_TEST_THREAD_FACTORY],
367 [
368   UTIL_ARG_ENABLE(NAME: jtreg-test-thread-factory, DEFAULT: auto,
369       RESULT: BUILD_JTREG_TEST_THREAD_FACTORY,
370       DESC: [enable building of the jtreg test thread factory],
371       DEFAULT_DESC: [enabled if jtreg is present],
372       CHECKING_MSG: [if the jtreg test thread factory should be built],
373       CHECK_AVAILABLE: [
374         AC_MSG_CHECKING([if the jtreg test thread factory is available])
375         if test "x$JT_HOME" != "x"; then
376           AC_MSG_RESULT([yes])
377         else
378           AVAILABLE=false
379           AC_MSG_RESULT([no (jtreg not present)])
380         fi
381       ])
382   AC_SUBST(BUILD_JTREG_TEST_THREAD_FACTORY)
383 ])