[Test] Reset timer for every unit test and provide timestamps for log messages (#17028)

This commit is contained in:
Stefan Kerkmann 2022-12-14 16:31:08 +01:00 committed by GitHub
parent e2ab98f960
commit 962e4c0e18
Failed to generate hash of commit
20 changed files with 1011 additions and 41 deletions

View file

@ -15,16 +15,26 @@
*/
#include "test_keymap_key.hpp"
#include <cstdint>
#include <ios>
#include "matrix.h"
#include "test_logger.hpp"
#include "gtest/gtest-message.h"
#include "gtest/gtest.h"
#include "timer.h"
void KeymapKey::press() {
test_logger.trace() << "Key pressed: (" << +this->position.col << "," << +this->position.row << ")" << std::endl;
EXPECT_FALSE(matrix_is_on(position.row, position.col)) << "tried to press key " << this->name << " that was already pressed! Check the test code." << std::endl;
press_key(this->position.col, this->position.row);
this->timestamp_pressed = timer_read32();
test_logger.trace() << std::setw(10) << std::left << "pressed: " << this->name << std::endl;
}
void KeymapKey::release() {
test_logger.trace() << "Key released: (" << +this->position.col << "," << +this->position.row << ")" << std::endl;
EXPECT_TRUE(matrix_is_on(this->position.row, this->position.col)) << "tried to release key " << this->name << " that wasn't pressed before! Check the test code." << std::endl;
release_key(this->position.col, this->position.row);
}
uint32_t now = timer_read32();
test_logger.trace() << std::setw(10) << std::left << "released: " << this->name << " was pressed for " << now - this->timestamp_pressed << "ms" << std::endl;
}