Skip to content

Commit acb6aee

Browse files
committed
Adde setUp and tearDown functions
1 parent c6d1c1d commit acb6aee

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

Diff for: tests/timer/timer.ino

+14-19
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,26 @@
77
hw_timer_t * timer = NULL;
88
static volatile bool alarm_flag;
99

10+
/* These functions are intended to be called before and after each test. */
11+
void setUp(void) {
12+
timer = timerBegin(0, TIMER_DIVIDER, true);
13+
timerStop(timer);
14+
timerRestart(timer);
15+
}
16+
17+
void tearDown(void){
18+
timerEnd(timer);
19+
}
20+
21+
22+
1023
void ARDUINO_ISR_ATTR onTimer(){
11-
//Serial.println("Timer ISR triggered");
1224
alarm_flag = true;
1325
}
1426

1527

1628
void timer_interrupt_test(void){
17-
18-
timer = timerBegin(0, TIMER_DIVIDER, true);
19-
timerStop(timer);
20-
timerRestart(timer);
21-
29+
2230
alarm_flag = false;
2331
timerAttachInterrupt(timer, &onTimer, true);
2432
timerAlarmWrite(timer, (1.2 * TIMER_SCALE), true);
@@ -37,19 +45,13 @@ void timer_interrupt_test(void){
3745

3846
delay(2000);
3947
TEST_ASSERT_EQUAL(false, alarm_flag);
40-
41-
timerEnd(timer);
42-
4348
}
4449

4550
void timer_divider_test(void){
4651

4752
uint64_t time_val;
4853
uint64_t comp_time_val;
4954

50-
timer = timerBegin(0, TIMER_DIVIDER, true);
51-
timerStop(timer);
52-
timerRestart(timer);
5355
timerStart(timer);
5456

5557
delay(1000);
@@ -76,24 +78,17 @@ void timer_divider_test(void){
7678
comp_time_val = timerRead(timer);
7779
TEST_ASSERT_INT_WITHIN(5000, 5000000, time_val);
7880
TEST_ASSERT_INT_WITHIN(3126, 312500, comp_time_val);
79-
80-
timerEnd(timer);
8181
}
8282

8383
void timer_read_test(void){
8484

8585
uint64_t set_timer_val = 0xFF;
8686
uint64_t get_timer_val = 0;
8787

88-
timer = timerBegin(0, TIMER_DIVIDER, true);
89-
timerStop(timer);
90-
9188
timerWrite(timer,set_timer_val);
9289
get_timer_val = timerRead(timer);
9390

9491
TEST_ASSERT_EQUAL(set_timer_val, get_timer_val);
95-
96-
timerEnd(timer);
9792
}
9893

9994
void setup(){

0 commit comments

Comments
 (0)