Commit 7f55c768 authored by Philip Withnall's avatar Philip Withnall

Merge branch '1444-install-tests' into 'master'

Install unit tests

Closes #1444

See merge request GNOME/glib!183
parents 16c6a735 1bba3276
...@@ -79,12 +79,11 @@ test_extra_programs = [ ...@@ -79,12 +79,11 @@ test_extra_programs = [
['gdbus-testserver'], ['gdbus-testserver'],
] ]
test_env = [ test_env = environment()
'G_TEST_SRCDIR=' + meson.current_source_dir(), test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
'G_TEST_BUILDDIR=' + meson.current_build_dir(), test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
'GIO_MODULE_DIR=', test_env.set('GIO_MODULE_DIR', '')
'GIO_LAUNCH_DESKTOP=' + meson.build_root() + '/gio/gio-launch-desktop', test_env.set('GIO_LAUNCH_DESKTOP', meson.build_root() + '/gio/gio-launch-desktop')
]
test_c_args = [ test_c_args = [
'-DG_LOG_DOMAIN="GLib-GIO"', '-DG_LOG_DOMAIN="GLib-GIO"',
......
glib_tests = [ glib_tests = {
'array-test', 'array-test' : {},
'asyncqueue', 'asyncqueue' : {},
'base64', 'atomic' : {
'bitlock', 'c_args' : cc.get_id() == 'gcc' ? ['-Wstrict-aliasing=2'] : [],
'bookmarkfile', },
'bytes', 'autoptr' : {
'cache', 'skip' : cc.get_id() == 'msvc',
'charset', },
'checksum', 'base64' : {},
'collate', 'bitlock' : {},
'cond', 'bookmarkfile' : {},
'convert', 'bytes' : {},
'dataset', 'cache' : {},
'date', 'charset' : {},
'dir', 'checksum' : {},
'environment', 'collate' : {},
'error', 'cond' : {},
'fileutils', 'convert' : {},
'gdatetime', 'dataset' : {},
'guuid', 'date' : {},
'gvariant', 'dir' : {},
'hash', 'environment' : {},
'hmac', 'error' : {},
'hook', 'fileutils' : {},
'hostutils', 'gdatetime' : {},
'keyfile', 'guuid' : {},
'list', 'gvariant' : {
'logging', 'suite' : ['slow'],
'mainloop', },
'mappedfile', 'gwakeup' : {
'markup', 'source' : ['gwakeuptest.c', '../gwakeup.c'],
'markup-parse', 'install' : false,
'markup-collect', },
'markup-escape', 'gwakeup-fallback' : {
'markup-subparser', 'skip' : not glib_conf.has('HAVE_EVENTFD'),
'mem-overflow', 'source' : ['gwakeuptest.c', '../gwakeup.c'],
'mutex', 'c_args' : ['-DTEST_EVENTFD_FALLBACK'],
'node', 'install' : false,
'once', },
'option-context', 'hash' : {},
'option-argv0', 'hmac' : {},
'overflow', 'hook' : {},
# overflow-fallback handled separately below 'hostutils' : {},
'pattern', 'include' : {
'private', 'skip' : host_machine.system() == 'windows',
'protocol', },
'queue', 'keyfile' : {},
'rand', 'list' : {},
'rcbox', 'logging' : {},
'rec-mutex', 'mainloop' : {},
'refcount', 'mappedfile' : {},
'refcount-macro', 'markup' : {},
'refstring', 'markup-parse' : {},
'regex', 'markup-collect' : {},
'rwlock', 'markup-escape' : {},
'scannerapi', 'markup-subparser' : {},
'search-utils', 'mem-overflow' : {},
'sequence', 'mutex' : {},
'shell', 'node' : {},
'slice', 'once' : {},
'slist', 'option-context' : {},
'sort', 'option-argv0' : {},
'spawn-multithreaded', 'overflow' : {},
'spawn-singlethread', 'overflow-fallback' : {
'strfuncs', 'source' : 'overflow.c',
'string', 'c_args' : ['-D_GLIB_TEST_OVERFLOW_FALLBACK'],
'testing', },
'test-printf', 'pattern' : {},
'thread', 'private' : {},
'timeout', 'protocol' : {},
'timer', 'queue' : {},
'tree', 'rand' : {},
'utf8-performance', 'rcbox' : {},
'utf8-pointer', 'rec-mutex' : {},
'utf8-validate', 'refcount' : {},
'utf8-misc', 'refcount-macro' : {
'utils', 'source' : 'refcount.c',
'unicode', 'c_args' : ['-DG_DISABLE_CHECKS'],
'uri', },
'1bit-mutex', 'refstring' : {},
'642026', 'regex' : {
] 'dependencies' : [pcre],
'c_args' : use_pcre_static_flag ? ['-DPCRE_STATIC'] : [],
},
'rwlock' : {},
'scannerapi' : {},
'search-utils' : {},
'sequence' : {
'suite' : ['slow'],
},
'shell' : {},
'slice' : {},
'slist' : {},
'sort' : {},
'spawn-multithreaded' : {},
'spawn-singlethread' : {},
'strfuncs' : {},
'string' : {},
'testing' : {},
'test-printf' : {},
'thread' : {},
'timeout' : {},
'timer' : {},
'tree' : {},
'utf8-performance' : {},
'utf8-pointer' : {},
'utf8-validate' : {},
'utf8-misc' : {},
'utils' : {},
'unicode' : {},
'unix' : {
'skip' : host_machine.system() == 'windows',
},
'uri' : {},
'1bit-mutex' : {},
'1bit-emufutex' : {
'source' : '1bit-mutex.c',
'c_args' : ['-DTEST_EMULATED_FUTEX'],
'install' : false,
},
'642026' : {
'suite' : ['slow'],
},
'642026-ec' : {
'source' : '642026.c',
'c_args' : ['-DG_ERRORCHECK_MUTEXES'],
'suite' : ['slow'],
},
}
if host_machine.system() != 'windows'
glib_tests += [ 'unix', 'include' ]
endif
if cc.get_id() != 'msvc'
glib_tests += [ 'autoptr' ]
endif
# FIXME: use new environment() object
# Not entirely random of course, but at least it changes over time # Not entirely random of course, but at least it changes over time
random_number = minor_version + meson.version().split('.').get(1).to_int() random_number = minor_version + meson.version().split('.').get(1).to_int()
test_env = [ test_env = environment()
'G_TEST_SRCDIR=' + meson.current_source_dir(), test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
'G_TEST_BUILDDIR=' + meson.current_build_dir(), test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
'G_DEBUG=gc-friendly', test_env.set('G_DEBUG', 'gc-friendly')
'MALLOC_CHECK_=2', test_env.set('MALLOC_CHECK_', '2')
'MALLOC_PERTURB_=@0@'.format(random_number % 256), test_env.set('MALLOC_PERTURB_', '@0@'.format(random_number % 256))
]
test_deps = [libm, thread_dep, libglib_dep]
test_cargs = ['-DG_LOG_DOMAIN="GLib"'] test_cargs = ['-DG_LOG_DOMAIN="GLib"']
# Tests that consistently time out on the CI infrastructure foreach test_name, extra_args : glib_tests
slow_tests = [ # FIXME: This condition is ugly, meson should either have 'continue'
'gvariant', # keyword (https://github.com/mesonbuild/meson/issues/3601), or support
'sequence', # mutable to dictionaries (https://github.com/mesonbuild/meson/pull/3820).
'642026', if not extra_args.get('skip', false)
] source = extra_args.get('source', test_name + '.c')
install = installed_tests_enabled and extra_args.get('install', true)
if install
test_conf = configuration_data()
test_conf.set('installed_tests_dir', installed_tests_execdir)
test_conf.set('program', test_name)
configure_file(
input: installed_tests_template,
output: test_name + '.test',
install_dir: installed_tests_metadir,
configuration: test_conf
)
endif
exe = executable(test_name, source,
c_args : test_cargs + extra_args.get('c_args', []),
dependencies : test_deps + extra_args.get('dependencies', []),
install_dir: installed_tests_execdir,
install: install,
)
foreach test_name : glib_tests suite = ['glib'] + extra_args.get('suite', [])
deps = [libm, thread_dep, libglib_dep] timeout = suite.contains('slow') ? 120 : 30
source = test_name + '.c' test(test_name, exe, env : test_env, timeout : timeout, suite : suite)
c_args = test_cargs + ['-DPCRE_STATIC']
if test_name == 'regex'
deps += [pcre]
endif
if test_name == 'gdatetime'
deps += [libintl]
endif
# We build the refcount test twice: one to test the function-based API,
# and the other to test the macro-based API that is used when disabling
# checks
if test_name == 'refcount-macro'
source = 'refcount.c'
c_args += ['-DG_DISABLE_CHECKS']
endif
exe = executable(test_name, source,
c_args : c_args,
dependencies : deps,
install : false,
)
# These tests may take more than 30 seconds to run on the CI infrastructure
if slow_tests.contains(test_name)
test(test_name, exe, env : test_env, timeout : 120, suite : ['glib', 'slow'])
else
test(test_name, exe, env : test_env, suite : ['glib'])
endif endif
endforeach endforeach
c_args_atomic = []
if cc.get_id() == 'gcc'
c_args_atomic += ['-Wstrict-aliasing=2']
endif
deps = [libm, thread_dep, libglib_dep]
exe = executable('atomic', 'atomic.c',
c_args : test_cargs + c_args_atomic,
dependencies : deps,
)
test('atomic', exe, env : test_env, suite : ['glib'])
# FIXME: consolidate all of these into the array
exe = executable('overflow-fallback', 'overflow.c',
c_args : test_cargs + ['-D_GLIB_TEST_OVERFLOW_FALLBACK'],
dependencies : deps,
install : false,
)
test('overflow-fallback', exe, env : test_env, suite : ['glib'])
exe = executable('642026-ec', '642026.c',
c_args : test_cargs + ['-DG_ERRORCHECK_MUTEXES'],
dependencies : deps,
install : false,
)
test('642026-ec', exe, env : test_env, timeout : 90, suite : ['glib', 'slow'])
exe = executable('1bit-emufutex', '1bit-mutex.c',
c_args : test_cargs + ['-DTEST_EMULATED_FUTEX'],
dependencies : deps,
install : false,
)
test('1bit-emufutex', exe, env : test_env, suite : ['glib'])
exe = executable('gwakeup', 'gwakeuptest.c', '../gwakeup.c',
c_args : test_cargs,
dependencies : deps,
install : false)
test('gwakeup', exe, env : test_env, suite : ['glib'])
if glib_conf.has('HAVE_EVENTFD')
exe = executable('gwakeup-fallback', 'gwakeuptest.c', '../gwakeup.c',
c_args : test_cargs + ['-DTEST_EVENTFD_FALLBACK'],
dependencies : deps,
install : false,
)
test('gwakeup-fallback', exe, env : test_env, suite : ['glib'])
endif
# test-spawn-echo helper binary required by the spawn tests above # test-spawn-echo helper binary required by the spawn tests above
executable('test-spawn-echo', 'test-spawn-echo.c', executable('test-spawn-echo', 'test-spawn-echo.c',
c_args : test_cargs, c_args : test_cargs,
dependencies : deps, dependencies : test_deps,
install : false, install_dir: installed_tests_execdir,
install: installed_tests_enabled,
) )
# some testing of gtester functionality # some testing of gtester functionality
...@@ -204,7 +189,6 @@ if not meson.is_cross_build() and host_system != 'windows' ...@@ -204,7 +189,6 @@ if not meson.is_cross_build() and host_system != 'windows'
if xmllint.found() if xmllint.found()
tmpsample_xml = custom_target('tmpsample.xml', tmpsample_xml = custom_target('tmpsample.xml',
output : 'tmpsample.xml', output : 'tmpsample.xml',
build_by_default : true, # hack around meson bug, see PR #1335
command : [ gtester, '-k', '--quiet', '-o', '@OUTPUT@', command : [ gtester, '-k', '--quiet', '-o', '@OUTPUT@',
'--test-arg=--gtester-selftest', gtester]) '--test-arg=--gtester-selftest', gtester])
......
...@@ -20,18 +20,16 @@ gobject_tests = [ ...@@ -20,18 +20,16 @@ gobject_tests = [
'ifaceproperties', 'ifaceproperties',
] ]
# FIXME: use new environment() object
# FIXME: put common bits of test environment() in one location # FIXME: put common bits of test environment() in one location
# Not entirely random of course, but at least it changes over time # Not entirely random of course, but at least it changes over time
random_number = minor_version + meson.version().split('.').get(1).to_int() random_number = minor_version + meson.version().split('.').get(1).to_int()
test_env = [ test_env = environment()
'G_TEST_SRCDIR=' + meson.current_source_dir(), test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
'G_TEST_BUILDDIR=' + meson.current_build_dir(), test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
'G_DEBUG=gc-friendly', test_env.set('G_DEBUG', 'gc-friendly')
'MALLOC_CHECK_=2', test_env.set('MALLOC_CHECK_', '2')
'MALLOC_PERTURB_=@0@'.format(random_number % 256), test_env.set('MALLOC_PERTURB_', '@0@'.format(random_number % 256))
]
foreach test_name : gobject_tests foreach test_name : gobject_tests
deps = [libm, thread_dep, libglib_dep, libgobject_dep] deps = [libm, thread_dep, libglib_dep, libgobject_dep]
......
...@@ -56,6 +56,7 @@ gioinc = include_directories('gio') ...@@ -56,6 +56,7 @@ gioinc = include_directories('gio')
glib_prefix = get_option('prefix') glib_prefix = get_option('prefix')
glib_bindir = join_paths(glib_prefix, get_option('bindir')) glib_bindir = join_paths(glib_prefix, get_option('bindir'))
glib_libdir = join_paths(glib_prefix, get_option('libdir')) glib_libdir = join_paths(glib_prefix, get_option('libdir'))
glib_libexecdir = join_paths(glib_prefix, get_option('libexecdir'))
glib_datadir = join_paths(glib_prefix, get_option('datadir')) glib_datadir = join_paths(glib_prefix, get_option('datadir'))
glib_pkgdatadir = join_paths(glib_datadir, 'glib-2.0') glib_pkgdatadir = join_paths(glib_datadir, 'glib-2.0')
glib_includedir = join_paths(glib_prefix, get_option('includedir')) glib_includedir = join_paths(glib_prefix, get_option('includedir'))
...@@ -66,6 +67,11 @@ endif ...@@ -66,6 +67,11 @@ endif
glib_pkgconfigreldir = join_paths(glib_libdir, 'pkgconfig') glib_pkgconfigreldir = join_paths(glib_libdir, 'pkgconfig')
installed_tests_metadir = join_paths(glib_datadir, 'installed-tests', meson.project_name())
installed_tests_execdir = join_paths(glib_libexecdir, 'installed-tests', meson.project_name())
installed_tests_enabled = get_option('installed_tests')
installed_tests_template = files('template.test.in')
add_project_arguments('-D_GNU_SOURCE', language: 'c') add_project_arguments('-D_GNU_SOURCE', language: 'c')
# Disable strict aliasing; # Disable strict aliasing;
......
...@@ -78,3 +78,8 @@ option('fam', ...@@ -78,3 +78,8 @@ option('fam',
type : 'boolean', type : 'boolean',
value : false, value : false,
description : 'Use fam for file system monitoring') description : 'Use fam for file system monitoring')
option('installed_tests',
type : 'boolean',
value : false,
description : 'enable installed tests')
[Test]
Type=session
Exec=@installed_tests_dir@/@program@
# tests # tests
test_env = [ test_env = environment()
'G_TEST_SRCDIR=' + meson.current_source_dir(), test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
'G_TEST_BUILDDIR=' + meson.current_build_dir(), test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
'G_DEBUG=gc-friendly', test_env.set('G_DEBUG', 'gc-friendly')
'MALLOC_CHECK_=2', test_env.set('MALLOC_CHECK_', '2')
]
test_cargs = ['-DG_LOG_DOMAIN="GLib"'] test_cargs = ['-DG_LOG_DOMAIN="GLib"']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment