aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build_test.mk13
-rw-r--r--docs/faq_debug.md2
-rw-r--r--docs/unit_testing.md10
-rw-r--r--tests/test_common/main.cpp32
-rw-r--r--tests/test_common/test_fixture.cpp8
5 files changed, 59 insertions, 6 deletions
diff --git a/build_test.mk b/build_test.mk
index 77c4265f9..519c142c4 100644
--- a/build_test.mk
+++ b/build_test.mk
@@ -24,7 +24,6 @@ GTEST_INTERNAL_INC :=\
24 24
25$(GTEST_OUTPUT)_SRC :=\ 25$(GTEST_OUTPUT)_SRC :=\
26 googletest/src/gtest-all.cc\ 26 googletest/src/gtest-all.cc\
27 googletest/src/gtest_main.cc\
28 googlemock/src/gmock-all.cc 27 googlemock/src/gmock-all.cc
29 28
30$(GTEST_OUTPUT)_DEFS := 29$(GTEST_OUTPUT)_DEFS :=
@@ -35,7 +34,8 @@ CREATE_MAP := no
35 34
36VPATH +=\ 35VPATH +=\
37 $(LIB_PATH)/googletest\ 36 $(LIB_PATH)/googletest\
38 $(LIB_PATH)/googlemock 37 $(LIB_PATH)/googlemock\
38 $(LIB_PATH)/printf
39 39
40all: elf 40all: elf
41 41
@@ -43,6 +43,10 @@ VPATH += $(COMMON_VPATH)
43PLATFORM:=TEST 43PLATFORM:=TEST
44PLATFORM_KEY:=test 44PLATFORM_KEY:=test
45 45
46ifeq ($(strip $(DEBUG)), 1)
47CONSOLE_ENABLE = yes
48endif
49
46ifneq ($(filter $(FULL_TESTS),$(TEST)),) 50ifneq ($(filter $(FULL_TESTS),$(TEST)),)
47include tests/$(TEST)/rules.mk 51include tests/$(TEST)/rules.mk
48endif 52endif
@@ -55,6 +59,11 @@ ifneq ($(filter $(FULL_TESTS),$(TEST)),)
55include build_full_test.mk 59include build_full_test.mk
56endif 60endif
57 61
62$(TEST)_SRC += \
63 tests/test_common/main.c \
64 $(LIB_PATH)/printf/printf.c \
65 $(COMMON_DIR)/printf.c
66
58$(TEST_OBJ)/$(TEST)_SRC := $($(TEST)_SRC) 67$(TEST_OBJ)/$(TEST)_SRC := $($(TEST)_SRC)
59$(TEST_OBJ)/$(TEST)_INC := $($(TEST)_INC) $(VPATH) $(GTEST_INC) 68$(TEST_OBJ)/$(TEST)_INC := $($(TEST)_INC) $(VPATH) $(GTEST_INC)
60$(TEST_OBJ)/$(TEST)_DEFS := $($(TEST)_DEFS) 69$(TEST_OBJ)/$(TEST)_DEFS := $($(TEST)_DEFS)
diff --git a/docs/faq_debug.md b/docs/faq_debug.md
index 13a649bfa..1afa38a62 100644
--- a/docs/faq_debug.md
+++ b/docs/faq_debug.md
@@ -28,7 +28,7 @@ For compatible platforms, [QMK Toolbox](https://github.com/qmk/qmk_toolbox) can
28 28
29Prefer a terminal based solution? [hid_listen](https://www.pjrc.com/teensy/hid_listen.html), provided by PJRC, can also be used to display debug messages. Prebuilt binaries for Windows,Linux,and MacOS are available. 29Prefer a terminal based solution? [hid_listen](https://www.pjrc.com/teensy/hid_listen.html), provided by PJRC, can also be used to display debug messages. Prebuilt binaries for Windows,Linux,and MacOS are available.
30 30
31## Sending Your Own Debug Messages 31## Sending Your Own Debug Messages :id=debug-api
32 32
33Sometimes it's useful to print debug messages from within your [custom code](custom_quantum_functions.md). Doing so is pretty simple. Start by including `print.h` at the top of your file: 33Sometimes it's useful to print debug messages from within your [custom code](custom_quantum_functions.md). Doing so is pretty simple. Start by including `print.h` at the top of your file:
34 34
diff --git a/docs/unit_testing.md b/docs/unit_testing.md
index 82073a201..a0eef51cb 100644
--- a/docs/unit_testing.md
+++ b/docs/unit_testing.md
@@ -36,12 +36,20 @@ Note how there's several different tests, each mocking out a separate part. Also
36 36
37## Running the Tests 37## Running the Tests
38 38
39To run all the tests in the codebase, type `make test`. You can also run test matching a substring by typing `make test:matchingsubstring` Note that the tests are always compiled with the native compiler of your platform, so they are also run like any other program on your computer. 39To run all the tests in the codebase, type `make test:all`. You can also run test matching a substring by typing `make test:matchingsubstring` Note that the tests are always compiled with the native compiler of your platform, so they are also run like any other program on your computer.
40 40
41## Debugging the Tests 41## Debugging the Tests
42 42
43If there are problems with the tests, you can find the executable in the `./build/test` folder. You should be able to run those with GDB or a similar debugger. 43If there are problems with the tests, you can find the executable in the `./build/test` folder. You should be able to run those with GDB or a similar debugger.
44 44
45To forward any [debug messages](unit_testing.md#debug-api) to `stderr`, the tests can run with `DEBUG=1`. For example
46
47```console
48make test:all DEBUG=1
49```
50
51Alternatively, add `CONSOLE_ENABLE=yes` to the tests `rules.mk`.
52
45## Full Integration Tests 53## Full Integration Tests
46 54
47It's not yet possible to do a full integration test, where you would compile the whole firmware and define a keymap that you are going to test. However there are plans for doing that, because writing tests that way would probably be easier, at least for people that are not used to unit testing. 55It's not yet possible to do a full integration test, where you would compile the whole firmware and define a keymap that you are going to test. However there are plans for doing that, because writing tests that way would probably be easier, at least for people that are not used to unit testing.
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
3extern "C" {
4#include "stdio.h"
5#include "debug.h"
6
7int8_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
14void 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
26int 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
9extern "C" { 9extern "C" {
10#include "debug.h"
11#include "eeconfig.h"
10#include "action_layer.h" 12#include "action_layer.h"
11}
12 13
13extern "C" {
14void set_time(uint32_t t); 14void set_time(uint32_t t);
15void advance_time(uint32_t ms); 15void advance_time(uint32_t ms);
16} 16}
@@ -21,6 +21,10 @@ using testing::Between;
21using testing::Return; 21using testing::Return;
22 22
23void TestFixture::SetUpTestCase() { 23void 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();