Skip to content

Commit b6054c0

Browse files
KarlK90tzarc
andauthored
[Tests] Increase QMK test coverage (#13789)
* Add per-test keymaps * Add better trace and info logs for failed unit-tests * Add layer state assertion with tracing message * Use individual test binaries configuration options * Add basic qmk functionality tests * Add tap hold configurations tests * Add auto shift tests * `qmk format-c * Fix tests Co-authored-by: Nick Brassel <nick@tzarc.org>
1 parent f4966a1 commit b6054c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2688
-265
lines changed

Makefile

+4-3
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,12 @@ define PARSE_ALL_KEYMAPS
378378
endef
379379

380380
define BUILD_TEST
381-
TEST_NAME := $1
381+
TEST_PATH := $1
382+
TEST_NAME := $$(notdir $$(TEST_PATH))
382383
MAKE_TARGET := $2
383384
COMMAND := $1
384385
MAKE_CMD := $$(MAKE) -r -R -C $(ROOT_DIR) -f build_test.mk $$(MAKE_TARGET)
385-
MAKE_VARS := TEST=$$(TEST_NAME) FULL_TESTS="$$(FULL_TESTS)"
386+
MAKE_VARS := TEST=$$(TEST_NAME) TEST_PATH=$$(TEST_PATH) FULL_TESTS="$$(FULL_TESTS)"
386387
MAKE_MSG := $$(MSG_MAKE_TEST)
387388
$$(eval $$(call BUILD))
388389
ifneq ($$(MAKE_TARGET),clean)
@@ -406,7 +407,7 @@ define PARSE_TEST
406407
ifeq ($$(TEST_NAME),all)
407408
MATCHED_TESTS := $$(TEST_LIST)
408409
else
409-
MATCHED_TESTS := $$(foreach TEST,$$(TEST_LIST),$$(if $$(findstring $$(TEST_NAME),$$(TEST)),$$(TEST),))
410+
MATCHED_TESTS := $$(foreach TEST, $$(TEST_LIST),$$(if $$(findstring $$(TEST_NAME), $$(notdir $$(TEST))), $$(TEST),))
410411
endif
411412
$$(foreach TEST,$$(MATCHED_TESTS),$$(eval $$(call BUILD_TEST,$$(TEST),$$(TEST_TARGET))))
412413
endef

build_full_test.mk

+13-10
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,24 @@
1313
# You should have received a copy of the GNU General Public License
1414
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1515

16-
#include $(TMK_PATH)/protocol.mk
16+
$(TEST)_INC := \
17+
tests\test_common\common_config.h
1718

18-
TEST_PATH=tests/$(TEST)
19-
20-
$(TEST)_SRC= \
21-
$(TEST_PATH)/keymap.c \
19+
$(TEST)_SRC := \
2220
$(TMK_COMMON_SRC) \
2321
$(QUANTUM_SRC) \
2422
$(SRC) \
23+
tests/test_common/keymap.c \
2524
tests/test_common/matrix.c \
2625
tests/test_common/test_driver.cpp \
2726
tests/test_common/keyboard_report_util.cpp \
28-
tests/test_common/test_fixture.cpp
29-
$(TEST)_SRC += $(patsubst $(ROOTDIR)/%,%,$(wildcard $(TEST_PATH)/*.cpp))
27+
tests/test_common/test_fixture.cpp \
28+
tests/test_common/test_keymap_key.cpp \
29+
tests/test_common/test_logger.cpp \
30+
$(patsubst $(ROOTDIR)/%,%,$(wildcard $(TEST_PATH)/*.cpp))
31+
32+
$(TEST)_DEFS := $(TMK_COMMON_DEFS) $(OPT_DEFS)
33+
34+
$(TEST)_CONFIG := $(TEST_PATH)/config.h
3035

31-
$(TEST)_DEFS=$(TMK_COMMON_DEFS) $(OPT_DEFS)
32-
$(TEST)_CONFIG=$(TEST_PATH)/config.h
33-
VPATH+=$(TOP_DIR)/tests/test_common
36+
VPATH += $(TOP_DIR)/tests/test_common

build_test.mk

+10-9
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ TEST_OBJ = $(BUILD_DIR)/test_obj
1616
OUTPUTS := $(TEST_OBJ)/$(TEST) $(GTEST_OUTPUT)
1717

1818
GTEST_INC := \
19-
$(LIB_PATH)/googletest/googletest/include\
20-
$(LIB_PATH)/googletest/googlemock/include\
19+
$(LIB_PATH)/googletest/googletest/include \
20+
$(LIB_PATH)/googletest/googlemock/include
2121

22-
GTEST_INTERNAL_INC :=\
23-
$(LIB_PATH)/googletest/googletest\
22+
GTEST_INTERNAL_INC := \
23+
$(LIB_PATH)/googletest/googletest \
2424
$(LIB_PATH)/googletest/googlemock
2525

26-
$(GTEST_OUTPUT)_SRC :=\
26+
$(GTEST_OUTPUT)_SRC := \
2727
googletest/src/gtest-all.cc\
2828
googlemock/src/gmock-all.cc
2929

@@ -33,9 +33,9 @@ $(GTEST_OUTPUT)_INC := $(GTEST_INC) $(GTEST_INTERNAL_INC)
3333
LDFLAGS += -lstdc++ -lpthread -shared-libgcc
3434
CREATE_MAP := no
3535

36-
VPATH +=\
37-
$(LIB_PATH)/googletest\
38-
$(LIB_PATH)/googlemock\
36+
VPATH += \
37+
$(LIB_PATH)/googletest \
38+
$(LIB_PATH)/googlemock \
3939
$(LIB_PATH)/printf
4040

4141
all: elf
@@ -49,7 +49,8 @@ CONSOLE_ENABLE = yes
4949
endif
5050

5151
ifneq ($(filter $(FULL_TESTS),$(TEST)),)
52-
include tests/$(TEST)/rules.mk
52+
include tests/test_common/build.mk
53+
include $(TEST_PATH)/test.mk
5354
endif
5455

5556
include common_features.mk

quantum/quantum_keycodes.h

-34
Original file line numberDiff line numberDiff line change
@@ -558,40 +558,6 @@ enum quantum_keycodes {
558558
PROGRAMMABLE_BUTTON_31,
559559
PROGRAMMABLE_BUTTON_32,
560560

561-
// Dedicated macro keys for Configurator and VIA
562-
MACRO_0,
563-
MACRO_1,
564-
MACRO_2,
565-
MACRO_3,
566-
MACRO_4,
567-
MACRO_5,
568-
MACRO_6,
569-
MACRO_7,
570-
MACRO_8,
571-
MACRO_9,
572-
MACRO_10,
573-
MACRO_11,
574-
MACRO_12,
575-
MACRO_13,
576-
MACRO_14,
577-
MACRO_15,
578-
MACRO_16,
579-
MACRO_17,
580-
MACRO_18,
581-
MACRO_19,
582-
MACRO_20,
583-
MACRO_21,
584-
MACRO_22,
585-
MACRO_23,
586-
MACRO_24,
587-
MACRO_25,
588-
MACRO_26,
589-
MACRO_27,
590-
MACRO_28,
591-
MACRO_29,
592-
MACRO_30,
593-
MACRO_31,
594-
595561
// Start of custom keycode range for keyboards and keymaps - always leave at the end
596562
SAFE_RANGE
597563
};

testlist.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
TEST_LIST = $(notdir $(patsubst %/rules.mk,%,$(wildcard $(ROOT_DIR)/tests/*/rules.mk)))
2-
FULL_TESTS := $(TEST_LIST)
1+
TEST_LIST = $(sort $(patsubst %/test.mk,%, $(shell find $(ROOT_DIR)tests -type f -name test.mk)))
2+
FULL_TESTS := $(notdir $(TEST_LIST))
33

44
include $(QUANTUM_PATH)/debounce/tests/testlist.mk
55
include $(QUANTUM_PATH)/encoder/tests/testlist.mk

tests/auto_shift/config.h

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* Copyright 2021 Stefan Kerkmann
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU General Public License as published by
5+
* the Free Software Foundation, either version 2 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
#pragma once
18+
19+
#include "test_common.h"

tests/auto_shift/test.mk

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2021 Stefan Kerkmann
2+
#
3+
# This program is free software: you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation, either version 2 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
16+
# --------------------------------------------------------------------------------
17+
# Keep this file, even if it is empty, as a marker that this folder contains tests
18+
# --------------------------------------------------------------------------------
19+
20+
AUTO_SHIFT_ENABLE = yes

tests/auto_shift/test_auto_shift.cpp

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/* Copyright 2021 Stefan Kerkmann
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU General Public License as published by
5+
* the Free Software Foundation, either version 2 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
#include "keyboard_report_util.hpp"
18+
#include "keycode.h"
19+
#include "test_common.hpp"
20+
#include "action_tapping.h"
21+
#include "test_fixture.hpp"
22+
#include "test_keymap_key.hpp"
23+
24+
using testing::_;
25+
using testing::InSequence;
26+
27+
class AutoShift : public TestFixture {};
28+
29+
TEST_F(AutoShift, key_release_before_timeout) {
30+
TestDriver driver;
31+
InSequence s;
32+
auto regular_key = KeymapKey(0, 2, 0, KC_A);
33+
34+
set_keymap({regular_key});
35+
36+
/* Press regular key */
37+
EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
38+
regular_key.press();
39+
run_one_scan_loop();
40+
testing::Mock::VerifyAndClearExpectations(&driver);
41+
42+
/* Release regular key */
43+
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A)));
44+
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
45+
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
46+
regular_key.release();
47+
run_one_scan_loop();
48+
testing::Mock::VerifyAndClearExpectations(&driver);
49+
}
50+
51+
TEST_F(AutoShift, key_release_after_timeout) {
52+
TestDriver driver;
53+
InSequence s;
54+
auto regular_key = KeymapKey(0, 2, 0, KC_A);
55+
56+
set_keymap({regular_key});
57+
58+
/* Press regular key */
59+
EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
60+
regular_key.press();
61+
idle_for(AUTO_SHIFT_TIMEOUT);
62+
testing::Mock::VerifyAndClearExpectations(&driver);
63+
64+
/* Release regular key */
65+
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_A)));
66+
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
67+
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
68+
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
69+
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
70+
regular_key.release();
71+
run_one_scan_loop();
72+
testing::Mock::VerifyAndClearExpectations(&driver);
73+
}

tests/basic/config.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@
1616

1717
#pragma once
1818

19-
#define MATRIX_ROWS 4
20-
#define MATRIX_COLS 10
19+
#include "test_common.h"

tests/basic/keymap.c

-45
This file was deleted.

tests/basic/test.mk

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2017 Fred Sundvik
2+
#
3+
# This program is free software: you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation, either version 2 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
16+
# --------------------------------------------------------------------------------
17+
# Keep this file, even if it is empty, as a marker that this folder contains tests
18+
# --------------------------------------------------------------------------------

0 commit comments

Comments
 (0)