Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/tools/jpackage/run_tests.sh
41144 views
1
#!/bin/bash
2
3
# Copyright (c) 2020, 2021, 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."
82
echo ' Should be one of `create`, `update` or `print-default-tests`.'
83
echo ' Optional, default mode is `update`.'
84
echo ' - `create`'
85
echo ' Remove all package bundles from the output directory before running jtreg tests.'
86
echo ' - `update`'
87
echo ' Run jtreg tests and overrite existing package bundles in the output directory.'
88
echo ' - `print-default-tests`'
89
echo ' Print default list of packaging tests and exit.'
90
}
91
92
error ()
93
{
94
echo "$@" > /dev/stderr
95
}
96
97
fatal ()
98
{
99
error "$@"
100
exit 1
101
}
102
103
fatal_with_help_usage ()
104
{
105
error "$@"
106
help_usage
107
exit 1
108
}
109
110
if command -v cygpath &> /dev/null; then
111
to_native_path ()
112
{
113
cygpath -m "$@"
114
}
115
else
116
to_native_path ()
117
{
118
echo "$@"
119
}
120
fi
121
122
exec_command ()
123
{
124
if [ -n "$dry_run" ]; then
125
echo "$@"
126
else
127
eval "$@"
128
fi
129
}
130
131
132
# Path to JDK to be tested.
133
test_jdk=
134
135
# Path to local copy of open jdk repo with jpackage jtreg tests
136
# hg clone http://hg.openjdk.java.net/jdk/sandbox
137
# cd sandbox; hg update -r JDK-8200758-branch
138
open_jdk_with_jpackage_jtreg_tests=$(dirname $0)/../../../../
139
140
# Directory where to save artifacts for testing.
141
output_dir=$PWD
142
143
# Script and jtreg debug.
144
verbose=
145
jtreg_verbose="-verbose:fail,error,summary"
146
147
keep_jtreg_cache=
148
149
# Mode in which to run jtreg tests
150
mode=update
151
152
# jtreg extra arguments
153
declare -a jtreg_args
154
155
# Create packages only
156
jtreg_args+=("-Djpackage.test.action=create")
157
158
# run all tests
159
run_all_tests=
160
161
mapfile -t tests < <(find_all_packaging_tests)
162
163
while getopts "vahdct:j:o:r:m:l:" argname; do
164
case "$argname" in
165
v) verbose=yes;;
166
a) run_all_tests=yes;;
167
d) dry_run=yes;;
168
c) keep_jtreg_cache=yes;;
169
t) test_jdk="$OPTARG";;
170
j) open_jdk_with_jpackage_jtreg_tests="$OPTARG";;
171
o) output_dir="$OPTARG";;
172
r) runtime_dir="$OPTARG";;
173
l) logfile="$OPTARG";;
174
m) mode="$OPTARG";;
175
h) help_usage; exit 0;;
176
?) help_usage; exit 1;;
177
esac
178
done
179
shift $(( OPTIND - 1 ))
180
181
[ -z "$verbose" ] || { set -x; jtreg_verbose=-va; }
182
183
if [ -z "$open_jdk_with_jpackage_jtreg_tests" ]; then
184
fatal_with_help_usage "Path to openjdk repo with jpackage jtreg tests not specified"
185
fi
186
187
if [ "$mode" = "print-default-tests" ]; then
188
exec_command for t in ${tests[@]}";" do echo '$t;' done
189
exit
190
fi
191
192
if [ -z "$test_jdk" ]; then
193
fatal_with_help_usage Path to test JDK not specified
194
fi
195
196
if [ -z "$JAVA_HOME" ]; then
197
echo JAVA_HOME environment variable not set, will use java from test JDK [$test_jdk] to run jtreg
198
JAVA_HOME="$test_jdk"
199
fi
200
if [ ! -e "$JAVA_HOME/bin/java" ]; then
201
fatal JAVA_HOME variable is set to [$JAVA_HOME] value, but $JAVA_HOME/bin/java not found.
202
fi
203
204
if [ -z "$JT_HOME" ]; then
205
if [ -z "$JT_BUNDLE_URL" ]; then
206
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/'.
207
fi
208
fi
209
210
if [ -n "$runtime_dir" ]; then
211
if [ ! -d "$runtime_dir" ]; then
212
fatal 'Value of `-r` option is set to non-existing directory'.
213
fi
214
jtreg_args+=("-Djpackage.test.runtime-image=$(to_native_path "$(cd "$runtime_dir" && pwd)")")
215
fi
216
217
if [ -n "$logfile" ]; then
218
if [ ! -d "$(dirname "$logfile")" ]; then
219
fatal 'Value of `-l` option specified a file in non-existing directory'.
220
fi
221
logfile="$(cd "$(dirname "$logfile")" && pwd)/$(basename "$logfile")"
222
jtreg_args+=("-Djpackage.test.logfile=$(to_native_path "$logfile")")
223
fi
224
225
if [ "$mode" = create ]; then
226
true
227
elif [ "$mode" = update ]; then
228
true
229
else
230
fatal_with_help_usage 'Invalid value of -m option:' [$mode]
231
fi
232
233
if [ -z "$run_all_tests" ]; then
234
jtreg_args+=(-Djpackage.test.SQETest=yes)
235
fi
236
237
# Drop arguments separator
238
[ "$1" != "--" ] || shift
239
240
# All remaining command line arguments are tests to run
241
# that should override the defaults and explicit jtreg arguments
242
[ $# -eq 0 ] || tests=($@)
243
244
245
installJtreg ()
246
{
247
# Install jtreg if missing
248
if [ -z "$JT_HOME" ]; then
249
if [ ! -f "$jtreg_jar" ]; then
250
exec_command mkdir -p "$workdir"
251
if [[ ${jtreg_bundle: -7} == ".tar.gz" ]]; then
252
exec_command "(" cd "$workdir" "&&" wget "$jtreg_bundle" "&&" tar -xzf "$(basename $jtreg_bundle)" ";" rm -f "$(basename $jtreg_bundle)" ")"
253
else
254
if [[ ${jtreg_bundle: -4} == ".zip" ]]; then
255
exec_command "(" cd "$workdir" "&&" wget "$jtreg_bundle" "&&" unzip "$(basename $jtreg_bundle)" ";" rm -f "$(basename $jtreg_bundle)" ")"
256
else
257
fatal 'Unsupported extension of JREG bundle ['$JT_BUNDLE_URL']. Only *.zip or *.tar.gz is supported.'
258
fi
259
fi
260
fi
261
else
262
# use jtreg provided via JT_HOME
263
jtreg_jar=$JT_HOME/lib/jtreg.jar
264
fi
265
266
echo 'jtreg jar file: '$jtreg_jar
267
}
268
269
270
preRun ()
271
{
272
if [ ! -d "$output_dir" ]; then
273
exec_command mkdir -p "$output_dir"
274
fi
275
[ ! -d "$output_dir" ] || output_dir=$(cd "$output_dir" && pwd)
276
277
# Clean output directory
278
if [ "$mode" == "create" ]; then
279
for f in $(find $output_dir -maxdepth 1 -type f -name '*.exe' -or -name '*.msi' -or -name '*.rpm' -or -name '*.deb'); do
280
echo rm "$f"
281
[ -n "$dry_run" ] || rm "$f"
282
done
283
fi
284
}
285
286
287
run ()
288
{
289
local jtreg_cmdline=(\
290
$JAVA_HOME/bin/java -jar $(to_native_path "$jtreg_jar") \
291
"-Djpackage.test.output=$(to_native_path "$output_dir")" \
292
"${jtreg_args[@]}" \
293
-nr \
294
"$jtreg_verbose" \
295
-retain:all \
296
-automatic \
297
-ignore:run \
298
-testjdk:"$(to_native_path $test_jdk)" \
299
-dir:"$(to_native_path $open_jdk_with_jpackage_jtreg_tests)" \
300
-reportDir:"$(to_native_path $workdir/run/results)" \
301
-workDir:"$(to_native_path $workdir/run/support)" \
302
"${tests[@]}" \
303
)
304
305
# Clear previous results
306
[ -n "$keep_jtreg_cache" ] || exec_command rm -rf "$workdir"/run
307
308
# Run jpackage jtreg tests to create artifacts for testing
309
exec_command ${jtreg_cmdline[@]}
310
}
311
312
313
installJtreg
314
preRun
315
run
316
317