thermal: substitute undefined temperature by NAN.

Bug: 34107726
Test: vts, cts

Change-Id: Ia6e9e83691e8b6b5e2760579e1131a5994a48572
This commit is contained in:
Polina Bondarenko
2017-01-19 15:55:19 +01:00
parent 2b965af4e5
commit 93a2d68efe
3 changed files with 22 additions and 22 deletions

View File

@@ -17,6 +17,7 @@
#define LOG_TAG "android.hardware.thermal@1.0-impl"
#include <errno.h>
#include <math.h>
#include <vector>
@@ -33,6 +34,14 @@ namespace thermal {
namespace V1_0 {
namespace implementation {
namespace {
float finalizeTemperature(float temperature) {
return temperature == UNKNOWN_TEMPERATURE ? NAN : temperature;
}
}
Thermal::Thermal(thermal_module_t* module) : mModule(module) {}
// Methods from ::android::hardware::thermal::V1_0::IThermal follow.
@@ -76,10 +85,11 @@ Return<void> Thermal::getTemperatures(getTemperatures_cb _hidl_cb) {
;
}
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;
temperatures[i].currentValue = finalizeTemperature(list[i].current_value);
temperatures[i].throttlingThreshold = finalizeTemperature(list[i].throttling_threshold);
temperatures[i].shutdownThreshold = finalizeTemperature(list[i].shutdown_threshold);
temperatures[i].vrThrottlingThreshold =
finalizeTemperature(list[i].vr_throttling_threshold);
}
}
}

View File

@@ -45,28 +45,27 @@ struct Temperature {
string name;
/**
* Current temperature in Celsius. If not available set by HAL to
* UNKNOWN_TEMPERATURE.
* Current temperature in Celsius. If not available set by HAL to NAN.
* Current temperature can be in any units if type=UNKNOWN.
*/
float currentValue;
/**
* Throttling temperature constant for this temperature.
* If not available, set by HAL to UNKNOWN_TEMPERATURE.
* If not available, set by HAL to NAN.
*/
float throttlingThreshold;
/**
* Shutdown temperature constant for this temperature.
* If not available, set by HAL to UNKNOWN_TEMPERATURE.
* If not available, set by HAL to NAN.
*/
float shutdownThreshold;
/**
* Threshold temperature above which the VR mode clockrate minimums cannot
* be maintained for this device.
* If not available, set by HAL to UNKNOWN_TEMPERATURE.
* If not available, set by HAL to NAN.
*/
float vrThrottlingThreshold;
@@ -135,7 +134,3 @@ struct ThermalStatus {
*/
string debugMessage;
};
/**
* TODO(pbond): add float constant UNDEFINED_TEMPERATURE.
*/

View File

@@ -43,8 +43,6 @@ 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
@@ -127,21 +125,18 @@ class ThermalHidlTest : public ::testing::Test {
// .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);
isnan(temperature.currentValue));
// .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);
isnan(temperature.currentValue) || isnan(temperature.shutdownThreshold));
// .throttlingThreshold must not exceed .shutdownThreshold if defined.
EXPECT_TRUE(temperature.throttlingThreshold <
temperature.shutdownThreshold ||
temperature.throttlingThreshold == UNDEFINED_TEMPERATURE ||
temperature.shutdownThreshold == UNDEFINED_TEMPERATURE);
EXPECT_TRUE(temperature.throttlingThreshold < temperature.shutdownThreshold ||
isnan(temperature.throttlingThreshold) || isnan(temperature.shutdownThreshold));
}
// Check validity of CPU usage returned by Thermal HAL.