Skip to content

Commit e5af53a

Browse files
pabigotnashif
authored andcommitted
tests: kernel: critical: add output to support diagnostics
As implemented this test runs for 20 s with no output, which makes it difficult to identify the cause of failure. Add output indicating progress, and emit diagnostics a particular failure observed on iMX boards. Signed-off-by: Peter Bigot <[email protected]>
1 parent d70b4aa commit e5af53a

File tree

1 file changed

+21
-7
lines changed
  • tests/kernel/critical/src

1 file changed

+21
-7
lines changed

tests/kernel/critical/src/main.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,31 @@ void critical_rtn(struct k_work *unused)
7878
*
7979
* @brief Common code for invoking offload work
8080
*
81+
* @param tag text identifying the invocation context
82+
*
8183
* @param count number of critical section calls made thus far
8284
*
8385
* @return number of critical section calls made by a thread
8486
*/
8587

86-
u32_t critical_loop(u32_t count)
88+
u32_t critical_loop(const char *tag,
89+
u32_t count)
8790
{
91+
s64_t now;
92+
s64_t last;
8893
s64_t mseconds;
8994

90-
mseconds = k_uptime_get();
91-
while (k_uptime_get() < mseconds + NUM_MILLISECONDS) {
95+
last = mseconds = k_uptime_get();
96+
TC_PRINT("Start %s at %u\n", tag, (u32_t)last);
97+
while (((now = k_uptime_get())) < mseconds + NUM_MILLISECONDS) {
9298
struct k_work work_item;
9399

100+
if (now < last) {
101+
TC_PRINT("Time went backwards: %u < %u\n",
102+
(u32_t)now, (u32_t)last);
103+
}
104+
last = now;
105+
94106
k_work_init(&work_item, critical_rtn);
95107
k_work_submit_to_queue(&offload_work_q, &work_item);
96108
count++;
@@ -103,6 +115,7 @@ u32_t critical_loop(u32_t count)
103115
*/
104116
#endif
105117
}
118+
TC_PRINT("End %s at %u\n", tag, (u32_t)now);
106119

107120
return count;
108121
}
@@ -124,13 +137,13 @@ void alternate_thread(void *arg1, void *arg2, void *arg3)
124137

125138
k_sem_take(&ALT_SEM, K_FOREVER); /* Wait to be activated */
126139

127-
alt_thread_iterations = critical_loop(alt_thread_iterations);
140+
alt_thread_iterations = critical_loop("alt1", alt_thread_iterations);
128141

129142
k_sem_give(&REGRESS_SEM);
130143

131144
k_sem_take(&ALT_SEM, K_FOREVER); /* Wait to be re-activated */
132145

133-
alt_thread_iterations = critical_loop(alt_thread_iterations);
146+
alt_thread_iterations = critical_loop("alt2", alt_thread_iterations);
134147

135148
k_sem_give(&REGRESS_SEM);
136149
}
@@ -156,7 +169,7 @@ void regression_thread(void *arg1, void *arg2, void *arg3)
156169

157170
k_sem_give(&ALT_SEM); /* Activate alternate_thread() */
158171

159-
ncalls = critical_loop(ncalls);
172+
ncalls = critical_loop("reg1", ncalls);
160173

161174
/* Wait for alternate_thread() to complete */
162175
zassert_true(k_sem_take(&REGRESS_SEM, TEST_TIMEOUT) == 0,
@@ -165,11 +178,12 @@ void regression_thread(void *arg1, void *arg2, void *arg3)
165178
zassert_equal(critical_var, ncalls + alt_thread_iterations,
166179
"Unexpected value for <critical_var>");
167180

181+
TC_PRINT("Enable timeslicing at %u\n", k_uptime_get_32());
168182
k_sched_time_slice_set(10, 10);
169183

170184
k_sem_give(&ALT_SEM); /* Re-activate alternate_thread() */
171185

172-
ncalls = critical_loop(ncalls);
186+
ncalls = critical_loop("reg2", ncalls);
173187

174188
/* Wait for alternate_thread() to finish */
175189
zassert_true(k_sem_take(&REGRESS_SEM, TEST_TIMEOUT) == 0,

0 commit comments

Comments
 (0)