From fc9fb2c77505cf1dcf5d1f50dd61a980471b3494 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Sun, 25 Jul 2021 17:18:09 +0100 Subject: Allow output of logging when running unit tests (#13556) * Initial pass at enabling logging for unit tests * Add to docs * Bind debug for more test types * Force everything * Tidy up slightly --- tests/test_common/main.cpp | 32 ++++++++++++++++++++++++++++++++ tests/test_common/test_fixture.cpp | 8 ++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 tests/test_common/main.cpp (limited to 'tests') diff --git a/tests/test_common/main.cpp b/tests/test_common/main.cpp new file mode 100644 index 0000000000..3e4b4c0f95 --- /dev/null +++ b/tests/test_common/main.cpp @@ -0,0 +1,32 @@ +#include "gtest/gtest.h" + +extern "C" { +#include "stdio.h" +#include "debug.h" + +int8_t sendchar(uint8_t c) { + fprintf(stderr, "%c", c); + return 0; +} + +__attribute__((weak)) debug_config_t debug_config = {0}; + +void init_logging(void) { + print_set_sendchar(sendchar); + + // Customise these values to desired behaviour + // debug_enable = true; + // debug_matrix = true; + // debug_keyboard = true; + // debug_mouse = true; + debug_config.raw = 0xFF; +} +} + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + + init_logging(); + + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/tests/test_common/test_fixture.cpp b/tests/test_common/test_fixture.cpp index 20ed838eb6..e041df7128 100644 --- a/tests/test_common/test_fixture.cpp +++ b/tests/test_common/test_fixture.cpp @@ -7,10 +7,10 @@ #include "action_tapping.h" extern "C" { +#include "debug.h" +#include "eeconfig.h" #include "action_layer.h" -} -extern "C" { void set_time(uint32_t t); void advance_time(uint32_t ms); } @@ -21,6 +21,10 @@ using testing::Between; using testing::Return; void TestFixture::SetUpTestCase() { + // The following is enough to bootstrap the values set in main + eeconfig_init_quantum(); + eeconfig_update_debug(debug_config.raw); + TestDriver driver; EXPECT_CALL(driver, send_keyboard_mock(_)); keyboard_init(); -- cgit v1.2.1