clang-format: re-format for clang-18
clang-format-18 isn't compatible with the clang-format-17 output, so we
need to reformat the code with the latest version. The way clang-18
handles lambda formatting also changed, so we have made changes to the
organization default style format to better handle lambda formatting.
See I5e08687e696dd240402a2780158664b7113def0e for updated style.
See Iea0776aaa7edd483fa395e23de25ebf5a6288f71 for clang-18 enablement.
Change-Id: If87740ef153661e338448c9de753cbd61fd164eb
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
diff --git a/.clang-format b/.clang-format
index d43e884..28e3328 100644
--- a/.clang-format
+++ b/.clang-format
@@ -87,7 +87,7 @@
IndentWrappedFunctionNames: true
InsertNewlineAtEOF: true
KeepEmptyLinesAtTheStartOfBlocks: false
-LambdaBodyIndentation: OuterScope
+LambdaBodyIndentation: Signature
LineEnding: LF
MacroBlockBegin: ''
MacroBlockEnd: ''
@@ -98,13 +98,14 @@
ObjCSpaceBeforeProtocolList: true
PackConstructorInitializers: BinPack
PenaltyBreakAssignment: 25
-PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakBeforeFirstCallParameter: 50
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
+PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
-PenaltyIndentedWhitespace: 0
+PenaltyIndentedWhitespace: 1
PointerAlignment: Left
QualifierAlignment: Left
ReferenceAlignment: Left
diff --git a/health_metric.cpp b/health_metric.cpp
index ad74597..13a5789 100644
--- a/health_metric.cpp
+++ b/health_metric.cpp
@@ -13,8 +13,8 @@
using association_t = std::tuple<std::string, std::string, std::string>;
-auto HealthMetric::getPath(MType type, std::string name, SubType subType)
- -> std::string
+auto HealthMetric::getPath(MType type, std::string name,
+ SubType subType) -> std::string
{
std::string path;
switch (subType)
@@ -59,8 +59,9 @@
static constexpr auto nameDelimiter = "_";
auto storageType = name.substr(
name.find_last_of(nameDelimiter) + 1, name.length());
- std::ranges::for_each(storageType,
- [](auto& c) { c = std::tolower(c); });
+ std::ranges::for_each(storageType, [](auto& c) {
+ c = std::tolower(c);
+ });
return std::string(BmcPath) + "/" + PathIntf::storage + "/" +
storageType;
}
@@ -212,8 +213,8 @@
{
return true;
}
- auto changed = std::abs((value.current - lastNotifiedValue) /
- lastNotifiedValue * 100.0);
+ auto changed = std::abs(
+ (value.current - lastNotifiedValue) / lastNotifiedValue * 100.0);
if (changed >= config.hysteresis)
{
lastNotifiedValue = value.current;
@@ -239,8 +240,8 @@
return;
}
- double average = (std::accumulate(history.begin(), history.end(), 0.0)) /
- history.size();
+ double average =
+ (std::accumulate(history.begin(), history.end(), 0.0)) / history.size();
value.current = average;
checkThresholds(value);
}
diff --git a/health_metric_collection.hpp b/health_metric_collection.hpp
index d1fd4fb..f8aac92 100644
--- a/health_metric_collection.hpp
+++ b/health_metric_collection.hpp
@@ -15,8 +15,7 @@
HealthMetricCollection(sdbusplus::bus_t& bus, MetricIntf::Type type,
const configs_t& configs,
MetricIntf::paths_t& bmcPaths) :
- bus(bus),
- type(type), configs(configs)
+ bus(bus), type(type), configs(configs)
{
create(bmcPaths);
}
diff --git a/health_metric_config.cpp b/health_metric_config.cpp
index c3b80ba..bb52331 100644
--- a/health_metric_config.cpp
+++ b/health_metric_config.cpp
@@ -43,11 +43,11 @@
{"Warning", ThresholdIntf::Type::Warning}};
// Valid metrics from config
-static const auto validTypes =
- std::unordered_map<std::string, Type>{{"CPU", Type::cpu},
- {"Memory", Type::memory},
- {"Storage", Type::storage},
- {"Inode", Type::inode}};
+static const auto validTypes = std::unordered_map<std::string, Type>{
+ {"CPU", Type::cpu},
+ {"Memory", Type::memory},
+ {"Storage", Type::storage},
+ {"Inode", Type::inode}};
// Valid submetrics from config
static const auto validSubTypes = std::unordered_map<std::string, SubType>{
@@ -73,8 +73,8 @@
/** Deserialize a HealthMetric from JSON. */
void from_json(const json& j, HealthMetric& self)
{
- self.windowSize = j.value("Window_size",
- HealthMetric::defaults::windowSize);
+ self.windowSize =
+ j.value("Window_size", HealthMetric::defaults::windowSize);
self.hysteresis = j.value("Hysteresis", HealthMetric::defaults::hysteresis);
// Path is only valid for storage
self.path = j.value("Path", "");
@@ -101,8 +101,8 @@
static constexpr auto keyDelimiter = "_";
std::string typeStr = key.substr(0, key.find_first_of(keyDelimiter));
- std::string boundStr = key.substr(key.find_last_of(keyDelimiter) + 1,
- key.length());
+ std::string boundStr =
+ key.substr(key.find_last_of(keyDelimiter) + 1, key.length());
self.thresholds.emplace(
std::make_tuple(validThresholdTypes.at(typeStr),
@@ -184,8 +184,8 @@
config.name = name;
auto subType = validSubTypes.find(name);
- config.subType = (subType != validSubTypes.end() ? subType->second
- : SubType::NA);
+ config.subType =
+ (subType != validSubTypes.end() ? subType->second : SubType::NA);
configs[type->second].emplace_back(std::move(config));
}
diff --git a/test/test_health_metric.cpp b/test/test_health_metric.cpp
index 47a840a..067ced0 100644
--- a/test/test_health_metric.cpp
+++ b/test/test_health_metric.cpp
@@ -28,8 +28,8 @@
static constexpr auto busName = "xyz.openbmc_project.test.HealthMon";
const std::set<std::string> properties = {"Value", "MaxValue", "MinValue",
"Unit"};
- const std::string objPath = std::string(PathIntf::value) + "/bmc/" +
- PathIntf::kernel_cpu;
+ const std::string objPath =
+ std::string(PathIntf::value) + "/bmc/" + PathIntf::kernel_cpu;
ConfigIntf::HealthMetric config;
void SetUp() override
@@ -66,26 +66,26 @@
.WillRepeatedly(Invoke(
[&]([[maybe_unused]] sd_bus* bus, [[maybe_unused]] const char* path,
[[maybe_unused]] const char* interface, const char** names) {
- EXPECT_THAT(properties, testing::Contains(names[0]));
- return 0;
- }));
+ EXPECT_THAT(properties, testing::Contains(names[0]));
+ return 0;
+ }));
EXPECT_CALL(sdbusMock, sd_bus_emit_properties_changed_strv(
IsNull(), StrEq(objPath),
StrEq(ThresholdIntf::interface), NotNull()))
.WillRepeatedly(Invoke(
[&]([[maybe_unused]] sd_bus* bus, [[maybe_unused]] const char* path,
[[maybe_unused]] const char* interface, const char** names) {
- EXPECT_THAT(thresholdProperties, testing::Contains(names[0]));
- return 0;
- }));
+ EXPECT_THAT(thresholdProperties, testing::Contains(names[0]));
+ return 0;
+ }));
EXPECT_CALL(sdbusMock,
sd_bus_message_new_signal(_, _, StrEq(objPath),
StrEq(ThresholdIntf::interface),
StrEq("AssertionChanged")))
.Times(4);
- auto metric = std::make_unique<HealthMetric>(bus, Type::cpu, config,
- paths_t());
+ auto metric =
+ std::make_unique<HealthMetric>(bus, Type::cpu, config, paths_t());
// Exceed the critical threshold
metric->update(MValue(1351, 1500));
// Go below critical threshold but above warning threshold
diff --git a/test/test_health_metric_collection.cpp b/test/test_health_metric_collection.cpp
index 7086369..8135eb0 100644
--- a/test/test_health_metric_collection.cpp
+++ b/test/test_health_metric_collection.cpp
@@ -98,16 +98,16 @@
.WillRepeatedly(Invoke(
[&]([[maybe_unused]] sd_bus* bus, [[maybe_unused]] const char* path,
[[maybe_unused]] const char* interface, const char** names) {
- // Test no signal generation for metric init properties
- const std::set<std::string> metricInitProperties = {"MaxValue",
- "MinValue", "Unit"};
- EXPECT_THAT(metricInitProperties,
- testing::Not(testing::Contains(names[0])));
- // Test signal generated for Value property set
- const std::set<std::string> metricSetProperties = {"Value"};
- EXPECT_THAT(metricSetProperties, testing::Contains(names[0]));
- return 0;
- }));
+ // Test no signal generation for metric init properties
+ const std::set<std::string> metricInitProperties = {
+ "MaxValue", "MinValue", "Unit"};
+ EXPECT_THAT(metricInitProperties,
+ testing::Not(testing::Contains(names[0])));
+ // Test signal generated for Value property set
+ const std::set<std::string> metricSetProperties = {"Value"};
+ EXPECT_THAT(metricSetProperties, testing::Contains(names[0]));
+ return 0;
+ }));
EXPECT_CALL(sdbusMock,
sd_bus_emit_properties_changed_strv(
@@ -115,12 +115,12 @@
.WillRepeatedly(Invoke(
[&]([[maybe_unused]] sd_bus* bus, [[maybe_unused]] const char* path,
[[maybe_unused]] const char* interface, const char** names) {
- // Test signal generated for Value property set
- EXPECT_STREQ("Value", names[0]);
- // Test no signal generation for threshold asserted
- EXPECT_STRNE("Asserted", names[0]);
- return 0;
- }));
+ // Test signal generated for Value property set
+ EXPECT_STREQ("Value", names[0]);
+ // Test no signal generation for threshold asserted
+ EXPECT_STRNE("Asserted", names[0]);
+ return 0;
+ }));
createCollection();
}
@@ -138,9 +138,9 @@
.WillRepeatedly(Invoke(
[&]([[maybe_unused]] sd_bus* bus, [[maybe_unused]] const char* path,
[[maybe_unused]] const char* interface, const char** names) {
- EXPECT_THAT("Value", StrEq(names[0]));
- return 0;
- }));
+ EXPECT_THAT("Value", StrEq(names[0]));
+ return 0;
+ }));
// Test threshold asserted property change
EXPECT_CALL(sdbusMock,
@@ -149,11 +149,12 @@
.WillRepeatedly(Invoke(
[&]([[maybe_unused]] sd_bus* bus, [[maybe_unused]] const char* path,
[[maybe_unused]] const char* interface, const char** names) {
- // Test signal generation for threshold properties set
- const std::set<std::string> thresholdProperties = {"Value", "Asserted"};
- EXPECT_THAT(thresholdProperties, testing::Contains(names[0]));
- return 0;
- }));
+ // Test signal generation for threshold properties set
+ const std::set<std::string> thresholdProperties = {"Value",
+ "Asserted"};
+ EXPECT_THAT(thresholdProperties, testing::Contains(names[0]));
+ return 0;
+ }));
// Test AssertionChanged signal generation
EXPECT_CALL(sdbusMock,