diff options
| author | Patrick Venture <venture@google.com> | 2018-08-31 09:42:48 -0700 |
|---|---|---|
| committer | Patrick Venture <venture@google.com> | 2018-08-31 09:53:59 -0700 |
| commit | da4a5dd133b88ebfeb69e89d05b381f81ba70e50 (patch) | |
| tree | aa1b8dcd7ce1432491e20d8a110fe2f762b59908 | |
| parent | 40be36ac31a4756498a1f297324129fe1271b726 (diff) | |
| download | phosphor-pid-control-da4a5dd133b88ebfeb69e89d05b381f81ba70e50.tar.gz phosphor-pid-control-da4a5dd133b88ebfeb69e89d05b381f81ba70e50.zip | |
add .clang-format
Change-Id: I6627b5569c2e0f730be7331403218b823a2c622f
Signed-off-by: Patrick Venture <venture@google.com>
72 files changed, 1227 insertions, 1295 deletions
diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..00d9a54 --- /dev/null +++ b/.clang-format @@ -0,0 +1,99 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlinesLeft: false +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: false +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: true + AfterControlStatement: true + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: true + BeforeCatch: true + BeforeElse: true + IndentBraces: false +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: AfterColon +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: true +PointerAlignment: Left +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^[<"](gtest|gmock)' + Priority: 5 + - Regex: '^"config.h"' + Priority: -1 + - Regex: '^".*\.hpp"' + Priority: 1 + - Regex: '^<.*\.h>' + Priority: 2 + - Regex: '^<.*' + Priority: 3 + - Regex: '.*' + Priority: 4 +IndentCaseLabels: true +IndentWidth: 4 +IndentWrappedFunctionNames: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +ReflowComments: true +SortIncludes: true +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 4 +UseTab: Never +... + @@ -1,12 +1,11 @@ #pragma once +#include "pid/ec/pid.hpp" + #include <map> #include <string> #include <vector> -#include "pid/ec/pid.hpp" - - /* * General sensor structure used for configuration. */ diff --git a/dbus/dbusactiveread.cpp b/dbus/dbusactiveread.cpp index e41ba7a..37a1f93 100644 --- a/dbus/dbusactiveread.cpp +++ b/dbus/dbusactiveread.cpp @@ -14,13 +14,13 @@ * limitations under the License. */ -#include <chrono> -#include <cmath> -#include <iostream> - #include "dbusactiveread.hpp" + #include "dbus/util.hpp" +#include <chrono> +#include <cmath> +#include <iostream> ReadReturn DbusActiveRead::read(void) { @@ -35,11 +35,7 @@ ReadReturn DbusActiveRead::read(void) * Technically it might not be a value from now, but there's no timestamp * on Sensor.Value yet. */ - struct ReadReturn r = { - value, - std::chrono::high_resolution_clock::now() - }; + struct ReadReturn r = {value, std::chrono::high_resolution_clock::now()}; return r; } - diff --git a/dbus/dbusactiveread.hpp b/dbus/dbusactiveread.hpp index 85380fb..b703006 100644 --- a/dbus/dbusactiveread.hpp +++ b/dbus/dbusactiveread.hpp @@ -1,35 +1,31 @@ #pragma once +#include "dbus/util.hpp" +#include "interfaces.hpp" + #include <memory> #include <sdbusplus/bus.hpp> #include <string> -#include "dbus/util.hpp" -#include "interfaces.hpp" - /* * This ReadInterface will actively reach out over dbus upon calling read to * get the value from whomever owns the associated dbus path. */ -class DbusActiveRead: public ReadInterface +class DbusActiveRead : public ReadInterface { - public: - DbusActiveRead(sdbusplus::bus::bus& bus, - const std::string& path, - const std::string& service, - DbusHelperInterface *helper) - : ReadInterface(), - _bus(bus), - _path(path), - _service(service), - _helper(helper) - { } + public: + DbusActiveRead(sdbusplus::bus::bus& bus, const std::string& path, + const std::string& service, DbusHelperInterface* helper) : + ReadInterface(), + _bus(bus), _path(path), _service(service), _helper(helper) + { + } - ReadReturn read(void) override; + ReadReturn read(void) override; - private: - sdbusplus::bus::bus& _bus; - const std::string _path; - const std::string _service; // the sensor service. - DbusHelperInterface *_helper; + private: + sdbusplus::bus::bus& _bus; + const std::string _path; + const std::string _service; // the sensor service. + DbusHelperInterface* _helper; }; diff --git a/dbus/dbuspassive.cpp b/dbus/dbuspassive.cpp index da9b387..e269b3d 100644 --- a/dbus/dbuspassive.cpp +++ b/dbus/dbuspassive.cpp @@ -13,6 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "dbuspassive.hpp" + +#include "dbus/util.hpp" + #include <chrono> #include <cmath> #include <memory> @@ -20,12 +24,9 @@ #include <sdbusplus/bus.hpp> #include <string> -#include "dbuspassive.hpp" -#include "dbus/util.hpp" - std::unique_ptr<ReadInterface> DbusPassive::CreateDbusPassive( - sdbusplus::bus::bus& bus, const std::string& type, - const std::string& id, DbusHelperInterface *helper) + sdbusplus::bus::bus& bus, const std::string& type, const std::string& id, + DbusHelperInterface* helper) { if (helper == nullptr) { @@ -39,16 +40,11 @@ std::unique_ptr<ReadInterface> DbusPassive::CreateDbusPassive( return std::make_unique<DbusPassive>(bus, type, id, helper); } -DbusPassive::DbusPassive( - sdbusplus::bus::bus& bus, - const std::string& type, - const std::string& id, - DbusHelperInterface *helper) - : ReadInterface(), - _bus(bus), - _signal(bus, GetMatch(type, id).c_str(), DbusHandleSignal, this), - _id(id), - _helper(helper) +DbusPassive::DbusPassive(sdbusplus::bus::bus& bus, const std::string& type, + const std::string& id, DbusHelperInterface* helper) : + ReadInterface(), + _bus(bus), _signal(bus, GetMatch(type, id).c_str(), DbusHandleSignal, this), + _id(id), _helper(helper) { /* Need to get the scale and initial value */ auto tempBus = sdbusplus::bus::new_default(); @@ -68,10 +64,7 @@ ReadReturn DbusPassive::read(void) { std::lock_guard<std::mutex> guard(_lock); - struct ReadReturn r = { - _value, - _updated - }; + struct ReadReturn r = {_value, _updated}; return r; } diff --git a/dbus/dbuspassive.hpp b/dbus/dbuspassive.hpp index 545b928..87315a0 100644 --- a/dbus/dbuspassive.hpp +++ b/dbus/dbuspassive.hpp @@ -1,23 +1,22 @@ #pragma once +#include "dbus/util.hpp" +#include "interfaces.hpp" + #include <chrono> #include <cmath> #include <iostream> #include <map> #include <memory> #include <mutex> +#include <sdbusplus/bus.hpp> +#include <sdbusplus/message.hpp> +#include <sdbusplus/server.hpp> #include <set> #include <string> #include <tuple> #include <vector> -#include <sdbusplus/bus.hpp> -#include <sdbusplus/message.hpp> -#include <sdbusplus/server.hpp> - -#include "interfaces.hpp" -#include "dbus/util.hpp" - int DbusHandleSignal(sd_bus_message* msg, void* data, sd_bus_error* err); /* @@ -33,33 +32,31 @@ int DbusHandleSignal(sd_bus_message* msg, void* data, sd_bus_error* err); */ class DbusPassive : public ReadInterface { - public: - static std::unique_ptr<ReadInterface> CreateDbusPassive( - sdbusplus::bus::bus& bus, const std::string& type, - const std::string& id, DbusHelperInterface *helper); - - DbusPassive(sdbusplus::bus::bus& bus, - const std::string& type, - const std::string& id, - DbusHelperInterface *helper); - - ReadReturn read(void) override; - - void setValue(double value); - int64_t getScale(void); - std::string getId(void); - - private: - sdbusplus::bus::bus& _bus; - sdbusplus::server::match::match _signal; - int64_t _scale; - std::string _id; // for debug identification - DbusHelperInterface *_helper; - - std::mutex _lock; - double _value = 0; - /* The last time the value was refreshed, not necessarily changed. */ - std::chrono::high_resolution_clock::time_point _updated; + public: + static std::unique_ptr<ReadInterface> + CreateDbusPassive(sdbusplus::bus::bus& bus, const std::string& type, + const std::string& id, DbusHelperInterface* helper); + + DbusPassive(sdbusplus::bus::bus& bus, const std::string& type, + const std::string& id, DbusHelperInterface* helper); + + ReadReturn read(void) override; + + void setValue(double value); + int64_t getScale(void); + std::string getId(void); + + private: + sdbusplus::bus::bus& _bus; + sdbusplus::server::match::match _signal; + int64_t _scale; + std::string _id; // for debug identification + DbusHelperInterface* _helper; + + std::mutex _lock; + double _value = 0; + /* The last time the value was refreshed, not necessarily changed. */ + std::chrono::high_resolution_clock::time_point _updated; }; int HandleSensorValue(sdbusplus::message::message& msg, DbusPassive* owner); diff --git a/dbus/dbuswrite.cpp b/dbus/dbuswrite.cpp index 4c045e5..b26b96e 100644 --- a/dbus/dbuswrite.cpp +++ b/dbus/dbuswrite.cpp @@ -14,7 +14,8 @@ // limitations under the License. */ -#include <dbus/dbuswrite.hpp> +#include "dbus/dbuswrite.hpp" + #include <iostream> #include <sdbusplus/bus.hpp> diff --git a/dbus/dbuswrite.hpp b/dbus/dbuswrite.hpp index 5beebb3..6733721 100644 --- a/dbus/dbuswrite.hpp +++ b/dbus/dbuswrite.hpp @@ -16,11 +16,11 @@ #pragma once -#include <string> +#include "dbus/util.hpp" +#include "interfaces.hpp" -#include <dbus/util.hpp> -#include <interfaces.hpp> #include <sdbusplus/bus.hpp> +#include <string> constexpr const char *pwmInterface = "xyz.openbmc_project.Control.FanPwm"; diff --git a/dbus/util.cpp b/dbus/util.cpp index ffdfe1f..f79bf4f 100644 --- a/dbus/util.cpp +++ b/dbus/util.cpp @@ -1,8 +1,8 @@ +#include "dbus/util.hpp" + #include <iostream> #include <set> -#include "dbus/util.hpp" - using Property = std::string; using Value = sdbusplus::message::variant<int64_t, double, std::string>; using PropertyMap = std::map<Property, Value>; @@ -14,11 +14,10 @@ std::string DbusHelper::GetService(sdbusplus::bus::bus& bus, const std::string& intf, const std::string& path) { - auto mapper = bus.new_method_call( - "xyz.openbmc_project.ObjectMapper", - "/xyz/openbmc_project/object_mapper", - "xyz.openbmc_project.ObjectMapper", - "GetObject"); + auto mapper = + bus.new_method_call("xyz.openbmc_project.ObjectMapper", + "/xyz/openbmc_project/object_mapper", + "xyz.openbmc_project.ObjectMapper", "GetObject"); mapper.append(path); mapper.append(std::vector<std::string>({intf})); @@ -45,10 +44,8 @@ void DbusHelper::GetProperties(sdbusplus::bus::bus& bus, const std::string& path, struct SensorProperties* prop) { - auto pimMsg = bus.new_method_call(service.c_str(), - path.c_str(), - propertiesintf.c_str(), - "GetAll"); + auto pimMsg = bus.new_method_call(service.c_str(), path.c_str(), + propertiesintf.c_str(), "GetAll"); pimMsg.append(sensorintf); auto valueResponseMsg = bus.call(pimMsg); @@ -116,7 +113,8 @@ std::string GetMatch(const std::string& type, const std::string& id) return std::string("type='signal'," "interface='org.freedesktop.DBus.Properties'," "member='PropertiesChanged'," - "path='" + GetSensorPath(type, id) + "'"); + "path='" + + GetSensorPath(type, id) + "'"); } bool ValidType(const std::string& type) diff --git a/dbus/util.hpp b/dbus/util.hpp index 5b1522f..e459524 100644 --- a/dbus/util.hpp +++ b/dbus/util.hpp @@ -14,46 +14,44 @@ const std::string propertiesintf = "org.freedesktop.DBus.Properties"; class DbusHelperInterface { - public: - virtual ~DbusHelperInterface() = default; + public: + virtual ~DbusHelperInterface() = default; - /** @brief Get the service providing the interface for the path. - */ - virtual std::string GetService(sdbusplus::bus::bus& bus, - const std::string& intf, - const std::string& path) = 0; + /** @brief Get the service providing the interface for the path. + */ + virtual std::string GetService(sdbusplus::bus::bus& bus, + const std::string& intf, + const std::string& path) = 0; - /** @brief Get all Sensor.Value properties for a service and path. - * - * @param[in] bus - A bus to use for the call. - * @param[in] service - The service providing the interface. - * @param[in] path - The dbus path. - * @param[out] prop - A pointer to a properties struct to fill out. - */ - virtual void GetProperties(sdbusplus::bus::bus& bus, - const std::string& service, - const std::string& path, - struct SensorProperties* prop) = 0; + /** @brief Get all Sensor.Value properties for a service and path. + * + * @param[in] bus - A bus to use for the call. + * @param[in] service - The service providing the interface. + * @param[in] path - The dbus path. + * @param[out] prop - A pointer to a properties struct to fill out. + */ + virtual void GetProperties(sdbusplus::bus::bus& bus, + const std::string& service, + const std::string& path, + struct SensorProperties* prop) = 0; }; class DbusHelper : public DbusHelperInterface { - public: - DbusHelper() = default; - ~DbusHelper() = default; - DbusHelper(const DbusHelper&) = default; - DbusHelper& operator=(const DbusHelper&) = default; - DbusHelper(DbusHelper&&) = default; - DbusHelper& operator=(DbusHelper&&) = default; + public: + DbusHelper() = default; + ~DbusHelper() = default; + DbusHelper(const DbusHelper&) = default; + DbusHelper& operator=(const DbusHelper&) = default; + DbusHelper(DbusHelper&&) = default; + DbusHelper& operator=(DbusHelper&&) = default; - std::string GetService(sdbusplus::bus::bus& bus, - const std::string& intf, - const std::string& path) override; + std::string GetService(sdbusplus::bus::bus& bus, const std::string& intf, + const std::string& path) override; - void GetProperties(sdbusplus::bus::bus& bus, - const std::string& service, - const std::string& path, - struct SensorProperties* prop) override; + void GetProperties(sdbusplus::bus::bus& bus, const std::string& service, + const std::string& path, + struct SensorProperties* prop) override; }; std::string GetSensorPath(const std::string& type, const std::string& id); @@ -64,14 +62,14 @@ struct VariantToFloatVisitor { template <typename T> std::enable_if_t<std::is_arithmetic<T>::value, float> - operator()(const T &t) const + operator()(const T& t) const { return static_cast<float>(t); } template <typename T> std::enable_if_t<!std::is_arithmetic<T>::value, float> - operator()(const T &t) const + operator()(const T& t) const { throw std::invalid_argument("Cannot translate type to float"); } @@ -81,14 +79,14 @@ struct VariantToDoubleVisitor { template <typename T> std::enable_if_t<std::is_arithmetic<T>::value, double> - operator()(const T &t) const + operator()(const T& t) const { return static_cast<double>(t); } template <typename T> std::enable_if_t<!std::is_arithmetic<T>::value, double> - operator()(const T &t) const + operator()(const T& t) const { throw std::invalid_argument("Cannot translate type to double"); } diff --git a/experiments/drive.cpp b/experiments/drive.cpp index a6fbd9c..d73148a 100644 --- a/experiments/drive.cpp +++ b/experiments/drive.cpp @@ -14,16 +14,16 @@ * limitations under the License. */ -#include <iostream> -#include <memory> -#include <tuple> - #include "drive.hpp" #include "interfaces.hpp" #include "sensors/pluggable.hpp" -#include "sysfs/sysfswrite.hpp" #include "sysfs/sysfsread.hpp" +#include "sysfs/sysfswrite.hpp" + +#include <iostream> +#include <memory> +#include <tuple> using tstamp = std::chrono::high_resolution_clock::time_point; @@ -32,15 +32,13 @@ using tstamp = std::chrono::high_resolution_clock::time_point; #define DRIVE DRIVE_TIME #define MAX_PWM 255 -static std::unique_ptr<Sensor> Create( - std::string readpath, - std::string writepath) +static std::unique_ptr<Sensor> Create(std::string readpath, + std::string writepath) { return std::make_unique<PluggableSensor>( - readpath, - 0, /* default the timeout to disabled */ - std::make_unique<SysFsRead>(readpath), - std::make_unique<SysFsWrite>(writepath, 0, MAX_PWM)); + readpath, 0, /* default the timeout to disabled */ + std::make_unique<SysFsRead>(readpath), + std::make_unique<SysFsWrite>(writepath, 0, MAX_PWM)); } int64_t getAverage(std::tuple<tstamp, int64_t, int64_t>& values) @@ -68,12 +66,9 @@ bool valueClose(int64_t value, int64_t goal) return false; } -static void driveGoal( - int64_t& seriesCnt, - int64_t setPwm, - int64_t goal, - std::vector<std::tuple<tstamp, int64_t, int64_t>>& series, - std::vector<std::unique_ptr<Sensor>>& fanSensors) +static void driveGoal(int64_t& seriesCnt, int64_t setPwm, int64_t goal, + std::vector<std::tuple<tstamp, int64_t, int64_t>>& series, + std::vector<std::unique_ptr<Sensor>>& fanSensors) { bool reading = true; @@ -132,12 +127,9 @@ static void driveGoal( return; } -static void driveTime( - int64_t& seriesCnt, - int64_t setPwm, - int64_t goal, - std::vector<std::tuple<tstamp, int64_t, int64_t>>& series, - std::vector<std::unique_ptr<Sensor>>& fanSensors) +static void driveTime(int64_t& seriesCnt, int64_t setPwm, int64_t goal, + std::vector<std::tuple<tstamp, int64_t, int64_t>>& series, + std::vector<std::unique_ptr<Sensor>>& fanSensors) { using namespace std::literals::chrono_literals; @@ -162,8 +154,9 @@ static void driveTime( series.push_back(std::make_tuple(t1, n0, n1)); - auto duration = std::chrono::duration_cast<std::chrono::microseconds> - (t1 - t0).count(); + auto duration = + std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0) + .count(); if (duration >= (20000000us).count()) { reading = false; @@ -175,7 +168,8 @@ static void driveTime( int driveMain(void) { - /* Time series of the data, the timestamp after both are read and the values. */ + /* Time series of the data, the timestamp after both are read and the + * values. */ std::vector<std::tuple<tstamp, int64_t, int64_t>> series; int64_t seriesCnt = 0; /* in case vector count isn't constant time */ int drive = DRIVE; @@ -187,17 +181,11 @@ int driveMain(void) * --> 2 | 6 * --> 3 | 7 */ - std::vector<std::string> fans = - { - "/sys/class/hwmon/hwmon0/fan0_input", - "/sys/class/hwmon/hwmon0/fan4_input" - }; + std::vector<std::string> fans = {"/sys/class/hwmon/hwmon0/fan0_input", + "/sys/class/hwmon/hwmon0/fan4_input"}; - std::vector<std::string> pwms = - { - "/sys/class/hwmon/hwmon0/pwm0", - "/sys/class/hwmon/hwmon0/pwm4" - }; + std::vector<std::string> pwms = {"/sys/class/hwmon/hwmon0/pwm0", + "/sys/class/hwmon/hwmon0/pwm4"}; std::vector<std::unique_ptr<Sensor>> fanSensors; @@ -261,8 +249,9 @@ int driveMain(void) int64_t n0 = std::get<1>(t); int64_t n1 = std::get<2>(t); - auto duration = std::chrono::duration_cast<std::chrono::microseconds> - (ts - tp).count(); + auto duration = + std::chrono::duration_cast<std::chrono::microseconds>(ts - tp) + .count(); std::cout << duration << "us, " << n0 << ", " << n1 << "\n"; tp = ts; @@ -270,4 +259,3 @@ int driveMain(void) return 0; } - diff --git a/interfaces.hpp b/interfaces.hpp index c16d19e..1ebd1cb 100644 --- a/interfaces.hpp +++ b/interfaces.hpp @@ -2,29 +2,33 @@ #include <chrono> - -struct ReadReturn { +struct ReadReturn +{ double value; std::chrono::high_resolution_clock::time_point updated; - bool operator==(const ReadReturn &rhs) const { + bool operator==(const ReadReturn &rhs) const + { return (this->value == rhs.value && this->updated == rhs.updated); } }; - /* * A ReadInterface is a plug-in for the PluggableSensor and anyone implementing * this basically is providing a way to read a sensor. */ class ReadInterface { - public: - ReadInterface() { } + public: + ReadInterface() + { + } - virtual ~ReadInterface() { } + virtual ~ReadInterface() + { + } - virtual ReadReturn read(void) = 0; + virtual ReadReturn read(void) = 0; }; /* @@ -33,29 +37,31 @@ class ReadInterface */ class WriteInterface { - public: - WriteInterface(int64_t min, int64_t max) - : _min(min), - _max(max) - { } - - virtual ~WriteInterface() { } - - virtual void write(double value) = 0; - - /* - * All WriteInterfaces have min/max available in case they want to error - * check. - */ - int64_t getMin(void) - { - return _min; - } - int64_t getMax(void) - { - return _max; - } - private: - int64_t _min; - int64_t _max; + public: + WriteInterface(int64_t min, int64_t max) : _min(min), _max(max) + { + } + + virtual ~WriteInterface() + { + } + + virtual void write(double value) = 0; + + /* + * All WriteInterfaces have min/max available in case they want to error + * check. + */ + int64_t getMin(void) + { + return _min; + } + int64_t getMax(void) + { + return _max; + } + + private: + int64_t _min; + int64_t _max; }; diff --git a/ipmi/manualcmds.cpp b/ipmi/manualcmds.cpp index f86db9e..eabcd0a 100644 --- a/ipmi/manualcmds.cpp +++ b/ipmi/manualcmds.cpp @@ -16,16 +16,16 @@ //#include <stdint.h> -#include <map> -#include <string> -#include <tuple> +#include "host-ipmid/oemopenbmc.hpp" +#include "host-ipmid/oemrouter.hpp" +#include <map> #include <sdbusplus/bus.hpp> #include <sdbusplus/message.hpp> +#include <string> +#include <tuple> #include "host-ipmid/ipmid-api.h" -#include "host-ipmid/oemopenbmc.hpp" -#include "host-ipmid/oemrouter.hpp" enum ManualSubCmd { @@ -34,12 +34,14 @@ enum ManualSubCmd GET_FAILSAFE_STATE = 2, }; -struct FanCtrlRequest { +struct FanCtrlRequest +{ uint8_t command; uint8_t zone; } __attribute__((packed)); -struct FanCtrlRequestSet { +struct FanCtrlRequestSet +{ uint8_t command; uint8_t zone; uint8_t value; @@ -72,16 +74,14 @@ static std::string GetControlPath(int8_t zone) * a{sv} 2 "Manual" b false "FailSafe" b false */ -static ipmi_ret_t -GetFanCtrlProperty(uint8_t zoneId, bool *value, const std::string &property) +static ipmi_ret_t GetFanCtrlProperty(uint8_t zoneId, bool* value, + const std::string& property) { std::string path = GetControlPath(zoneId); auto propertyReadBus = sdbusplus::bus::new_default(); - auto pimMsg = propertyReadBus.new_method_call(busName, - path.c_str(), - propertiesintf, - "GetAll"); + auto pimMsg = propertyReadBus.new_method_call(busName, path.c_str(), + propertiesintf, "GetAll"); pimMsg.append(intf); auto valueResponseMsg = propertyReadBus.call(pimMsg); @@ -103,8 +103,8 @@ GetFanCtrlProperty(uint8_t zoneId, bool *value, const std::string &property) return IPMI_CC_OK; } -static ipmi_ret_t -GetFailsafeModeState(const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen) +static ipmi_ret_t GetFailsafeModeState(const uint8_t* reqBuf, uint8_t* replyBuf, + size_t* dataLen) { ipmi_ret_t rc = IPMI_CC_OK; bool current; @@ -115,7 +115,7 @@ GetFailsafeModeState(const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen) } const auto request = - reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]); + reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]); rc = GetFanCtrlProperty(request->zone, ¤t, failsafeProperty); if (rc) @@ -134,8 +134,8 @@ GetFailsafeModeState(const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen) * <arg name="properties" direction="out" type="a{sv}"/> * </method> */ -static ipmi_ret_t -GetManualModeState(const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen) +static ipmi_ret_t GetManualModeState(const uint8_t* reqBuf, uint8_t* replyBuf, + size_t* dataLen) { ipmi_ret_t rc = IPMI_CC_OK; bool current; @@ -146,7 +146,7 @@ GetManualModeState(const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen) } const auto request = - reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]); + reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]); rc = GetFanCtrlProperty(request->zone, ¤t, manualProperty); if (rc) @@ -166,8 +166,8 @@ GetManualModeState(const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen) * <arg name="value" direction="in" type="v"/> * </method> */ -static ipmi_ret_t -SetManualModeState(const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen) +static ipmi_ret_t SetManualModeState(const uint8_t* reqBuf, uint8_t* replyBuf, + size_t* dataLen) { ipmi_ret_t rc = IPMI_CC_OK; if (*dataLen < sizeof(struct FanCtrlRequestSet)) @@ -178,20 +178,18 @@ SetManualModeState(const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen) using Value = sdbusplus::message::variant<bool>; const auto request = - reinterpret_cast<const struct FanCtrlRequestSet*>(&reqBuf[0]); + reinterpret_cast<const struct FanCtrlRequestSet*>(&reqBuf[0]); /* 0 is false, 1 is true */ bool setValue = static_cast<bool>(request->value); - Value v {setValue}; + Value v{setValue}; auto PropertyWriteBus = sdbusplus::bus::new_default(); std::string path = GetControlPath(request->zone); - auto pimMsg = PropertyWriteBus.new_method_call(busName, - path.c_str(), - propertiesintf, - "Set"); + auto pimMsg = PropertyWriteBus.new_method_call(busName, path.c_str(), + propertiesintf, "Set"); pimMsg.append(intf); pimMsg.append(manualProperty); pimMsg.append(v); @@ -206,12 +204,8 @@ SetManualModeState(const uint8_t* reqBuf, uint8_t* replyBuf, size_t* dataLen) } /* Three command packages: get, set true, set false */ -static ipmi_ret_t -ManualModeControl( - ipmi_cmd_t cmd, - const uint8_t* reqBuf, - uint8_t* replyCmdBuf, - size_t* dataLen) +static ipmi_ret_t ManualModeControl(ipmi_cmd_t cmd, const uint8_t* reqBuf, + uint8_t* replyCmdBuf, size_t* dataLen) { ipmi_ret_t rc = IPMI_CC_OK; // FanCtrlRequest is the smaller of the requests, so it's at a minimum. @@ -221,7 +215,7 @@ ManualModeControl( } const auto request = - reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]); + reinterpret_cast<const struct FanCtrlRequest*>(&reqBuf[0]); switch (request->command) { @@ -246,11 +240,8 @@ void setupGlobalOemFanControl() fprintf(stderr, "Registering OEM:[%#08X], Cmd:[%#04X] for Manual Zone Control\n", - oem::obmcOemNumber, - oem::Cmd::fanManualCmd); + oem::obmcOemNumber, oem::Cmd::fanManualCmd); - router->registerHandler( - oem::obmcOemNumber, - oem::Cmd::fanManualCmd, - ManualModeControl); + router->registerHandler(oem::obmcOemNumber, oem::Cmd::fanManualCmd, + ManualModeControl); } diff --git a/ipmi/manualcmds.hpp b/ipmi/manualcmds.hpp index 3f59c93..6f70f09 100644 --- a/ipmi/manualcmds.hpp +++ b/ipmi/manualcmds.hpp @@ -1,2 +1 @@ #pragma once - @@ -14,40 +14,33 @@ * limitations under the License. */ -#include <chrono> -#include <experimental/any> -#include <getopt.h> -#include <iostream> -#include <map> -#include <memory> -#include <mutex> /* not yet used. */ -#include <thread> -#include <unordered_map> -#include <vector> - -#include <sdbusplus/bus.hpp> - -/* Configuration. */ -#include "conf.hpp" #include "config.h" -#include <dbus/dbusconfiguration.hpp> -/* Misc. */ -#include "util.hpp" - -/* Controllers & Sensors. */ +#include "conf.hpp" +#include "dbus/dbusconfiguration.hpp" #include "interfaces.hpp" #include "pid/builder.hpp" #include "pid/builderconfig.hpp" +#include "pid/pidthread.hpp" #include "pid/zone.hpp" #include "sensors/builder.hpp" #include "sensors/builderconfig.hpp" #include "sensors/manager.hpp" - -/* Threads. */ -#include "pid/pidthread.hpp" #include "threads/busthread.hpp" +#include "util.hpp" +#include <getopt.h> + +#include <chrono> +#include <experimental/any> +#include <iostream> +#include <map> +#include <memory> +#include <mutex> /* not yet used. */ +#include <sdbusplus/bus.hpp> +#include <thread> +#include <unordered_map> +#include <vector> /* The YAML converted sensor list. */ extern std::map<std::string, struct sensor> SensorConfig; @@ -64,11 +57,12 @@ int main(int argc, char* argv[]) while (1) { - static struct option long_options[] = - { + // clang-format off + static struct option long_options[] = { {"conf", required_argument, 0, 'c'}, {0, 0, 0, 0} }; + // clang-format on int option_index = 0; c = getopt_long(argc, argv, "c:", long_options, &option_index); @@ -81,7 +75,7 @@ int main(int argc, char* argv[]) switch (c) { case 'c': - configPath = std::string {optarg}; + configPath = std::string{optarg}; break; default: /* skip garbage. */ @@ -141,28 +135,16 @@ int main(int argc, char* argv[]) std::cerr << "Starting threads\n"; /* TODO(venture): Ask SensorManager if we have any passive sensors. */ - struct ThreadParams p = - { - std::ref(PassiveListeningBus), - "" - }; + struct ThreadParams p = {std::ref(PassiveListeningBus), ""}; std::thread l(BusThread, std::ref(p)); /* TODO(venture): Ask SensorManager if we have any host sensors. */ static constexpr auto hostBus = "xyz.openbmc_project.Hwmon.external"; - struct ThreadParams e = - { - std::ref(HostSensorBus), - hostBus - }; + struct ThreadParams e = {std::ref(HostSensorBus), hostBus}; std::thread te(BusThread, std::ref(e)); static constexpr auto modeBus = "xyz.openbmc_project.State.FanCtrl"; - struct ThreadParams m = - { - std::ref(ModeControlBus), - modeBus - }; + struct ThreadParams m = {std::ref(ModeControlBus), modeBus}; std::thread tm(BusThread, std::ref(m)); std::vector<std::thread> zoneThreads; @@ -189,4 +171,3 @@ int main(int argc, char* argv[]) return rc; } - diff --git a/notimpl/readonly.cpp b/notimpl/readonly.cpp index f6ddad3..1ae2b30 100644 --- a/notimpl/readonly.cpp +++ b/notimpl/readonly.cpp @@ -14,10 +14,9 @@ * limitations under the License. */ -#include <stdexcept> - #include "readonly.hpp" +#include <stdexcept> void ReadOnly::write(double value) { diff --git a/notimpl/readonly.hpp b/notimpl/readonly.hpp index a609e22..2929b75 100644 --- a/notimpl/readonly.hpp +++ b/notimpl/readonly.hpp @@ -4,23 +4,22 @@ #include "interfaces.hpp" - -class ReadOnly: public WriteInterface +class ReadOnly : public WriteInterface { - public: - ReadOnly() - : WriteInterface(0, 0) - { } + public: + ReadOnly() : WriteInterface(0, 0) + { + } - void write(double value) override; + void write(double value) override; }; -class ReadOnlyNoExcept: public WriteInterface +class ReadOnlyNoExcept : public WriteInterface { - public: - ReadOnlyNoExcept() - : WriteInterface(0, 0) - { } + public: + ReadOnlyNoExcept() : WriteInterface(0, 0) + { + } - void write(double value) override; + void write(double value) override; }; diff --git a/notimpl/writeonly.cpp b/notimpl/writeonly.cpp index a465ecf..9fc99fd 100644 --- a/notimpl/writeonly.cpp +++ b/notimpl/writeonly.cpp @@ -14,13 +14,11 @@ * limitations under the License. */ -#include <stdexcept> - #include "writeonly.hpp" +#include <stdexcept> ReadReturn WriteOnly::read(void) { throw std::runtime_error("Not supported."); } - diff --git a/notimpl/writeonly.hpp b/notimpl/writeonly.hpp index 4c26fbd..6dc7afd 100644 --- a/notimpl/writeonly.hpp +++ b/notimpl/writeonly.hpp @@ -3,13 +3,12 @@ #include "interfaces.hpp" - -class WriteOnly: public ReadInterface +class WriteOnly : public ReadInterface { - public: - WriteOnly() - : ReadInterface() - { } + public: + WriteOnly() : ReadInterface() + { + } - ReadReturn read(void) override; + ReadReturn read(void) override; }; diff --git a/pid/builder.cpp b/pid/builder.cpp index 45838e7..8ffa77c 100644 --- a/pid/builder.cpp +++ b/pid/builder.cpp @@ -16,15 +16,15 @@ #include "pid/builder.hpp" +#include "conf.hpp" +#include "pid/fancontroller.hpp" +#include "pid/thermalcontroller.hpp" + #include <iostream> #include <memory> #include <sdbusplus/bus.hpp> #include <unordered_map> -#include "conf.hpp" -#include "pid/fancontroller.hpp" -#include "pid/thermalcontroller.hpp" - static constexpr bool deferSignals = true; static constexpr auto objectPath = "/xyz/openbmc_project/settings/fanctrl/zone"; @@ -33,11 +33,10 @@ static std::string GetControlPath(int64_t zone) return std::string(objectPath) + std::to_string(zone); } -std::unordered_map<int64_t, std::unique_ptr<PIDZone>> BuildZones( - std::map<int64_t, PIDConf>& zonePids, - std::map<int64_t, struct zone>& zoneConfigs, - SensorManager& mgr, - sdbusplus::bus::bus& modeControlBus) +std::unordered_map<int64_t, std::unique_ptr<PIDZone>> + BuildZones(std::map<int64_t, PIDConf>& zonePids, + std::map<int64_t, struct zone>& zoneConfigs, SensorManager& mgr, + sdbusplus::bus::bus& modeControlBus) { std::unordered_map<int64_t, std::unique_ptr<PIDZone>> zones; @@ -62,13 +61,9 @@ std::unordered_map<int64_t, std::unique_ptr<PIDZone>> BuildZones( PIDConf& PIDConfig = zi.second; auto zone = std::make_unique<PIDZone>( - zoneId, - zoneConf->second.minthermalrpm, - zoneConf->second.failsafepercent, - mgr, - modeControlBus, - GetControlPath(zi.first).c_str(), - deferSignals); + zoneId, zoneConf->second.minthermalrpm, + zoneConf->second.failsafepercent, mgr, modeControlBus, + GetControlPath(zi.first).c_str(), deferSignals); std::cerr << "Zone Id: " << zone->getZoneId() << "\n"; @@ -93,11 +88,8 @@ std::unordered_map<int64_t, std::unique_ptr<PIDZone>> BuildZones( zone->addFanInput(i); } - auto pid = FanController::CreateFanPid( - zone.get(), - name, - inputs, - info->info); + auto pid = FanController::CreateFanPid(zone.get(), name, inputs, + info->info); zone->addFanPID(std::move(pid)); } else if (info->type == "temp" || info->type == "margin") @@ -109,11 +101,7 @@ std::unordered_map<int64_t, std::unique_ptr<PIDZone>> BuildZones( } auto pid = ThermalController::CreateThermalPid( - zone.get(), - name, - inputs, - info->setpoint, - info->info); + zone.get(), name, inputs, info->setpoint, info->info); zone->addThermalPID(std::move(pid)); } diff --git a/pid/builder.hpp b/pid/builder.hpp index 5c03bd1..9201b9a 100644 --- a/pid/builder.hpp +++ b/pid/builder.hpp @@ -1,14 +1,13 @@ #pragma once +#include "pid/zone.hpp" +#include "sensors/manager.hpp" + #include <memory> #include <sdbusplus/bus.hpp> #include <unordered_map> -#include "pid/zone.hpp" -#include "sensors/manager.hpp" - -std::unordered_map<int64_t, std::unique_ptr<PIDZone>> BuildZones( - std::map<int64_t, PIDConf>& zonePids, - std::map<int64_t, struct zone>& zoneConfigs, - SensorManager& mgr, - sdbusplus::bus::bus& modeControlBus); +std::unordered_map<int64_t, std::unique_ptr<PIDZone>> + BuildZones(std::map<int64_t, PIDConf>& zonePids, + std::map<int64_t, struct zone>& zoneConfigs, SensorManager& mgr, + sdbusplus::bus::bus& modeControlBus); diff --git a/pid/builderconfig.cpp b/pid/builderconfig.cpp index 33301e2..0106057 100644 --- a/pid/builderconfig.cpp +++ b/pid/builderconfig.cpp @@ -16,6 +16,9 @@ #include "pid/builderconfig.hpp" +#include "conf.hpp" +#include "pid/builder.hpp" + #include <fstream> #include <iostream> #include <libconfig.h++> @@ -24,13 +27,9 @@ #include <string> #include <unordered_map> -#include "conf.hpp" -#include "pid/builder.hpp" - -std::unordered_map<int64_t, std::unique_ptr<PIDZone>> BuildZonesFromConfig( - const std::string& path, - SensorManager& mgr, - sdbusplus::bus::bus& modeControlBus) +std::unordered_map<int64_t, std::unique_ptr<PIDZone>> + BuildZonesFromConfig(const std::string& path, SensorManager& mgr, + sdbusplus::bus::bus& modeControlBus) { using namespace libconfig; // zone -> pids @@ -77,10 +76,9 @@ std::unordered_map<int64_t, std::unique_ptr<PIDZone>> BuildZonesFromConfig( zoneSettings.lookupValue("id", id); - thisZoneConfig.minthermalrpm = - zoneSettings.lookup("minthermalrpm"); + thisZoneConfig.minthermalrpm = zoneSettings.lookup("minthermalrpm"); thisZoneConfig.failsafepercent = - zoneSettings.lookup("failsafepercent"); + zoneSettings.lookup("failsafepercent"); const Setting& pids = zoneSettings["pids"]; int pidCount = pids.getLength(); @@ -136,7 +134,7 @@ std::unordered_map<int64_t, std::unique_ptr<PIDZone>> BuildZonesFromConfig( zoneConfig[static_cast<int64_t>(id)] = thisZoneConfig; } } - catch (const SettingTypeException &setex) + catch (const SettingTypeException& setex) { std::cerr << "Setting '" << setex.getPath() << "' type exception!" << std::endl; diff --git a/pid/builderconfig.hpp b/pid/builderconfig.hpp index ad83932..a7f41f8 100644 --- a/pid/builderconfig.hpp +++ b/pid/builderconfig.hpp @@ -1,14 +1,13 @@ #pragma once +#include "pid/zone.hpp" +#include "sensors/manager.hpp" + #include <memory> #include <sdbusplus/bus.hpp> #include <string> #include <unordered_map> -#include "pid/zone.hpp" -#include "sensors/manager.hpp" - -std::unordered_map<int64_t, std::unique_ptr<PIDZone>> BuildZonesFromConfig( - const std::string& path, - SensorManager& mgr, - sdbusplus::bus::bus& modeControlBus); +std::unordered_map<int64_t, std::unique_ptr<PIDZone>> + BuildZonesFromConfig(const std::string& path, SensorManager& mgr, + sdbusplus::bus::bus& modeControlBus); diff --git a/pid/controller.cpp b/pid/controller.cpp index a5360fe..138268b 100644 --- a/pid/controller.cpp +++ b/pid/controller.cpp @@ -14,6 +14,10 @@ * limitations under the License. */ +#include "controller.hpp" + +#include "ec/pid.hpp" + #include <algorithm> #include <chrono> #include <iostream> @@ -22,10 +26,6 @@ #include <thread> #include <vector> -#include "controller.hpp" -#include "ec/pid.hpp" - - void PIDController::pid_process(void) { float input; diff --git a/pid/controller.hpp b/pid/controller.hpp index 4220e07..57ee43f 100644 --- a/pid/controller.hpp +++ b/pid/controller.hpp @@ -1,11 +1,11 @@ #pragma once +#include "ec/pid.hpp" +#include "fan.hpp" + #include <memory> #include <vector> -#include "fan.hpp" -#include "ec/pid.hpp" - class ZoneInterface; /* @@ -14,46 +14,46 @@ class ZoneInterface; */ class PIDController { - public: - PIDController(const std::string& id, ZoneInterface* owner) - : _owner(owner), - _setpoint(0), - _id(id) - { } - - virtual ~PIDController() { } - - virtual float input_proc(void) = 0; - virtual float setpt_proc(void) = 0; - virtual void output_proc(float value) = 0; - - void pid_process(void); - - std::string get_id(void) - { - return _id; - } - float get_setpoint(void) - { - return _setpoint; - } - void set_setpoint(float setpoint) - { - _setpoint = setpoint; - } - - ec::pid_info_t* get_pid_info(void) - { - return &_pid_info; - } - - protected: - ZoneInterface* _owner; - - private: - // parameters - ec::pid_info_t _pid_info; - float _setpoint; - std::string _id; + public: + PIDController(const std::string& id, ZoneInterface* owner) : + _owner(owner), _setpoint(0), _id(id) + { + } + + virtual ~PIDController() + { + } + + virtual float input_proc(void) = 0; + virtual float setpt_proc(void) = 0; + virtual void output_proc(float value) = 0; + + void pid_process(void); + + std::string get_id(void) + { + return _id; + } + float get_setpoint(void) + { + return _setpoint; + } + void set_setpoint(float setpoint) + { + _setpoint = setpoint; + } + + ec::pid_info_t* get_pid_info(void) + { + return &_pid_info; + } + + protected: + ZoneInterface* _owner; + + private: + // parameters + ec::pid_info_t _pid_info; + float _setpoint; + std::string _id; }; - diff --git a/pid/ec/pid.cpp b/pid/ec/pid.cpp index a1c4e41..ef0df14 100644 --- a/pid/ec/pid.cpp +++ b/pid/ec/pid.cpp @@ -53,15 +53,15 @@ float pid(pid_info_t* pidinfoptr, float input, float setpoint) // calculate P, I, D, FF // Pid - error = setpoint - input; - p_term = pidinfoptr->p_c * error; + error = setpoint - input; + p_term = pidinfoptr->p_c * error; // pId if (0.0f != pidinfoptr->i_c) { - i_term = pidinfoptr->integral; - i_term += error * pidinfoptr->i_c * pidinfoptr->ts; - i_term = clamp(i_term, pidinfoptr->i_lim.min, pidinfoptr->i_lim.max); + i_term = pidinfoptr->integral; + i_term += error * pidinfoptr->i_c * pidinfoptr->ts; + i_term = clamp(i_term, pidinfoptr->i_lim.min, pidinfoptr->i_lim.max); } // FF @@ -79,8 +79,8 @@ float pid(pid_info_t* pidinfoptr, float input, float setpoint) if (pidinfoptr->slew_neg != 0.0f) { // Don't decrease too fast - float min_out = pidinfoptr->last_output + pidinfoptr->slew_neg * - pidinfoptr->ts; + float min_out = + pidinfoptr->last_output + pidinfoptr->slew_neg * pidinfoptr->ts; if (output < min_out) { output = min_out; @@ -89,8 +89,8 @@ float pid(pid_info_t* pidinfoptr, float input, float setpoint) if (pidinfoptr->slew_pos != 0.0f) { // Don't increase too fast - float max_out = pidinfoptr->last_output + pidinfoptr->slew_pos * - pidinfoptr->ts; + float max_out = + pidinfoptr->last_output + pidinfoptr->slew_pos * pidinfoptr->ts; if (output > max_out) { output = max_out; @@ -107,12 +107,12 @@ float pid(pid_info_t* pidinfoptr, float input, float setpoint) // Clamp again because having limited the output may result in a // larger integral term - i_term = clamp(i_term, pidinfoptr->i_lim.min, pidinfoptr->i_lim.max); + i_term = clamp(i_term, pidinfoptr->i_lim.min, pidinfoptr->i_lim.max); pidinfoptr->integral = i_term; - pidinfoptr->initialized = true; - pidinfoptr->last_output = output; + pidinfoptr->initialized = true; + pidinfoptr->last_output = output; return output; } -} +} // namespace ec diff --git a/pid/ec/pid.hpp b/pid/ec/pid.hpp index e138933..6b1030a 100644 --- a/pid/ec/pid.hpp +++ b/pid/ec/pid.hpp @@ -7,8 +7,8 @@ namespace ec typedef struct { - float min; - float max; + float min; + float max; } limits_t; /* Note: If you update these structs you need to update the copy code in @@ -16,21 +16,21 @@ typedef struct */ typedef struct { - bool initialized; // has pid been initialized + bool initialized; // has pid been initialized - float ts; // sample time in seconds - float integral; // intergal of error - float last_output; // value of last output + float ts; // sample time in seconds + float integral; // intergal of error + float last_output; // value of last output - float p_c; // coeff for P - float i_c; // coeff for I - float ff_off; // offset coeff for feed-forward term - float ff_gain; // gain for feed-forward term + float p_c; // coeff for P + float i_c; // coeff for I + float ff_off; // offset coeff for feed-forward term + float ff_gain; // gain for feed-forward term - limits_t i_lim; // clamp of integral - limits_t out_lim; // clamp of output - float slew_neg; - float slew_pos; + limits_t i_lim; // clamp of integral + limits_t out_lim; // clamp of output + float slew_neg; + float slew_pos; } pid_info_t; float pid(pid_info_t* pidinfoptr, float input, float setpoint); @@ -38,16 +38,15 @@ float pid(pid_info_t* pidinfoptr, float input, float setpoint); /* Condensed version for use by the configuration. */ struct pidinfo { - float ts; // sample time in seconds - float p_c; // coeff for P - float i_c; // coeff for I - float ff_off; // offset coeff for feed-forward term - float ff_gain; // gain for feed-forward term - ec::limits_t i_lim; // clamp of integral - ec::limits_t out_lim; // clamp of output - float slew_neg; - float slew_pos; + float ts; // sample time in seconds + float p_c; // coeff for P + float i_c; // coeff for I + float ff_off; // offset coeff for feed-forward term + float ff_gain; // gain for feed-forward term + ec::limits_t i_lim; // clamp of integral + ec::limits_t out_lim; // clamp of output + float slew_neg; + float slew_pos; }; - -} +} // namespace ec diff --git a/pid/fancontroller.cpp b/pid/fancontroller.cpp index 9407689..4a94458 100644 --- a/pid/fancontroller.cpp +++ b/pid/fancontroller.cpp @@ -14,18 +14,18 @@ * limitations under the License. */ -#include <algorithm> -#include <iostream> - #include "fancontroller.hpp" + #include "util.hpp" #include "zone.hpp" -std::unique_ptr<PIDController> FanController::CreateFanPid( - ZoneInterface* owner, - const std::string& id, - std::vector<std::string>& inputs, - ec::pidinfo initial) +#include <algorithm> +#include <iostream> + +std::unique_ptr<PIDController> + FanController::CreateFanPid(ZoneInterface* owner, const std::string& id, + std::vector<std::string>& inputs, + ec::pidinfo initial) { if (inputs.size() == 0) { @@ -79,7 +79,7 @@ float FanController::input_proc(void) /* When this is a configuration option in a later update, this code * will be updated. */ - //value = sum / _inputs.size(); + // value = sum / _inputs.size(); /* the fan PID algorithm was unstable with average, and seemed to work * better with minimum. I had considered making this choice a variable @@ -145,4 +145,3 @@ void FanController::output_proc(float value) return; } - diff --git a/pid/fancontroller.hpp b/pid/fancontroller.hpp index 3354bb6..aaccd4b 100644 --- a/pid/fancontroller.hpp +++ b/pid/fancontroller.hpp @@ -1,13 +1,12 @@ #pragma once -#include <memory> -#include <string> -#include <vector> - #include "controller.hpp" -#include "fan.hpp" #include "ec/pid.hpp" +#include "fan.hpp" +#include <memory> +#include <string> +#include <vector> /* * A FanController is a PID controller that reads a number of fans and given @@ -16,36 +15,33 @@ */ class FanController : public PIDController { - public: - static std::unique_ptr<PIDController> CreateFanPid( - ZoneInterface* owner, - const std::string& id, - std::vector<std::string>& inputs, - ec::pidinfo initial); - - FanController(const std::string& id, - std::vector<std::string>& inputs, - ZoneInterface* owner) - : PIDController(id, owner), - _inputs(inputs), - _direction(FanSpeedDirection::NEUTRAL) - { } - - float input_proc(void) override; - float setpt_proc(void) override; - void output_proc(float value) override; - - FanSpeedDirection getFanDirection(void) const - { - return _direction; - } - - void setFanDirection(FanSpeedDirection direction) - { - _direction = direction; - }; - - private: - std::vector<std::string> _inputs; - FanSpeedDirection _direction; + public: + static std::unique_ptr<PIDController> + CreateFanPid(ZoneInterface* owner, const std::string& id, + std::vector<std::string>& inputs, ec::pidinfo initial); + + FanController(const std::string& id, std::vector<std::string>& inputs, + ZoneInterface* owner) : + PIDController(id, owner), + _inputs(inputs), _direction(FanSpeedDirection::NEUTRAL) + { + } + + float input_proc(void) override; + float setpt_proc(void) override; + void output_proc(float value) override; + + FanSpeedDirection getFanDirection(void) const + { + return _direction; + } + + void setFanDirection(FanSpeedDirection direction) + { + _direction = direction; + }; + + private: + std::vector<std::string> _inputs; + FanSpeedDirection _direction; }; diff --git a/pid/pidthread.cpp b/pid/pidthread.cpp index d387ac9..490b70e 100644 --- a/pid/pidthread.cpp +++ b/pid/pidthread.cpp @@ -14,17 +14,16 @@ * limitations under the License. */ -#include <chrono> -#include <map> -#include <memory> -#include <thread> -#include <vector> - #include "pidthread.hpp" #include "pid/controller.hpp" #include "sensors/sensor.hpp" +#include <chrono> +#include <map> +#include <memory> +#include <thread> +#include <vector> static void ProcessThermals(PIDZone* zone) { @@ -38,7 +37,6 @@ static void ProcessThermals(PIDZone* zone) zone->determineMaxRPMRequest(); } - void PIDControlThread(PIDZone* zone) { int ms100cnt = 0; @@ -104,5 +102,3 @@ void PIDControlThread(PIDZone* zone) return; } - - diff --git a/pid/thermalcontroller.cpp b/pid/thermalcontroller.cpp index 81e3e80..1422bef 100644 --- a/pid/thermalcontroller.cpp +++ b/pid/thermalcontroller.cpp @@ -15,16 +15,13 @@ */ #include "thermalcontroller.hpp" + #include "util.hpp" #include "zone.hpp" - std::unique_ptr<PIDController> ThermalController::CreateThermalPid( - ZoneInterface* owner, - const std::string& id, - std::vector<std::string>& inputs, - float setpoint, - ec::pidinfo initial) + ZoneInterface* owner, const std::string& id, + std::vector<std::string>& inputs, float setpoint, ec::pidinfo initial) { // ThermalController currently only supports precisely one input. if (inputs.size() != 1) @@ -42,7 +39,7 @@ std::unique_ptr<PIDController> ThermalController::CreateThermalPid( return thermal; } -//bmc_host_sensor_value_float +// bmc_host_sensor_value_float float ThermalController::input_proc(void) { /* @@ -79,4 +76,3 @@ void ThermalController::output_proc(float value) return; } - diff --git a/pid/thermalcontroller.hpp b/pid/thermalcontroller.hpp index 32d4a7f..ed94acb 100644 --- a/pid/thermalcontroller.hpp +++ b/pid/thermalcontroller.hpp @@ -1,12 +1,11 @@ #pragma once -#include <memory> -#include <string> -#include <vector> - #include "controller.hpp" #include "ec/pid.hpp" +#include <memory> +#include <string> +#include <vector> /* * A ThermalController is a PID controller that reads a number of sensors and @@ -14,26 +13,23 @@ */ class ThermalController : public PIDController { - public: - static std::unique_ptr<PIDController> CreateThermalPid( - ZoneInterface* owner, - const std::string& id, - std::vector<std::string>& inputs, - float setpoint, - ec::pidinfo initial); - - ThermalController(const std::string& id, - std::vector<std::string>& inputs, - ZoneInterface* owner) - : PIDController(id, owner), - _inputs(inputs) - { } - - float input_proc(void) override; - float setpt_proc(void) override; - void output_proc(float value) override; - - private: - std::vector<std::string> _inputs; + public: + static std::unique_ptr<PIDController> + CreateThermalPid(ZoneInterface* owner, const std::string& id, + std::vector<std::string>& inputs, float setpoint, + ec::pidinfo initial); + + ThermalController(const std::string& id, std::vector<std::string>& inputs, + ZoneInterface* owner) : + PIDController(id, owner), + _inputs(inputs) + { + } + + float input_proc(void) override; + float setpt_proc(void) override; + void output_proc(float value) override; + + private: + std::vector<std::string> _inputs; }; - diff --git a/pid/util.cpp b/pid/util.cpp index 79da7e1..9004059 100644 --- a/pid/util.cpp +++ b/pid/util.cpp @@ -14,11 +14,11 @@ * limitations under the License. */ +#include "ec/pid.hpp" + #include <cstring> #include <iostream> -#include "ec/pid.hpp" - void InitializePIDStruct(ec::pid_info_t* info, ec::pidinfo* initial) { std::memset(info, 0x00, sizeof(ec::pid_info_t)); @@ -36,12 +36,10 @@ void InitializePIDStruct(ec::pid_info_t* info, ec::pidinfo* initial) info->slew_pos = initial->slew_pos; } -void DumpPIDStruct(ec::pid_info_t *info) +void DumpPIDStruct(ec::pid_info_t* info) { - std::cerr << " ts: " << info->ts - << " p_c: " << info->p_c - << " i_c: " << info->i_c - << " ff_off: " << info->ff_off + std::cerr << " ts: " << info->ts << " p_c: " << info->p_c + << " i_c: " << info->i_c << " ff_off: " << info->ff_off << " ff_gain: " << info->ff_gain << " i_lim.min: " << info->i_lim.min << " i_lim.max: " << info->i_lim.max @@ -50,8 +48,7 @@ void DumpPIDStruct(ec::pid_info_t *info) << " slew_neg: " << info->slew_neg << " slew_pos: " << info->slew_pos << " last_output: " << info->last_output - << " integral: " << info->integral - << std::endl; + << " integral: " << info->integral << std::endl; return; } diff --git a/pid/util.hpp b/pid/util.hpp index eb6e713..0f37afe 100644 --- a/pid/util.hpp +++ b/pid/util.hpp @@ -2,11 +2,10 @@ #include "ec/pid.hpp" - /* * Given a configuration structure, fill out the information we use within the * PID loop. */ void InitializePIDStruct(ec::pid_info_t* info, ec::pidinfo* initial); -void DumpPIDStruct(ec::pid_info_t *info); +void DumpPIDStruct(ec::pid_info_t* info); diff --git a/pid/zone.cpp b/pid/zone.cpp index fdf16fc..9e948f0 100644 --- a/pid/zone.cpp +++ b/pid/zone.cpp @@ -15,10 +15,14 @@ */ /* Configuration. */ -#include "conf.hpp" - #include "zone.hpp" +#include "conf.hpp" +#include "pid/controller.hpp" +#include "pid/ec/pid.hpp" +#include "pid/fancontroller.hpp" +#include "pid/thermalcontroller.hpp" + #include <algorithm> #include <chrono> #include <cstring> @@ -27,12 +31,6 @@ #include <libconfig.h++> #include <memory> -#include "pid/controller.hpp" -#include "pid/fancontroller.hpp" -#include "pid/thermalcontroller.hpp" -#include "pid/ec/pid.hpp" - - using tstamp = std::chrono::high_resolution_clock::time_point; using namespace std::literals::chrono_literals; @@ -136,7 +134,8 @@ void PIDZone::determineMaxRPMRequest(void) int value; std::ifstream ifs; ifs.open(setpointpath); - if (ifs.good()) { + if (ifs.good()) + { ifs >> value; max = value; // expecting RPM set-point, not pwm% } @@ -202,7 +201,9 @@ void PIDZone::updateFanTelemetry(void) */ #ifdef __TUNING_LOGGING__ tstamp now = std::chrono::high_resolution_clock::now(); - _log << std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count(); + _log << std::chrono::duration_cast<std::chrono::milliseconds>( + now.time_since_epoch()) + .count(); _log << "," << _maximumRPMSetPt; #endif @@ -252,12 +253,12 @@ void PIDZone::updateSensors(void) */ if (timeout > 0) { - auto duration = duration_cast<std::chrono::seconds> - (now - then).count(); + auto duration = + duration_cast<std::chrono::seconds>(now - then).count(); auto period = std::chrono::seconds(timeout).count(); if (duration >= period) { - //std::cerr << "Entering fail safe mode.\n"; + // std::cerr << "Entering fail safe mode.\n"; _failSafeSensors.insert(t); } else diff --git a/pid/zone.hpp b/pid/zone.hpp index 1934a66..99a8f14 100644 --- a/pid/zone.hpp +++ b/pid/zone.hpp @@ -1,39 +1,36 @@ #pragma once -#include <fstream> -#include <map> -#include <memory> -#include <set> -#include <string> -#include <vector> - #include "conf.hpp" #include "controller.hpp" -#include "sensors/sensor.hpp" #include "sensors/manager.hpp" - +#include "sensors/sensor.hpp" #include "xyz/openbmc_project/Control/Mode/server.hpp" + +#include <fstream> +#include <map> +#include <memory> #include <sdbusplus/bus.hpp> #include <sdbusplus/server.hpp> - +#include <set> +#include <string> +#include <vector> template <typename... T> using ServerObject = typename sdbusplus::server::object::object<T...>; -using ModeInterface = - sdbusplus::xyz::openbmc_project::Control::server::Mode; +using ModeInterface = sdbusplus::xyz::openbmc_project::Control::server::Mode; using ModeObject = ServerObject<ModeInterface>; class ZoneInterface { - public: - virtual ~ZoneInterface() = default; - - virtual double getCachedValue(const std::string& name) = 0; - virtual void addRPMSetPoint(float setpoint) = 0; - virtual float getMaxRPMRequest() const = 0; - virtual bool getFailSafeMode() const = 0; - virtual float getFailSafePercent() const = 0; - virtual Sensor* getSensor(std::string name) = 0; + public: + virtual ~ZoneInterface() = default; + + virtual double getCachedValue(const std::string& name) = 0; + virtual void addRPMSetPoint(float setpoint) = 0; + virtual float getMaxRPMRequest() const = 0; + virtual bool getFailSafeMode() const = 0; + virtual float getFailSafePercent() const = 0; + virtual Sensor* getSensor(std::string name) = 0; }; /* @@ -43,84 +40,77 @@ class ZoneInterface */ class PIDZone : public ZoneInterface, public ModeObject { - public: - PIDZone(int64_t zone, - float minThermalRpm, - float failSafePercent, - const SensorManager& mgr, - sdbusplus::bus::bus& bus, - const char* objPath, - bool defer) - : ModeObject(bus, objPath, defer), - _zoneId(zone), - _maximumRPMSetPt(), - _minThermalRpmSetPt(minThermalRpm), - _failSafePercent(failSafePercent), - _mgr(mgr) - { + public: + PIDZone(int64_t zone, float minThermalRpm, float failSafePercent, + const SensorManager& mgr, sdbusplus::bus::bus& bus, + const char* objPath, bool defer) : + ModeObject(bus, objPath, defer), + _zoneId(zone), _maximumRPMSetPt(), _minThermalRpmSetPt(minThermalRpm), + _failSafePercent(failSafePercent), _mgr(mgr) + { #ifdef __TUNING_LOGGING__ - _log.open("/tmp/swampd.log"); + _log.open("/tmp/swampd.log"); #endif - } - - float getMaxRPMRequest(void) const override; - bool getManualMode(void) const; - - /* Could put lock around this since it's accessed from two threads, but - * only one reader/one writer. - */ - void setManualMode(bool mode); - bool getFailSafeMode(void) const override; - int64_t getZoneId(void) const; - void addRPMSetPoint(float setpoint) override; - void clearRPMSetPoints(void); - float getFailSafePercent(void) const override; - float getMinThermalRpmSetPt(void) const; - - Sensor* getSensor(std::string name) override; - void determineMaxRPMRequest(void); - void updateFanTelemetry(void); - void updateSensors(void); - void initializeCache(void); - void dumpCache(void); - void process_fans(void); - void process_thermals(void); - - void addFanPID(std::unique_ptr<PIDController> pid); - void addThermalPID(std::unique_ptr<PIDController> pid); - double getCachedValue(const std::string& name) override; - void addFanInput(std::string fan); - void addThermalInput(std::string therm); + } + + float getMaxRPMRequest(void) const override; + bool getManualMode(void) const; + + /* Could put lock around this since it's accessed from two threads, but + * only one reader/one writer. + */ + void setManualMode(bool mode); + bool getFailSafeMode(void) const override; + int64_t getZoneId(void) const; + void addRPMSetPoint(float setpoint) override; + void clearRPMSetPoints(void); + float getFailSafePercent(void) const override; + float getMinThermalRpmSetPt(void) const; + + Sensor* getSensor(std::string name) override; + void determineMaxRPMRequest(void); + void updateFanTelemetry(void); + void updateSensors(void); + void initializeCache(void); + void dumpCache(void); + void process_fans(void); + void process_thermals(void); + + void addFanPID(std::unique_ptr<PIDController> pid); + void addThermalPID(std::unique_ptr<PIDController> pid); + double getCachedValue(const std::string& name) override; + void addFanInput(std::string fan); + void addThermalInput(std::string therm); #ifdef __TUNING_LOGGING__ - void initializeLog(void); - std::ofstream& getLogHandle(void); + void initializeLog(void); + std::ofstream& getLogHandle(void); #endif - /* Method for setting the manual mode over dbus */ - bool manual(bool value) override; - /* Method for reading whether in fail-safe mode over dbus */ - bool failSafe() const override; + /* Method for setting the manual mode over dbus */ + bool manual(bool value) override; + /* Method for reading whether in fail-safe mode over dbus */ + bool failSafe() const override; - private: + private: #ifdef __TUNING_LOGGING__ - std::ofstream _log; + std::ofstream _log; #endif - const int64_t _zoneId; - float _maximumRPMSetPt = 0; - bool _manualMode = false; - const float _minThermalRpmSetPt; - const float _failSafePercent; + const int64_t _zoneId; + float _maximumRPMSetPt = 0; + bool _manualMode = false; + const float _minThermalRpmSetPt; + const float _failSafePercent; - std::set<std::string> _failSafeSensors; + std::set<std::string> _failSafeSensors; - std::vector<float> _RPMSetPoints; - std::vector<std::string> _fanInputs; - std::vector<std::string> _thermalInputs; - std::map<std::string, double> _cachedValuesByName; - const SensorManager& _mgr; + std::vector<float> _RPMSetPoints; + std::vector<std::string> _fanInputs; + std::vector<std::string> _thermalInputs; + std::map<std::string, double> _cachedValuesByName; + const SensorManager& _mgr; - std::vector<std::unique_ptr<PIDController>> _fans; - std::vector<std::unique_ptr<PIDController>> _thermals; + std::vector<std::unique_ptr<PIDController>> _fans; + std::vector<std::unique_ptr<PIDController>> _thermals; }; diff --git a/sensors/builder.cpp b/sensors/builder.cpp index 106b154..881a9c2 100644 --- a/sensors/builder.cpp +++ b/sensors/builder.cpp @@ -20,15 +20,14 @@ /* Configuration. */ #include "conf.hpp" - #include "dbus/dbuspassive.hpp" #include "dbus/dbuswrite.hpp" #include "interfaces.hpp" #include "notimpl/readonly.hpp" #include "notimpl/writeonly.hpp" #include "sensors/builder.hpp" -#include "sensors/manager.hpp" #include "sensors/host.hpp" +#include "sensors/manager.hpp" #include "sensors/pluggable.hpp" #include "sysfs/sysfsread.hpp" #include "sysfs/sysfswrite.hpp" @@ -37,8 +36,7 @@ static constexpr bool deferSignals = true; static DbusHelper helper; -SensorManager BuildSensors( - const std::map<std::string, struct sensor>& config) +SensorManager BuildSensors(const std::map<std::string, struct sensor>& config) { SensorManager mgmr; auto& HostSensorBus = mgmr.getHostBus(); @@ -60,17 +58,15 @@ SensorManager BuildSensors( // fan sensors can be ready any way and written others. // fan sensors are the only sensors this is designed to write. - // Nothing here should be write-only, although, in theory a fan could be. - // I'm just not sure how that would fit together. + // Nothing here should be write-only, although, in theory a fan could + // be. I'm just not sure how that would fit together. // TODO(venture): It should check with the ObjectMapper to check if // that sensor exists on the Dbus. switch (rtype) { case IOInterfaceType::DBUSPASSIVE: ri = DbusPassive::CreateDbusPassive(PassiveListeningBus, - info->type, - name, - &helper); + info->type, name, &helper); /* TODO(venture): if this returns nullptr */ break; case IOInterfaceType::EXTERNAL: @@ -92,33 +88,25 @@ SensorManager BuildSensors( if (info->max > 0) { wi = std::make_unique<SysFsWritePercent>( - info->writepath, - info->min, - info->max); + info->writepath, info->min, info->max); } else { - wi = std::make_unique<SysFsWrite>( - info->writepath, - info->min, - info->max); + wi = std::make_unique<SysFsWrite>(info->writepath, + info->min, info->max); } break; case IOInterfaceType::DBUSACTIVE: if (info->max > 0) { - wi = std::make_unique<DbusWritePercent>(info->writepath, - info->min, - info->max, - helper); + wi = std::make_unique<DbusWritePercent>( + info->writepath, info->min, info->max, helper); } else { - wi = std::make_unique<DbusWrite>(info->writepath, - info->min, - info->max, - helper); + wi = std::make_unique<DbusWrite>( + info->writepath, info->min, info->max, helper); } break; @@ -128,10 +116,7 @@ SensorManager BuildSensors( } auto sensor = std::make_unique<PluggableSensor>( - name, - info->timeout, - std::move(ri), - std::move(wi)); + name, info->timeout, std::move(ri), std::move(wi)); mgmr.addSensor(info->type, name, std::move(sensor)); } else if (info->type == "temp" || info->type == "margin") @@ -150,21 +135,15 @@ SensorManager BuildSensors( * not quite pluggable; but maybe it could be. */ auto sensor = HostSensor::CreateTemp( - name, - info->timeout, - HostSensorBus, - info->readpath.c_str(), - deferSignals); + name, info->timeout, HostSensorBus, info->readpath.c_str(), + deferSignals); mgmr.addSensor(info->type, name, std::move(sensor)); } else { wi = std::make_unique<ReadOnlyNoExcept>(); auto sensor = std::make_unique<PluggableSensor>( - name, - info->timeout, - std::move(ri), - std::move(wi)); + name, info->timeout, std::move(ri), std::move(wi)); mgmr.addSensor(info->type, name, std::move(sensor)); } } @@ -172,4 +151,3 @@ SensorManager BuildSensors( return mgmr; } - diff --git a/sensors/builder.hpp b/sensors/builder.hpp index edb30c3..78a578a 100644 --- a/sensors/builder.hpp +++ b/sensors/builder.hpp @@ -1,14 +1,12 @@ #pragma once -#include <map> -#include <string> - #include "sensors/manager.hpp" #include "sensors/sensor.hpp" +#include <map> +#include <string> + /** * Build the sensors and associate them with a SensorManager. */ -SensorManager BuildSensors( - const std::map<std::string, struct sensor>& config); - +SensorManager BuildSensors(const std::map<std::string, struct sensor>& config); diff --git a/sensors/builderconfig.cpp b/sensors/builderconfig.cpp index f1d95a0..cb3fd81 100644 --- a/sensors/builderconfig.cpp +++ b/sensors/builderconfig.cpp @@ -21,7 +21,6 @@ /* Configuration. */ #include "conf.hpp" - #include "sensors/builder.hpp" #include "sensors/manager.hpp" @@ -46,7 +45,8 @@ SensorManager BuildSensorsFromConfig(const std::string& path) } catch (const FileIOException& fioex) { - std::cerr << "I/O error while reading file: " << fioex.what() << std::endl; + std::cerr << "I/O error while reading file: " << fioex.what() + << std::endl; throw; } catch (const ParseException& pex) @@ -71,7 +71,8 @@ SensorManager BuildSensorsFromConfig(const std::string& path) std::string name; struct sensor thisOne; - /* Not a super fan of using this library for run-time configuration. */ + /* Not a super fan of using this library for run-time configuration. + */ name = sensor.lookup("name").c_str(); thisOne.type = sensor.lookup("type").c_str(); thisOne.readpath = sensor.lookup("readpath").c_str(); @@ -89,20 +90,18 @@ SensorManager BuildSensorsFromConfig(const std::string& path) // leaving for verification for now. and yea the above is // necessary. - std::cerr << "min: " << min - << " max: " << max - << " savedmin: " << thisOne.min - << " savedmax: " << thisOne.max - << " timeout: " << thisOne.timeout - << std::endl; + std::cerr << "min: " << min << " max: " << max + << " savedmin: " << thisOne.min + << " savedmax: " << thisOne.max + << " timeout: " << thisOne.timeout << std::endl; config[name] = thisOne; } } - catch (const SettingTypeException &setex) + catch (const SettingTypeException& setex) { - std::cerr << "Setting '" << setex.getPath() - << "' type exception!" << std::endl; + std::cerr << "Setting '" << setex.getPath() << "' type exception!" + << std::endl; throw; } catch (const SettingNotFoundException& snex) @@ -113,4 +112,3 @@ SensorManager BuildSensorsFromConfig(const std::string& path) return BuildSensors(config); } - diff --git a/sensors/builderconfig.hpp b/sensors/builderconfig.hpp index 0948c69..649ca70 100644 --- a/sensors/builderconfig.hpp +++ b/sensors/builderconfig.hpp @@ -1,9 +1,9 @@ #pragma once -#include <string> - #include "sensors/manager.hpp" +#include <string> + /** * Given a configuration file, parsable by libconfig++, parse it and then pass * the information onto BuildSensors. diff --git a/sensors/host.cpp b/sensors/host.cpp index b38d651..30addd5 100644 --- a/sensors/host.cpp +++ b/sensors/host.cpp @@ -14,21 +14,20 @@ * limitations under the License. */ +#include "host.hpp" + #include <cmath> #include <iostream> #include <memory> #include <mutex> -#include "host.hpp" - -std::unique_ptr<Sensor> HostSensor::CreateTemp( - const std::string& name, - int64_t timeout, - sdbusplus::bus::bus& bus, - const char* objPath, - bool defer) +std::unique_ptr<Sensor> HostSensor::CreateTemp(const std::string& name, + int64_t timeout, + sdbusplus::bus::bus& bus, + const char* objPath, bool defer) { - auto sensor = std::make_unique<HostSensor>(name, timeout, bus, objPath, defer); + auto sensor = + std::make_unique<HostSensor>(name, timeout, bus, objPath, defer); sensor->value(0); // DegreesC and value of 0 are the defaults at present, therefore testing @@ -65,10 +64,7 @@ ReadReturn HostSensor::read(void) std::lock_guard<std::mutex> guard(_lock); /* This doesn't sanity check anything, that's the caller's job. */ - struct ReadReturn r = { - _value, - _updated - }; + struct ReadReturn r = {_value, _updated}; return r; } @@ -77,4 +73,3 @@ void HostSensor::write(double value) { throw std::runtime_error("Not Implemented."); } - diff --git a/sensors/host.hpp b/sensors/host.hpp index 5d25aa0..ad3f834 100644 --- a/sensors/host.hpp +++ b/sensors/host.hpp @@ -1,13 +1,12 @@ #pragma once +#include "sensor.hpp" +#include "xyz/openbmc_project/Sensor/Value/server.hpp" + #include <memory> #include <mutex> - #include <sdbusplus/bus.hpp> #include <sdbusplus/server.hpp> -#include "xyz/openbmc_project/Sensor/Value/server.hpp" - -#include "sensor.hpp" template <typename... T> using ServerObject = typename sdbusplus::server::object::object<T...>; @@ -21,36 +20,31 @@ using ValueObject = ServerObject<ValueInterface>; */ class HostSensor : public Sensor, public ValueObject { - public: - static std::unique_ptr<Sensor> CreateTemp( - const std::string& name, - int64_t timeout, - sdbusplus::bus::bus& bus, - const char* objPath, - bool defer); - - HostSensor(const std::string& name, - int64_t timeout, - sdbusplus::bus::bus& bus, - const char* objPath, - bool defer) - : Sensor(name, timeout), - ValueObject(bus, objPath, defer) - { } - - /* Note: This must be int64_t because it's from ValueObject */ - int64_t value(int64_t value) override; - - ReadReturn read(void) override; - void write(double value) override; - - private: - /* - * _lock will be used to make sure _updated & _value are updated - * together. - */ - std::mutex _lock; - std::chrono::high_resolution_clock::time_point _updated; - double _value = 0; + public: + static std::unique_ptr<Sensor> CreateTemp(const std::string& name, + int64_t timeout, + sdbusplus::bus::bus& bus, + const char* objPath, bool defer); + + HostSensor(const std::string& name, int64_t timeout, + sdbusplus::bus::bus& bus, const char* objPath, bool defer) : + Sensor(name, timeout), + ValueObject(bus, objPath, defer) + { + } + + /* Note: This must be int64_t because it's from ValueObject */ + int64_t value(int64_t value) override; + + ReadReturn read(void) override; + void write(double value) override; + + private: + /* + * _lock will be used to make sure _updated & _value are updated + * together. + */ + std::mutex _lock; + std::chrono::high_resolution_clock::time_point _updated; + double _value = 0; }; - diff --git a/sensors/manager.cpp b/sensors/manager.cpp index fad2c33..78b7e64 100644 --- a/sensors/manager.cpp +++ b/sensors/manager.cpp @@ -15,14 +15,12 @@ */ /* Configuration. */ -#include "conf.hpp" - #include "sensors/manager.hpp" -void SensorManager::addSensor( - std::string type, - std::string name, - std::unique_ptr<Sensor> sensor) +#include "conf.hpp" + +void SensorManager::addSensor(std::string type, std::string name, + std::unique_ptr<Sensor> sensor) { _sensorMap[name] = std::move(sensor); diff --git a/sensors/manager.hpp b/sensors/manager.hpp index ebf4962..97e20cf 100644 --- a/sensors/manager.hpp +++ b/sensors/manager.hpp @@ -1,73 +1,67 @@ #pragma once +#include "sensors/sensor.hpp" + #include <map> #include <memory> -#include <string> -#include <vector> - #include <sdbusplus/bus.hpp> #include <sdbusplus/server.hpp> - -#include "sensors/sensor.hpp" - +#include <string> +#include <vector> /* * The SensorManager holds all sensors across all zones. */ class SensorManager { - public: - SensorManager(sdbusplus::bus::bus&& pass, sdbusplus::bus::bus&& host) - : _passiveListeningBus(std::move(pass)), - _hostSensorBus(std::move(host)) - { - // manager gets its interface from the bus. :D - sdbusplus::server::manager::manager(_hostSensorBus, SensorRoot); - } + public: + SensorManager(sdbusplus::bus::bus&& pass, sdbusplus::bus::bus&& host) : + _passiveListeningBus(std::move(pass)), _hostSensorBus(std::move(host)) + { + // manager gets its interface from the bus. :D + sdbusplus::server::manager::manager(_hostSensorBus, SensorRoot); + } - SensorManager() - : SensorManager(std::move(sdbusplus::bus::new_default()), - std::move(sdbusplus::bus::new_default())) - { - } + SensorManager() : + SensorManager(std::move(sdbusplus::bus::new_default()), + std::move(sdbusplus::bus::new_default())) + { + } - ~SensorManager() = default; - SensorManager(const SensorManager&) = delete; - SensorManager& operator=(const SensorManager&) = delete; - SensorManager(SensorManager&&) = default; - SensorManager& operator=(SensorManager&&) = default; + ~SensorManager() = default; + SensorManager(const SensorManager&) = delete; + SensorManager& operator=(const SensorManager&) = delete; + SensorManager(SensorManager&&) = default; + SensorManager& operator=(SensorManager&&) = default; - /* - * Add a Sensor to the Manager. - */ - void addSensor( - std::string type, - std::string name, - std::unique_ptr<Sensor> sensor); + /* + * Add a Sensor to the Manager. + */ + void addSensor(std::string type, std::string name, + std::unique_ptr<Sensor> sensor); - // TODO(venture): Should implement read/write by name. - Sensor* getSensor(const std::string& name) const - { - return _sensorMap.at(name).get(); - } + // TODO(venture): Should implement read/write by name. + Sensor* getSensor(const std::string& name) const + { + return _sensorMap.at(name).get(); + } - sdbusplus::bus::bus& getPassiveBus(void) - { - return _passiveListeningBus; - } + sdbusplus::bus::bus& getPassiveBus(void) + { + return _passiveListeningBus; + } - sdbusplus::bus::bus& getHostBus(void) - { - return _hostSensorBus; - } + sdbusplus::bus::bus& getHostBus(void) + { + return _hostSensorBus; + } - private: - std::map<std::string, std::unique_ptr<Sensor>> _sensorMap; - std::map<std::string, std::vector<std::string>> _sensorTypeList; + private: + std::map<std::string, std::unique_ptr<Sensor>> _sensorMap; + std::map<std::string, std::vector<std::string>> _sensorTypeList; - sdbusplus::bus::bus _passiveListeningBus; - sdbusplus::bus::bus _hostSensorBus; + sdbusplus::bus::bus _passiveListeningBus; + sdbusplus::bus::bus _hostSensorBus; - static constexpr auto SensorRoot = "/xyz/openbmc_project/extsensors"; + static constexpr auto SensorRoot = "/xyz/openbmc_project/extsensors"; }; - diff --git a/sensors/pluggable.cpp b/sensors/pluggable.cpp index 8039aea..8e4d789 100644 --- a/sensors/pluggable.cpp +++ b/sensors/pluggable.cpp @@ -16,14 +16,13 @@ #include "pluggable.hpp" +#include "dbus/dbuspassive.hpp" +#include "sysfs/sysfswrite.hpp" + #include <iostream> #include <memory> #include <string> -#include "sysfs/sysfswrite.hpp" -#include "dbus/dbuspassive.hpp" - - ReadReturn PluggableSensor::read(void) { return _reader->read(); @@ -33,4 +32,3 @@ void PluggableSensor::write(double value) { _writer->write(value); } - diff --git a/sensors/pluggable.hpp b/sensors/pluggable.hpp index 1eb6571..005d9ad 100644 --- a/sensors/pluggable.hpp +++ b/sensors/pluggable.hpp @@ -1,33 +1,30 @@ #pragma once -#include <memory> -#include <string> - -#include <sdbusplus/bus.hpp> - #include "interfaces.hpp" #include "sensor.hpp" +#include <memory> +#include <sdbusplus/bus.hpp> +#include <string> /* * A Sensor that can use any reader or writer you provide. */ class PluggableSensor : public Sensor { - public: - PluggableSensor(const std::string& name, - int64_t timeout, - std::unique_ptr<ReadInterface> reader, - std::unique_ptr<WriteInterface> writer) - : Sensor(name, timeout), - _reader(std::move(reader)), - _writer(std::move(writer)) - { } + public: + PluggableSensor(const std::string& name, int64_t timeout, + std::unique_ptr<ReadInterface> reader, + std::unique_ptr<WriteInterface> writer) : + Sensor(name, timeout), + _reader(std::move(reader)), _writer(std::move(writer)) + { + } - ReadReturn read(void) override; - void write(double value) override; + ReadReturn read(void) override; + void write(double value) override; - private: - std::unique_ptr<ReadInterface> _reader; - std::unique_ptr<WriteInterface> _writer; + private: + std::unique_ptr<ReadInterface> _reader; + std::unique_ptr<WriteInterface> _writer; }; diff --git a/sensors/sensor.hpp b/sensors/sensor.hpp index dc5f3e0..9ff0584 100644 --- a/sensors/sensor.hpp +++ b/sensors/sensor.hpp @@ -1,41 +1,41 @@ #pragma once -#include <chrono> -#include <string> - #include "interfaces.hpp" +#include <chrono> +#include <string> /** * Abstract base class for all sensors. */ class Sensor { - public: - Sensor(std::string name, int64_t timeout) - : _name(name), _timeout(timeout) - { } - - virtual ~Sensor() { } - - virtual ReadReturn read(void) = 0; - virtual void write(double value) = 0; - - std::string GetName(void) const - { - return _name; - } - - /* Returns the configurable timeout period - * for this sensor in seconds (undecorated). - */ - int64_t GetTimeout(void) const - { - return _timeout; - } - - private: - std::string _name; - int64_t _timeout; + public: + Sensor(std::string name, int64_t timeout) : _name(name), _timeout(timeout) + { + } + + virtual ~Sensor() + { + } + + virtual ReadReturn read(void) = 0; + virtual void write(double value) = 0; + + std::string GetName(void) const + { + return _name; + } + + /* Returns the configurable timeout period + * for this sensor in seconds (undecorated). + */ + int64_t GetTimeout(void) const + { + return _timeout; + } + + private: + std::string _name; + int64_t _timeout; }; - diff --git a/setsensor.cpp b/setsensor.cpp index cef8090..a60778f 100644 --- a/setsensor.cpp +++ b/setsensor.cpp @@ -1,8 +1,7 @@ #include <iostream> -#include <string> - #include <sdbusplus/bus.hpp> #include <sdbusplus/message.hpp> +#include <string> /* Fan Control */ static constexpr auto objectPath = "/xyz/openbmc_project/settings/fanctrl/zone"; @@ -19,23 +18,19 @@ static constexpr auto sintf = "xyz.openbmc_project.Sensor.Value"; static constexpr auto sproperty = "Value"; using sValue = sdbusplus::message::variant<int64_t>; - static constexpr auto propertiesintf = "org.freedesktop.DBus.Properties"; static void SetHostSensor(void) { int64_t value = 300; - sValue v {value}; + sValue v{value}; - std::string busname {sbusName}; + std::string busname{sbusName}; auto PropertyWriteBus = sdbusplus::bus::new_default(); - std::string path {sobjectPath}; + std::string path{sobjectPath}; auto pimMsg = PropertyWriteBus.new_method_call( - busname.c_str(), - path.c_str(), - propertiesintf, - "Set"); + busname.c_str(), path.c_str(), propertiesintf, "Set"); pimMsg.append(sintf); pimMsg.append(sproperty); @@ -61,17 +56,14 @@ static void SetManualMode(int8_t zone) { bool setValue = (bool)0x01; - Value v {setValue}; + Value v{setValue}; - std::string busname {busName}; + std::string busname{busName}; auto PropertyWriteBus = sdbusplus::bus::new_default(); std::string path = GetControlPath(zone); auto pimMsg = PropertyWriteBus.new_method_call( - busname.c_str(), - path.c_str(), - propertiesintf, - "Set"); + busname.c_str(), path.c_str(), propertiesintf, "Set"); pimMsg.append(intf); pimMsg.append(property); diff --git a/sysfs/sysfsread.cpp b/sysfs/sysfsread.cpp index 284aa55..a070af2 100644 --- a/sysfs/sysfsread.cpp +++ b/sysfs/sysfsread.cpp @@ -14,13 +14,12 @@ * limitations under the License. */ +#include "sysfs/sysfsread.hpp" + #include <chrono> #include <fstream> #include <iostream> -#include "sysfs/sysfsread.hpp" - - ReadReturn SysFsRead::read(void) { int64_t value; @@ -30,10 +29,8 @@ ReadReturn SysFsRead::read(void) ifs >> value; ifs.close(); - struct ReadReturn r = { - static_cast<double>(value), - std::chrono::high_resolution_clock::now() - }; + struct ReadReturn r = {static_cast<double>(value), + std::chrono::high_resolution_clock::now()}; return r; } diff --git a/sysfs/sysfsread.hpp b/sysfs/sysfsread.hpp index 0dbc71b..4cd2a78 100644 --- a/sysfs/sysfsread.hpp +++ b/sysfs/sysfsread.hpp @@ -1,10 +1,9 @@ #pragma once -#include <string> - #include "interfaces.hpp" #include "sysfs/util.hpp" +#include <string> /* * A ReadInterface that is expecting a path that's sysfs, but really could be @@ -12,14 +11,13 @@ */ class SysFsRead : public ReadInterface { - public: - SysFsRead(const std::string& path) - : ReadInterface(), - _path(FixupPath(path)) - { } + public: + SysFsRead(const std::string& path) : ReadInterface(), _path(FixupPath(path)) + { + } - ReadReturn read(void) override; + ReadReturn read(void) override; - private: - const std::string _path; + private: + const std::string _path; }; diff --git a/sysfs/sysfswrite.cpp b/sysfs/sysfswrite.cpp index c3e1b03..1ea4c4d 100644 --- a/sysfs/sysfswrite.cpp +++ b/sysfs/sysfswrite.cpp @@ -14,11 +14,10 @@ * limitations under the License. */ -#include <fstream> -#include <iostream> - #include "sysfswrite.hpp" +#include <fstream> +#include <iostream> void SysFsWritePercent::write(double value) { diff --git a/sysfs/sysfswrite.hpp b/sysfs/sysfswrite.hpp index 989f800..9510dff 100644 --- a/sysfs/sysfswrite.hpp +++ b/sysfs/sysfswrite.hpp @@ -1,10 +1,9 @@ #pragma once -#include <string> - #include "interfaces.hpp" #include "sysfs/util.hpp" +#include <string> /* * A WriteInterface that is expecting a path that's sysfs, but really could be @@ -12,29 +11,28 @@ */ class SysFsWritePercent : public WriteInterface { - public: - SysFsWritePercent(const std::string& writepath, int64_t min, - int64_t max) - : WriteInterface(min, max), - _writepath(FixupPath(writepath)) - { } + public: + SysFsWritePercent(const std::string& writepath, int64_t min, int64_t max) : + WriteInterface(min, max), _writepath(FixupPath(writepath)) + { + } - void write(double value) override; + void write(double value) override; - private: - std::string _writepath; + private: + std::string _writepath; }; class SysFsWrite : public WriteInterface { - public: - SysFsWrite(const std::string& writepath, int64_t min, int64_t max) - : WriteInterface(min, max), - _writepath(FixupPath(writepath)) - { } + public: + SysFsWrite(const std::string& writepath, int64_t min, int64_t max) : + WriteInterface(min, max), _writepath(FixupPath(writepath)) + { + } - void write(double value) override; + void write(double value) override; - private: - std::string _writepath; + private: + std::string _writepath; }; diff --git a/sysfs/util.cpp b/sysfs/util.cpp index c297412..aeceada 100644 --- a/sysfs/util.cpp +++ b/sysfs/util.cpp @@ -14,17 +14,17 @@ * limitations under the License. */ +#include "sysfs/util.hpp" + #include <experimental/filesystem> #include <iostream> #include <string> - -#include "sysfs/util.hpp" - /* * There are two basic paths I want to support: * 1. /sys/class/hwmon/hwmon0/pwm1 - * 2. /sys/devices/platform/ahb/1e786000.pwm-tacho-controller/hwmon/<asterisk asterisk>/pwm1 + * 2. /sys/devices/platform/ahb/1e786000.pwm-tacho-controller/hwmon/<asterisk + * asterisk>/pwm1 * * In this latter case, I want to fill in that gap. Assuming because it's this * path that it'll only have one directory there. @@ -33,7 +33,6 @@ static constexpr auto platform = "/sys/devices/platform/"; namespace fs = std::experimental::filesystem; - std::string FixupPath(std::string original) { std::string::size_type n, x; diff --git a/test/controller_mock.hpp b/test/controller_mock.hpp index 241e83a..38d0446 100644 --- a/test/controller_mock.hpp +++ b/test/controller_mock.hpp @@ -1,18 +1,20 @@ #pragma once -#include <gmock/gmock.h> - #include "pid/controller.hpp" +#include <gmock/gmock.h> + class ControllerMock : public PIDController { - public: - virtual ~ControllerMock() = default; + public: + virtual ~ControllerMock() = default; - ControllerMock(const std::string& id, PIDZone* owner) - : PIDController(id, owner) {} + ControllerMock(const std::string& id, PIDZone* owner) : + PIDController(id, owner) + { + } - MOCK_METHOD0(input_proc, float()); - MOCK_METHOD0(setpt_proc, float()); - MOCK_METHOD1(output_proc, void(float)); + MOCK_METHOD0(input_proc, float()); + MOCK_METHOD0(setpt_proc, float()); + MOCK_METHOD1(output_proc, void(float)); }; diff --git a/test/dbus_active_unittest.cpp b/test/dbus_active_unittest.cpp index c83e9ce..5a7bcfe 100644 --- a/test/dbus_active_unittest.cpp +++ b/test/dbus_active_unittest.cpp @@ -1,17 +1,18 @@ #include "dbus/dbusactiveread.hpp" +#include "test/dbushelper_mock.hpp" -#include <gmock/gmock.h> -#include <gtest/gtest.h> #include <sdbusplus/test/sdbus_mock.hpp> #include <string> -#include "test/dbushelper_mock.hpp" +#include <gmock/gmock.h> +#include <gtest/gtest.h> +using ::testing::_; using ::testing::Invoke; using ::testing::NotNull; -using ::testing::_; -TEST(DbusActiveReadTest, BoringConstructorTest) { +TEST(DbusActiveReadTest, BoringConstructorTest) +{ // Verify we can construct it. sdbusplus::SdBusMock sdbus_mock; @@ -23,7 +24,8 @@ TEST(DbusActiveReadTest, BoringConstructorTest) { DbusActiveRead ar(bus_mock, path, service, &helper); } -TEST(DbusActiveReadTest, Read_VerifyCallsToDbusForValue) { +TEST(DbusActiveReadTest, Read_VerifyCallsToDbusForValue) +{ // Verify it calls to get the value from dbus when requested. sdbusplus::SdBusMock sdbus_mock; @@ -35,14 +37,13 @@ TEST(DbusActiveReadTest, Read_VerifyCallsToDbusForValue) { DbusActiveRead ar(bus_mock, path, service, &helper); EXPECT_CALL(helper, GetProperties(_, service, path, NotNull())) - .WillOnce(Invoke([&](sdbusplus::bus::bus& bus, - const std::string& service, - const std::string& path, - struct SensorProperties* prop) { - prop->scale = -3; - prop->value = 10000; - prop->unit = "x"; - })); + .WillOnce( + Invoke([&](sdbusplus::bus::bus& bus, const std::string& service, + const std::string& path, struct SensorProperties* prop) { + prop->scale = -3; + prop->value = 10000; + prop->unit = "x"; + })); ReadReturn r = ar.read(); EXPECT_EQ(10, r.value); diff --git a/test/dbus_passive_unittest.cpp b/test/dbus_passive_unittest.cpp index e84de89..6b8cc8e 100644 --- a/test/dbus_passive_unittest.cpp +++ b/test/dbus_passive_unittest.cpp @@ -1,23 +1,24 @@ #include "dbus/dbuspassive.hpp" +#include "test/dbushelper_mock.hpp" -#include <gmock/gmock.h> -#include <gtest/gtest.h> #include <sdbusplus/test/sdbus_mock.hpp> #include <string> -#include "test/dbushelper_mock.hpp" +#include <gmock/gmock.h> +#include <gtest/gtest.h> +using ::testing::_; using ::testing::InSequence; using ::testing::Invoke; using ::testing::IsNull; using ::testing::NotNull; using ::testing::Return; using ::testing::StrEq; -using ::testing::_; std::string SensorIntf = "xyz.openbmc_project.Sensor.Value"; -TEST(DbusPassiveTest, FactoryFailsWithInvalidType) { +TEST(DbusPassiveTest, FactoryFailsWithInvalidType) +{ // Verify the type is checked by the factory. sdbusplus::SdBusMock sdbus_mock; @@ -33,7 +34,8 @@ TEST(DbusPassiveTest, FactoryFailsWithInvalidType) { EXPECT_EQ(ri, nullptr); } -TEST(DbusPassiveTest, BoringConstructorTest) { +TEST(DbusPassiveTest, BoringConstructorTest) +{ // Just build the object, which should be avoided as this does no error // checking at present. @@ -47,61 +49,59 @@ TEST(DbusPassiveTest, BoringConstructorTest) { EXPECT_CALL(helper, GetService(_, StrEq(SensorIntf), StrEq(path))) .WillOnce(Return("asdf")); - EXPECT_CALL(helper, GetProperties(_, StrEq("asdf"), StrEq(path), - NotNull())) - .WillOnce(Invoke([&](sdbusplus::bus::bus& bus, - const std::string& service, - const std::string& path, - struct SensorProperties* prop) { - prop->scale = -3; - prop->value = 10; - prop->unit = "x"; - })); + EXPECT_CALL(helper, GetProperties(_, StrEq("asdf"), StrEq(path), NotNull())) + .WillOnce( + Invoke([&](sdbusplus::bus::bus &bus, const std::string &service, + const std::string &path, struct SensorProperties *prop) { + prop->scale = -3; + prop->value = 10; + prop->unit = "x"; + })); DbusPassive(bus_mock, type, id, &helper); // Success } -class DbusPassiveTestObj : public ::testing::Test { - protected: - DbusPassiveTestObj() - : sdbus_mock(), - bus_mock(std::move(sdbusplus::get_mocked_new(&sdbus_mock))), - helper() - { - EXPECT_CALL(helper, GetService(_, StrEq(SensorIntf), StrEq(path))) - .WillOnce(Return("asdf")); - - EXPECT_CALL(helper, GetProperties(_, StrEq("asdf"), StrEq(path), - NotNull())) - .WillOnce(Invoke([&](sdbusplus::bus::bus& bus, - const std::string& service, - const std::string& path, - struct SensorProperties* prop) { +class DbusPassiveTestObj : public ::testing::Test +{ + protected: + DbusPassiveTestObj() : + sdbus_mock(), + bus_mock(std::move(sdbusplus::get_mocked_new(&sdbus_mock))), helper() + { + EXPECT_CALL(helper, GetService(_, StrEq(SensorIntf), StrEq(path))) + .WillOnce(Return("asdf")); + + EXPECT_CALL(helper, + GetProperties(_, StrEq("asdf"), StrEq(path), NotNull())) + .WillOnce(Invoke( + [&](sdbusplus::bus::bus &bus, const std::string &service, + const std::string &path, struct SensorProperties *prop) { prop->scale = _scale; prop->value = _value; prop->unit = "x"; })); - ri = DbusPassive::CreateDbusPassive(bus_mock, type, id, &helper); - passive = reinterpret_cast<DbusPassive*>(ri.get()); - EXPECT_FALSE(passive == nullptr); - } - - sdbusplus::SdBusMock sdbus_mock; - sdbusplus::bus::bus bus_mock; - DbusHelperMock helper; - std::string type = "temp"; - std::string id = "id"; - std::string path = "/xyz/openbmc_project/sensors/temperature/id"; - int64_t _scale = -3; - int64_t _value = 10; - - std::unique_ptr<ReadInterface> ri; - DbusPassive *passive; + ri = DbusPassive::CreateDbusPassive(bus_mock, type, id, &helper); + passive = reinterpret_cast<DbusPassive *>(ri.get()); + EXPECT_FALSE(passive == nullptr); + } + + sdbusplus::SdBusMock sdbus_mock; + sdbusplus::bus::bus bus_mock; + DbusHelperMock helper; + std::string type = "temp"; + std::string id = "id"; + std::string path = "/xyz/openbmc_project/sensors/temperature/id"; + int64_t _scale = -3; + int64_t _value = 10; + + std::unique_ptr<ReadInterface> ri; + DbusPassive *passive; }; -TEST_F(DbusPassiveTestObj, ReadReturnsExpectedValues) { +TEST_F(DbusPassiveTestObj, ReadReturnsExpectedValues) +{ // Verify read is returning the values. ReadReturn v; v.value = 0.01; @@ -111,7 +111,8 @@ TEST_F(DbusPassiveTestObj, ReadReturnsExpectedValues) { EXPECT_EQ(v.value, r.value); } -TEST_F(DbusPassiveTestObj, SetValueUpdatesValue) { +TEST_F(DbusPassiveTestObj, SetValueUpdatesValue) +{ // Verify setvalue does as advertised. double value = 0.01; @@ -122,17 +123,20 @@ TEST_F(DbusPassiveTestObj, SetValueUpdatesValue) { EXPECT_EQ(value, r.value); } -TEST_F(DbusPassiveTestObj, GetScaleReturnsExpectedValue) { +TEST_F(DbusPassiveTestObj, GetScaleReturnsExpectedValue) +{ // Verify the scale is returned as expected. EXPECT_EQ(_scale, passive->getScale()); } -TEST_F(DbusPassiveTestObj, GetIdReturnsExpectedValue) { +TEST_F(DbusPassiveTestObj, GetIdReturnsExpectedValue) +{ // Verify getId returns the expected value. EXPECT_EQ(id, passive->getId()); } -TEST_F(DbusPassiveTestObj, VerifyHandlesDbusSignal) { +TEST_F(DbusPassiveTestObj, VerifyHandlesDbusSignal) +{ // The dbus passive sensor listens for updates and if it's the Value // property, it needs to handle it. @@ -146,8 +150,7 @@ TEST_F(DbusPassiveTestObj, VerifyHandlesDbusSignal) { // string, std::map<std::string, sdbusplus::message::variant<int64_t>> // msg.read(msgSensor, msgData); - EXPECT_CALL(sdbus_mock, - sd_bus_message_read_basic(IsNull(), 's', NotNull())) + EXPECT_CALL(sdbus_mock, sd_bus_message_read_basic(IsNull(), 's', NotNull())) .WillOnce(Invoke([&](sd_bus_message *m, char type, void *p) { const char **s = static_cast<const char **>(p); // Read the first parameter, the string. @@ -169,7 +172,7 @@ TEST_F(DbusPassiveTestObj, VerifyHandlesDbusSignal) { // while !at_end() EXPECT_CALL(sdbus_mock, sd_bus_message_at_end(IsNull(), 0)) .WillOnce(Return(0)) - .WillOnce(Return(1)); // So it exits the loop after reading one pair. + .WillOnce(Return(1)); // So it exits the loop after reading one pair. // std::pair EXPECT_CALL(sdbus_mock, @@ -183,8 +186,7 @@ TEST_F(DbusPassiveTestObj, VerifyHandlesDbusSignal) { sd_bus_message_enter_container(IsNull(), 'v', StrEq("x"))) .WillOnce(Return(0)); - EXPECT_CALL(sdbus_mock, - sd_bus_message_read_basic(IsNull(), 'x', NotNull())) + EXPECT_CALL(sdbus_mock, sd_bus_message_read_basic(IsNull(), 'x', NotNull())) .WillOnce(Invoke([&](sd_bus_message *m, char type, void *p) { int64_t *s = static_cast<int64_t *>(p); *s = xValue; @@ -203,7 +205,8 @@ TEST_F(DbusPassiveTestObj, VerifyHandlesDbusSignal) { EXPECT_EQ(10, r.value); } -TEST_F(DbusPassiveTestObj, VerifyIgnoresOtherPropertySignal) { +TEST_F(DbusPassiveTestObj, VerifyIgnoresOtherPropertySignal) +{ // The dbus passive sensor listens for updates and if it's the Value // property, it needs to handle it. In this case, it won't be. @@ -217,8 +220,7 @@ TEST_F(DbusPassiveTestObj, VerifyIgnoresOtherPropertySignal) { // string, std::map<std::string, sdbusplus::message::variant<int64_t>> // msg.read(msgSensor, msgData); - EXPECT_CALL(sdbus_mock, - sd_bus_message_read_basic(IsNull(), 's', NotNull())) + EXPECT_CALL(sdbus_mock, sd_bus_message_read_basic(IsNull(), 's', NotNull())) .WillOnce(Invoke([&](sd_bus_message *m, char type, void *p) { const char **s = static_cast<const char **>(p); // Read the first parameter, the string. @@ -240,7 +242,7 @@ TEST_F(DbusPassiveTestObj, VerifyIgnoresOtherPropertySignal) { // while !at_end() EXPECT_CALL(sdbus_mock, sd_bus_message_at_end(IsNull(), 0)) .WillOnce(Return(0)) - .WillOnce(Return(1)); // So it exits the loop after reading one pair. + .WillOnce(Return(1)); // So it exits the loop after reading one pair. // std::pair EXPECT_CALL(sdbus_mock, @@ -254,8 +256,7 @@ TEST_F(DbusPassiveTestObj, VerifyIgnoresOtherPropertySignal) { sd_bus_message_enter_container(IsNull(), 'v', StrEq("x"))) .WillOnce(Return(0)); - EXPECT_CALL(sdbus_mock, - sd_bus_message_read_basic(IsNull(), 'x', NotNull())) + EXPECT_CALL(sdbus_mock, sd_bus_message_read_basic(IsNull(), 'x', NotNull())) .WillOnce(Invoke([&](sd_bus_message *m, char type, void *p) { int64_t *s = static_cast<int64_t *>(p); *s = xScale; diff --git a/test/dbushelper_mock.hpp b/test/dbushelper_mock.hpp index 23dd81c..6d3464e 100644 --- a/test/dbushelper_mock.hpp +++ b/test/dbushelper_mock.hpp @@ -1,21 +1,21 @@ #pragma once -#include <gmock/gmock.h> +#include "dbus/util.hpp" + #include <sdbusplus/bus.hpp> #include <string> -#include "dbus/util.hpp" +#include <gmock/gmock.h> class DbusHelperMock : public DbusHelperInterface { - public: - virtual ~DbusHelperMock() = default; + public: + virtual ~DbusHelperMock() = default; - MOCK_METHOD3(GetService, std::string(sdbusplus::bus::bus&, - const std::string&, - const std::string&)); - MOCK_METHOD4(GetProperties, void(sdbusplus::bus::bus&, - const std::string&, - const std::string&, - struct SensorProperties*)); + MOCK_METHOD3(GetService, + std::string(sdbusplus::bus::bus&, const std::string&, + const std::string&)); + MOCK_METHOD4(GetProperties, + void(sdbusplus::bus::bus&, const std::string&, + const std::string&, struct SensorProperties*)); }; diff --git a/test/helpers.hpp b/test/helpers.hpp index 74c969f..a06eb2e 100644 --- a/test/helpers.hpp +++ b/test/helpers.hpp @@ -1,18 +1,19 @@ // THIS EXISTS AS A COPY OF SDBUSPLUS/TEST/HELPERS.HPP until that is merged. #pragma once -#include <gmock/gmock.h> -#include <gtest/gtest.h> #include <sdbusplus/test/sdbus_mock.hpp> #include <string> #include <vector> +#include <gmock/gmock.h> +#include <gtest/gtest.h> + +using ::testing::_; using ::testing::Invoke; using ::testing::IsNull; using ::testing::NotNull; using ::testing::Return; using ::testing::StrEq; -using ::testing::_; /** @brief Setup the expectations for sdbus-based object creation. * diff --git a/test/pid_fancontroller_unittest.cpp b/test/pid_fancontroller_unittest.cpp index b127929..c7b7bc7 100644 --- a/test/pid_fancontroller_unittest.cpp +++ b/test/pid_fancontroller_unittest.cpp @@ -1,21 +1,22 @@ +#include "pid/ec/pid.hpp" #include "pid/fancontroller.hpp" +#include "test/sensor_mock.hpp" +#include "test/zone_mock.hpp" -#include <gmock/gmock.h> -#include <gtest/gtest.h> #include <string> #include <vector> -#include "pid/ec/pid.hpp" -#include "test/sensor_mock.hpp" -#include "test/zone_mock.hpp" +#include <gmock/gmock.h> +#include <gtest/gtest.h> +using ::testing::_; using ::testing::DoubleEq; using ::testing::Invoke; using ::testing::Return; using ::testing::StrEq; -using ::testing::_; -TEST(FanControllerTest, BoringFactoryTest) { +TEST(FanControllerTest, BoringFactoryTest) +{ // Verify the factory will properly build the FanPIDController in the // boring (uninteresting) case. ZoneMock z; @@ -29,7 +30,8 @@ TEST(FanControllerTest, BoringFactoryTest) { EXPECT_FALSE(p == nullptr); } -TEST(FanControllerTest, VerifyFactoryFailsWithZeroInputs) { +TEST(FanControllerTest, VerifyFactoryFailsWithZeroInputs) +{ // A fan controller needs at least one input. ZoneMock z; @@ -42,7 +44,8 @@ TEST(FanControllerTest, VerifyFactoryFailsWithZeroInputs) { EXPECT_TRUE(p == nullptr); } -TEST(FanControllerTest, InputProc_AllSensorsReturnZero) { +TEST(FanControllerTest, InputProc_AllSensorsReturnZero) +{ // If all your inputs are 0, return 0. ZoneMock z; @@ -60,7 +63,8 @@ TEST(FanControllerTest, InputProc_AllSensorsReturnZero) { EXPECT_EQ(0.0, p->input_proc()); } -TEST(FanControllerTest, InputProc_IfSensorNegativeIsIgnored) { +TEST(FanControllerTest, InputProc_IfSensorNegativeIsIgnored) +{ // A sensor value returning sub-zero is ignored as an error. ZoneMock z; @@ -77,7 +81,8 @@ TEST(FanControllerTest, InputProc_IfSensorNegativeIsIgnored) { EXPECT_EQ(0.0, p->input_proc()); } -TEST(FanControllerTest, InputProc_ChoosesMinimumValue) { +TEST(FanControllerTest, InputProc_ChoosesMinimumValue) +{ // Verify it selects the minimum value from its inputs. ZoneMock z; @@ -97,7 +102,8 @@ TEST(FanControllerTest, InputProc_ChoosesMinimumValue) { } // The direction is unused presently, but these tests validate the logic. -TEST(FanControllerTest, SetPtProc_SpeedChanges_VerifyDirection) { +TEST(FanControllerTest, SetPtProc_SpeedChanges_VerifyDirection) +{ // The fan direction defaults to neutral, because we have no data. Verify // that after this point it appropriately will indicate speeding up or // slowing down based on the RPM values specified. @@ -111,7 +117,7 @@ TEST(FanControllerTest, SetPtProc_SpeedChanges_VerifyDirection) { FanController::CreateFanPid(&z, "fan1", inputs, initial); EXPECT_FALSE(p == nullptr); // Grab pointer for mocking. - FanController *fp = reinterpret_cast<FanController*>(p.get()); + FanController *fp = reinterpret_cast<FanController *>(p.get()); // Fanspeed starts are Neutral. EXPECT_EQ(FanSpeedDirection::NEUTRAL, fp->getFanDirection()); @@ -135,7 +141,8 @@ TEST(FanControllerTest, SetPtProc_SpeedChanges_VerifyDirection) { EXPECT_EQ(FanSpeedDirection::NEUTRAL, fp->getFanDirection()); } -TEST(FanControllerTest, OutputProc_VerifiesIfFailsafeEnabledInputIsIgnored) { +TEST(FanControllerTest, OutputProc_VerifiesIfFailsafeEnabledInputIsIgnored) +{ // Verify that if failsafe mode is enabled and the input value for the fans // is below the failsafe minimum value, the input is not used and the fans // are driven at failsafe RPM. @@ -156,8 +163,8 @@ TEST(FanControllerTest, OutputProc_VerifiesIfFailsafeEnabledInputIsIgnored) { std::unique_ptr<Sensor> s1 = std::make_unique<SensorMock>("fan0", timeout); std::unique_ptr<Sensor> s2 = std::make_unique<SensorMock>("fan1", timeout); // Grab pointers for mocking. - SensorMock *sm1 = reinterpret_cast<SensorMock*>(s1.get()); - SensorMock *sm2 = reinterpret_cast<SensorMock*>(s2.get()); + SensorMock *sm1 = reinterpret_cast<SensorMock *>(s1.get()); + SensorMock *sm2 = reinterpret_cast<SensorMock *>(s2.get()); EXPECT_CALL(z, getSensor(StrEq("fan0"))).WillOnce(Return(s1.get())); EXPECT_CALL(*sm1, write(0.75)); @@ -167,11 +174,13 @@ TEST(FanControllerTest, OutputProc_VerifiesIfFailsafeEnabledInputIsIgnored) { // This is a fan PID, so calling output_proc will try to write this value // to the sensors. - // Setting 50%, will end up being 75% because the sensors are in failsafe mode. + // Setting 50%, will end up being 75% because the sensors are in failsafe + // mode. p->output_proc(50.0); } -TEST(FanControllerTest, OutputProc_BehavesAsExpected) { +TEST(FanControllerTest, OutputProc_BehavesAsExpected) +{ // Verifies that when the system is not in failsafe mode, the input value // to output_proc is used to drive the sensors (fans). @@ -190,8 +199,8 @@ TEST(FanControllerTest, OutputProc_BehavesAsExpected) { std::unique_ptr<Sensor> s1 = std::make_unique<SensorMock>("fan0", timeout); std::unique_ptr<Sensor> s2 = std::make_unique<SensorMock>("fan1", timeout); // Grab pointers for mocking. - SensorMock *sm1 = reinterpret_cast<SensorMock*>(s1.get()); - SensorMock *sm2 = reinterpret_cast<SensorMock*>(s2.get()); + SensorMock *sm1 = reinterpret_cast<SensorMock *>(s1.get()); + SensorMock *sm2 = reinterpret_cast<SensorMock *>(s2.get()); EXPECT_CALL(z, getSensor(StrEq("fan0"))).WillOnce(Return(s1.get())); EXPECT_CALL(*sm1, write(0.5)); @@ -203,7 +212,8 @@ TEST(FanControllerTest, OutputProc_BehavesAsExpected) { p->output_proc(50.0); } -TEST(FanControllerTest, OutputProc_VerifyFailSafeIgnoredIfInputHigher) { +TEST(FanControllerTest, OutputProc_VerifyFailSafeIgnoredIfInputHigher) +{ // If the requested output is higher than the failsafe value, then use the // value provided to output_proc. @@ -222,7 +232,7 @@ TEST(FanControllerTest, OutputProc_VerifyFailSafeIgnoredIfInputHigher) { int64_t timeout = 0; std::unique_ptr<Sensor> s1 = std::make_unique<SensorMock>("fan0", timeout); // Grab pointer for mocking. - SensorMock *sm1 = reinterpret_cast<SensorMock*>(s1.get()); + SensorMock *sm1 = reinterpret_cast<SensorMock *>(s1.get()); // Converting from float to double for expectation. float percent = 80; diff --git a/test/pid_thermalcontroller_unittest.cpp b/test/pid_thermalcontroller_unittest.cpp index b0de1a9..386c779 100644 --- a/test/pid_thermalcontroller_unittest.cpp +++ b/test/pid_thermalcontroller_unittest.cpp @@ -1,17 +1,18 @@ +#include "pid/ec/pid.hpp" #include "pid/thermalcontroller.hpp" +#include "test/zone_mock.hpp" -#include <gmock/gmock.h> -#include <gtest/gtest.h> #include <string> #include <vector> -#include "pid/ec/pid.hpp" -#include "test/zone_mock.hpp" +#include <gmock/gmock.h> +#include <gtest/gtest.h> using ::testing::Return; using ::testing::StrEq; -TEST(ThermalControllerTest, BoringFactoryTest) { +TEST(ThermalControllerTest, BoringFactoryTest) +{ // Verifies building a ThermalPIDController with the factory works as // expected in the boring (uninteresting) case. @@ -21,14 +22,14 @@ TEST(ThermalControllerTest, BoringFactoryTest) { float setpoint = 10.0; ec::pidinfo initial; - std::unique_ptr<PIDController> p = - ThermalController::CreateThermalPid(&z, "therm1", inputs, setpoint, - initial); + std::unique_ptr<PIDController> p = ThermalController::CreateThermalPid( + &z, "therm1", inputs, setpoint, initial); // Success EXPECT_FALSE(p == nullptr); } -TEST(ThermalControllerTest, VerifyFactoryFailsWithZeroInputs) { +TEST(ThermalControllerTest, VerifyFactoryFailsWithZeroInputs) +{ // A thermal controller needs at least one input. ZoneMock z; @@ -37,13 +38,13 @@ TEST(ThermalControllerTest, VerifyFactoryFailsWithZeroInputs) { float setpoint = 10.0; ec::pidinfo initial; - std::unique_ptr<PIDController> p = - ThermalController::CreateThermalPid(&z, "therm1", inputs, setpoint, - initial); + std::unique_ptr<PIDController> p = ThermalController::CreateThermalPid( + &z, "therm1", inputs, setpoint, initial); EXPECT_TRUE(p == nullptr); } -TEST(ThermalControllerTest, VerifyFactoryFailsForMoreThanOneInput) { +TEST(ThermalControllerTest, VerifyFactoryFailsForMoreThanOneInput) +{ // ThermalControllers currently only support one input, so don't let // someone accidentally specify more. @@ -53,13 +54,13 @@ TEST(ThermalControllerTest, VerifyFactoryFailsForMoreThanOneInput) { float setpoint = 10.0; ec::pidinfo initial; - std::unique_ptr<PIDController> p = - ThermalController::CreateThermalPid(&z, "therm1", inputs, setpoint, - initial); + std::unique_ptr<PIDController> p = ThermalController::CreateThermalPid( + &z, "therm1", inputs, setpoint, initial); EXPECT_TRUE(p == nullptr); } -TEST(ThermalControllerTest, InputProc_BehavesAsExpected) { +TEST(ThermalControllerTest, InputProc_BehavesAsExpected) +{ // This test just verifies input_proc behaves as expected. ZoneMock z; @@ -68,9 +69,8 @@ TEST(ThermalControllerTest, InputProc_BehavesAsExpected) { float setpoint = 10.0; ec::pidinfo initial; - std::unique_ptr<PIDController> p = - ThermalController::CreateThermalPid(&z, "therm1", inputs, setpoint, - initial); + std::unique_ptr<PIDController> p = ThermalController::CreateThermalPid( + &z, "therm1", inputs, setpoint, initial); EXPECT_FALSE(p == nullptr); EXPECT_CALL(z, getCachedValue(StrEq("fleeting0"))).WillOnce(Return(5.0)); @@ -78,7 +78,8 @@ TEST(ThermalControllerTest, InputProc_BehavesAsExpected) { EXPECT_EQ(5.0, p->input_proc()); } -TEST(ThermalControllerTest, SetPtProc_BehavesAsExpected) { +TEST(ThermalControllerTest, SetPtProc_BehavesAsExpected) +{ // This test just verifies input_proc behaves as expected. ZoneMock z; @@ -87,15 +88,15 @@ TEST(ThermalControllerTest, SetPtProc_BehavesAsExpected) { float setpoint = 10.0; ec::pidinfo initial; - std::unique_ptr<PIDController> p = - ThermalController::CreateThermalPid(&z, "therm1", inputs, setpoint, - initial); + std::unique_ptr<PIDController> p = ThermalController::CreateThermalPid( + &z, "therm1", inputs, setpoint, initial); EXPECT_FALSE(p == nullptr); EXPECT_EQ(setpoint, p->setpt_proc()); } -TEST(ThermalControllerTest, OutputProc_BehavesAsExpected) { +TEST(ThermalControllerTest, OutputProc_BehavesAsExpected) +{ // This test just verifies input_proc behaves as expected. ZoneMock z; @@ -104,9 +105,8 @@ TEST(ThermalControllerTest, OutputProc_BehavesAsExpected) { float setpoint = 10.0; ec::pidinfo initial; - std::unique_ptr<PIDController> p = - ThermalController::CreateThermalPid(&z, "therm1", inputs, setpoint, - initial); + std::unique_ptr<PIDController> p = ThermalController::CreateThermalPid( + &z, "therm1", inputs, setpoint, initial); EXPECT_FALSE(p == nullptr); float value = 90.0; diff --git a/test/pid_zone_unittest.cpp b/test/pid_zone_unittest.cpp index c511b3c..a8e03a0 100644 --- a/test/pid_zone_unittest.cpp +++ b/test/pid_zone_unittest.cpp @@ -1,28 +1,30 @@ +#include "pid/ec/pid.hpp" #include "pid/zone.hpp" +#include "sensors/manager.hpp" +#include "test/controller_mock.hpp" +#include "test/helpers.hpp" +#include "test/sensor_mock.hpp" #include <chrono> #include <cstring> -#include <gmock/gmock.h> -#include <gtest/gtest.h> #include <sdbusplus/test/sdbus_mock.hpp> #include <vector> -#include "pid/ec/pid.hpp" -#include "sensors/manager.hpp" -#include "test/controller_mock.hpp" -#include "test/sensor_mock.hpp" -#include "test/helpers.hpp" +#include <gmock/gmock.h> +#include <gtest/gtest.h> +using ::testing::_; using ::testing::IsNull; using ::testing::Return; using ::testing::StrEq; -using ::testing::_; static std::string modeInterface = "xyz.openbmc_project.Control.Mode"; -namespace { +namespace +{ -TEST(PidZoneConstructorTest, BoringConstructorTest) { +TEST(PidZoneConstructorTest, BoringConstructorTest) +{ // Build a PID Zone. sdbusplus::SdBusMock sdbus_mock_passive, sdbus_mock_host, sdbus_mock_mode; @@ -32,13 +34,10 @@ TEST(PidZoneConstructorTest, BoringConstructorTest) { EXPECT_CALL(sdbus_mock_host, sd_bus_add_object_manager( - IsNull(), - _, - StrEq("/xyz/openbmc_project/extsensors"))) + IsNull(), _, StrEq("/xyz/openbmc_project/extsensors"))) .WillOnce(Return(0)); - SensorManager m(std::move(bus_mock_passive), - std::move(bus_mock_host)); + SensorManager m(std::move(bus_mock_passive), std::move(bus_mock_host)); bool defer = true; const char *objPath = "/path/"; @@ -48,74 +47,69 @@ TEST(PidZoneConstructorTest, BoringConstructorTest) { int i; std::vector<std::string> properties; - SetupDbusObject(&sdbus_mock_mode, defer, objPath, modeInterface, - properties, &i); + SetupDbusObject(&sdbus_mock_mode, defer, objPath, modeInterface, properties, + &i); PIDZone p(zone, minThermalRpm, failSafePercent, m, bus_mock_mode, objPath, defer); // Success. } -} +} // namespace -class PidZoneTest : public ::testing::Test { - protected: - PidZoneTest() - : property_index(), - properties(), - sdbus_mock_passive(), - sdbus_mock_host(), - sdbus_mock_mode() - { - EXPECT_CALL(sdbus_mock_host, - sd_bus_add_object_manager( - IsNull(), - _, - StrEq("/xyz/openbmc_project/extsensors"))) - .WillOnce(Return(0)); - - auto bus_mock_passive = - sdbusplus::get_mocked_new(&sdbus_mock_passive); - auto bus_mock_host = sdbusplus::get_mocked_new(&sdbus_mock_host); - auto bus_mock_mode = sdbusplus::get_mocked_new(&sdbus_mock_mode); - - // Compiler weirdly not happy about just instantiating mgr(...); - SensorManager m(std::move(bus_mock_passive), - std::move(bus_mock_host)); - mgr = std::move(m); - - SetupDbusObject(&sdbus_mock_mode, defer, objPath, modeInterface, - properties, &property_index); - - zone = std::make_unique<PIDZone>(zoneId, minThermalRpm, - failSafePercent, mgr, - bus_mock_mode, objPath, defer); - } - - // unused - int property_index; - std::vector<std::string> properties; - - sdbusplus::SdBusMock sdbus_mock_passive; - sdbusplus::SdBusMock sdbus_mock_host; - sdbusplus::SdBusMock sdbus_mock_mode; - int64_t zoneId = 1; - float minThermalRpm = 1000.0; - float failSafePercent = 0.75; - bool defer = true; - const char *objPath = "/path/"; - SensorManager mgr; - - std::unique_ptr<PIDZone> zone; +class PidZoneTest : public ::testing::Test +{ + protected: + PidZoneTest() : + property_index(), properties(), sdbus_mock_passive(), sdbus_mock_host(), + sdbus_mock_mode() + { + EXPECT_CALL(sdbus_mock_host, + sd_bus_add_object_manager( + IsNull(), _, StrEq("/xyz/openbmc_project/extsensors"))) + .WillOnce(Return(0)); + + auto bus_mock_passive = sdbusplus::get_mocked_new(&sdbus_mock_passive); + auto bus_mock_host = sdbusplus::get_mocked_new(&sdbus_mock_host); + auto bus_mock_mode = sdbusplus::get_mocked_new(&sdbus_mock_mode); + + // Compiler weirdly not happy about just instantiating mgr(...); + SensorManager m(std::move(bus_mock_passive), std::move(bus_mock_host)); + mgr = std::move(m); + + SetupDbusObject(&sdbus_mock_mode, defer, objPath, modeInterface, + properties, &property_index); + + zone = std::make_unique<PIDZone>(zoneId, minThermalRpm, failSafePercent, + mgr, bus_mock_mode, objPath, defer); + } + + // unused + int property_index; + std::vector<std::string> properties; + + sdbusplus::SdBusMock sdbus_mock_passive; + sdbusplus::SdBusMock sdbus_mock_host; + sdbusplus::SdBusMock sdbus_mock_mode; + int64_t zoneId = 1; + float minThermalRpm = 1000.0; + float failSafePercent = 0.75; + bool defer = true; + const char *objPath = "/path/"; + SensorManager mgr; + + std::unique_ptr<PIDZone> zone; }; -TEST_F(PidZoneTest, GetZoneId_ReturnsExpected) { +TEST_F(PidZoneTest, GetZoneId_ReturnsExpected) +{ // Verifies the zoneId returned is what we expect. EXPECT_EQ(zoneId, zone->getZoneId()); } -TEST_F(PidZoneTest, GetAndSetManualModeTest_BehavesAsExpected) { +TEST_F(PidZoneTest, GetAndSetManualModeTest_BehavesAsExpected) +{ // Verifies that the zone starts in manual mode. Verifies that one can set // the mode. EXPECT_FALSE(zone->getManualMode()); @@ -124,7 +118,8 @@ TEST_F(PidZoneTest, GetAndSetManualModeTest_BehavesAsExpected) { EXPECT_TRUE(zone->getManualMode()); } -TEST_F(PidZoneTest, RpmSetPoints_AddMaxClear_BehaveAsExpected) { +TEST_F(PidZoneTest, RpmSetPoints_AddMaxClear_BehaveAsExpected) +{ // Tests addRPMSetPoint, clearRPMSetPoints, determineMaxRPMRequest // and getMinThermalRpmSetPt. @@ -148,7 +143,8 @@ TEST_F(PidZoneTest, RpmSetPoints_AddMaxClear_BehaveAsExpected) { EXPECT_EQ(zone->getMinThermalRpmSetPt(), zone->getMaxRPMRequest()); } -TEST_F(PidZoneTest, RpmSetPoints_AddBelowMinimum_BehavesAsExpected) { +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. @@ -165,12 +161,14 @@ TEST_F(PidZoneTest, RpmSetPoints_AddBelowMinimum_BehavesAsExpected) { EXPECT_EQ(zone->getMinThermalRpmSetPt(), zone->getMaxRPMRequest()); } -TEST_F(PidZoneTest, GetFailSafePercent_ReturnsExpected) { +TEST_F(PidZoneTest, GetFailSafePercent_ReturnsExpected) +{ // Verify the value used to create the object is stored. EXPECT_EQ(failSafePercent, zone->getFailSafePercent()); } -TEST_F(PidZoneTest, ThermalInputs_FailsafeToValid_ReadsSensors) { +TEST_F(PidZoneTest, ThermalInputs_FailsafeToValid_ReadsSensors) +{ // This test will add a couple thermal inputs, and verify that the zone // initializes into failsafe mode, and will read each sensor. @@ -179,12 +177,12 @@ TEST_F(PidZoneTest, ThermalInputs_FailsafeToValid_ReadsSensors) { std::unique_ptr<Sensor> sensor1 = std::make_unique<SensorMock>(name1, timeout); - SensorMock *sensor_ptr1 = reinterpret_cast<SensorMock*>(sensor1.get()); + SensorMock *sensor_ptr1 = reinterpret_cast<SensorMock *>(sensor1.get()); std::string name2 = "temp2"; std::unique_ptr<Sensor> sensor2 = std::make_unique<SensorMock>(name2, timeout); - SensorMock *sensor_ptr2 = reinterpret_cast<SensorMock*>(sensor2.get()); + SensorMock *sensor_ptr2 = reinterpret_cast<SensorMock *>(sensor2.get()); std::string type = "unchecked"; mgr.addSensor(type, name1, std::move(sensor1)); @@ -222,7 +220,8 @@ TEST_F(PidZoneTest, ThermalInputs_FailsafeToValid_ReadsSensors) { EXPECT_EQ(r2.value, zone->getCachedValue(name2)); } -TEST_F(PidZoneTest, FanInputTest_VerifiesFanValuesCached) { +TEST_F(PidZoneTest, FanInputTest_VerifiesFanValuesCached) +{ // This will add a couple fan inputs, and verify the values are cached. std::string name1 = "fan1"; @@ -230,12 +229,12 @@ TEST_F(PidZoneTest, FanInputTest_VerifiesFanValuesCached) { std::unique_ptr<Sensor> sensor1 = std::make_unique<SensorMock>(name1, timeout); - SensorMock *sensor_ptr1 = reinterpret_cast<SensorMock*>(sensor1.get()); + SensorMock *sensor_ptr1 = reinterpret_cast<SensorMock *>(sensor1.get()); std::string name2 = "fan2"; std::unique_ptr<Sensor> sensor2 = std::make_unique<SensorMock>(name2, timeout); - SensorMock *sensor_ptr2 = reinterpret_cast<SensorMock*>(sensor2.get()); + SensorMock *sensor_ptr2 = reinterpret_cast<SensorMock *>(sensor2.get()); std::string type = "unchecked"; mgr.addSensor(type, name1, std::move(sensor1)); @@ -268,7 +267,8 @@ TEST_F(PidZoneTest, FanInputTest_VerifiesFanValuesCached) { EXPECT_EQ(r2.value, zone->getCachedValue(name2)); } -TEST_F(PidZoneTest, ThermalInput_ValueTimeoutEntersFailSafeMode) { +TEST_F(PidZoneTest, ThermalInput_ValueTimeoutEntersFailSafeMode) +{ // On the second updateSensors call, the updated timestamp will be beyond // the timeout limit. @@ -277,12 +277,12 @@ TEST_F(PidZoneTest, ThermalInput_ValueTimeoutEntersFailSafeMode) { std::string name1 = "temp1"; std::unique_ptr<Sensor> sensor1 = std::make_unique<SensorMock>(name1, timeout); - SensorMock *sensor_ptr1 = reinterpret_cast<SensorMock*>(sensor1.get()); + SensorMock *sensor_ptr1 = reinterpret_cast<SensorMock *>(sensor1.get()); std::string name2 = "temp2"; std::unique_ptr<Sensor> sensor2 = std::make_unique<SensorMock>(name2, timeout); - SensorMock *sensor_ptr2 = reinterpret_cast<SensorMock*>(sensor2.get()); + SensorMock *sensor_ptr2 = reinterpret_cast<SensorMock *>(sensor2.get()); std::string type = "unchecked"; mgr.addSensor(type, name1, std::move(sensor1)); @@ -327,7 +327,8 @@ TEST_F(PidZoneTest, ThermalInput_ValueTimeoutEntersFailSafeMode) { EXPECT_TRUE(zone->getFailSafeMode()); } -TEST_F(PidZoneTest, GetSensorTest_ReturnsExpected) { +TEST_F(PidZoneTest, GetSensorTest_ReturnsExpected) +{ // One can grab a sensor from the manager through the zone. int64_t timeout = 1; @@ -335,7 +336,7 @@ TEST_F(PidZoneTest, GetSensorTest_ReturnsExpected) { std::string name1 = "temp1"; std::unique_ptr<Sensor> sensor1 = std::make_unique<SensorMock>(name1, timeout); - SensorMock *sensor_ptr1 = reinterpret_cast<SensorMock*>(sensor1.get()); + SensorMock *sensor_ptr1 = reinterpret_cast<SensorMock *>(sensor1.get()); std::string type = "unchecked"; mgr.addSensor(type, name1, std::move(sensor1)); @@ -347,17 +348,18 @@ TEST_F(PidZoneTest, GetSensorTest_ReturnsExpected) { EXPECT_EQ(mgr.getSensor(name1), zone->getSensor(name1)); } -TEST_F(PidZoneTest, AddThermalPIDTest_VerifiesThermalPIDsProcessed) { +TEST_F(PidZoneTest, AddThermalPIDTest_VerifiesThermalPIDsProcessed) +{ // Tests adding a thermal PID controller to the zone, and verifies it's // touched during processing. std::unique_ptr<PIDController> tpid = std::make_unique<ControllerMock>("thermal1", zone.get()); - ControllerMock *tmock = reinterpret_cast<ControllerMock*>(tpid.get()); + ControllerMock *tmock = reinterpret_cast<ControllerMock *>(tpid.get()); // Access the internal pid configuration to clear it out (unrelated to the // test). - ec::pid_info_t* info = tpid->get_pid_info(); + ec::pid_info_t *info = tpid->get_pid_info(); std::memset(info, 0x00, sizeof(ec::pid_info_t)); zone->addThermalPID(std::move(tpid)); @@ -371,17 +373,18 @@ TEST_F(PidZoneTest, AddThermalPIDTest_VerifiesThermalPIDsProcessed) { zone->process_thermals(); } -TEST_F(PidZoneTest, AddFanPIDTest_VerifiesFanPIDsProcessed) { +TEST_F(PidZoneTest, AddFanPIDTest_VerifiesFanPIDsProcessed) +{ // Tests adding a fan PID controller to the zone, and verifies it's // touched during processing. std::unique_ptr<PIDController> tpid = std::make_unique<ControllerMock>("fan1", zone.get()); - ControllerMock *tmock = reinterpret_cast<ControllerMock*>(tpid.get()); + ControllerMock *tmock = reinterpret_cast<ControllerMock *>(tpid.get()); // Access the internal pid configuration to clear it out (unrelated to the // test). - ec::pid_info_t* info = tpid->get_pid_info(); + ec::pid_info_t *info = tpid->get_pid_info(); std::memset(info, 0x00, sizeof(ec::pid_info_t)); zone->addFanPID(std::move(tpid)); @@ -394,15 +397,15 @@ TEST_F(PidZoneTest, AddFanPIDTest_VerifiesFanPIDsProcessed) { zone->process_fans(); } -TEST_F(PidZoneTest, ManualModeDbusTest_VerifySetManualBehavesAsExpected) { +TEST_F(PidZoneTest, ManualModeDbusTest_VerifySetManualBehavesAsExpected) +{ // The manual(bool) method is inherited from the dbus mode interface. // Verifies that someone doesn't remove the internal call to the dbus // object from which we're inheriting. EXPECT_CALL(sdbus_mock_mode, - sd_bus_emit_properties_changed_strv(IsNull(), StrEq(objPath), - StrEq(modeInterface), - NotNull())) + sd_bus_emit_properties_changed_strv( + IsNull(), StrEq(objPath), StrEq(modeInterface), NotNull())) .WillOnce(Invoke([&](sd_bus *bus, const char *path, const char *interface, char **names) { EXPECT_STREQ("Manual", names[0]); @@ -415,7 +418,8 @@ TEST_F(PidZoneTest, ManualModeDbusTest_VerifySetManualBehavesAsExpected) { EXPECT_TRUE(zone->getManualMode()); } -TEST_F(PidZoneTest, FailsafeDbusTest_VerifiesReturnsExpected) { +TEST_F(PidZoneTest, FailsafeDbusTest_VerifiesReturnsExpected) +{ // This property is implemented by us as read-only, such that trying to // write to it will have no effect. EXPECT_EQ(zone->failSafe(), zone->getFailSafeMode()); diff --git a/test/readinterface_mock.hpp b/test/readinterface_mock.hpp index b8ab5ac..1d2c82d 100644 --- a/test/readinterface_mock.hpp +++ b/test/readinterface_mock.hpp @@ -6,8 +6,8 @@ class ReadInterfaceMock : public ReadInterface { - public: - virtual ~ReadInterfaceMock() = default; + public: + virtual ~ReadInterfaceMock() = default; - MOCK_METHOD0(read, ReadReturn()); + MOCK_METHOD0(read, ReadReturn()); }; diff --git a/test/sensor_host_unittest.cpp b/test/sensor_host_unittest.cpp index 5e8af4b..99d4924 100644 --- a/test/sensor_host_unittest.cpp +++ b/test/sensor_host_unittest.cpp @@ -1,25 +1,27 @@ #include "sensors/host.hpp" +#include "test/helpers.hpp" #include <chrono> -#include <gmock/gmock.h> -#include <gtest/gtest.h> #include <memory> #include <sdbusplus/test/sdbus_mock.hpp> #include <string> #include <vector> -#include "test/helpers.hpp" +#include <gmock/gmock.h> +#include <gtest/gtest.h> using ::testing::IsNull; using ::testing::Return; using ::testing::StrEq; -TEST(HostSensorTest, BoringConstructorTest) { +TEST(HostSensorTest, BoringConstructorTest) +{ // WARN: The host sensor is not presently meant to be created this way, // TODO: Can I move the constructor into private? } -TEST(HostSensorTest, CreateHostTempSensorTest) { +TEST(HostSensorTest, CreateHostTempSensorTest) +{ // The normal case for this sensor is to be a temperature sensor, where // the value is treated as a margin sensor. @@ -40,24 +42,19 @@ TEST(HostSensorTest, CreateHostTempSensorTest) { // The CreateTemp updates all the properties, however, only Scale is set // to non-default. - SetupDbusObject( - &sdbus_mock, - defer, - objPath, - interface, - properties, - &i); + SetupDbusObject(&sdbus_mock, defer, objPath, interface, properties, &i); // This is called during object destruction. EXPECT_CALL(sdbus_mock, sd_bus_emit_object_removed(IsNull(), StrEq(objPath))) .WillOnce(Return(0)); - std::unique_ptr<Sensor> s = HostSensor::CreateTemp( - name, timeout, bus_mock, objPath, defer); + std::unique_ptr<Sensor> s = + HostSensor::CreateTemp(name, timeout, bus_mock, objPath, defer); } -TEST(HostSensorTest, VerifyWriteThenReadMatches) { +TEST(HostSensorTest, VerifyWriteThenReadMatches) +{ // Verify that when value is updated, the information matches // what we expect when read back. @@ -76,20 +73,14 @@ TEST(HostSensorTest, VerifyWriteThenReadMatches) { std::vector<std::string> properties = {"Scale"}; int i; - SetupDbusObject( - &sdbus_mock, - defer, - objPath, - interface, - properties, - &i); + SetupDbusObject(&sdbus_mock, defer, objPath, interface, properties, &i); EXPECT_CALL(sdbus_mock, sd_bus_emit_object_removed(IsNull(), StrEq(objPath))) .WillOnce(Return(0)); - std::unique_ptr<Sensor> s = HostSensor::CreateTemp( - name, timeout, bus_mock, objPath, defer); + std::unique_ptr<Sensor> s = + HostSensor::CreateTemp(name, timeout, bus_mock, objPath, defer); // Value is updated from dbus calls only (normally). HostSensor *hs = static_cast<HostSensor *>(s.get()); @@ -99,20 +90,13 @@ TEST(HostSensorTest, VerifyWriteThenReadMatches) { EXPECT_EQ(r.value, 0); EXPECT_CALL(sdbus_mock, - sd_bus_emit_properties_changed_strv( - IsNull(), - StrEq(objPath), - StrEq(interface), - NotNull())) - .WillOnce( - Invoke([=](sd_bus *bus, - const char *path, - const char *interface, - char **names) { - EXPECT_STREQ("Value", names[0]); - return 0; - }) - ); + sd_bus_emit_properties_changed_strv( + IsNull(), StrEq(objPath), StrEq(interface), NotNull())) + .WillOnce(Invoke([=](sd_bus *bus, const char *path, + const char *interface, char **names) { + EXPECT_STREQ("Value", names[0]); + return 0; + })); std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now(); @@ -121,8 +105,9 @@ TEST(HostSensorTest, VerifyWriteThenReadMatches) { r = hs->read(); EXPECT_EQ(r.value, new_value * 0.001); - auto duration = std::chrono::duration_cast<std::chrono::seconds>( - t1 - r.updated).count(); + auto duration = + std::chrono::duration_cast<std::chrono::seconds>(t1 - r.updated) + .count(); // Verify it was updated within the last second. EXPECT_TRUE(duration < 1); diff --git a/test/sensor_manager_unittest.cpp b/test/sensor_manager_unittest.cpp index eed26cd..54253ac 100644 --- a/test/sensor_manager_unittest.cpp +++ b/test/sensor_manager_unittest.cpp @@ -1,17 +1,18 @@ #include "sensors/manager.hpp" +#include "test/sensor_mock.hpp" -#include <gmock/gmock.h> -#include <gtest/gtest.h> #include <sdbusplus/test/sdbus_mock.hpp> -#include "test/sensor_mock.hpp" +#include <gmock/gmock.h> +#include <gtest/gtest.h> using ::testing::_; using ::testing::IsNull; using ::testing::Return; using ::testing::StrEq; -TEST(SensorManagerTest, BoringConstructorTest) { +TEST(SensorManagerTest, BoringConstructorTest) +{ // Build a boring SensorManager. sdbusplus::SdBusMock sdbus_mock_passive, sdbus_mock_host; @@ -20,16 +21,15 @@ TEST(SensorManagerTest, BoringConstructorTest) { EXPECT_CALL(sdbus_mock_host, sd_bus_add_object_manager( - IsNull(), - _, - StrEq("/xyz/openbmc_project/extsensors"))) + IsNull(), _, StrEq("/xyz/openbmc_project/extsensors"))) .WillOnce(Return(0)); SensorManager s(std::move(bus_mock_passive), std::move(bus_mock_host)); // Success } -TEST(SensorManagerTest, AddSensorInvalidTypeTest) { +TEST(SensorManagerTest, AddSensorInvalidTypeTest) +{ // AddSensor doesn't validate the type of sensor you're adding, because // ultimately it doesn't care -- but if we decide to change that this // test will start failing :D @@ -40,9 +40,7 @@ TEST(SensorManagerTest, AddSensorInvalidTypeTest) { EXPECT_CALL(sdbus_mock_host, sd_bus_add_object_manager( - IsNull(), - _, - StrEq("/xyz/openbmc_project/extsensors"))) + IsNull(), _, StrEq("/xyz/openbmc_project/extsensors"))) .WillOnce(Return(0)); SensorManager s(std::move(bus_mock_passive), std::move(bus_mock_host)); diff --git a/test/sensor_mock.hpp b/test/sensor_mock.hpp index 2b63d02..2cc8d28 100644 --- a/test/sensor_mock.hpp +++ b/test/sensor_mock.hpp @@ -1,18 +1,19 @@ #pragma once -#include <gmock/gmock.h> - #include "interfaces.hpp" #include "sensors/sensor.hpp" +#include <gmock/gmock.h> + class SensorMock : public Sensor { - public: - virtual ~SensorMock() = default; + public: + virtual ~SensorMock() = default; - SensorMock(const std::string& name, int64_t timeout) - : Sensor(name, timeout) {} + SensorMock(const std::string& name, int64_t timeout) : Sensor(name, timeout) + { + } - MOCK_METHOD0(read, ReadReturn()); - MOCK_METHOD1(write, void(double)); + MOCK_METHOD0(read, ReadReturn()); + MOCK_METHOD1(write, void(double)); }; diff --git a/test/sensor_pluggable_unittest.cpp b/test/sensor_pluggable_unittest.cpp index 1e32230..015b911 100644 --- a/test/sensor_pluggable_unittest.cpp +++ b/test/sensor_pluggable_unittest.cpp @@ -1,15 +1,16 @@ #include "sensors/pluggable.hpp" +#include "test/readinterface_mock.hpp" +#include "test/writeinterface_mock.hpp" #include <chrono> + #include <gmock/gmock.h> #include <gtest/gtest.h> -#include "test/readinterface_mock.hpp" -#include "test/writeinterface_mock.hpp" - using ::testing::Invoke; -TEST(PluggableSensorTest, BoringConstructorTest) { +TEST(PluggableSensorTest, BoringConstructorTest) +{ // Build a boring Pluggable Sensor. int64_t min = 0; @@ -26,7 +27,8 @@ TEST(PluggableSensorTest, BoringConstructorTest) { // Successfully created it. } -TEST(PluggableSensorTest, TryReadingTest) { +TEST(PluggableSensorTest, TryReadingTest) +{ // Verify calling read, calls the ReadInterface. int64_t min = 0; @@ -47,12 +49,7 @@ TEST(PluggableSensorTest, TryReadingTest) { r.value = 0.1; r.updated = std::chrono::high_resolution_clock::now(); - EXPECT_CALL(*rip, read()) - .WillOnce( - Invoke([&](void) { - return r; - }) - ); + EXPECT_CALL(*rip, read()).WillOnce(Invoke([&](void) { return r; })); // TODO(venture): Implement comparison operator for ReadReturn. ReadReturn v = p.read(); @@ -60,7 +57,8 @@ TEST(PluggableSensorTest, TryReadingTest) { EXPECT_EQ(r.updated, v.updated); } -TEST(PluggableSensorTest, TryWritingTest) { +TEST(PluggableSensorTest, TryWritingTest) +{ // Verify calling write, calls the WriteInterface. int64_t min = 0; diff --git a/test/util_unittest.cpp b/test/util_unittest.cpp index 8abf1eb..6fe77b2 100644 --- a/test/util_unittest.cpp +++ b/test/util_unittest.cpp @@ -1,69 +1,80 @@ #include "util.hpp" +#include <string> + #include <gmock/gmock.h> #include <gtest/gtest.h> -#include <string> -TEST(UtilTest, WriteTypeEmptyString_ReturnsNONE) { +TEST(UtilTest, WriteTypeEmptyString_ReturnsNONE) +{ // Verify it responds to an empty string. EXPECT_EQ(IOInterfaceType::NONE, GetWriteInterfaceType("")); } -TEST(UtilTest, WriteTypeNonePath_ReturnsNONE) { +TEST(UtilTest, WriteTypeNonePath_ReturnsNONE) +{ // Verify it responds to a path of "None" EXPECT_EQ(IOInterfaceType::NONE, GetWriteInterfaceType("None")); } -TEST(UtilTest, WriteTypeSysfs_ReturnsSYSFS) { +TEST(UtilTest, WriteTypeSysfs_ReturnsSYSFS) +{ // Verify the sysfs type is determined with an expected path std::string path = "/sys/devices/asfdadsf"; EXPECT_EQ(IOInterfaceType::SYSFS, GetWriteInterfaceType(path)); } -TEST(UtilTest, WriteTypeUnknown_ReturnsUNKNOWN) { +TEST(UtilTest, WriteTypeUnknown_ReturnsUNKNOWN) +{ // Verify it reports unknown by default. std::string path = "/xyz/openbmc_project"; EXPECT_EQ(IOInterfaceType::UNKNOWN, GetWriteInterfaceType(path)); } -TEST(UtilTest, ReadTypeEmptyString_ReturnsNONE) { +TEST(UtilTest, ReadTypeEmptyString_ReturnsNONE) +{ // Verify it responds to an empty string. EXPECT_EQ(IOInterfaceType::NONE, GetReadInterfaceType("")); } -TEST(UtilTest, ReadTypeNonePath_ReturnsNONE) { +TEST(UtilTest, ReadTypeNonePath_ReturnsNONE) +{ // Verify it responds to a path of "None" EXPECT_EQ(IOInterfaceType::NONE, GetReadInterfaceType("None")); } -TEST(UtilTest, ReadTypeExternalSensors_ReturnsEXTERNAL) { +TEST(UtilTest, ReadTypeExternalSensors_ReturnsEXTERNAL) +{ // Verify it responds to a path that represents a host sensor. std::string path = "/xyz/openbmc_project/extsensors/temperature/fleeting0"; EXPECT_EQ(IOInterfaceType::EXTERNAL, GetReadInterfaceType(path)); } -TEST(UtilTest, ReadTypeOpenBMCSensor_ReturnsDBUSPASSIVE) { +TEST(UtilTest, ReadTypeOpenBMCSensor_ReturnsDBUSPASSIVE) +{ // Verify it responds to a path that represents a dbus sensor. std::string path = "/xyz/openbmc_project/sensors/fan_tach/fan1"; EXPECT_EQ(IOInterfaceType::DBUSPASSIVE, GetReadInterfaceType(path)); } -TEST(UtilTest, ReadTypeSysfsPath_ReturnsSYSFS) { +TEST(UtilTest, ReadTypeSysfsPath_ReturnsSYSFS) +{ // Verify the sysfs type is determined with an expected path std::string path = "/sys/devices/asdf/asdf0"; EXPECT_EQ(IOInterfaceType::SYSFS, GetReadInterfaceType(path)); } -TEST(UtilTest, ReadTypeUnknownDefault_ReturnsUNKNOWN) { +TEST(UtilTest, ReadTypeUnknownDefault_ReturnsUNKNOWN) +{ // Verify it reports unknown by default. std::string path = "asdf09as0df9a0fd"; diff --git a/test/writeinterface_mock.hpp b/test/writeinterface_mock.hpp index 6aaa4de..6e5b350 100644 --- a/test/writeinterface_mock.hpp +++ b/test/writeinterface_mock.hpp @@ -6,11 +6,12 @@ class WriteInterfaceMock : public WriteInterface { - public: - virtual ~WriteInterfaceMock() = default; + public: + virtual ~WriteInterfaceMock() = default; - WriteInterfaceMock(int64_t min, int64_t max) - : WriteInterface(min, max) {} + WriteInterfaceMock(int64_t min, int64_t max) : WriteInterface(min, max) + { + } - MOCK_METHOD1(write, void(double)); + MOCK_METHOD1(write, void(double)); }; diff --git a/test/zone_mock.hpp b/test/zone_mock.hpp index f08c68f..8dbf24a 100644 --- a/test/zone_mock.hpp +++ b/test/zone_mock.hpp @@ -1,19 +1,20 @@ #pragma once -#include <gmock/gmock.h> +#include "pid/zone.hpp" + #include <string> -#include "pid/zone.hpp" +#include <gmock/gmock.h> class ZoneMock : public ZoneInterface { - public: - virtual ~ZoneMock() = default; + public: + virtual ~ZoneMock() = default; - MOCK_METHOD1(getCachedValue, double(const std::string&)); - MOCK_METHOD1(addRPMSetPoint, void(float)); - MOCK_CONST_METHOD0(getMaxRPMRequest, float()); - MOCK_CONST_METHOD0(getFailSafeMode, bool()); - MOCK_CONST_METHOD0(getFailSafePercent, float()); - MOCK_METHOD1(getSensor, Sensor*(std::string)); + MOCK_METHOD1(getCachedValue, double(const std::string&)); + MOCK_METHOD1(addRPMSetPoint, void(float)); + MOCK_CONST_METHOD0(getMaxRPMRequest, float()); + MOCK_CONST_METHOD0(getFailSafeMode, bool()); + MOCK_CONST_METHOD0(getFailSafePercent, float()); + MOCK_METHOD1(getSensor, Sensor*(std::string)); }; diff --git a/threads/busthread.cpp b/threads/busthread.cpp index f007bf9..59704e3 100644 --- a/threads/busthread.cpp +++ b/threads/busthread.cpp @@ -14,10 +14,9 @@ * limitations under the License. */ -#include <string> - #include "busthread.hpp" +#include <string> void BusThread(struct ThreadParams& params) { @@ -14,18 +14,16 @@ * limitations under the License. */ -#include <string> - #include "util.hpp" +#include <string> static constexpr auto external_sensor = - "/xyz/openbmc_project/extsensors/"; // type/ + "/xyz/openbmc_project/extsensors/"; // type/ static constexpr auto openbmc_sensor = "/xyz/openbmc_project/"; // type/ static constexpr auto dbus_pwm = "/xyz/openbmc_project/control/fanpwm/"; static constexpr auto sysfs = "/sys/"; - IOInterfaceType GetWriteInterfaceType(const std::string& path) { if (path.empty() || "None" == path) @@ -71,4 +69,3 @@ IOInterfaceType GetReadInterfaceType(const std::string& path) return IOInterfaceType::UNKNOWN; } - @@ -7,8 +7,8 @@ * but -- how would it know whether to use Control.FanSpeed or Control.FanPwm? * * One could get the interface list for the object and search for Control.* - * but, it needs to know the maximum, minimum. The only sensors it wants to write - * in this code base are Fans... + * but, it needs to know the maximum, minimum. The only sensors it wants to + * write in this code base are Fans... */ enum class IOInterfaceType { @@ -24,4 +24,3 @@ enum class IOInterfaceType IOInterfaceType GetWriteInterfaceType(const std::string& path); IOInterfaceType GetReadInterfaceType(const std::string& path); - |

