[CRIU] [RESEND PATCH v2 3/3] test: Add testcases for image-proxy/image-cache
Pavel Emelyanov
xemul at virtuozzo.com
Mon Aug 8 07:49:20 PDT 2016
Katerina,
As far as the tests are concerned -- the tests that would really test
this feature would look as an extension to the zdtm.py. Look at how
the --page-server option to this script works -- it makes zdtm.py start
page server in the background and dump __everything__ via it. And then
restore.
So the same should be done for cache/proxy -- zdtm.py should dump and
restore all the tests (in all the applicable ways) via cache and proxy.
-- Pavel
On 08/04/2016 02:28 PM, Katerina Koukiou wrote:
> Signed-off-by: Rodrigo Bruno <rbruno at gsd.inesc-id.pt>
> Signed-off-by: Katerina Koukiou <k.koukiou at gmail.com>
> ---
> test/proxy-cache/Makefile | 29 +++++++++++++
> test/proxy-cache/loop.sh | 8 ++++
> test/proxy-cache/run.sh | 106 ++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 143 insertions(+)
> create mode 100644 test/proxy-cache/Makefile
> create mode 100755 test/proxy-cache/loop.sh
> create mode 100755 test/proxy-cache/run.sh
>
> diff --git a/test/proxy-cache/Makefile b/test/proxy-cache/Makefile
> new file mode 100644
> index 0000000..674c493
> --- /dev/null
> +++ b/test/proxy-cache/Makefile
> @@ -0,0 +1,29 @@
> +DIR := $(shell pwd)/data
> +CRIU := $(DIR)/criu
> +
> +LOOP := $(DIR)/loop.sh
> +PIDFILE := $(DIR)/loop.pid
> +
> +DUMPDIR := $(DIR)/dump
> +PREDIR := $(DIR)/predump
> +LOG := $(DIR)/log
> +
> +PROXY_CACHE_TCP_PORT := 9997
> +LOCAL_CACHE_PATH := $(DIR)/image-cache.sock
> +LOCAL_PROXY_PATH := $(DIR)/image-proxy.sock
> +
> +export DIR LOOP PIDFILE DUMPDIR PREDIR CRIU LOG PROXY_CACHE_TCP_PORT LOCAL_CACHE_PATH LOCAL_PROXY_PATH
> +
> +run: testdir
> + ./run.sh
> +
> +testdir: ../../criu
> + mkdir -p $(DIR)
> + mkdir -p $(DUMPDIR)
> + mkdir -p $(PREDIR)
> + mkdir -p $(LOG)
> + cp ../../criu/criu $(CRIU)
> + cp loop.sh $(LOOP)
> +
> +clean:
> + rm -rf $(DIR)
> diff --git a/test/proxy-cache/loop.sh b/test/proxy-cache/loop.sh
> new file mode 100755
> index 0000000..a5fcb08
> --- /dev/null
> +++ b/test/proxy-cache/loop.sh
> @@ -0,0 +1,8 @@
> +#!/bin/bash
> +
> +echo $$ > $1.int
> +mv $1.int $1
> +
> +while :; do
> + sleep 1
> +done
> diff --git a/test/proxy-cache/run.sh b/test/proxy-cache/run.sh
> new file mode 100755
> index 0000000..4b3a66e
> --- /dev/null
> +++ b/test/proxy-cache/run.sh
> @@ -0,0 +1,106 @@
> +#!/bin/bash
> +
> +set -x
> +
> +PID=
> +CACHE_PID=
> +PROXY_PID=
> +
> +function run {
> + echo "== Run ${LOOP}"
> + echo ${PIDFILE}
> + rm -f ${PIDFILE}
> + setsid ${LOOP} ${PIDFILE} < /dev/null &> /dev/null &
> + for i in `seq 100`; do
> + test -f ${PIDFILE} && break
> + sleep 1
> + done
> + PID=`cat ${PIDFILE}`
> + echo ${PID}
> +}
> +
> +function prepare {
> + ${CRIU} image-cache -vvvv -o ${LOG}/image-cache.log \
> + --local-cache-path ${LOCAL_CACHE_PATH} \
> + --port ${PROXY_CACHE_TCP_PORT} < /dev/null &> /dev/null &
> + CACHE_PID=$!
> + sleep 1
> +
> + ${CRIU} image-proxy -vvvv -o ${LOG}/image-proxy.log \
> + --local-proxy-path ${LOCAL_PROXY_PATH} \
> + --address localhost \
> + --port ${PROXY_CACHE_TCP_PORT} < /dev/null &> /dev/null &
> + PROXY_PID=$!
> + sleep 1
> +}
> +
> +function predump {
> + test -d ${PREDIR} && rm -rf ${PREDIR}
> + mkdir -p ${PREDIR}
> + echo "== Predump ${PID}"
> + ${CRIU} pre-dump -vvvv --tree ${PID} --images-dir ${PREDIR} \
> + -o ${LOG}/predump.log \
> + --remote --local-proxy-path ${LOCAL_PROXY_PATH}
> + return $?
> +}
> +
> +function dump {
> + test -d ${DUMPDIR} && rm -rf ${DUMPDIR}
> + mkdir -p ${DUMPDIR}
> + echo "== Dump ${PID}"
> + ${CRIU} dump -vvvv --tree ${PID} --images-dir ${DUMPDIR} \
> + -o ${LOG}/dump.log --prev-images-dir ${PREDIR} --track-mem \
> + --remote --local-proxy-path ${LOCAL_PROXY_PATH}
> + return $?
> +}
> +
> +function restore {
> + echo "== Restore ${DUMPDIR}"
> + ${CRIU} restore -vvvv --images-dir ${DUMPDIR} --restore-detached \
> + -o ${LOG}/restore.log \
> + --remote --local-cache-path ${LOCAL_CACHE_PATH}
> + return $?
> +}
> +
> +function result {
> + local BGRED='\033[41m'
> + local BGGREEN='\033[42m'
> + local NORMAL=$(tput sgr0)
> +
> + if [ $1 -ne 0 ]; then
> + echo -e "${BGRED}FAIL${NORMAL}"
> + exit 1
> + else
> + echo -e "${BGGREEN}PASS${NORMAL}"
> + fi
> +}
> +
> +function test_dump_restore {
> + echo "==== Check if dump-restore works with proxy-cache"
> +
> + run
> + prepare
> + dump; result $(($?))
> + restore ; result $(($?))
> +
> + kill -SIGKILL ${PID}
> + kill -SIGKILL ${CACHE_PID}
> + kill -SIGKILL ${PROXY_PID}
> +}
> +
> +function test_predump_dump_restore {
> + echo "==== Check if predump-dump-restore works with proxy-cache"
> +
> + run
> + prepare
> + predump; result $(($?))
> + dump; result $(($?))
> + restore ; result $(($?))
> +
> + kill -SIGKILL ${PID}
> + kill -SIGKILL ${CACHE_PID}
> + kill -SIGKILL ${PROXY_PID}
> +}
> +
> +test_dump_restore
> +test_predump_dump_restore
>
More information about the CRIU
mailing list