# virtme-ng offers a netdev for ssh when using "--ssh", but we also need a # control port forwarded for vsock_test. Because virtme-ng doesn't support # adding an additional port to forward to the device created from "--ssh" and # virtme-init mistakenly sets identical IPs to the ssh device and additional # devices, we instead opt out of using --ssh, add the device manually, and also # add the kernel cmdline options that virtme-init uses to setup the interface.
readonly QEMU_TEST_PORT_FWD="hostfwd=tcp::${TEST_HOST_PORT}-:${TEST_GUEST_PORT}"
readonly QEMU_SSH_PORT_FWD="hostfwd=tcp::${SSH_HOST_PORT}-:${SSH_GUEST_PORT}"
readonly QEMU_OPTS="\
-netdev user,id=n0,${QEMU_TEST_PORT_FWD},${QEMU_SSH_PORT_FWD} \
-device virtio-net-pci,netdev=n0 \
-device vhost-vsock-pci,guest-cid=${VSOCK_CID} \
--pidfile ${QEMU_PIDFILE} \ "
readonly KERNEL_CMDLINE="\
virtme.dhcp net.ifnames=0 biosdevname=0 \
virtme.ssh virtme_ssh_channel=tcp virtme_ssh_user=$USER \ "
readonly LOG=$(mktemp /tmp/vsock_vmtest_XXXX.log)
readonly TEST_NAMES=(vm_server_host_client vm_client_host_server vm_loopback)
readonly TEST_DESCS=( "Run vsock_test in server mode on the VM and in client mode on the host." "Run vsock_test in client mode on the VM and in server mode on the host." "Run vsock_test using the loopback transport in the VM."
)
VERBOSE=0
usage() {
local name
local desc
local i
echo echo"$0 [OPTIONS] [TEST]..." echo"If no TEST argument is given, all tests will be run." echo echo"Options" echo" -b: build the kernel from the current source tree and use it for guest VMs" echo" -q: set the path to or name of qemu binary" echo" -v: verbose output" echo echo"Available tests"
for ((i = 0; i < ${#TEST_NAMES[@]}; i++)); do
name=${TEST_NAMES[${i}]}
desc=${TEST_DESCS[${i}]}
printf "\t%-35s%-35s\n""${name}""${desc}" done echo
cleanup() { if [[ -s "${QEMU_PIDFILE}" ]]; then
pkill -SIGTERM -F "${QEMU_PIDFILE}" > /dev/null 2>&1 fi
# If failure occurred during or before qemu start up, then we need # to clean this up ourselves. if [[ -e "${QEMU_PIDFILE}" ]]; then rm"${QEMU_PIDFILE}" fi
}
check_args() {
local found
for arg in "$@"; do
found=0 for name in "${TEST_NAMES[@]}"; do if [[ "${name}" = "${arg}" ]]; then
found=1
break fi done
if [[ "${found}" -eq 0 ]]; then echo"${arg} is not an available test" >&2
usage fi done
for arg in "$@"; do if ! command -v > /dev/null "test_${arg}"; then echo"Test ${arg} not found" >&2
usage fi done
}
check_deps() { for dep in vng ${QEMU} busybox pkill ssh; do if [[ ! -x $(command -v "${dep}") ]]; then echo -e "skip: dependency ${dep} not found!\n"
exit "${KSFT_SKIP}" fi done
if [[ ! -x $(command -v "${VSOCK_TEST}") ]]; then
printf "skip: %s not found!""${VSOCK_TEST}"
printf " Please build the kselftest vsock target.\n"
exit "${KSFT_SKIP}" fi
}
check_vng() {
local tested_versions
local version
local ok
ok=0 for tv in "${tested_versions[@]}"; do if [[ "${version}" == *"${tv}"* ]]; then
ok=1
break fi done
if [[ ! "${ok}" -eq 1 ]]; then
printf "warning: vng version '%s' has not been tested and may ""${version}" >&2
printf "not function properly.\n\tThe following versions have been tested: " >&2 echo"${tested_versions[@]}" >&2 fi
}
handle_build() { if [[ ! "${BUILD}" -eq 1 ]]; then
return fi
if [[ ! -d "${KERNEL_CHECKOUT}" ]]; then echo"-b requires vmtest.sh called from the kernel source tree" >&2
exit 1 fi
pushd "${KERNEL_CHECKOUT}" &>/dev/null
if ! vng --kconfig --config "${SCRIPT_DIR}"/config; then
die "failed to generate .config for kernel source tree (${KERNEL_CHECKOUT})" fi
if ! make -j$(nproc); then
die "failed to build kernel from source tree (${KERNEL_CHECKOUT})" fi
popd &>/dev/null
}
vm_start() {
local logfile=/dev/null
local verbose_opt=""
local kernel_opt=""
local qemu
qemu=$(command -v "${QEMU}")
if [[ "${VERBOSE}" -eq 1 ]]; then
verbose_opt="--verbose"
logfile=/dev/stdout fi
if [[ "${BUILD}" -eq 1 ]]; then
kernel_opt="${KERNEL_CHECKOUT}" fi
if ! timeout ${WAIT_TOTAL} \
bash -c 'while [[ ! -s '"${QEMU_PIDFILE}"' ]]; do sleep 1; done; exit 0'; then
die "failed to boot VM" fi
}
vm_wait_for_ssh() {
local i
i=0 while true; do if [[ ${i} -gt ${WAIT_PERIOD_MAX} ]]; then
die "Timed out waiting for guest ssh" fi if vm_ssh -- true; then
break fi
i=$(( i + 1 ))
sleep ${WAIT_PERIOD} done
}
# derived from selftests/net/net_helper.sh
wait_for_listener()
{
local port=$1
local interval=$2
local max_intervals=$3
local protocol=tcp
local pattern
local i
pattern=":$(printf "%04X" "${port}") "
# for tcp protocol additionally check the socket state
[ "${protocol}" = "tcp" ] && pattern="${pattern}0A" for i in $(seq "${max_intervals}"); do if awk '{print $2" "$4}' /proc/net/"${protocol}"* | \
grep -q "${pattern}"; then
break fi
sleep "${interval}" done
}
run_test() {
local host_oops_cnt_before
local host_warn_cnt_before
local vm_oops_cnt_before
local vm_warn_cnt_before
local host_oops_cnt_after
local host_warn_cnt_after
local vm_oops_cnt_after
local vm_warn_cnt_after
local name
local rc
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.