Skip to content

Commit 88dfb88

Browse files
franciscomunozandrewboie
authored andcommitted
tests: drivers: kscan: Add simple API tests
Introduce API tests for kscan driver Signed-off-by: Francisco Munoz <[email protected]>
1 parent de1bb01 commit 88dfb88

File tree

6 files changed

+146
-0
lines changed

6 files changed

+146
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.13.1)
4+
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
5+
project(kscan_api)
6+
7+
FILE(GLOB app_sources src/*.c)
8+
target_sources(app PRIVATE ${app_sources})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_KSCAN=y
2+
CONFIG_ZTEST=y
3+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CONFIG_KSCAN=y
2+
CONFIG_USERSPACE=y
3+
CONFIG_ZTEST=y
4+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2019 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
8+
#include <ztest.h>
9+
10+
void test_init_callback(void);
11+
void test_control_callback(void);
12+
13+
void test_main(void)
14+
{
15+
ztest_test_suite(kscan_basic_test,
16+
ztest_unit_test(test_init_callback),
17+
ztest_unit_test(test_control_callback));
18+
ztest_run_test_suite(kscan_basic_test);
19+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright (c) 2019 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <device.h>
8+
#include <stdlib.h>
9+
#include <drivers/kscan.h>
10+
#include <zephyr.h>
11+
#include <ztest.h>
12+
13+
#if defined(DT_KSCAN_0_NAME)
14+
#define KSCAN_DEV_NAME DT_KSCAN_0_NAME
15+
#endif
16+
17+
static void kb_callback(struct device *dev, u8_t row, u8_t col, bool pressed)
18+
{
19+
ARG_UNUSED(dev);
20+
ARG_UNUSED(row);
21+
ARG_UNUSED(col);
22+
ARG_UNUSED(pressed);
23+
}
24+
25+
static int test_kb_callback(void)
26+
{
27+
struct device *kscan_dev = device_get_binding(KSCAN_DEV_NAME);
28+
29+
if (!kscan_dev) {
30+
TC_PRINT("Cannot get KBSCAN device\n");
31+
return TC_FAIL;
32+
}
33+
34+
if (kscan_config(kscan_dev, kb_callback) != 0) {
35+
TC_PRINT("Unexpected error code received\n");
36+
return TC_FAIL;
37+
}
38+
39+
return TC_PASS;
40+
}
41+
42+
static int test_null_callback(void)
43+
{
44+
struct device *kscan_dev = device_get_binding(KSCAN_DEV_NAME);
45+
46+
if (!kscan_dev) {
47+
TC_PRINT("Cannot get KBSCAN device\n");
48+
return TC_FAIL;
49+
}
50+
51+
if (kscan_config(kscan_dev, NULL) != -EINVAL) {
52+
TC_PRINT("Unexpected error code received\n");
53+
return TC_FAIL;
54+
}
55+
56+
return TC_PASS;
57+
}
58+
59+
static int test_disable_enable_callback(void)
60+
{
61+
struct device *kscan_dev = device_get_binding(KSCAN_DEV_NAME);
62+
63+
if (!kscan_dev) {
64+
TC_PRINT("Cannot get KBSCAN device\n");
65+
return TC_FAIL;
66+
}
67+
68+
if (kscan_config(kscan_dev, kb_callback) != 0) {
69+
TC_PRINT("Unexpected error code received\n");
70+
return TC_FAIL;
71+
}
72+
73+
if (kscan_disable_callback(kscan_dev) != 0) {
74+
TC_PRINT("Error while disabling callback\n");
75+
return TC_FAIL;
76+
}
77+
78+
if (kscan_enable_callback(kscan_dev) != 0) {
79+
TC_PRINT("Error while enabling callback\n");
80+
return TC_FAIL;
81+
}
82+
83+
return TC_PASS;
84+
}
85+
86+
void test_init_callback(void)
87+
{
88+
/* Configure kscan matrix with an appropriate callback */
89+
zassert_true(test_kb_callback() == TC_PASS, NULL);
90+
k_sleep(K_MSEC(1000));
91+
92+
/* Configure kscan with a null callback */
93+
zassert_true(test_null_callback() == TC_PASS, NULL);
94+
}
95+
96+
void test_control_callback(void)
97+
{
98+
/* Disable/enable notifications to user */
99+
zassert_true(test_disable_enable_callback() == TC_PASS, NULL);
100+
k_sleep(K_MSEC(1000));
101+
}
102+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
tests:
2+
peripheral.kscan:
3+
tags: drivers kscan userspace
4+
depends_on: kscan
5+
platform_exclude: mec15xxevb_assy6853
6+
peripheral.kscan.mec15xxevb_assy6853:
7+
depends_on: kscan
8+
tags: drivers kscan
9+
extra_args: CONF_FILE="mec15xxevb_assy6853.conf"
10+
platform_whitelist: mec15xxevb_assy6853

0 commit comments

Comments
 (0)