[PATCH libinput 6/5] tools: add a test to verify the builddir lookup works correctly

Peter Hutterer peter.hutterer at who-t.net
Mon Jul 9 01:27:45 UTC 2018


found this one stuck in my outbox...

On Mon, Jul 02, 2018 at 03:41:04PM +0300, Pekka Paalanen wrote:
> On Fri, 29 Jun 2018 11:08:31 +1000
> Peter Hutterer <peter.hutterer at who-t.net> wrote:
> 
> > The binary takes an argument to check whether we expect the builddir to be
> > detected or not. Then it's executed once as normal test and once after being
> > copied to /tmp.
> > 
> > Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> > ---
> > 
> > that was easier than expected... :)
> > 
> >  meson.build                            | 16 +++++++++
> >  tools/helper-copy-and-exec-from-tmp.sh | 18 ++++++++++
> >  tools/test-builddir-lookup.c           | 47 ++++++++++++++++++++++++++
> >  3 files changed, 81 insertions(+)
> >  create mode 100755 tools/helper-copy-and-exec-from-tmp.sh
> >  create mode 100644 tools/test-builddir-lookup.c
> > 
> > diff --git a/meson.build b/meson.build
> > index 826b4fd0..45786d9f 100644
> > --- a/meson.build
> > +++ b/meson.build
> > @@ -679,6 +679,22 @@ executable('ptraccel-debug',
> >  	   install : false
> >  	   )
> >  
> > +# the libinput tools check whether we execute from the builddir, this is
> > +# the test to verify that lookup. We test twice, once as normal test
> > +# run from the builddir, once after copying to /tmp
> > +test_builddir_lookup = executable('test-builddir-lookup',
> > +				  'tools/test-builddir-lookup.c',
> > +				  dependencies : [ dep_tools_shared],
> > +				  include_directories : [includes_src, includes_include],
> > +				  install : false)
> > +test('tools-builddir-lookup',
> > +     test_builddir_lookup,
> > +     args : ['--builddir-is-set'])
> > +test('tools-builddir-lookup-installed',
> > +     find_program('tools/helper-copy-and-exec-from-tmp.sh'),
> > +     args : [test_builddir_lookup.full_path(), '--builddir-is-null'],
> > +     workdir : '/tmp')
> > +
> >  ############ tests ############
> >  
> >  test_symbols_leak = find_program('test/symbols-leak-test.in')
> > diff --git a/tools/helper-copy-and-exec-from-tmp.sh b/tools/helper-copy-and-exec-from-tmp.sh
> > new file mode 100755
> > index 00000000..46182c42
> > --- /dev/null
> > +++ b/tools/helper-copy-and-exec-from-tmp.sh
> > @@ -0,0 +1,18 @@
> > +#!/bin/bash -x
> > +#
> > +# Usage: helper-copy-and-exec-from-tmp.sh /path/to/binary [args]
> > +#
> > +# Copies the given binary into a unique file in /tmp and executes it with
> > +# [args]. Exits with the same return code as the binary did.
> > +
> > +executable="$1"
> > +shift
> > +
> > +target_name=$(mktemp)
> > +cp "$executable" "$target_name"
> > +chmod +x "$target_name"
> > +
> > +$target_name "$@"
> > +rc=$?
> > +rm $target_name
> > +exit $rc
> 
> I'd apply more paranoia in bash scripts and but $target_name in quotes.

done in the udpated patch
 
> > diff --git a/tools/test-builddir-lookup.c b/tools/test-builddir-lookup.c
> > new file mode 100644
> > index 00000000..457ed8cb
> > --- /dev/null
> > +++ b/tools/test-builddir-lookup.c
> > @@ -0,0 +1,47 @@
> > +/*
> > + * Copyright © 2018 Red Hat, Inc.
> > + *
> > + * Permission is hereby granted, free of charge, to any person obtaining a
> > + * copy of this software and associated documentation files (the "Software"),
> > + * to deal in the Software without restriction, including without limitation
> > + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> > + * and/or sell copies of the Software, and to permit persons to whom the
> > + * Software is furnished to do so, subject to the following conditions:
> > + *
> > + * The above copyright notice and this permission notice (including the next
> > + * paragraph) shall be included in all copies or substantial portions of the
> > + * Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> > + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> > + * DEALINGS IN THE SOFTWARE.
> > + */
> > +
> > +#include "config.h"
> > +#include "libinput-util.h"
> > +#include "shared.h"
> > +
> > +
> > +int main(int argc, char **argv) {
> > +	char *builddir;
> > +	char *mode;
> > +
> > +	assert(argc == 2);
> 
> Is libinput test suite buildable with NDEBUG? I suppose not.

not really. Most of the actual tests will probably work because they resolve
to abort(), not assert. But I do wonder what the point of it would be to
disable assert in tests.

I think this falls under the "hop along, now that you've successfully shot
yourself in the foot" category.

Thanks for the review, much appreciated

Cheers,
   Peter


> > +	mode = argv[1];
> > +
> > +	builddir = tools_execdir_is_builddir();
> > +	if (streq(mode, "--builddir-is-null")) {
> > +		assert(builddir == NULL);
> > +	} else if (streq(mode, "--builddir-is-set")) {
> > +		assert(builddir != NULL);
> > +		assert(streq(MESON_BUILD_ROOT, builddir));
> > +	} else {
> > +		abort();
> > +	}
> > +
> > +	return 0;
> > +}
> 
> Looks good to me. This patch:
> 
> Reviewed-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
> with a pinch of salt.
> 
> 
> Thanks,
> pq




More information about the wayland-devel mailing list