[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH v2 1/3] tests: Introduce global mock library



On Tue, May 10, 2016 at 17:24:12 +0200, Michal Privoznik wrote:
> The intent is that this library is going to be called every time
> to check if we are not touching anything outside srcdir or
> builddir.
> 
> Signed-off-by: Michal Privoznik <mprivozn redhat com>
> ---
>  cfg.mk                |   2 +-
>  tests/Makefile.am     |  13 +++-
>  tests/testutils.c     |   9 +++
>  tests/testutils.h     |  10 +--
>  tests/vircgroupmock.c |   6 +-
>  tests/virpcimock.c    |   6 +-
>  tests/virtestmock.c   | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  7 files changed, 215 insertions(+), 11 deletions(-)
>  create mode 100644 tests/virtestmock.c

[...]

I'll have to look whether this is really necessary.

> diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c
> index cfc51e8..395254b 100644
> --- a/tests/vircgroupmock.c
> +++ b/tests/vircgroupmock.c
> @@ -416,8 +416,10 @@ static void init_syms(void)
>  
>      LOAD_SYM(fopen);
>      LOAD_SYM(access);
> -    LOAD_SYM_ALT(lstat, __lxstat);
> -    LOAD_SYM_ALT(stat, __xstat);
> +    LOAD_SYM(lstat);
> +    LOAD_SYM(__lxstat);
> +    LOAD_SYM(stat);
> +    LOAD_SYM(__xstat);
>      LOAD_SYM(mkdir);
>      LOAD_SYM(open);
>  }


LOAD_SYM_ALT is unused after this. Additionally this could be aggregated
into a single header so that every mock library doesn't have to
reimplement these helpers.

> diff --git a/tests/virpcimock.c b/tests/virpcimock.c
> index cfe42a6..ac8a665 100644
> --- a/tests/virpcimock.c
> +++ b/tests/virpcimock.c
> @@ -790,8 +790,10 @@ init_syms(void)
>      } while (0)
>  
>      LOAD_SYM(access);
> -    LOAD_SYM_ALT(lstat, __lxstat);
> -    LOAD_SYM_ALT(stat, __xstat);
> +    LOAD_SYM(lstat);
> +    LOAD_SYM(__lxstat);
> +    LOAD_SYM(stat);
> +    LOAD_SYM(__xstat);
>      LOAD_SYM(canonicalize_file_name);
>      LOAD_SYM(open);
>      LOAD_SYM(close);

Same as above in regards of LOAD_SYM_ALT.

> diff --git a/tests/virtestmock.c b/tests/virtestmock.c
> new file mode 100644
> index 0000000..f138e98
> --- /dev/null
> +++ b/tests/virtestmock.c
> @@ -0,0 +1,180 @@
> +/*
> + * Copyright (C) 2014 Red Hat, Inc.

2016?

> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library.  If not, see
> + * <http://www.gnu.org/licenses/>.
> + *
> + * Author: Michal Privoznik <mprivozn redhat com>
> + */
> +
> +#include <config.h>
> +#include <unistd.h>
> +#include <sys/types.h>
> +#include <stdio.h>
> +#include <dlfcn.h>
> +#include <sys/stat.h>
> +#include <fcntl.h>
> +
> +#include "internal.h"
> +#include "configmake.h"
> +
> +static int (*realopen)(const char *path, int flags, ...);
> +static FILE *(*realfopen)(const char *path, const char *mode);
> +static int (*realaccess)(const char *path, int mode);
> +static int (*realstat)(const char *path, struct stat *sb);
> +static int (*real__xstat)(int ver, const char *path, struct stat *sb);
> +static int (*reallstat)(const char *path, struct stat *sb);
> +static int (*real__lxstat)(int ver, const char *path, struct stat *sb);
> +
> +static void init_syms(void)
> +{
> +    if (realopen)
> +        return;
> +
> +#define LOAD_SYM(name)                                                 \
> +   do {                                                                \
> +       if (!(real ## name = dlsym(RTLD_NEXT, #name))) {                \
> +           fprintf(stderr, "Cannot find real '%s' symbol\n", #name);   \
> +           abort();                                                    \
> +       }                                                               \
> +   } while (0)
> +
> +#define LOAD_SYM_ALT(name1, name2)                                     \
> +   do {                                                                \
> +       if (!(real ## name1 = dlsym(RTLD_NEXT, #name1)) &&              \
> +           !(real ## name2 = dlsym(RTLD_NEXT, #name2))) {              \
> +           fprintf(stderr, "Cannot find real '%s' or '%s' symbol\n", #name1, #name2); \
> +           abort();                                                    \
> +       }                                                               \
> +   } while (0)

This would too benefit from not having to reimplement these.

> +
> +    LOAD_SYM(open);
> +    LOAD_SYM(fopen);
> +    LOAD_SYM(access);
> +    LOAD_SYM_ALT(stat, __xstat);
> +    LOAD_SYM_ALT(lstat, __lxstat);
> +}
> +
> +static void
> +checkPath(const char *path)
> +{
> +    if (!STRPREFIX(path, abs_topsrcdir) &&
> +        !STRPREFIX(path, abs_topbuilddir)) {
> +        /* Okay, this is a dummy check and spurious print.
> +         * But this is going to be replaced soon. */
> +        fprintf(stderr, "*** %s ***\n", path);

I'd rather do nothing at this place. Leave it empty until you implement
it in the next patch.

> +    }
> +}

ACK if you remove contents of checkPath and remove or refactor the
symbol extractors.

Peter

Attachment: signature.asc
Description: Digital signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]