haltest: add test for thermistor 13/255713/1
authorYoungjae Cho <y0.cho@samsung.com>
Tue, 23 Mar 2021 00:38:50 +0000 (09:38 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Tue, 23 Mar 2021 01:22:22 +0000 (10:22 +0900)
Change-Id: I860d15706d05e4fd792175a5bdd6890afe6ec563
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
haltest/haltest.h
haltest/thermal.cpp [new file with mode: 0644]

index 287b196..2e4af32 100644 (file)
@@ -49,12 +49,13 @@ do { \
        testing::internal::ColoredPrintf(testing::internal::COLOR_DEFAULT, "\n"); \
 } while (0)
 
-#define FEATURE_BATTERY     "http://tizen.org/feature/battery"
-#define FEATURE_DISPLAY     "http://tizen.org/feature/display"
-#define FEATURE_LED         "http://tizen.org/feature/led"
-#define FEATURE_IR          "http://tizen.org/feature/consumer_ir"
-#define FEATURE_THERMISTOR  "http://tizen.org/feature/thermistor.ap"
-#define FEATURE_BEZEL       "http://tizen.org/feature/input.rotating_bezel"
+#define FEATURE_BATTERY             "http://tizen.org/feature/battery"
+#define FEATURE_DISPLAY             "http://tizen.org/feature/display"
+#define FEATURE_LED                 "http://tizen.org/feature/led"
+#define FEATURE_IR                  "http://tizen.org/feature/consumer_ir"
+#define FEATURE_THERMISTOR_AP       "http://tizen.org/feature/thermistor.ap"
+#define FEATURE_THERMISTOR_BATTERY  "http://tizen.org/feature/thermistor.battery"
+#define FEATURE_BEZEL               "http://tizen.org/feature/input.rotating_bezel"
 
 // SetUp/TearDown function for a testsuite differ by gtest version
 #if (GTEST_VERSION_MAJOR >= 2 || (GTEST_VERSION_MAJOR == 1 && GTEST_VERSION_MINOR >= 10))
diff --git a/haltest/thermal.cpp b/haltest/thermal.cpp
new file mode 100644 (file)
index 0000000..2d11fc5
--- /dev/null
@@ -0,0 +1,116 @@
+#include <system_info.h>
+
+#include "haltest.h"
+#include "hal-thermal.h"
+
+class THERMAL : public testing::Test
+{
+       protected:
+               static void SetUpHalTestSuite() {
+                       int ret_val;
+
+                       ret_val = system_info_get_platform_bool(FEATURE_THERMISTOR_AP, &THERMAL::ap);
+                       EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret_val) << strerr("Failed to get thermal ap feature", ret_val);
+
+                       ret_val = system_info_get_platform_bool(FEATURE_THERMISTOR_BATTERY, &THERMAL::battery);
+                       EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret_val) << strerr("Failed to get thermal battery feature", ret_val);
+
+                       if (ap || battery) {
+                               ret_val = hal_device_thermal_get_backend();
+                               ASSERT_EQ(ret_val, 0) << strerr("Failed to get thermal backend", ret_val);
+
+                               supported = true;
+                       }
+               }
+
+               static bool supported;
+
+               // supported thermistor
+               static bool ap;
+               static bool battery;
+};
+
+bool THERMAL::supported = false;
+bool THERMAL::ap = false;
+bool THERMAL::battery = false;
+
+// dummy
+static void __updated_cb(struct thermal_info *info, void *data)
+{
+       EXPECT_NE(info, nullptr) << "Failed to get thermal information";
+}
+
+TEST_F(THERMAL, GetInfoP)
+{
+       int ret_val;
+       struct thermal_info info;
+
+       if (!THERMAL::supported) {
+               SKIP_MESSAGE("Thermal not supported");
+               return;
+       }
+
+       if (THERMAL::ap) {
+               info.temp = -1;
+               info.adc = -1;
+
+               ret_val = hal_device_thermal_get_info(DEVICE_THERMAL_AP, &info);
+               if (ret_val == -ENODEV) {
+                       SKIP_MESSAGE("Not supported HAL");
+                       return;
+               }
+               EXPECT_EQ(ret_val, 0) << strerr("Failed to get ap thermal info", ret_val);
+               EXPECT_NE(info.temp, -1) << "Failed to get ap thermal info";
+               EXPECT_NE(info.adc, -1) << "Failed to get ap thermal info";
+               DEBUG_MESSAGE("ap temp=%d adc=%d", info.temp, info.adc);
+       }
+
+       if (THERMAL::battery) {
+               info.temp = -1;
+               info.adc = -1;
+
+               ret_val = hal_device_thermal_get_info(DEVICE_THERMAL_BATTERY, &info);
+               if (ret_val == -ENODEV) {
+                       SKIP_MESSAGE("Not supported HAL");
+                       return;
+               }
+               EXPECT_EQ(ret_val, 0) << strerr("Failed to get battery thermal info", ret_val);
+               EXPECT_NE(info.temp, -1) << "Failed to get battery thermal info";
+               EXPECT_NE(info.adc, -1) << "Failed to get battery thermal info";
+               DEBUG_MESSAGE("battery temp=%d adc=%d", info.temp, info.adc);
+       }
+}
+
+TEST_F(THERMAL, RegisterChangedEventP)
+{
+       int ret_val;
+
+       if (!THERMAL::supported) {
+               SKIP_MESSAGE("Thermal not supported");
+               return;
+       }
+
+       ret_val = hal_device_thermal_register_changed_event(__updated_cb, NULL);
+       if (ret_val == -ENODEV) {
+               SKIP_MESSAGE("Not supported HAL");
+               return;
+       }
+       ASSERT_EQ(ret_val, 0) << strerr("Failed to register changed callback", ret_val);
+}
+
+TEST_F(THERMAL, UnrgisterChangedEventP)
+{
+       int ret_val;
+
+       if (!THERMAL::supported) {
+               SKIP_MESSAGE("Thermal not supported");
+               return;
+       }
+
+       ret_val = hal_device_thermal_unregister_changed_event(__updated_cb);
+       if (ret_val == -ENODEV) {
+               SKIP_MESSAGE("Not supported HAL");
+               return;
+       }
+       ASSERT_EQ(ret_val, 0) << strerr("Failed to unregister changed callback", ret_val);
+}