diff options
| author | Patrick Venture <venture@google.com> | 2018-11-11 12:55:14 -0800 |
|---|---|---|
| committer | Patrick Venture <venture@google.com> | 2018-11-11 12:57:02 -0800 |
| commit | 5f59c0fdbda807ac54a58657fbd6cbde718e8678 (patch) | |
| tree | 8934e1a3e91c2281f4a306419a9c53a77f471ad9 /test | |
| parent | ba3c8c1c15ab10e3c9ad287c93d8a7598addc22f (diff) | |
| download | phosphor-pid-control-5f59c0fdbda807ac54a58657fbd6cbde718e8678.tar.gz phosphor-pid-control-5f59c0fdbda807ac54a58657fbd6cbde718e8678.zip | |
Move all floats to doubles
The code was developed initially around a pid loop implemented using
floats. Therefore, the code was converting back and forth between
double for sensor values as inputs and outputs from this PID loop.
Change-Id: I2d2919e1165103040729c9f16bb84fde3dd6b81b
Signed-off-by: Patrick Venture <venture@google.com>
Diffstat (limited to 'test')
| -rw-r--r-- | test/controller_mock.hpp | 6 | ||||
| -rw-r--r-- | test/pid_fancontroller_unittest.cpp | 6 | ||||
| -rw-r--r-- | test/pid_stepwisecontroller_unittest.cpp | 4 | ||||
| -rw-r--r-- | test/pid_thermalcontroller_unittest.cpp | 14 | ||||
| -rw-r--r-- | test/pid_zone_unittest.cpp | 12 | ||||
| -rw-r--r-- | test/zone_mock.hpp | 6 |
6 files changed, 24 insertions, 24 deletions
diff --git a/test/controller_mock.hpp b/test/controller_mock.hpp index c0af859..94c7cb5 100644 --- a/test/controller_mock.hpp +++ b/test/controller_mock.hpp @@ -14,7 +14,7 @@ class ControllerMock : public PIDController { } - MOCK_METHOD0(inputProc, float()); - MOCK_METHOD0(setptProc, float()); - MOCK_METHOD1(outputProc, void(float)); + MOCK_METHOD0(inputProc, double()); + MOCK_METHOD0(setptProc, double()); + MOCK_METHOD1(outputProc, void(double)); }; diff --git a/test/pid_fancontroller_unittest.cpp b/test/pid_fancontroller_unittest.cpp index 57932c9..ad646bf 100644 --- a/test/pid_fancontroller_unittest.cpp +++ b/test/pid_fancontroller_unittest.cpp @@ -234,9 +234,9 @@ TEST(FanControllerTest, OutputProc_VerifyFailSafeIgnoredIfInputHigher) // Grab pointer for mocking. SensorMock* sm1 = reinterpret_cast<SensorMock*>(s1.get()); - // Converting from float to double for expectation. - float percent = 80; - double value = static_cast<double>(percent / 100); + // Converting from double to double for expectation. + double percent = 80; + double value = percent / 100; EXPECT_CALL(z, getSensor(StrEq("fan0"))).WillOnce(Return(s1.get())); EXPECT_CALL(*sm1, write(value)); diff --git a/test/pid_stepwisecontroller_unittest.cpp b/test/pid_stepwisecontroller_unittest.cpp index 880864d..e3c4f09 100644 --- a/test/pid_stepwisecontroller_unittest.cpp +++ b/test/pid_stepwisecontroller_unittest.cpp @@ -24,7 +24,7 @@ TEST(StepwiseControllerTest, HysteresisTestPositive) initial.positiveHysteresis = 2.0; initial.reading[0] = 20.0; initial.reading[1] = 30.0; - initial.reading[2] = std::numeric_limits<float>::quiet_NaN(); + initial.reading[2] = std::numeric_limits<double>::quiet_NaN(); initial.output[0] = 40.0; initial.output[1] = 60.0; @@ -59,7 +59,7 @@ TEST(StepwiseControllerTest, HysteresisTestNegative) initial.positiveHysteresis = 2.0; initial.reading[0] = 20.0; initial.reading[1] = 30.0; - initial.reading[2] = std::numeric_limits<float>::quiet_NaN(); + initial.reading[2] = std::numeric_limits<double>::quiet_NaN(); initial.output[0] = 40.0; initial.output[1] = 60.0; diff --git a/test/pid_thermalcontroller_unittest.cpp b/test/pid_thermalcontroller_unittest.cpp index 97550f8..6da309f 100644 --- a/test/pid_thermalcontroller_unittest.cpp +++ b/test/pid_thermalcontroller_unittest.cpp @@ -19,7 +19,7 @@ TEST(ThermalControllerTest, BoringFactoryTest) ZoneMock z; std::vector<std::string> inputs = {"fleeting0"}; - float setpoint = 10.0; + double setpoint = 10.0; ec::pidinfo initial; std::unique_ptr<PIDController> p = ThermalController::createThermalPid( @@ -35,7 +35,7 @@ TEST(ThermalControllerTest, VerifyFactoryFailsWithZeroInputs) ZoneMock z; std::vector<std::string> inputs = {}; - float setpoint = 10.0; + double setpoint = 10.0; ec::pidinfo initial; std::unique_ptr<PIDController> p = ThermalController::createThermalPid( @@ -51,7 +51,7 @@ TEST(ThermalControllerTest, VerifyFactoryFailsForMoreThanOneInput) ZoneMock z; std::vector<std::string> inputs = {"fleeting0", "asdf"}; - float setpoint = 10.0; + double setpoint = 10.0; ec::pidinfo initial; std::unique_ptr<PIDController> p = ThermalController::createThermalPid( @@ -66,7 +66,7 @@ TEST(ThermalControllerTest, InputProc_BehavesAsExpected) ZoneMock z; std::vector<std::string> inputs = {"fleeting0"}; - float setpoint = 10.0; + double setpoint = 10.0; ec::pidinfo initial; std::unique_ptr<PIDController> p = ThermalController::createThermalPid( @@ -85,7 +85,7 @@ TEST(ThermalControllerTest, SetPtProc_BehavesAsExpected) ZoneMock z; std::vector<std::string> inputs = {"fleeting0"}; - float setpoint = 10.0; + double setpoint = 10.0; ec::pidinfo initial; std::unique_ptr<PIDController> p = ThermalController::createThermalPid( @@ -102,14 +102,14 @@ TEST(ThermalControllerTest, OutputProc_BehavesAsExpected) ZoneMock z; std::vector<std::string> inputs = {"fleeting0"}; - float setpoint = 10.0; + double setpoint = 10.0; ec::pidinfo initial; std::unique_ptr<PIDController> p = ThermalController::createThermalPid( &z, "therm1", inputs, setpoint, initial); EXPECT_FALSE(p == nullptr); - float value = 90.0; + double value = 90.0; EXPECT_CALL(z, addRPMSetPoint(value)); p->outputProc(value); diff --git a/test/pid_zone_unittest.cpp b/test/pid_zone_unittest.cpp index 0b9aa9f..239a04a 100644 --- a/test/pid_zone_unittest.cpp +++ b/test/pid_zone_unittest.cpp @@ -42,8 +42,8 @@ TEST(PidZoneConstructorTest, BoringConstructorTest) bool defer = true; const char* objPath = "/path/"; int64_t zone = 1; - float minThermalRpm = 1000.0; - float failSafePercent = 0.75; + double minThermalRpm = 1000.0; + double failSafePercent = 0.75; int i; std::vector<std::string> properties; @@ -92,8 +92,8 @@ class PidZoneTest : public ::testing::Test sdbusplus::SdBusMock sdbus_mock_host; sdbusplus::SdBusMock sdbus_mock_mode; int64_t zoneId = 1; - float minThermalRpm = 1000.0; - float failSafePercent = 0.75; + double minThermalRpm = 1000.0; + double failSafePercent = 0.75; bool defer = true; const char* objPath = "/path/"; SensorManager mgr; @@ -125,7 +125,7 @@ TEST_F(PidZoneTest, RpmSetPoints_AddMaxClear_BehaveAsExpected) // At least one value must be above the minimum thermal setpoint used in // the constructor otherwise it'll choose that value - std::vector<float> values = {100, 200, 300, 400, 500, 5000}; + std::vector<double> values = {100, 200, 300, 400, 500, 5000}; for (auto v : values) { zone->addRPMSetPoint(v); @@ -148,7 +148,7 @@ TEST_F(PidZoneTest, RpmSetPoints_AddBelowMinimum_BehavesAsExpected) // Tests adding several RPM setpoints, however, they're all lower than the // configured minimal thermal set-point RPM value. - std::vector<float> values = {100, 200, 300, 400, 500}; + std::vector<double> values = {100, 200, 300, 400, 500}; for (auto v : values) { zone->addRPMSetPoint(v); diff --git a/test/zone_mock.hpp b/test/zone_mock.hpp index 79947fb..35a6b32 100644 --- a/test/zone_mock.hpp +++ b/test/zone_mock.hpp @@ -12,9 +12,9 @@ class ZoneMock : public ZoneInterface virtual ~ZoneMock() = default; MOCK_METHOD1(getCachedValue, double(const std::string&)); - MOCK_METHOD1(addRPMSetPoint, void(float)); - MOCK_CONST_METHOD0(getMaxRPMRequest, float()); + MOCK_METHOD1(addRPMSetPoint, void(double)); + MOCK_CONST_METHOD0(getMaxRPMRequest, double()); MOCK_CONST_METHOD0(getFailSafeMode, bool()); - MOCK_CONST_METHOD0(getFailSafePercent, float()); + MOCK_CONST_METHOD0(getFailSafePercent, double()); MOCK_METHOD1(getSensor, Sensor*(const std::string&)); }; |

