Add Thermal HAL VTS
Bug: 32022734
Test: vts
Change-Id: I29ecd8b9da8275674343bce73c9f9deb20692bf2
diff --git a/thermal/1.0/IThermal.hal b/thermal/1.0/IThermal.hal
index a60bc7d..e5f70cb 100644
--- a/thermal/1.0/IThermal.hal
+++ b/thermal/1.0/IThermal.hal
@@ -32,6 +32,9 @@
* always returns and never removes such temperatures.
*
*/
+ @callflow(next={"*"})
+ @entry
+ @exit
getTemperatures()
generates (ThermalStatus status, vec<Temperature> temperatures);
@@ -47,6 +50,9 @@
* the same regardless the number of calls to this method.
*
*/
+ @callflow(next={"*"})
+ @entry
+ @exit
getCpuUsages() generates (ThermalStatus status, vec<CpuUsage> cpuUsages);
/*
@@ -63,6 +69,9 @@
* the list such cooling devices.
*
*/
+ @callflow(next={"*"})
+ @entry
+ @exit
getCoolingDevices()
generates (ThermalStatus status, vec<CoolingDevice> devices);
diff --git a/thermal/1.0/default/Thermal.cpp b/thermal/1.0/default/Thermal.cpp
index 1b91687..6c2111f 100644
--- a/thermal/1.0/default/Thermal.cpp
+++ b/thermal/1.0/default/Thermal.cpp
@@ -20,6 +20,7 @@
#include <errno.h>
#include <hardware/hardware.h>
#include <hardware/thermal.h>
+#include <vector>
#include "Thermal.h"
@@ -29,173 +30,167 @@
namespace V1_0 {
namespace implementation {
-Thermal::Thermal(thermal_module_t* module) : mModule(module) {
-}
+Thermal::Thermal(thermal_module_t* module) : mModule(module) {}
// Methods from ::android::hardware::thermal::V1_0::IThermal follow.
-Return<void> Thermal::getTemperatures(getTemperatures_cb _hidl_cb) {
- ThermalStatus status;
- status.code = ThermalStatusCode::SUCCESS;
- hidl_vec<Temperature> temperatures;
+Return<void> Thermal::getTemperatures(getTemperatures_cb _hidl_cb) {
+ ThermalStatus status;
+ status.code = ThermalStatusCode::SUCCESS;
+ hidl_vec<Temperature> temperatures;
- if (!mModule || !mModule->getTemperatures) {
- ALOGI("getTemperatures is not implemented in Thermal HAL.");
- _hidl_cb(status, temperatures);
- return Void();
- }
-
- ssize_t list_size = mModule->getTemperatures(mModule, nullptr, 0);
- if (list_size >= 0) {
- temperature_t *list = new temperature_t[list_size];
- ssize_t size = mModule->getTemperatures(mModule, list, list_size);
- if (size >= 0) {
- if (list_size > size) {
- list_size = size;
- }
-
- temperatures.resize(list_size);
- for (ssize_t i = 0; i < list_size; ++i) {
- switch (list[i].type) {
- case DEVICE_TEMPERATURE_UNKNOWN:
- temperatures[i].type = TemperatureType::UNKNOWN;
- break;
- case DEVICE_TEMPERATURE_CPU:
- temperatures[i].type = TemperatureType::CPU;
- break;
- case DEVICE_TEMPERATURE_GPU:
- temperatures[i].type = TemperatureType::GPU;
- break;
- case DEVICE_TEMPERATURE_BATTERY:
- temperatures[i].type = TemperatureType::BATTERY;
- break;
- case DEVICE_TEMPERATURE_SKIN:
- temperatures[i].type = TemperatureType::SKIN;
- break;
- default:
- ALOGE("Unknown temperature %s type", list[i].name);;
- }
- temperatures[i].name = list[i].name;
- temperatures[i].currentValue = list[i].current_value;
- temperatures[i].throttlingThreshold = list[i].throttling_threshold;
- temperatures[i].shutdownThreshold = list[i].shutdown_threshold;
- temperatures[i].vrThrottlingThreshold = list[i].vr_throttling_threshold;
- }
- } else {
- status.code = ThermalStatusCode::FAILURE;
- status.debugMessage = strerror(-size);
- }
- delete[] list;
- } else {
- status.code = ThermalStatusCode::FAILURE;
- status.debugMessage = strerror(-list_size);
- }
+ if (!mModule || !mModule->getTemperatures) {
+ ALOGI("getTemperatures is not implemented in Thermal HAL.");
_hidl_cb(status, temperatures);
return Void();
+ }
+
+ ssize_t size = mModule->getTemperatures(mModule, nullptr, 0);
+ if (size >= 0) {
+ std::vector<temperature_t> list;
+ list.resize(size);
+ size = mModule->getTemperatures(mModule, list.data(), list.size());
+ if (size >= 0) {
+ temperatures.resize(list.size());
+ for (size_t i = 0; i < list.size(); ++i) {
+ switch (list[i].type) {
+ case DEVICE_TEMPERATURE_UNKNOWN:
+ temperatures[i].type = TemperatureType::UNKNOWN;
+ break;
+ case DEVICE_TEMPERATURE_CPU:
+ temperatures[i].type = TemperatureType::CPU;
+ break;
+ case DEVICE_TEMPERATURE_GPU:
+ temperatures[i].type = TemperatureType::GPU;
+ break;
+ case DEVICE_TEMPERATURE_BATTERY:
+ temperatures[i].type = TemperatureType::BATTERY;
+ break;
+ case DEVICE_TEMPERATURE_SKIN:
+ temperatures[i].type = TemperatureType::SKIN;
+ break;
+ default:
+ ALOGE("Unknown temperature %s type", list[i].name);
+ ;
+ }
+ temperatures[i].name = list[i].name;
+ temperatures[i].currentValue = list[i].current_value;
+ temperatures[i].throttlingThreshold = list[i].throttling_threshold;
+ temperatures[i].shutdownThreshold = list[i].shutdown_threshold;
+ temperatures[i].vrThrottlingThreshold = list[i].vr_throttling_threshold;
+ }
+ }
+ }
+ if (size < 0) {
+ status.code = ThermalStatusCode::FAILURE;
+ status.debugMessage = strerror(-size);
+ }
+ _hidl_cb(status, temperatures);
+ return Void();
}
-Return<void> Thermal::getCpuUsages(getCpuUsages_cb _hidl_cb) {
- ThermalStatus status;
- hidl_vec<CpuUsage> cpuUsages;
- status.code = ThermalStatusCode::SUCCESS;
+Return<void> Thermal::getCpuUsages(getCpuUsages_cb _hidl_cb) {
+ ThermalStatus status;
+ hidl_vec<CpuUsage> cpuUsages;
+ status.code = ThermalStatusCode::SUCCESS;
- if (!mModule || !mModule->getCpuUsages) {
- ALOGI("getCpuUsages is not implemented in Thermal HAL");
- _hidl_cb(status, cpuUsages);
- return Void();
- }
-
- ssize_t size = mModule->getCpuUsages(mModule, nullptr);
- if (size >= 0) {
- cpu_usage_t *list = new cpu_usage_t[size];
- size = mModule->getCpuUsages(mModule, list);
- if (size >= 0) {
- cpuUsages.resize(size);
- for (ssize_t i = 0; i < size; ++i) {
- cpuUsages[i].name = list[i].name;
- cpuUsages[i].active = list[i].active;
- cpuUsages[i].total = list[i].total;
- cpuUsages[i].isOnline = list[i].is_online;
- }
- } else {
- status.code = ThermalStatusCode::FAILURE;
- status.debugMessage = strerror(-size);
- }
- delete[] list;
- } else {
- status.code = ThermalStatusCode::FAILURE;
- status.debugMessage = strerror(-size);
- }
+ if (!mModule || !mModule->getCpuUsages) {
+ ALOGI("getCpuUsages is not implemented in Thermal HAL");
_hidl_cb(status, cpuUsages);
return Void();
+ }
+
+ ssize_t size = mModule->getCpuUsages(mModule, nullptr);
+ if (size >= 0) {
+ std::vector<cpu_usage_t> list;
+ list.resize(size);
+ size = mModule->getCpuUsages(mModule, list.data());
+ if (size >= 0) {
+ list.resize(size);
+ cpuUsages.resize(size);
+ for (size_t i = 0; i < list.size(); ++i) {
+ cpuUsages[i].name = list[i].name;
+ cpuUsages[i].active = list[i].active;
+ cpuUsages[i].total = list[i].total;
+ cpuUsages[i].isOnline = list[i].is_online;
+ }
+ } else {
+ status.code = ThermalStatusCode::FAILURE;
+ status.debugMessage = strerror(-size);
+ }
+ }
+ if (size < 0) {
+ status.code = ThermalStatusCode::FAILURE;
+ status.debugMessage = strerror(-size);
+ }
+ _hidl_cb(status, cpuUsages);
+ return Void();
}
-Return<void> Thermal::getCoolingDevices(getCoolingDevices_cb _hidl_cb) {
- ThermalStatus status;
- status.code = ThermalStatusCode::SUCCESS;
- hidl_vec<CoolingDevice> coolingDevices;
+Return<void> Thermal::getCoolingDevices(getCoolingDevices_cb _hidl_cb) {
+ ThermalStatus status;
+ status.code = ThermalStatusCode::SUCCESS;
+ hidl_vec<CoolingDevice> coolingDevices;
- if (!mModule || !mModule->getCoolingDevices) {
- ALOGI("getCoolingDevices is not implemented in Thermal HAL.");
- _hidl_cb(status, coolingDevices);
- return Void();
- }
-
- ssize_t list_size = mModule->getCoolingDevices(mModule, nullptr, 0);
- if (list_size >= 0) {
- cooling_device_t *list = new cooling_device_t[list_size];
- ssize_t size = mModule->getCoolingDevices(mModule, list, list_size);
- if (size >= 0) {
- if (list_size > size) {
- list_size = size;
- }
- coolingDevices.resize(list_size);
- for (ssize_t i = 0; i < list_size; ++i) {
- switch (list[i].type) {
- case FAN_RPM:
- coolingDevices[i].type = CoolingType::FAN_RPM;
- break;
- default:
- ALOGE("Unknown cooling device %s type", list[i].name);
- }
- coolingDevices[i].name = list[i].name;
- coolingDevices[i].currentValue = list[i].current_value;
- }
-
- } else {
- status.code = ThermalStatusCode::FAILURE;
- status.debugMessage = strerror(-size);
- }
- delete[] list;
- } else {
- status.code = ThermalStatusCode::FAILURE;
- status.debugMessage = strerror(-list_size);
- }
+ if (!mModule || !mModule->getCoolingDevices) {
+ ALOGI("getCoolingDevices is not implemented in Thermal HAL.");
_hidl_cb(status, coolingDevices);
return Void();
+ }
+
+ ssize_t size = mModule->getCoolingDevices(mModule, nullptr, 0);
+ if (size >= 0) {
+ std::vector<cooling_device_t> list;
+ list.resize(size);
+ size = mModule->getCoolingDevices(mModule, list.data(), list.size());
+ if (size >= 0) {
+ list.resize(size);
+ coolingDevices.resize(list.size());
+ for (size_t i = 0; i < list.size(); ++i) {
+ switch (list[i].type) {
+ case FAN_RPM:
+ coolingDevices[i].type = CoolingType::FAN_RPM;
+ break;
+ default:
+ ALOGE("Unknown cooling device %s type", list[i].name);
+ }
+ coolingDevices[i].name = list[i].name;
+ coolingDevices[i].currentValue = list[i].current_value;
+ }
+ }
+ }
+ if (size < 0) {
+ status.code = ThermalStatusCode::FAILURE;
+ status.debugMessage = strerror(-size);
+ }
+ _hidl_cb(status, coolingDevices);
+ return Void();
}
IThermal* HIDL_FETCH_IThermal(const char* /* name */) {
- thermal_module_t* module;
- status_t err = hw_get_module(THERMAL_HARDWARE_MODULE_ID,
- const_cast<hw_module_t const**>(reinterpret_cast<hw_module_t**>(&module)));
- if (err || !module) {
- ALOGE("Couldn't load %s module (%s)", THERMAL_HARDWARE_MODULE_ID,
- strerror(-err));
- }
+ thermal_module_t* module;
+ status_t err = hw_get_module(THERMAL_HARDWARE_MODULE_ID,
+ const_cast<hw_module_t const**>(
+ reinterpret_cast<hw_module_t**>(&module)));
+ if (err || !module) {
+ ALOGE("Couldn't load %s module (%s)", THERMAL_HARDWARE_MODULE_ID,
+ strerror(-err));
+ }
- if (err == 0 && module->common.methods->open) {
- struct hw_device_t* device;
- err = module->common.methods->open(&module->common, THERMAL_HARDWARE_MODULE_ID, &device);
- if (err) {
- ALOGE("Couldn't open %s module (%s)", THERMAL_HARDWARE_MODULE_ID, strerror(-err));
- } else {
- return new Thermal(reinterpret_cast<thermal_module_t*>(device));
- }
+ if (err == 0 && module->common.methods->open) {
+ struct hw_device_t* device;
+ err = module->common.methods->open(&module->common,
+ THERMAL_HARDWARE_MODULE_ID, &device);
+ if (err) {
+ ALOGE("Couldn't open %s module (%s)", THERMAL_HARDWARE_MODULE_ID,
+ strerror(-err));
+ } else {
+ return new Thermal(reinterpret_cast<thermal_module_t*>(device));
}
- return new Thermal(module);
+ }
+ return new Thermal(module);
}
-} // namespace implementation
+} // namespace implementation
} // namespace V1_0
} // namespace thermal
} // namespace hardware
diff --git a/thermal/1.0/types.hal b/thermal/1.0/types.hal
index 26a0f6f..8864f43 100644
--- a/thermal/1.0/types.hal
+++ b/thermal/1.0/types.hal
@@ -26,7 +26,7 @@
SKIN = 3,
};
-enum CoolingType : int32_t {
+enum CoolingType : uint32_t {
/** Fan cooling device speed in RPM. */
FAN_RPM = 0,
};
@@ -118,9 +118,9 @@
enum ThermalStatusCode : uint32_t {
/** No errors. */
- SUCCESS,
+ SUCCESS = 0,
/** Unknown failure occured. */
- FAILURE
+ FAILURE = 1
};
/**
diff --git a/thermal/1.0/vts/Android.mk b/thermal/1.0/vts/Android.mk
new file mode 100644
index 0000000..f1ac716
--- /dev/null
+++ b/thermal/1.0/vts/Android.mk
@@ -0,0 +1,84 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+# build VTS driver for Thermal v1.0.
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := libvts_driver_hidl_thermal@1.0
+
+LOCAL_SRC_FILES := \
+ Thermal.vts \
+ types.vts \
+
+LOCAL_C_INCLUDES := \
+ android.hardware.thermal@1.0 \
+ system/core/base/include \
+ system/core/include \
+
+LOCAL_SHARED_LIBRARIES += \
+ android.hardware.thermal@1.0 \
+ libbase \
+ libutils \
+ libcutils \
+ liblog \
+ libhidl \
+ libhwbinder \
+ libprotobuf-cpp-full \
+ libvts_common \
+ libvts_datatype \
+ libvts_measurement \
+ libvts_multidevice_proto \
+
+LOCAL_STATIC_LIBRARIES := \
+
+LOCAL_PROTOC_OPTIMIZE_TYPE := full
+
+LOCAL_MULTILIB := both
+
+include $(BUILD_SHARED_LIBRARY)
+
+# build profiler for thermal.
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := libvts_profiler_hidl_thermal@1.0
+
+LOCAL_SRC_FILES := \
+ Thermal.vts \
+ types.vts \
+
+LOCAL_C_INCLUDES += \
+ test/vts/drivers/libprofiling \
+
+LOCAL_VTS_MODE := PROFILER
+
+LOCAL_SHARED_LIBRARIES := \
+ android.hardware.thermal@1.0 \
+ libbase \
+ libcutils \
+ liblog \
+ libhidl \
+ libhwbinder \
+ libprotobuf-cpp-full \
+ libvts_common \
+ libvts_multidevice_proto \
+ libvts_profiling \
+ libutils \
+
+LOCAL_PROTOC_OPTIMIZE_TYPE := full
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/thermal/1.0/vts/Thermal.vts b/thermal/1.0/vts/Thermal.vts
new file mode 100644
index 0000000..e76d943
--- /dev/null
+++ b/thermal/1.0/vts/Thermal.vts
@@ -0,0 +1,82 @@
+component_class: HAL_HIDL
+component_type_version: 1.0
+component_name: "IThermal"
+
+package: "android.hardware.thermal"
+
+import: "android.hardware.thermal@1.0::types"
+
+interface: {
+ api: {
+ name: "getTemperatures"
+ return_type_hidl: {
+ type: TYPE_STRUCT
+ predefined_type: "::android::hardware::thermal::V1_0::ThermalStatus"
+ }
+ return_type_hidl: {
+ type: TYPE_VECTOR
+ vector_value: {
+ type: TYPE_STRUCT
+ predefined_type: "::android::hardware::thermal::V1_0::Temperature"
+ }
+ }
+ callflow: {
+ next: "*"
+ }
+ callflow: {
+ entry: true
+ }
+ callflow: {
+ exit: true
+ }
+ }
+
+ api: {
+ name: "getCpuUsages"
+ return_type_hidl: {
+ type: TYPE_STRUCT
+ predefined_type: "::android::hardware::thermal::V1_0::ThermalStatus"
+ }
+ return_type_hidl: {
+ type: TYPE_VECTOR
+ vector_value: {
+ type: TYPE_STRUCT
+ predefined_type: "::android::hardware::thermal::V1_0::CpuUsage"
+ }
+ }
+ callflow: {
+ next: "*"
+ }
+ callflow: {
+ entry: true
+ }
+ callflow: {
+ exit: true
+ }
+ }
+
+ api: {
+ name: "getCoolingDevices"
+ return_type_hidl: {
+ type: TYPE_STRUCT
+ predefined_type: "::android::hardware::thermal::V1_0::ThermalStatus"
+ }
+ return_type_hidl: {
+ type: TYPE_VECTOR
+ vector_value: {
+ type: TYPE_STRUCT
+ predefined_type: "::android::hardware::thermal::V1_0::CoolingDevice"
+ }
+ }
+ callflow: {
+ next: "*"
+ }
+ callflow: {
+ entry: true
+ }
+ callflow: {
+ exit: true
+ }
+ }
+
+}
diff --git a/thermal/1.0/vts/functional/Android.bp b/thermal/1.0/vts/functional/Android.bp
new file mode 100644
index 0000000..7e0d1d0
--- /dev/null
+++ b/thermal/1.0/vts/functional/Android.bp
@@ -0,0 +1,37 @@
+//
+// Copyright (C) 2016 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+cc_test {
+ name: "thermal_hidl_hal_test",
+ gtest: true,
+ srcs: ["thermal_hidl_hal_test.cpp"],
+ shared_libs: [
+ "libbase",
+ "liblog",
+ "libcutils",
+ "libhidl",
+ "libhwbinder",
+ "libnativehelper",
+ "libutils",
+ "android.hardware.thermal@1.0",
+ ],
+ static_libs: ["libgtest"],
+ cflags: [
+ "-O0",
+ "-g",
+ ],
+}
+
diff --git a/thermal/1.0/vts/functional/thermal_hidl_hal_test.cpp b/thermal/1.0/vts/functional/thermal_hidl_hal_test.cpp
new file mode 100644
index 0000000..e3b00ab
--- /dev/null
+++ b/thermal/1.0/vts/functional/thermal_hidl_hal_test.cpp
@@ -0,0 +1,219 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <algorithm>
+#include <cmath>
+#include <string>
+#include <vector>
+
+#define LOG_TAG "thermal_hidl_hal_test"
+
+#include <android-base/logging.h>
+#include <android/hardware/thermal/1.0/IThermal.h>
+#include <android/hardware/thermal/1.0/types.h>
+#include <gtest/gtest.h>
+#include <unistd.h>
+
+using ::android::hardware::hidl_string;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::thermal::V1_0::CoolingDevice;
+using ::android::hardware::thermal::V1_0::CpuUsage;
+using ::android::hardware::thermal::V1_0::IThermal;
+using ::android::hardware::thermal::V1_0::Temperature;
+using ::android::hardware::thermal::V1_0::TemperatureType;
+using ::android::hardware::thermal::V1_0::ThermalStatus;
+using ::android::hardware::thermal::V1_0::ThermalStatusCode;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::sp;
+
+#define THERMAL_SERVICE_NAME "thermal"
+#define MONITORING_OPERATION_NUMBER 10
+
+#define UNDEFINED_TEMPERATURE (-FLT_MAX)
+
+#define MAX_DEVICE_TEMPERATURE 200
+#define MAX_FAN_SPEED 20000
+
+// The main test class for THERMAL HIDL HAL.
+class ThermalHidlTest : public ::testing::Test {
+ public:
+ virtual void SetUp() override {
+ thermal_ = IThermal::getService(THERMAL_SERVICE_NAME, false);
+ ASSERT_NE(thermal_, nullptr);
+ baseSize_ = 0;
+ names_.clear();
+ }
+
+ virtual void TearDown() override {}
+
+ protected:
+ // Check validity of temperatures returned by Thremal HAL.
+ void checkTemperatures(const hidl_vec<Temperature> temperatures) {
+ size_t size = temperatures.size();
+ EXPECT_LE(baseSize_, size);
+
+ for (size_t i = 0; i < size; ++i) {
+ checkDeviceTemperature(temperatures[i]);
+ if (i < baseSize_) {
+ EXPECT_EQ(names_[i], temperatures[i].name.c_str());
+ } else {
+ // Names must be unique.
+ EXPECT_EQ(names_.end(), std::find(names_.begin(), names_.end(),
+ temperatures[i].name.c_str()));
+ names_.push_back(temperatures[i].name);
+ }
+ }
+ baseSize_ = size;
+ }
+
+ // Check validity of CPU usages returned by Thermal HAL.
+ void checkCpuUsages(const hidl_vec<CpuUsage>& cpuUsages) {
+ size_t size = cpuUsages.size();
+ // A number of CPU's does not change.
+ if (baseSize_ != 0) EXPECT_EQ(baseSize_, size);
+
+ for (size_t i = 0; i < size; ++i) {
+ checkCpuUsage(cpuUsages[i]);
+ if (i < baseSize_) {
+ EXPECT_EQ(names_[i], cpuUsages[i].name.c_str());
+ } else {
+ // Names must be unique.
+ EXPECT_EQ(names_.end(), std::find(names_.begin(), names_.end(),
+ cpuUsages[i].name.c_str()));
+ names_.push_back(cpuUsages[i].name);
+ }
+ }
+ baseSize_ = size;
+ }
+
+ // Check validity of cooling devices information returned by Thermal HAL.
+ void checkCoolingDevices(const hidl_vec<CoolingDevice> coolingDevices) {
+ size_t size = coolingDevices.size();
+ EXPECT_LE(baseSize_, size);
+
+ for (size_t i = 0; i < size; ++i) {
+ checkCoolingDevice(coolingDevices[i]);
+ if (i < baseSize_) {
+ EXPECT_EQ(names_[i], coolingDevices[i].name.c_str());
+ } else {
+ // Names must be unique.
+ EXPECT_EQ(names_.end(), std::find(names_.begin(), names_.end(),
+ coolingDevices[i].name.c_str()));
+ names_.push_back(coolingDevices[i].name);
+ }
+ }
+ baseSize_ = size;
+ }
+
+ sp<IThermal> thermal_;
+
+ private:
+ // Check validity of temperature returned by Thermal HAL.
+ void checkDeviceTemperature(const Temperature& temperature) {
+ // .currentValue of known type is in Celsius and must be reasonable.
+ EXPECT_TRUE(temperature.type == TemperatureType::UNKNOWN ||
+ std::abs(temperature.currentValue) < MAX_DEVICE_TEMPERATURE ||
+ temperature.currentValue == UNDEFINED_TEMPERATURE);
+
+ // .name must not be empty.
+ EXPECT_LT(0u, temperature.name.size());
+
+ // .currentValue must not exceed .shutdwonThreshold if defined.
+ EXPECT_TRUE(temperature.currentValue < temperature.shutdownThreshold ||
+ temperature.currentValue == UNDEFINED_TEMPERATURE ||
+ temperature.shutdownThreshold == UNDEFINED_TEMPERATURE);
+
+ // .throttlingThreshold must not exceed .shutdownThreshold if defined.
+ EXPECT_TRUE(temperature.throttlingThreshold <
+ temperature.shutdownThreshold ||
+ temperature.throttlingThreshold == UNDEFINED_TEMPERATURE ||
+ temperature.shutdownThreshold == UNDEFINED_TEMPERATURE);
+ }
+
+ // Check validity of CPU usage returned by Thermal HAL.
+ void checkCpuUsage(const CpuUsage& cpuUsage) {
+ // .active must be less than .total if CPU is online.
+ EXPECT_TRUE(!cpuUsage.isOnline ||
+ (cpuUsage.active >= 0 && cpuUsage.total >= 0 &&
+ cpuUsage.total >= cpuUsage.active));
+
+ // .name must be not empty.
+ EXPECT_LT(0u, cpuUsage.name.size());
+ }
+
+ // Check validity of a cooling device information returned by Thermal HAL.
+ void checkCoolingDevice(const CoolingDevice& coolingDevice) {
+ EXPECT_LE(0, coolingDevice.currentValue);
+ EXPECT_GT(MAX_FAN_SPEED, coolingDevice.currentValue);
+ EXPECT_LT(0u, coolingDevice.name.size());
+ }
+
+ size_t baseSize_;
+ std::vector<hidl_string> names_;
+};
+
+// Sanity test for Thermal::getTemperatures().
+TEST_F(ThermalHidlTest, TemperatureTest) {
+ hidl_vec<Temperature> passed;
+ for (size_t i = 0; i < MONITORING_OPERATION_NUMBER; ++i) {
+ thermal_->getTemperatures(
+ [&passed](ThermalStatus status, hidl_vec<Temperature> temperatures) {
+ EXPECT_EQ(ThermalStatusCode::SUCCESS, status.code);
+ passed = temperatures;
+ });
+
+ checkTemperatures(passed);
+ sleep(1);
+ }
+}
+
+// Sanity test for Thermal::getCpuUsages().
+TEST_F(ThermalHidlTest, CpuUsageTest) {
+ hidl_vec<CpuUsage> passed;
+ for (size_t i = 0; i < MONITORING_OPERATION_NUMBER; ++i) {
+ thermal_->getCpuUsages(
+ [&passed](ThermalStatus status, hidl_vec<CpuUsage> cpuUsages) {
+ EXPECT_EQ(ThermalStatusCode::SUCCESS, status.code);
+ passed = cpuUsages;
+ });
+
+ checkCpuUsages(passed);
+ sleep(1);
+ }
+}
+
+// Sanity test for Thermal::getCoolingDevices().
+TEST_F(ThermalHidlTest, CoolingDeviceTest) {
+ hidl_vec<CoolingDevice> passed;
+ for (size_t i = 0; i < MONITORING_OPERATION_NUMBER; ++i) {
+ thermal_->getCoolingDevices([&passed](
+ ThermalStatus status, hidl_vec<CoolingDevice> coolingDevices) {
+ EXPECT_EQ(ThermalStatusCode::SUCCESS, status.code);
+ passed = coolingDevices;
+ });
+
+ checkCoolingDevices(passed);
+ sleep(1);
+ }
+}
+
+int main(int argc, char** argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ int status = RUN_ALL_TESTS();
+ ALOGI("Test result = %d", status);
+ return status;
+}
diff --git a/thermal/1.0/vts/types.vts b/thermal/1.0/vts/types.vts
new file mode 100644
index 0000000..1e60f48
--- /dev/null
+++ b/thermal/1.0/vts/types.vts
@@ -0,0 +1,157 @@
+component_class: HAL_HIDL
+component_type_version: 1.0
+component_name: "types"
+
+package: "android.hardware.thermal"
+
+
+attribute: {
+ name: "::android::hardware::thermal::V1_0::TemperatureType"
+ type: TYPE_ENUM
+ enum_value: {
+ scalar_type: "uint32_t"
+
+ enumerator: "UNKNOWN"
+ scalar_value: {
+ uint32_t: 1000
+ }
+ enumerator: "CPU"
+ scalar_value: {
+ uint32_t: 0
+ }
+ enumerator: "GPU"
+ scalar_value: {
+ uint32_t: 1
+ }
+ enumerator: "BATTERY"
+ scalar_value: {
+ uint32_t: 2
+ }
+ enumerator: "SKIN"
+ scalar_value: {
+ uint32_t: 3
+ }
+ }
+}
+
+attribute: {
+ name: "::android::hardware::thermal::V1_0::CoolingType"
+ type: TYPE_ENUM
+ enum_value: {
+ scalar_type: "uint32_t"
+
+ enumerator: "FAN_RPM"
+ scalar_value: {
+ uint32_t: 0
+ }
+ }
+}
+
+attribute: {
+ name: "::android::hardware::thermal::V1_0::Temperature"
+ type: TYPE_STRUCT
+ struct_value: {
+ name: "type"
+ type: TYPE_ENUM
+ predefined_type: "::android::hardware::thermal::V1_0::TemperatureType"
+ }
+ struct_value: {
+ name: "name"
+ type: TYPE_STRING
+ }
+ struct_value: {
+ name: "currentValue"
+ type: TYPE_SCALAR
+ scalar_type: "float_t"
+ }
+ struct_value: {
+ name: "throttlingThreshold"
+ type: TYPE_SCALAR
+ scalar_type: "float_t"
+ }
+ struct_value: {
+ name: "shutdownThreshold"
+ type: TYPE_SCALAR
+ scalar_type: "float_t"
+ }
+ struct_value: {
+ name: "vrThrottlingThreshold"
+ type: TYPE_SCALAR
+ scalar_type: "float_t"
+ }
+}
+
+attribute: {
+ name: "::android::hardware::thermal::V1_0::CoolingDevice"
+ type: TYPE_STRUCT
+ struct_value: {
+ name: "type"
+ type: TYPE_ENUM
+ predefined_type: "::android::hardware::thermal::V1_0::CoolingType"
+ }
+ struct_value: {
+ name: "name"
+ type: TYPE_STRING
+ }
+ struct_value: {
+ name: "currentValue"
+ type: TYPE_SCALAR
+ scalar_type: "float_t"
+ }
+}
+
+attribute: {
+ name: "::android::hardware::thermal::V1_0::CpuUsage"
+ type: TYPE_STRUCT
+ struct_value: {
+ name: "name"
+ type: TYPE_STRING
+ }
+ struct_value: {
+ name: "active"
+ type: TYPE_SCALAR
+ scalar_type: "uint64_t"
+ }
+ struct_value: {
+ name: "total"
+ type: TYPE_SCALAR
+ scalar_type: "uint64_t"
+ }
+ struct_value: {
+ name: "isOnline"
+ type: TYPE_SCALAR
+ scalar_type: "bool_t"
+ }
+}
+
+attribute: {
+ name: "::android::hardware::thermal::V1_0::ThermalStatusCode"
+ type: TYPE_ENUM
+ enum_value: {
+ scalar_type: "uint32_t"
+
+ enumerator: "SUCCESS"
+ scalar_value: {
+ uint32_t: 0
+ }
+ enumerator: "FAILURE"
+ scalar_value: {
+ uint32_t: 1
+ }
+ }
+}
+
+attribute: {
+ name: "::android::hardware::thermal::V1_0::ThermalStatus"
+ type: TYPE_STRUCT
+ struct_value: {
+ name: "code"
+ type: TYPE_ENUM
+ predefined_type: "::android::hardware::thermal::V1_0::ThermalStatusCode"
+ }
+ struct_value: {
+ name: "debugMessage"
+ type: TYPE_STRING
+ }
+}
+
diff --git a/thermal/Android.bp b/thermal/Android.bp
index ba90f2c..ed19a37 100644
--- a/thermal/Android.bp
+++ b/thermal/Android.bp
@@ -2,4 +2,5 @@
subdirs = [
"1.0",
"1.0/default",
+ "1.0/vts/functional",
]