summaryrefslogtreecommitdiff
path: root/zephyr/test/drivers/default/src/thermistor.c
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/test/drivers/default/src/thermistor.c')
-rw-r--r--zephyr/test/drivers/default/src/thermistor.c47
1 files changed, 39 insertions, 8 deletions
diff --git a/zephyr/test/drivers/default/src/thermistor.c b/zephyr/test/drivers/default/src/thermistor.c
index 417b482d99..edbe7acad5 100644
--- a/zephyr/test/drivers/default/src/thermistor.c
+++ b/zephyr/test/drivers/default/src/thermistor.c
@@ -3,18 +3,19 @@
* found in the LICENSE file.
*/
-#include <zephyr/kernel.h>
-#include <zephyr/ztest.h>
+#include "../driver/temp_sensor/thermistor.h"
+#include "common.h"
+#include "temp_sensor/temp_sensor.h"
+#include "test/drivers/test_state.h"
+
#include <zephyr/drivers/adc.h>
#include <zephyr/drivers/adc/adc_emul.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/gpio/gpio_emul.h>
-#include <temp_sensor.h>
+#include <zephyr/kernel.h>
+#include <zephyr/ztest.h>
-#include "common.h"
-#include "../driver/temp_sensor/thermistor.h"
-#include "temp_sensor/temp_sensor.h"
-#include "test/drivers/test_state.h"
+#include <temp_sensor.h>
#define GPIO_PG_EC_DSW_PWROK_PATH DT_PATH(named_gpios, pg_ec_dsw_pwrok)
#define GPIO_PG_EC_DSW_PWROK_PORT DT_GPIO_PIN(GPIO_PG_EC_DSW_PWROK_PATH, gpios)
@@ -58,6 +59,10 @@ ZTEST_USER(thermistor, test_thermistor_power_pin)
sensor_idx++) {
const struct temp_sensor_t *sensor = &temp_sensors[sensor_idx];
+ /* Skip for sensors that are not thermistors */
+ if (sensor->zephyr_info->thermistor == NULL)
+ continue;
+
zassert_ok(adc_emul_const_value_set(adc_dev, sensor->idx,
A_VALID_VOLTAGE),
"adc_emul_value_func_set() failed on %s",
@@ -72,6 +77,10 @@ ZTEST_USER(thermistor, test_thermistor_power_pin)
sensor_idx++) {
const struct temp_sensor_t *sensor = &temp_sensors[sensor_idx];
+ /* Skip for sensors that are not thermistors */
+ if (sensor->zephyr_info->thermistor == NULL)
+ continue;
+
zassert_equal(EC_ERROR_NOT_POWERED,
sensor->zephyr_info->read(sensor, &temp),
"%s failed", sensor->name);
@@ -85,6 +94,10 @@ ZTEST_USER(thermistor, test_thermistor_power_pin)
sensor_idx++) {
const struct temp_sensor_t *sensor = &temp_sensors[sensor_idx];
+ /* Skip for sensors that are not thermistors */
+ if (sensor->zephyr_info->thermistor == NULL)
+ continue;
+
zassert_equal(EC_SUCCESS,
sensor->zephyr_info->read(sensor, &temp),
"%s failed", sensor->name);
@@ -113,6 +126,10 @@ ZTEST_USER(thermistor, test_thermistor_adc_read_error)
sensor_idx++) {
const struct temp_sensor_t *sensor = &temp_sensors[sensor_idx];
+ /* Skip for sensors that are not thermistors */
+ if (sensor->zephyr_info->thermistor == NULL)
+ continue;
+
zassert_ok(adc_emul_value_func_set(adc_dev, sensor->idx,
adc_error_func, NULL),
"adc_emul_value_func_set() failed on %s",
@@ -123,6 +140,10 @@ ZTEST_USER(thermistor, test_thermistor_adc_read_error)
sensor_idx++) {
const struct temp_sensor_t *sensor = &temp_sensors[sensor_idx];
+ /* Skip for sensors that are not thermistors */
+ if (sensor->zephyr_info->thermistor == NULL)
+ continue;
+
zassert_equal(EC_ERROR_UNKNOWN,
sensor->zephyr_info->read(sensor, &temp),
"%s failed", sensor->name);
@@ -265,10 +286,16 @@ ZTEST_USER(thermistor, test_thermistors_adc_temperature_conversion)
const static int reference_res_arr[] = { DT_FOREACH_STATUS_OKAY(
THERMISTOR_COMPAT, GET_THERMISTOR_REF_RES) };
- for (sensor_idx = 0; sensor_idx < NAMED_TEMP_SENSORS_SIZE; sensor_idx++)
+ for (sensor_idx = 0; sensor_idx < NAMED_TEMP_SENSORS_SIZE;
+ sensor_idx++) {
+ /* Skip for sensors that are not thermistors */
+ if (temp_sensors[sensor_idx].zephyr_info->thermistor == NULL)
+ continue;
+
do_thermistor_test(&temp_sensors[sensor_idx],
reference_mv_arr[sensor_idx],
reference_res_arr[sensor_idx]);
+ }
}
ZTEST_USER(thermistor, test_device_nodes_enabled)
@@ -312,6 +339,10 @@ static void thermistor_cleanup(void *state)
for (sensor_idx = 0; sensor_idx < NAMED_TEMP_SENSORS_SIZE;
sensor_idx++) {
+ /* Skip for sensors that are not thermistors */
+ if (temp_sensors[sensor_idx].zephyr_info->thermistor == NULL)
+ continue;
+
/* Setup ADC to return 27*C (300K) which is reasonable value */
adc_emul_const_value_set(
adc_dev, temp_sensors[sensor_idx].idx,