diff --git a/tests/gumjs/script.c b/tests/gumjs/script.c index 46fe89b31..61459eae8 100644 --- a/tests/gumjs/script.c +++ b/tests/gumjs/script.c @@ -5039,6 +5039,12 @@ TESTCASE (process_threads_have_names) TESTCASE (process_threads_have_user_time) { + GThread * thread; + GumThreadId thread_id; + volatile gboolean done = FALSE; + + thread = create_sleeping_dummy_thread_sync (&done, &thread_id); + #ifdef HAVE_LINUX if (!check_exception_handling_testable ()) return; @@ -5053,53 +5059,40 @@ TESTCASE (process_threads_have_user_time) #endif #if defined (HAVE_LINUX) && !defined (HAVE_ANDROID) - COMPILE_AND_LOAD_SCRIPT ( - "function fibonacci(num) {" - " if(num < 2) {" - " return num;" - " }" - " else {" - " return fibonacci(num-1) + fibonacci(num - 2);" - " }" - "}" - "const tid = Process.getCurrentThreadId();" - "fibonacci(30);" + COMPILE_AND_LOAD_SCRIPT ( + "Thread.sleep(0.25);" "const userTimeA = Process.enumerateThreads()" - " .find(t => t.id == tid)" + " .find(t => t.id == " GUM_PTR_CONST ")" " .userTime;" "send(userTimeA != 0);" - "fibonacci(30);" + "Thread.sleep(0.25);" "const userTimeB = Process.enumerateThreads()" - " .find(t => t.id == tid)" + " .find(t => t.id == " GUM_PTR_CONST ")" " .userTime;" - "send(userTimeB > userTimeA);" - ); + "send(userTimeB > userTimeA);", + thread_id, + thread_id); #else - COMPILE_AND_LOAD_SCRIPT ( - "function fibonacci(num) {" - " if(num < 2) {" - " return num;" - " }" - " else {" - " return fibonacci(num-1) + fibonacci(num - 2);" - " }" - "}" - "const tid = Process.getCurrentThreadId();" - "fibonacci(30);" + COMPILE_AND_LOAD_SCRIPT ( + "Thread.sleep(0.25);" "const userTimeA = Process.enumerateThreads()" - " .find(t => t.id == tid)" + " .find(t => t.id == " GUM_PTR_CONST ")" " .userTime;" "send(userTimeA == 0);" - "fibonacci(30);" + "Thread.sleep(0.25);" "const userTimeB = Process.enumerateThreads()" - " .find(t => t.id == tid)" + " .find(t => t.id == " GUM_PTR_CONST ")" " .userTime;" - "send(userTimeB == 0);" - ); + "send(userTimeB == 0);", + thread_id, + thread_id); #endif EXPECT_SEND_MESSAGE_WITH ("true"); EXPECT_SEND_MESSAGE_WITH ("true"); + + done = TRUE; + g_thread_join (thread); } static gpointer