[CRIU] Re: [PATCH 2/3] zdtm: Add pipe02 test
Andrey Wagin
avagin at gmail.com
Sun Jul 1 08:39:16 EDT 2012
What is the idea of this test? I found, that pipe01 checks that all
data are restored.
A few comments inline.
2012/6/27 Cyrill Gorcunov <gorcunov at openvz.org>:
> To test pipe reception via SCM.
>
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
> test/zdtm.sh | 1 +
> test/zdtm/live/static/Makefile | 1 +
> test/zdtm/live/static/pipe02.c | 68 ++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 70 insertions(+), 0 deletions(-)
> create mode 100644 test/zdtm/live/static/pipe02.c
>
> diff --git a/test/zdtm.sh b/test/zdtm.sh
> index f730c96..2b74b41 100644
> --- a/test/zdtm.sh
> +++ b/test/zdtm.sh
> @@ -5,6 +5,7 @@ ZP="zdtm/live"
> TEST_LIST="
> static/pipe00
> static/pipe01
> +static/pipe02
> static/busyloop00
> static/cwd00
> static/env00
> diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
> index 6059bb9..8a002c3 100644
> --- a/test/zdtm/live/static/Makefile
> +++ b/test/zdtm/live/static/Makefile
> @@ -30,6 +30,7 @@ TST_NOFILE = \
> ptrace_sig \
> pipe00 \
> pipe01 \
> + pipe02 \
> pthread00 \
> vdso00 \
> utsname \
> diff --git a/test/zdtm/live/static/pipe02.c b/test/zdtm/live/static/pipe02.c
> new file mode 100644
> index 0000000..ac29cec
> --- /dev/null
> +++ b/test/zdtm/live/static/pipe02.c
> @@ -0,0 +1,68 @@
> +#include <unistd.h>
> +#include <stdlib.h>
> +#include <signal.h>
> +#include <string.h>
> +#include <sys/wait.h>
> +
> +#include "zdtmtst.h"
> +
> +const char *test_doc = "Pipes with slave creation";
> +const char *test_author = "Cyrill Gorcunov <gorcunov at openvz.org>";
> +
> +#define TEST_STRING "Test message"
> +
> +int main(int argc, char ** argv)
> +{
> + char buf[sizeof(TEST_STRING)];
> + task_waiter_t t;
> + int pipes[2];
> + int status;
> + pid_t pid;
> + int ret;
> +
> + test_init(argc, argv);
> + task_waiter_init(&t);
> +
> + ret = pipe(pipes);
> + if (ret) {
> + err("Can't create pipe");
> + exit(1);
> + }
> +
> + pid = test_fork();
> + if (pid == 0) {
> + task_waiter_wait4(&t, getppid());
> +
> + ret = read(pipes[0], buf, sizeof(buf));
> + if (ret != sizeof(buf) || strcmp(buf, TEST_STRING)) {
> + err("read failed: %d", ret);
> + exit(1);
> + }
> +
> + exit(0);
> + } else if (pid < 0) {
> + err("Can't fork");
> + exit(1);
> + }
> +
> + ret = write(pipes[1], TEST_STRING, sizeof(TEST_STRING));
> + if (ret != sizeof(TEST_STRING)) {
> + err("write failed: %d", ret);
don't forget to kill a child
> + exit(1);
> + }
> +
> + test_daemon();
> + test_waitsig();
> +
> + task_waiter_complete_current(&t);
> +
> + waitpid(pid, &status, P_ALL);
> + errno = (status >> 8) & 0x7f;
use macroses WEXITSTATUS and WIFEXITED
> + if (errno) {
> + fail("Child exited with error %m");
> + exit(errno);
> + }
> +
> + pass();
> + return 0;
> +}
> --
> 1.7.7.6
>
More information about the CRIU
mailing list