diff options
author | YH Lin <yueherngl@google.com> | 2022-11-30 21:44:08 +0000 |
---|---|---|
committer | YH Lin <yueherngl@google.com> | 2022-11-30 21:44:08 +0000 |
commit | af25602b15b22b9ef5821dcba9934311f2157c48 (patch) | |
tree | d0c89ae8814c2ba35c238c6c0644ec6b1602c63a /zephyr/test/drivers/default/src/temp_sensor.c | |
parent | 54462f034b635260dd09173b3d082e47fc960ef3 (diff) | |
parent | aa40b859b3a73e5a205bc561c1a29eff38485461 (diff) | |
download | chrome-ec-af25602b15b22b9ef5821dcba9934311f2157c48.tar.gz |
Merge remote-tracking branch cros/main into factory-brya-14517.B-main
Generated by: util/update_release_branch.py --baseboard brya --relevant_paths_file
baseboard/brya/relevant-paths.txt factory-brya-14517.B-main
Relevant changes:
git log --oneline 54462f034b..aa40b859b3 -- baseboard/brya board/agah
board/anahera board/banshee board/brya board/crota board/felwinter
board/gimble board/kano board/mithrax board/osiris board/primus
board/redrix board/taeko board/taniks board/vell board/volmar
driver/bc12/pi3usb9201_public.* driver/charger/bq25710.*
driver/ppc/nx20p348x.* driver/ppc/syv682x_public.*
driver/retimer/bb_retimer_public.* driver/tcpm/nct38xx.*
driver/tcpm/ps8xxx_public.* driver/tcpm/tcpci.* include/power/alderlake*
include/intel_x86.h power/alderlake* power/intel_x86.c
util/getversion.sh
e6da633c38 driver: Sort header files
234a87ae2d tcpci: Add FRS enable to driver structure
a56be59ccd tcpm_header: add test for tcpm_dump_registers
57b3256963 Rename CONFIG_CHARGER_INPUT_CURRENT to _CHARGER_DEFAULT_CURRENT_LIMIT
e420c8ff9a marasov: Modify TypeC and TypeA configuration.
43b53e0045 Add default implementation of board_set_charge_limit
b75dc90677 Add CONFIG_CHARGER_MIN_INPUT_CURRENT_LIMIT
f1b563c350 baseboard: Sort header files
7d01b1e58d driver/retimer/ps8818.h: Add I2C ADDR FLAGS 0x30, 0x58, 0x70
ec31407993 Add CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT
8f89f69a5b crota: disable lid angle sensor for clamshell
BRANCH=None
BUG=b:259002141 b:255184961 b:247100970 b:259354679 b:260630630
BUG=b:163093572 b:254328661
TEST=`emerge-brya chromeos-ec`
Force-Relevant-Builds: all
Change-Id: Ia85a701fbf6b8e67ec214b9e25e0e55e980a6f47
Signed-off-by: YH Lin <yueherngl@google.com>
Diffstat (limited to 'zephyr/test/drivers/default/src/temp_sensor.c')
-rw-r--r-- | zephyr/test/drivers/default/src/temp_sensor.c | 111 |
1 files changed, 102 insertions, 9 deletions
diff --git a/zephyr/test/drivers/default/src/temp_sensor.c b/zephyr/test/drivers/default/src/temp_sensor.c index 61441a0229..83d9aa3812 100644 --- a/zephyr/test/drivers/default/src/temp_sensor.c +++ b/zephyr/test/drivers/default/src/temp_sensor.c @@ -3,19 +3,24 @@ * found in the LICENSE file. */ -#include <zephyr/kernel.h> -#include <zephyr/ztest.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 <math.h> - #include "common.h" +#include "driver/temp_sensor/pct2075.h" +#include "emul/emul_pct2075.h" +#include "math_util.h" #include "temp_sensor.h" #include "temp_sensor/temp_sensor.h" #include "test/drivers/test_state.h" +#include "timer.h" + +#include <math.h> + +#include <zephyr/drivers/adc.h> +#include <zephyr/drivers/adc/adc_emul.h> +#include <zephyr/drivers/emul.h> +#include <zephyr/drivers/gpio.h> +#include <zephyr/drivers/gpio/gpio_emul.h> +#include <zephyr/kernel.h> +#include <zephyr/ztest.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) @@ -110,6 +115,11 @@ ZTEST_USER(temp_sensor, test_temp_sensor_pg_pin) named_temp_pp3300_regulator)), &temp), NULL); + zassert_equal( + EC_ERROR_NOT_POWERED, + temp_sensor_read(TEMP_SENSOR_ID(DT_NODELABEL(named_pct2075)), + &temp), + NULL); /* power ADC */ zassert_ok(gpio_emul_input_set(gpio_dev, GPIO_EC_PG_PIN_TEMP_PORT, 1), @@ -179,12 +189,92 @@ ZTEST_USER(temp_sensor, test_temp_sensor_read) } } +/** Test if temp_sensor_read() returns temperature on success for PCT2075 */ +ZTEST_USER(temp_sensor, test_temp_sensor_pct2075) +{ + int temp; + const struct emul *dev = EMUL_DT_GET(DT_NODELABEL(pct2075_emul)); + int mk[] = { + MILLI_CELSIUS_TO_MILLI_KELVIN(127000), + MILLI_CELSIUS_TO_MILLI_KELVIN(126850), + MILLI_CELSIUS_TO_MILLI_KELVIN(125), + MILLI_CELSIUS_TO_MILLI_KELVIN(0), + MILLI_CELSIUS_TO_MILLI_KELVIN(-125), + MILLI_CELSIUS_TO_MILLI_KELVIN(-54875), + MILLI_CELSIUS_TO_MILLI_KELVIN(-55000), + }; + + for (int i = 0; i < ARRAY_SIZE(mk); i++) { + pct2075_emul_set_temp(dev, mk[i]); + /* Highly dependent on current implementation. The sensor + * update temperature in the 1 second periodic hook, so + * we need to wait for it. + */ + msleep(1100); + zassert_equal(EC_SUCCESS, + temp_sensor_read(TEMP_SENSOR_ID(DT_NODELABEL( + named_pct2075)), + &temp)); + zassert_equal(MILLI_KELVIN_TO_KELVIN(mk[i]), temp); + } +} + +/** Test if temperature is not updated on I2C read fail. + * The test highly dependent on current implementation - temp_sensor_read + * doesn't return an error on the i2c read fail, which can/should be changed + * in the future. + */ +ZTEST_USER(temp_sensor, test_temp_sensor_pct2075_fail) +{ + const struct emul *dev = EMUL_DT_GET(DT_NODELABEL(pct2075_emul)); + struct pct2075_data *data = (struct pct2075_data *)dev->data; + int mk1 = 373000, mk2 = 273000; + int temp; + + /* Set initial temperature */ + pct2075_emul_set_temp(dev, mk1); + msleep(1100); + + zassert_equal(EC_SUCCESS, temp_sensor_read(TEMP_SENSOR_ID(DT_NODELABEL( + named_pct2075)), + &temp)); + /* Make sure the temperature is read correctly */ + zassert_equal(MILLI_KELVIN_TO_KELVIN(mk1), temp); + + /* Set I2C fail on the temperature register */ + i2c_common_emul_set_read_fail_reg(&data->common, PCT2075_REG_TEMP); + pct2075_emul_set_temp(dev, mk2); + /* Wait for potential update */ + msleep(1100); + + /* Make sure the temperature is not changed */ + zassert_equal(EC_SUCCESS, temp_sensor_read(TEMP_SENSOR_ID(DT_NODELABEL( + named_pct2075)), + &temp)); + zassert_equal(MILLI_KELVIN_TO_KELVIN(mk1), temp); + + /* Restore I2C */ + i2c_common_emul_set_read_fail_reg(&data->common, + I2C_COMMON_EMUL_NO_FAIL_REG); + /* Wait for update */ + msleep(1100); + /* Make sure the temperature is updated */ + zassert_equal(EC_SUCCESS, temp_sensor_read(TEMP_SENSOR_ID(DT_NODELABEL( + named_pct2075)), + &temp)); + zassert_equal(MILLI_KELVIN_TO_KELVIN(mk2), temp); +} + static void *temp_sensor_setup(void) { const struct device *dev = DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_PG_EC_DSW_PWROK_PATH, gpios)); const struct device *dev_pin = DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_EC_PG_PIN_TEMP_PATH, gpios)); + const struct emul *pct2075_dev = + EMUL_DT_GET(DT_NODELABEL(pct2075_emul)); + struct pct2075_data *pct2075_data = + (struct pct2075_data *)pct2075_dev->data; zassert_not_null(dev, NULL); /* Before tests make sure that power pins are set. */ @@ -193,6 +283,9 @@ static void *temp_sensor_setup(void) zassert_ok(gpio_emul_input_set(dev_pin, GPIO_EC_PG_PIN_TEMP_PORT, 1), NULL); + i2c_common_emul_set_read_fail_reg(&pct2075_data->common, + I2C_COMMON_EMUL_NO_FAIL_REG); + return NULL; } |