test/jdk/tools/jpackage/run_tests.sh
branchJDK-8200758-branch
changeset 58301 e0efb29609bd
child 58761 88e2753a2334
equal deleted inserted replaced
58172:bf06a1d3aef6 58301:e0efb29609bd
       
     1 #!/bin/bash
       
     2 
       
     3 #
       
     4 # Script to run jpackage tests.
       
     5 #
       
     6 
       
     7 
       
     8 # Fail fast
       
     9 set -e; set -o pipefail;
       
    10 
       
    11 
       
    12 # Link obtained from https://openjdk.java.net/jtreg/ page
       
    13 jtreg_bundle=https://ci.adoptopenjdk.net/view/Dependencies/job/jtreg/lastSuccessfulBuild/artifact/jtreg-4.2.0-tip.tar.gz
       
    14 workdir=/tmp/jpackage_jtreg_testing
       
    15 jtreg_jar=$workdir/jtreg/lib/jtreg.jar
       
    16 
       
    17 # Names of shared packaging tests to run
       
    18 share_package_test_names="
       
    19   FileAssociationsTest
       
    20   InstallDirTest
       
    21   LicenseTest
       
    22   SimplePackageTest
       
    23   RuntimePackageTest
       
    24   AdditionalLaunchersTest
       
    25   AppImagePackageTest
       
    26 "
       
    27 mapfile -t packaging_tests_share < <(for t in $share_package_test_names; do echo test/jdk/tools/jpackage/share/$t.java; done)
       
    28 packaging_tests_windows=test/jdk/tools/jpackage/windows
       
    29 packaging_tests_linux=test/jdk/tools/jpackage/linux
       
    30 packaging_tests_mac=test/jdk/tools/jpackage/macosx
       
    31 
       
    32 case "$(uname -s)" in
       
    33   Darwin)
       
    34     tests=( "$packaging_tests_mac" );;
       
    35   Linux)
       
    36     tests=( "$packaging_tests_linux" );;
       
    37   CYGWIN*|MINGW32*|MSYS*)
       
    38     tests=( "$packaging_tests_windows" );;
       
    39   *)
       
    40     fatal Failed to detect OS type;;
       
    41 esac
       
    42 tests+=(${packaging_tests_share[@]})
       
    43 
       
    44 
       
    45 help_usage ()
       
    46 {
       
    47   echo "Usage: `basename $0` [options] [test_names]"
       
    48   echo "Options:"
       
    49   echo "  -h              - print this message"
       
    50   echo "  -v              - verbose output"
       
    51   echo "  -c              - keep jtreg cache"
       
    52   echo "  -d              - dry run. Print jtreg command line, but don't execute it"
       
    53   echo "  -t <jdk>        - path to JDK to be tested [ mandatory ]"
       
    54   echo "  -j <openjdk>    - path to local copy of openjdk repo with jpackage jtreg tests"
       
    55   echo "                    Optional, default is openjdk repo where this script resides"
       
    56   echo "  -o <outputdir>  - path to folder where to copy artifacts for testing."
       
    57   echo "                    Optional, default is the current directory."
       
    58   echo '  -r <runtimedir> - value for `jpackage.test.runtime-image` property.'
       
    59   echo "                    Optional, for jtreg tests debug purposes only."
       
    60   echo '  -l <logfile>    - value for `jpackage.test.logfile` property.'
       
    61   echo "                    Optional, for jtreg tests debug purposes only."
       
    62   echo "  -m <mode>       - mode to run jtreg tests."
       
    63   echo '                    Should be one of `create`, `update`, `verify-install` or `verify-uninstall`.'
       
    64   echo '                    Optional, default mode is `update`.'
       
    65   echo '                    - `create`'
       
    66   echo '                      Remove all package bundles from the output directory before running jtreg tests.'
       
    67   echo '                    - `update`'
       
    68   echo '                      Run jtreg tests and overrite existing package bundles in the output directory.'
       
    69   echo '                    - `verify-install`'
       
    70   echo '                      Verify installed packages created with the previous run of the script.'
       
    71   echo '                    - `verify-uninstall`'
       
    72   echo '                      Verify packages created with the previous run of the script were uninstalled cleanly.'
       
    73   echo '                    - `print-default-tests`'
       
    74   echo '                      Print default tests list and exit.'
       
    75 }
       
    76 
       
    77 error ()
       
    78 {
       
    79   echo "$@" > /dev/stderr
       
    80 }
       
    81 
       
    82 fatal ()
       
    83 {
       
    84   error "$@"
       
    85   exit 1
       
    86 }
       
    87 
       
    88 fatal_with_help_usage ()
       
    89 {
       
    90   error "$@"
       
    91   help_usage
       
    92   exit 1
       
    93 }
       
    94 
       
    95 if command -v cygpath &> /dev/null; then
       
    96 to_native_path ()
       
    97 {
       
    98   cygpath -m "$@"
       
    99 }
       
   100 else
       
   101 to_native_path ()
       
   102 {
       
   103   echo "$@"
       
   104 }
       
   105 fi
       
   106 
       
   107 exec_command ()
       
   108 {
       
   109   if [ -n "$dry_run" ]; then
       
   110     echo "$@"
       
   111   else
       
   112     eval "$@"
       
   113   fi
       
   114 }
       
   115 
       
   116 expand_test_selector ()
       
   117 {
       
   118   if [ -d "$open_jdk_with_jpackage_jtreg_tests/$1" ]; then
       
   119     for java in $(find "$open_jdk_with_jpackage_jtreg_tests/$1" -maxdepth 1 -name '*.java'); do
       
   120       ! grep -q '@test' "$java" || echo "$1/$(basename "$java")"
       
   121     done
       
   122   else
       
   123     echo "$1"
       
   124   fi
       
   125 }
       
   126 
       
   127 
       
   128 # Path to JDK to be tested.
       
   129 test_jdk=
       
   130 
       
   131 # Path to local copy of open jdk repo with jpackage jtreg tests
       
   132 # hg clone http://hg.openjdk.java.net/jdk/sandbox
       
   133 # cd sandbox; hg update -r JDK-8200758-branch
       
   134 open_jdk_with_jpackage_jtreg_tests=$(dirname $0)/../../../../
       
   135 
       
   136 # Directory where to save artifacts for testing.
       
   137 output_dir=$PWD
       
   138 
       
   139 # Script and jtreg debug.
       
   140 verbose=
       
   141 jtreg_verbose="-verbose:fail,error,summary"
       
   142 
       
   143 keep_jtreg_cache=
       
   144 
       
   145 # Mode in which to run jtreg tests
       
   146 mode=update
       
   147 
       
   148 # JVM extra arguments
       
   149 declare -a vm_args
       
   150 
       
   151 while getopts "vhdct:j:o:r:m:l:" argname; do
       
   152   case "$argname" in
       
   153     v) verbose=yes;;
       
   154     d) dry_run=yes;;
       
   155     c) keep_jtreg_cache=yes;;
       
   156     t) test_jdk="$OPTARG";;
       
   157     j) open_jdk_with_jpackage_jtreg_tests="$OPTARG";;
       
   158     o) output_dir="$OPTARG";;
       
   159     r) runtime_dir="$OPTARG";;
       
   160     l) logfile="$OPTARG";;
       
   161     m) mode="$OPTARG";;
       
   162     h) help_usage; exit 0;;
       
   163     ?) help_usage; exit 1;;
       
   164   esac
       
   165 done
       
   166 shift $(( OPTIND - 1 ))
       
   167 
       
   168 [ -z "$verbose" ] || { set -x; jtreg_verbose=-va; }
       
   169 
       
   170 if [ -z "$open_jdk_with_jpackage_jtreg_tests" ]; then
       
   171   fatal_with_help_usage "Path to openjdk repo with jpackage jtreg tests not specified"
       
   172 fi
       
   173 
       
   174 if [ "$mode" = "print-default-tests" ]; then
       
   175   exec_command for t in ${tests[@]}";" do expand_test_selector '$t;' done
       
   176   exit
       
   177 fi
       
   178 
       
   179 if [ -z "$test_jdk" ]; then
       
   180   fatal_with_help_usage Path to test JDK not specified
       
   181 fi
       
   182 
       
   183 if [ -z "$JAVA_HOME" ]; then
       
   184   echo JAVA_HOME environment variable not set, will use java from test JDK [$test_jdk] to run jtreg
       
   185   JAVA_HOME="$test_jdk"
       
   186 fi
       
   187 if [ ! -e "$JAVA_HOME/bin/java" ]; then
       
   188   fatal JAVA_HOME variable is set to [$JAVA_HOME] value, but $JAVA_HOME/bin/java not found.
       
   189 fi
       
   190 
       
   191 if [ -n "$runtime_dir" ]; then
       
   192   if [ ! -d "$runtime_dir" ]; then
       
   193     fatal 'Value of `-r` option is set to non-existing directory'.
       
   194   fi
       
   195   vm_args+=("-Djpackage.test.runtime-image=$(to_native_path "$(cd "$runtime_dir" && pwd)")")
       
   196 fi
       
   197 
       
   198 if [ -n "$logfile" ]; then
       
   199   if [ ! -d "$(dirname "$logfile")" ]; then
       
   200     fatal 'Value of `-l` option specified a file in non-existing directory'.
       
   201   fi
       
   202   logfile="$(cd "$(dirname "$logfile")" && pwd)/$(basename "$logfile")"
       
   203   vm_args+=("-Djpackage.test.logfile=$(to_native_path "$logfile")")
       
   204 fi
       
   205 
       
   206 if [ "$mode" = create ]; then
       
   207   true
       
   208 elif [ "$mode" = update ]; then
       
   209   true
       
   210 elif [ "$mode" = verify-install ]; then
       
   211   vm_args+=("-Djpackage.test.action=$mode")
       
   212 elif [ "$mode" = verify-uninstall ]; then
       
   213   vm_args+=("-Djpackage.test.action=$mode")
       
   214 else
       
   215   fatal_with_help_usage 'Invalid value of -m option:' [$mode]
       
   216 fi
       
   217 
       
   218 
       
   219 # All remaining command line arguments are tests to run that should override the defaults
       
   220 [ $# -eq 0 ] || tests=($@)
       
   221 
       
   222 
       
   223 installJtreg ()
       
   224 {
       
   225   # Install jtreg if missing
       
   226   if [ ! -f "$jtreg_jar" ]; then
       
   227     exec_command mkdir -p "$workdir"
       
   228     exec_command "(" cd "$workdir" "&&" wget "$jtreg_bundle" "&&" tar -xzf "$(basename $jtreg_bundle)" ";" rm -f "$(basename $jtreg_bundle)" ")"
       
   229   fi
       
   230 }
       
   231 
       
   232 
       
   233 preRun ()
       
   234 {
       
   235   local xargs_args=(-t --no-run-if-empty rm)
       
   236   if [ -n "$dry_run" ]; then
       
   237     xargs_args=(--no-run-if-empty echo rm)
       
   238   fi
       
   239 
       
   240   if [ ! -d "$output_dir" ]; then
       
   241     exec_command mkdir -p "$output_dir"
       
   242   fi
       
   243   [ ! -d "$output_dir" ] || output_dir=$(cd "$output_dir" && pwd)
       
   244 
       
   245   # Clean output directory
       
   246   [ "$mode" != "create" ] || find $output_dir -maxdepth 1 -type f -name '*.exe' -or -name '*.msi' -or -name '*.rpm' -or -name '*.deb' | xargs "${xargs_args[@]}"
       
   247 }
       
   248 
       
   249 
       
   250 run ()
       
   251 {
       
   252   local jtreg_cmdline=(\
       
   253     $JAVA_HOME/bin/java -jar $(to_native_path "$jtreg_jar") \
       
   254     "-Djpackage.test.output=$(to_native_path "$output_dir")" \
       
   255     "${vm_args[@]}" \
       
   256     -nr \
       
   257     "$jtreg_verbose" \
       
   258     -retain:all \
       
   259     -automatic \
       
   260     -ignore:run \
       
   261     -testjdk:"$(to_native_path $test_jdk)" \
       
   262     -dir:"$(to_native_path $open_jdk_with_jpackage_jtreg_tests)" \
       
   263     -reportDir:"$(to_native_path $workdir/run/results)" \
       
   264     -workDir:"$(to_native_path $workdir/run/support)" \
       
   265     "${tests[@]}" \
       
   266   )
       
   267 
       
   268   # Clear previous results
       
   269   [ -n "$keep_jtreg_cache" ] || exec_command rm -rf "$workdir"/run
       
   270 
       
   271   # Run jpackage jtreg tests to create artifacts for testing
       
   272   exec_command ${jtreg_cmdline[@]}
       
   273 }
       
   274 
       
   275 
       
   276 installJtreg
       
   277 preRun
       
   278 run