diff options
Diffstat (limited to 'quantum/debounce/tests/debounce_test_common.cpp')
-rw-r--r-- | quantum/debounce/tests/debounce_test_common.cpp | 72 |
1 files changed, 24 insertions, 48 deletions
diff --git a/quantum/debounce/tests/debounce_test_common.cpp b/quantum/debounce/tests/debounce_test_common.cpp index 1c5e7c9f4..f9414e571 100644 --- a/quantum/debounce/tests/debounce_test_common.cpp +++ b/quantum/debounce/tests/debounce_test_common.cpp | |||
@@ -31,9 +31,7 @@ void set_time(uint32_t t); | |||
31 | void advance_time(uint32_t ms); | 31 | void advance_time(uint32_t ms); |
32 | } | 32 | } |
33 | 33 | ||
34 | void DebounceTest::addEvents(std::initializer_list<DebounceTestEvent> events) { | 34 | void DebounceTest::addEvents(std::initializer_list<DebounceTestEvent> events) { events_.insert(events_.end(), events.begin(), events.end()); } |
35 | events_.insert(events_.end(), events.begin(), events.end()); | ||
36 | } | ||
37 | 35 | ||
38 | void DebounceTest::runEvents() { | 36 | void DebounceTest::runEvents() { |
39 | /* Run the test multiple times, from 1kHz to 10kHz scan rate */ | 37 | /* Run the test multiple times, from 1kHz to 10kHz scan rate */ |
@@ -54,7 +52,7 @@ void DebounceTest::runEvents() { | |||
54 | 52 | ||
55 | void DebounceTest::runEventsInternal() { | 53 | void DebounceTest::runEventsInternal() { |
56 | fast_timer_t previous = 0; | 54 | fast_timer_t previous = 0; |
57 | bool first = true; | 55 | bool first = true; |
58 | 56 | ||
59 | /* Initialise keyboard with start time (offset to avoid testing at 0) and all keys UP */ | 57 | /* Initialise keyboard with start time (offset to avoid testing at 0) and all keys UP */ |
60 | debounce_init(MATRIX_ROWS); | 58 | debounce_init(MATRIX_ROWS); |
@@ -80,7 +78,7 @@ void DebounceTest::runEventsInternal() { | |||
80 | } | 78 | } |
81 | } | 79 | } |
82 | 80 | ||
83 | first = false; | 81 | first = false; |
84 | previous = event.time_; | 82 | previous = event.time_; |
85 | 83 | ||
86 | /* Prepare input matrix */ | 84 | /* Prepare input matrix */ |
@@ -98,12 +96,7 @@ void DebounceTest::runEventsInternal() { | |||
98 | 96 | ||
99 | /* Check output matrix has expected change events */ | 97 | /* Check output matrix has expected change events */ |
100 | for (auto &output : event.outputs_) { | 98 | for (auto &output : event.outputs_) { |
101 | EXPECT_EQ(!!(cooked_matrix_[output.row_] & (1U << output.col_)), directionValue(output.direction_)) | 99 | EXPECT_EQ(!!(cooked_matrix_[output.row_] & (1U << output.col_)), directionValue(output.direction_)) << "Missing event at " << strTime() << " expected key " << output.row_ << "," << output.col_ << " " << directionLabel(output.direction_) << "\ninput_matrix: changed=" << !event.inputs_.empty() << "\n" << strMatrix(input_matrix_) << "\nexpected_matrix:\n" << strMatrix(output_matrix_) << "\nactual_matrix:\n" << strMatrix(cooked_matrix_); |
102 | << "Missing event at " << strTime() | ||
103 | << " expected key " << output.row_ << "," << output.col_ << " " << directionLabel(output.direction_) | ||
104 | << "\ninput_matrix: changed=" << !event.inputs_.empty() << "\n" << strMatrix(input_matrix_) | ||
105 | << "\nexpected_matrix:\n" << strMatrix(output_matrix_) | ||
106 | << "\nactual_matrix:\n" << strMatrix(cooked_matrix_); | ||
107 | } | 100 | } |
108 | 101 | ||
109 | /* Check output matrix has no other changes */ | 102 | /* Check output matrix has no other changes */ |
@@ -133,27 +126,20 @@ void DebounceTest::runDebounce(bool changed) { | |||
133 | debounce(raw_matrix_, cooked_matrix_, MATRIX_ROWS, changed); | 126 | debounce(raw_matrix_, cooked_matrix_, MATRIX_ROWS, changed); |
134 | 127 | ||
135 | if (!std::equal(std::begin(input_matrix_), std::end(input_matrix_), std::begin(raw_matrix_))) { | 128 | if (!std::equal(std::begin(input_matrix_), std::end(input_matrix_), std::begin(raw_matrix_))) { |
136 | FAIL() << "Fatal error: debounce() modified raw matrix at " << strTime() | 129 | FAIL() << "Fatal error: debounce() modified raw matrix at " << strTime() << "\ninput_matrix: changed=" << changed << "\n" << strMatrix(input_matrix_) << "\nraw_matrix:\n" << strMatrix(raw_matrix_); |
137 | << "\ninput_matrix: changed=" << changed << "\n" << strMatrix(input_matrix_) | ||
138 | << "\nraw_matrix:\n" << strMatrix(raw_matrix_); | ||
139 | } | 130 | } |
140 | } | 131 | } |
141 | 132 | ||
142 | void DebounceTest::checkCookedMatrix(bool changed, const std::string &error_message) { | 133 | void DebounceTest::checkCookedMatrix(bool changed, const std::string &error_message) { |
143 | if (!std::equal(std::begin(output_matrix_), std::end(output_matrix_), std::begin(cooked_matrix_))) { | 134 | if (!std::equal(std::begin(output_matrix_), std::end(output_matrix_), std::begin(cooked_matrix_))) { |
144 | FAIL() << "Unexpected event: " << error_message << " at " << strTime() | 135 | FAIL() << "Unexpected event: " << error_message << " at " << strTime() << "\ninput_matrix: changed=" << changed << "\n" << strMatrix(input_matrix_) << "\nexpected_matrix:\n" << strMatrix(output_matrix_) << "\nactual_matrix:\n" << strMatrix(cooked_matrix_); |
145 | << "\ninput_matrix: changed=" << changed << "\n" << strMatrix(input_matrix_) | ||
146 | << "\nexpected_matrix:\n" << strMatrix(output_matrix_) | ||
147 | << "\nactual_matrix:\n" << strMatrix(cooked_matrix_); | ||
148 | } | 136 | } |
149 | } | 137 | } |
150 | 138 | ||
151 | std::string DebounceTest::strTime() { | 139 | std::string DebounceTest::strTime() { |
152 | std::stringstream text; | 140 | std::stringstream text; |
153 | 141 | ||
154 | text << "time " << (timer_read_fast() - time_offset_) | 142 | text << "time " << (timer_read_fast() - time_offset_) << " (extra_iterations=" << extra_iterations_ << ", auto_advance_time=" << auto_advance_time_ << ")"; |
155 | << " (extra_iterations=" << extra_iterations_ | ||
156 | << ", auto_advance_time=" << auto_advance_time_ << ")"; | ||
157 | 143 | ||
158 | return text.str(); | 144 | return text.str(); |
159 | } | 145 | } |
@@ -181,49 +167,39 @@ std::string DebounceTest::strMatrix(matrix_row_t matrix[]) { | |||
181 | 167 | ||
182 | bool DebounceTest::directionValue(Direction direction) { | 168 | bool DebounceTest::directionValue(Direction direction) { |
183 | switch (direction) { | 169 | switch (direction) { |
184 | case DOWN: | 170 | case DOWN: |
185 | return true; | 171 | return true; |
186 | 172 | ||
187 | case UP: | 173 | case UP: |
188 | return false; | 174 | return false; |
189 | } | 175 | } |
190 | } | 176 | } |
191 | 177 | ||
192 | std::string DebounceTest::directionLabel(Direction direction) { | 178 | std::string DebounceTest::directionLabel(Direction direction) { |
193 | switch (direction) { | 179 | switch (direction) { |
194 | case DOWN: | 180 | case DOWN: |
195 | return "DOWN"; | 181 | return "DOWN"; |
196 | 182 | ||
197 | case UP: | 183 | case UP: |
198 | return "UP"; | 184 | return "UP"; |
199 | } | 185 | } |
200 | } | 186 | } |
201 | 187 | ||
202 | /* Modify a matrix and verify that events always specify a change */ | 188 | /* Modify a matrix and verify that events always specify a change */ |
203 | void DebounceTest::matrixUpdate(matrix_row_t matrix[], const std::string &name, const MatrixTestEvent &event) { | 189 | void DebounceTest::matrixUpdate(matrix_row_t matrix[], const std::string &name, const MatrixTestEvent &event) { |
204 | ASSERT_NE(!!(matrix[event.row_] & (1U << event.col_)), directionValue(event.direction_)) | 190 | ASSERT_NE(!!(matrix[event.row_] & (1U << event.col_)), directionValue(event.direction_)) << "Test " << name << " at " << strTime() << " sets key " << event.row_ << "," << event.col_ << " " << directionLabel(event.direction_) << " but it is already " << directionLabel(event.direction_) << "\n" << name << "_matrix:\n" << strMatrix(matrix); |
205 | << "Test " << name << " at " << strTime() | ||
206 | << " sets key " << event.row_ << "," << event.col_ << " " << directionLabel(event.direction_) | ||
207 | << " but it is already " << directionLabel(event.direction_) | ||
208 | << "\n" << name << "_matrix:\n" << strMatrix(matrix); | ||
209 | 191 | ||
210 | switch (event.direction_) { | 192 | switch (event.direction_) { |
211 | case DOWN: | 193 | case DOWN: |
212 | matrix[event.row_] |= (1U << event.col_); | 194 | matrix[event.row_] |= (1U << event.col_); |
213 | break; | 195 | break; |
214 | 196 | ||
215 | case UP: | 197 | case UP: |
216 | matrix[event.row_] &= ~(1U << event.col_); | 198 | matrix[event.row_] &= ~(1U << event.col_); |
217 | break; | 199 | break; |
218 | } | 200 | } |
219 | } | 201 | } |
220 | 202 | ||
221 | DebounceTestEvent::DebounceTestEvent(fast_timer_t time, | 203 | DebounceTestEvent::DebounceTestEvent(fast_timer_t time, std::initializer_list<MatrixTestEvent> inputs, std::initializer_list<MatrixTestEvent> outputs) : time_(time), inputs_(inputs), outputs_(outputs) {} |
222 | std::initializer_list<MatrixTestEvent> inputs, | ||
223 | std::initializer_list<MatrixTestEvent> outputs) | ||
224 | : time_(time), inputs_(inputs), outputs_(outputs) { | ||
225 | } | ||
226 | 204 | ||
227 | MatrixTestEvent::MatrixTestEvent(int row, int col, Direction direction) | 205 | MatrixTestEvent::MatrixTestEvent(int row, int col, Direction direction) : row_(row), col_(col), direction_(direction) {} |
228 | : row_(row), col_(col), direction_(direction) { | ||
229 | } | ||