Skip to content

Commit

Permalink
Fix test for checking user time of running thread
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Dec 23, 2022
1 parent ed24121 commit 8d6f34c
Showing 1 changed file with 25 additions and 32 deletions.
57 changes: 25 additions & 32 deletions tests/gumjs/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 8d6f34c

Please sign in to comment.