Skip to content

Commit 1588826

Browse files
committed
tests: drivers: sensors: ALS
Added a new sensor test for ALS. Signed-off-by: Rick Talbott <[email protected]> tests: drivers: build_all: updated to include TSL2540 build updated to include TSL2540 Signed-off-by: Rick Talbott <[email protected]>
1 parent db74e3e commit 1588826

10 files changed

+118
-0
lines changed

tests/drivers/build_all/sensor/i2c.dtsi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,3 +745,9 @@ test_i2c_tcs3400: tcs3400@72 {
745745
reg = <0x72>;
746746
int-gpios = <&test_gpio 0 0>;
747747
};
748+
749+
test_i2c_tsl2540: tsl2540@73 {
750+
compatible = "ams,tsl2540";
751+
reg = <0x73>;
752+
int-gpios = <&test_gpio 0 0>;
753+
};

tests/drivers/build_all/sensor/sensors_trigger_global.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ CONFIG_LIS2DW12_TRIGGER_GLOBAL_THREAD=y
3333
CONFIG_LIS2MDL_TRIGGER_GLOBAL_THREAD=y
3434
CONFIG_LIS3MDL_TRIGGER_GLOBAL_THREAD=y
3535
CONFIG_LPS22HH_TRIGGER_GLOBAL_THREAD=y
36+
CONFIG_TSL2540_TRIGGER_GLOBAL_THREAD=y
3637
CONFIG_LSM6DSL_TRIGGER_GLOBAL_THREAD=y
3738
CONFIG_LSM6DSO_TRIGGER_GLOBAL_THREAD=y
3839
CONFIG_LSM6DSO16IS_TRIGGER_GLOBAL_THREAD=y

tests/drivers/build_all/sensor/sensors_trigger_none.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ CONFIG_LIS2DW12_TRIGGER_NONE=y
3333
CONFIG_LIS2MDL_TRIGGER_NONE=y
3434
CONFIG_LIS3MDL_TRIGGER_NONE=y
3535
CONFIG_LPS22HH_TRIGGER_NONE=y
36+
CONFIG_TSL2540_TRIGGER_NONE=y
3637
CONFIG_LSM6DSL_TRIGGER_NONE=y
3738
CONFIG_LSM6DSO_TRIGGER_NONE=y
3839
CONFIG_LSM6DSO16IS_TRIGGER_NONE=y

tests/drivers/build_all/sensor/sensors_trigger_own.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ CONFIG_LIS2DW12_TRIGGER_OWN_THREAD=y
3131
CONFIG_LIS2MDL_TRIGGER_OWN_THREAD=y
3232
CONFIG_LIS3MDL_TRIGGER_OWN_THREAD=y
3333
CONFIG_LPS22HH_TRIGGER_OWN_THREAD=y
34+
CONFIG_TSL2540_TRIGGER_OWN_THREAD=y
3435
CONFIG_LSM6DSL_TRIGGER_OWN_THREAD=y
3536
CONFIG_LSM6DSO_TRIGGER_OWN_THREAD=y
3637
CONFIG_LSM6DSO16IS_TRIGGER_OWN_THREAD=y
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.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(device)
6+
7+
FILE(GLOB app_sources src/*.c)
8+
target_sources(app PRIVATE ${app_sources})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (c) 2023 T-Mobile
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_I2C=y
5+
CONFIG_SENSOR=y
6+
CONFIG_TSL2540=y
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* Copyright (c) 2023 T-Mobile
2+
* SPDX-License-Identifier: Apache-2.0
3+
*/
4+
5+
/ {
6+
aliases {
7+
als-0 = &tsl2540_i2c;
8+
};
9+
};
10+
11+
&i2c0 {
12+
status = "okay";
13+
tsl2540_i2c: tsl2540@39 {
14+
status = "okay";
15+
compatible = "ams,tsl2540";
16+
reg = <0x39 0x4>;
17+
};
18+
};

tests/drivers/sensor/als/prj.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_ZTEST=y
2+
CONFIG_ZTEST_NEW_API=y

tests/drivers/sensor/als/src/main.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2032 T-Mobile
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @defgroup driver_sensor_subsys_tests sensor_subsys
9+
* @ingroup all_tests
10+
* @{
11+
* @}
12+
*/
13+
14+
#include <zephyr/ztest.h>
15+
#include <zephyr/drivers/sensor.h>
16+
17+
struct sensor_als_fixture {
18+
const struct device *als_i2c;
19+
};
20+
21+
static enum sensor_channel channel[] = {
22+
SENSOR_CHAN_LIGHT,
23+
SENSOR_CHAN_IR,
24+
};
25+
26+
static void test_sensor_als_basic(const struct device *dev)
27+
{
28+
zassert_equal(sensor_sample_fetch(dev), 0, "fail to fetch sample");
29+
30+
for (int i = 0; i < ARRAY_SIZE(channel); i++) {
31+
struct sensor_value val;
32+
33+
zassert_ok(sensor_channel_get(dev, channel[i], &val),
34+
"fail to get channel");
35+
}
36+
}
37+
38+
/* Run all of our tests on an als device with the given label */
39+
static void run_tests_on_als(const struct device *als)
40+
{
41+
zassert_true(device_is_ready(als), "als device is not ready");
42+
43+
PRINT("Running tests on '%s'\n", als->name);
44+
k_object_access_grant(als, k_current_get());
45+
}
46+
47+
48+
ZTEST_USER_F(sensor_als, test_sensor_als_basic_i2c)
49+
{
50+
if (fixture->als_i2c == NULL) {
51+
ztest_test_skip();
52+
}
53+
54+
run_tests_on_als(fixture->als_i2c);
55+
test_sensor_als_basic(fixture->als_i2c);
56+
}
57+
58+
static void *sensor_als_setup(void)
59+
{
60+
static struct sensor_als_fixture fixture = {
61+
.als_i2c = DEVICE_DT_GET_OR_NULL(DT_ALIAS(als_0))
62+
};
63+
64+
return &fixture;
65+
}
66+
67+
ZTEST_SUITE(sensor_als, NULL, sensor_als_setup, NULL, NULL, NULL);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
tests:
2+
drivers.sensor.als:
3+
tags:
4+
- drivers
5+
- sensor
6+
- subsys
7+
integration_platforms:
8+
- tmo_dev_edge

0 commit comments

Comments
 (0)