Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/tools/jpackage/run_tests.sh
66643 views
1
#!/bin/bash
2
3
# Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
4
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
#
6
# This code is free software; you can redistribute it and/or modify it
7
# under the terms of the GNU General Public License version 2 only, as
8
# published by the Free Software Foundation.
9
#
10
# This code is distributed in the hope that it will be useful, but WITHOUT
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
# version 2 for more details (a copy is included in the LICENSE file that
14
# accompanied this code).
15
#
16
# You should have received a copy of the GNU General Public License version
17
# 2 along with this work; if not, write to the Free Software Foundation,
18
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
#
20
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
# or visit www.oracle.com if you need additional information or have any
22
# questions.
23
24
#
25
# Script to run jpackage tests.
26
#
27
28
29
# Fail fast
30
set -e; set -o pipefail;
31
32
# $JT_BUNDLE_URL (Link can be obtained from https://openjdk.java.net/jtreg/ page)
33
jtreg_bundle=$JT_BUNDLE_URL
34
workdir=/tmp/jpackage_jtreg_testing
35
jtreg_jar=$workdir/jtreg/lib/jtreg.jar
36
jpackage_test_selector=test/jdk/tools/jpackage
37
38
39
find_packaging_tests ()
40
{
41
(cd "$open_jdk_with_jpackage_jtreg_tests" && \
42
find "$jpackage_test_selector/$1" -type f -name '*.java' \
43
| xargs grep -E -l '@key[[:space:]]+jpackagePlatformPackage')
44
}
45
46
47
find_all_packaging_tests ()
48
{
49
find_packaging_tests share
50
case "$(uname -s)" in
51
Darwin)
52
find_packaging_tests macosx;;
53
Linux)
54
find_packaging_tests linux;;
55
CYGWIN*|MINGW32*|MSYS*)
56
find_packaging_tests windows;;
57
*)
58
fatal Failed to detect OS type;;
59
esac
60
}
61
62
63
help_usage ()
64
{
65
echo "Usage: `basename $0` [options] [--] [jtreg_options|test_names]"
66
echo "Options:"
67
echo " -h - print this message"
68
echo " -v - verbose output"
69
echo " -c - keep jtreg cache"
70
echo " -a - run all, not only SQE tests"
71
echo " -d - dry run. Print jtreg command line, but don't execute it"
72
echo " -t <jdk> - path to JDK to be tested [ mandatory ]"
73
echo " -j <openjdk> - path to local copy of openjdk repo with jpackage jtreg tests"
74
echo " Optional, default is openjdk repo where this script resides"
75
echo " -o <outputdir> - path to folder where to copy artifacts for testing."
76
echo " Optional, default is the current directory."
77
echo ' -r <runtimedir> - value for `jpackage.test.runtime-image` property.'
78
echo " Optional, for jtreg tests debug purposes only."
79
echo ' -l <logfile> - value for `jpackage.test.logfile` property.'
80
echo " Optional, for jtreg tests debug purposes only."
81
echo " -m <mode> - mode to run jtreg tests. Supported values:"
82
echo ' - `create`'
83
echo ' Remove all package bundles from the output directory before running jtreg tests.'
84
echo ' - `update`'
85
echo ' Run jtreg tests and overrite existing package bundles in the output directory.'
86
echo ' - `print-default-tests`'
87
echo ' Print default list of packaging tests and exit.'
88
echo ' - `create-small-runtime`'
89
echo ' Create small Java runtime using <jdk>/bin/jlink command in the output directory.'
90
echo ' - `create-packages`'
91
echo ' Create packages.'
92
echo ' The script will set `jpackage.test.action` property.'
93
echo ' - `test-packages`'
94
echo ' Create and fully test packages. Will create, unpack, install, and uninstall packages.'
95
echo ' The script will set `jpackage.test.action` property.'
96
echo ' - `do-packages`'
97
echo " Create, unpack and verify packages."
98
echo ' The script will not set `jpackage.test.action` property.'
99
echo ' Optional, defaults are `update` and `create-packages`.'
100
}
101
102
error ()
103
{
104
echo "$@" > /dev/stderr
105
}
106
107
fatal ()
108
{
109
error "$@"
110
exit 1
111
}
112
113
fatal_with_help_usage ()
114
{
115
error "$@"
116
help_usage
117
exit 1
118
}
119
120
if command -v cygpath &> /dev/null; then
121
to_native_path ()
122
{
123
cygpath -m "$@"
124
}
125
else
126
to_native_path ()
127
{
128
echo "$@"
129
}
130
fi
131
132
exec_command ()
133
{
134
if [ -n "$dry_run" ]; then
135
echo "$@"
136
else
137
eval "$@"
138
fi
139
}
140
141
142
# Path to JDK to be tested.
143
test_jdk=
144
145
# Path to local copy of open jdk repo with jpackage jtreg tests
146
open_jdk_with_jpackage_jtreg_tests=$(dirname $0)/../../../../
147
148
# Directory where to save artifacts for testing.
149
output_dir=$PWD
150
151
# Script and jtreg debug.
152
verbose=
153
jtreg_verbose="-verbose:fail,error,summary"
154
155
keep_jtreg_cache=
156
157
# Mode in which to run jtreg tests
158
mode=update
159
160
# jtreg extra arguments
161
declare -a jtreg_args
162
163
# run all tests
164
run_all_tests=
165
166
test_actions=
167
168
set_mode ()
169
{
170
case "$1" in
171
create-packages) test_actions='-Djpackage.test.action=create';;
172
test-packages) test_actions='-Djpackage.test.action=uninstall,create,unpack,verify-install,install,verify-install,uninstall,verify-uninstall,purge';;
173
do-packages) test_actions=;;
174
create-small-runtime) mode=$1;;
175
print-default-tests) mode=$1;;
176
create) mode=$1;;
177
update) mode=$1;;
178
*) fatal_with_help_usage 'Invalid value of -m option:' [$1];;
179
esac
180
}
181
182
set_mode 'create-packages'
183
184
mapfile -t tests < <(find_all_packaging_tests)
185
186
while getopts "vahdct:j:o:r:m:l:" argname; do
187
case "$argname" in
188
v) verbose=yes;;
189
a) run_all_tests=yes;;
190
d) dry_run=yes;;
191
c) keep_jtreg_cache=yes;;
192
t) test_jdk="$OPTARG";;
193
j) open_jdk_with_jpackage_jtreg_tests="$OPTARG";;
194
o) output_dir="$OPTARG";;
195
r) runtime_dir="$OPTARG";;
196
l) logfile="$OPTARG";;
197
m) set_mode "$OPTARG";;
198
h) help_usage; exit 0;;
199
?) help_usage; exit 1;;
200
esac
201
done
202
shift $(( OPTIND - 1 ))
203
204
[ -z "$verbose" ] || { set -x; jtreg_verbose=-va; }
205
206
if [ -z "$open_jdk_with_jpackage_jtreg_tests" ]; then
207
fatal_with_help_usage "Path to openjdk repo with jpackage jtreg tests not specified"
208
fi
209
210
if [ "$mode" = "print-default-tests" ]; then
211
exec_command for t in ${tests[@]}";" do echo '$t;' done
212
exit
213
fi
214
215
if [ -z "$test_jdk" ]; then
216
fatal_with_help_usage Path to test JDK not specified
217
fi
218
219
if [ -z "$JAVA_HOME" ]; then
220
echo JAVA_HOME environment variable not set, will use java from test JDK [$test_jdk] to run jtreg
221
JAVA_HOME="$test_jdk"
222
fi
223
if [ ! -e "$JAVA_HOME/bin/java" ]; then
224
fatal JAVA_HOME variable is set to [$JAVA_HOME] value, but $JAVA_HOME/bin/java not found.
225
fi
226
227
if [ "$mode" = "create-small-runtime" ]; then
228
exec_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"
229
exit
230
fi
231
232
if [ -z "$JT_HOME" ]; then
233
if [ -z "$JT_BUNDLE_URL" ]; then
234
fatal 'JT_HOME or JT_BUNDLE_URL environment variable is not set. Link to JTREG bundle can be found at https://openjdk.java.net/jtreg/'.
235
fi
236
fi
237
238
if [ -n "$runtime_dir" ]; then
239
if [ ! -d "$runtime_dir" ]; then
240
fatal 'Value of `-r` option is set to non-existing directory'.
241
fi
242
jtreg_args+=("-Djpackage.test.runtime-image=$(to_native_path "$(cd "$runtime_dir" && pwd)")")
243
fi
244
245
if [ -n "$logfile" ]; then
246
if [ ! -d "$(dirname "$logfile")" ]; then
247
fatal 'Value of `-l` option specified a file in non-existing directory'.
248
fi
249
logfile="$(cd "$(dirname "$logfile")" && pwd)/$(basename "$logfile")"
250
jtreg_args+=("-Djpackage.test.logfile=$(to_native_path "$logfile")")
251
fi
252
253
if [ -z "$run_all_tests" ]; then
254
jtreg_args+=(-Djpackage.test.SQETest=yes)
255
fi
256
257
jtreg_args+=("$test_actions")
258
259
# Drop arguments separator
260
[ "$1" != "--" ] || shift
261
262
# All remaining command line arguments are tests to run
263
# that should override the defaults and explicit jtreg arguments
264
[ $# -eq 0 ] || tests=($@)
265
266
267
installJtreg ()
268
{
269
# Install jtreg if missing
270
if [ -z "$JT_HOME" ]; then
271
if [ ! -f "$jtreg_jar" ]; then
272
exec_command mkdir -p "$workdir"
273
if [[ ${jtreg_bundle: -7} == ".tar.gz" ]]; then
274
exec_command "(" cd "$workdir" "&&" wget --no-check-certificate "$jtreg_bundle" "&&" tar -xzf "$(basename $jtreg_bundle)" ";" rm -f "$(basename $jtreg_bundle)" ")"
275
else
276
if [[ ${jtreg_bundle: -4} == ".zip" ]]; then
277
exec_command "(" cd "$workdir" "&&" wget --no-check-certificate "$jtreg_bundle" "&&" unzip "$(basename $jtreg_bundle)" ";" rm -f "$(basename $jtreg_bundle)" ")"
278
else
279
fatal 'Unsupported extension of JREG bundle ['$JT_BUNDLE_URL']. Only *.zip or *.tar.gz is supported.'
280
fi
281
fi
282
fi
283
else
284
# use jtreg provided via JT_HOME
285
jtreg_jar=$JT_HOME/lib/jtreg.jar
286
fi
287
288
echo 'jtreg jar file: '$jtreg_jar
289
}
290
291
292
preRun ()
293
{
294
if [ ! -d "$output_dir" ]; then
295
exec_command mkdir -p "$output_dir"
296
fi
297
[ ! -d "$output_dir" ] || output_dir=$(cd "$output_dir" && pwd)
298
299
# Clean output directory
300
if [ "$mode" == "create" ]; then
301
for f in $(find $output_dir -maxdepth 1 -type f -name '*.exe' -or -name '*.msi' -or -name '*.rpm' -or -name '*.deb'); do
302
echo rm "$f"
303
[ -n "$dry_run" ] || rm "$f"
304
done
305
fi
306
}
307
308
309
run ()
310
{
311
local jtreg_cmdline=(\
312
$JAVA_HOME/bin/java -jar $(to_native_path "$jtreg_jar") \
313
"-Djpackage.test.output=$(to_native_path "$output_dir")" \
314
"${jtreg_args[@]}" \
315
-nr \
316
"$jtreg_verbose" \
317
-retain:all \
318
-automatic \
319
-ignore:run \
320
-testjdk:"$(to_native_path $test_jdk)" \
321
-dir:"$(to_native_path $open_jdk_with_jpackage_jtreg_tests)" \
322
-reportDir:"$(to_native_path $workdir/run/results)" \
323
-workDir:"$(to_native_path $workdir/run/support)" \
324
"${tests[@]}" \
325
)
326
327
# Clear previous results
328
[ -n "$keep_jtreg_cache" ] || exec_command rm -rf "$workdir"/run
329
330
# Run jpackage jtreg tests to create artifacts for testing
331
exec_command ${jtreg_cmdline[@]}
332
}
333
334
335
installJtreg
336
preRun
337
run
338
339