Skip to content

Commit c228c08

Browse files
committed
testing/ostest: Fix Coverity for spinlock test.
This commit fixed coverity for spinlock test. Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
1 parent c3d6034 commit c228c08

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

testing/ostest/spinlock.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,20 @@ void run_test_thread(void *lock, FAR void *(*thread_func)(FAR void *arg),
215215
total_ns += param[i].delta;
216216
}
217217

218-
printf("%s: Test Results:\n", lock_type);
219-
printf("%s: Final counter: %" PRIu32 "\n", lock_type, pub.counter);
220-
assert(pub.counter == thread_num * LOOP_TIMES);
221-
printf("%s: Average throughput : %" PRIu64 " op/s\n", lock_type,
222-
(uint64_t)NSEC_PER_SEC * LOOP_TIMES * thread_num / total_ns);
223-
printf("%s: Total execution time: %" PRIu64 " ns\n \n",
224-
lock_type, calc_diff(&stime, &etime));
218+
if (total_ns != 0)
219+
{
220+
printf("%s: Test Results:\n", lock_type);
221+
printf("%s: Final counter: %" PRIu32 "\n", lock_type, pub.counter);
222+
assert(pub.counter == thread_num * LOOP_TIMES);
223+
printf("%s: Average throughput : %" PRIu64 " op/s\n", lock_type,
224+
(uint64_t)NSEC_PER_SEC * LOOP_TIMES * thread_num / total_ns);
225+
printf("%s: Total execution time: %" PRIu64 " ns\n \n",
226+
lock_type, calc_diff(&stime, &etime));
227+
}
228+
else
229+
{
230+
printf("spinlock_test: ERROR: total_ns is 0\n");
231+
}
225232
}
226233

227234
/****************************************************************************
@@ -258,7 +265,7 @@ void spinlock_test(void)
258265
{
259266
unsigned tnr;
260267

261-
for (tnr = 1; tnr < MAX_THREAD_NUM; tnr++)
268+
for (tnr = 1; tnr <= MAX_THREAD_NUM; tnr++)
262269
{
263270
spinlock_test_thread_num(tnr);
264271
}

0 commit comments

Comments
 (0)