Skip to content

Commit b521778

Browse files
committed
tests: drivers: counter: Fix coverity issues
Issues 190937, 190952, 190967, 190983 Signed-off-by: Krzysztof Chruscinski <[email protected]>
1 parent 6368ed4 commit b521778

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

tests/drivers/counter/counter_basic_api/src/test_counter.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ void test_set_top_value_with_alarm_instance(const char *dev_name)
121121
int err;
122122
u32_t cnt;
123123
u32_t ticks;
124+
u32_t tmp_top_cnt;
124125

125126
top_cnt = 0;
126127

@@ -141,9 +142,10 @@ void test_set_top_value_with_alarm_instance(const char *dev_name)
141142

142143
k_busy_wait(5.2*COUNTER_PERIOD_US);
143144

144-
zassert_true((u32_t)top_cnt == 5,
145+
tmp_top_cnt = top_cnt; /* to avoid passing volatile to the macro */
146+
zassert_true(tmp_top_cnt == 5,
145147
"Unexpected number of turnarounds (%d) (dev: %s).\n",
146-
(u32_t)top_cnt, dev_name);
148+
tmp_top_cnt, dev_name);
147149
}
148150

149151
void test_set_top_value_with_alarm(void)
@@ -168,6 +170,7 @@ void test_single_shot_alarm_instance(const char *dev_name, bool set_top)
168170
struct device *dev;
169171
int err;
170172
u32_t ticks;
173+
u32_t tmp_alarm_cnt;
171174

172175
dev = device_get_binding(dev_name);
173176
ticks = counter_us_to_ticks(dev, COUNTER_PERIOD_US);
@@ -205,10 +208,12 @@ void test_single_shot_alarm_instance(const char *dev_name, bool set_top)
205208
zassert_equal(0, err, "Counter set alarm failed\n");
206209

207210
k_busy_wait(1.5*counter_ticks_to_us(dev, ticks));
208-
zassert_equal(1, (u32_t)alarm_cnt, "Expecting alarm callback\n");
211+
tmp_alarm_cnt = alarm_cnt; /* to avoid passing volatile to the macro */
212+
zassert_equal(1, tmp_alarm_cnt, "Expecting alarm callback\n");
209213

210214
k_busy_wait(1.5*counter_ticks_to_us(dev, ticks));
211-
zassert_equal(1, (u32_t)alarm_cnt, "Expecting alarm callback\n");
215+
tmp_alarm_cnt = alarm_cnt; /* to avoid passing volatile to the macro */
216+
zassert_equal(1, tmp_alarm_cnt, "Expecting alarm callback\n");
212217

213218
err = counter_cancel_channel_alarm(dev, 0);
214219
zassert_equal(0, err, "Counter disabling alarm failed\n");
@@ -266,6 +271,7 @@ void test_multiple_alarms_instance(const char *dev_name)
266271
struct device *dev;
267272
int err;
268273
u32_t ticks;
274+
u32_t tmp_alarm_cnt;
269275

270276
dev = device_get_binding(dev_name);
271277
ticks = counter_us_to_ticks(dev, COUNTER_PERIOD_US);
@@ -302,7 +308,8 @@ void test_multiple_alarms_instance(const char *dev_name)
302308
zassert_equal(0, err, "Counter set alarm failed\n");
303309

304310
k_busy_wait(1.2*counter_ticks_to_us(dev, 2*ticks));
305-
zassert_equal(2, (u32_t)alarm_cnt, "Counter set alarm failed\n");
311+
tmp_alarm_cnt = alarm_cnt; /* to avoid passing volatile to the macro */
312+
zassert_equal(2, tmp_alarm_cnt, "Counter set alarm failed\n");
306313
zassert_equal(&alarm_cfg2, clbk_data[0],
307314
"Expected different order or callbacks\n");
308315
zassert_equal(&alarm_cfg, clbk_data[1],
@@ -330,6 +337,7 @@ void test_all_channels_instance(const char *str)
330337
bool limit_reached = false;
331338
struct counter_alarm_cfg alarm_cfgs;
332339
u32_t ticks;
340+
u32_t tmp_alarm_cnt;
333341

334342
dev = device_get_binding(str);
335343
ticks = counter_us_to_ticks(dev, COUNTER_PERIOD_US);
@@ -355,7 +363,8 @@ void test_all_channels_instance(const char *str)
355363
}
356364

357365
k_busy_wait(1.5*counter_ticks_to_us(dev, ticks));
358-
zassert_equal(nchan, (u32_t)alarm_cnt, "Expecting alarm callback\n");
366+
tmp_alarm_cnt = alarm_cnt; /* to avoid passing volatile to the macro */
367+
zassert_equal(nchan, tmp_alarm_cnt, "Expecting alarm callback\n");
359368

360369
for (int i = 0; i < nchan; i++) {
361370
err = counter_cancel_channel_alarm(dev, i);

0 commit comments

Comments
 (0)