diff options
author | Rob Barnes <robbarnes@google.com> | 2021-08-06 13:18:02 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-08-21 18:48:30 +0000 |
commit | dd46fdb485a9cdb82ae733e4cec2320931e78dbc (patch) | |
tree | 9b6e38ce3058b0575dc8d9eb80ad1b416d8c2cda /test | |
parent | 1418bf3629b9fb767fca0a72455659bf46f06498 (diff) | |
download | chrome-ec-dd46fdb485a9cdb82ae733e4cec2320931e78dbc.tar.gz |
common: Add Milli Kelvin conversion macros
Add macros to convert to and from milli kelvin and various temperature
units. Utilize round_divide for more accurate conversions.
BUG=b:176994331
TEST=Unit test
BRANCH=None
Change-Id: Ie6750b9d2d2b8093fdf9c14f904382e91d8d95bb
Signed-off-by: Rob Barnes <robbarnes@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3078051
Reviewed-by: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/math_util.c | 46 | ||||
-rw-r--r-- | test/sbs_charging_v2.c | 1 |
2 files changed, 47 insertions, 0 deletions
diff --git a/test/math_util.c b/test/math_util.c index b45de1a29d..6482888e55 100644 --- a/test/math_util.c +++ b/test/math_util.c @@ -78,12 +78,58 @@ static int test_rotate(void) return EC_SUCCESS; } +test_static int test_round_divide(void) +{ + /* Check function version */ + TEST_EQ(round_divide(10, 1), 10, "%d"); + TEST_EQ(round_divide(10, 2), 5, "%d"); + TEST_EQ(round_divide(10, 3), 3, "%d"); + TEST_EQ(round_divide(10, 4), 3, "%d"); + TEST_EQ(round_divide(10, 5), 2, "%d"); + TEST_EQ(round_divide(10, 6), 2, "%d"); + TEST_EQ(round_divide(10, 7), 1, "%d"); + TEST_EQ(round_divide(10, 9), 1, "%d"); + TEST_EQ(round_divide(10, 10), 1, "%d"); + TEST_EQ(round_divide(10, 11), 1, "%d"); + TEST_EQ(round_divide(10, 20), 1, "%d"); + TEST_EQ(round_divide(10, 21), 0, "%d"); + + /* Check negative conditions */ + TEST_EQ(round_divide(-10, 6), -2, "%d"); + TEST_EQ(round_divide(10, -6), -2, "%d"); + TEST_EQ(round_divide(-10, -6), 2, "%d"); + + return EC_SUCCESS; +} + +test_static int test_temp_conversion(void) +{ + TEST_EQ(C_TO_K(100), 373, "%d"); + TEST_EQ(K_TO_C(100), -173, "%d"); + + TEST_EQ((int)CELSIUS_TO_DECI_KELVIN(100), 3732, "%d"); + TEST_EQ(DECI_KELVIN_TO_CELSIUS(100), -263, "%d"); + + TEST_EQ(MILLI_KELVIN_TO_MILLI_CELSIUS(100), -273050, "%d"); + TEST_EQ(MILLI_CELSIUS_TO_MILLI_KELVIN(100), 273250, "%d"); + + TEST_EQ(MILLI_KELVIN_TO_KELVIN(5000), 5, "%d"); + TEST_EQ(KELVIN_TO_MILLI_KELVIN(100), 100000, "%d"); + + TEST_EQ(CELSIUS_TO_MILLI_KELVIN(100), 373150, "%d"); + TEST_EQ(MILLI_KELVIN_TO_CELSIUS(100), -273, "%d"); + + return EC_SUCCESS; +} + void run_test(int argc, char **argv) { test_reset(); RUN_TEST(test_acos); RUN_TEST(test_rotate); + RUN_TEST(test_round_divide); + RUN_TEST(test_temp_conversion); test_print_result(); } diff --git a/test/sbs_charging_v2.c b/test/sbs_charging_v2.c index 520db7bb20..bdca592d6c 100644 --- a/test/sbs_charging_v2.c +++ b/test/sbs_charging_v2.c @@ -12,6 +12,7 @@ #include "gpio.h" #include "hooks.h" #include "host_command.h" +#include "math_util.h" #include "power.h" #include "task.h" #include "test_util.h" |