From 30f22d450da19c65584e6deb8515a1fa5b074e07 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 20:21:28 +0300 Subject: Add basic infrastrucure for building full tests --- tests/basic/config.h | 22 ++++++++++++++++++++++ tests/basic/rules.mk | 14 ++++++++++++++ tests/basic/test.c | 17 +++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 tests/basic/config.h create mode 100644 tests/basic/rules.mk create mode 100644 tests/basic/test.c (limited to 'tests') diff --git a/tests/basic/config.h b/tests/basic/config.h new file mode 100644 index 000000000..c24fdcf3f --- /dev/null +++ b/tests/basic/config.h @@ -0,0 +1,22 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef TESTS_BASIC_CONFIG_H_ +#define TESTS_BASIC_CONFIG_H_ + + + +#endif /* TESTS_BASIC_CONFIG_H_ */ diff --git a/tests/basic/rules.mk b/tests/basic/rules.mk new file mode 100644 index 000000000..0405b9d0f --- /dev/null +++ b/tests/basic/rules.mk @@ -0,0 +1,14 @@ +# Copyright 2017 Fred Sundvik +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . \ No newline at end of file diff --git a/tests/basic/test.c b/tests/basic/test.c new file mode 100644 index 000000000..01d1930ea --- /dev/null +++ b/tests/basic/test.c @@ -0,0 +1,17 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + -- cgit v1.2.3 From 585d64612811a61f8476380dac77199c04246085 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 21:39:00 +0300 Subject: Define MATRIX_COLS and MATRIX_ROWS --- tests/basic/config.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/basic/config.h b/tests/basic/config.h index c24fdcf3f..c5578b83f 100644 --- a/tests/basic/config.h +++ b/tests/basic/config.h @@ -17,6 +17,8 @@ #ifndef TESTS_BASIC_CONFIG_H_ #define TESTS_BASIC_CONFIG_H_ +#define MATRIX_ROWS 1 +#define MATRIX_COLS 2 #endif /* TESTS_BASIC_CONFIG_H_ */ -- cgit v1.2.3 From 1c0fe956ac242b1c85a9b024b9b3966020b862ed Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 22:14:47 +0300 Subject: Split common.mk into common.mk and common_features.mk To support including keyboard/keymap specific rules before it --- build_full_test.mk | 2 +- build_keyboard.mk | 15 +---- build_test.mk | 5 ++ common.mk | 128 ------------------------------------------- common_features.mk | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++ tests/basic/rules.mk | 4 +- 6 files changed, 164 insertions(+), 142 deletions(-) create mode 100644 common_features.mk (limited to 'tests') diff --git a/build_full_test.mk b/build_full_test.mk index 8b04cc3a4..a4fc8d820 100644 --- a/build_full_test.mk +++ b/build_full_test.mk @@ -18,6 +18,6 @@ include tests/$(TEST)/rules.mk TEST_PATH=tests/$(TEST) -$(TEST)_SRC=$(TEST_PATH)/test.c $(TMK_COMMON_SRC) +$(TEST)_SRC=$(TEST_PATH)/test.c $(TMK_COMMON_SRC) $(QUANTUM_SRC) $(TEST)_DEFS=$(TMK_COMMON_DEFS) $(TEST)_CONFIG=$(TEST_PATH)/config.h diff --git a/build_keyboard.mk b/build_keyboard.mk index f13d5b6d6..3ec389ac9 100644 --- a/build_keyboard.mk +++ b/build_keyboard.mk @@ -31,8 +31,6 @@ $(error MASTER does not have a valid value(left/right)) endif endif - - KEYBOARD_PATH := keyboards/$(KEYBOARD) KEYBOARD_C := $(KEYBOARD_PATH)/$(KEYBOARD).c @@ -42,7 +40,6 @@ else $(error "$(KEYBOARD_C)" does not exist) endif - ifneq ($(SUBPROJECT),) SUBPROJECT_PATH := keyboards/$(KEYBOARD)/$(SUBPROJECT) SUBPROJECT_C := $(SUBPROJECT_PATH)/$(SUBPROJECT).c @@ -118,19 +115,12 @@ endif # # project specific files SRC += $(KEYBOARD_C) \ $(KEYMAP_C) \ - $(QUANTUM_DIR)/quantum.c \ - $(QUANTUM_DIR)/keymap_common.c \ - $(QUANTUM_DIR)/keycode_config.c \ - $(QUANTUM_DIR)/process_keycode/process_leader.c + $(QUANTUM_SRC) ifneq ($(SUBPROJECT),) SRC += $(SUBPROJECT_C) endif -ifndef CUSTOM_MATRIX - SRC += $(QUANTUM_DIR)/matrix.c -endif - # Optimize size but this may cause error "relocation truncated to fit" #EXTRALDFLAGS = -Wl,--relax @@ -142,9 +132,10 @@ endif VPATH += $(KEYBOARD_PATH) VPATH += $(COMMON_VPATH) +include common_features.mk include $(TMK_PATH)/protocol.mk - include $(TMK_PATH)/common.mk + SRC += $(TMK_COMMON_SRC) OPT_DEFS += $(TMK_COMMON_DEFS) EXTRALDFLAGS += $(TMK_COMMON_LDFLAGS) diff --git a/build_test.mk b/build_test.mk index 609b094af..cac2cba50 100644 --- a/build_test.mk +++ b/build_test.mk @@ -42,6 +42,11 @@ all: elf VPATH += $(COMMON_VPATH) PLATFORM:=TEST +ifneq ($(filter $(FULL_TESTS),$(TEST)),) +include tests/$(TEST)/rules.mk +endif + +include common_features.mk include $(TMK_PATH)/common.mk include $(QUANTUM_PATH)/serial_link/tests/rules.mk ifneq ($(filter $(FULL_TESTS),$(TEST)),) diff --git a/common.mk b/common.mk index 51e4283ba..70f7ae099 100644 --- a/common.mk +++ b/common.mk @@ -11,12 +11,6 @@ QUANTUM_PATH = $(TOP_DIR)/$(QUANTUM_DIR) BUILD_DIR := $(TOP_DIR)/.build -SERIAL_DIR := $(QUANTUM_DIR)/serial_link -SERIAL_PATH := $(QUANTUM_PATH)/serial_link -SERIAL_SRC := $(wildcard $(SERIAL_PATH)/protocol/*.c) -SERIAL_SRC += $(wildcard $(SERIAL_PATH)/system/*.c) -SERIAL_DEFS += -DSERIAL_LINK_ENABLE - COMMON_VPATH := $(TOP_DIR) COMMON_VPATH += $(TMK_PATH) COMMON_VPATH += $(QUANTUM_PATH) @@ -25,125 +19,3 @@ COMMON_VPATH += $(QUANTUM_PATH)/audio COMMON_VPATH += $(QUANTUM_PATH)/process_keycode COMMON_VPATH += $(QUANTUM_PATH)/api COMMON_VPATH += $(SERIAL_PATH) - -ifeq ($(strip $(API_SYSEX_ENABLE)), yes) - OPT_DEFS += -DAPI_SYSEX_ENABLE - SRC += $(QUANTUM_DIR)/api/api_sysex.c - OPT_DEFS += -DAPI_ENABLE - SRC += $(QUANTUM_DIR)/api.c - MIDI_ENABLE=yes -endif - -MUSIC_ENABLE := 0 - -ifeq ($(strip $(AUDIO_ENABLE)), yes) - OPT_DEFS += -DAUDIO_ENABLE - MUSIC_ENABLE := 1 - SRC += $(QUANTUM_DIR)/process_keycode/process_audio.c - SRC += $(QUANTUM_DIR)/audio/audio.c - SRC += $(QUANTUM_DIR)/audio/voices.c - SRC += $(QUANTUM_DIR)/audio/luts.c -endif - -ifeq ($(strip $(MIDI_ENABLE)), yes) - OPT_DEFS += -DMIDI_ENABLE - MUSIC_ENABLE := 1 - SRC += $(QUANTUM_DIR)/process_keycode/process_midi.c -endif - -ifeq ($(MUSIC_ENABLE), 1) - SRC += $(QUANTUM_DIR)/process_keycode/process_music.c -endif - -ifeq ($(strip $(COMBO_ENABLE)), yes) - OPT_DEFS += -DCOMBO_ENABLE - SRC += $(QUANTUM_DIR)/process_keycode/process_combo.c -endif - -ifeq ($(strip $(VIRTSER_ENABLE)), yes) - OPT_DEFS += -DVIRTSER_ENABLE -endif - -ifeq ($(strip $(FAUXCLICKY_ENABLE)), yes) - OPT_DEFS += -DFAUXCLICKY_ENABLE - SRC += $(QUANTUM_DIR)/fauxclicky.c -endif - -ifeq ($(strip $(UCIS_ENABLE)), yes) - OPT_DEFS += -DUCIS_ENABLE - UNICODE_COMMON = yes - SRC += $(QUANTUM_DIR)/process_keycode/process_ucis.c -endif - -ifeq ($(strip $(UNICODEMAP_ENABLE)), yes) - OPT_DEFS += -DUNICODEMAP_ENABLE - UNICODE_COMMON = yes - SRC += $(QUANTUM_DIR)/process_keycode/process_unicodemap.c -endif - -ifeq ($(strip $(UNICODE_ENABLE)), yes) - OPT_DEFS += -DUNICODE_ENABLE - UNICODE_COMMON = yes - SRC += $(QUANTUM_DIR)/process_keycode/process_unicode.c -endif - -ifeq ($(strip $(UNICODE_COMMON)), yes) - SRC += $(QUANTUM_DIR)/process_keycode/process_unicode_common.c -endif - -ifeq ($(strip $(RGBLIGHT_ENABLE)), yes) - OPT_DEFS += -DRGBLIGHT_ENABLE - SRC += $(QUANTUM_DIR)/light_ws2812.c - SRC += $(QUANTUM_DIR)/rgblight.c - CIE1931_CURVE = yes - LED_BREATHING_TABLE = yes -endif - -ifeq ($(strip $(TAP_DANCE_ENABLE)), yes) - OPT_DEFS += -DTAP_DANCE_ENABLE - SRC += $(QUANTUM_DIR)/process_keycode/process_tap_dance.c -endif - -ifeq ($(strip $(PRINTING_ENABLE)), yes) - OPT_DEFS += -DPRINTING_ENABLE - SRC += $(QUANTUM_DIR)/process_keycode/process_printer.c - SRC += $(TMK_DIR)/protocol/serial_uart.c -endif - -ifeq ($(strip $(SERIAL_LINK_ENABLE)), yes) - SRC += $(patsubst $(QUANTUM_PATH)/%,%,$(SERIAL_SRC)) - OPT_DEFS += $(SERIAL_DEFS) - VAPTH += $(SERIAL_PATH) -endif - -ifneq ($(strip $(VARIABLE_TRACE)),) - SRC += $(QUANTUM_DIR)/variable_trace.c - OPT_DEFS += -DNUM_TRACED_VARIABLES=$(strip $(VARIABLE_TRACE)) -ifneq ($(strip $(MAX_VARIABLE_TRACE_SIZE)),) - OPT_DEFS += -DMAX_VARIABLE_TRACE_SIZE=$(strip $(MAX_VARIABLE_TRACE_SIZE)) -endif -endif - -ifeq ($(strip $(LCD_ENABLE)), yes) - CIE1931_CURVE = yes -endif - -ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) - ifeq ($(strip $(VISUALIZER_ENABLE)), yes) - CIE1931_CURVE = yes - endif -endif - -ifeq ($(strip $(CIE1931_CURVE)), yes) - OPT_DEFS += -DUSE_CIE1931_CURVE - LED_TABLES = yes -endif - -ifeq ($(strip $(LED_BREATHING_TABLE)), yes) - OPT_DEFS += -DUSE_LED_BREATHING_TABLE - LED_TABLES = yes -endif - -ifeq ($(strip $(LED_TABLES)), yes) - SRC += $(QUANTUM_DIR)/led_tables.c -endif diff --git a/common_features.mk b/common_features.mk new file mode 100644 index 000000000..a8a52afb9 --- /dev/null +++ b/common_features.mk @@ -0,0 +1,152 @@ +# Copyright 2017 Fred Sundvik +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +SERIAL_DIR := $(QUANTUM_DIR)/serial_link +SERIAL_PATH := $(QUANTUM_PATH)/serial_link +SERIAL_SRC := $(wildcard $(SERIAL_PATH)/protocol/*.c) +SERIAL_SRC += $(wildcard $(SERIAL_PATH)/system/*.c) +SERIAL_DEFS += -DSERIAL_LINK_ENABLE + +ifeq ($(strip $(API_SYSEX_ENABLE)), yes) + OPT_DEFS += -DAPI_SYSEX_ENABLE + SRC += $(QUANTUM_DIR)/api/api_sysex.c + OPT_DEFS += -DAPI_ENABLE + SRC += $(QUANTUM_DIR)/api.c + MIDI_ENABLE=yes +endif + +MUSIC_ENABLE := 0 + +ifeq ($(strip $(AUDIO_ENABLE)), yes) + OPT_DEFS += -DAUDIO_ENABLE + MUSIC_ENABLE := 1 + SRC += $(QUANTUM_DIR)/process_keycode/process_audio.c + SRC += $(QUANTUM_DIR)/audio/audio.c + SRC += $(QUANTUM_DIR)/audio/voices.c + SRC += $(QUANTUM_DIR)/audio/luts.c +endif + +ifeq ($(strip $(MIDI_ENABLE)), yes) + OPT_DEFS += -DMIDI_ENABLE + MUSIC_ENABLE := 1 + SRC += $(QUANTUM_DIR)/process_keycode/process_midi.c +endif + +ifeq ($(MUSIC_ENABLE), 1) + SRC += $(QUANTUM_DIR)/process_keycode/process_music.c +endif + +ifeq ($(strip $(COMBO_ENABLE)), yes) + OPT_DEFS += -DCOMBO_ENABLE + SRC += $(QUANTUM_DIR)/process_keycode/process_combo.c +endif + +ifeq ($(strip $(VIRTSER_ENABLE)), yes) + OPT_DEFS += -DVIRTSER_ENABLE +endif + +ifeq ($(strip $(FAUXCLICKY_ENABLE)), yes) + OPT_DEFS += -DFAUXCLICKY_ENABLE + SRC += $(QUANTUM_DIR)/fauxclicky.c +endif + +ifeq ($(strip $(UCIS_ENABLE)), yes) + OPT_DEFS += -DUCIS_ENABLE + UNICODE_COMMON = yes + SRC += $(QUANTUM_DIR)/process_keycode/process_ucis.c +endif + +ifeq ($(strip $(UNICODEMAP_ENABLE)), yes) + OPT_DEFS += -DUNICODEMAP_ENABLE + UNICODE_COMMON = yes + SRC += $(QUANTUM_DIR)/process_keycode/process_unicodemap.c +endif + +ifeq ($(strip $(UNICODE_ENABLE)), yes) + OPT_DEFS += -DUNICODE_ENABLE + UNICODE_COMMON = yes + SRC += $(QUANTUM_DIR)/process_keycode/process_unicode.c +endif + +ifeq ($(strip $(UNICODE_COMMON)), yes) + SRC += $(QUANTUM_DIR)/process_keycode/process_unicode_common.c +endif + +ifeq ($(strip $(RGBLIGHT_ENABLE)), yes) + OPT_DEFS += -DRGBLIGHT_ENABLE + SRC += $(QUANTUM_DIR)/light_ws2812.c + SRC += $(QUANTUM_DIR)/rgblight.c + CIE1931_CURVE = yes + LED_BREATHING_TABLE = yes +endif + +ifeq ($(strip $(TAP_DANCE_ENABLE)), yes) + OPT_DEFS += -DTAP_DANCE_ENABLE + SRC += $(QUANTUM_DIR)/process_keycode/process_tap_dance.c +endif + +ifeq ($(strip $(PRINTING_ENABLE)), yes) + OPT_DEFS += -DPRINTING_ENABLE + SRC += $(QUANTUM_DIR)/process_keycode/process_printer.c + SRC += $(TMK_DIR)/protocol/serial_uart.c +endif + +ifeq ($(strip $(SERIAL_LINK_ENABLE)), yes) + SRC += $(patsubst $(QUANTUM_PATH)/%,%,$(SERIAL_SRC)) + OPT_DEFS += $(SERIAL_DEFS) + VAPTH += $(SERIAL_PATH) +endif + +ifneq ($(strip $(VARIABLE_TRACE)),) + SRC += $(QUANTUM_DIR)/variable_trace.c + OPT_DEFS += -DNUM_TRACED_VARIABLES=$(strip $(VARIABLE_TRACE)) +ifneq ($(strip $(MAX_VARIABLE_TRACE_SIZE)),) + OPT_DEFS += -DMAX_VARIABLE_TRACE_SIZE=$(strip $(MAX_VARIABLE_TRACE_SIZE)) +endif +endif + +ifeq ($(strip $(LCD_ENABLE)), yes) + CIE1931_CURVE = yes +endif + +ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) + ifeq ($(strip $(VISUALIZER_ENABLE)), yes) + CIE1931_CURVE = yes + endif +endif + +ifeq ($(strip $(CIE1931_CURVE)), yes) + OPT_DEFS += -DUSE_CIE1931_CURVE + LED_TABLES = yes +endif + +ifeq ($(strip $(LED_BREATHING_TABLE)), yes) + OPT_DEFS += -DUSE_LED_BREATHING_TABLE + LED_TABLES = yes +endif + +ifeq ($(strip $(LED_TABLES)), yes) + SRC += $(QUANTUM_DIR)/led_tables.c +endif + +QUANTUM_SRC:= \ + $(QUANTUM_DIR)/quantum.c \ + $(QUANTUM_DIR)/keymap_common.c \ + $(QUANTUM_DIR)/keycode_config.c \ + $(QUANTUM_DIR)/process_keycode/process_leader.c + +ifndef CUSTOM_MATRIX + QUANTUM_SRC += $(QUANTUM_DIR)/matrix.c +endif \ No newline at end of file diff --git a/tests/basic/rules.mk b/tests/basic/rules.mk index 0405b9d0f..8a906807c 100644 --- a/tests/basic/rules.mk +++ b/tests/basic/rules.mk @@ -11,4 +11,6 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program. If not, see . \ No newline at end of file +# along with this program. If not, see . + +CUSTOM_MATRIX=yes \ No newline at end of file -- cgit v1.2.3 From a72e8f0865e54777a152652c5d46280ceb58efbc Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 22:30:07 +0300 Subject: Dummy test matrix implementation --- build_full_test.mk | 4 ++-- tests/test_common/matrix.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 tests/test_common/matrix.c (limited to 'tests') diff --git a/build_full_test.mk b/build_full_test.mk index a4fc8d820..43e2a20a7 100644 --- a/build_full_test.mk +++ b/build_full_test.mk @@ -13,11 +13,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -include tests/$(TEST)/rules.mk #include $(TMK_PATH)/protocol.mk TEST_PATH=tests/$(TEST) -$(TEST)_SRC=$(TEST_PATH)/test.c $(TMK_COMMON_SRC) $(QUANTUM_SRC) +$(TEST)_SRC=$(TEST_PATH)/test.c $(TMK_COMMON_SRC) $(QUANTUM_SRC) tests/test_common/matrix.c $(TEST)_DEFS=$(TMK_COMMON_DEFS) $(TEST)_CONFIG=$(TEST_PATH)/config.h +VPATH+=$(TOP_DIR)/tests/test_common diff --git a/tests/test_common/matrix.c b/tests/test_common/matrix.c new file mode 100644 index 000000000..940f28f35 --- /dev/null +++ b/tests/test_common/matrix.c @@ -0,0 +1,43 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include "matrix.h" + +void matrix_init(void) { + matrix_init_quantum(); +} + +uint8_t matrix_scan(void) { + matrix_scan_quantum(); + return 1; +} + +matrix_row_t matrix_get_row(uint8_t row) { + return 0; +} + +void matrix_print(void) { + +} + +void matrix_init_kb(void) { + +} + +void matrix_scan_kb(void) { + +} -- cgit v1.2.3 From 617578399cf1a0fff70ceeb21d63a06524c801a3 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 22:39:56 +0300 Subject: Add keymap --- tests/basic/config.h | 2 +- tests/basic/test.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/basic/config.h b/tests/basic/config.h index c5578b83f..4da8d0425 100644 --- a/tests/basic/config.h +++ b/tests/basic/config.h @@ -17,7 +17,7 @@ #ifndef TESTS_BASIC_CONFIG_H_ #define TESTS_BASIC_CONFIG_H_ -#define MATRIX_ROWS 1 +#define MATRIX_ROWS 2 #define MATRIX_COLS 2 diff --git a/tests/basic/test.c b/tests/basic/test.c index 01d1930ea..2afb4d6a9 100644 --- a/tests/basic/test.c +++ b/tests/basic/test.c @@ -14,4 +14,11 @@ * along with this program. If not, see . */ +#include "quantum.h" +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = { + {KC_A, KC_B}, + {KC_C, KC_D} + }, +}; -- cgit v1.2.3 From 3bb0586acc6472380365d78ee81a332aca468239 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 16 Jun 2017 23:50:44 +0300 Subject: Add a couple of basic tests and implement driver mock --- build_full_test.mk | 7 ++++- tests/basic/test.c | 24 ---------------- tests/basic/test.cpp | 50 +++++++++++++++++++++++++++++++++ tests/test_common/matrix.c | 13 ++++++++- tests/test_common/test_driver.cpp | 58 +++++++++++++++++++++++++++++++++++++++ tests/test_common/test_driver.h | 45 ++++++++++++++++++++++++++++++ tests/test_common/test_matrix.h | 31 +++++++++++++++++++++ 7 files changed, 202 insertions(+), 26 deletions(-) delete mode 100644 tests/basic/test.c create mode 100644 tests/basic/test.cpp create mode 100644 tests/test_common/test_driver.cpp create mode 100644 tests/test_common/test_driver.h create mode 100644 tests/test_common/test_matrix.h (limited to 'tests') diff --git a/build_full_test.mk b/build_full_test.mk index 43e2a20a7..5f9bbe5e6 100644 --- a/build_full_test.mk +++ b/build_full_test.mk @@ -17,7 +17,12 @@ TEST_PATH=tests/$(TEST) -$(TEST)_SRC=$(TEST_PATH)/test.c $(TMK_COMMON_SRC) $(QUANTUM_SRC) tests/test_common/matrix.c +$(TEST)_SRC= \ + $(TEST_PATH)/test.cpp \ + $(TMK_COMMON_SRC) \ + $(QUANTUM_SRC) \ + tests/test_common/matrix.c \ + tests/test_common/test_driver.cpp $(TEST)_DEFS=$(TMK_COMMON_DEFS) $(TEST)_CONFIG=$(TEST_PATH)/config.h VPATH+=$(TOP_DIR)/tests/test_common diff --git a/tests/basic/test.c b/tests/basic/test.c deleted file mode 100644 index 2afb4d6a9..000000000 --- a/tests/basic/test.c +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright 2017 Fred Sundvik - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "quantum.h" - -const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { - [0] = { - {KC_A, KC_B}, - {KC_C, KC_D} - }, -}; diff --git a/tests/basic/test.cpp b/tests/basic/test.cpp new file mode 100644 index 000000000..ce9a0cd72 --- /dev/null +++ b/tests/basic/test.cpp @@ -0,0 +1,50 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +#include "quantum.h" +#include "keyboard.h" +#include "test_driver.h" +#include "test_matrix.h" + +using testing::_; +using testing::Return; + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = { + {KC_A, KC_B}, + {KC_C, KC_D} + }, +}; + +TEST(Basic, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { + keyboard_init(); + TestDriver driver; + EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + keyboard_task(); +} + +TEST(Basic, SendKeyboardIsCalledWhenAKeyIsPressed) { + keyboard_init(); + TestDriver driver; + press_key(0, 0); + EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); + EXPECT_CALL(driver, send_keyboard_mock(_)); + keyboard_task(); +} diff --git a/tests/test_common/matrix.c b/tests/test_common/matrix.c index 940f28f35..85556e2c4 100644 --- a/tests/test_common/matrix.c +++ b/tests/test_common/matrix.c @@ -16,6 +16,9 @@ #include "matrix.h" +#include "test_matrix.h" + +static matrix_row_t matrix[MATRIX_ROWS] = {}; void matrix_init(void) { matrix_init_quantum(); @@ -27,7 +30,7 @@ uint8_t matrix_scan(void) { } matrix_row_t matrix_get_row(uint8_t row) { - return 0; + return matrix[row]; } void matrix_print(void) { @@ -41,3 +44,11 @@ void matrix_init_kb(void) { void matrix_scan_kb(void) { } + +void press_key(uint8_t col, uint8_t row) { + matrix[row] |= 1 << col; +} + +void release_key(uint8_t col, uint8_t row) { + matrix[row] &= ~(1 << col); +} diff --git a/tests/test_common/test_driver.cpp b/tests/test_common/test_driver.cpp new file mode 100644 index 000000000..7c67f5776 --- /dev/null +++ b/tests/test_common/test_driver.cpp @@ -0,0 +1,58 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test_driver.h" + +TestDriver* TestDriver::m_this = nullptr; + +TestDriver::TestDriver() + : m_driver{ + &TestDriver::keyboard_leds, + &TestDriver::send_keyboard, + &TestDriver::send_mouse, + &TestDriver::send_system, + &TestDriver::send_consumer + } +{ + + host_set_driver(&m_driver); + m_this = this; +} + +TestDriver::~TestDriver() { + m_this = nullptr; +} + +uint8_t TestDriver::keyboard_leds(void) { + return m_this->keyboard_leds_mock(); +} + +void TestDriver::send_keyboard(report_keyboard_t* report) { + m_this->send_keyboard_mock(report); + +} + +void TestDriver::send_mouse(report_mouse_t* report) { + m_this->send_mouse_mock(report); +} + +void TestDriver::send_system(uint16_t data) { + m_this->send_system_mock(data); +} + +void TestDriver::send_consumer(uint16_t data) { + m_this->send_consumer_mock(data); +} diff --git a/tests/test_common/test_driver.h b/tests/test_common/test_driver.h new file mode 100644 index 000000000..d5b831884 --- /dev/null +++ b/tests/test_common/test_driver.h @@ -0,0 +1,45 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef TESTS_TEST_COMMON_TEST_DRIVER_H_ +#define TESTS_TEST_COMMON_TEST_DRIVER_H_ + +#include "gmock/gmock.h" +#include +#include "host.h" + + +class TestDriver { +public: + TestDriver(); + ~TestDriver(); + MOCK_METHOD0(keyboard_leds_mock, uint8_t ()); + MOCK_METHOD1(send_keyboard_mock, void (report_keyboard_t*)); + MOCK_METHOD1(send_mouse_mock, void (report_mouse_t*)); + MOCK_METHOD1(send_system_mock, void (uint16_t)); + MOCK_METHOD1(send_consumer_mock, void (uint16_t)); +private: + static uint8_t keyboard_leds(void); + static void send_keyboard(report_keyboard_t *report); + static void send_mouse(report_mouse_t* report); + static void send_system(uint16_t data); + static void send_consumer(uint16_t data); + host_driver_t m_driver; + static TestDriver* m_this; +}; + + +#endif /* TESTS_TEST_COMMON_TEST_DRIVER_H_ */ diff --git a/tests/test_common/test_matrix.h b/tests/test_common/test_matrix.h new file mode 100644 index 000000000..afc65c556 --- /dev/null +++ b/tests/test_common/test_matrix.h @@ -0,0 +1,31 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef TESTS_TEST_COMMON_TEST_MATRIX_H_ +#define TESTS_TEST_COMMON_TEST_MATRIX_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +void press_key(uint8_t col, uint8_t row); +void release_key(uint8_t col, uint8_t row); + +#ifdef __cplusplus +} +#endif + +#endif /* TESTS_TEST_COMMON_TEST_MATRIX_H_ */ -- cgit v1.2.3 From c38589d8615ba3ff93736cb02d12b3c8ceb68094 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 17 Jun 2017 15:18:30 +0300 Subject: Fix the order of init and driver creation --- tests/basic/test.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/basic/test.cpp b/tests/basic/test.cpp index ce9a0cd72..e3190085d 100644 --- a/tests/basic/test.cpp +++ b/tests/basic/test.cpp @@ -33,16 +33,18 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }; TEST(Basic, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { - keyboard_init(); TestDriver driver; + EXPECT_CALL(driver, send_keyboard_mock(_)); + keyboard_init(); EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); keyboard_task(); } TEST(Basic, SendKeyboardIsCalledWhenAKeyIsPressed) { - keyboard_init(); TestDriver driver; + EXPECT_CALL(driver, send_keyboard_mock(_)); + keyboard_init(); press_key(0, 0); EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); EXPECT_CALL(driver, send_keyboard_mock(_)); -- cgit v1.2.3 From bd1729d5be376fecae67ab5ddc92eab82416a5c1 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 17 Jun 2017 18:18:15 +0300 Subject: Actually test for correct key presses --- build_full_test.mk | 3 +- tests/basic/test.cpp | 8 +++-- tests/test_common/keyboard_report_util.cpp | 47 ++++++++++++++++++++++++++++++ tests/test_common/keyboard_report_util.h | 39 +++++++++++++++++++++++++ tests/test_common/test_driver.cpp | 6 ++-- tests/test_common/test_driver.h | 5 ++-- 6 files changed, 100 insertions(+), 8 deletions(-) create mode 100644 tests/test_common/keyboard_report_util.cpp create mode 100644 tests/test_common/keyboard_report_util.h (limited to 'tests') diff --git a/build_full_test.mk b/build_full_test.mk index 5f9bbe5e6..67c1ca5e5 100644 --- a/build_full_test.mk +++ b/build_full_test.mk @@ -22,7 +22,8 @@ $(TEST)_SRC= \ $(TMK_COMMON_SRC) \ $(QUANTUM_SRC) \ tests/test_common/matrix.c \ - tests/test_common/test_driver.cpp + tests/test_common/test_driver.cpp \ + tests/test_common/keyboard_report_util.cpp $(TEST)_DEFS=$(TMK_COMMON_DEFS) $(TEST)_CONFIG=$(TEST_PATH)/config.h VPATH+=$(TOP_DIR)/tests/test_common diff --git a/tests/basic/test.cpp b/tests/basic/test.cpp index e3190085d..804642eae 100644 --- a/tests/basic/test.cpp +++ b/tests/basic/test.cpp @@ -21,6 +21,7 @@ #include "keyboard.h" #include "test_driver.h" #include "test_matrix.h" +#include "keyboard_report_util.h" using testing::_; using testing::Return; @@ -32,7 +33,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }, }; -TEST(Basic, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { +TEST(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { TestDriver driver; EXPECT_CALL(driver, send_keyboard_mock(_)); keyboard_init(); @@ -41,12 +42,15 @@ TEST(Basic, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { keyboard_task(); } -TEST(Basic, SendKeyboardIsCalledWhenAKeyIsPressed) { +TEST(KeyPress, CorrectKeyIsReportedWhenPressed) { TestDriver driver; EXPECT_CALL(driver, send_keyboard_mock(_)); keyboard_init(); press_key(0, 0); EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); + keyboard_task(); +} EXPECT_CALL(driver, send_keyboard_mock(_)); keyboard_task(); } diff --git a/tests/test_common/keyboard_report_util.cpp b/tests/test_common/keyboard_report_util.cpp new file mode 100644 index 000000000..70fc1c048 --- /dev/null +++ b/tests/test_common/keyboard_report_util.cpp @@ -0,0 +1,47 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + #include "keyboard_report_util.h" + using namespace testing; + +bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) { + return memcmp(lhs.raw, rhs.raw, sizeof(lhs.raw))==0; +} + +std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) { + stream << "Keyboard report:" << std::endl; + stream << (uint32_t)value.keys[0] << std::endl; + return stream; +} + +KeyboardReportMatcher::KeyboardReportMatcher(const std::vector& keys) { + memset(m_report.raw, 0, sizeof(m_report.raw)); + for (auto k: keys) { + add_key_to_report(&m_report, k); + } +} + +bool KeyboardReportMatcher::MatchAndExplain(report_keyboard_t& report, MatchResultListener* listener) const { + return m_report == report; +} + +void KeyboardReportMatcher::DescribeTo(::std::ostream* os) const { + *os << "is equal to " << m_report; +} + +void KeyboardReportMatcher::DescribeNegationTo(::std::ostream* os) const { + *os << "is not equal to " << m_report; +} \ No newline at end of file diff --git a/tests/test_common/keyboard_report_util.h b/tests/test_common/keyboard_report_util.h new file mode 100644 index 000000000..48543c205 --- /dev/null +++ b/tests/test_common/keyboard_report_util.h @@ -0,0 +1,39 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include "report.h" +#include +#include "gmock/gmock.h" + +bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs); +std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value); + +class KeyboardReportMatcher : public testing::MatcherInterface { + public: + KeyboardReportMatcher(const std::vector& keys); + virtual bool MatchAndExplain(report_keyboard_t& report, testing::MatchResultListener* listener) const override; + virtual void DescribeTo(::std::ostream* os) const override; + virtual void DescribeNegationTo(::std::ostream* os) const override; +private: + report_keyboard_t m_report; +}; + + +template +inline testing::Matcher KeyboardReport(Ts... keys) { + return testing::MakeMatcher(new KeyboardReportMatcher(std::vector({keys...}))); +} \ No newline at end of file diff --git a/tests/test_common/test_driver.cpp b/tests/test_common/test_driver.cpp index 7c67f5776..9e618aa97 100644 --- a/tests/test_common/test_driver.cpp +++ b/tests/test_common/test_driver.cpp @@ -41,12 +41,12 @@ uint8_t TestDriver::keyboard_leds(void) { } void TestDriver::send_keyboard(report_keyboard_t* report) { - m_this->send_keyboard_mock(report); + m_this->send_keyboard_mock(*report); } void TestDriver::send_mouse(report_mouse_t* report) { - m_this->send_mouse_mock(report); + m_this->send_mouse_mock(*report); } void TestDriver::send_system(uint16_t data) { @@ -54,5 +54,5 @@ void TestDriver::send_system(uint16_t data) { } void TestDriver::send_consumer(uint16_t data) { - m_this->send_consumer_mock(data); + m_this->send_consumer(data); } diff --git a/tests/test_common/test_driver.h b/tests/test_common/test_driver.h index d5b831884..b1b95fbcc 100644 --- a/tests/test_common/test_driver.h +++ b/tests/test_common/test_driver.h @@ -20,6 +20,7 @@ #include "gmock/gmock.h" #include #include "host.h" +#include "keyboard_report_util.h" class TestDriver { @@ -27,8 +28,8 @@ public: TestDriver(); ~TestDriver(); MOCK_METHOD0(keyboard_leds_mock, uint8_t ()); - MOCK_METHOD1(send_keyboard_mock, void (report_keyboard_t*)); - MOCK_METHOD1(send_mouse_mock, void (report_mouse_t*)); + MOCK_METHOD1(send_keyboard_mock, void (report_keyboard_t&)); + MOCK_METHOD1(send_mouse_mock, void (report_mouse_t&)); MOCK_METHOD1(send_system_mock, void (uint16_t)); MOCK_METHOD1(send_consumer_mock, void (uint16_t)); private: -- cgit v1.2.3 From e85b1857968d4c0378b9778650c30b9d2bca3ea9 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 18 Jun 2017 14:40:22 +0300 Subject: Test two keys pressed at once --- tests/basic/test.cpp | 16 +++++++++++++++- tests/test_common/keyboard_report_util.cpp | 30 ++++++++++++++++++++++++++++-- tests/test_common/matrix.c | 2 ++ 3 files changed, 45 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/basic/test.cpp b/tests/basic/test.cpp index 804642eae..398063fca 100644 --- a/tests/basic/test.cpp +++ b/tests/basic/test.cpp @@ -51,6 +51,20 @@ TEST(KeyPress, CorrectKeyIsReportedWhenPressed) { EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); keyboard_task(); } - EXPECT_CALL(driver, send_keyboard_mock(_)); + +TEST(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { + TestDriver driver; + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + keyboard_init(); + press_key(1, 0); + press_key(0, 1); + EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); + //TODO: This is a left-over from the previous test and need to be fixed + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + keyboard_task(); + //Note that QMK only processes one key at a time + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))); + keyboard_task(); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C))); keyboard_task(); } diff --git a/tests/test_common/keyboard_report_util.cpp b/tests/test_common/keyboard_report_util.cpp index 70fc1c048..34e53cd4c 100644 --- a/tests/test_common/keyboard_report_util.cpp +++ b/tests/test_common/keyboard_report_util.cpp @@ -15,15 +15,41 @@ */ #include "keyboard_report_util.h" + #include + #include using namespace testing; + namespace + { + std::vector get_keys(const report_keyboard_t& report) { + std::vector result; + #if defined(NKRO_ENABLE) + #error NKRO support not implemented yet + #elif defined(USB_6KRO_ENABLE) + #error 6KRO support not implemented yet + #else + for(size_t i=0; i static matrix_row_t matrix[MATRIX_ROWS] = {}; void matrix_init(void) { + memset(matrix, 0, sizeof(matrix)); matrix_init_quantum(); } -- cgit v1.2.3 From 36f820be7e80bc8f1f5489373708356cf142c269 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 18 Jun 2017 23:49:38 +0300 Subject: Add a test fixture It only initializes QMK once, and clears the matrix after each test. --- build_full_test.mk | 3 ++- tests/basic/test.cpp | 19 ++++++------------- tests/test_common/matrix.c | 6 +++++- tests/test_common/test_fixture.cpp | 38 ++++++++++++++++++++++++++++++++++++++ tests/test_common/test_fixture.h | 28 ++++++++++++++++++++++++++++ tests/test_common/test_matrix.h | 1 + 6 files changed, 80 insertions(+), 15 deletions(-) create mode 100644 tests/test_common/test_fixture.cpp create mode 100644 tests/test_common/test_fixture.h (limited to 'tests') diff --git a/build_full_test.mk b/build_full_test.mk index 67c1ca5e5..bfd89174d 100644 --- a/build_full_test.mk +++ b/build_full_test.mk @@ -23,7 +23,8 @@ $(TEST)_SRC= \ $(QUANTUM_SRC) \ tests/test_common/matrix.c \ tests/test_common/test_driver.cpp \ - tests/test_common/keyboard_report_util.cpp + tests/test_common/keyboard_report_util.cpp \ + tests/test_common/test_fixture.cpp $(TEST)_DEFS=$(TMK_COMMON_DEFS) $(TEST)_CONFIG=$(TEST_PATH)/config.h VPATH+=$(TOP_DIR)/tests/test_common diff --git a/tests/basic/test.cpp b/tests/basic/test.cpp index 398063fca..26a09585c 100644 --- a/tests/basic/test.cpp +++ b/tests/basic/test.cpp @@ -18,10 +18,10 @@ #include "gmock/gmock.h" #include "quantum.h" -#include "keyboard.h" #include "test_driver.h" #include "test_matrix.h" #include "keyboard_report_util.h" +#include "test_fixture.h" using testing::_; using testing::Return; @@ -33,35 +33,28 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }, }; -TEST(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { +class KeyPress : public TestFixture {}; + +TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { TestDriver driver; - EXPECT_CALL(driver, send_keyboard_mock(_)); - keyboard_init(); EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); keyboard_task(); } -TEST(KeyPress, CorrectKeyIsReportedWhenPressed) { +TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) { TestDriver driver; - EXPECT_CALL(driver, send_keyboard_mock(_)); - keyboard_init(); press_key(0, 0); EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); keyboard_task(); } -TEST(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { +TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { TestDriver driver; - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); - keyboard_init(); press_key(1, 0); press_key(0, 1); EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); - //TODO: This is a left-over from the previous test and need to be fixed - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); - keyboard_task(); //Note that QMK only processes one key at a time EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))); keyboard_task(); diff --git a/tests/test_common/matrix.c b/tests/test_common/matrix.c index 5ab5bac6c..0d9fa68b0 100644 --- a/tests/test_common/matrix.c +++ b/tests/test_common/matrix.c @@ -22,7 +22,7 @@ static matrix_row_t matrix[MATRIX_ROWS] = {}; void matrix_init(void) { - memset(matrix, 0, sizeof(matrix)); + clear_all_keys(); matrix_init_quantum(); } @@ -54,3 +54,7 @@ void press_key(uint8_t col, uint8_t row) { void release_key(uint8_t col, uint8_t row) { matrix[row] &= ~(1 << col); } + +void clear_all_keys(void) { + memset(matrix, 0, sizeof(matrix)); +} diff --git a/tests/test_common/test_fixture.cpp b/tests/test_common/test_fixture.cpp new file mode 100644 index 000000000..aff518d21 --- /dev/null +++ b/tests/test_common/test_fixture.cpp @@ -0,0 +1,38 @@ +#include "test_fixture.h" +#include "gmock/gmock.h" +#include "test_driver.h" +#include "test_matrix.h" +#include "keyboard.h" + +using testing::_; +using testing::AnyNumber; +using testing::Return; +using testing::Between; + +void TestFixture::SetUpTestCase() { + TestDriver driver; + EXPECT_CALL(driver, send_keyboard_mock(_)); + keyboard_init(); +} + +void TestFixture::TearDownTestCase() { +} + +TestFixture::TestFixture() { +} + +TestFixture::~TestFixture() { + TestDriver driver; + clear_all_keys(); + // Run for a while to make sure all keys are completely released + // Should probably wait until tapping term etc, has timed out + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(AnyNumber()); + EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); + for (int i=0; i<100; i++) { + keyboard_task(); + } + testing::Mock::VerifyAndClearExpectations(&driver); + // Verify that the matrix really is cleared + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(Between(0, 1)); + EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); +} \ No newline at end of file diff --git a/tests/test_common/test_fixture.h b/tests/test_common/test_fixture.h new file mode 100644 index 000000000..a775a425a --- /dev/null +++ b/tests/test_common/test_fixture.h @@ -0,0 +1,28 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + #pragma once + +#include "gtest/gtest.h" + +class TestFixture : public testing::Test { +public: + TestFixture(); + ~TestFixture(); + static void SetUpTestCase(); + static void TearDownTestCase(); + +}; \ No newline at end of file diff --git a/tests/test_common/test_matrix.h b/tests/test_common/test_matrix.h index afc65c556..174fc4f22 100644 --- a/tests/test_common/test_matrix.h +++ b/tests/test_common/test_matrix.h @@ -23,6 +23,7 @@ extern "C" { void press_key(uint8_t col, uint8_t row); void release_key(uint8_t col, uint8_t row); +void clear_all_keys(void); #ifdef __cplusplus } -- cgit v1.2.3 From 43d8fa5bf1248ce5c1ce5f9cb0d238d794b4475d Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Mon, 19 Jun 2017 00:19:09 +0300 Subject: More natural interface for setting keyboard leds --- tests/basic/test.cpp | 3 --- tests/test_common/test_driver.cpp | 3 +-- tests/test_common/test_driver.h | 4 +++- tests/test_common/test_fixture.cpp | 2 -- 4 files changed, 4 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/basic/test.cpp b/tests/basic/test.cpp index 26a09585c..1bd5c2762 100644 --- a/tests/basic/test.cpp +++ b/tests/basic/test.cpp @@ -37,7 +37,6 @@ class KeyPress : public TestFixture {}; TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { TestDriver driver; - EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); keyboard_task(); } @@ -45,7 +44,6 @@ TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) { TestDriver driver; press_key(0, 0); - EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); keyboard_task(); } @@ -54,7 +52,6 @@ TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { TestDriver driver; press_key(1, 0); press_key(0, 1); - EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); //Note that QMK only processes one key at a time EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))); keyboard_task(); diff --git a/tests/test_common/test_driver.cpp b/tests/test_common/test_driver.cpp index 9e618aa97..feb80563a 100644 --- a/tests/test_common/test_driver.cpp +++ b/tests/test_common/test_driver.cpp @@ -27,7 +27,6 @@ TestDriver::TestDriver() &TestDriver::send_consumer } { - host_set_driver(&m_driver); m_this = this; } @@ -37,7 +36,7 @@ TestDriver::~TestDriver() { } uint8_t TestDriver::keyboard_leds(void) { - return m_this->keyboard_leds_mock(); + return m_this->m_leds; } void TestDriver::send_keyboard(report_keyboard_t* report) { diff --git a/tests/test_common/test_driver.h b/tests/test_common/test_driver.h index b1b95fbcc..0123fd539 100644 --- a/tests/test_common/test_driver.h +++ b/tests/test_common/test_driver.h @@ -27,7 +27,8 @@ class TestDriver { public: TestDriver(); ~TestDriver(); - MOCK_METHOD0(keyboard_leds_mock, uint8_t ()); + void set_leds(uint8_t leds) { m_leds = leds; } + MOCK_METHOD1(send_keyboard_mock, void (report_keyboard_t&)); MOCK_METHOD1(send_mouse_mock, void (report_mouse_t&)); MOCK_METHOD1(send_system_mock, void (uint16_t)); @@ -39,6 +40,7 @@ private: static void send_system(uint16_t data); static void send_consumer(uint16_t data); host_driver_t m_driver; + uint8_t m_leds = 0; static TestDriver* m_this; }; diff --git a/tests/test_common/test_fixture.cpp b/tests/test_common/test_fixture.cpp index aff518d21..eef9b854b 100644 --- a/tests/test_common/test_fixture.cpp +++ b/tests/test_common/test_fixture.cpp @@ -27,12 +27,10 @@ TestFixture::~TestFixture() { // Run for a while to make sure all keys are completely released // Should probably wait until tapping term etc, has timed out EXPECT_CALL(driver, send_keyboard_mock(_)).Times(AnyNumber()); - EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); for (int i=0; i<100; i++) { keyboard_task(); } testing::Mock::VerifyAndClearExpectations(&driver); // Verify that the matrix really is cleared EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(Between(0, 1)); - EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0)); } \ No newline at end of file -- cgit v1.2.3 From fb9b8dadb97e69f2c206a96e879a9350b535fe98 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Mon, 19 Jun 2017 00:22:12 +0300 Subject: Add a couple of todos to keyboard_report_util.cpp Also print the modifier state --- tests/test_common/keyboard_report_util.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/test_common/keyboard_report_util.cpp b/tests/test_common/keyboard_report_util.cpp index 34e53cd4c..aca4433dd 100644 --- a/tests/test_common/keyboard_report_util.cpp +++ b/tests/test_common/keyboard_report_util.cpp @@ -47,6 +47,8 @@ bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) { std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) { stream << "Keyboard report:" << std::endl; + stream << "Mods: " << value.mods << std::endl; + // TODO: This should probably print friendly names for the keys for (uint32_t k: get_keys(value)) { stream << k << std::endl; } @@ -54,6 +56,7 @@ std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) { } KeyboardReportMatcher::KeyboardReportMatcher(const std::vector& keys) { + // TODO: Support modifiers memset(m_report.raw, 0, sizeof(m_report.raw)); for (auto k: keys) { add_key_to_report(&m_report, k); -- cgit v1.2.3