test/vhost: Use heredoc to create run.sh

This is to make the code that's about to be written out more clear
and drop the unecessary usage of a subshell.

Signed-off-by: Michal Berger <michalx.berger@intel.com>
Change-Id: I024012b08fc3c29d3c37c59a42e64d8429929799
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2004
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Michal Berger 2020-05-04 09:54:28 +02:00 committed by Tomasz Zawadzki
parent 16e16c7700
commit 08f0abebb4

View File

@ -774,30 +774,31 @@ function vm_setup()
(( ${#qemu_args[@]} )) && cmd+=("${qemu_args[@]}") (( ${#qemu_args[@]} )) && cmd+=("${qemu_args[@]}")
notice "Saving to $vm_dir/run.sh" notice "Saving to $vm_dir/run.sh"
( cat <<-RUN >"$vm_dir/run.sh"
echo '#!/bin/bash' #!/bin/bash
echo 'if [[ $EUID -ne 0 ]]; then '
echo ' echo "Go away user come back as root"' if [[ \$EUID -ne 0 ]]; then
echo ' exit 1' echo "Go away user come back as root"
echo 'fi'; exit 1
echo fi
echo "qemu_cmd=($(printf '%s\n' "${cmd[@]}"))";
echo qemu_cmd=($(printf '%s\n' "${cmd[@]}"))
echo "echo 'Running VM in $vm_dir'"
echo "rm -f $qemu_pid_file" echo "Running VM in $vm_dir"
echo '"${qemu_cmd[@]}"' rm -f $qemu_pid_file
echo "echo 'Waiting for QEMU pid file'" "\${qemu_cmd[@]}"
echo "sleep 1" echo "Waiting for QEMU pid file"
echo "[[ ! -f $qemu_pid_file ]] && sleep 1" sleep 1
echo "[[ ! -f $qemu_pid_file ]] && echo 'ERROR: no qemu pid file found' && exit 1" [[ ! -f $qemu_pid_file ]] && sleep 1
echo [[ ! -f $qemu_pid_file ]] && echo "ERROR: no qemu pid file found" && exit 1
echo "chmod +r $vm_dir/*"
echo chmod +r $vm_dir/*
echo "echo '=== qemu.log ==='"
echo "cat $vm_dir/qemu.log" echo "=== qemu.log ==="
echo "echo '=== qemu.log ==='" cat $vm_dir/qemu.log
echo '# EOF' echo "=== qemu.log ==="
) > $vm_dir/run.sh # EOF
RUN
chmod +x $vm_dir/run.sh chmod +x $vm_dir/run.sh
# Save generated sockets redirection # Save generated sockets redirection