test cases for volumes

Signed-off-by: Avi Deitcher <avi@deitcher.net>
This commit is contained in:
Avi Deitcher 2024-07-21 12:20:53 +03:00
parent a5085fc9ea
commit 38a0cb6376
23 changed files with 502 additions and 0 deletions

View File

@ -0,0 +1,15 @@
#!/bin/sh
set -x
function failed {
printf "rw_on_rw test suite FAILED\n" >&1
exit 1
}
# check that the files we created are there and have the contents
[ -d /vola ] || failed
[ -e /vola/mytestfile ] || failed
[ "$(cat /vola/mytestfile)" == "file" ] || failed
printf "rw_on_rw test suite PASSED\n" >&1

View File

@ -0,0 +1,26 @@
#!/bin/sh
# SUMMARY: Check that writing to a volume makes it visible
# LABELS:
# REPEAT:
set -ex
# Source libraries. Uncomment if needed/defined
#. "${RT_LIB}"
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
NAME=volume_rw_on_rw
clean_up() {
rm -rf ${NAME}-* ${DISK}
}
trap clean_up EXIT
# Test code goes here
linuxkit build --format kernel+initrd --name ${NAME} test.yml
RESULT="$(linuxkit run ${NAME})"
echo "${RESULT}"
echo "${RESULT}" | grep -q "suite PASSED"
exit 0

View File

@ -0,0 +1,31 @@
kernel:
image: linuxkit/kernel:6.6.13
cmdline: "console=ttyS0 console=ttyAMA0"
init:
- linuxkit/init:872d2e1be745f1acb948762562cf31c367303a3b
- linuxkit/runc:6062483d748609d505f2bcde4e52ee64a3329f5f
onboot:
- name: test1
image: alpine:3.20
binds:
- /write.sh:/write.sh
- vola:/vola
command: ["sh", "-c", "/write.sh"]
- name: test2
image: alpine:3.20
binds:
- /check.sh:/check.sh
- vola:/vola
command: ["sh", "-c", "/check.sh"]
- name: poweroff
image: linuxkit/poweroff:401dc53c604c0b2179ed0369a6968fd4179cc176
command: ["/bin/sh", "/poweroff.sh", "10"]
volumes:
- name: vola
files:
- path: check.sh
source: ./check.sh
mode: "0700"
- path: write.sh
source: ./write.sh
mode: "0700"

View File

@ -0,0 +1,5 @@
#!/bin/sh
set -x
echo -n "file" > /vola/mytestfile

View File

@ -0,0 +1,15 @@
#!/bin/sh
set -x
function failed {
printf "ro_on_ro test suite FAILED\n" >&1
exit 1
}
# this should fail as it is read-only
echo -n "file" > /vola/mytestfile || true
[ -e /vola/mytestfile ] && failed
printf "ro_on_ro test suite PASSED\n" >&1

View File

@ -0,0 +1,26 @@
#!/bin/sh
# SUMMARY: Check that writing to a volume makes it visible
# LABELS:
# REPEAT:
set -ex
# Source libraries. Uncomment if needed/defined
#. "${RT_LIB}"
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
NAME=volume_ro_on_ro
clean_up() {
rm -rf ${NAME}-* ${DISK}
}
trap clean_up EXIT
# Test code goes here
linuxkit build --format kernel+initrd --name ${NAME} test.yml
RESULT="$(linuxkit run ${NAME})"
echo "${RESULT}"
echo "${RESULT}" | grep -q "suite PASSED"
exit 0

View File

@ -0,0 +1,23 @@
kernel:
image: linuxkit/kernel:6.6.13
cmdline: "console=ttyS0 console=ttyAMA0"
init:
- linuxkit/init:872d2e1be745f1acb948762562cf31c367303a3b
- linuxkit/runc:6062483d748609d505f2bcde4e52ee64a3329f5f
onboot:
- name: test
image: alpine:3.20
binds:
- /check.sh:/check.sh
- vola:/vola:ro
command: ["sh", "-c", "/check.sh"]
- name: poweroff
image: linuxkit/poweroff:401dc53c604c0b2179ed0369a6968fd4179cc176
command: ["/bin/sh", "/poweroff.sh", "10"]
volumes:
- name: vola
readonly: true
files:
- path: check.sh
source: ./check.sh
mode: "0700"

View File

@ -0,0 +1,15 @@
#!/bin/sh
set -x
function failed {
printf "rw_on_ro test suite FAILED\n" >&1
exit 1
}
# this should fail as it is read-only
echo -n "file" > /vola/mytestfile || true
[ -e /vola/mytestfile ] && failed
printf "rw_on_ro test suite PASSED\n" >&1

View File

@ -0,0 +1,29 @@
#!/bin/sh
# SUMMARY: Check that writing to a volume makes it visible
# LABELS:
# REPEAT:
set -ex
# Source libraries. Uncomment if needed/defined
#. "${RT_LIB}"
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
NAME=volume_rw_on_r0
clean_up() {
rm -rf ${NAME}-* ${DISK}
}
trap clean_up EXIT
# Test code goes here
set +e
linuxkit build --format kernel+initrd --name ${NAME} test.yml
retcode=$?
set -e
# the build should fail, as we have are mounting a read-only volume as read-write in a container
if [ $retcode -eq 0 ]; then
exit 1
fi

View File

@ -0,0 +1,23 @@
kernel:
image: linuxkit/kernel:6.6.13
cmdline: "console=ttyS0 console=ttyAMA0"
init:
- linuxkit/init:872d2e1be745f1acb948762562cf31c367303a3b
- linuxkit/runc:6062483d748609d505f2bcde4e52ee64a3329f5f
onboot:
- name: test
image: alpine:3.20
binds:
- /check.sh:/check.sh
- vola:/vola
command: ["sh", "-c", "/check.sh"]
- name: poweroff
image: linuxkit/poweroff:401dc53c604c0b2179ed0369a6968fd4179cc176
command: ["/bin/sh", "/poweroff.sh", "10"]
volumes:
- name: vola
readonly: true
files:
- path: check.sh
source: ./check.sh
mode: "0700"

View File

@ -0,0 +1,14 @@
#!/bin/sh
set -x
function failed {
printf "ro_on_rw test suite FAILED\n" >&1
exit 1
}
# the file should not exist, as it was mounted read-only
[ -d /vola ] || failed
[ -e /vola/mytestfile ] && failed
printf "ro_on_rw test suite PASSED\n" >&1

View File

@ -0,0 +1,26 @@
#!/bin/sh
# SUMMARY: Check that writing to a volume makes it visible
# LABELS:
# REPEAT:
set -ex
# Source libraries. Uncomment if needed/defined
#. "${RT_LIB}"
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
NAME=volume_ro_on_rw
clean_up() {
rm -rf ${NAME}-* ${DISK}
}
trap clean_up EXIT
# Test code goes here
linuxkit build --format kernel+initrd --name ${NAME} test.yml
RESULT="$(linuxkit run ${NAME})"
echo "${RESULT}"
echo "${RESULT}" | grep -q "suite PASSED"
exit 0

View File

@ -0,0 +1,28 @@
kernel:
image: linuxkit/kernel:6.6.13
cmdline: "console=ttyS0 console=ttyAMA0"
init:
- linuxkit/init:872d2e1be745f1acb948762562cf31c367303a3b
- linuxkit/runc:6062483d748609d505f2bcde4e52ee64a3329f5f
onboot:
- name: test1
image: alpine:3.20
binds:
- /write.sh:/write.sh
- vola:/vola:ro
command: ["sh", "-c", "/write.sh"]
- name: test2
image: alpine:3.20
binds:
- /check.sh:/check.sh
- vola:/vola:ro
command: ["sh", "-c", "/check.sh"]
- name: poweroff
image: linuxkit/poweroff:401dc53c604c0b2179ed0369a6968fd4179cc176
command: ["/bin/sh", "/poweroff.sh", "10"]
volumes:
- name: vola
files:
- path: check.sh
source: ./check.sh
mode: "0700"

View File

@ -0,0 +1,15 @@
#!/bin/sh
set -x
function failed {
printf "ro_on_ro test suite FAILED\n" >&1
exit 1
}
# this should fail as it is read-only
echo -n "file" > /vola/mytestfile || true
[ -e /vola/mytestfile ] && failed
printf "ro_on_ro test suite PASSED\n" >&1

View File

@ -0,0 +1,16 @@
#!/bin/sh
set -x
function failed {
printf "blank volume test suite FAILED\n" >&1
exit 1
}
# check that no files exist
[ -d /vola ] || failed
contents=$(ls -A /vola)
[ -z "$contents" ] || failed
printf "blank volume test suite PASSED\n" >&1

View File

@ -0,0 +1,26 @@
#!/bin/sh
# SUMMARY: Check that writing to a volume makes it visible
# LABELS:
# REPEAT:
set -ex
# Source libraries. Uncomment if needed/defined
#. "${RT_LIB}"
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
NAME=volume_blank
clean_up() {
rm -rf ${NAME}-* ${DISK}
}
trap clean_up EXIT
# Test code goes here
linuxkit build --format kernel+initrd --name ${NAME} test.yml
RESULT="$(linuxkit run ${NAME})"
echo "${RESULT}"
echo "${RESULT}" | grep -q "suite PASSED"
exit 0

View File

@ -0,0 +1,22 @@
kernel:
image: linuxkit/kernel:6.6.13
cmdline: "console=ttyS0 console=ttyAMA0"
init:
- linuxkit/init:872d2e1be745f1acb948762562cf31c367303a3b
- linuxkit/runc:6062483d748609d505f2bcde4e52ee64a3329f5f
onboot:
- name: test
image: alpine:3.20
binds:
- /check.sh:/check.sh
- vola:/vola
command: ["sh", "-c", "/check.sh"]
- name: poweroff
image: linuxkit/poweroff:401dc53c604c0b2179ed0369a6968fd4179cc176
command: ["/bin/sh", "/poweroff.sh", "10"]
volumes:
- name: vola
files:
- path: check.sh
source: ./check.sh
mode: "0700"

View File

@ -0,0 +1,17 @@
#!/bin/sh
set -x
function failed {
printf "blank volume test suite FAILED\n" >&1
exit 1
}
# check that no files exist
[ -d /vola ] || failed
contents=$(ls -A /vola)
[ -n "$contents" ] || failed
[ -e "/vola/bin/busybox" ] || failed
printf "blank volume test suite PASSED\n" >&1

View File

@ -0,0 +1,26 @@
#!/bin/sh
# SUMMARY: Check that writing to a volume makes it visible
# LABELS:
# REPEAT:
set -ex
# Source libraries. Uncomment if needed/defined
#. "${RT_LIB}"
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
NAME=volume_image
clean_up() {
rm -rf ${NAME}-* ${DISK}
}
trap clean_up EXIT
# Test code goes here
linuxkit build --format kernel+initrd --name ${NAME} test.yml
RESULT="$(linuxkit run ${NAME})"
echo "${RESULT}"
echo "${RESULT}" | grep -q "suite PASSED"
exit 0

View File

@ -0,0 +1,23 @@
kernel:
image: linuxkit/kernel:6.6.13
cmdline: "console=ttyS0 console=ttyAMA0"
init:
- linuxkit/init:872d2e1be745f1acb948762562cf31c367303a3b
- linuxkit/runc:6062483d748609d505f2bcde4e52ee64a3329f5f
onboot:
- name: test
image: alpine:3.20
binds:
- /check.sh:/check.sh
- vola:/vola
command: ["sh", "-c", "/check.sh"]
- name: poweroff
image: linuxkit/poweroff:401dc53c604c0b2179ed0369a6968fd4179cc176
command: ["/bin/sh", "/poweroff.sh", "10"]
volumes:
- name: vola
image: alpine:3.19
files:
- path: check.sh
source: ./check.sh
mode: "0700"

View File

@ -0,0 +1,17 @@
#!/bin/sh
set -x
function failed {
printf "blank volume test suite FAILED\n" >&1
exit 1
}
# check that no files exist
[ -d /vola ] || failed
contents=$(ls -A /vola)
[ -n "$contents" ] || failed
[ -e "/vola/bin/busybox" ] || failed
printf "blank volume test suite PASSED\n" >&1

View File

@ -0,0 +1,26 @@
#!/bin/sh
# SUMMARY: Check that writing to a volume makes it visible
# LABELS:
# REPEAT:
set -ex
# Source libraries. Uncomment if needed/defined
#. "${RT_LIB}"
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
NAME=volume_mount_types
clean_up() {
rm -rf ${NAME}-* ${DISK}
}
trap clean_up EXIT
# Test code goes here
linuxkit build --format kernel+initrd --name ${NAME} test.yml
RESULT="$(linuxkit run ${NAME})"
echo "${RESULT}"
echo "${RESULT}" | grep -q "suite PASSED"
exit 0

View File

@ -0,0 +1,38 @@
kernel:
image: linuxkit/kernel:6.6.13
cmdline: "console=ttyS0 console=ttyAMA0"
init:
- linuxkit/init:872d2e1be745f1acb948762562cf31c367303a3b
- linuxkit/runc:6062483d748609d505f2bcde4e52ee64a3329f5f
onboot:
- name: testbinds
image: alpine:3.20
binds:
- /check.sh:/check.sh
- vola:/vola
command: ["sh", "-c", "/check.sh"]
- name: testmounts
image: alpine:3.20
binds:
- /check.sh:/check.sh
mounts:
- type: bind
source: vola
destination: /vola
command: ["sh", "-c", "/check.sh"]
- name: testbindadds
image: alpine:3.20
binds.add:
- /check.sh:/check.sh
- vola:/vola
command: ["sh", "-c", "/check.sh"]
- name: poweroff
image: linuxkit/poweroff:401dc53c604c0b2179ed0369a6968fd4179cc176
command: ["/bin/sh", "/poweroff.sh", "10"]
volumes:
- name: vola
image: alpine:3.19
files:
- path: check.sh
source: ./check.sh
mode: "0700"