[libgpiod,v4] install-tests to bindir test

Message ID 20190311222007.15311-1-anders.roxell@linaro.org
State New
Headers show
Series
  • [libgpiod,v4] install-tests to bindir test
Related show

Commit Message

Anders Roxell March 11, 2019, 10:20 p.m.
When building the tests it assumes that the build artifacts is located
in the srcdir.
Rework so we install tests into the bindir, if that is done we look for
the binaries in bin dir and not in the src dir.

Signed-off-by: Anders Roxell <anders.roxell@linaro.org>

---

changes since v3:

If you don't enable install-tests you can now run the ./tests/gpiod-test
which you couldn't before.

 configure.ac       |  7 +++++++
 libgpiod.pc.in     |  1 +
 tests/Makefile.am  |  9 +++++++++
 tests/gpiod-test.c | 10 +++++-----
 4 files changed, 22 insertions(+), 5 deletions(-)

-- 
2.20.1

Comments

Bartosz Golaszewski March 12, 2019, 11:02 a.m. | #1
pon., 11 mar 2019 o 23:20 Anders Roxell <anders.roxell@linaro.org> napisaƂ(a):
>

> When building the tests it assumes that the build artifacts is located

> in the srcdir.

> Rework so we install tests into the bindir, if that is done we look for

> the binaries in bin dir and not in the src dir.

>

> Signed-off-by: Anders Roxell <anders.roxell@linaro.org>

> ---

>

> changes since v3:

>

> If you don't enable install-tests you can now run the ./tests/gpiod-test

> which you couldn't before.

>

>  configure.ac       |  7 +++++++

>  libgpiod.pc.in     |  1 +

>  tests/Makefile.am  |  9 +++++++++

>  tests/gpiod-test.c | 10 +++++-----

>  4 files changed, 22 insertions(+), 5 deletions(-)

>

> diff --git a/configure.ac b/configure.ac

> index 1253cb14749c..6455af5331e0 100644

> --- a/configure.ac

> +++ b/configure.ac

> @@ -107,6 +107,13 @@ then

>         AC_CHECK_HEADERS([sys/signalfd.h], [], [HEADER_NOT_FOUND_TOOLS([sys/signalfd.h])])

>  fi

>

> +AC_ARG_ENABLE([install-tests],

> +       [AC_HELP_STRING([--enable-install-tests],

> +               [enable install tests [default=no]])],

> +       [if test "x$enableval" = xyes; then with_install_tests=true; with_tests=true; fi;],

> +       [with_install_tests=false])

> +AM_CONDITIONAL([WITH_INSTALL_TESTS], [test "x$with_install_tests" = xtrue])

> +

>  AC_ARG_ENABLE([tests],

>         [AC_HELP_STRING([--enable-tests],

>                 [enable libgpiod tests [default=no]])],

> diff --git a/libgpiod.pc.in b/libgpiod.pc.in

> index 48ff11392ae4..96d1111324e5 100644

> --- a/libgpiod.pc.in

> +++ b/libgpiod.pc.in

> @@ -1,5 +1,6 @@

>  prefix=@prefix@

>  exec_prefix=@exec_prefix@

> +bindir=@bindir@

>  libdir=@libdir@

>  includedir=@includedir@

>

> diff --git a/tests/Makefile.am b/tests/Makefile.am

> index a9319a725f0d..80631b4f528d 100644

> --- a/tests/Makefile.am

> +++ b/tests/Makefile.am

> @@ -13,6 +13,15 @@ LDADD = ../src/lib/libgpiod.la $(KMOD_LIBS) $(UDEV_LIBS)

>

>  check_PROGRAMS = gpiod-test

>

> +if WITH_INSTALL_TESTS

> +bin_PROGRAMS = $(check_PROGRAMS)

> +GPIOD_TOOLS_PATH=@prefix@/bin

> +else

> +noinst_PROGRAMS = $(check_PROGRAMS)

> +GPIOD_TOOLS_PATH="$(abs_top_builddir)/src/tools"

> +endif

> +AM_CFLAGS += -DGPIOD_TOOLS_PATH=$(GPIOD_TOOLS_PATH)/

> +

>  gpiod_test_SOURCES =   gpiod-test.c \

>                         gpiod-test.h \

>                         tests-chip.c \

> diff --git a/tests/gpiod-test.c b/tests/gpiod-test.c

> index c67314332e41..2ed229e61b45 100644

> --- a/tests/gpiod-test.c

> +++ b/tests/gpiod-test.c

> @@ -30,6 +30,9 @@

>  #define NORETURN       __attribute__((noreturn))

>  #define MALLOC         __attribute__((malloc))

>

> +#define xstr(s) str(s)

> +#define str(s) #s

> +

>  static const unsigned int min_kern_major = 4;

>  static const unsigned int min_kern_minor = 16;

>  static const unsigned int min_kern_release = 0;

> @@ -449,12 +452,9 @@ static void gpiotool_proc_dup_fds(int in_fd, int out_fd, int err_fd)

>

>  static char *gpiotool_proc_get_path(const char *tool)

>  {

> -       char *path, *progpath, *progdir;

> +       char *path;

>

> -       progpath = xstrdup(program_invocation_name);

> -       progdir = dirname(progpath);

> -       path = xappend(NULL, "%s/../../src/tools/%s", progdir, tool);

> -       free(progpath);

> +       path = xappend(NULL, "%s%s", xstr(GPIOD_TOOLS_PATH), tool);

>


Hi Anders,

the problem with this is that it still breaks the current behavior if
we specify --enable-install-tests AND if we don't in which case we
won't be able to run tests from any location. I have an idea for this
- I'll send a patch today or tomorrow.

Bart

>         return path;

>  }

> --

> 2.20.1

>

Patch

diff --git a/configure.ac b/configure.ac
index 1253cb14749c..6455af5331e0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -107,6 +107,13 @@  then
 	AC_CHECK_HEADERS([sys/signalfd.h], [], [HEADER_NOT_FOUND_TOOLS([sys/signalfd.h])])
 fi
 
+AC_ARG_ENABLE([install-tests],
+	[AC_HELP_STRING([--enable-install-tests],
+		[enable install tests [default=no]])],
+	[if test "x$enableval" = xyes; then with_install_tests=true; with_tests=true; fi;],
+	[with_install_tests=false])
+AM_CONDITIONAL([WITH_INSTALL_TESTS], [test "x$with_install_tests" = xtrue])
+
 AC_ARG_ENABLE([tests],
 	[AC_HELP_STRING([--enable-tests],
 		[enable libgpiod tests [default=no]])],
diff --git a/libgpiod.pc.in b/libgpiod.pc.in
index 48ff11392ae4..96d1111324e5 100644
--- a/libgpiod.pc.in
+++ b/libgpiod.pc.in
@@ -1,5 +1,6 @@ 
 prefix=@prefix@
 exec_prefix=@exec_prefix@
+bindir=@bindir@
 libdir=@libdir@
 includedir=@includedir@
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a9319a725f0d..80631b4f528d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -13,6 +13,15 @@  LDADD = ../src/lib/libgpiod.la $(KMOD_LIBS) $(UDEV_LIBS)
 
 check_PROGRAMS = gpiod-test
 
+if WITH_INSTALL_TESTS
+bin_PROGRAMS = $(check_PROGRAMS)
+GPIOD_TOOLS_PATH=@prefix@/bin
+else
+noinst_PROGRAMS = $(check_PROGRAMS)
+GPIOD_TOOLS_PATH="$(abs_top_builddir)/src/tools"
+endif
+AM_CFLAGS += -DGPIOD_TOOLS_PATH=$(GPIOD_TOOLS_PATH)/
+
 gpiod_test_SOURCES =	gpiod-test.c \
 			gpiod-test.h \
 			tests-chip.c \
diff --git a/tests/gpiod-test.c b/tests/gpiod-test.c
index c67314332e41..2ed229e61b45 100644
--- a/tests/gpiod-test.c
+++ b/tests/gpiod-test.c
@@ -30,6 +30,9 @@ 
 #define NORETURN	__attribute__((noreturn))
 #define MALLOC		__attribute__((malloc))
 
+#define xstr(s) str(s)
+#define str(s) #s
+
 static const unsigned int min_kern_major = 4;
 static const unsigned int min_kern_minor = 16;
 static const unsigned int min_kern_release = 0;
@@ -449,12 +452,9 @@  static void gpiotool_proc_dup_fds(int in_fd, int out_fd, int err_fd)
 
 static char *gpiotool_proc_get_path(const char *tool)
 {
-	char *path, *progpath, *progdir;
+	char *path;
 
-	progpath = xstrdup(program_invocation_name);
-	progdir = dirname(progpath);
-	path = xappend(NULL, "%s/../../src/tools/%s", progdir, tool);
-	free(progpath);
+	path = xappend(NULL, "%s%s", xstr(GPIOD_TOOLS_PATH), tool);
 
 	return path;
 }