From 44a29efa6b189d3e1442266e2d645c6cb9f54654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Mon, 12 Feb 2024 22:06:43 +0000 Subject: [PATCH] tests: Skip thread name tests if libc is too old --- meson.build | 18 ++++++++++++------ tests/core/process.c | 12 ++++++++---- tests/gumjs/script.c | 16 ++++++++++------ 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/meson.build b/meson.build index 110aff56c..73765901b 100644 --- a/meson.build +++ b/meson.build @@ -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 ') - 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 ') + cdata.set('HAVE_' + f.to_upper(), 1) + endif +endforeach if host_os_family == 'windows' extra_deps += cc.find_library('psapi') diff --git a/tests/core/process.c b/tests/core/process.c index 8fa67d813..b46db3bf2 100644 --- a/tests/core/process.c +++ b/tests/core/process.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2023 Ole André Vadla Ravnås + * Copyright (C) 2008-2024 Ole André Vadla Ravnås * Copyright (C) 2008 Christian Berentsen * Copyright (C) 2015 Asger Hautop Drewsen * Copyright (C) 2023 Grant Douglas @@ -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, @@ -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 (" "); +#else volatile gboolean done = FALSE; GThread * thread; GumThreadDetails d = { 0, }; @@ -256,6 +259,7 @@ TESTCASE (process_threads_should_include_name) g_thread_join (thread); g_free ((gpointer) d.name); +#endif } static gboolean @@ -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 diff --git a/tests/gumjs/script.c b/tests/gumjs/script.c index a1bcbdd6f..d4060b028 100644 --- a/tests/gumjs/script.c +++ b/tests/gumjs/script.c @@ -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); @@ -5052,21 +5052,24 @@ sleeping_dummy (gpointer data) TESTCASE (process_threads_have_names) { +#if defined (HAVE_LINUX) && !defined (HAVE_PTHREAD_SETNAME_NP) + g_print (" "); +#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 (" "); return; } -#endif +# endif ctx.controller_messages = g_async_queue_new (); ctx.sleeper_messages = g_async_queue_new (); @@ -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 @@ -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