[CRIU] [PATCH 8/8] test: zdtm -- Add test for alternative signal stack

Andrew Vagin avagin at parallels.com
Tue Jun 18 06:51:00 EDT 2013


Could you add one more process which will sleep in a signal handler which
is executed on alt stack?

On Tue, Jun 18, 2013 at 10:06:58AM +0400, Cyrill Gorcunov wrote:
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  test/zdtm.sh                        |   1 +
>  test/zdtm/live/static/Makefile      |   2 +
>  test/zdtm/live/static/sigaltstack.c | 118 ++++++++++++++++++++++++++++++++++++
>  3 files changed, 121 insertions(+)
>  create mode 100644 test/zdtm/live/static/sigaltstack.c
> 

> diff --git a/test/zdtm.sh b/test/zdtm.sh
> index fd807e9..2d821fd 100755
> --- a/test/zdtm.sh
> +++ b/test/zdtm.sh
> @@ -86,6 +86,7 @@ static/fdt_shared
>  static/file_locks00
>  static/file_locks01
>  static/sigpending
> +static/sigaltstack
>  static/sk-netlink
>  static/proc-self
>  "
> diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
> index 0432030..e4b5e25 100644
> --- a/test/zdtm/live/static/Makefile
> +++ b/test/zdtm/live/static/Makefile
> @@ -94,6 +94,7 @@ TST_NOFILE	=				\
>  		child_opened_proc		\
>  		posix_timers			\
>  		sigpending			\
> +		sigaltstack			\
>  		sk-netlink			\
>  		mem-touch			\
>  #		jobctl00			\
> @@ -228,6 +229,7 @@ inotify_system_nodel:	override CFLAGS += -DNODEL
>  pthread00:		override LDLIBS += -pthread
>  pthread01:		override LDLIBS += -pthread
>  sigpending:		override LDLIBS += -pthread
> +sigaltstack:		override LDLIBS += -pthread
>  shm:			override CFLAGS += -DNEW_IPC_NS
>  msgque:			override CFLAGS += -DNEW_IPC_NS
>  sem:			override CFLAGS += -DNEW_IPC_NS
> diff --git a/test/zdtm/live/static/sigaltstack.c b/test/zdtm/live/static/sigaltstack.c
> new file mode 100644
> index 0000000..a23b510
> --- /dev/null
> +++ b/test/zdtm/live/static/sigaltstack.c
> @@ -0,0 +1,118 @@
> +#define _GNU_SOURCE
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <signal.h>
> +#include <unistd.h>
> +#include <string.h>
> +#include <pthread.h>
> +#include <syscall.h>
> +
> +#include <sys/types.h>
> +#include <sys/wait.h>
> +
> +#include "zdtmtst.h"
> +
> +const char *test_doc	= "Check for alternate signal stack";
> +const char *test_author	= "Cyrill Gorcunov <gorcunov at openvz.org>";
> +
> +static char stack_thread[SIGSTKSZ];
> +static char stack_main[SIGSTKSZ];
> +static stack_t sas_state[4];

I whould prefer to have a comment here, which describe each element of
sas_state.

> +
> +static task_waiter_t t;
> +
> +#define exit_group(code) syscall(__NR_exit_group, code)
> +
> +static int sascmp(stack_t *old, stack_t *new)
> +{
> +	return old->ss_size != new->ss_size	||
> +		old->ss_sp != new->ss_sp	||
> +		old->ss_flags != new->ss_flags;
> +}
> +
> +static void show_ss(char *prefix, stack_t *s)
> +{
> +	test_msg("%10s: at %p (size %#8x flags %#2x)\n",
> +		 prefix, s->ss_sp, s->ss_size, s->ss_flags);
> +}
> +
> +static void *thread_func(void *arg)
> +{
> +	sas_state[2] = (stack_t) {
> +		.ss_size	= SIGSTKSZ,
> +		.ss_sp		= stack_thread,
> +	};
> +
> +	task_waiter_wait4(&t, 1);
> +
> +	if (sigaltstack(&sas_state[2], NULL)) {
> +		err("thread sigaltstack");
> +		exit_group(-1);
> +	}
> +
> +	task_waiter_complete(&t, 2);
> +	task_waiter_wait4(&t, 3);
> +
> +	if (sigaltstack(NULL, &sas_state[3])) {
> +		err("thread sigaltstack");
> +		exit_group(-2);
> +	}
> +
> +	return NULL;
> +}
> +
> +int main(int argc, char *argv[])
> +{
> +	pthread_t thread;
> +
> +	sas_state[0] = (stack_t) {
> +		.ss_size	= SIGSTKSZ,
> +		.ss_sp		= stack_main,
> +	};
> +
> +	test_init(argc, argv);
> +	task_waiter_init(&t);
> +
> +	if (pthread_create(&thread, NULL, &thread_func, NULL)) {
> +		err("Can't create thread");
> +		exit(-1);
> +	}
> +
> +	if (sigaltstack(&sas_state[0], NULL)) {
> +		err("sigaltstack");
> +		exit(-1);

Should we use exit_group here?

> +	}
> +
> +	task_waiter_complete(&t, 1);
> +	task_waiter_wait4(&t, 2);
> +
> +	test_daemon();
> +	test_waitsig();
> +
> +	task_waiter_complete(&t, 3);
> +
> +	if (pthread_join(thread, NULL)) {
> +		fail("Error joining thread");
> +		exit(-1);
> +	}
> +	task_waiter_fini(&t);
> +
> +	if (sigaltstack(NULL, &sas_state[1])) {
> +		err("sigaltstack");
> +		exit(-1);
> +	}
> +
> +	show_ss("main old", &sas_state[0]);
> +	show_ss("main new", &sas_state[1]);
> +	show_ss("thrd old", &sas_state[2]);
> +	show_ss("thrd new", &sas_state[3]);
> +
> +	if (sascmp(&sas_state[0], &sas_state[1]) ||
> +	    sascmp(&sas_state[0], &sas_state[1])) {

	    sascmp(&sas_state[2], &sas_state[3])){

> +		fail("sas not restored");
> +	} else
> +		pass();
> +
> +	return 0;
> +}



More information about the CRIU mailing list