aboutsummaryrefslogtreecommitdiff
path: root/cpp/watchdog
diff options
context:
space:
mode:
authorLakshman Annadorai <lakshmana@google.com>2021-06-09 17:42:51 +0000
committerLakshman Annadorai <lakshmana@google.com>2021-06-09 21:27:45 +0000
commitf6c9a60b3ee9d11a061af53f2b9d870c2f64f8f4 (patch)
tree633f97b7779f9c871079597ad40cd34f90aae995 /cpp/watchdog
parentb62fb474b6eef1c948951b0b97103fad103abba3 (diff)
downloadCar-f6c9a60b3ee9d11a061af53f2b9d870c2f64f8f4.tar.gz
Revert^2 "Convert per state thresholds read from XML configs."
b62fb474b6eef1c948951b0b97103fad103abba3 Test: atest libwatchdog_test Bug: 186445673 Change-Id: I5ccfb50af9260821001340e0ba373d267d804346
Diffstat (limited to 'cpp/watchdog')
-rw-r--r--cpp/watchdog/server/src/OveruseConfigurationXmlHelper.cpp13
-rw-r--r--cpp/watchdog/server/src/OveruseConfigurationXmlHelper.h2
-rw-r--r--cpp/watchdog/server/tests/OveruseConfigurationXmlHelperTest.cpp31
-rw-r--r--cpp/watchdog/server/tests/data/valid_overuse_third_party_configuration.xml2
4 files changed, 31 insertions, 17 deletions
diff --git a/cpp/watchdog/server/src/OveruseConfigurationXmlHelper.cpp b/cpp/watchdog/server/src/OveruseConfigurationXmlHelper.cpp
index f76bcc5737..f3d0f044ec 100644
--- a/cpp/watchdog/server/src/OveruseConfigurationXmlHelper.cpp
+++ b/cpp/watchdog/server/src/OveruseConfigurationXmlHelper.cpp
@@ -233,22 +233,23 @@ Result<PerStateBytes> readPerStateBytes(const XMLElement* rootElement) {
if (seenStates.find(state) != seenStates.end()) {
return Error() << "Duplicate threshold specified for state '" << state << "'";
}
- int64_t bytes = 0;
+ int64_t megaBytes = 0;
if (const auto text = childElement->GetText(); text == nullptr) {
return Error() << "Must specify non-empty threshold for state '" << state << "'";
- } else if (const auto bytesStr = Trim(text); !ParseInt(bytesStr.c_str(), &bytes)) {
+ } else if (const auto megaBytesStr = Trim(text);
+ !ParseInt(megaBytesStr.c_str(), &megaBytes)) {
return Error() << "Failed to parse threshold for the state '" << state
- << "': Received threshold value '" << bytesStr << "'";
+ << "': Received threshold value '" << megaBytesStr << "'";
}
if (!strcmp(state, kStateIdForegroundMode)) {
seenStates.insert(kStateIdForegroundMode);
- perStateBytes.foregroundBytes = bytes;
+ perStateBytes.foregroundBytes = megaBytes * kOneMegaByte;
} else if (!strcmp(state, kStateIdBackgroundMode)) {
seenStates.insert(kStateIdBackgroundMode);
- perStateBytes.backgroundBytes = bytes;
+ perStateBytes.backgroundBytes = megaBytes * kOneMegaByte;
} else if (!strcmp(state, kStateIdGarageMode)) {
seenStates.insert(kStateIdGarageMode);
- perStateBytes.garageModeBytes = bytes;
+ perStateBytes.garageModeBytes = megaBytes * kOneMegaByte;
} else {
return Error() << "Invalid state '" << state << "' in per-state bytes";
}
diff --git a/cpp/watchdog/server/src/OveruseConfigurationXmlHelper.h b/cpp/watchdog/server/src/OveruseConfigurationXmlHelper.h
index 9f501c4c3d..382c4f58f0 100644
--- a/cpp/watchdog/server/src/OveruseConfigurationXmlHelper.h
+++ b/cpp/watchdog/server/src/OveruseConfigurationXmlHelper.h
@@ -25,6 +25,8 @@ namespace android {
namespace automotive {
namespace watchdog {
+constexpr int64_t kOneMegaByte = 1024 * 1024;
+
class OveruseConfigurationXmlHelper : public android::RefBase {
public:
static android::base::Result<
diff --git a/cpp/watchdog/server/tests/OveruseConfigurationXmlHelperTest.cpp b/cpp/watchdog/server/tests/OveruseConfigurationXmlHelperTest.cpp
index 2595c2bc3b..88006d7424 100644
--- a/cpp/watchdog/server/tests/OveruseConfigurationXmlHelperTest.cpp
+++ b/cpp/watchdog/server/tests/OveruseConfigurationXmlHelperTest.cpp
@@ -72,10 +72,14 @@ std::string getTestFilePath(const char* filename) {
TEST(OveruseConfigurationXmlHelperTest, TestValidSystemConfiguration) {
auto ioConfig = constructIoOveruseConfig(
- /*componentLevel=*/toPerStateIoOveruseThreshold(ComponentType::SYSTEM, 300, 150, 500),
+ /*componentLevel=*/toPerStateIoOveruseThreshold(ComponentType::SYSTEM,
+ 300 * kOneMegaByte, 150 * kOneMegaByte,
+ 500 * kOneMegaByte),
/*packageSpecific=*/
- {toPerStateIoOveruseThreshold("system.package.C", 400, 100, 200),
- toPerStateIoOveruseThreshold("system.package.D", 1024, 500, 2048)},
+ {toPerStateIoOveruseThreshold("system.package.C", 400 * kOneMegaByte,
+ 100 * kOneMegaByte, 200 * kOneMegaByte),
+ toPerStateIoOveruseThreshold("system.package.D", 1024 * kOneMegaByte,
+ 500 * kOneMegaByte, 2048 * kOneMegaByte)},
/*categorySpecific=*/{},
/*systemWide=*/{toIoOveruseAlertThreshold(10, 200), toIoOveruseAlertThreshold(5, 50)});
ResourceOveruseConfiguration expected =
@@ -97,13 +101,19 @@ TEST(OveruseConfigurationXmlHelperTest, TestValidSystemConfiguration) {
TEST(OveruseConfigurationXmlHelperTest, TestValidVendorConfiguration) {
auto ioConfig = constructIoOveruseConfig(
- /*componentLevel=*/toPerStateIoOveruseThreshold(ComponentType::VENDOR, 1024, 512, 3072),
+ /*componentLevel=*/toPerStateIoOveruseThreshold(ComponentType::VENDOR,
+ 1024 * kOneMegaByte, 512 * kOneMegaByte,
+ 3072 * kOneMegaByte),
/*packageSpecific=*/
- {toPerStateIoOveruseThreshold("com.vendor.package.C", 400, 100, 200),
- toPerStateIoOveruseThreshold("com.vendor.package.D", 1024, 500, 2048)},
+ {toPerStateIoOveruseThreshold("com.vendor.package.C", 400 * kOneMegaByte,
+ 100 * kOneMegaByte, 200 * kOneMegaByte),
+ toPerStateIoOveruseThreshold("com.vendor.package.D", 1024 * kOneMegaByte,
+ 500 * kOneMegaByte, 2048 * kOneMegaByte)},
/*categorySpecific=*/
- {toPerStateIoOveruseThreshold("MAPS", 800, 900, 2048),
- toPerStateIoOveruseThreshold("MEDIA", 600, 700, 1024)},
+ {toPerStateIoOveruseThreshold("MAPS", 800 * kOneMegaByte, 900 * kOneMegaByte,
+ 2048 * kOneMegaByte),
+ toPerStateIoOveruseThreshold("MEDIA", 600 * kOneMegaByte, 700 * kOneMegaByte,
+ 1024 * kOneMegaByte)},
/*systemWide=*/{});
ResourceOveruseConfiguration expected =
constructResourceOveruseConfig(ComponentType::VENDOR,
@@ -129,8 +139,9 @@ TEST(OveruseConfigurationXmlHelperTest, TestValidVendorConfiguration) {
TEST(OveruseConfigurationXmlHelperTest, TestValidThirdPartyConfiguration) {
auto ioConfig = constructIoOveruseConfig(
- /*componentLevel=*/toPerStateIoOveruseThreshold(ComponentType::THIRD_PARTY, 300, 150,
- 500),
+ /*componentLevel=*/toPerStateIoOveruseThreshold(ComponentType::THIRD_PARTY,
+ 300 * kOneMegaByte, 150 * kOneMegaByte,
+ 500 * kOneMegaByte),
/*packageSpecific=*/{},
/*categorySpecific=*/{},
/*systemWide=*/{});
diff --git a/cpp/watchdog/server/tests/data/valid_overuse_third_party_configuration.xml b/cpp/watchdog/server/tests/data/valid_overuse_third_party_configuration.xml
index b3bacb60e5..f12a47c452 100644
--- a/cpp/watchdog/server/tests/data/valid_overuse_third_party_configuration.xml
+++ b/cpp/watchdog/server/tests/data/valid_overuse_third_party_configuration.xml
@@ -24,4 +24,4 @@
<state id="garage_mode"> 500 </state>
</componentLevelThresholds>
</ioOveruseConfiguration>
-</resourceOveruseConfiguration> \ No newline at end of file
+</resourceOveruseConfiguration>