1 #!/bin/bash
2
3 # Copyright (c) 2025-2026, 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 " --build-hat Build HAT for all remote servers and run the tests."
43 echo " --tests Run HAT unittests. It assumes a previous build was performed."
44
45 echo
46 echo "How to use it?"
47 echo " 1. Run this script with --generate-config-file "
48 echo " 2. Fill the template file: remoteTesting.conf"
49 echo " 3. If needed, you can run with --build-babylon to clone babylon and build HAT"
50 echo " 4. (Optional if we run step 3): --build-hat assumes Babylon JDK exists and just checks for latest changes "
51 echo " 5. Run tests: --tests"
52 echo " "
53 echo "Note: if run with no options, it will use --build-hat + --tests"
54 exit 0
55 }
56
57 GREEN="\033[0;32m"
58 NC="\033[0m" # No Color (reset)
59
60 generate_config_file() {
61 cat << EOF > remoteTesting.conf
62 # HAT Remote Testing Settings
63 SERVERS=server1 server2 ...
64 REMOTE_USERS=user1 user2 ...
65
66 ## List of Backends to test
67 # To test one backend
68 #BACKENDS=ffi-opencl
69 # We can also test multiple backends
70 BACKENDS=ffi-cuda ffi-opencl
71 # Specify the Babylon fork to test
72 FORK=https://github.com/openjdk/babylon
73
74 ## Remote path. It assumes all servers use the same path
75 REMOTE_PATH=repos/babylon/hat
76 ## Branch to test
77 BRANCH=code-reflection
78 EOF
79 echo "✅ Default configuration file 'remoteTesting.conf' has been generated."
80 exit 0
81 }
82
83 read_config_file() {
84 CONFIG_FILE="remoteTesting.conf"
85
86 # Check if the config file exists
87 if [ ! -f "$CONFIG_FILE" ]; then
88 echo "Error: $CONFIG_FILE not found."
89 echo "Run this script with --generate-config-file to generate a template."
90 exit 1
91 fi
92
93 ## Process the config file
94 while IFS='=' read -r key value
95 do
96 if [[ -z "$key" || "$key" =~ ^# ]]; then
97 continue
98 fi
99
100 case "$key" in
101 "SERVERS") SERVERS="$value" ;;
102 "REMOTE_USERS") REMOTE_USERS="$value" ;;
103 "BACKENDS") BACKENDS=($value) ;;
104 "REMOTE_PATH") REMOTE_PATH="$value" ;;
105 "BRANCH") BRANCH="$value" ;;
106 "FORK") FORK="$value" ;;
107 esac
108 done < "$CONFIG_FILE"
109
110 isSet=1
111 if [[ -z $SERVERS ]]; then
112 echo "❌ SERVERS is not set."
113 isSet=0
114 fi
115 if [[ -z $REMOTE_USERS ]]; then
116 echo "❌ REMOTE_USERS is not set."
117 isSet=0
118 fi
119 if [[ -z $BACKENDS ]]; then
120 echo "❌ BACKENDS is not set."
121 isSet=0
122 fi
123 if [[ -z $REMOTE_PATH ]]; then
124 echo "❌ REMOTE_PATH is not set."
125 isSet=0
126 fi
127 if [[ -z $BRANCH ]]; then
128 echo "❌ BRANCH is not set."
129 isSet=0
130 fi
131 if [[ -z $FORK ]]; then
132 echo "❌ FORK is not set."
133 isSet=0
134 fi
135
136 if [[ "$isSet" -eq 0 ]]; then
137 exit
138 fi
139
140 echo
141 echo "Servers : $SERVERS"
142 echo "Users : $REMOTE_USERS"
143 echo "Backends : ${BACKENDS[@]}"
144 echo "Remote Path: $REMOTE_PATH"
145 echo "Fork : $FORK"
146 echo "Branch : $BRANCH"
147 echo
148
149 read -ra listOfServers <<< $SERVERS
150 read -ra listOfUsers <<< $REMOTE_USERS
151 }
152
153 build_babylon() {
154 echo "Build Babylon and HAT"
155 read_config_file
156 for index in "${!listOfServers[@]}"
157 do
158 server=${listOfServers[$index]}
159 user=${listOfUsers[$index]}
160 echo -e "\n${GREEN}[info] ssh -t $user@$server 'bash -s -- $FORK $BRANCH $REMOTE_PATH' < scripts/build_babylon.sh ${NC}"
161 ssh -t $user@$server "bash -s -- ${FORK} ${BRANCH} ${REMOTE_PATH}" < scripts/build_babylon.sh
162 done
163 }
164
165 build_hat() {
166 read_config_file
167 for index in "${!listOfServers[@]}"
168 do
169 server=${listOfServers[$index]}
170 user=${listOfUsers[$index]}
171 list_backends=${BACKENDS[@]}
172 echo -e "\n${GREEN}[info] ssh -t $user@$server 'bash -s -- $BRANCH $REMOTE_PATH ${BACKENDS[@]}' < scripts/compile.sh ${NC}"
173 ssh -t $user@$server "bash -s -- ${BRANCH} ${REMOTE_PATH} ${list_backends}" < scripts/compile.sh
174 done
175 }
176
177 run_tests_hat() {
178 read_config_file
179 for index in "${!listOfServers[@]}"
180 do
181 server=${listOfServers[$index]}
182 user=${listOfUsers[$index]}
183 list_backends=${BACKENDS[@]}
184 echo -e "\n${GREEN}[info] ssh -t $user@$server 'bash -s -- $BRANCH $REMOTE_PATH ${BACKENDS[@]}' < scripts/test.sh ${NC}"
185 ssh -t $user@$server "bash -s -- ${BRANCH} ${REMOTE_PATH} ${list_backends}" < scripts/test.sh
186 done
187 }
188
189 build_and_and_test() {
190 build_hat
191 run_tests_hat
192 }
193
194 main() {
195 while [[ $# -gt 0 ]]; do
196 key="$1"
197 case $key in
198 --help)
199 display_help
200 exit
201 ;;
202 --generate-config-file)
203 generate_config_file
204 exit
205 ;;
206 --build-babylon)
207 build_babylon
208 exit 0
209 ;;
210 --build-hat)
211 build_hat
212 exit 0
213 ;;
214 --tests)
215 run_tests_hat
216 exit 0
217 ;;
218 *)
219 # Unknown option
220 echo "Error: Unknown option '$key'"
221 echo "Use --help for a list of available options."
222 exit 1
223 ;;
224 esac
225 done
226 ## No options, builds HAT and run the tests
227 build_and_and_test
228 }
229
230 main $@
231
232