[CRIU] [PATCH 7/8] zdtm: Add test for cwd ghost directory

Filipe Brandenburger filbranden at google.com
Thu Jul 3 08:29:28 PDT 2014


Please remember to also add it to .gitignore in the zdtm tree.

Thanks!
Filipe


On Thu, Jul 3, 2014 at 8:08 AM, Pavel Emelyanov <xemul at parallels.com> wrote:
> Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
> ---
>  test/zdtm.sh                   |  1 +
>  test/zdtm/live/static/Makefile |  1 +
>  test/zdtm/live/static/cwd01.c  | 85 ++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 87 insertions(+)
>  create mode 100644 test/zdtm/live/static/cwd01.c
>
> diff --git a/test/zdtm.sh b/test/zdtm.sh
> index 2fa4bcf..3603519 100755
> --- a/test/zdtm.sh
> +++ b/test/zdtm.sh
> @@ -17,6 +17,7 @@ static/pipe01
>  static/pipe02
>  static/busyloop00
>  static/cwd00
> +static/cwd01
>  static/env00
>  static/maps00
>  static/maps01
> diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
> index 387fbf5..d4aeec2 100644
> --- a/test/zdtm/live/static/Makefile
> +++ b/test/zdtm/live/static/Makefile
> @@ -153,6 +153,7 @@ TST_FILE    =                               \
>
>  TST_DIR                =                               \
>                 cwd00                           \
> +               cwd01                           \
>                 overmount_dev                   \
>                 overmount_file                  \
>                 overmount_fifo                  \
> diff --git a/test/zdtm/live/static/cwd01.c b/test/zdtm/live/static/cwd01.c
> new file mode 100644
> index 0000000..0cbed6e
> --- /dev/null
> +++ b/test/zdtm/live/static/cwd01.c
> @@ -0,0 +1,85 @@
> +#include <errno.h>
> +#include <unistd.h>
> +#include <stdlib.h>
> +#include <sys/stat.h>
> +#include <string.h>
> +#include <sys/wait.h>
> +
> +#include "zdtmtst.h"
> +
> +const char *test_doc   = "Check that removed cwd works";
> +const char *test_author        = "Pavel Emelianov <xemul at parallels.com>";
> +
> +char *dirname;
> +TEST_OPTION(dirname, string, "directory name", 1);
> +
> +int main(int argc, char **argv)
> +{
> +       char cwd0[256], cwd1[256], cwd2[256];
> +       int pid, p[2], aux;
> +
> +       test_init(argc, argv);
> +
> +       pipe(p);
> +       pid = fork();
> +       if (pid == 0) {
> +               close(p[1]);
> +               read(p[0], &aux, sizeof(aux));
> +               aux = rmdir(dirname);
> +               exit(aux ? 1 : 0);
> +       }
> +
> +       if (!getcwd(cwd0, sizeof(cwd0))) {
> +               err("can't get cwd: %m\n");
> +               exit(1);
> +       }
> +
> +       if (mkdir(dirname, 0700)) {
> +               err("can't make directory %s: %m\n", dirname);
> +               exit(1);
> +       }
> +
> +       if (chdir(dirname)) {
> +               err("can't change directory to %s: %m\n", dirname);
> +               goto cleanup;
> +       }
> +
> +       close(p[1]);
> +       close(p[0]);
> +       waitpid(pid, &aux, 0);
> +       if (!WIFEXITED(aux) || WEXITSTATUS(aux) != 0) {
> +               err("can't remove dir\n");
> +               goto cleanup;
> +       }
> +
> +       aux = readlink("/proc/self/cwd", cwd1, sizeof(cwd1));
> +       if (aux < 0) {
> +               err("can't get cwd: %m\n");
> +               goto cleanup;
> +       }
> +
> +       cwd1[aux] = '\0';
> +
> +       test_daemon();
> +       test_waitsig();
> +
> +       if (readlink("/proc/self/cwd", cwd2, sizeof(cwd2)) < 0) {
> +               fail("can't get cwd: %m\n");
> +               goto cleanup;
> +       }
> +
> +       /* FIXME -- criu adds a suffix to removed cwd */
> +       if (strncmp(cwd1, cwd2, aux))
> +               fail("%s != %s\n", cwd1, cwd2);
> +       else
> +               pass();
> +cleanup:
> +       /* return to the initial dir before writing out results */
> +       if (chdir(cwd0)) {
> +               err("can't change directory to %s: %m\n", cwd0);
> +               exit(1);
> +       }
> +
> +       rmdir(dirname);
> +       return 0;
> +}
> --
> 1.8.3.1
>
>
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu


More information about the CRIU mailing list