1 #!/bin/env/bash
2
3 # Copyright (c) 2025, 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. Oracle designates this
9 # particular file as subject to the "Classpath" exception as provided
10 # by Oracle in the LICENSE file that accompanied this code.
11 #
12 # This code is distributed in the hope that it will be useful, but WITHOUT
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 # version 2 for more details (a copy is included in the LICENSE file that
16 # accompanied this code).
17 #
18 # You should have received a copy of the GNU General Public License version
19 # 2 along with this work; if not, write to the Free Software Foundation,
20 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 #
22 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23 # or visit www.oracle.com if you need additional information or have any
24 # questions.
25
26 ##############################################
27 # How to use it?
28 # 1. Run this script with --generate-config-file
29 # 2. Fill the template file: remoteTesting.conf
30 # 3. Run again this script without any parameters
31 # ############################################
32
33 display_help() {
34 echo "Usage: $(basename "$0") [options]"
35 echo
36 echo "When running without any options, it reads the \"remoteTesting.conf\" and runs the testing framework on the remote machines."
37 echo
38 echo "Options:"
39 echo " --help Display this help message and exit."
40 echo " --generate-config-file Generate a default configuration file and exit."
41 echo " --build-babylon Build Babylon and HAT for all remote servers"
42 echo
43 echo "How to use it?"
44 echo " 1. Run this script with --generate-config-file "
45 echo " 2. Fill the template file: remoteTesting.conf"
46 echo " 3. Run again this script without any parameters "
47 exit 0
48 }
49
50 GREEN="\033[0;32m"
51 NC="\033[0m" # No Color (reset)
52
53 generate_config_file() {
54 cat << EOF > remoteTesting.conf
55 # HAT Remote Testing Settings
56 SERVERS=server1 server2 ...
57 REMOTE_USERS=user1 user2 ...
58
59 ## List of Backends to test
60 # To test one backend
61 #BACKENDS=ffi-opencl
62 # We can also test multiple backends
63 BACKENDS=ffi-cuda ffi-opencl
64 # Specify the Babylon fork to test
65 FORK=https://github.com/openjdk/babylon
66
67 ## Remote path. It assumes all servers use the same path
68 REMOTE_PATH=repos/babylon/hat
69 ## Branch to test
70 BRANCH=code-reflection
71 EOF
72 echo "✅ Default configuration file 'remoteTesting.conf' has been generated."
73 exit 0
74 }
75
76 read_config_file() {
77 CONFIG_FILE="remoteTesting.conf"
78
79 # Check if the config file exists
80 if [ ! -f "$CONFIG_FILE" ]; then
81 echo "Error: $CONFIG_FILE not found."
82 echo "Run this script with --generate-config-file to generate a template."
83 exit 1
84 fi
85
86 ## Process the config file
87 while IFS='=' read -r key value
88 do
89 if [[ -z "$key" || "$key" =~ ^# ]]; then
90 continue
91 fi
92
93 case "$key" in
94 "SERVERS") SERVERS="$value" ;;
95 "REMOTE_USERS") REMOTE_USERS="$value" ;;
96 "BACKENDS") BACKENDS=($value) ;;
97 "REMOTE_PATH") REMOTE_PATH="$value" ;;
98 "BRANCH") BRANCH="$value" ;;
99 "FORK") FORK="$value" ;;
100 esac
101 done < "$CONFIG_FILE"
102
103 isSet=1
104 if [[ -z $SERVERS ]]; then
105 echo "❌ SERVERS is not set."
106 isSet=0
107 fi
108 if [[ -z $REMOTE_USERS ]]; then
109 echo "❌ REMOTE_USERS is not set."
110 isSet=0
111 fi
112 if [[ -z $BACKENDS ]]; then
113 echo "❌ BACKENDS is not set."
114 isSet=0
115 fi
116 if [[ -z $REMOTE_PATH ]]; then
117 echo "❌ REMOTE_PATH is not set."
118 isSet=0
119 fi
120 if [[ -z $BRANCH ]]; then
121 echo "❌ BRANCH is not set."
122 isSet=0
123 fi
124 if [[ -z $FORK ]]; then
125 echo "❌ FORK is not set."
126 isSet=0
127 fi
128
129 if [[ "$isSet" -eq 0 ]]; then
130 exit
131 fi
132
133 echo
134 echo "Servers : $SERVERS"
135 echo "Users : $REMOTE_USERS"
136 echo "Backends : ${BACKENDS[@]}"
137 echo "Remote Path: $REMOTE_PATH"
138 echo "Fork : $FORK"
139 echo "Branch : $BRANCH"
140 echo
141
142 read -ra listOfServers <<< $SERVERS
143 read -ra listOfUsers <<< $REMOTE_USERS
144 }
145
146 build_babylon() {
147
148 echo "Build Babylon and HAT"
149
150 read_config_file
151
152 for index in "${!listOfServers[@]}"
153 do
154 server=${listOfServers[$index]}
155 user=${listOfUsers[$index]}
156
157 echo -e "${GREEN}[info] ssh $user@$server${NC}"
158 ssh -T $user@$server << EOF
159 if [ ! -d $REMOTE_PATH ];
160 then
161 mkdir -p \$(dirname $REMOTE_PATH)
162 cd \$(dirname $REMOTE_PATH)
163 git clone $FORK \$(basename $REMOTE_PATH)
164 fi
165
166 #Assuming the remote path ends with babylon
167 cd $REMOTE_PATH
168 git fetch --all
169 git checkout $BRANCH
170 git pull
171
172 echo "bash configure --with-boot-jdk=\$HOME/.sdkman/candidates/java/current"
173 bash configure --with-boot-jdk="\$HOME/.sdkman/candidates/java/current" > jvmconfig.log
174 make clean
175 make images > jvmbuild.log
176
177 ## Build HAT
178 cd hat
179 if [ ! -d jextract-22 ];
180 then
181 echo "ARCHITECTIRE \$(uname -m)"
182 if [[ "\$(uname -m)" == "x86_64" ]]; then
183 wget https://download.java.net/java/early_access/jextract/22/6/openjdk-22-jextract+6-47_linux-x64_bin.tar.gz
184 tar xvzf openjdk-22-jextract+6-47_linux-x64_bin.tar.gz > /dev/null
185 elif [[ "\$(uname -m)" == "arm64" ]]; then
186 wget https://download.java.net/java/early_access/jextract/22/6/openjdk-22-jextract+6-47_macos-aarch64_bin.tar.gz
187 tar xvzf openjdk-22-jextract+6-47_macos-aarch64_bin.tar.gz > /dev/null
188 fi
189 echo "export PATH=\$(pwd)/jextract-22/bin:\$PATH" >> setup.sh
190 echo "source env.bash" >> setup.sh
191 fi
192
193 source setup.sh > /dev/null 2> /dev/null
194 java @hat/clean > hatCompilation.log 2> hatCompilationErrors.log
195 java @hat/bld >> hatCompilation.log 2>> hatCompilationErrors.log
196 EOF
197 done
198
199 }
200
201 run_tests_hat() {
202
203 read_config_file
204
205 for index in "${!listOfServers[@]}"
206 do
207
208 server=${listOfServers[$index]}
209 user=${listOfUsers[$index]}
210
211 echo -e "\n${GREEN}[info] ssh $user@$server${NC}"
212 backend_definition=$(typeset -p BACKENDS)
213 ssh $user@$server bash << EOF
214 $backend_definition
215 cd "$REMOTE_PATH"
216 cd hat/
217 git fetch --all
218 git checkout $BRANCH
219 git pull
220
221 # compile
222 source setup.sh > /dev/null 2> /dev/null
223 java @hat/clean > hatCompilation.log 2> hatCompilationErrors.log
224 java @hat/bld >> hatCompilation.log 2>> hatCompilationErrors.log
225
226 # run the test suite per backend
227 for backend in "\${BACKENDS[@]}"
228 do
229 echo -e "${GREEN}[running] java -cp hat/job.jar hat.java test "\$backend" ${NC}"
230 java -cp hat/job.jar hat.java test-suite "\$backend" > "\$backend".txt 2> "\$backend"Errors.txt
231 done
232
233 # Print logs
234 for backend in "\${BACKENDS[@]}"
235 do
236 cat "\$backend".txt
237 done
238
239 ## Run violajones
240 for backend in "\${BACKENDS[@]}"
241 do
242 echo -e "${GREEN}[running] java -cp hat/job.jar hat.java run "\$backend" -Dheadless=true violajones${NC}"
243 java -cp hat/job.jar hat.java run "\$backend" -Dheadless=true violajones > "\$backend"Violajones.log
244 done
245
246 for backend in "\${BACKENDS[@]}"
247 do
248 cat "\$backend"Violajones.log | grep "336faces found"
249 done
250 EOF
251 done
252 }
253
254 while [[ $# -gt 0 ]]; do
255 key="$1"
256 case $key in
257 --help)
258 display_help
259 exit
260 ;;
261 --generate-config-file)
262 generate_config_file
263 exit
264 ;;
265 --build-babylon)
266 build_babylon
267 exit 0
268 ;;
269 *)
270 # Unknown option
271 echo "Error: Unknown option '$key'"
272 echo "Use --help for a list of available options."
273 exit 1
274 ;;
275 esac
276 done
277
278 run_tests_hat
279