Skip to content

Commit e01dcf6

Browse files
author
Erik Schilling
committed
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 <[email protected]> Link: https://linaro.atlassian.net/browse/ORKO-17
1 parent 63ac63c commit e01dcf6

File tree

7 files changed

+133
-0
lines changed

7 files changed

+133
-0
lines changed

crates/scsi/test/.containerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
results/
2+
test-data/

crates/scsi/test/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
results/
2+
test-data/

crates/scsi/test/Containerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM fedora:39
2+
RUN dnf install --quiet --assumeyes \
3+
/usr/bin/qemu-system-x86_64 \
4+
/usr/bin/qemu-img \
5+
/usr/bin/virt-sysprep \
6+
/usr/bin/ssh-keygen \
7+
/usr/bin/ssh \
8+
/usr/sbin/libvirtd \
9+
wget \
10+
&& dnf clean all
11+
VOLUME /tests/

crates/scsi/test/README.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Testing tools
2+
3+
This folder contains some tooling for tests
4+
5+
## Prerequisites
6+
7+
For running these tests, you need a KVM enabled x86_64 machine and `podman`.
8+
9+
vhost-user-scsi must have been built already.
10+
11+
## Performed tests
12+
13+
Right now, the test harness will only run
14+
[blktests](https://github.com/osandov/blktests) against the target device
15+
(these tests are probably testing the guest kernel more than the actual
16+
device).
17+
18+
## Test execution
19+
20+
Triggering the build of the necessary container images and invoking the tests
21+
is done by calling `./invoke-test.sh`.
22+
23+
That will build the `Containerfile`, launch a container and invoke
24+
`./start-test.sh` inside of the container. That will download a Fedora cloud
25+
image, launch the daemon, launch QEMU, waits until it is up and triggers the
26+
test execution.
27+
28+
Results will be downloaded into a timestamped folder under `results/`.

crates/scsi/test/invoke-test.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash -xe
2+
3+
cd $(dirname "$0")
4+
5+
DAEMON_BINARY="$PWD/../../../target/debug/vhost-device-scsi"
6+
7+
if [[ ! -e "$DAEMON_BINARY" ]]
8+
then
9+
echo "Unable to find \"$DAEMON_BINARY\". Did you run cargo build?"
10+
exit 1
11+
fi
12+
13+
TAG_NAME=vhost-device-scsi-test-env
14+
podman build -t "$TAG_NAME" .
15+
podman run \
16+
-v /dev/kvm:/dev/kvm \
17+
--security-opt label=disable \
18+
-v "$DAEMON_BINARY":/usr/local/bin/vhost-device-scsi:ro \
19+
-v $PWD:/test "$TAG_NAME" \
20+
/test/start-test.sh

crates/scsi/test/start-test.sh

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash -xe
2+
3+
cd $(dirname "$0")
4+
5+
libvirtd --daemon
6+
virtlogd --daemon
7+
export LIBGUESTFS_BACKEND=direct
8+
9+
mkdir -p test-data/
10+
pushd test-data
11+
IMAGE=Fedora-Cloud-Base-38-1.6.x86_64.qcow2
12+
test -e "$IMAGE" || wget --quiet "https://download.fedoraproject.org/pub/fedora/linux/releases/38/Cloud/x86_64/images/$IMAGE" -O "$IMAGE"
13+
qemu-img create -f qcow2 -F qcow2 -b "$PWD/$IMAGE" fedora-overlay.qcow2
14+
15+
test -e test-key-id_rsa || ssh-keygen -N "" -f test-key-id_rsa
16+
17+
virt-sysprep -a fedora-overlay.qcow2 \
18+
--ssh-inject root:file:test-key-id_rsa.pub
19+
20+
fallocate -l 5GiB big-image.img
21+
popd
22+
23+
SSH_OPTS="-i test-data/test-key-id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o User=root -o Port=2222"
24+
25+
vhost-device-scsi --socket-path /tmp/vhost-user-scsi.sock test-data/big-image.img &
26+
27+
sleep 1
28+
29+
qemu-system-x86_64 \
30+
-enable-kvm -cpu host \
31+
-device virtio-net-pci,netdev=net0,mac=52:54:00:12:35:02\
32+
-netdev user,id=net0,hostfwd=tcp::2222-:22,hostfwd=tcp::2323-:23 \
33+
-object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0 \
34+
-hda test-data/fedora-overlay.qcow2 \
35+
-object memory-backend-memfd,id=mem,size=8192M,share=on \
36+
-numa node,memdev=mem \
37+
-device vhost-user-scsi-pci,num_queues=1,param_change=off,chardev=vus \
38+
-chardev socket,id=vus,path=/tmp/vhost-user-scsi.sock \
39+
-smp 4 -m 8192 \
40+
-serial mon:stdio \
41+
-display none &
42+
43+
44+
while ! ssh $SSH_OPTS localhost echo waiting for guest to come online
45+
do
46+
sleep 1
47+
done
48+
49+
50+
scp $SSH_OPTS test-script.sh localhost:~/
51+
ssh $SSH_OPTS localhost /root/test-script.sh || echo "tests failed"
52+
53+
export RESULT_DIR="$PWD/results/$(date --rfc-3339=s)"
54+
mkdir -p "$RESULT_DIR"
55+
56+
scp $SSH_OPTS -r localhost:/root/blktests/results/ "$RESULT_DIR/"
57+
ssh $SSH_OPTS localhost poweroff
58+
59+
wait # wait for qemu to terminate
60+

crates/scsi/test/test-script.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash -xe
2+
3+
dnf install -y git make g++ fio liburing-devel blktrace
4+
5+
git clone https://github.com/osandov/blktests.git
6+
pushd blktests
7+
echo "TEST_DEVS=(/dev/sdb)" > config
8+
make -j $(nproc)
9+
./check scsi block
10+
popd

0 commit comments

Comments
 (0)