Skip to content
Snippets Groups Projects
Commit a3d36bed authored by Simon McVittie's avatar Simon McVittie
Browse files

Add a simple build-time and installed test


While there, drop unused $(shim_files) and $(shim_srcs) variables.

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent 60344a62
No related branches found
No related tags found
1 merge request!311Build capsule-capture-libs from a bundled copy of libcapsule
Showing with 698 additions and 8 deletions
......@@ -60,4 +60,5 @@ libcapsule-*.txt
*.prerequisites
*.signals
!/build-aux/git-version-gen
!/build-aux/tap-test.sh
!/m4/ax_is_release.m4
......@@ -92,8 +92,7 @@ dist_pkgdata_DATA = data/capsule-shim.h \
data/capsule-shim.mk.in \
disabled.mk
BUILT_SOURCES = $(shim_srcs)
BUILT_SOURCES += $(top_srcdir)/.version
BUILT_SOURCES = $(top_srcdir)/.version
$(top_srcdir)/.version:
$(AM_V_GEN)echo $(VERSION) > $@-t && mv $@-t $@
......@@ -105,6 +104,127 @@ dist-hook-git-version-gen:
include $(top_srcdir)/disabled.mk
# ============================================================================
# GNOME-style installed-tests
insttestsdir = $(libexecdir)/installed-tests/$(PACKAGE_TARNAME)
# /!\ Order is important here: the helper library must come first
nobase_insttests_LTLIBRARIES = tests/red/libhelper.la \
tests/green/libhelper.la \
tests/lib/libhelper.la \
tests/red/libnotgl.la \
tests/green/libnotgl.la \
tests/lib/libnotgl.la \
tests/shim/libnotgl.la
# Install the source code so we can rebuild it inside a container if we want to
nobase_dist_insttests_DATA = tests/libtest.sh \
tests/notgl.h \
tests/notgl-green.c \
tests/notgl-red.c \
tests/notgl-ref.c \
tests/notgl-helper.h \
tests/notgl-helper-green.c \
tests/notgl-helper-red.c \
tests/notgl-helper-ref.c \
tests/shim/libnotgl.so.c.dlopen \
tests/shim/libnotgl.so.c.dlsym \
tests/shim/libnotgl.so.c.excluded \
tests/shim/libnotgl.so.c.shared \
tests/shim/libnotgl.so.c.symbols
tests_lib_libnotgl_la_SOURCES = tests/notgl-ref.c \
tests/notgl.h \
tests/notgl-helper.h
tests_lib_libnotgl_la_LDFLAGS = -shared -version-number 0:42:23
tests_lib_libnotgl_la_LIBADD = tests/lib/libhelper.la
tests_red_libnotgl_la_SOURCES = tests/notgl-red.c \
tests/notgl.h \
tests/notgl-helper.h
# Give it a gratuitously higher version number
tests_red_libnotgl_la_LDFLAGS = -shared -version-number 0:123:456
# We want the RUNPATH to point to tests/lib here, so link to that helper
tests_red_libnotgl_la_LIBADD = tests/lib/libhelper.la
tests_green_libnotgl_la_SOURCES = tests/notgl-green.c \
tests/notgl.h \
tests/notgl-helper.h
# Give this one a gratuitously *lower* version number
tests_green_libnotgl_la_LDFLAGS = -shared -version-number 0:23:42
# Again, we want the RUNPATH to point to tests/lib here, so link to that helper
tests_green_libnotgl_la_LIBADD = tests/lib/libhelper.la
tests_lib_libhelper_la_SOURCES = tests/notgl-helper-ref.c \
tests/notgl-helper.h
tests_lib_libhelper_la_LDFLAGS = -shared -version-number 0:42:23
tests_red_libhelper_la_SOURCES = tests/notgl-helper-red.c \
tests/notgl-helper.h
tests_red_libhelper_la_LDFLAGS = -shared -version-number 0:123:456
tests_green_libhelper_la_SOURCES = tests/notgl-helper-green.c \
tests/notgl-helper.h
tests_green_libhelper_la_LDFLAGS = -shared -version-number 0:23:42
nodist_tests_shim_libnotgl_la_SOURCES = tests/shim/libnotgl.so.c
tests_shim_libnotgl_la_LIBADD = libcapsule.la
tests_shim_libnotgl_la_LDFLAGS = -shared -version-number 0:0:0
tests_shim_libnotgl_la_CFLAGS = $(AM_CFLAGS) -I$(top_srcdir)/capsule
tests/shim/lib%.so.c: tests/shim/lib%.so.c.excluded tests/shim/lib%.so.c.dlopen tests/shim/lib%.so.c.dlsym tests/shim/lib%.so.c.shared tests/shim/lib%.so.c.symbols data/capsule-mkstublib Makefile
$(AM_V_GEN)\
PKG_CONFIG_PATH=$(abs_builddir)/data \
V=$V \
$(top_srcdir)/data/capsule-mkstublib \
--dlopen-implementation=$(srcdir)/$@.dlopen \
--dlsym-implementation=$(srcdir)/$@.dlsym \
--symbols-from=$(srcdir)/$@.symbols \
--no-update-symbols \
--runtime-tree=/host \
$$(basename $@ .c).0 \
$(srcdir)/$@.excluded \
$(srcdir)/$@.shared \
$@
LOG_DRIVER = env AM_TAP_AWK='$(AWK)' \
$(SHELL) $(top_srcdir)/build-aux/tap-driver.sh
LOG_COMPILER = $(top_srcdir)/build-aux/tap-test.sh
TEST_EXTENSIONS = .sh
SH_LOG_DRIVER = $(LOG_DRIVER)
SH_LOG_COMPILER = $(LOG_COMPILER)
AM_TESTS_ENVIRONMENT = export CAPSULE_TESTS_UNINSTALLED=1; \
export G_TEST_SRCDIR="$(abs_srcdir)"; \
export G_TEST_BUILDDIR="$(abs_builddir)";\
export G_DEBUG=gc-friendly; \
export MALLOC_CHECK_=2;
test_extra_programs = tests/notgl-user \
tests/notgl-helper-user
tests_notgl_user_LDADD = tests/lib/libnotgl.la
tests_notgl_helper_user_LDADD = tests/lib/libnotgl.la \
tests/lib/libhelper.la
test_extra_scripts =
test_programs =
test_scripts = tests/notgl.sh
nobase_insttests_PROGRAMS = $(test_programs) \
$(test_extra_programs)
nobase_dist_insttests_SCRIPTS = $(test_scripts) \
$(test_extra_scripts)
TESTS = $(test_programs) \
$(test_scripts)
testmetadir = $(datadir)/installed-tests/$(PACKAGE_TARNAME)
testmeta_DATA = $(patsubst %,%.test,$(test_programs) $(test_scripts))
$(testmeta_DATA): tests/%.test: tests/% Makefile
@$(MKDIR_P) $(dir $@)
$(AM_V_GEN)set -e; \
(\
echo "[Test]"; \
echo "Type=session"; \
echo "Output=TAP"; \
echo "Exec=$(insttestsdir)/tests/$* --tap"; \
) > $@.tmp && mv $@.tmp $@
# ============================================================================
# gtk-doc configuration: see /usr/share/doc/gtk-doc-tools/examples/Makefile.am
DOC_MODULE = libcapsule
......@@ -126,13 +246,12 @@ GTKDOC_CFLAGS =
GTKDOC_LIBS =
include $(top_srcdir)/gtk-doc.make
# ============================================================================
# CLEANFILES is unconditionally set by gtk-doc.make, have to do these after:
CLEANFILES += $(shim_files) $(shim_srcs)
# ============================================================================
# standalone man pages
include $(top_srcdir)/documentation.mk
# This needs to come after we include gtk-doc.make, which unconditionally
# defines it
# These need to come after we include gtk-doc.make, which unconditionally
# defines these variables
CLEANFILES += $(testmeta_DATA)
CLEANFILES += tests/shim/libnotgl.so.c
EXTRA_DIST += $(top_srcdir)/.version
EXTRA_DIST += build-aux/tap-test.sh
#!/bin/sh
# Wrapper to make GTest tests output TAP syntax, because Automake's test
# drivers do not currently support passing the same command-line argument
# to each test executable. All GTest tests produce TAP output if invoked
# with the --tap option.
#
# Usage: "tap-test.sh test-foo --verbose ..." is equivalent to
# "test-foo --tap --verbose ..."
set -e
t="$1"
shift
exec "$t" --tap "$@"
......@@ -22,6 +22,7 @@ AC_INIT([libcapsule],
[], [], [https://gitlab.collabora.com/vivek/libcapsule])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
AC_REQUIRE_AUX_FILE([tap-driver.sh])
m4_pattern_forbid([^AX_], [Please install GNU autoconf-archive])
......
......@@ -7,6 +7,7 @@ Build-Depends:
autoconf,
autoconf-archive (>= 20160916-1),
automake,
bubblewrap,
debhelper,
dh-autoreconf,
gtk-doc-tools,
......@@ -49,6 +50,21 @@ Description:
.
This package contains the files needed to generate libcapsule proxy libraries.
Package: libcapsule-tests
Architecture: amd64 i386
Section: misc
Priority: optional
Depends:
bubblewrap,
${shlibs:Depends},
Description:
libcapsule is a helper library used to implement segregated run-time
dynamic linking proxy libraries - used (for example) to load a library
that has dependencies incompatible with the regular libraries that are
part of the host OS, such as an incompatible libstdc++ version.
.
This package contains automated tests.
Package: libcapsule0
Architecture: amd64 i386
Multi-Arch: same
......
usr/lib/*/capsule/installed-tests/libcapsule
usr/share/installed-tests/libcapsule
......@@ -12,6 +12,7 @@ override_dh_auto_configure:
override_dh_install:
rm -f debian/tmp/usr/lib/*/*.la
find debian/tmp/usr/lib/*/capsule/installed-tests -name '*.la' -print -delete
dh_install --fail-missing
override_dh_autoreconf:
......
......@@ -2,3 +2,8 @@ Tests: smoke
Depends:
build-essential,
libcapsule-dev,
Tests: gnome-desktop-testing
Depends:
gnome-desktop-testing,
libcapsule-tests,
#!/bin/sh
set -e
exec 2>&1
exec gnome-desktop-testing-runner libcapsule
# vim:set ft=sh sts=4 sw=4 et:
# Copyright © 2017 Collabora Ltd
# This file is part of libcapsule.
# libcapsule 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.
# libcapsule 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 libcapsule. If not, see <http://www.gnu.org/licenses/>.
test_tempdir="$(mktemp -d /tmp/libcapsule.XXXXXXXX)"
trap 'rm -fr --one-file-system $test_tempdir' EXIT
mkdir "$test_tempdir/host"
export CAPSULE_PREFIX="$test_tempdir/host"
test_num=0
any_failed=0
skip_all () {
echo "1..0 # SKIP - $*"
exit 0
}
pass () {
test_num=$((test_num + 1))
echo "ok $test_num - $*"
}
fail () {
test_num=$((test_num + 1))
echo "not ok $test_num - $*"
any_failed=1
}
skip () {
test_num=$((test_num + 1))
echo "ok $test_num # SKIP - $*"
}
ok () {
local condition="$1"
shift
if $condition; then
pass "$*"
else
fail "$*"
fi
}
is () {
local got="$1"
local expected="$2"
shift 2
if [ "x$got" = "x$expected" ]; then
pass "$* ($got)"
else
echo "# Got: $got"
echo "# Expected: $expected"
fail "$* ($got != $expected)"
fi
}
isnt () {
local got="$1"
local unexpected="$2"
shift 2
if [ "x$got" != "x$unexpected" ]; then
echo "# Got: $got"
echo "# Expected: anything but $unexpected"
fail "$* (expected anything but $unexpected)"
else
pass "$* ($got)"
fi
}
exec_is () {
local command="$1"
local expected_status="$2"
local expected="$3"
local status=0
shift 3
got="$(eval "$command")" || status="$?"
if [ "x$status" != "x$expected_status" ]; then
fail "$* (status $status != $expected_status)"
fi
if [ "x$got" = "x$expected" ]; then
pass "$* ($got)"
else
echo "# Got: $got"
echo "# Expected: $expected"
fail "$* ($got != $expected)"
fi
}
run_verbose () {
echo "# \$($*)..."
"$@"
}
done_testing () {
echo "# End of tests"
echo "1..$test_num"
exit $any_failed
}
// Copyright © 2017 Collabora Ltd
// notgl-green — one of two implementations of libnotgl, taking the
// role of the NVIDIA implementation of OpenGL
// This file is part of libcapsule.
//
// libcapsule 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.
//
// libcapsule 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 libcapsule. If not, see <http://www.gnu.org/licenses/>.
#include "notgl.h"
#include <dlfcn.h>
#include "notgl-helper.h"
const char *
notgl_get_implementation( void )
{
return "green";
}
const char *
notgl_extension_both( void )
{
return "green implementation of common extension";
}
const char *
notgl_extension_green( void )
{
return "green-only extension";
}
const char *
notgl_use_helper( void )
{
return helper_get_implementation();
}
// Copyright © 2017 Collabora Ltd
// notgl-helper-green — An implementation of libnotgl-helper in the
// host, taking the role of the host's libstdc++
// This file is part of libcapsule.
//
// libcapsule 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.
//
// libcapsule 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 libcapsule. If not, see <http://www.gnu.org/licenses/>.
#include "notgl-helper.h"
const char *
helper_get_implementation( void )
{
return "host (green)";
}
// Copyright © 2017 Collabora Ltd
// notgl-helper-red — An implementation of libnotgl-helper in the
// host, taking the role of the host's libstdc++
// This file is part of libcapsule.
//
// libcapsule 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.
//
// libcapsule 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 libcapsule. If not, see <http://www.gnu.org/licenses/>.
#include "notgl-helper.h"
const char *
helper_get_implementation( void )
{
return "host (red)";
}
// Copyright © 2017 Collabora Ltd
// notgl-helper-ref — The implementation of libnotgl-helper in the
// container, taking the role of the container's libstdc++
// This file is part of libcapsule.
//
// libcapsule 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.
//
// libcapsule 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 libcapsule. If not, see <http://www.gnu.org/licenses/>.
#include "notgl-helper.h"
const char *
helper_get_implementation( void )
{
return "container (reference)";
}
// Copyright © 2017 Collabora Ltd
// This file is part of libcapsule.
//
// libcapsule 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.
//
// libcapsule 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 libcapsule. If not, see <http://www.gnu.org/licenses/>.
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include "notgl.h"
#include "notgl-helper.h"
static notgl_extension_function
get_extension( const char *name )
{
return dlsym( RTLD_DEFAULT, name );
}
int
main ( int argc,
char **argv )
{
notgl_extension_function f;
printf( "NotGL implementation: %s\n", notgl_get_implementation() );
printf( "NotGL helper implementation: %s\n", notgl_use_helper() );
f = get_extension( "notgl_extension_both" );
if( f )
printf( "notgl_extension_both: %s\n", f() );
else
printf( "notgl_extension_both: (not found)\n" );
f = get_extension( "notgl_extension_red" );
if( f )
printf( "notgl_extension_red: %s\n", f() );
else
printf( "notgl_extension_red: (not found)\n" );
f = get_extension( "notgl_extension_green" );
if( f )
printf( "notgl_extension_green: %s\n", f() );
else
printf( "notgl_extension_green: (not found)\n" );
printf( "NotGL helper implementation as seen by executable: %s\n", helper_get_implementation () );
return 0;
}
// Copyright © 2017 Collabora Ltd
// libnotgl-helper — A library used by the OpenGL driver, taking the
// role of libstdc++
// This file is part of libcapsule.
//
// libcapsule 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.
//
// libcapsule 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 libcapsule. If not, see <http://www.gnu.org/licenses/>.
#pragma once
#define HELPER_PUBLIC __attribute__((visibility("default")))
HELPER_PUBLIC
const char *helper_get_implementation( void );
// Copyright © 2017 Collabora Ltd
// notgl-red — one of two implementations of libnotgl, taking the
// role of the AMD implementation of OpenGL
// This file is part of libcapsule.
//
// libcapsule 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.
//
// libcapsule 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 libcapsule. If not, see <http://www.gnu.org/licenses/>.
#include "notgl.h"
#include <dlfcn.h>
#include "notgl-helper.h"
const char *
notgl_get_implementation( void )
{
return "red";
}
const char *
notgl_extension_both( void )
{
return "red implementation of common extension";
}
const char *
notgl_extension_red( void )
{
return "red-only extension";
}
const char *
notgl_use_helper( void )
{
return helper_get_implementation ();
}
// Copyright © 2017 Collabora Ltd
// notgl-ref — reference implementation of libnotgl, taking the
// role of the (possibly outdated) implementation of OpenGL in the container
// This file is part of libcapsule.
//
// libcapsule 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.
//
// libcapsule 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 libcapsule. If not, see <http://www.gnu.org/licenses/>.
#include "notgl.h"
#include <dlfcn.h>
#include "notgl-helper.h"
const char *
notgl_get_implementation( void )
{
return "reference";
}
const char *
notgl_extension_both( void )
{
return "reference implementation of common extension";
}
const char *
notgl_use_helper( void )
{
return helper_get_implementation ();
}
// Copyright © 2017 Collabora Ltd
// This file is part of libcapsule.
//
// libcapsule 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.
//
// libcapsule 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 libcapsule. If not, see <http://www.gnu.org/licenses/>.
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include "notgl.h"
static notgl_extension_function
get_extension( const char *name )
{
return dlsym( RTLD_DEFAULT, name );
}
int
main ( int argc,
char **argv )
{
notgl_extension_function f;
printf( "NotGL implementation: %s\n", notgl_get_implementation() );
printf( "NotGL helper implementation: %s\n", notgl_use_helper() );
f = get_extension( "notgl_extension_both" );
if( f )
printf( "notgl_extension_both: %s\n", f() );
else
printf( "notgl_extension_both: (not found)\n" );
f = get_extension( "notgl_extension_red" );
if( f )
printf( "notgl_extension_red: %s\n", f() );
else
printf( "notgl_extension_red: (not found)\n" );
f = get_extension( "notgl_extension_green" );
if( f )
printf( "notgl_extension_green: %s\n", f() );
else
printf( "notgl_extension_green: (not found)\n" );
return 0;
}
// Copyright © 2017 Collabora Ltd
// notgl — a library not entirely unlike OpenGL
// This file is part of libcapsule.
//
// libcapsule 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.
//
// libcapsule 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 libcapsule. If not, see <http://www.gnu.org/licenses/>.
#pragma once
#define NOTGL_PUBLIC __attribute__((visibility("default")))
typedef const char *(*notgl_extension_function)( void );
NOTGL_PUBLIC
const char *notgl_get_implementation( void );
NOTGL_PUBLIC
const char *notgl_extension_both( void );
NOTGL_PUBLIC
const char *notgl_extension_red( void );
NOTGL_PUBLIC
const char *notgl_extension_green( void );
NOTGL_PUBLIC
const char *notgl_use_helper( void );
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment