From f02fa01e9a9af1a1637a387f3e8044a791b47ced Mon Sep 17 00:00:00 2001 From: Cody McGinnis Date: Fri, 28 Aug 2020 16:21:31 -0400 Subject: [PATCH] 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; - }; - - 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>; - }; + zmk,kscan = &kscan; }; - 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