Path: blob/master/test/jdk/tools/jpackage/run_tests.sh
66643 views
#!/bin/bash12# Copyright (c) 2020, 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 it6# under the terms of the GNU General Public License version 2 only, as7# published by the Free Software Foundation.8#9# This code is distributed in the hope that it will be useful, but WITHOUT10# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12# version 2 for more details (a copy is included in the LICENSE file that13# accompanied this code).14#15# You should have received a copy of the GNU General Public License version16# 2 along with this work; if not, write to the Free Software Foundation,17# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18#19# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20# or visit www.oracle.com if you need additional information or have any21# questions.2223#24# Script to run jpackage tests.25#262728# Fail fast29set -e; set -o pipefail;3031# $JT_BUNDLE_URL (Link can be obtained from https://openjdk.java.net/jtreg/ page)32jtreg_bundle=$JT_BUNDLE_URL33workdir=/tmp/jpackage_jtreg_testing34jtreg_jar=$workdir/jtreg/lib/jtreg.jar35jpackage_test_selector=test/jdk/tools/jpackage363738find_packaging_tests ()39{40(cd "$open_jdk_with_jpackage_jtreg_tests" && \41find "$jpackage_test_selector/$1" -type f -name '*.java' \42| xargs grep -E -l '@key[[:space:]]+jpackagePlatformPackage')43}444546find_all_packaging_tests ()47{48find_packaging_tests share49case "$(uname -s)" in50Darwin)51find_packaging_tests macosx;;52Linux)53find_packaging_tests linux;;54CYGWIN*|MINGW32*|MSYS*)55find_packaging_tests windows;;56*)57fatal Failed to detect OS type;;58esac59}606162help_usage ()63{64echo "Usage: `basename $0` [options] [--] [jtreg_options|test_names]"65echo "Options:"66echo " -h - print this message"67echo " -v - verbose output"68echo " -c - keep jtreg cache"69echo " -a - run all, not only SQE tests"70echo " -d - dry run. Print jtreg command line, but don't execute it"71echo " -t <jdk> - path to JDK to be tested [ mandatory ]"72echo " -j <openjdk> - path to local copy of openjdk repo with jpackage jtreg tests"73echo " Optional, default is openjdk repo where this script resides"74echo " -o <outputdir> - path to folder where to copy artifacts for testing."75echo " Optional, default is the current directory."76echo ' -r <runtimedir> - value for `jpackage.test.runtime-image` property.'77echo " Optional, for jtreg tests debug purposes only."78echo ' -l <logfile> - value for `jpackage.test.logfile` property.'79echo " Optional, for jtreg tests debug purposes only."80echo " -m <mode> - mode to run jtreg tests. Supported values:"81echo ' - `create`'82echo ' Remove all package bundles from the output directory before running jtreg tests.'83echo ' - `update`'84echo ' Run jtreg tests and overrite existing package bundles in the output directory.'85echo ' - `print-default-tests`'86echo ' Print default list of packaging tests and exit.'87echo ' - `create-small-runtime`'88echo ' Create small Java runtime using <jdk>/bin/jlink command in the output directory.'89echo ' - `create-packages`'90echo ' Create packages.'91echo ' The script will set `jpackage.test.action` property.'92echo ' - `test-packages`'93echo ' Create and fully test packages. Will create, unpack, install, and uninstall packages.'94echo ' The script will set `jpackage.test.action` property.'95echo ' - `do-packages`'96echo " Create, unpack and verify packages."97echo ' The script will not set `jpackage.test.action` property.'98echo ' Optional, defaults are `update` and `create-packages`.'99}100101error ()102{103echo "$@" > /dev/stderr104}105106fatal ()107{108error "$@"109exit 1110}111112fatal_with_help_usage ()113{114error "$@"115help_usage116exit 1117}118119if command -v cygpath &> /dev/null; then120to_native_path ()121{122cygpath -m "$@"123}124else125to_native_path ()126{127echo "$@"128}129fi130131exec_command ()132{133if [ -n "$dry_run" ]; then134echo "$@"135else136eval "$@"137fi138}139140141# Path to JDK to be tested.142test_jdk=143144# Path to local copy of open jdk repo with jpackage jtreg tests145open_jdk_with_jpackage_jtreg_tests=$(dirname $0)/../../../../146147# Directory where to save artifacts for testing.148output_dir=$PWD149150# Script and jtreg debug.151verbose=152jtreg_verbose="-verbose:fail,error,summary"153154keep_jtreg_cache=155156# Mode in which to run jtreg tests157mode=update158159# jtreg extra arguments160declare -a jtreg_args161162# run all tests163run_all_tests=164165test_actions=166167set_mode ()168{169case "$1" in170create-packages) test_actions='-Djpackage.test.action=create';;171test-packages) test_actions='-Djpackage.test.action=uninstall,create,unpack,verify-install,install,verify-install,uninstall,verify-uninstall,purge';;172do-packages) test_actions=;;173create-small-runtime) mode=$1;;174print-default-tests) mode=$1;;175create) mode=$1;;176update) mode=$1;;177*) fatal_with_help_usage 'Invalid value of -m option:' [$1];;178esac179}180181set_mode 'create-packages'182183mapfile -t tests < <(find_all_packaging_tests)184185while getopts "vahdct:j:o:r:m:l:" argname; do186case "$argname" in187v) verbose=yes;;188a) run_all_tests=yes;;189d) dry_run=yes;;190c) keep_jtreg_cache=yes;;191t) test_jdk="$OPTARG";;192j) open_jdk_with_jpackage_jtreg_tests="$OPTARG";;193o) output_dir="$OPTARG";;194r) runtime_dir="$OPTARG";;195l) logfile="$OPTARG";;196m) set_mode "$OPTARG";;197h) help_usage; exit 0;;198?) help_usage; exit 1;;199esac200done201shift $(( OPTIND - 1 ))202203[ -z "$verbose" ] || { set -x; jtreg_verbose=-va; }204205if [ -z "$open_jdk_with_jpackage_jtreg_tests" ]; then206fatal_with_help_usage "Path to openjdk repo with jpackage jtreg tests not specified"207fi208209if [ "$mode" = "print-default-tests" ]; then210exec_command for t in ${tests[@]}";" do echo '$t;' done211exit212fi213214if [ -z "$test_jdk" ]; then215fatal_with_help_usage Path to test JDK not specified216fi217218if [ -z "$JAVA_HOME" ]; then219echo JAVA_HOME environment variable not set, will use java from test JDK [$test_jdk] to run jtreg220JAVA_HOME="$test_jdk"221fi222if [ ! -e "$JAVA_HOME/bin/java" ]; then223fatal JAVA_HOME variable is set to [$JAVA_HOME] value, but $JAVA_HOME/bin/java not found.224fi225226if [ "$mode" = "create-small-runtime" ]; then227exec_command "$test_jdk/bin/jlink" --add-modules java.base,java.datatransfer,java.xml,java.prefs,java.desktop --compress=2 --no-header-files --no-man-pages --strip-debug --output "$output_dir"228exit229fi230231if [ -z "$JT_HOME" ]; then232if [ -z "$JT_BUNDLE_URL" ]; then233fatal 'JT_HOME or JT_BUNDLE_URL environment variable is not set. Link to JTREG bundle can be found at https://openjdk.java.net/jtreg/'.234fi235fi236237if [ -n "$runtime_dir" ]; then238if [ ! -d "$runtime_dir" ]; then239fatal 'Value of `-r` option is set to non-existing directory'.240fi241jtreg_args+=("-Djpackage.test.runtime-image=$(to_native_path "$(cd "$runtime_dir" && pwd)")")242fi243244if [ -n "$logfile" ]; then245if [ ! -d "$(dirname "$logfile")" ]; then246fatal 'Value of `-l` option specified a file in non-existing directory'.247fi248logfile="$(cd "$(dirname "$logfile")" && pwd)/$(basename "$logfile")"249jtreg_args+=("-Djpackage.test.logfile=$(to_native_path "$logfile")")250fi251252if [ -z "$run_all_tests" ]; then253jtreg_args+=(-Djpackage.test.SQETest=yes)254fi255256jtreg_args+=("$test_actions")257258# Drop arguments separator259[ "$1" != "--" ] || shift260261# All remaining command line arguments are tests to run262# that should override the defaults and explicit jtreg arguments263[ $# -eq 0 ] || tests=($@)264265266installJtreg ()267{268# Install jtreg if missing269if [ -z "$JT_HOME" ]; then270if [ ! -f "$jtreg_jar" ]; then271exec_command mkdir -p "$workdir"272if [[ ${jtreg_bundle: -7} == ".tar.gz" ]]; then273exec_command "(" cd "$workdir" "&&" wget --no-check-certificate "$jtreg_bundle" "&&" tar -xzf "$(basename $jtreg_bundle)" ";" rm -f "$(basename $jtreg_bundle)" ")"274else275if [[ ${jtreg_bundle: -4} == ".zip" ]]; then276exec_command "(" cd "$workdir" "&&" wget --no-check-certificate "$jtreg_bundle" "&&" unzip "$(basename $jtreg_bundle)" ";" rm -f "$(basename $jtreg_bundle)" ")"277else278fatal 'Unsupported extension of JREG bundle ['$JT_BUNDLE_URL']. Only *.zip or *.tar.gz is supported.'279fi280fi281fi282else283# use jtreg provided via JT_HOME284jtreg_jar=$JT_HOME/lib/jtreg.jar285fi286287echo 'jtreg jar file: '$jtreg_jar288}289290291preRun ()292{293if [ ! -d "$output_dir" ]; then294exec_command mkdir -p "$output_dir"295fi296[ ! -d "$output_dir" ] || output_dir=$(cd "$output_dir" && pwd)297298# Clean output directory299if [ "$mode" == "create" ]; then300for f in $(find $output_dir -maxdepth 1 -type f -name '*.exe' -or -name '*.msi' -or -name '*.rpm' -or -name '*.deb'); do301echo rm "$f"302[ -n "$dry_run" ] || rm "$f"303done304fi305}306307308run ()309{310local jtreg_cmdline=(\311$JAVA_HOME/bin/java -jar $(to_native_path "$jtreg_jar") \312"-Djpackage.test.output=$(to_native_path "$output_dir")" \313"${jtreg_args[@]}" \314-nr \315"$jtreg_verbose" \316-retain:all \317-automatic \318-ignore:run \319-testjdk:"$(to_native_path $test_jdk)" \320-dir:"$(to_native_path $open_jdk_with_jpackage_jtreg_tests)" \321-reportDir:"$(to_native_path $workdir/run/results)" \322-workDir:"$(to_native_path $workdir/run/support)" \323"${tests[@]}" \324)325326# Clear previous results327[ -n "$keep_jtreg_cache" ] || exec_command rm -rf "$workdir"/run328329# Run jpackage jtreg tests to create artifacts for testing330exec_command ${jtreg_cmdline[@]}331}332333334installJtreg335preRun336run337338339