[PATCH 2/8] tests: use *BSD replacement for /proc

Pekka Paalanen ppaalanen at gmail.com
Fri Feb 8 14:03:05 UTC 2019


On Fri,  8 Feb 2019 15:13:35 +0200
Leonid Bobrov <mazocomp at disroot.org> wrote:

> Signed-off-by: Leonid Bobrov <mazocomp at disroot.org>
> ---
>  Makefile.am          |  2 +-
>  configure.ac         | 12 ++++++++++++
>  tests/test-helpers.c | 33 ++++++++++++++++++++++++++++++++-
>  3 files changed, 45 insertions(+), 2 deletions(-)
> 
> diff --git a/Makefile.am b/Makefile.am
> index cce4d73..52c7895 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -215,7 +215,7 @@ noinst_LTLIBRARIES +=				\
>  	libtest-helpers.la
>  
>  libtest_helpers_la_SOURCES = tests/test-helpers.c
> -libtest_helpers_la_LIBADD = -lrt -ldl $(FFI_LIBS)
> +libtest_helpers_la_LIBADD = -lrt -ldl $(FFI_LIBS) $(KVM_LIBS)
>  
>  libtest_runner_la_SOURCES =			\
>  	tests/test-runner.c			\
> diff --git a/configure.ac b/configure.ac
> index 18fb649..912330e 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -65,6 +65,18 @@ AC_SUBST(GCC_CFLAGS)
>  AC_CHECK_HEADERS([sys/prctl.h])
>  AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl])
>  
> +# Replacement for /proc on BSD
> +AC_CHECK_HEADERS([kvm.h])
> +SAVE_LIBS="$LIBS"
> +LIBS=
> +AC_CHECK_LIB([kvm], [kvm_getfiles])
> +KVM_LIBS="$LIBS"
> +LIBS="$SAVE_LIBS"
> +AC_SUBST(KVM_LIBS)
> +if test "x$ac_cv_header_kvm_h" != "x" && test "x$ac_cv_lib_kvm_kvm_getfiles" != "x"; then
> +	AC_DEFINE(USE_LIBKVM, 1, [use libkvm on BSD])
> +fi

Hi Leonid,

My autoconf is getting rusty, but this looks ok to me.

> +
>  AC_ARG_ENABLE([libraries],
>  	      [AC_HELP_STRING([--disable-libraries],
>  			      [Disable compilation of wayland libraries])],
> diff --git a/tests/test-helpers.c b/tests/test-helpers.c
> index b2189d8..1c83e00 100644
> --- a/tests/test-helpers.c
> +++ b/tests/test-helpers.c
> @@ -25,9 +25,20 @@
>  
>  #include "config.h"
>  
> -#include <assert.h>
> +#include "../config.h"

Why is this adding a second config.h include?

> +
> +#ifdef USE_LIBKVM
> +#include <sys/types.h>
> +#include <sys/sysctl.h>
> +#include <fcntl.h>
> +#include <kvm.h>
> +#include <limits.h>
> +#else
>  #include <errno.h>
>  #include <dirent.h>
> +#endif
> +
> +#include <assert.h>
>  #include <stdio.h>
>  #include <unistd.h>
>  #include <time.h>
> @@ -43,6 +54,25 @@
>  int
>  count_open_fds(void)
>  {
> +#ifdef USE_LIBKVM
> +	/* Use BSD-specific kernel memory interface */
> +
> +	struct kinfo_file *kif;
> +	kvm_t *kd;
> +	int count;
> +	char errstr[_POSIX2_LINE_MAX];
> +
> +	kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY|KVM_NO_FILES, errstr);
> +	assert(kd != NULL);
> +	kif = kvm_getfiles(kd, KERN_FILE_BYPID, getpid(), sizeof(struct kinfo_file), &count);
> +	assert(kif != NULL);
> +
> +	/* KVM library frees memory on itself */
> +	kvm_close(kd);
> +	return count;
> +#else
> +	/* Use /proc filesystem. */
> +
>  	DIR *dir;
>  	struct dirent *ent;
>  	int count = 0;
> @@ -62,6 +92,7 @@ count_open_fds(void)
>  	closedir(dir);
>  
>  	return count;
> +#endif
>  }
>  
>  void

I suppose this patch is fine. It's such a small chunk and there does
not seem to be anything else to special-case that would warrant a
new .c file or anything.

At the moment I do think this one needs to wait to see the CI support
materialize.


Thanks,
pq
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/wayland-devel/attachments/20190208/a366e1be/attachment-0001.sig>


More information about the wayland-devel mailing list