mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-25 19:52:10 +01:00
Merge branch 'wip/smcv/simplify-openpty-linking' into 'main'
tests: Call openpty (if available) without using dlsym See merge request GNOME/glib!2562
This commit is contained in:
commit
f8302d29f1
@ -12,20 +12,20 @@ test_c_args = [
|
|||||||
'-UG_DISABLE_ASSERT',
|
'-UG_DISABLE_ASSERT',
|
||||||
]
|
]
|
||||||
|
|
||||||
# workaround for https://github.com/mesonbuild/meson/issues/6880
|
libutil_dep = dependency('', required : false)
|
||||||
if build_machine.system() == 'linux'
|
|
||||||
libutil_name = 'libutil'
|
|
||||||
libutil = run_command('sh', '-c',
|
|
||||||
'''ldconfig -p | grep -o "[[:space:]]@0@\.so\(\.[0-9]\+\)\?\b"'''
|
|
||||||
.format(libutil_name), check: false).stdout().strip().split('\n')
|
|
||||||
|
|
||||||
if libutil.length() > 0
|
if cc.has_header('pty.h')
|
||||||
message('Found libutil as @0@'.format(libutil[0]))
|
have_openpty = cc.has_function('openpty', prefix : '#include <pty.h>')
|
||||||
test_c_args += '-DLIBUTIL_SONAME="@0@"'.format(libutil[0])
|
|
||||||
else
|
if host_machine.system() == 'linux' and not have_openpty
|
||||||
warning('libutil not found')
|
libutil_dep = cc.find_library('util', required : false)
|
||||||
endif # libutil.length() > 0
|
have_openpty = cc.has_function('openpty', dependencies : libutil_dep, prefix : '#include <pty.h>')
|
||||||
endif # build_machine.system() == 'linux'
|
endif
|
||||||
|
|
||||||
|
if have_openpty
|
||||||
|
test_c_args += '-DHAVE_OPENPTY'
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
if host_machine.system() == 'windows'
|
if host_machine.system() == 'windows'
|
||||||
common_gio_tests_deps += [iphlpapi_dep, winsock2, cc.find_library ('secur32')]
|
common_gio_tests_deps += [iphlpapi_dep, winsock2, cc.find_library ('secur32')]
|
||||||
@ -91,7 +91,7 @@ gio_tests = {
|
|||||||
'network-monitor' : {},
|
'network-monitor' : {},
|
||||||
'network-monitor-race' : {},
|
'network-monitor-race' : {},
|
||||||
'permission' : {},
|
'permission' : {},
|
||||||
'pollable' : {'dependencies' : [libdl_dep]},
|
'pollable' : {'dependencies' : [libutil_dep]},
|
||||||
'power-profile-monitor' : {},
|
'power-profile-monitor' : {},
|
||||||
'proxy-test' : {},
|
'proxy-test' : {},
|
||||||
'readwrite' : {},
|
'readwrite' : {},
|
||||||
|
@ -22,12 +22,20 @@
|
|||||||
#include <glib/gstdio.h>
|
#include <glib/gstdio.h>
|
||||||
|
|
||||||
#ifdef G_OS_UNIX
|
#ifdef G_OS_UNIX
|
||||||
#include <dlfcn.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#ifdef HAVE_OPENPTY
|
||||||
|
#include <pty.h>
|
||||||
|
#endif
|
||||||
#include <gio/gunixinputstream.h>
|
#include <gio/gunixinputstream.h>
|
||||||
#include <gio/gunixoutputstream.h>
|
#include <gio/gunixoutputstream.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* openpty() is non-standard and might not be available on all kernels
|
||||||
|
* and libc implementations, but glibc on Linux definitely has it */
|
||||||
|
#if defined(__linux__) && defined(__GNUC__) && !defined(HAVE_OPENPTY)
|
||||||
|
#error Should have been able to find openpty on GNU/Linux
|
||||||
|
#endif
|
||||||
|
|
||||||
GMainLoop *loop;
|
GMainLoop *loop;
|
||||||
GPollableInputStream *in;
|
GPollableInputStream *in;
|
||||||
GOutputStream *out;
|
GOutputStream *out;
|
||||||
@ -185,31 +193,19 @@ test_pollable_unix_pipe (void)
|
|||||||
static void
|
static void
|
||||||
test_pollable_unix_pty (void)
|
test_pollable_unix_pty (void)
|
||||||
{
|
{
|
||||||
int (*openpty_impl) (int *, int *, char *, void *, void *);
|
#ifdef HAVE_OPENPTY
|
||||||
int a, b, status;
|
int a, b, status;
|
||||||
#ifdef LIBUTIL_SONAME
|
|
||||||
void *handle;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
g_test_summary ("Test that PTYs are considered pollable");
|
g_test_summary ("Test that PTYs are considered pollable");
|
||||||
|
|
||||||
#ifdef LIBUTIL_SONAME
|
#ifdef HAVE_OPENPTY
|
||||||
handle = dlopen (LIBUTIL_SONAME, RTLD_GLOBAL | RTLD_LAZY);
|
status = openpty (&a, &b, NULL, NULL, NULL);
|
||||||
g_assert_nonnull (handle);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
openpty_impl = dlsym (RTLD_DEFAULT, "openpty");
|
|
||||||
if (openpty_impl == NULL)
|
|
||||||
{
|
|
||||||
g_test_skip ("System does not support openpty()");
|
|
||||||
goto close_libutil;
|
|
||||||
}
|
|
||||||
|
|
||||||
status = openpty_impl (&a, &b, NULL, NULL, NULL);
|
|
||||||
if (status == -1)
|
if (status == -1)
|
||||||
{
|
{
|
||||||
g_test_skip ("Unable to open PTY");
|
g_test_skip ("Unable to open PTY");
|
||||||
goto close_libutil;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
in = G_POLLABLE_INPUT_STREAM (g_unix_input_stream_new (a, TRUE));
|
in = G_POLLABLE_INPUT_STREAM (g_unix_input_stream_new (a, TRUE));
|
||||||
@ -222,12 +218,8 @@ test_pollable_unix_pty (void)
|
|||||||
|
|
||||||
close (a);
|
close (a);
|
||||||
close (b);
|
close (b);
|
||||||
|
|
||||||
close_libutil:
|
|
||||||
#ifdef LIBUTIL_SONAME
|
|
||||||
dlclose (handle);
|
|
||||||
#else
|
#else
|
||||||
return;
|
g_test_skip ("openpty not found");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user