1 #
  2 # Copyright (c) 2018, 2022, 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 version
 31 JTREG_MINIMUM_VERSION=7
 32 
 33 ###############################################################################
 34 #
 35 # Setup and check for gtest framework source files
 36 #
 37 AC_DEFUN_ONCE([LIB_TESTS_SETUP_GTEST],
 38 [
 39   AC_ARG_WITH(gtest, [AS_HELP_STRING([--with-gtest],
 40       [specify prefix directory for the gtest framework])])
 41 
 42   if test "x${with_gtest}" != x; then
 43     AC_MSG_CHECKING([for gtest])
 44     if test "x${with_gtest}" = xno; then
 45       AC_MSG_RESULT([no, disabled])
 46     elif test "x${with_gtest}" = xyes; then
 47       AC_MSG_RESULT([no, error])
 48       AC_MSG_ERROR([--with-gtest must have a value])
 49     else
 50       if ! test -s "${with_gtest}/googletest/include/gtest/gtest.h"; then
 51         AC_MSG_RESULT([no])
 52         AC_MSG_ERROR([Can't find 'googletest/include/gtest/gtest.h' under ${with_gtest} given with the --with-gtest option.])
 53       elif ! test -s "${with_gtest}/googlemock/include/gmock/gmock.h"; then
 54         AC_MSG_RESULT([no])
 55         AC_MSG_ERROR([Can't find 'googlemock/include/gmock/gmock.h' under ${with_gtest} given with the --with-gtest option.])
 56       else
 57         GTEST_FRAMEWORK_SRC=${with_gtest}
 58         AC_MSG_RESULT([$GTEST_FRAMEWORK_SRC])
 59         UTIL_FIXUP_PATH([GTEST_FRAMEWORK_SRC])
 60       fi
 61     fi
 62   fi
 63 
 64   AC_SUBST(GTEST_FRAMEWORK_SRC)
 65 ])
 66 
 67 ###############################################################################
 68 #
 69 # Setup and check the Java Microbenchmark Harness
 70 #
 71 AC_DEFUN_ONCE([LIB_TESTS_SETUP_JMH],
 72 [
 73   AC_ARG_WITH(jmh, [AS_HELP_STRING([--with-jmh],
 74       [Java Microbenchmark Harness for building the OpenJDK Microbenchmark Suite])])
 75 
 76   AC_MSG_CHECKING([for jmh (Java Microbenchmark Harness)])
 77   if test "x$with_jmh" = xno || test "x$with_jmh" = x; then
 78     AC_MSG_RESULT([no, disabled])
 79   elif test "x$with_jmh" = xyes; then
 80     AC_MSG_RESULT([no, error])
 81     AC_MSG_ERROR([--with-jmh requires a directory containing all jars needed by JMH])
 82   else
 83     # Path specified
 84     JMH_HOME="$with_jmh"
 85     if test ! -d [$JMH_HOME]; then
 86       AC_MSG_RESULT([no, error])
 87       AC_MSG_ERROR([$JMH_HOME does not exist or is not a directory])
 88     fi
 89     AC_MSG_RESULT([yes, $JMH_HOME])
 90 
 91     UTIL_FIXUP_PATH([JMH_HOME])
 92 
 93     jar_names="jmh-core jmh-generator-annprocess jopt-simple commons-math3"
 94     for jar in $jar_names; do
 95       found_jar_files=$($ECHO $(ls $JMH_HOME/$jar-*.jar 2> /dev/null))
 96 
 97       if test "x$found_jar_files" = x; then
 98         AC_MSG_ERROR([--with-jmh does not contain $jar-*.jar])
 99       elif ! test -e "$found_jar_files"; then
100         AC_MSG_ERROR([--with-jmh contain multiple $jar-*.jar: $found_jar_files])
101       fi
102 
103       found_jar_var_name=found_${jar//-/_}
104       eval $found_jar_var_name='"'$found_jar_files'"'
105     done
106 
107     JMH_CORE_JAR=$found_jmh_core
108     JMH_GENERATOR_JAR=$found_jmh_generator_annprocess
109     JMH_JOPT_SIMPLE_JAR=$found_jopt_simple
110     JMH_COMMONS_MATH_JAR=$found_commons_math3
111 
112 
113     if [ [[ "$JMH_CORE_JAR" =~ jmh-core-(.*)\.jar$ ]] ] ; then
114       JMH_VERSION=${BASH_REMATCH[[1]]}
115     else
116       JMH_VERSION=unknown
117     fi
118 
119     AC_MSG_NOTICE([JMH core version: $JMH_VERSION])
120   fi
121 
122   AC_SUBST(JMH_CORE_JAR)
123   AC_SUBST(JMH_GENERATOR_JAR)
124   AC_SUBST(JMH_JOPT_SIMPLE_JAR)
125   AC_SUBST(JMH_COMMONS_MATH_JAR)
126   AC_SUBST(JMH_VERSION)
127 ])
128 
129 # Setup the JTReg Regression Test Harness.
130 AC_DEFUN_ONCE([LIB_TESTS_SETUP_JTREG],
131 [
132   AC_ARG_WITH(jtreg, [AS_HELP_STRING([--with-jtreg],
133       [Regression Test Harness @<:@probed@:>@])])
134 
135   if test "x$with_jtreg" = xno; then
136     # jtreg disabled
137     AC_MSG_CHECKING([for jtreg test harness])
138     AC_MSG_RESULT([no, disabled])
139   elif test "x$with_jtreg" != xyes && test "x$with_jtreg" != x; then
140     if test -d "$with_jtreg"; then
141       # An explicit path is specified, use it.
142       JT_HOME="$with_jtreg"
143     else
144       case "$with_jtreg" in
145         *.zip )
146           JTREG_SUPPORT_DIR=$CONFIGURESUPPORT_OUTPUTDIR/jtreg
147           $RM -rf $JTREG_SUPPORT_DIR
148           $MKDIR -p $JTREG_SUPPORT_DIR
149           $UNZIP -qq -d $JTREG_SUPPORT_DIR $with_jtreg
150 
151           # Try to find jtreg to determine JT_HOME path
152           JTREG_PATH=`$FIND $JTREG_SUPPORT_DIR | $GREP "/bin/jtreg"`
153           if test "x$JTREG_PATH" != x; then
154             JT_HOME=$($DIRNAME $($DIRNAME $JTREG_PATH))
155           fi
156           ;;
157         * )
158           ;;
159       esac
160     fi
161     UTIL_FIXUP_PATH([JT_HOME])
162     if test ! -d "$JT_HOME"; then
163       AC_MSG_ERROR([jtreg home directory from --with-jtreg=$with_jtreg does not exist])
164     fi
165 
166     if test ! -e "$JT_HOME/lib/jtreg.jar"; then
167       AC_MSG_ERROR([jtreg home directory from --with-jtreg=$with_jtreg is not a valid jtreg home])
168     fi
169 
170     AC_MSG_CHECKING([for jtreg test harness])
171     AC_MSG_RESULT([$JT_HOME])
172   else
173     # Try to locate jtreg using the JT_HOME environment variable
174     if test "x$JT_HOME" != x; then
175       # JT_HOME set in environment, use it
176       if test ! -d "$JT_HOME"; then
177         AC_MSG_WARN([Ignoring JT_HOME pointing to invalid directory: $JT_HOME])
178         JT_HOME=
179       else
180         if test ! -e "$JT_HOME/lib/jtreg.jar"; then
181           AC_MSG_WARN([Ignoring JT_HOME which is not a valid jtreg home: $JT_HOME])
182           JT_HOME=
183         else
184           AC_MSG_NOTICE([Located jtreg using JT_HOME from environment])
185         fi
186       fi
187     fi
188 
189     if test "x$JT_HOME" = x; then
190       # JT_HOME is not set in environment, or was deemed invalid.
191       # Try to find jtreg on path
192       UTIL_LOOKUP_PROGS(JTREGEXE, jtreg)
193       if test "x$JTREGEXE" != x; then
194         # That's good, now try to derive JT_HOME
195         JT_HOME=`(cd $($DIRNAME $JTREGEXE)/.. && pwd)`
196         if test ! -e "$JT_HOME/lib/jtreg.jar"; then
197           AC_MSG_WARN([Ignoring jtreg from path since a valid jtreg home cannot be found])
198           JT_HOME=
199         else
200           AC_MSG_NOTICE([Located jtreg using jtreg executable in path])
201         fi
202       fi
203     fi
204 
205     AC_MSG_CHECKING([for jtreg test harness])
206     if test "x$JT_HOME" != x; then
207       AC_MSG_RESULT([$JT_HOME])
208     else
209       AC_MSG_RESULT([no, not found])
210 
211       if test "x$with_jtreg" = xyes; then
212         AC_MSG_ERROR([--with-jtreg was specified, but no jtreg found.])
213       fi
214     fi
215   fi
216 
217   UTIL_FIXUP_PATH(JT_HOME)
218   AC_SUBST(JT_HOME)
219 
220   # Verify jtreg version
221   if test "x$JT_HOME" != x; then
222     AC_MSG_CHECKING([jtreg version number])
223     # jtreg -version looks like this: "jtreg 6.1+1-19"
224     # Extract actual version part ("6.1" in this case)
225     jtreg_version_full=`$JAVA -jar $JT_HOME/lib/jtreg.jar -version | $HEAD -n 1 | $CUT -d ' ' -f 2`
226     jtreg_version=${jtreg_version_full/%+*}
227     AC_MSG_RESULT([$jtreg_version])
228 
229     # This is a simplified version of TOOLCHAIN_CHECK_COMPILER_VERSION
230     comparable_actual_version=`$AWK -F. '{ printf("%05d%05d%05d%05d\n", [$]1, [$]2, [$]3, [$]4) }' <<< "$jtreg_version"`
231     comparable_minimum_version=`$AWK -F. '{ printf("%05d%05d%05d%05d\n", [$]1, [$]2, [$]3, [$]4) }' <<< "$JTREG_MINIMUM_VERSION"`
232     if test $comparable_actual_version -lt $comparable_minimum_version ; then
233       AC_MSG_ERROR([jtreg version is too old, at least version $JTREG_MINIMUM_VERSION is required])
234     fi
235   fi
236 ])
237 
238 # Setup the JTReg Regression Test Harness.
239 AC_DEFUN_ONCE([LIB_TESTS_SETUP_JTREG_MW],
240 [
241   AC_ARG_WITH(jtregMW, [AS_HELP_STRING([--with-jtregMW],
242       [Regression Test Harness @<:@probed@:>@])])
243 
244   if test "x$with_jtregMW" = xno; then
245     # jtreg disabled
246     AC_MSG_CHECKING([for jtreg test harness])
247     AC_MSG_RESULT([no, disabled])
248   elif test "x$with_jtregMW" != xyes && test "x$with_jtregMW" != x; then
249     # An explicit path is specified, use it.
250     JT_HOME_MW="$with_jtregMW"
251     UTIL_FIXUP_PATH([JT_HOME_MW])
252     if test ! -d "$JT_HOME_MW"; then
253       AC_MSG_ERROR([jtreg home directory from --with-jtregMW=$with_jtregMW does not exist])
254     fi
255 
256     if test ! -e "$JT_HOME_MW/lib/jtreg.jar"; then
257       AC_MSG_ERROR([jtreg home directory from --with-jtregMW=$with_jtregMW is not a valid jtreg home])
258     fi
259 
260     JTREGEXE_MW="$JT_HOME_MW/bin/jtreg"
261     if test ! -x "$JTREGEXE_MW"; then
262       AC_MSG_ERROR([jtreg home directory from --with-jtregMW=$with_jtregMW does not contain valid jtreg executable])
263     fi
264 
265     AC_MSG_CHECKING([for jtreg test harness])
266     AC_MSG_RESULT([$JT_HOME_MW])
267   else
268     # Try to locate jtreg
269     if test "x$JT_HOME_MW" != x; then
270       # JT_HOME_MW set in environment, use it
271       if test ! -d "$JT_HOME_MW"; then
272         AC_MSG_WARN([Ignoring JT_HOME_MW pointing to invalid directory: $JT_HOME_MW])
273         JT_HOME_MW=
274       else
275         if test ! -e "$JT_HOME_MW/lib/jtreg.jar"; then
276           AC_MSG_WARN([Ignoring JT_HOME_MW which is not a valid jtreg home: $JT_HOME_MW])
277           JT_HOME_MW=
278         elif test ! -x "$JT_HOME_MW/bin/jtreg"; then
279           AC_MSG_WARN([Ignoring JT_HOME_MW which does not contain valid jtreg executable: $JT_HOME_MW])
280           JT_HOME_MW=
281         else
282           JTREGEXE_MW="$JT_HOME_MW/bin/jtreg"
283           AC_MSG_NOTICE([Located jtreg using JT_HOME_MW from environment])
284         fi
285       fi
286     fi
287 
288     if test "x$JT_HOME_MW" = x; then
289       # JT_HOME_MW is not set in environment, or was deemed invalid.
290       # Try to find jtreg on path
291       UTIL_LOOKUP_PROGS(JTREGEXE_MW, jtreg)
292       if test "x$JTREGEXE_MW" != x; then
293         # That's good, now try to derive JT_HOME_MW
294         JT_HOME_MW=`(cd $($DIRNAME $JTREGEXE_MW)/.. && pwd)`
295         if test ! -e "$JT_HOME_MW/lib/jtreg.jar"; then
296           AC_MSG_WARN([Ignoring jtreg from path since a valid jtreg home cannot be found])
297           JT_HOME_MW=
298           JTREGEXE_MW=
299         else
300           AC_MSG_NOTICE([Located jtreg using jtreg executable in path])
301         fi
302       fi
303     fi
304 
305     AC_MSG_CHECKING([for jtreg test harness])
306     if test "x$JT_HOME_MW" != x; then
307       AC_MSG_RESULT([$JT_HOME_MW])
308     else
309       AC_MSG_RESULT([no, not found])
310 
311       if test "x$with_jtregMW" = xyes; then
312         AC_MSG_ERROR([--with-jtregMW was specified, but no jtreg found.])
313       fi
314     fi
315   fi
316 
317   UTIL_FIXUP_EXECUTABLE(JTREGEXE_MW)
318   UTIL_FIXUP_PATH(JT_HOME_MW)
319   AC_SUBST(JT_HOME_MW)
320   AC_SUBST(JTREGEXE_MW)
321 ])
322 
323 # Setup the JIB dependency resolver
324 AC_DEFUN_ONCE([LIB_TESTS_SETUP_JIB],
325 [
326   AC_ARG_WITH(jib, [AS_HELP_STRING([--with-jib],
327       [Jib dependency management tool @<:@not used@:>@])])
328 
329   if test "x$with_jib" = xno || test "x$with_jib" = x; then
330     # jib disabled
331     AC_MSG_CHECKING([for jib])
332     AC_MSG_RESULT(no)
333   elif test "x$with_jib" = xyes; then
334     AC_MSG_ERROR([Must supply a value to --with-jib])
335   else
336     JIB_HOME="${with_jib}"
337     AC_MSG_CHECKING([for jib])
338     AC_MSG_RESULT(${JIB_HOME})
339     if test ! -d "${JIB_HOME}"; then
340       AC_MSG_ERROR([--with-jib must be a directory])
341     fi
342     JIB_JAR=$(ls ${JIB_HOME}/lib/jib-*.jar)
343     if test ! -f "${JIB_JAR}"; then
344       AC_MSG_ERROR([Could not find jib jar file in ${JIB_HOME}])
345     fi
346   fi
347 
348   AC_SUBST(JIB_HOME)
349 ])
350 
351 ################################################################################
352 #
353 # Check if building of the jtreg failure handler should be enabled.
354 #
355 AC_DEFUN_ONCE([LIB_TESTS_ENABLE_DISABLE_FAILURE_HANDLER],
356 [
357   UTIL_ARG_ENABLE(NAME: jtreg-failure-handler, DEFAULT: auto,
358       RESULT: BUILD_FAILURE_HANDLER,
359       DESC: [enable building of the jtreg failure handler],
360       DEFAULT_DESC: [enabled if jtreg is present],
361       CHECKING_MSG: [if the jtreg failure handler should be built],
362       CHECK_AVAILABLE: [
363         AC_MSG_CHECKING([if the jtreg failure handler is available])
364         if test "x$JT_HOME" != "x"; then
365           AC_MSG_RESULT([yes])
366         else
367           AVAILABLE=false
368           AC_MSG_RESULT([no (jtreg not present)])
369         fi
370       ])
371   AC_SUBST(BUILD_FAILURE_HANDLER)
372 ])