Path: blob/master/test/jdk/tools/jpackage/run_tests.sh
41144 views
#!/bin/bash12# Copyright (c) 2020, 2021, 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."81echo ' Should be one of `create`, `update` or `print-default-tests`.'82echo ' Optional, default mode is `update`.'83echo ' - `create`'84echo ' Remove all package bundles from the output directory before running jtreg tests.'85echo ' - `update`'86echo ' Run jtreg tests and overrite existing package bundles in the output directory.'87echo ' - `print-default-tests`'88echo ' Print default list of packaging tests and exit.'89}9091error ()92{93echo "$@" > /dev/stderr94}9596fatal ()97{98error "$@"99exit 1100}101102fatal_with_help_usage ()103{104error "$@"105help_usage106exit 1107}108109if command -v cygpath &> /dev/null; then110to_native_path ()111{112cygpath -m "$@"113}114else115to_native_path ()116{117echo "$@"118}119fi120121exec_command ()122{123if [ -n "$dry_run" ]; then124echo "$@"125else126eval "$@"127fi128}129130131# Path to JDK to be tested.132test_jdk=133134# Path to local copy of open jdk repo with jpackage jtreg tests135# hg clone http://hg.openjdk.java.net/jdk/sandbox136# cd sandbox; hg update -r JDK-8200758-branch137open_jdk_with_jpackage_jtreg_tests=$(dirname $0)/../../../../138139# Directory where to save artifacts for testing.140output_dir=$PWD141142# Script and jtreg debug.143verbose=144jtreg_verbose="-verbose:fail,error,summary"145146keep_jtreg_cache=147148# Mode in which to run jtreg tests149mode=update150151# jtreg extra arguments152declare -a jtreg_args153154# Create packages only155jtreg_args+=("-Djpackage.test.action=create")156157# run all tests158run_all_tests=159160mapfile -t tests < <(find_all_packaging_tests)161162while getopts "vahdct:j:o:r:m:l:" argname; do163case "$argname" in164v) verbose=yes;;165a) run_all_tests=yes;;166d) dry_run=yes;;167c) keep_jtreg_cache=yes;;168t) test_jdk="$OPTARG";;169j) open_jdk_with_jpackage_jtreg_tests="$OPTARG";;170o) output_dir="$OPTARG";;171r) runtime_dir="$OPTARG";;172l) logfile="$OPTARG";;173m) mode="$OPTARG";;174h) help_usage; exit 0;;175?) help_usage; exit 1;;176esac177done178shift $(( OPTIND - 1 ))179180[ -z "$verbose" ] || { set -x; jtreg_verbose=-va; }181182if [ -z "$open_jdk_with_jpackage_jtreg_tests" ]; then183fatal_with_help_usage "Path to openjdk repo with jpackage jtreg tests not specified"184fi185186if [ "$mode" = "print-default-tests" ]; then187exec_command for t in ${tests[@]}";" do echo '$t;' done188exit189fi190191if [ -z "$test_jdk" ]; then192fatal_with_help_usage Path to test JDK not specified193fi194195if [ -z "$JAVA_HOME" ]; then196echo JAVA_HOME environment variable not set, will use java from test JDK [$test_jdk] to run jtreg197JAVA_HOME="$test_jdk"198fi199if [ ! -e "$JAVA_HOME/bin/java" ]; then200fatal JAVA_HOME variable is set to [$JAVA_HOME] value, but $JAVA_HOME/bin/java not found.201fi202203if [ -z "$JT_HOME" ]; then204if [ -z "$JT_BUNDLE_URL" ]; then205fatal 'JT_HOME or JT_BUNDLE_URL environment variable is not set. Link to JTREG bundle can be found at https://openjdk.java.net/jtreg/'.206fi207fi208209if [ -n "$runtime_dir" ]; then210if [ ! -d "$runtime_dir" ]; then211fatal 'Value of `-r` option is set to non-existing directory'.212fi213jtreg_args+=("-Djpackage.test.runtime-image=$(to_native_path "$(cd "$runtime_dir" && pwd)")")214fi215216if [ -n "$logfile" ]; then217if [ ! -d "$(dirname "$logfile")" ]; then218fatal 'Value of `-l` option specified a file in non-existing directory'.219fi220logfile="$(cd "$(dirname "$logfile")" && pwd)/$(basename "$logfile")"221jtreg_args+=("-Djpackage.test.logfile=$(to_native_path "$logfile")")222fi223224if [ "$mode" = create ]; then225true226elif [ "$mode" = update ]; then227true228else229fatal_with_help_usage 'Invalid value of -m option:' [$mode]230fi231232if [ -z "$run_all_tests" ]; then233jtreg_args+=(-Djpackage.test.SQETest=yes)234fi235236# Drop arguments separator237[ "$1" != "--" ] || shift238239# All remaining command line arguments are tests to run240# that should override the defaults and explicit jtreg arguments241[ $# -eq 0 ] || tests=($@)242243244installJtreg ()245{246# Install jtreg if missing247if [ -z "$JT_HOME" ]; then248if [ ! -f "$jtreg_jar" ]; then249exec_command mkdir -p "$workdir"250if [[ ${jtreg_bundle: -7} == ".tar.gz" ]]; then251exec_command "(" cd "$workdir" "&&" wget "$jtreg_bundle" "&&" tar -xzf "$(basename $jtreg_bundle)" ";" rm -f "$(basename $jtreg_bundle)" ")"252else253if [[ ${jtreg_bundle: -4} == ".zip" ]]; then254exec_command "(" cd "$workdir" "&&" wget "$jtreg_bundle" "&&" unzip "$(basename $jtreg_bundle)" ";" rm -f "$(basename $jtreg_bundle)" ")"255else256fatal 'Unsupported extension of JREG bundle ['$JT_BUNDLE_URL']. Only *.zip or *.tar.gz is supported.'257fi258fi259fi260else261# use jtreg provided via JT_HOME262jtreg_jar=$JT_HOME/lib/jtreg.jar263fi264265echo 'jtreg jar file: '$jtreg_jar266}267268269preRun ()270{271if [ ! -d "$output_dir" ]; then272exec_command mkdir -p "$output_dir"273fi274[ ! -d "$output_dir" ] || output_dir=$(cd "$output_dir" && pwd)275276# Clean output directory277if [ "$mode" == "create" ]; then278for f in $(find $output_dir -maxdepth 1 -type f -name '*.exe' -or -name '*.msi' -or -name '*.rpm' -or -name '*.deb'); do279echo rm "$f"280[ -n "$dry_run" ] || rm "$f"281done282fi283}284285286run ()287{288local jtreg_cmdline=(\289$JAVA_HOME/bin/java -jar $(to_native_path "$jtreg_jar") \290"-Djpackage.test.output=$(to_native_path "$output_dir")" \291"${jtreg_args[@]}" \292-nr \293"$jtreg_verbose" \294-retain:all \295-automatic \296-ignore:run \297-testjdk:"$(to_native_path $test_jdk)" \298-dir:"$(to_native_path $open_jdk_with_jpackage_jtreg_tests)" \299-reportDir:"$(to_native_path $workdir/run/results)" \300-workDir:"$(to_native_path $workdir/run/support)" \301"${tests[@]}" \302)303304# Clear previous results305[ -n "$keep_jtreg_cache" ] || exec_command rm -rf "$workdir"/run306307# Run jpackage jtreg tests to create artifacts for testing308exec_command ${jtreg_cmdline[@]}309}310311312installJtreg313preRun314run315316317