Bug 37849 - test-autolaunch assumes dbus-launch is already installed
Summary: test-autolaunch assumes dbus-launch is already installed
Status: RESOLVED FIXED
Alias: None
Product: dbus
Classification: Unclassified
Component: core (show other bugs)
Version: unspecified
Hardware: Other All
: low minor
Assignee: Havoc Pennington
QA Contact: John (J5) Palmieri
URL:
Whiteboard: review-, needs rebase
Keywords: patch
Depends on:
Blocks:
 
Reported: 2011-06-02 04:06 UTC by Simon McVittie
Modified: 2013-10-08 15:18 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments
[PATCH 1/2] Use test binaries in build dir to do test (3.98 KB, patch)
2013-09-13 09:14 UTC, Chengwei Yang
Details | Splinter Review
[PATCH 2/2] Unify the way to find dbus-daemon test binary (2.04 KB, patch)
2013-09-13 09:15 UTC, Chengwei Yang
Details | Splinter Review
[PATCH v2] Unify the way to find dbus-daemon test binary (4.77 KB, patch)
2013-09-14 02:25 UTC, Chengwei Yang
Details | Splinter Review
dbus-launch: avoid asprintf(), and die gracefully on out-of-memory (1.74 KB, patch)
2013-09-16 12:46 UTC, Simon McVittie
Details | Splinter Review
When using dbus-launch for tests, fail hard if test binary is missing (1.01 KB, patch)
2013-09-16 12:51 UTC, Simon McVittie
Details | Splinter Review
[PATCH v3] Unify the way to find dbus-daemon test binary (4.86 KB, patch)
2013-10-08 14:01 UTC, Chengwei Yang
Details | Splinter Review

Description Simon McVittie 2011-06-02 04:06:39 UTC
When performing X11 autolaunch, libdbus tries to run ${prefix}/bin/dbus-launch, then searches for dbus-launch in $PATH. While running the regression tests, we haven't installed ${prefix}/bin/dbus-launch, so we end up testing the installed dbus-launch (if there is one), or failing (which is what happens in a minimal chroot environment).

When DBUS_BUILD_TESTS is defined (or perhaps even when it isn't - this isn't a fast path), there should be an environment-variable-based override, perhaps via ${DBUS_LAUNCH}. The tests should use it, to test the not-yet-installed dbus-launch binary.
Comment 1 Chengwei Yang 2013-09-13 06:48:07 UTC
(In reply to comment #0)
> When performing X11 autolaunch, libdbus tries to run
> ${prefix}/bin/dbus-launch, then searches for dbus-launch in $PATH. While
> running the regression tests, we haven't installed
> ${prefix}/bin/dbus-launch, so we end up testing the installed dbus-launch
> (if there is one), or failing (which is what happens in a minimal chroot
> environment).
> 
> When DBUS_BUILD_TESTS is defined (or perhaps even when it isn't - this isn't
> a fast path), there should be an environment-variable-based override,
> perhaps via ${DBUS_LAUNCH}. The tests should use it, to test the
> not-yet-installed dbus-launch binary.

I'd like to create a patch to fix this issue, so far as I know, there is DBUS_USE_TEST_BINARY checked by dbus-launch to see which dbus-daemon to be used. I just want to reuse this environment, if it's set, use dbus-launch in build tree rather than installed path or fall back to $PATH.
Comment 2 Chengwei Yang 2013-09-13 09:14:59 UTC
Created attachment 85755 [details] [review]
[PATCH 1/2] Use test binaries in build dir to do test
Comment 3 Chengwei Yang 2013-09-13 09:15:32 UTC
Created attachment 85756 [details] [review]
[PATCH 2/2] Unify the way to find dbus-daemon test binary
Comment 4 Simon McVittie 2013-09-13 13:30:57 UTC
Comment on attachment 85755 [details] [review]
[PATCH 1/2] Use test binaries in build dir to do test

Review of attachment 85755 [details] [review]:
-----------------------------------------------------------------

Nice. I'll apply it
Comment 5 Simon McVittie 2013-09-13 13:35:06 UTC
Comment on attachment 85756 [details] [review]
[PATCH 2/2] Unify the way to find dbus-daemon test binary

Review of attachment 85756 [details] [review]:
-----------------------------------------------------------------

I'd prefer this unified in the other direction, if anything.

::: test/dbus-daemon.c
@@ +226,2 @@
>  
>    if (dbus_daemon == NULL)

This breaks the ability to run this as an OSTree-style installed test: TEST_BUS_BINARY will always be non-NULL so it'll be used unconditionally.
Comment 6 Simon McVittie 2013-09-13 13:36:29 UTC
(In reply to comment #5)
> ::: test/dbus-daemon.c
> @@ +226,2 @@
> >  
> >    if (dbus_daemon == NULL)
> 
> This breaks the ability to run this as an OSTree-style installed test:
> TEST_BUS_BINARY will always be non-NULL so it'll be used unconditionally.

Ugh, splinter threw away the context that I wanted to point to, which was something like this:

   dbus_daemon = g_strdup (TEST_BUS_BINARY);

   if (dbus_daemon == NULL)
     dbus_daemon = g_strdup ("dbus-daemon" EXEEXT);
Comment 7 Chengwei Yang 2013-09-13 14:17:16 UTC
(In reply to comment #5)
> Comment on attachment 85756 [details] [review] [review]
> [PATCH 2/2] Unify the way to find dbus-daemon test binary
> 
> Review of attachment 85756 [details] [review] [review]:
> -----------------------------------------------------------------
> 
> I'd prefer this unified in the other direction, if anything.
> 
> ::: test/dbus-daemon.c
> @@ +226,2 @@
> >  
> >    if (dbus_daemon == NULL)
> 
> This breaks the ability to run this as an OSTree-style installed test:
> TEST_BUS_BINARY will always be non-NULL so it'll be used unconditionally.

Hmm, since I found that another place uses DBUS_TEST_DAEMON is in installcheck_environment, however the installcheck_tests is empty so far.

Anyway, it's better to unify in the other direction to not break the ready code for OSTree-style installed test. I'll upload a new one.
Comment 8 Chengwei Yang 2013-09-14 02:25:20 UTC
Created attachment 85804 [details] [review]
[PATCH v2] Unify the way to find dbus-daemon test binary
Comment 9 Simon McVittie 2013-09-16 12:30:50 UTC
Comment on attachment 85804 [details] [review]
[PATCH v2] Unify the way to find dbus-daemon test binary

Review of attachment 85804 [details] [review]:
-----------------------------------------------------------------

::: test/name-test/Makefile.am
@@ +18,4 @@
>          DBUS_TOP_SRCDIR=@abs_top_srcdir@ \
>          PYTHON=@PYTHON@ \
>          DBUS_TEST_DATA=@abs_top_builddir@/test/data \
> +        DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT) \

How does this information get to the tests under CMake? (Does it?)

::: tools/dbus-launch.c
@@ -1114,5 @@
> -        {
> -          if (config_file == NULL && getenv ("DBUS_TEST_DATA") != NULL)
> -            {
> -              ret = asprintf (&config_file, "%s/valid-config-files/session.conf",
> -                        getenv ("DBUS_TEST_DATA"));

I just noticed I merged this with an asprintf(), which isn't portable. :-(

I'll have to add a concatenate function or something.

@@ -1117,5 @@
> -              ret = asprintf (&config_file, "%s/valid-config-files/session.conf",
> -                        getenv ("DBUS_TEST_DATA"));
> -            }
> -            if (ret == -1 && config_file != NULL)
> -              free (config_file);

I shouldn't have merged with this either: if we run out of memory, we shouldn't just carry on and see what happens, we should stop with an error.

@@ -1130,5 @@
> -                 NULL); 
> -
> -          fprintf (stderr,
> -                   "Failed to execute test message bus daemon %s: %s. Will try again with the system path.\n",
> -                   TEST_BUS_BINARY, strerror (errno));

This was pre-existing, but I think it's wrong too.
Comment 10 Chengwei Yang 2013-09-16 12:37:32 UTC
(In reply to comment #9)
> Comment on attachment 85804 [details] [review] [review]
> [PATCH v2] Unify the way to find dbus-daemon test binary
> 
> Review of attachment 85804 [details] [review] [review]:
> -----------------------------------------------------------------
> 
> ::: test/name-test/Makefile.am
> @@ +18,4 @@
> >          DBUS_TOP_SRCDIR=@abs_top_srcdir@ \
> >          PYTHON=@PYTHON@ \
> >          DBUS_TEST_DATA=@abs_top_builddir@/test/data \
> > +        DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT) \
> 
> How does this information get to the tests under CMake? (Does it?)

This test doesn't work in cmake at all. I think there are still more, will fill up the gap later.

> 
> ::: tools/dbus-launch.c
> @@ -1114,5 @@
> > -        {
> > -          if (config_file == NULL && getenv ("DBUS_TEST_DATA") != NULL)
> > -            {
> > -              ret = asprintf (&config_file, "%s/valid-config-files/session.conf",
> > -                        getenv ("DBUS_TEST_DATA"));
> 
> I just noticed I merged this with an asprintf(), which isn't portable. :-(

Hmm, sorry.

> 
> I'll have to add a concatenate function or something.
> 
> @@ -1117,5 @@
> > -              ret = asprintf (&config_file, "%s/valid-config-files/session.conf",
> > -                        getenv ("DBUS_TEST_DATA"));
> > -            }
> > -            if (ret == -1 && config_file != NULL)
> > -              free (config_file);
> 
> I shouldn't have merged with this either: if we run out of memory, we
> shouldn't just carry on and see what happens, we should stop with an error.

From the asprintf(3), it's may not a OOM error.

"If memory allocation wasn't possible, or some other error occurs, these functions will return -1, and the contents of strp is undefined."

> 
> @@ -1130,5 @@
> > -                 NULL); 
> > -
> > -          fprintf (stderr,
> > -                   "Failed to execute test message bus daemon %s: %s. Will try again with the system path.\n",
> > -                   TEST_BUS_BINARY, strerror (errno));
> 
> This was pre-existing, but I think it's wrong too.

Hmm, not got you here.
Comment 11 Simon McVittie 2013-09-16 12:42:58 UTC
(In reply to comment #7)
> Hmm, since I found that another place uses DBUS_TEST_DAEMON is in
> installcheck_environment, however the installcheck_tests is empty so far.

If you enable modular tests (on by default), the installable_tests are added to installcheck_tests. That includes shell-test, test-printf, and if GLib is available, various tests that use GLib.
Comment 12 Simon McVittie 2013-09-16 12:44:52 UTC
(In reply to comment #10)
> > > -          fprintf (stderr,
> > > -                   "Failed to execute test message bus daemon %s: %s. Will try again with the system path.\n",
> > > -                   TEST_BUS_BINARY, strerror (errno));
> > 
> > This was pre-existing, but I think it's wrong too.
> 
> Hmm, not got you here.

If DBUS_USE_TEST_BINARY is set, but we can't exec that binary, we shouldn't run the system version instead - we should just fail. We're trying to test the version under test, not the system version, after all :-)
Comment 13 Simon McVittie 2013-09-16 12:46:07 UTC
Created attachment 85907 [details] [review]
dbus-launch: avoid asprintf(), and die gracefully on  out-of-memory

asprintf() is a GNU extension (non-portable).
Comment 14 Simon McVittie 2013-09-16 12:51:45 UTC
Created attachment 85908 [details] [review]
When using dbus-launch for tests, fail hard if test binary is  missing

We want to test the version-under-test, not the system version.

---

Manual test of the above and this:

% DBUS_TEST_DATA=/xxx DBUS_USE_TEST_BINARY=1 ~/build/dbus/debug/tools/dbus-launch
Failed to start message bus: Failed to open "/xxx/valid-config-files/session.conf": No such file or directory
EOF in dbus-launch reading address from bus daemon
% rm ~/build/dbus/debug/bus/dbus-daemon
% DBUS_TEST_DATA=/xxx DBUS_USE_TEST_BINARY=1 ~/build/dbus/debug/tools/dbus-launch
Failed to execute test message bus daemon /home/smcv/build/dbus/debug/bus/dbus-daemon: No such file or directory.
EOF in dbus-launch reading address from bus daemon

(~/build/dbus/debug is my $top_builddir.)
Comment 15 Simon McVittie 2013-09-16 12:54:34 UTC
(In reply to comment #10)
> This test doesn't work in cmake at all. I think there are still more, will
> fill up the gap later.

Not a regression, then. OK, standardizing on DBUS_TEST_DAEMON seems fine in principle (but I'd like to apply the patches I just added here first).
Comment 16 Chengwei Yang 2013-09-16 12:56:14 UTC
(In reply to comment #12)
> (In reply to comment #10)
> > > > -          fprintf (stderr,
> > > > -                   "Failed to execute test message bus daemon %s: %s. Will try again with the system path.\n",
> > > > -                   TEST_BUS_BINARY, strerror (errno));
> > > 
> > > This was pre-existing, but I think it's wrong too.
> > 
> > Hmm, not got you here.
> 
> If DBUS_USE_TEST_BINARY is set, but we can't exec that binary, we shouldn't
> run the system version instead - we should just fail. We're trying to test
> the version under test, not the system version, after all :-)

Sure, make sense to me.
Comment 17 Chengwei Yang 2013-09-16 13:03:45 UTC
Comment on attachment 85907 [details] [review]
dbus-launch: avoid asprintf(), and die gracefully on  out-of-memory

Review of attachment 85907 [details] [review]:
-----------------------------------------------------------------

::: tools/dbus-launch.c
@@ +1134,4 @@
>          {
>            if (config_file == NULL && getenv ("DBUS_TEST_DATA") != NULL)
>              {
> +              config_file = concat2 (getenv ("DBUS_TEST_DATA"),

Hmm, why not strcat or strncat? I think a buffer long as PATH_MAX is enough since it's a path.
Comment 18 Chengwei Yang 2013-09-16 13:05:16 UTC
Comment on attachment 85908 [details] [review]
When using dbus-launch for tests, fail hard if test binary is  missing

Review of attachment 85908 [details] [review]:
-----------------------------------------------------------------

Looks good.
Comment 19 Simon McVittie 2013-09-16 13:52:23 UTC
(In reply to comment #17)
> > +              config_file = concat2 (getenv ("DBUS_TEST_DATA"),
> 
> Hmm, why not strcat or strncat? I think a buffer long as PATH_MAX is enough
> since it's a path.

On a modern OS, PATH_MAX is a convenient lie (e.g. see <http://insanecoding.blogspot.co.uk/2007/11/pathmax-simply-isnt.html>). I'd rather not have to think about whether buffer overflows can happen.
Comment 20 Simon McVittie 2013-09-16 13:54:07 UTC
(In reply to comment #19)
> On a modern OS, PATH_MAX is a convenient lie

(unless it's one of the few that doesn't define it at all, like Hurd - which is non-pragmatic but is arguably obeying the spirit of POSIX better)
Comment 21 Chengwei Yang 2013-09-17 09:30:07 UTC
(In reply to comment #17)
> Comment on attachment 85907 [details] [review] [review]
> dbus-launch: avoid asprintf(), and die gracefully on  out-of-memory
> 
> Review of attachment 85907 [details] [review] [review]:
> -----------------------------------------------------------------
> 
> ::: tools/dbus-launch.c
> @@ +1134,4 @@
> >          {
> >            if (config_file == NULL && getenv ("DBUS_TEST_DATA") != NULL)
> >              {
> > +              config_file = concat2 (getenv ("DBUS_TEST_DATA"),
> 
> Hmm, why not strcat or strncat? I think a buffer long as PATH_MAX is enough
> since it's a path.

Looks good after learned something new.
Comment 22 Simon McVittie 2013-10-08 09:58:03 UTC
Comment on attachment 85907 [details] [review]
dbus-launch: avoid asprintf(), and die gracefully on  out-of-memory

Applied for 1.7.6, thanks. Regression in 1.7.x, no need to backport.
Comment 23 Simon McVittie 2013-10-08 09:58:28 UTC
Comment on attachment 85908 [details] [review]
When using dbus-launch for tests, fail hard if test binary is  missing

Applied for 1.7.6, thanks. Not important enough to backport, IMO.
Comment 24 Simon McVittie 2013-10-08 09:59:52 UTC
(In reply to comment #9)
> Comment on attachment 85804 [details] [review]
> [PATCH v2] Unify the way to find dbus-daemon test binary

This will need rebasing/redoing, I'm afraid.

> > +        DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT) \
> 
> How does this information get to the tests under CMake? (Does it?)

This problem still exists.
Comment 25 Chengwei Yang 2013-10-08 13:49:22 UTC
(In reply to comment #24)
> (In reply to comment #9)
> > Comment on attachment 85804 [details] [review] [review]
> > [PATCH v2] Unify the way to find dbus-daemon test binary
> 
> This will need rebasing/redoing, I'm afraid.

Sure.

> 
> > > +        DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT) \
> > 
> > How does this information get to the tests under CMake? (Does it?)
> 
> This problem still exists.

Yes, I was not trying to fix the CMake gap in this patch, I'll create patch[es] to do that in CMake later, maybe file another bug to track.
Comment 26 Chengwei Yang 2013-10-08 14:01:24 UTC
Created attachment 87281 [details] [review]
[PATCH v3] Unify the way to find dbus-daemon test binary

rebase to HEAD of master
Comment 27 Simon McVittie 2013-10-08 15:18:03 UTC
I had to add a missing "}" to make it compile. Did you test this?

Fixed in git for 1.7.6, thanks.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.