Skip to content

Commit

Permalink
tests: Skip thread name tests if libc is too old
Browse files Browse the repository at this point in the history
  • Loading branch information
oleavr committed Feb 12, 2024
1 parent 6259a88 commit 44a29ef
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
18 changes: 12 additions & 6 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,18 @@ if ffi_dep.found() and (ffi_dep.type_name() == 'internal' or cc.has_function('ff
cdata.set('HAVE_FRIDA_LIBFFI', 1)
endif

if cc.has_function('pthread_attr_getstack',
args: ['-D_GNU_SOURCE'],
dependencies: [threads_dep],
prefix: '#include <pthread.h>')
cdata.set('HAVE_PTHREAD_ATTR_GETSTACK', 1)
endif
pthread_functions = [
'pthread_attr_getstack',
'pthread_setname_np',
]
foreach f : pthread_functions
if cc.has_function(f,
args: ['-D_GNU_SOURCE'],
dependencies: [threads_dep],
prefix: '#include <pthread.h>')
cdata.set('HAVE_' + f.to_upper(), 1)
endif
endforeach

if host_os_family == 'windows'
extra_deps += cc.find_library('psapi')
Expand Down
12 changes: 8 additions & 4 deletions tests/core/process.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008-2023 Ole André Vadla Ravnås <[email protected]>
* Copyright (C) 2008-2024 Ole André Vadla Ravnås <[email protected]>
* Copyright (C) 2008 Christian Berentsen <[email protected]>
* Copyright (C) 2015 Asger Hautop Drewsen <[email protected]>
* Copyright (C) 2023 Grant Douglas <[email protected]>
Expand Down Expand Up @@ -154,8 +154,8 @@ static gboolean thread_found_cb (const GumThreadDetails * details,
gpointer user_data);
static gboolean thread_check_cb (const GumThreadDetails * details,
gpointer user_data);
static gboolean thread_collect_if_matching_id (const GumThreadDetails * details,
gpointer user_data);
G_GNUC_UNUSED static gboolean thread_collect_if_matching_id (
const GumThreadDetails * details, gpointer user_data);
static gboolean module_found_cb (const GumModuleDetails * details,
gpointer user_data);
static gboolean import_found_cb (const GumImportDetails * details,
Expand Down Expand Up @@ -240,6 +240,9 @@ TESTCASE (process_threads_exclude_cloaked)

TESTCASE (process_threads_should_include_name)
{
#if defined (HAVE_LINUX) && !defined (HAVE_PTHREAD_SETNAME_NP)
g_print ("<skipping, libc is too old> ");
#else
volatile gboolean done = FALSE;
GThread * thread;
GumThreadDetails d = { 0, };
Expand All @@ -256,6 +259,7 @@ TESTCASE (process_threads_should_include_name)
g_thread_join (thread);

g_free ((gpointer) d.name);
#endif
}

static gboolean
Expand Down Expand Up @@ -1146,7 +1150,7 @@ sleeping_dummy (gpointer data)
* to GLib potentially having been prebuilt against an old libc. Therefore we
* set the name manually using pthreads.
*/
#ifdef HAVE_LINUX
#if defined (HAVE_LINUX) && defined (HAVE_PTHREAD_SETNAME_NP)
pthread_setname_np (pthread_self (), sync_data->name);
#endif

Expand Down
16 changes: 10 additions & 6 deletions tests/gumjs/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ static gpointer run_stalked_through_target_function (gpointer data);
#endif

static gpointer sleeping_dummy (gpointer data);
static gpointer named_sleeper (gpointer data);
G_GNUC_UNUSED static gpointer named_sleeper (gpointer data);

static gpointer invoke_target_function_int_worker (gpointer data);
static gpointer invoke_target_function_trigger (gpointer data);
Expand Down Expand Up @@ -5052,21 +5052,24 @@ sleeping_dummy (gpointer data)

TESTCASE (process_threads_have_names)
{
#if defined (HAVE_LINUX) && !defined (HAVE_PTHREAD_SETNAME_NP)
g_print ("<skipping, libc is too old> ");
#else
GumNamedSleeperContext ctx;
GThread * thread;

#ifdef HAVE_LINUX
# ifdef HAVE_LINUX
if (!check_exception_handling_testable ())
return;
#endif
# endif

#ifdef HAVE_MIPS
# ifdef HAVE_MIPS
if (!g_test_slow ())
{
g_print ("<skipping, run in slow mode> ");
return;
}
#endif
# endif

ctx.controller_messages = g_async_queue_new ();
ctx.sleeper_messages = g_async_queue_new ();
Expand All @@ -5085,6 +5088,7 @@ TESTCASE (process_threads_have_names)

g_async_queue_unref (ctx.sleeper_messages);
g_async_queue_unref (ctx.controller_messages);
#endif
}

static gpointer
Expand All @@ -5097,7 +5101,7 @@ named_sleeper (gpointer data)
* to GLib potentially having been prebuilt against an old libc. Therefore we
* set the name manually using pthreads.
*/
#ifdef HAVE_LINUX
#if defined (HAVE_LINUX) && defined (HAVE_PTHREAD_SETNAME_NP)
pthread_setname_np (pthread_self (), "named-sleeper");
#endif

Expand Down

0 comments on commit 44a29ef

Please sign in to comment.