Skip to content

Commit 3d6785b

Browse files
Fix-Pointxiaoxiang781216
authored andcommitted
testing/ostest: Fix busyloop on tee platform
This patch fixed busyloop on tee platform. Signed-off-by: ouyangxiangzhen <[email protected]>
1 parent b01765c commit 3d6785b

File tree

1 file changed

+31
-50
lines changed

1 file changed

+31
-50
lines changed

testing/ostest/wdog.c

Lines changed: 31 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
#define wdtest_printf(...) printf(__VA_ARGS__)
4545

46-
#define wdtest_delay(delay_us) usleep(delay_us)
46+
#define wdtest_delay(delay_ns) usleep(delay_ns / 1000 + 1)
4747

4848
/****************************************************************************
4949
* Private Type
@@ -74,97 +74,89 @@ static void wdtest_callback(wdparm_t param)
7474
}
7575

7676
static void wdtest_once(FAR struct wdog_s *wdog, FAR wdtest_param_t *param,
77-
sclock_t delay_us)
77+
sclock_t delay_ns)
7878
{
7979
uint64_t cnt;
8080
long long diff;
8181
clock_t wdset_tick;
8282
struct timespec tp;
83-
clock_t delay_ticks = USEC2TICK((clock_t)delay_us);
83+
clock_t delay_ticks = (clock_t)NSEC2TICK((clock_t)delay_ns);
8484

85-
wdtest_printf("wdtest_once %lld us\n", (long long)delay_us);
85+
wdtest_printf("wdtest_once %lld ns\n", (long long)delay_ns);
8686

8787
clock_gettime(CLOCK_MONOTONIC, &tp);
8888

8989
wdset_tick = clock_time2ticks(&tp);
9090
cnt = param->callback_cnt;
91+
9192
wdtest_assert(wd_start(wdog, delay_ticks, wdtest_callback,
9293
(wdparm_t)param) == OK);
9394

94-
while (cnt + 1 != param->callback_cnt)
95-
{
96-
wdtest_delay(delay_us);
97-
}
95+
wdtest_delay(delay_ns);
9896

9997
diff = (long long)(param->triggered_tick - wdset_tick);
10098

101-
/* Ensure diff - delay_ticks is within the tolerance limit. */
99+
wdtest_assert(cnt + 1 == param->callback_cnt);
102100

103-
wdtest_assert(diff - delay_ticks >= 0);
104-
wdtest_assert(diff - delay_ticks <
105-
USEC2TICK(WDOGTEST_TOLERENT_LATENCY_US) + 1);
101+
/* Ensure diff - delay_ticks >= 0. */
102+
103+
wdtest_assert(diff - (long long)delay_ticks >= 0);
106104
wdtest_printf("wdtest_once latency ticks %lld\n", diff - delay_ticks);
107105
}
108106

109107
static void wdtest_rand(FAR struct wdog_s *wdog, FAR wdtest_param_t *param,
110-
sclock_t rand_us)
108+
sclock_t rand_ns)
111109
{
112110
int idx;
113-
sclock_t delay_us;
114-
uint64_t cnt = param->callback_cnt;
111+
sclock_t delay_ns;
115112

116113
for (idx = 0; idx < WDOGTEST_RAND_ITER; idx++)
117114
{
118-
delay_us = rand() % rand_us;
119-
wdtest_assert(wd_start(wdog, USEC2TICK(delay_us), wdtest_callback,
115+
delay_ns = rand() % rand_ns;
116+
wdtest_assert(wd_start(wdog, NSEC2TICK(delay_ns), wdtest_callback,
120117
(wdparm_t)param) == 0);
121118

122119
/* Wait or Cancel 50/50 */
123120

124-
if (delay_us % 2)
121+
if (delay_ns % 2)
125122
{
126-
while (cnt + 1 != param->callback_cnt)
127-
{
128-
wdtest_delay(delay_us);
129-
}
123+
wdtest_delay(delay_ns);
130124
}
131125
else
132126
{
133127
wd_cancel(wdog);
134128
}
135-
136-
cnt = param->callback_cnt;
137129
}
138130
}
139131

140132
static void wdtest_callback_recursive(wdparm_t param)
141133
{
142134
struct timespec tp;
143135
FAR wdtest_param_t *wdtest_param = (FAR wdtest_param_t *)param;
144-
sclock_t interval = wdtest_param->interval;
145-
146-
wd_start(wdtest_param->wdog, interval,
147-
wdtest_callback_recursive, param);
136+
sclock_t interval = wdtest_param->interval;
148137

149138
clock_gettime(CLOCK_MONOTONIC, &tp);
150139

151140
wdtest_param->callback_cnt += 1;
152141
wdtest_param->triggered_tick = clock_time2ticks(&tp);
142+
143+
wd_start(wdtest_param->wdog, interval,
144+
wdtest_callback_recursive, param);
153145
}
154146

155147
static void wdtest_recursive(FAR struct wdog_s *wdog,
156148
FAR wdtest_param_t *param,
157-
sclock_t delay_us,
149+
sclock_t delay_ns,
158150
unsigned int times)
159151
{
160152
uint64_t cnt;
161153
struct timespec tp;
162154
clock_t wdset_tick;
163155

164-
wdtest_printf("wdtest_recursive %lldus\n", (long long)delay_us);
156+
wdtest_printf("wdtest_recursive %lldus\n", (long long)delay_ns);
165157
cnt = param->callback_cnt;
166158
param->wdog = wdog;
167-
param->interval = (sclock_t)USEC2TICK((clock_t)delay_us);
159+
param->interval = (sclock_t)NSEC2TICK((clock_t)delay_ns);
168160

169161
wdtest_assert(param->interval >= 0);
170162

@@ -175,15 +167,12 @@ static void wdtest_recursive(FAR struct wdog_s *wdog,
175167
wdtest_callback_recursive,
176168
(wdparm_t)param) == OK);
177169

178-
while (param->callback_cnt < cnt + times)
179-
{
180-
wdtest_delay(delay_us);
181-
}
170+
wdtest_delay(times * delay_ns);
182171

183172
wdtest_assert(wd_cancel(param->wdog) == 0);
184173

185-
wdtest_printf("recursive wdog triggered %u times, elapsed tick %lld\n",
186-
times,
174+
wdtest_printf("recursive wdog triggered %llu times, elapsed tick %lld\n",
175+
(unsigned long long)(param->callback_cnt - cnt),
187176
(long long)(param->triggered_tick - wdset_tick));
188177
}
189178

@@ -253,7 +242,8 @@ static void wdog_test_run(FAR wdtest_param_t *param)
253242

254243
wdtest_assert(rest < delay && rest > (delay >> 1));
255244

256-
wdtest_printf("wd_start with maximum delay, cancel %ld\n", (long)rest);
245+
wdtest_printf("wd_start with maximum delay, cancel %lld\n",
246+
(long long)rest);
257247

258248
wdtest_assert(wd_cancel(&test_wdog) == 0);
259249

@@ -264,19 +254,10 @@ static void wdog_test_run(FAR wdtest_param_t *param)
264254
wdtest_callback, (wdparm_t)param) != OK);
265255
wdtest_assert(wd_gettime(&test_wdog) == 0);
266256

267-
/* Recursive wdog delay from 10us to 1000us */
257+
/* Recursive wdog delay from 1000us to 10000us */
268258

269-
wdtest_recursive(&test_wdog, param, 10, 1000);
270-
wdtest_delay(10);
271-
wdtest_recursive(&test_wdog, param, 100, 100);
272-
wdtest_delay(10);
273-
wdtest_recursive(&test_wdog, param, 1000, 10);
274-
wdtest_delay(10);
275-
276-
/* Random delay ~1us */
277-
278-
wdtest_rand(&test_wdog, param, 1024);
279-
wdtest_delay(10);
259+
wdtest_recursive(&test_wdog, param, 1000000, 100);
260+
wdtest_recursive(&test_wdog, param, 10000000, 10);
280261

281262
/* Random delay ~12us */
282263

0 commit comments

Comments
 (0)