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
8 # The following packages are required:
15 script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
16 qemu_dir="${script_dir}/.qemu"
18 ssh_pubkey_file="${qemu_dir}/qemu.pub"
19 ssh_key_file="${qemu_dir}/qemu"
21 mkdir -p "${qemu_dir}"
24 if [[ -n "$(jobs -p)" ]]; then
25 echo killing qemu processes "$(jobs -p)"
36 image_version="xenial"
37 image_url_base="http://cloud-images.ubuntu.com/${image_version}/current"
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"
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"
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"
55 *) die "Unsupported arch" ;;
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}
62 #create a delta disk to keep the original image clean
63 delta_disk="${qemu_dir}/disk.img"
65 qemu-img create -q -f qcow2 -b "${qemu_dir}/${image_disk}" ${delta_disk}
67 # generate an ssh keys
68 [[ -f ${ssh_pubkey_file} ]] || ssh-keygen -q -N "" -f ${ssh_key_file}
70 # create a config disk to set the SSH keys
71 cat > "${qemu_dir}/meta-data" <<EOF
75 cat > "${qemu_dir}/user-data" <<EOF
78 manage_etc_hosts: true
82 - $(cat "${ssh_pubkey_file}")
83 sudo: ['ALL=(ALL) NOPASSWD:ALL']
87 genisoimage -quiet -output "${qemu_dir}/cloud.iso" -volid cidata -joliet -rock "${qemu_dir}/user-data" "${qemu_dir}/meta-data"
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
101 i[[3456]]86*|x86_64*|amd64*)
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}" \
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 \
122 *) die "Unsupported arch" ;;
129 run_ssh "sudo shutdown now" || true
137 -o UserKnownHostsFile=/dev/null
138 -o StrictHostKeyChecking=no
139 -o IdentitiesOnly=yes
151 echo "waiting for machine to come up."
152 echo "tail -F ${qemu_dir}/console.log for progress."
156 ssh -q ${ssh_args[*]} -o ConnectTimeout=1 qemu@localhost "echo done"
159 if [[ $error == 0 ]]; then
163 if [[ ${retries} == ${retry_count} ]]; then
175 ssh -q ${ssh_args[*]} qemu@localhost "$@"
179 scp -q ${shared_args[*]} -P ${ssh_port} "$@"
188 rsync -avz -e "ssh ${ssh_args[*]}" ${rsync_args[*]} "$@"
192 run_ssh "sudo apt-get -y install --no-install-recommends make gcc autoconf libtool automake"
195 init_machine_and_copy_source() {
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"
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
211 # this test run the unit tests on the machine using "make check"
212 run_test_simd_basic() {
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)); }
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)); }
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)); }
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)); }