[CRIU] [PATCH 5/6] RFC: zdtm: Remove run logic from makefiles

Pavel Emelyanov xemul at parallels.com
Thu Aug 7 02:09:56 PDT 2014


On 08/07/2014 02:02 AM, Christopher Covington wrote:
> While `make` is a very useful build-time tool, requiring it at
> run-time increases the complexity required of target root
> filesystems, which can in turn make testing across multiple
> architectures more difficult. Move all run-time logic into the shell
> script. As part of this transition, don't keep a list of which tests
> need which options, but figure this out by invoking the test once
> with the --help parameter before running it with the real parameters.

When developing a new test it's quite handy to check how it works by
simply running make test.pid; make test.out. How would this change
if we remove these targets from Makefiles?

> Signed-off-by: Christopher Covington <cov at codeaurora.org>
> ---
>  test/zdtm.sh                       | 21 +++++++++--
>  test/zdtm/live/static/Makefile     | 75 ++------------------------------------
>  test/zdtm/live/streaming/Makefile  | 35 +-----------------
>  test/zdtm/live/transition/Makefile | 33 +----------------
>  4 files changed, 23 insertions(+), 141 deletions(-)
> 
> diff --git a/test/zdtm.sh b/test/zdtm.sh
> index 878d70c..30ea3ec 100755
> --- a/test/zdtm.sh
> +++ b/test/zdtm.sh
> @@ -357,8 +357,6 @@ construct_root()
>  	chmod 0777 $tmpdir
>  }
>  
> -export MAKEFLAGS=--no-print-directory
> -
>  start_test()
>  {
>  	local tdir=$1
> @@ -367,7 +365,11 @@ start_test()
>  	export ZDTM_ROOT
>  
>  	killall -9 $tname > /dev/null 2>&1
> -	make -C $tdir $tname.cleanout
> +	rm -fr	$test.pid	\
> +		$test.out*	\
> +		$test.test*	\
> +		$test.*.test	\
> +		$test.state
>  
>  	unset ZDTM_UID
>  	unset ZDTM_GID
> @@ -396,7 +398,18 @@ start_test()
>  		rm -f $ZDTM_PIDFILE
>  	fi
>  
> -	if ! make -C $tdir $tname.pid; then
> +	local args=`$test --help 2>&1 | sed -nr				\
> +		-e "s%.*(--pidfile=).*%\1$test.pid%p"			\
> +		-e "s%.*(--outfile=).*%\1$test.out%p"			\
> +		-e "s%.*(--dirname=).*%\1$test.dir.test%p"		\
> +		-e "s%.*(--envname=).*%\1ENV_00_TEST%p"			\
> +		-e "s%.*(--filename=).*%\1$test.test%p"			\
> +		-e "s%.*(--mask=).*%\10345%p"				\
> +		-e "s%.*(--name_slave=).*%\1$test.slave.test%p"		\
> +		-e "s%.*(--name_master=).*%\1$test.master.test%p"	\
> +		-e "s%.*--(arg[1-3])=.*%--\1=\1%p"`
> +
> +	if ! $test $args; then
>  		echo ERROR: fail to start $test
>  		return 1
>  	fi
> diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
> index d3d42a1..3a165ca 100644
> --- a/test/zdtm/live/static/Makefile
> +++ b/test/zdtm/live/static/Makefile
> @@ -6,7 +6,7 @@ override CPPFLAGS += -I$(LIBDIR)
>  CFLAGS	= -g -O2 -Wall -Werror -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
>  CFLAGS	+= $(USERCFLAGS)
>  
> -TST_NOFILE	=				\
> +TST		=				\
>  		busyloop00			\
>  		sleeping00			\
>  		pid00				\
> @@ -113,9 +113,6 @@ TST_NOFILE	=				\
>  		clean_mntns			\
>  		dumpable01			\
>  		dumpable02			\
> -#		jobctl00			\
> -
> -TST_FILE	=				\
>  		write_read00			\
>  		write_read01			\
>  		write_read02			\
> @@ -150,8 +147,6 @@ TST_FILE	=				\
>  		file_locks01			\
>  		netns-nf			\
>  		maps_file_prot			\
> -
> -TST_DIR		=				\
>  		cwd00				\
>  		cwd01				\
>  		cwd02				\
> @@ -164,33 +159,18 @@ TST_DIR		=				\
>  		cgroup00			\
>  		rmdir_open			\
>  		cgroup01			\
> -
> -TST_DIR_FILE	=				\
>  		chroot				\
> -		chroot-file
> -
> -TST		=				\
> -		$(TST_NOFILE)			\
> -		$(TST_FILE)			\
> -		$(TST_DIR)			\
> -		$(TST_DIR_FILE)			\
> +		chroot-file			\
>  		env00				\
>  		fifo-rowo-pair			\
>  		umask00				\
>  		cmdlinenv00			\
> -
> -TST_STATE	=				\
>  		conntracks			\
>  		route_rules			\
>  
> -
>  SRC	= $(TST:%=%.c)
>  OBJ	= $(SRC:%.c=%.o)
>  DEP	= $(SRC:%.c=%.d)
> -PID	= $(TST:%=%.pid)
> -OUT	= $(TST:%=%.out)
> -STATE	= $(TST_STATE:%=%.state)
> -STATE_OUT	= $(TST_STATE:%=%.out)
>  
>  DEPEND.c = $(COMPILE.c) -MM -MP
>  %.d:	%.c
> @@ -203,55 +183,6 @@ install: all
>  inotify_system_nodel.c: inotify_system.c
>  	ln -s inotify_system.c inotify_system_nodel.c
>  
> -$(TST_NOFILE:%=%.pid):	%.pid:	%
> -	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out
> -
> -$(TST_FILE:%=%.pid):	%.pid:	%
> -	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --filename=$<.test
> -
> -$(TST_DIR:%=%.pid):	%.pid:	%
> -	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --dirname=$<.test
> -
> -$(TST_DIR_FILE:%=%.pid):	%.pid:	%
> -	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --dirname=$<.dir.test --filename=$<.test
> -
> -cmdlinenv00.pid: cmdlinenv00
> -	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --arg1=arg1 --arg2=arg2 --arg3=arg3
> -
> -env00.pid:	env00
> -	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --envname=ENV_00_TEST
> -umask00.pid:	umask00
> -	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --mask=0345
> -
> -fifo-rowo-pair.pid: fifo-rowo-pair
> -	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --name_master=$<.master.test --name_slave=$<.slave.test
> -
> -%.out:	%.pid %
> -	-kill -TERM `cat $<`
> -
> -$(TST_STATE:%=%.state):	%.state: %
> -	$(<D)/$(<F) --statefile=$@ --outfile=$<.out start
> -
> -$(TST_STATE:%=%.out): %.out: %
> -	-$(<D)/$(<F) --statefile=$<.state --outfile=$@ stop
> -
> -start:	$(PID) $(STATE)
> -
> -%.is_running:	%.pid
> -	kill -0 `cat $<`
> -
> -check_start:	$(PID:%.pid=%.is_running)
> -
> -stop:	$(STATE_OUT)
> -	-kill -TERM `cat *.pid`
> -
> -WAIT_TIME=10
> -wait_stop:
> -	-for ((i = 0; i < $(WAIT_TIME); i++)); do \
> -		kill -0 `cat *.pid 2>/dev/null` 2>/dev/null || break; \
> -		sleep 1; \
> -	done
> -
>  $(TST):	$(LIB)
>  
>  futex.o:		override CFLAGS += -pthread
> @@ -304,7 +235,7 @@ criu-rtc.pb-c.c: criu-rtc.proto
>  criu-rtc.so: criu-rtc.c criu-rtc.pb-c.c
>  	$(CC) -g -Wall -shared -nostartfiles criu-rtc.c criu-rtc.pb-c.c -o criu-rtc.so -iquote ../../../../include -fPIC $(USERCFLAGS)
>  
> -.PHONY:	force clean cleandep cleanout realclean start check_start stop wait_stop
> +.PHONY:	force clean cleandep cleanout realclean
>  
>  ifeq ($(filter-out no-deps-targets, $(MAKECMDGOALS)),)
>  -include $(DEP)
> diff --git a/test/zdtm/live/streaming/Makefile b/test/zdtm/live/streaming/Makefile
> index 1149dbe..5b4e02d 100644
> --- a/test/zdtm/live/streaming/Makefile
> +++ b/test/zdtm/live/streaming/Makefile
> @@ -6,7 +6,7 @@ override CPPFLAGS += -I$(LIBDIR)
>  CFLAGS	= -g -O2 -Wall -Werror -fno-strict-aliasing
>  CFLAGS	+= $(USERCFLAGS)
>  
> -TST_NOFILE	=	\
> +TST		=		\
>  		pipe_loop00	\
>  		pipe_shared00	\
>  		socket_loop00	\
> @@ -14,18 +14,13 @@ TST_NOFILE	=	\
>  		file_aio	\
>  		socket-tcp	\
>  		socket-tcp6	\
> -
> -TST_FILE	=	\
>  		unix_sock	\
>  		fifo_dyn	\
>  		fifo_loop	\
>  
> -TST	= $(TST_NOFILE) $(TST_FILE)
>  SRC	= $(TST:%=%.c)
>  OBJ	= $(SRC:%.c=%.o)
>  DEP	= $(SRC:%.c=%.d)
> -PID	= $(TST:%=%.pid)
> -OUT	= $(TST:%=%.out)
>  
>  DEPEND.c = $(COMPILE.c) -MM -MP
>  %.d:	%.c
> @@ -35,32 +30,6 @@ all:	$(TST)
>  install: all
>  .PHONY: all install
>  
> -$(TST_NOFILE:%=%.pid):	%.pid:	%
> -	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out
> -
> -$(TST_FILE:%=%.pid):	%.pid:	%
> -	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --filename=$<.test
> -
> -%.out:	%.pid %
> -	-kill -TERM `cat $<`
> -
> -start:	$(PID)
> -
> -%.is_running:	%.pid
> -	kill -0 `cat $<`
> -
> -check_start:	$(PID:%.pid=%.is_running)
> -
> -stop:
> -	-kill -TERM `cat *.pid`
> -
> -WAIT_TIME=10
> -wait_stop:
> -	-for ((i = 0; i < $(WAIT_TIME); i++)); do \
> -		kill -0 `cat *.pid 2>/dev/null` 2>/dev/null || break; \
> -		sleep 1; \
> -	done
> -
>  $(TST):	$(LIB)
>  
>  file_aio: override LDLIBS += -lrt -pthread
> @@ -84,7 +53,7 @@ cleanout:
>  
>  realclean:	cleandep cleanout
>  
> -.PHONY:	force clean cleandep cleanout realclean start check_start stop wait_stop
> +.PHONY:	force clean cleandep cleanout realclean
>  
>  ifeq ($(filter-out no-deps-targets, $(MAKECMDGOALS)),)
>  -include $(DEP)
> diff --git a/test/zdtm/live/transition/Makefile b/test/zdtm/live/transition/Makefile
> index 66b9589..4f01c9c 100644
> --- a/test/zdtm/live/transition/Makefile
> +++ b/test/zdtm/live/transition/Makefile
> @@ -6,7 +6,7 @@ override CPPFLAGS += -I$(LIBDIR)
>  CFLAGS	= -g -O2 -Wall -Werror
>  CFLAGS	+= $(USERCFLAGS)
>  
> -TST_NOFILE	=	\
> +TST		=	\
>  		ipc		\
>  		ptrace		\
>  		epoll		\
> @@ -14,16 +14,11 @@ TST_NOFILE	=	\
>  		fork2		\
>  		thread-bomb	\
>  		maps007		\
> -
> -TST_FILE	=	\
>  		file_read	\
>  
> -TST	= $(TST_NOFILE) $(TST_FILE)
>  SRC	= $(TST:%=%.c)
>  OBJ	= $(SRC:%.c=%.o)
>  DEP	= $(SRC:%.c=%.d)
> -PID	= $(TST:%=%.pid)
> -OUT	= $(TST:%=%.out)
>  
>  DEPEND.c = $(COMPILE.c) -MM -MP
>  %.d:	%.c
> @@ -33,32 +28,6 @@ all:	$(TST)
>  install: all
>  .PHONY: all install
>  
> -$(TST_NOFILE:%=%.pid):	%.pid:	%
> -	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out
> -
> -$(TST_FILE:%=%.pid):	%.pid:	%
> -	$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --filename=$<.test
> -
> -%.out:	%.pid %
> -	-kill -TERM `cat $<`
> -
> -start:	$(PID)
> -
> -%.is_running:	%.pid
> -	kill -0 `cat $<`
> -
> -check_start:	$(PID:%.pid=%.is_running)
> -
> -stop:
> -	-kill -TERM `cat *.pid`
> -
> -WAIT_TIME=10
> -wait_stop:
> -	-for ((i = 0; i < $(WAIT_TIME); i++)); do \
> -		kill -0 `cat *.pid 2>/dev/null` 2>/dev/null || break; \
> -		sleep 1; \
> -	done
> -
>  $(TST):	$(LIB)
>  
>  ptrace.o:	override CFLAGS += -pthread
> 



More information about the CRIU mailing list