Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: drivers: sensors: ALS #209

Open
wants to merge 4 commits into
base: tmo-main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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