@@ -26,8 +26,12 @@ extern "C" {
26
26
#include " debounce.h"
27
27
#include " timer.h"
28
28
29
- void set_time (uint32_t t);
30
- void advance_time (uint32_t ms);
29
+ void simulate_async_tick (uint32_t t);
30
+ void reset_access_counter (void );
31
+ uint32_t current_access_counter (void );
32
+ uint32_t timer_read_internal (void );
33
+ void set_time (uint32_t t);
34
+ void advance_time (uint32_t ms);
31
35
}
32
36
33
37
void DebounceTest::addEvents (std::initializer_list<DebounceTestEvent> events) {
@@ -58,6 +62,7 @@ void DebounceTest::runEventsInternal() {
58
62
/* Initialise keyboard with start time (offset to avoid testing at 0) and all keys UP */
59
63
debounce_init (MATRIX_ROWS);
60
64
set_time (time_offset_);
65
+ simulate_async_tick (async_time_jumps_);
61
66
std::fill (std::begin (input_matrix_), std::end (input_matrix_), 0 );
62
67
std::fill (std::begin (output_matrix_), std::end (output_matrix_), 0 );
63
68
@@ -70,9 +75,9 @@ void DebounceTest::runEventsInternal() {
70
75
advance_time (1 );
71
76
} else {
72
77
/* Fast forward to the time for this event, calling debounce() with no changes */
73
- ASSERT_LT ((time_offset_ + event.time_ ) - timer_read_fast (), 60000 ) << " Test tries to advance more than 1 minute of time" ;
78
+ ASSERT_LT ((time_offset_ + event.time_ ) - timer_read_internal (), 60000 ) << " Test tries to advance more than 1 minute of time" ;
74
79
75
- while (timer_read_fast () != time_offset_ + event.time_ ) {
80
+ while (timer_read_internal () != time_offset_ + event.time_ ) {
76
81
runDebounce (false );
77
82
checkCookedMatrix (false , " debounce() modified cooked matrix" );
78
83
advance_time (1 );
@@ -124,14 +129,20 @@ void DebounceTest::runDebounce(bool changed) {
124
129
std::copy (std::begin (input_matrix_), std::end (input_matrix_), std::begin (raw_matrix_));
125
130
std::copy (std::begin (output_matrix_), std::end (output_matrix_), std::begin (cooked_matrix_));
126
131
132
+ reset_access_counter ();
133
+
127
134
bool cooked_changed = debounce (raw_matrix_, cooked_matrix_, MATRIX_ROWS, changed);
128
135
129
136
if (!std::equal (std::begin (input_matrix_), std::end (input_matrix_), std::begin (raw_matrix_))) {
130
137
FAIL () << " Fatal error: debounce() modified raw matrix at " << strTime () << " \n input_matrix: changed=" << changed << " \n " << strMatrix (input_matrix_) << " \n raw_matrix:\n " << strMatrix (raw_matrix_);
131
138
}
132
139
133
- if (std::equal (std::begin (output_matrix_), std::end (output_matrix_), std::begin (cooked_matrix_)) && cooked_changed) {
134
- FAIL () << " Fatal error: debounce() did detect a wrong cooked matrix change at " << strTime () << " \n output_matrix: cooked_changed=" << cooked_changed << " \n " << strMatrix (output_matrix_) << " \n cooked_matrix:\n " << strMatrix (cooked_matrix_);
140
+ if (std::equal (std::begin (output_matrix_), std::end (output_matrix_), std::begin (cooked_matrix_)) == cooked_changed) {
141
+ FAIL () << " Fatal error: debounce() reported a wrong cooked matrix change result at " << strTime () << " \n output_matrix: cooked_changed=" << cooked_changed << " \n " << strMatrix (output_matrix_) << " \n cooked_matrix:\n " << strMatrix (cooked_matrix_);
142
+ }
143
+
144
+ if (current_access_counter () > 1 ) {
145
+ FAIL () << " Fatal error: debounce() read the timer multiple times, which is not allowed, at " << strTime () << " \n timer: access_count=" << current_access_counter () << " \n output_matrix: cooked_changed=" << cooked_changed << " \n " << strMatrix (output_matrix_) << " \n cooked_matrix:\n " << strMatrix (cooked_matrix_);
135
146
}
136
147
}
137
148
@@ -144,7 +155,7 @@ void DebounceTest::checkCookedMatrix(bool changed, const std::string &error_mess
144
155
std::string DebounceTest::strTime () {
145
156
std::stringstream text;
146
157
147
- text << " time " << (timer_read_fast () - time_offset_) << " (extra_iterations=" << extra_iterations_ << " , auto_advance_time=" << auto_advance_time_ << " )" ;
158
+ text << " time " << (timer_read_internal () - time_offset_) << " (extra_iterations=" << extra_iterations_ << " , auto_advance_time=" << auto_advance_time_ << " )" ;
148
159
149
160
return text.str ();
150
161
}
0 commit comments