]> git.proxmox.com Git - ceph.git/blob - ceph/src/erasure-code/jerasure/gf-complete/tools/test_simd_qemu.sh
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / erasure-code / jerasure / gf-complete / tools / test_simd_qemu.sh
1 #!/bin/bash -e
2
3 # This script will use QEMU to test gf-complete especially SIMD support
4 # on different architectures and cpus. It will boot a qemu machine
5 # and run an Ubuntu cloud image. All testing will happen inside the
6 # QEMU machine.
7
8 # The following packages are required:
9 # qemu-system-aarch64
10 # qemu-system-arm
11 # qemu-system-x86_64
12 # genisoimage
13
14
15 script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
16 qemu_dir="${script_dir}/.qemu"
17 ssh_port=2222
18 ssh_pubkey_file="${qemu_dir}/qemu.pub"
19 ssh_key_file="${qemu_dir}/qemu"
20
21 mkdir -p "${qemu_dir}"
22
23 cleanup() {
24 if [[ -n "$(jobs -p)" ]]; then
25 echo killing qemu processes "$(jobs -p)"
26 kill $(jobs -p)
27 fi
28 }
29
30 trap cleanup EXIT
31
32 start_qemu() {
33 arch=$1
34 cpu=$2
35
36 image_version="xenial"
37 image_url_base="http://cloud-images.ubuntu.com/${image_version}/current"
38
39 case $arch in
40 i[[3456]]86*|x86_64*|amd64*)
41 image_kernel="${image_version}-server-cloudimg-amd64-vmlinuz-generic"
42 image_initrd="${image_version}-server-cloudimg-amd64-initrd-generic"
43 image_disk="${image_version}-server-cloudimg-amd64-disk1.img"
44 ;;
45 aarch64*)
46 image_kernel="${image_version}-server-cloudimg-arm64-vmlinuz-generic"
47 image_initrd="${image_version}-server-cloudimg-arm64-initrd-generic"
48 image_disk="${image_version}-server-cloudimg-arm64-disk1.img"
49 ;;
50 arm*)
51 image_kernel="${image_version}-server-cloudimg-armhf-vmlinuz-lpae"
52 image_initrd="${image_version}-server-cloudimg-armhf-initrd-generic-lpae"
53 image_disk="${image_version}-server-cloudimg-armhf-disk1.img"
54 ;;
55 *) die "Unsupported arch" ;;
56 esac
57
58 [[ -f ${qemu_dir}/${image_kernel} ]] || wget -O ${qemu_dir}/${image_kernel} ${image_url_base}/unpacked/${image_kernel}
59 [[ -f ${qemu_dir}/${image_initrd} ]] || wget -O ${qemu_dir}/${image_initrd} ${image_url_base}/unpacked/${image_initrd}
60 [[ -f ${qemu_dir}/${image_disk} ]] || wget -O ${qemu_dir}/${image_disk} ${image_url_base}/${image_disk}
61
62 #create a delta disk to keep the original image clean
63 delta_disk="${qemu_dir}/disk.img"
64 rm -f ${delta_disk}
65 qemu-img create -q -f qcow2 -b "${qemu_dir}/${image_disk}" ${delta_disk}
66
67 # generate an ssh keys
68 [[ -f ${ssh_pubkey_file} ]] || ssh-keygen -q -N "" -f ${ssh_key_file}
69
70 # create a config disk to set the SSH keys
71 cat > "${qemu_dir}/meta-data" <<EOF
72 instance-id: qemu
73 local-hostname: qemu
74 EOF
75 cat > "${qemu_dir}/user-data" <<EOF
76 #cloud-config
77 hostname: qemu
78 manage_etc_hosts: true
79 users:
80 - name: qemu
81 ssh-authorized-keys:
82 - $(cat "${ssh_pubkey_file}")
83 sudo: ['ALL=(ALL) NOPASSWD:ALL']
84 groups: sudo
85 shell: /bin/bash
86 EOF
87 genisoimage -quiet -output "${qemu_dir}/cloud.iso" -volid cidata -joliet -rock "${qemu_dir}/user-data" "${qemu_dir}/meta-data"
88
89 common_args=( \
90 -name "qemu" \
91 -m 1024 \
92 -nodefaults \
93 -nographic \
94 -kernel ${qemu_dir}/${image_kernel} \
95 -initrd ${qemu_dir}/${image_initrd} \
96 -cdrom ${qemu_dir}/cloud.iso \
97 -serial file:${qemu_dir}/console.log
98 )
99
100 case $arch in
101 i[[3456]]86*|x86_64*|amd64*)
102 qemu-system-x86_64 \
103 "${common_args[@]}" \
104 -machine accel=kvm -cpu $cpu \
105 -append "console=ttyS0 root=/dev/sda1" \
106 -hda "${delta_disk}" \
107 -net nic,vlan=0,model=virtio \
108 -net user,vlan=0,hostfwd=tcp::"${ssh_port}"-:22,hostname="${vm_name}" \
109 &
110 ;;
111 aarch64*|arm*)
112 qemu-system-$arch \
113 "${common_args[@]}" \
114 -machine virt -cpu $cpu -machine type=virt -smp 1 \
115 -drive if=none,file="${delta_disk}",id=hd0 \
116 -device virtio-blk-device,drive=hd0 \
117 -append "console=ttyAMA0 root=/dev/vda1" \
118 -netdev user,id=eth0,hostfwd=tcp::"${ssh_port}"-:22,hostname="${vm_name}" \
119 -device virtio-net-device,netdev=eth0 \
120 &
121 ;;
122 *) die "Unsupported arch" ;;
123 esac
124
125 wait_for_ssh
126 }
127
128 stop_qemu() {
129 run_ssh "sudo shutdown now" || true
130 wait $(jobs -p)
131 }
132
133 shared_args=(
134 -i ${ssh_key_file}
135 -F /dev/null
136 -o BatchMode=yes
137 -o UserKnownHostsFile=/dev/null
138 -o StrictHostKeyChecking=no
139 -o IdentitiesOnly=yes
140 )
141
142 ssh_args=(
143 ${shared_args[*]}
144 -p ${ssh_port}
145 )
146
147 wait_for_ssh() {
148 retries=0
149 retry_count=50
150
151 echo "waiting for machine to come up."
152 echo "tail -F ${qemu_dir}/console.log for progress."
153
154 while true; do
155 set +e
156 ssh -q ${ssh_args[*]} -o ConnectTimeout=1 qemu@localhost "echo done"
157 error=$?
158 set -e
159 if [[ $error == 0 ]]; then
160 return 0
161 fi
162
163 if [[ ${retries} == ${retry_count} ]]; then
164 echo "timeout"
165 return 1
166 fi
167
168 echo -n "."
169 ((++retries))
170 sleep 10
171 done
172 }
173
174 run_ssh() {
175 ssh -q ${ssh_args[*]} qemu@localhost "$@"
176 }
177
178 run_scp() {
179 scp -q ${shared_args[*]} -P ${ssh_port} "$@"
180 }
181
182 rsync_args=(
183 --exclude '.qemu'
184 --exclude '.git'
185 )
186
187 run_rsync() {
188 rsync -avz -e "ssh ${ssh_args[*]}" ${rsync_args[*]} "$@"
189 }
190
191 init_machine() {
192 run_ssh "sudo apt-get -y install --no-install-recommends make gcc autoconf libtool automake"
193 }
194
195 init_machine_and_copy_source() {
196 init_machine
197 run_ssh "rm -fr ~/gf-complete; mkdir -p ~/gf-complete"
198 run_rsync ${script_dir}/.. qemu@localhost:gf-complete
199 run_ssh "cd ~/gf-complete && ./autogen.sh"
200 }
201
202 run_test() {
203 arch=$1; shift
204 cpu=$1; shift
205 test=$1; shift
206
207 run_ssh "~/gf-complete/tools/test_simd.sh ${test}"
208 run_scp qemu@localhost:gf-complete/tools/test_simd.results ${script_dir}/test_simd_${test}_${arch}_${cpu}.results
209 }
210
211 # this test run the unit tests on the machine using "make check"
212 run_test_simd_basic() {
213 arch=$1; shift
214 cpu=$1; shift
215
216 failed=0
217
218 echo "=====starting qemu machine $arch $cpu"
219 start_qemu $arch $cpu
220 init_machine_and_copy_source
221 echo "=====running compile test"
222 { run_test $arch $cpu "compile" && echo "SUCCESS"; } || { echo "FAILED"; ((++failed)); }
223 echo "=====running unit test"
224 { run_test $arch $cpu "unit" && echo "SUCCESS"; } || { echo "FAILED"; ((++failed)); }
225 echo "=====running functions test"
226 { run_test $arch $cpu "functions" && echo "SUCCESS"; } || { echo "FAILED"; ((++failed)); }
227 echo "=====running detection test"
228 { run_test $arch $cpu "detection" && echo "SUCCESS"; } || { echo "FAILED"; ((++failed)); }
229 echo "=====running runtime test"
230 { run_test $arch $cpu "runtime" && echo "SUCCESS"; } || { echo "FAILED"; ((++failed)); }
231 stop_qemu
232
233 return ${failed}
234 }
235
236 run_all_tests() {
237 failed=0
238
239 echo ============================
240 echo =====running x86_64 tests
241 # NOTE: Broadwell has all the supported SIMD instructions
242 { run_test_simd_basic "x86_64" "Broadwell" && echo "SUCCESS"; } || { echo "FAILED"; ((++failed)); }
243
244 echo ============================
245 echo =====running aarch64 tests
246 # NOTE: cortex-a57 has ASIMD support
247 { run_test_simd_basic "aarch64" "cortex-a57" && echo "SUCCESS"; } || { echo "FAILED"; ((++failed)); }
248
249 echo ============================
250 echo =====running arm tests
251 # NOTE: cortex-a15 has NEON support
252 { run_test_simd_basic "arm" "cortex-a15" && echo "SUCCESS"; } || { echo "FAILED"; ((++failed)); }
253
254 return ${failed}
255 }
256
257 run_all_tests
258 exit $?