Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/drivers/build_all/sensor/i2c.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -745,3 +745,9 @@ test_i2c_tcs3400: tcs3400@72 {
reg = <0x72>;
int-gpios = <&test_gpio 0 0>;
};

test_i2c_tsl2540: tsl2540@73 {
compatible = "ams,tsl2540";
reg = <0x73>;
int-gpios = <&test_gpio 0 0>;
};
1 change: 1 addition & 0 deletions tests/drivers/build_all/sensor/sensors_trigger_global.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ CONFIG_LIS2DW12_TRIGGER_GLOBAL_THREAD=y
CONFIG_LIS2MDL_TRIGGER_GLOBAL_THREAD=y
CONFIG_LIS3MDL_TRIGGER_GLOBAL_THREAD=y
CONFIG_LPS22HH_TRIGGER_GLOBAL_THREAD=y
CONFIG_TSL2540_TRIGGER_GLOBAL_THREAD=y
CONFIG_LSM6DSL_TRIGGER_GLOBAL_THREAD=y
CONFIG_LSM6DSO_TRIGGER_GLOBAL_THREAD=y
CONFIG_LSM6DSO16IS_TRIGGER_GLOBAL_THREAD=y
Expand Down
1 change: 1 addition & 0 deletions tests/drivers/build_all/sensor/sensors_trigger_none.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ CONFIG_LIS2DW12_TRIGGER_NONE=y
CONFIG_LIS2MDL_TRIGGER_NONE=y
CONFIG_LIS3MDL_TRIGGER_NONE=y
CONFIG_LPS22HH_TRIGGER_NONE=y
CONFIG_TSL2540_TRIGGER_NONE=y
CONFIG_LSM6DSL_TRIGGER_NONE=y
CONFIG_LSM6DSO_TRIGGER_NONE=y
CONFIG_LSM6DSO16IS_TRIGGER_NONE=y
Expand Down
1 change: 1 addition & 0 deletions tests/drivers/build_all/sensor/sensors_trigger_own.conf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ CONFIG_LIS2DW12_TRIGGER_OWN_THREAD=y
CONFIG_LIS2MDL_TRIGGER_OWN_THREAD=y
CONFIG_LIS3MDL_TRIGGER_OWN_THREAD=y
CONFIG_LPS22HH_TRIGGER_OWN_THREAD=y
CONFIG_TSL2540_TRIGGER_OWN_THREAD=y
CONFIG_LSM6DSL_TRIGGER_OWN_THREAD=y
CONFIG_LSM6DSO_TRIGGER_OWN_THREAD=y
CONFIG_LSM6DSO16IS_TRIGGER_OWN_THREAD=y
Expand Down
8 changes: 8 additions & 0 deletions tests/drivers/sensor/als/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(device)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
6 changes: 6 additions & 0 deletions tests/drivers/sensor/als/boards/tmo_dev_edge.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) 2023 T-Mobile
# SPDX-License-Identifier: Apache-2.0

CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_TSL2540=y
18 changes: 18 additions & 0 deletions tests/drivers/sensor/als/boards/tmo_dev_edge.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* Copyright (c) 2023 T-Mobile
* SPDX-License-Identifier: Apache-2.0
*/

/ {
aliases {
als-0 = &tsl2540_i2c;
};
};

&i2c0 {
status = "okay";
tsl2540_i2c: tsl2540@39 {
status = "okay";
compatible = "ams,tsl2540";
reg = <0x39 0x4>;
};
};
2 changes: 2 additions & 0 deletions tests/drivers/sensor/als/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_ZTEST=y
CONFIG_ZTEST_NEW_API=y
67 changes: 67 additions & 0 deletions tests/drivers/sensor/als/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2032 T-Mobile
*
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @defgroup driver_sensor_subsys_tests sensor_subsys
* @ingroup all_tests
* @{
* @}
*/

#include <zephyr/ztest.h>
#include <zephyr/drivers/sensor.h>

struct sensor_als_fixture {
const struct device *als_i2c;
};

static enum sensor_channel channel[] = {
SENSOR_CHAN_LIGHT,
SENSOR_CHAN_IR,
};

static void test_sensor_als_basic(const struct device *dev)
{
zassert_equal(sensor_sample_fetch(dev), 0, "fail to fetch sample");

for (int i = 0; i < ARRAY_SIZE(channel); i++) {
struct sensor_value val;

zassert_ok(sensor_channel_get(dev, channel[i], &val),
"fail to get channel");
}
}

/* Run all of our tests on an als device with the given label */
static void run_tests_on_als(const struct device *als)
{
zassert_true(device_is_ready(als), "als device is not ready");

PRINT("Running tests on '%s'\n", als->name);
k_object_access_grant(als, k_current_get());
}


ZTEST_USER_F(sensor_als, test_sensor_als_basic_i2c)
{
if (fixture->als_i2c == NULL) {
ztest_test_skip();
}

run_tests_on_als(fixture->als_i2c);
test_sensor_als_basic(fixture->als_i2c);
}

static void *sensor_als_setup(void)
{
static struct sensor_als_fixture fixture = {
.als_i2c = DEVICE_DT_GET_OR_NULL(DT_ALIAS(als_0))
};

return &fixture;
}

ZTEST_SUITE(sensor_als, NULL, sensor_als_setup, NULL, NULL, NULL);
8 changes: 8 additions & 0 deletions tests/drivers/sensor/als/testcase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tests:
drivers.sensor.als:
tags:
- drivers
- sensor
- subsys
integration_platforms:
- tmo_dev_edge