From f02fa01e9a9af1a1637a387f3e8044a791b47ced Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Fri, 28 Aug 2020 16:21:31 -0400 Subject: [PATCH 01/17] fix(test): change the layout --- app/boards/native_posix.conf | 3 +- app/boards/native_posix.overlay | 73 ++----------------- app/dts/bindings/zmk,kscan-mock.yaml | 2 + .../{ => dt-bindings}/zmk/kscan-mock.h | 0 app/prj.conf | 0 app/run-test.sh | 17 +++++ app/src/kscan_mock.c | 12 ++- app/tests/keypress/behavior_keymap.dtsi | 28 +++++++ .../keypress/cp-press-release/events.patterns | 1 + .../cp-press-release/keycode_events.snapshot | 2 + .../cp-press-release/native_posix.keymap | 5 ++ .../keypress/kp-press-release/events.patterns | 1 + .../kp-press-release/keycode_events.snapshot | 2 + .../kp-press-release/native_posix.keymap | 8 ++ 14 files changed, 82 insertions(+), 72 deletions(-) rename app/include/{ => dt-bindings}/zmk/kscan-mock.h (100%) create mode 100644 app/prj.conf create mode 100755 app/run-test.sh create mode 100644 app/tests/keypress/behavior_keymap.dtsi create mode 100644 app/tests/keypress/cp-press-release/events.patterns create mode 100644 app/tests/keypress/cp-press-release/keycode_events.snapshot create mode 100644 app/tests/keypress/cp-press-release/native_posix.keymap create mode 100644 app/tests/keypress/kp-press-release/events.patterns create mode 100644 app/tests/keypress/kp-press-release/keycode_events.snapshot create mode 100644 app/tests/keypress/kp-press-release/native_posix.keymap diff --git a/app/boards/native_posix.conf b/app/boards/native_posix.conf index 5bfb366c..357b1b86 100644 --- a/app/boards/native_posix.conf +++ b/app/boards/native_posix.conf @@ -1,9 +1,8 @@ CONFIG_KSCAN=n CONFIG_ZMK_KSCAN_MOCK_DRIVER=y -CONFIG_ZMK_KSCAN_COMPOSITE_DRIVER=y CONFIG_ZMK_KSCAN_GPIO_DRIVER=n CONFIG_GPIO=n CONFIG_ZMK_BLE=n CONFIG_LOG=y -CONFIG_KSCAN_LOG_LEVEL_DBG=y +CONFIG_LOG_BACKEND_SHOW_COLOR=n CONFIG_ZMK_LOG_LEVEL_DBG=y diff --git a/app/boards/native_posix.overlay b/app/boards/native_posix.overlay index e9c4c959..bbb23b65 100644 --- a/app/boards/native_posix.overlay +++ b/app/boards/native_posix.overlay @@ -1,79 +1,18 @@ -#include #include -#include +#include +#include / { chosen { - zmk,kscan = &kscan0; - zmk,keymap = &keymap0; + zmk,kscan = &kscan; }; - kscan0: kscan_0 { - compatible = "zmk,kscan-composite"; - label = "KSCAN_COMP"; - rows = <2>; - columns = <4>; - - left: left { - kscan = <&left_hand>; - }; - - right: right { - kscan = <&right_hand>; - column-offset = <2>; - }; - }; - - left_hand: kscan_1 { + kscan: kscan { compatible = "zmk,kscan-mock"; - label = "KSCAN_LEFT"; + label = "KSCAN_MOCK"; rows = <2>; columns = <2>; - events = ; - // events = ; - }; - - right_hand: kscan_2 { - compatible = "zmk,kscan-mock"; - label = "KSCAN_RIGHT"; - - rows = <2>; - columns = <2>; - events = ; - }; - - keymap0: keymap { - compatible = "zmk,keymap"; - label ="Default keymap"; - layers = <&default &lower &raise>; - }; - - layers { - compatible = "zmk,layers"; - - default: layer_0 { - label = "DEFAULT"; - - bindings = < - &kp B &mo 1 &kp C &kp E - &kp D &kp G &kp F &kp Q>; - }; - - lower: layer_1 { - label = "LOWER"; - - bindings = < - &cp M_NEXT &trans &kp O &kp Q - &kp L &kp J &kp P &kp K>; - }; - - raise: layer_2 { - label = "RAISE"; - - bindings = < - &kp W &kp U &kp I &kp N - &kp X &kp M &kp C &kp B>; - }; + exit-after; }; }; diff --git a/app/dts/bindings/zmk,kscan-mock.yaml b/app/dts/bindings/zmk,kscan-mock.yaml index 41dd5b81..f9d83fa7 100644 --- a/app/dts/bindings/zmk,kscan-mock.yaml +++ b/app/dts/bindings/zmk,kscan-mock.yaml @@ -15,3 +15,5 @@ properties: type: int columns: type: int + exit-after: + type: boolean diff --git a/app/include/zmk/kscan-mock.h b/app/include/dt-bindings/zmk/kscan-mock.h similarity index 100% rename from app/include/zmk/kscan-mock.h rename to app/include/dt-bindings/zmk/kscan-mock.h diff --git a/app/prj.conf b/app/prj.conf new file mode 100644 index 00000000..e69de29b diff --git a/app/run-test.sh b/app/run-test.sh new file mode 100755 index 00000000..4ed12a2c --- /dev/null +++ b/app/run-test.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +if [ -z "$1" ]; then + echo "Usage: ./run-test.sh " + exit 1 +elif [ "$1" = "all" ]; then + find tests -name native_posix.keymap -exec dirname \{\} \; | xargs -l -P 2 ./run-test.sh + exit $? +fi + +testcase="$1" +echo "Running $testcase:" + +west build --pristine -d build/$testcase -b native_posix -- -DZMK_CONFIG=$testcase > /dev/null +./build/$testcase/zephyr/zmk.exe | sed -e "s/.*> //" | sed -n -f $testcase/events.patterns > build/$testcase/keycode_events.log + +diff -au $testcase/keycode_events.snapshot build/$testcase/keycode_events.log diff --git a/app/src/kscan_mock.c b/app/src/kscan_mock.c index b0ba90bb..1bd8a748 100644 --- a/app/src/kscan_mock.c +++ b/app/src/kscan_mock.c @@ -6,13 +6,14 @@ #define DT_DRV_COMPAT zmk_kscan_mock +#include #include #include #include LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); -#include +#include struct kscan_mock_data { @@ -50,6 +51,7 @@ static int kscan_mock_configure(struct device *dev, kscan_callback_t callback) struct kscan_mock_config_##n \ { \ u32_t events[DT_INST_PROP_LEN(n, events)]; \ + bool exit_after; \ }; \ static void kscan_mock_schedule_next_event_##n(struct device *dev) \ { \ @@ -60,6 +62,9 @@ static int kscan_mock_configure(struct device *dev, kscan_callback_t callback) u32_t ev = cfg->events[data->event_index]; \ LOG_DBG("delaying next keypress: %d", ZMK_MOCK_MSEC(ev)); \ k_delayed_work_submit(&data->work, K_MSEC(ZMK_MOCK_MSEC(ev))); \ + } else if (cfg->exit_after) { \ + LOG_DBG("Exiting"); \ + exit(0); \ } \ } \ static void kscan_mock_work_handler_##n(struct k_work *work) \ @@ -93,11 +98,12 @@ static int kscan_mock_configure(struct device *dev, kscan_callback_t callback) }; \ static struct kscan_mock_data kscan_mock_data_##n; \ static const struct kscan_mock_config_##n kscan_mock_config_##n = { \ - .events = DT_INST_PROP(n, events)}; \ + .events = DT_INST_PROP(n, events), \ + .exit_after = DT_INST_PROP(n, exit_after) }; \ DEVICE_AND_API_INIT(kscan_mock_##n, DT_INST_LABEL(n), kscan_mock_init_##n, \ &kscan_mock_data_##n, \ &kscan_mock_config_##n, \ APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ &mock_driver_api_##n); -DT_INST_FOREACH_STATUS_OKAY(MOCK_INST_INIT) \ No newline at end of file +DT_INST_FOREACH_STATUS_OKAY(MOCK_INST_INIT) diff --git a/app/tests/keypress/behavior_keymap.dtsi b/app/tests/keypress/behavior_keymap.dtsi new file mode 100644 index 00000000..34c445cf --- /dev/null +++ b/app/tests/keypress/behavior_keymap.dtsi @@ -0,0 +1,28 @@ +#include +#include +#include + +/ { + keymap { + compatible = "zmk,keymap"; + label ="Default keymap"; + + default_layer { + bindings = < + &kp B &mo 1 + &kp D &kp G>; + }; + + lower_layer { + bindings = < + &cp M_NEXT &trans + &kp L &kp J>; + }; + + raise_layer { + bindings = < + &kp W &kp U + &kp X &kp M>; + }; + }; +}; diff --git a/app/tests/keypress/cp-press-release/events.patterns b/app/tests/keypress/cp-press-release/events.patterns new file mode 100644 index 00000000..833100f6 --- /dev/null +++ b/app/tests/keypress/cp-press-release/events.patterns @@ -0,0 +1 @@ +s/.*hid_listener_keycode_//p \ No newline at end of file diff --git a/app/tests/keypress/cp-press-release/keycode_events.snapshot b/app/tests/keypress/cp-press-release/keycode_events.snapshot new file mode 100644 index 00000000..f1ef0eda --- /dev/null +++ b/app/tests/keypress/cp-press-release/keycode_events.snapshot @@ -0,0 +1,2 @@ +pressed: usage_page 0x0c keycode 0xb5 +released: usage_page 0x0c keycode 0xb5 diff --git a/app/tests/keypress/cp-press-release/native_posix.keymap b/app/tests/keypress/cp-press-release/native_posix.keymap new file mode 100644 index 00000000..7f9ae8af --- /dev/null +++ b/app/tests/keypress/cp-press-release/native_posix.keymap @@ -0,0 +1,5 @@ +#include "../behavior_keymap.dtsi" + +&kscan { + events = ; +}; \ No newline at end of file diff --git a/app/tests/keypress/kp-press-release/events.patterns b/app/tests/keypress/kp-press-release/events.patterns new file mode 100644 index 00000000..833100f6 --- /dev/null +++ b/app/tests/keypress/kp-press-release/events.patterns @@ -0,0 +1 @@ +s/.*hid_listener_keycode_//p \ No newline at end of file diff --git a/app/tests/keypress/kp-press-release/keycode_events.snapshot b/app/tests/keypress/kp-press-release/keycode_events.snapshot new file mode 100644 index 00000000..f1ef0eda --- /dev/null +++ b/app/tests/keypress/kp-press-release/keycode_events.snapshot @@ -0,0 +1,2 @@ +pressed: usage_page 0x0c keycode 0xb5 +released: usage_page 0x0c keycode 0xb5 diff --git a/app/tests/keypress/kp-press-release/native_posix.keymap b/app/tests/keypress/kp-press-release/native_posix.keymap new file mode 100644 index 00000000..235348e9 --- /dev/null +++ b/app/tests/keypress/kp-press-release/native_posix.keymap @@ -0,0 +1,8 @@ +#include +#include +#include +#include "../behavior_keymap.dtsi" + +&kscan { + events = ; +}; \ No newline at end of file From 5b21f15a0a3e2d27d57b7a657d031a66d1124701 Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Fri, 28 Aug 2020 16:21:31 -0400 Subject: [PATCH 02/17] fix(test): off by one error with kscan processing --- app/src/kscan_mock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/kscan_mock.c b/app/src/kscan_mock.c index 1bd8a748..d626c71e 100644 --- a/app/src/kscan_mock.c +++ b/app/src/kscan_mock.c @@ -72,12 +72,13 @@ static int kscan_mock_configure(struct device *dev, kscan_callback_t callback) struct kscan_mock_data *data = \ CONTAINER_OF(work, struct kscan_mock_data, work); \ const struct kscan_mock_config_##n *cfg = data->dev->config_info; \ - u32_t ev = cfg->events[data->event_index++]; \ + u32_t ev = cfg->events[data->event_index]; \ LOG_DBG("ev %u row %d column %d state %d\n", ev, \ ZMK_MOCK_ROW(ev), ZMK_MOCK_COL(ev), ZMK_MOCK_IS_PRESS(ev)); \ data->callback(data->dev, \ ZMK_MOCK_ROW(ev), ZMK_MOCK_COL(ev), ZMK_MOCK_IS_PRESS(ev)); \ kscan_mock_schedule_next_event_##n(data->dev); \ + data->event_index++; \ } \ static int kscan_mock_init_##n(struct device *dev) \ { \ From 5f56266a6953dd1ebeb95ded4213e74f9572ae4d Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Fri, 28 Aug 2020 16:21:31 -0400 Subject: [PATCH 03/17] feat(test): add tests for momentary layers --- .../momentary-layer/behavior_keymap.dtsi | 28 +++++++++++++++++++ .../early-key-release/events.patterns | 2 ++ .../early-key-release/keycode_events.snapshot | 4 +++ .../early-key-release/native_posix.keymap | 8 ++++++ .../momentary-layer/normal/events.patterns | 2 ++ .../normal/keycode_events.snapshot | 4 +++ .../normal/native_posix.keymap | 8 ++++++ 7 files changed, 56 insertions(+) create mode 100644 app/tests/momentary-layer/behavior_keymap.dtsi create mode 100644 app/tests/momentary-layer/early-key-release/events.patterns create mode 100644 app/tests/momentary-layer/early-key-release/keycode_events.snapshot create mode 100644 app/tests/momentary-layer/early-key-release/native_posix.keymap create mode 100644 app/tests/momentary-layer/normal/events.patterns create mode 100644 app/tests/momentary-layer/normal/keycode_events.snapshot create mode 100644 app/tests/momentary-layer/normal/native_posix.keymap diff --git a/app/tests/momentary-layer/behavior_keymap.dtsi b/app/tests/momentary-layer/behavior_keymap.dtsi new file mode 100644 index 00000000..34c445cf --- /dev/null +++ b/app/tests/momentary-layer/behavior_keymap.dtsi @@ -0,0 +1,28 @@ +#include +#include +#include + +/ { + keymap { + compatible = "zmk,keymap"; + label ="Default keymap"; + + default_layer { + bindings = < + &kp B &mo 1 + &kp D &kp G>; + }; + + lower_layer { + bindings = < + &cp M_NEXT &trans + &kp L &kp J>; + }; + + raise_layer { + bindings = < + &kp W &kp U + &kp X &kp M>; + }; + }; +}; diff --git a/app/tests/momentary-layer/early-key-release/events.patterns b/app/tests/momentary-layer/early-key-release/events.patterns new file mode 100644 index 00000000..bd7b4880 --- /dev/null +++ b/app/tests/momentary-layer/early-key-release/events.patterns @@ -0,0 +1,2 @@ +s/.*hid_listener_keycode/kp/p +s/.*mo_keymap_binding/mo/p \ No newline at end of file diff --git a/app/tests/momentary-layer/early-key-release/keycode_events.snapshot b/app/tests/momentary-layer/early-key-release/keycode_events.snapshot new file mode 100644 index 00000000..474eef7a --- /dev/null +++ b/app/tests/momentary-layer/early-key-release/keycode_events.snapshot @@ -0,0 +1,4 @@ +kp_pressed: usage_page 0x07 keycode 0x05 +mo_pressed: position 1 layer 1 +kp_released: usage_page 0x07 keycode 0x05 +mo_released: position 1 layer 1 diff --git a/app/tests/momentary-layer/early-key-release/native_posix.keymap b/app/tests/momentary-layer/early-key-release/native_posix.keymap new file mode 100644 index 00000000..a58ad26c --- /dev/null +++ b/app/tests/momentary-layer/early-key-release/native_posix.keymap @@ -0,0 +1,8 @@ +#include +#include +#include +#include "../behavior_keymap.dtsi" + +&kscan { + events = ; +}; \ No newline at end of file diff --git a/app/tests/momentary-layer/normal/events.patterns b/app/tests/momentary-layer/normal/events.patterns new file mode 100644 index 00000000..bd7b4880 --- /dev/null +++ b/app/tests/momentary-layer/normal/events.patterns @@ -0,0 +1,2 @@ +s/.*hid_listener_keycode/kp/p +s/.*mo_keymap_binding/mo/p \ No newline at end of file diff --git a/app/tests/momentary-layer/normal/keycode_events.snapshot b/app/tests/momentary-layer/normal/keycode_events.snapshot new file mode 100644 index 00000000..f3fca66f --- /dev/null +++ b/app/tests/momentary-layer/normal/keycode_events.snapshot @@ -0,0 +1,4 @@ +mo_pressed: position 1 layer 1 +kp_pressed: usage_page 0x0c keycode 0xb5 +kp_released: usage_page 0x0c keycode 0xb5 +mo_released: position 1 layer 1 \ No newline at end of file diff --git a/app/tests/momentary-layer/normal/native_posix.keymap b/app/tests/momentary-layer/normal/native_posix.keymap new file mode 100644 index 00000000..1b678585 --- /dev/null +++ b/app/tests/momentary-layer/normal/native_posix.keymap @@ -0,0 +1,8 @@ +#include +#include +#include +#include "../behavior_keymap.dtsi" + +&kscan { + events = ; +}; \ No newline at end of file From f1224422c502cb86c9138c42e28eb645fe62272f Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Fri, 28 Aug 2020 16:21:31 -0400 Subject: [PATCH 04/17] fix(test): stop using pristine and use 4 threads --- app/run-test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/run-test.sh b/app/run-test.sh index 4ed12a2c..722cb939 100755 --- a/app/run-test.sh +++ b/app/run-test.sh @@ -4,14 +4,14 @@ if [ -z "$1" ]; then echo "Usage: ./run-test.sh " exit 1 elif [ "$1" = "all" ]; then - find tests -name native_posix.keymap -exec dirname \{\} \; | xargs -l -P 2 ./run-test.sh + find tests -name native_posix.keymap -exec dirname \{\} \; | xargs -l -P 4 ./run-test.sh exit $? fi testcase="$1" echo "Running $testcase:" -west build --pristine -d build/$testcase -b native_posix -- -DZMK_CONFIG=$testcase > /dev/null +west build -d build/$testcase -b native_posix -- -DZMK_CONFIG=$testcase > /dev/null ./build/$testcase/zephyr/zmk.exe | sed -e "s/.*> //" | sed -n -f $testcase/events.patterns > build/$testcase/keycode_events.log diff -au $testcase/keycode_events.snapshot build/$testcase/keycode_events.log From de92bf2b2de4a895dd36cffb549772f48428a0db Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Fri, 28 Aug 2020 16:21:31 -0400 Subject: [PATCH 05/17] fix(test): use a smaller value for mock key intervals --- app/tests/keypress/cp-press-release/native_posix.keymap | 2 +- app/tests/keypress/kp-press-release/native_posix.keymap | 2 +- app/tests/momentary-layer/early-key-release/native_posix.keymap | 2 +- app/tests/momentary-layer/normal/native_posix.keymap | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/tests/keypress/cp-press-release/native_posix.keymap b/app/tests/keypress/cp-press-release/native_posix.keymap index 7f9ae8af..0e86f935 100644 --- a/app/tests/keypress/cp-press-release/native_posix.keymap +++ b/app/tests/keypress/cp-press-release/native_posix.keymap @@ -1,5 +1,5 @@ #include "../behavior_keymap.dtsi" &kscan { - events = ; + events = ; }; \ No newline at end of file diff --git a/app/tests/keypress/kp-press-release/native_posix.keymap b/app/tests/keypress/kp-press-release/native_posix.keymap index 235348e9..7f736904 100644 --- a/app/tests/keypress/kp-press-release/native_posix.keymap +++ b/app/tests/keypress/kp-press-release/native_posix.keymap @@ -4,5 +4,5 @@ #include "../behavior_keymap.dtsi" &kscan { - events = ; + events = ; }; \ No newline at end of file diff --git a/app/tests/momentary-layer/early-key-release/native_posix.keymap b/app/tests/momentary-layer/early-key-release/native_posix.keymap index a58ad26c..e7628c0e 100644 --- a/app/tests/momentary-layer/early-key-release/native_posix.keymap +++ b/app/tests/momentary-layer/early-key-release/native_posix.keymap @@ -4,5 +4,5 @@ #include "../behavior_keymap.dtsi" &kscan { - events = ; + events = ; }; \ No newline at end of file diff --git a/app/tests/momentary-layer/normal/native_posix.keymap b/app/tests/momentary-layer/normal/native_posix.keymap index 1b678585..7f736904 100644 --- a/app/tests/momentary-layer/normal/native_posix.keymap +++ b/app/tests/momentary-layer/normal/native_posix.keymap @@ -4,5 +4,5 @@ #include "../behavior_keymap.dtsi" &kscan { - events = ; + events = ; }; \ No newline at end of file From abf8b5abfae2c240e71db11f13183369a14333d7 Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Fri, 28 Aug 2020 16:21:31 -0400 Subject: [PATCH 06/17] fix(test): fix normal momentary-layer test snapshot --- app/tests/momentary-layer/normal/keycode_events.snapshot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/tests/momentary-layer/normal/keycode_events.snapshot b/app/tests/momentary-layer/normal/keycode_events.snapshot index f3fca66f..9dc6101c 100644 --- a/app/tests/momentary-layer/normal/keycode_events.snapshot +++ b/app/tests/momentary-layer/normal/keycode_events.snapshot @@ -1,4 +1,4 @@ mo_pressed: position 1 layer 1 kp_pressed: usage_page 0x0c keycode 0xb5 kp_released: usage_page 0x0c keycode 0xb5 -mo_released: position 1 layer 1 \ No newline at end of file +mo_released: position 1 layer 1 From 3d325ccb84ecd3b25dd86d829c448dfd9b41a08f Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Fri, 28 Aug 2020 16:21:31 -0400 Subject: [PATCH 07/17] feat(test): add tests for none behavior --- app/tests/none/behavior_keymap.dtsi | 22 +++++++++++++++++++ app/tests/none/layered/events.patterns | 1 + .../none/layered/keycode_events.snapshot | 0 app/tests/none/layered/native_posix.keymap | 8 +++++++ app/tests/none/normal/events.patterns | 1 + app/tests/none/normal/keycode_events.snapshot | 0 app/tests/none/normal/native_posix.keymap | 8 +++++++ 7 files changed, 40 insertions(+) create mode 100644 app/tests/none/behavior_keymap.dtsi create mode 100644 app/tests/none/layered/events.patterns create mode 100644 app/tests/none/layered/keycode_events.snapshot create mode 100644 app/tests/none/layered/native_posix.keymap create mode 100644 app/tests/none/normal/events.patterns create mode 100644 app/tests/none/normal/keycode_events.snapshot create mode 100644 app/tests/none/normal/native_posix.keymap diff --git a/app/tests/none/behavior_keymap.dtsi b/app/tests/none/behavior_keymap.dtsi new file mode 100644 index 00000000..0a4f7cb7 --- /dev/null +++ b/app/tests/none/behavior_keymap.dtsi @@ -0,0 +1,22 @@ +#include +#include +#include + +/ { + keymap { + compatible = "zmk,keymap"; + label ="Default keymap"; + + default_layer { + bindings = < + &none &mo 1 + &kp A &none>; + }; + + lower_layer { + bindings = < + &none &trans + &none &kp A>; + }; + }; +}; diff --git a/app/tests/none/layered/events.patterns b/app/tests/none/layered/events.patterns new file mode 100644 index 00000000..3c9d3f83 --- /dev/null +++ b/app/tests/none/layered/events.patterns @@ -0,0 +1 @@ +s/.*hid_listener_keycode/kp/p \ No newline at end of file diff --git a/app/tests/none/layered/keycode_events.snapshot b/app/tests/none/layered/keycode_events.snapshot new file mode 100644 index 00000000..e69de29b diff --git a/app/tests/none/layered/native_posix.keymap b/app/tests/none/layered/native_posix.keymap new file mode 100644 index 00000000..59ea4811 --- /dev/null +++ b/app/tests/none/layered/native_posix.keymap @@ -0,0 +1,8 @@ +#include +#include +#include +#include "../behavior_keymap.dtsi" + +&kscan { + events = ; +}; \ No newline at end of file diff --git a/app/tests/none/normal/events.patterns b/app/tests/none/normal/events.patterns new file mode 100644 index 00000000..3c9d3f83 --- /dev/null +++ b/app/tests/none/normal/events.patterns @@ -0,0 +1 @@ +s/.*hid_listener_keycode/kp/p \ No newline at end of file diff --git a/app/tests/none/normal/keycode_events.snapshot b/app/tests/none/normal/keycode_events.snapshot new file mode 100644 index 00000000..e69de29b diff --git a/app/tests/none/normal/native_posix.keymap b/app/tests/none/normal/native_posix.keymap new file mode 100644 index 00000000..94d7539c --- /dev/null +++ b/app/tests/none/normal/native_posix.keymap @@ -0,0 +1,8 @@ +#include +#include +#include +#include "../behavior_keymap.dtsi" + +&kscan { + events = ; +}; \ No newline at end of file From 033bb7bfc4e1772ea19784bd71a57f49b4368e2d Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Fri, 28 Aug 2020 16:21:31 -0400 Subject: [PATCH 08/17] fix(behavior): add logging to toggle layer for tests --- app/src/behaviors/behavior_toggle_layer.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/src/behaviors/behavior_toggle_layer.c b/app/src/behaviors/behavior_toggle_layer.c index 13f4a29d..02a76d29 100644 --- a/app/src/behaviors/behavior_toggle_layer.c +++ b/app/src/behaviors/behavior_toggle_layer.c @@ -14,28 +14,35 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); -struct behavior_tog_config { }; -struct behavior_tog_data { }; +struct behavior_tog_config +{ +}; +struct behavior_tog_data +{ +}; static int behavior_tog_init(struct device *dev) { - return 0; + return 0; }; - static int tog_keymap_binding_pressed(struct device *dev, u32_t position, u32_t layer, u32_t _) { + LOG_DBG("position %d layer %d", position, layer); + return zmk_keymap_layer_toggle(layer); } static int tog_keymap_binding_released(struct device *dev, u32_t position, u32_t layer, u32_t _) { + LOG_DBG("position %d layer %d", position, layer); + return 0; } static const struct behavior_driver_api behavior_tog_driver_api = { - .binding_pressed = tog_keymap_binding_pressed, - .binding_released = tog_keymap_binding_released, + .binding_pressed = tog_keymap_binding_pressed, + .binding_released = tog_keymap_binding_released, }; static const struct behavior_tog_config behavior_tog_config = {}; From a722cbcea37e276a1778c6b0d0e3154fbe70334f Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Fri, 28 Aug 2020 16:21:31 -0400 Subject: [PATCH 09/17] feat(test): add tests for toggle layer --- app/tests/toggle-layer/behavior_keymap.dtsi | 28 +++++++++++++++++++ .../early-key-release/events.patterns | 2 ++ .../early-key-release/keycode_events.snapshot | 6 ++++ .../early-key-release/native_posix.keymap | 9 ++++++ app/tests/toggle-layer/normal/events.patterns | 2 ++ .../normal/keycode_events.snapshot | 4 +++ .../toggle-layer/normal/native_posix.keymap | 8 ++++++ 7 files changed, 59 insertions(+) create mode 100644 app/tests/toggle-layer/behavior_keymap.dtsi create mode 100644 app/tests/toggle-layer/early-key-release/events.patterns create mode 100644 app/tests/toggle-layer/early-key-release/keycode_events.snapshot create mode 100644 app/tests/toggle-layer/early-key-release/native_posix.keymap create mode 100644 app/tests/toggle-layer/normal/events.patterns create mode 100644 app/tests/toggle-layer/normal/keycode_events.snapshot create mode 100644 app/tests/toggle-layer/normal/native_posix.keymap diff --git a/app/tests/toggle-layer/behavior_keymap.dtsi b/app/tests/toggle-layer/behavior_keymap.dtsi new file mode 100644 index 00000000..d2b41a9a --- /dev/null +++ b/app/tests/toggle-layer/behavior_keymap.dtsi @@ -0,0 +1,28 @@ +#include +#include +#include + +/ { + keymap { + compatible = "zmk,keymap"; + label ="Default keymap"; + + default_layer { + bindings = < + &kp B &tog 1 + &kp D &kp G>; + }; + + lower_layer { + bindings = < + &cp M_NEXT &trans + &kp L &kp J>; + }; + + raise_layer { + bindings = < + &kp W &kp U + &kp X &kp M>; + }; + }; +}; diff --git a/app/tests/toggle-layer/early-key-release/events.patterns b/app/tests/toggle-layer/early-key-release/events.patterns new file mode 100644 index 00000000..397fef4f --- /dev/null +++ b/app/tests/toggle-layer/early-key-release/events.patterns @@ -0,0 +1,2 @@ +s/.*hid_listener_keycode/kp/p +s/.*tog_keymap_binding/tog/p \ No newline at end of file diff --git a/app/tests/toggle-layer/early-key-release/keycode_events.snapshot b/app/tests/toggle-layer/early-key-release/keycode_events.snapshot new file mode 100644 index 00000000..3ac017c8 --- /dev/null +++ b/app/tests/toggle-layer/early-key-release/keycode_events.snapshot @@ -0,0 +1,6 @@ +kp_pressed: usage_page 0x07 keycode 0x05 +tog_pressed: position 1 layer 1 +kp_released: usage_page 0x07 keycode 0x05 +tog_released: position 1 layer 1 +kp_pressed: usage_page 0x0c keycode 0xb5 +kp_released: usage_page 0x0c keycode 0xb5 diff --git a/app/tests/toggle-layer/early-key-release/native_posix.keymap b/app/tests/toggle-layer/early-key-release/native_posix.keymap new file mode 100644 index 00000000..6b2b8f20 --- /dev/null +++ b/app/tests/toggle-layer/early-key-release/native_posix.keymap @@ -0,0 +1,9 @@ +#include +#include +#include +#include "../behavior_keymap.dtsi" + +&kscan { + events = ; +}; \ No newline at end of file diff --git a/app/tests/toggle-layer/normal/events.patterns b/app/tests/toggle-layer/normal/events.patterns new file mode 100644 index 00000000..397fef4f --- /dev/null +++ b/app/tests/toggle-layer/normal/events.patterns @@ -0,0 +1,2 @@ +s/.*hid_listener_keycode/kp/p +s/.*tog_keymap_binding/tog/p \ No newline at end of file diff --git a/app/tests/toggle-layer/normal/keycode_events.snapshot b/app/tests/toggle-layer/normal/keycode_events.snapshot new file mode 100644 index 00000000..42174cc5 --- /dev/null +++ b/app/tests/toggle-layer/normal/keycode_events.snapshot @@ -0,0 +1,4 @@ +tog_pressed: position 1 layer 1 +tog_released: position 1 layer 1 +kp_pressed: usage_page 0x0c keycode 0xb5 +kp_released: usage_page 0x0c keycode 0xb5 diff --git a/app/tests/toggle-layer/normal/native_posix.keymap b/app/tests/toggle-layer/normal/native_posix.keymap new file mode 100644 index 00000000..202c105c --- /dev/null +++ b/app/tests/toggle-layer/normal/native_posix.keymap @@ -0,0 +1,8 @@ +#include +#include +#include +#include "../behavior_keymap.dtsi" + +&kscan { + events = ; +}; \ No newline at end of file From e2f77f25c8212856a5b3b3995b8e9199b59c2650 Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Fri, 28 Aug 2020 16:21:31 -0400 Subject: [PATCH 10/17] feat(test): add testing for transparent --- app/tests/transparent/behavior_keymap.dtsi | 22 +++++++++++++++++++ app/tests/transparent/layered/events.patterns | 1 + .../layered/keycode_events.snapshot | 2 ++ .../transparent/layered/native_posix.keymap | 8 +++++++ app/tests/transparent/normal/events.patterns | 1 + .../normal/keycode_events.snapshot | 0 .../transparent/normal/native_posix.keymap | 8 +++++++ 7 files changed, 42 insertions(+) create mode 100644 app/tests/transparent/behavior_keymap.dtsi create mode 100644 app/tests/transparent/layered/events.patterns create mode 100644 app/tests/transparent/layered/keycode_events.snapshot create mode 100644 app/tests/transparent/layered/native_posix.keymap create mode 100644 app/tests/transparent/normal/events.patterns create mode 100644 app/tests/transparent/normal/keycode_events.snapshot create mode 100644 app/tests/transparent/normal/native_posix.keymap diff --git a/app/tests/transparent/behavior_keymap.dtsi b/app/tests/transparent/behavior_keymap.dtsi new file mode 100644 index 00000000..d6c5e27f --- /dev/null +++ b/app/tests/transparent/behavior_keymap.dtsi @@ -0,0 +1,22 @@ +#include +#include +#include + +/ { + keymap { + compatible = "zmk,keymap"; + label ="Default keymap"; + + default_layer { + bindings = < + &trans &mo 1 + &kp A &none>; + }; + + lower_layer { + bindings = < + &trans &trans + &trans &kp A>; + }; + }; +}; diff --git a/app/tests/transparent/layered/events.patterns b/app/tests/transparent/layered/events.patterns new file mode 100644 index 00000000..3c9d3f83 --- /dev/null +++ b/app/tests/transparent/layered/events.patterns @@ -0,0 +1 @@ +s/.*hid_listener_keycode/kp/p \ No newline at end of file diff --git a/app/tests/transparent/layered/keycode_events.snapshot b/app/tests/transparent/layered/keycode_events.snapshot new file mode 100644 index 00000000..d0bd2455 --- /dev/null +++ b/app/tests/transparent/layered/keycode_events.snapshot @@ -0,0 +1,2 @@ +kp_pressed: usage_page 0x07 keycode 0x04 +kp_released: usage_page 0x07 keycode 0x04 diff --git a/app/tests/transparent/layered/native_posix.keymap b/app/tests/transparent/layered/native_posix.keymap new file mode 100644 index 00000000..59ea4811 --- /dev/null +++ b/app/tests/transparent/layered/native_posix.keymap @@ -0,0 +1,8 @@ +#include +#include +#include +#include "../behavior_keymap.dtsi" + +&kscan { + events = ; +}; \ No newline at end of file diff --git a/app/tests/transparent/normal/events.patterns b/app/tests/transparent/normal/events.patterns new file mode 100644 index 00000000..3c9d3f83 --- /dev/null +++ b/app/tests/transparent/normal/events.patterns @@ -0,0 +1 @@ +s/.*hid_listener_keycode/kp/p \ No newline at end of file diff --git a/app/tests/transparent/normal/keycode_events.snapshot b/app/tests/transparent/normal/keycode_events.snapshot new file mode 100644 index 00000000..e69de29b diff --git a/app/tests/transparent/normal/native_posix.keymap b/app/tests/transparent/normal/native_posix.keymap new file mode 100644 index 00000000..94d7539c --- /dev/null +++ b/app/tests/transparent/normal/native_posix.keymap @@ -0,0 +1,8 @@ +#include +#include +#include +#include "../behavior_keymap.dtsi" + +&kscan { + events = ; +}; \ No newline at end of file From 79bff11ddd55204cf0ed4f43985e096a30cbf137 Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Fri, 28 Aug 2020 16:21:31 -0400 Subject: [PATCH 11/17] fancier run test stuff --- app/run-test.sh | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/run-test.sh b/app/run-test.sh index 722cb939..d923e855 100755 --- a/app/run-test.sh +++ b/app/run-test.sh @@ -4,14 +4,25 @@ if [ -z "$1" ]; then echo "Usage: ./run-test.sh " exit 1 elif [ "$1" = "all" ]; then + echo "" > ./build/tests/pass-fail.log find tests -name native_posix.keymap -exec dirname \{\} \; | xargs -l -P 4 ./run-test.sh - exit $? + err=$? + sort -k2 ./build/tests/pass-fail.log + exit $err fi testcase="$1" echo "Running $testcase:" -west build -d build/$testcase -b native_posix -- -DZMK_CONFIG=$testcase > /dev/null -./build/$testcase/zephyr/zmk.exe | sed -e "s/.*> //" | sed -n -f $testcase/events.patterns > build/$testcase/keycode_events.log - -diff -au $testcase/keycode_events.snapshot build/$testcase/keycode_events.log +west build -d build/$testcase -b native_posix -- -DZMK_CONFIG=$testcase > /dev/null 2>&1 +if [ $? -gt 0 ]; then + echo "FAIL: $testcase did not build" >> ./build/tests/pass-fail.log +else + ./build/$testcase/zephyr/zmk.exe | sed -e "s/.*> //" | sed -n -f $testcase/events.patterns > build/$testcase/keycode_events.log + diff -au $testcase/keycode_events.snapshot build/$testcase/keycode_events.log + if [ $? -gt 0 ]; then + echo "FAIL: $testcase" >> ./build/tests/pass-fail.log + else + echo "PASS: $testcase" >> ./build/tests/pass-fail.log + fi +fi \ No newline at end of file From 4564d374776b0ade3c69bdddbf0a654aff38985e Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Fri, 28 Aug 2020 16:21:31 -0400 Subject: [PATCH 12/17] feat(test): create simple docs for creating tests --- app/tests/Creating Tests.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 app/tests/Creating Tests.md diff --git a/app/tests/Creating Tests.md b/app/tests/Creating Tests.md new file mode 100644 index 00000000..5e211c0f --- /dev/null +++ b/app/tests/Creating Tests.md @@ -0,0 +1,23 @@ +# Basics +Any folder under `/app/tests` containing `native_posix.keymap` will be selected when running +`./run-test.sh all`. + +`test_case/events.patterns` contains sed patterns that will select the interesting output from the +application + +`test_case/keycode_events.snapshot` contains the expected output after applying `events.pattern` to +the output + +`test_case/native_posix.keymap` defines the keys and the mock key presses. Most tests include a +common keymap for their test set + +## Creating a New Test Set +1. Copy the test set that most closely resembles the tests you will be creating. +2. Rename the newly created test set to the behavior you're testing e.g, toggle-layer +3. Modify `behavior_keymap.dtsi` to create a keymap using the behavior and related behaviors +4. Modify `test_case/native_posix.keymap` for a simulated use case +5. Modify `test_case/events.patterns` to collect relevant logs to the test + - See: [sed manual](https://www.gnu.org/software/sed/manual/sed.html) and + [tutorial](https://www.digitalocean.com/community/tutorials/the-basics-of-using-the-sed-stream-editor-to-manipulate-text-in-linux) +6. Modify `test_case/keycode_events.snapshot` for to include the expected output +7. Repeat steps 4 to 6 for every test case \ No newline at end of file From aff39e57d041b9b3c895d3968912ef4fd9b6c6ce Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Fri, 28 Aug 2020 16:21:31 -0400 Subject: [PATCH 13/17] fix: add license header to run-test.sh --- app/run-test.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/run-test.sh b/app/run-test.sh index d923e855..6c3e8788 100755 --- a/app/run-test.sh +++ b/app/run-test.sh @@ -1,4 +1,9 @@ #!/bin/sh +# +# Copyright (c) 2020 Peter Johanson; Cody McGinnis +# +# SPDX-License-Identifier: MIT +# if [ -z "$1" ]; then echo "Usage: ./run-test.sh " From b1d9a7b68450438a7ac6bce26bf89dfdf00a4393 Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Fri, 28 Aug 2020 16:21:31 -0400 Subject: [PATCH 14/17] feat(test): record full key log as well --- app/run-test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/run-test.sh b/app/run-test.sh index 6c3e8788..53277ba5 100755 --- a/app/run-test.sh +++ b/app/run-test.sh @@ -23,7 +23,7 @@ west build -d build/$testcase -b native_posix -- -DZMK_CONFIG=$testcase > /dev/n if [ $? -gt 0 ]; then echo "FAIL: $testcase did not build" >> ./build/tests/pass-fail.log else - ./build/$testcase/zephyr/zmk.exe | sed -e "s/.*> //" | sed -n -f $testcase/events.patterns > build/$testcase/keycode_events.log + ./build/$testcase/zephyr/zmk.exe | sed -e "s/.*> //" | tee build/$testcase/keycode_events_full.log | sed -n -f $testcase/events.patterns > build/$testcase/keycode_events.log diff -au $testcase/keycode_events.snapshot build/$testcase/keycode_events.log if [ $? -gt 0 ]; then echo "FAIL: $testcase" >> ./build/tests/pass-fail.log From 26414a69824a37a65c0fb3a6c423f4cb6c1ef068 Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Fri, 28 Aug 2020 16:21:31 -0400 Subject: [PATCH 15/17] fix(docs): move testing docs to website docs --- app/tests/Creating Tests.md => docs/docs/dev-tests.md | 4 ++-- docs/sidebars.js | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) rename app/tests/Creating Tests.md => docs/docs/dev-tests.md (83%) diff --git a/app/tests/Creating Tests.md b/docs/docs/dev-tests.md similarity index 83% rename from app/tests/Creating Tests.md rename to docs/docs/dev-tests.md index 5e211c0f..1709ccd7 100644 --- a/app/tests/Creating Tests.md +++ b/docs/docs/dev-tests.md @@ -1,6 +1,6 @@ # Basics -Any folder under `/app/tests` containing `native_posix.keymap` will be selected when running -`./run-test.sh all`. +Running tests requires native [posix support](./dev-posix-board). Any folder under `/app/tests` +containing `native_posix.keymap` will be selected when running `./run-test.sh all`. `test_case/events.patterns` contains sed patterns that will select the interesting output from the application diff --git a/docs/sidebars.js b/docs/sidebars.js index 51313fc5..d4266670 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -20,6 +20,7 @@ module.exports = { "dev-setup", "dev-boards-shields-keymaps", "dev-posix-board", + "dev-tests", ], "Dev Guides": ["dev-guide-new-shield", "dev-guide-usb-logging"], }, From 205a54baeb75f631795c3de34948e5e9f1af0083 Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Fri, 28 Aug 2020 16:21:31 -0400 Subject: [PATCH 16/17] fix(docs): update the testing docs --- docs/docs/dev-tests.md | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/docs/docs/dev-tests.md b/docs/docs/dev-tests.md index 1709ccd7..68d47251 100644 --- a/docs/docs/dev-tests.md +++ b/docs/docs/dev-tests.md @@ -1,16 +1,12 @@ -# Basics -Running tests requires native [posix support](./dev-posix-board). Any folder under `/app/tests` +--- +id: dev-tests +title: Tests +sidebar_label: Tests +--- + +Running tests requires [native posix support](./dev-posix-board). Any folder under `/app/tests` containing `native_posix.keymap` will be selected when running `./run-test.sh all`. -`test_case/events.patterns` contains sed patterns that will select the interesting output from the -application - -`test_case/keycode_events.snapshot` contains the expected output after applying `events.pattern` to -the output - -`test_case/native_posix.keymap` defines the keys and the mock key presses. Most tests include a -common keymap for their test set - ## Creating a New Test Set 1. Copy the test set that most closely resembles the tests you will be creating. 2. Rename the newly created test set to the behavior you're testing e.g, toggle-layer @@ -20,4 +16,5 @@ common keymap for their test set - See: [sed manual](https://www.gnu.org/software/sed/manual/sed.html) and [tutorial](https://www.digitalocean.com/community/tutorials/the-basics-of-using-the-sed-stream-editor-to-manipulate-text-in-linux) 6. Modify `test_case/keycode_events.snapshot` for to include the expected output -7. Repeat steps 4 to 6 for every test case \ No newline at end of file +7. Rename the `test_case` folder to describe the test. +8. Repeat steps 4 to 7 for every test case \ No newline at end of file From 80bef160fcb3c2c63f11c71832c9afd959a1828c Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Fri, 28 Aug 2020 16:28:49 -0400 Subject: [PATCH 17/17] feat(tests): allow tests to be marked as pending pending tests will not fail the build --- app/run-test.sh | 9 ++++++++- app/tests/momentary-layer/early-key-release/pending | 0 app/tests/toggle-layer/early-key-release/pending | 0 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 app/tests/momentary-layer/early-key-release/pending create mode 100644 app/tests/toggle-layer/early-key-release/pending diff --git a/app/run-test.sh b/app/run-test.sh index 53277ba5..be335c62 100755 --- a/app/run-test.sh +++ b/app/run-test.sh @@ -26,8 +26,15 @@ else ./build/$testcase/zephyr/zmk.exe | sed -e "s/.*> //" | tee build/$testcase/keycode_events_full.log | sed -n -f $testcase/events.patterns > build/$testcase/keycode_events.log diff -au $testcase/keycode_events.snapshot build/$testcase/keycode_events.log if [ $? -gt 0 ]; then - echo "FAIL: $testcase" >> ./build/tests/pass-fail.log + if [ -f $testcase/pending ]; then + echo "PEND: $testcase" >> ./build/tests/pass-fail.log + exit 0 + else + echo "FAIL: $testcase" >> ./build/tests/pass-fail.log + exit 1 + fi else echo "PASS: $testcase" >> ./build/tests/pass-fail.log + exit 0 fi fi \ No newline at end of file diff --git a/app/tests/momentary-layer/early-key-release/pending b/app/tests/momentary-layer/early-key-release/pending new file mode 100644 index 00000000..e69de29b diff --git a/app/tests/toggle-layer/early-key-release/pending b/app/tests/toggle-layer/early-key-release/pending new file mode 100644 index 00000000..e69de29b