scsi: add some helper scripts for testing

This provides some tooling for running blktests. The README.md contains
documentation about the architecture.

I am seeing some race-conditions that sometimes lead to boot
freezes [1], so this is not really ready for automatic evaluation during
a CI pipeline.

[1] https://linaro.atlassian.net/browse/ORKO-37

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
Link: https://linaro.atlassian.net/browse/ORKO-17
This commit is contained in:
Erik Schilling 2023-05-11 10:38:41 +02:00 committed by Viresh Kumar
parent a6382dd937
commit 8bb862d415
7 changed files with 133 additions and 0 deletions

View File

@ -0,0 +1,2 @@
results/
test-data/

2
crates/scsi/test/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
results/
test-data/

View File

@ -0,0 +1,11 @@
FROM fedora:39
RUN dnf install --quiet --assumeyes \
/usr/bin/qemu-system-x86_64 \
/usr/bin/qemu-img \
/usr/bin/virt-sysprep \
/usr/bin/ssh-keygen \
/usr/bin/ssh \
/usr/sbin/libvirtd \
wget \
&& dnf clean all
VOLUME /tests/

View File

@ -0,0 +1,28 @@
# Testing tools
This folder contains some tooling for tests
## Prerequisites
For running these tests, you need a KVM enabled x86_64 machine and `podman`.
vhost-user-scsi must have been built already.
## Performed tests
Right now, the test harness will only run
[blktests](https://github.com/osandov/blktests) against the target device
(these tests are probably testing the guest kernel more than the actual
device).
## Test execution
Triggering the build of the necessary container images and invoking the tests
is done by calling `./invoke-test.sh`.
That will build the `Containerfile`, launch a container and invoke
`./start-test.sh` inside of the container. That will download a Fedora cloud
image, launch the daemon, launch QEMU, waits until it is up and triggers the
test execution.
Results will be downloaded into a timestamped folder under `results/`.

20
crates/scsi/test/invoke-test.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash -xe
cd $(dirname "$0")
DAEMON_BINARY="$PWD/../../../target/debug/vhost-device-scsi"
if [[ ! -e "$DAEMON_BINARY" ]]
then
echo "Unable to find \"$DAEMON_BINARY\". Did you run cargo build?"
exit 1
fi
TAG_NAME=vhost-device-scsi-test-env
podman build -t "$TAG_NAME" .
podman run \
-v /dev/kvm:/dev/kvm \
--security-opt label=disable \
-v "$DAEMON_BINARY":/usr/local/bin/vhost-device-scsi:ro \
-v $PWD:/test "$TAG_NAME" \
/test/start-test.sh

60
crates/scsi/test/start-test.sh Executable file
View File

@ -0,0 +1,60 @@
#!/bin/bash -xe
cd $(dirname "$0")
libvirtd --daemon
virtlogd --daemon
export LIBGUESTFS_BACKEND=direct
mkdir -p test-data/
pushd test-data
IMAGE=Fedora-Cloud-Base-38-1.6.x86_64.qcow2
test -e "$IMAGE" || wget --quiet "https://download.fedoraproject.org/pub/fedora/linux/releases/38/Cloud/x86_64/images/$IMAGE" -O "$IMAGE"
qemu-img create -f qcow2 -F qcow2 -b "$PWD/$IMAGE" fedora-overlay.qcow2
test -e test-key-id_rsa || ssh-keygen -N "" -f test-key-id_rsa
virt-sysprep -a fedora-overlay.qcow2 \
--ssh-inject root:file:test-key-id_rsa.pub
fallocate -l 5GiB big-image.img
popd
SSH_OPTS="-i test-data/test-key-id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o User=root -o Port=2222"
vhost-device-scsi --socket-path /tmp/vhost-user-scsi.sock test-data/big-image.img &
sleep 1
qemu-system-x86_64 \
-enable-kvm -cpu host \
-device virtio-net-pci,netdev=net0,mac=52:54:00:12:35:02\
-netdev user,id=net0,hostfwd=tcp::2222-:22,hostfwd=tcp::2323-:23 \
-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0 \
-hda test-data/fedora-overlay.qcow2 \
-object memory-backend-memfd,id=mem,size=8192M,share=on \
-numa node,memdev=mem \
-device vhost-user-scsi-pci,num_queues=1,param_change=off,chardev=vus \
-chardev socket,id=vus,path=/tmp/vhost-user-scsi.sock \
-smp 4 -m 8192 \
-serial mon:stdio \
-display none &
while ! ssh $SSH_OPTS localhost echo waiting for guest to come online
do
sleep 1
done
scp $SSH_OPTS test-script.sh localhost:~/
ssh $SSH_OPTS localhost /root/test-script.sh || echo "tests failed"
export RESULT_DIR="$PWD/results/$(date --rfc-3339=s)"
mkdir -p "$RESULT_DIR"
scp $SSH_OPTS -r localhost:/root/blktests/results/ "$RESULT_DIR/"
ssh $SSH_OPTS localhost poweroff
wait # wait for qemu to terminate

10
crates/scsi/test/test-script.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash -xe
dnf install -y git make g++ fio liburing-devel blktrace
git clone https://github.com/osandov/blktests.git
pushd blktests
echo "TEST_DEVS=(/dev/sdb)" > config
make -j $(nproc)
./check scsi block
popd