mirror of
https://github.com/flatpak/flatpak.git
synced 2026-05-10 17:09:07 -04:00
tests: Add support for adding internal tests
If the internal_tests option is enabled we build some internal tests into the binary. These are added to the tests we run in testlibrary. This is not intended to be enabled in production, as it adds size to the real binary, but is useful for CI and development.
This commit is contained in:
committed by
Sebastian Wick
parent
14bfb56ba3
commit
5c12cd83a1
2
.github/workflows/check.yml
vendored
2
.github/workflows/check.yml
vendored
@@ -64,6 +64,7 @@ jobs:
|
||||
-Dgtkdoc=disabled \
|
||||
-Dhttp_backend=curl \
|
||||
-Dinternal_checks=true \
|
||||
-Dinternal_tests=true \
|
||||
-Dsystem_dbus_proxy=xdg-dbus-proxy \
|
||||
_build
|
||||
env:
|
||||
@@ -123,6 +124,7 @@ jobs:
|
||||
-Dgtkdoc=disabled \
|
||||
-Dhttp_backend=soup \
|
||||
-Dinternal_checks=true \
|
||||
-Dinternal_tests=true \
|
||||
_build
|
||||
env:
|
||||
CFLAGS: -O2 -Wp,-D_FORTIFY_SOURCE=2
|
||||
|
||||
@@ -29,6 +29,11 @@
|
||||
#include "flatpak-error.h"
|
||||
#include "flatpak-glib-backports-private.h"
|
||||
|
||||
#define XCONCATENATE(x, y) x ## y
|
||||
#define CONCATENATE(x, y) XCONCATENATE(x, y)
|
||||
|
||||
#define FLATPAK_UNIQUE_NAME(base) CONCATENATE(base, __COUNTER__)
|
||||
|
||||
#define AUTOFS_SUPER_MAGIC 0x0187
|
||||
|
||||
#define FLATPAK_XA_CACHE_VERSION 2
|
||||
@@ -348,6 +353,21 @@ gboolean running_under_sudo (void);
|
||||
void flatpak_set_debugging (gboolean debugging);
|
||||
gboolean flatpak_is_debugging (void);
|
||||
|
||||
#ifdef INCLUDE_INTERNAL_TESTS
|
||||
typedef void (*flatpak_test_fn) (void);
|
||||
void flatpak_add_test (const char *path, flatpak_test_fn fn);
|
||||
#define FLATPAK_INTERNAL_TEST(path, fn) \
|
||||
__attribute__((constructor)) static void \
|
||||
FLATPAK_UNIQUE_NAME(internal_test_) (void) { \
|
||||
flatpak_add_test (path, fn); \
|
||||
}
|
||||
#else
|
||||
#define FLATPAK_INTERNAL_TEST(path, fn)
|
||||
#endif
|
||||
|
||||
FLATPAK_EXTERN
|
||||
void flatpak_add_all_tests (void);
|
||||
|
||||
#define FLATPAK_MESSAGE_ID "c7b39b1e006b464599465e105b361485"
|
||||
|
||||
#endif /* __FLATPAK_UTILS_H__ */
|
||||
|
||||
@@ -2471,3 +2471,23 @@ flatpak_is_debugging (void)
|
||||
|
||||
return is_debugging;
|
||||
}
|
||||
|
||||
#ifdef INCLUDE_INTERNAL_TESTS
|
||||
static GList *flatpak_test_paths = NULL;
|
||||
static GList *flatpak_test_fns = NULL;
|
||||
|
||||
void flatpak_add_test (const char *path, flatpak_test_fn fn)
|
||||
{
|
||||
flatpak_test_paths = g_list_prepend (flatpak_test_paths, (void *)path);
|
||||
flatpak_test_fns = g_list_prepend (flatpak_test_fns, fn);
|
||||
}
|
||||
#endif
|
||||
|
||||
void flatpak_add_all_tests (void)
|
||||
{
|
||||
#ifdef INCLUDE_INTERNAL_TESTS
|
||||
for (GList *l1 = flatpak_test_paths, *l2 = flatpak_test_fns; l1 != NULL; l1 = l1->next, l2 = l2->next) {
|
||||
g_test_add_func (l1->data, l2->data);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -360,6 +360,10 @@ cdata.set_quoted('GETTEXT_PACKAGE', 'flatpak')
|
||||
cdata.set('FUSE_USE_VERSION', fuse_api)
|
||||
cdata.set_quoted('FUSERMOUNT', fusermount)
|
||||
|
||||
if get_option('internal_tests')
|
||||
cdata.set('INCLUDE_INTERNAL_TESTS', 1)
|
||||
endif
|
||||
|
||||
if get_option('system_bubblewrap') == ''
|
||||
cdata.set_quoted('HELPER', get_option('prefix') / get_option('libexecdir') / 'flatpak-bwrap')
|
||||
else
|
||||
|
||||
@@ -74,6 +74,12 @@ option(
|
||||
description : 'enable internal checking',
|
||||
value : false,
|
||||
)
|
||||
option(
|
||||
'internal_tests',
|
||||
type : 'boolean',
|
||||
description : 'include internal tests in binary',
|
||||
value : false,
|
||||
)
|
||||
option(
|
||||
'libzstd',
|
||||
type : 'feature',
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "can-use-fuse.h"
|
||||
#include "testlib.h"
|
||||
|
||||
void flatpak_add_all_tests (void);
|
||||
|
||||
static char *testdir;
|
||||
static char *flatpak_runtimedir;
|
||||
static char *flatpak_systemdir;
|
||||
@@ -5128,6 +5130,8 @@ main (int argc, char *argv[])
|
||||
g_test_add_func ("/library/installation-unused-refs-excludes-pins", test_installation_unused_refs_excludes_pins);
|
||||
g_test_add_func ("/library/installation-unused-refs-across-installations", test_installation_unused_refs_across_installations);
|
||||
|
||||
flatpak_add_all_tests ();
|
||||
|
||||
global_setup ();
|
||||
|
||||
res = g_test_run ();
|
||||
|
||||
Reference in New Issue
Block a user