diff options
| author | Joel Challis <git@zvecr.com> | 2021-07-25 17:18:09 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-25 17:18:09 +0100 |
| commit | fc9fb2c77505cf1dcf5d1f50dd61a980471b3494 (patch) | |
| tree | 3dce233f23dbe991c4dee0a63eb4dc0fe9c2b6f5 /tests | |
| parent | b69e7431aa2e22b4f4662c64e84ed242caac055e (diff) | |
| download | qmk_firmware-fc9fb2c77505cf1dcf5d1f50dd61a980471b3494.tar.gz qmk_firmware-fc9fb2c77505cf1dcf5d1f50dd61a980471b3494.zip | |
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
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_common/main.cpp | 32 | ||||
| -rw-r--r-- | tests/test_common/test_fixture.cpp | 8 |
2 files changed, 38 insertions, 2 deletions
diff --git a/tests/test_common/main.cpp b/tests/test_common/main.cpp new file mode 100644 index 000000000..3e4b4c0f9 --- /dev/null +++ b/tests/test_common/main.cpp | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | #include "gtest/gtest.h" | ||
| 2 | |||
| 3 | extern "C" { | ||
| 4 | #include "stdio.h" | ||
| 5 | #include "debug.h" | ||
| 6 | |||
| 7 | int8_t sendchar(uint8_t c) { | ||
| 8 | fprintf(stderr, "%c", c); | ||
| 9 | return 0; | ||
| 10 | } | ||
| 11 | |||
| 12 | __attribute__((weak)) debug_config_t debug_config = {0}; | ||
| 13 | |||
| 14 | void init_logging(void) { | ||
| 15 | print_set_sendchar(sendchar); | ||
| 16 | |||
| 17 | // Customise these values to desired behaviour | ||
| 18 | // debug_enable = true; | ||
| 19 | // debug_matrix = true; | ||
| 20 | // debug_keyboard = true; | ||
| 21 | // debug_mouse = true; | ||
| 22 | debug_config.raw = 0xFF; | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | int main(int argc, char **argv) { | ||
| 27 | ::testing::InitGoogleTest(&argc, argv); | ||
| 28 | |||
| 29 | init_logging(); | ||
| 30 | |||
| 31 | return RUN_ALL_TESTS(); | ||
| 32 | } \ No newline at end of file | ||
diff --git a/tests/test_common/test_fixture.cpp b/tests/test_common/test_fixture.cpp index 20ed838eb..e041df712 100644 --- a/tests/test_common/test_fixture.cpp +++ b/tests/test_common/test_fixture.cpp | |||
| @@ -7,10 +7,10 @@ | |||
| 7 | #include "action_tapping.h" | 7 | #include "action_tapping.h" |
| 8 | 8 | ||
| 9 | extern "C" { | 9 | extern "C" { |
| 10 | #include "debug.h" | ||
| 11 | #include "eeconfig.h" | ||
| 10 | #include "action_layer.h" | 12 | #include "action_layer.h" |
| 11 | } | ||
| 12 | 13 | ||
| 13 | extern "C" { | ||
| 14 | void set_time(uint32_t t); | 14 | void set_time(uint32_t t); |
| 15 | void advance_time(uint32_t ms); | 15 | void advance_time(uint32_t ms); |
| 16 | } | 16 | } |
| @@ -21,6 +21,10 @@ using testing::Between; | |||
| 21 | using testing::Return; | 21 | using testing::Return; |
| 22 | 22 | ||
| 23 | void TestFixture::SetUpTestCase() { | 23 | void TestFixture::SetUpTestCase() { |
| 24 | // The following is enough to bootstrap the values set in main | ||
| 25 | eeconfig_init_quantum(); | ||
| 26 | eeconfig_update_debug(debug_config.raw); | ||
| 27 | |||
| 24 | TestDriver driver; | 28 | TestDriver driver; |
| 25 | EXPECT_CALL(driver, send_keyboard_mock(_)); | 29 | EXPECT_CALL(driver, send_keyboard_mock(_)); |
| 26 | keyboard_init(); | 30 | keyboard_init(); |
