diff options
author | Tristan Honscheid <honscheid@google.com> | 2022-09-13 16:55:14 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-09-16 23:39:50 +0000 |
commit | 20afff909ae6f437657295663d9274d7a004c7e5 (patch) | |
tree | 5e1fed14b4be8c2923afe838cc17dcdc9c54fa92 | |
parent | 38233ee7028784b127b8f5c11dfcf5d22fb020c5 (diff) | |
download | chrome-ec-20afff909ae6f437657295663d9274d7a004c7e5.tar.gz |
zephyr: tests: Test Host command EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT
Test the above host command in `common/keyboard_backlight.c`
BRANCH=None
BUG=b:246577858
TEST=./twister
Signed-off-by: Tristan Honscheid <honscheid@google.com>
Change-Id: I4f5c6074bddd4ec78919794cc02a98ed2faa4638
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3893396
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Reviewed-by: Yuval Peress <peress@google.com>
-rw-r--r-- | zephyr/test/drivers/keyboard_scan/CMakeLists.txt | 1 | ||||
-rw-r--r-- | zephyr/test/drivers/keyboard_scan/src/keyboard_backlight.c | 60 |
2 files changed, 61 insertions, 0 deletions
diff --git a/zephyr/test/drivers/keyboard_scan/CMakeLists.txt b/zephyr/test/drivers/keyboard_scan/CMakeLists.txt index 0def2a5ff9..07040187f2 100644 --- a/zephyr/test/drivers/keyboard_scan/CMakeLists.txt +++ b/zephyr/test/drivers/keyboard_scan/CMakeLists.txt @@ -3,6 +3,7 @@ # found in the LICENSE file. target_sources(app PRIVATE + src/keyboard_backlight.c src/keyboard_scan.c src/keyboard_test_utils.c src/mkbp_event.c diff --git a/zephyr/test/drivers/keyboard_scan/src/keyboard_backlight.c b/zephyr/test/drivers/keyboard_scan/src/keyboard_backlight.c new file mode 100644 index 0000000000..00cf99b7ac --- /dev/null +++ b/zephyr/test/drivers/keyboard_scan/src/keyboard_backlight.c @@ -0,0 +1,60 @@ +/* Copyright 2022 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <stdint.h> +#include <zephyr/ztest.h> +#include <zephyr/kernel.h> +#include <zephyr/ztest_assert.h> + +#include "host_command.h" +#include "keyboard_backlight.h" +#include "test/drivers/test_state.h" + +/** + * @brief Send host command to set the backlight percentage + * + * @param percent Backlight intensity, from 0 to 100 (inclusive). + * @return uint16_t Host command return code + */ +static uint16_t set_backlight_percent_helper(uint8_t percent) +{ + struct ec_params_pwm_set_keyboard_backlight params = { + .percent = percent + }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND_PARAMS( + EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT, 0, params); + + return host_command_process(&args); +} + +ZTEST(keyboard_backlight, host_command_set_backlight__normal) +{ + /* Set the backlight intensity level to this and verify */ + uint8_t expected_percentage = 50; + + zassert_ok(set_backlight_percent_helper(expected_percentage), NULL); + zassert_equal(expected_percentage, kblight_get(), NULL); +} + +ZTEST(keyboard_backlight, host_command_set_backlight__out_of_range) +{ + /* Too high */ + uint8_t expected_percentage = 101; + + zassert_equal(EC_RES_ERROR, + set_backlight_percent_helper(expected_percentage), NULL); +} + +static void reset(void *data) +{ + ARG_UNUSED(data); + + /* Reset the backlight to off and 0% brightness */ + kblight_set(0); + kblight_enable(0); +} + +ZTEST_SUITE(keyboard_backlight, drivers_predicate_post_main, NULL, reset, reset, + NULL); |