Skip to content

Commit 2f7cc4a

Browse files
dcpleungMaureenHelm
authored andcommitted
tests: thread_apis: move uptime gathering in join scenario
When doing test_thread_join with OTHER_ABORT_TIMEOUT, the interval between two k_uptime_get() includes the two k_thread_create() which means the interval delta does not exactly count the time spent in k_thread_join(). On x86_64 with userspace, time spent inside k_thread_create() scales with memory size as it needs to create a new page table for the thread. So to actually measure the time spent in k_thread_join(), the locations where uptime is obtained need to be moved. Fixes #28549 Signed-off-by: Daniel Leung <[email protected]>
1 parent 470176e commit 2f7cc4a

File tree

1 file changed

+18
-5
lines changed
  • tests/kernel/threads/thread_apis/src

1 file changed

+18
-5
lines changed

tests/kernel/threads/thread_apis/src/main.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ void do_join_from_isr(const void *arg)
328328

329329
#define JOIN_TIMEOUT_MS 100
330330

331-
int join_scenario(enum control_method m)
331+
int join_scenario_interval(enum control_method m, int64_t *interval)
332332
{
333333
k_timeout_t timeout = K_FOREVER;
334334
int ret;
@@ -368,7 +368,17 @@ int join_scenario(enum control_method m)
368368
irq_offload(do_join_from_isr, (const void *)&ret);
369369
} else {
370370
printk("ztest_thread: joining join_thread\n");
371+
372+
if (interval != NULL) {
373+
*interval = k_uptime_get();
374+
}
375+
371376
ret = k_thread_join(&join_thread, timeout);
377+
378+
if (interval != NULL) {
379+
*interval = k_uptime_get() - *interval;
380+
}
381+
372382
printk("ztest_thread: k_thread_join() returned with %d\n", ret);
373383
}
374384

@@ -382,6 +392,11 @@ int join_scenario(enum control_method m)
382392
return ret;
383393
}
384394

395+
static inline int join_scenario(enum control_method m)
396+
{
397+
return join_scenario_interval(m, NULL);
398+
}
399+
385400
void test_thread_join(void)
386401
{
387402
int64_t interval;
@@ -396,10 +411,8 @@ void test_thread_join(void)
396411
zassert_equal(join_scenario(SELF_ABORT), 0, "failed self-abort case");
397412
zassert_equal(join_scenario(OTHER_ABORT), 0, "failed other-abort case");
398413

399-
interval = k_uptime_get();
400-
zassert_equal(join_scenario(OTHER_ABORT_TIMEOUT), 0,
401-
"failed other-abort case with timeout");
402-
interval = k_uptime_get() - interval;
414+
zassert_equal(join_scenario_interval(OTHER_ABORT_TIMEOUT, &interval),
415+
0, "failed other-abort case with timeout");
403416
zassert_true(interval < JOIN_TIMEOUT_MS, "join took too long (%lld ms)",
404417
interval);
405418
zassert_equal(join_scenario(ALREADY_EXIT), 0,

0 commit comments

Comments
 (0)