diff options
author | Lakshman Annadorai <lakshmana@google.com> | 2021-09-14 12:13:59 -0700 |
---|---|---|
committer | Lakshman Annadorai <lakshmana@google.com> | 2021-09-20 15:45:24 -0700 |
commit | f58a106cf64402ba77c86d8e9d14a8763629bacd (patch) | |
tree | b0c3b007dc8fa930431ca15c13990fdc9e43f290 /cpp/watchdog | |
parent | c12e8c6f7eb5d05beb9931130876fc70bf486116 (diff) | |
download | Car-f58a106cf64402ba77c86d8e9d14a8763629bacd.tar.gz |
Reuse constructPackageInfo method from PackageInfoTestUtils.
- Use const references in tets matchers.
- Address some minor nits.
Test: atest libwatchdog_test
Bug: 199782126
Change-Id: If39d5ef31d9705f6471f0875ac3e1f93aa1932b6
Diffstat (limited to 'cpp/watchdog')
8 files changed, 80 insertions, 117 deletions
diff --git a/cpp/watchdog/server/src/IoOveruseConfigs.cpp b/cpp/watchdog/server/src/IoOveruseConfigs.cpp index 2ff118a368..0237e7d948 100644 --- a/cpp/watchdog/server/src/IoOveruseConfigs.cpp +++ b/cpp/watchdog/server/src/IoOveruseConfigs.cpp @@ -580,7 +580,8 @@ Result<void> IoOveruseConfigs::update( return {}; } -void IoOveruseConfigs::get(std::vector<ResourceOveruseConfiguration>* resourceOveruseConfigs) { +void IoOveruseConfigs::get( + std::vector<ResourceOveruseConfiguration>* resourceOveruseConfigs) const { auto systemConfig = get(mSystemConfig, kSystemComponentUpdatableConfigs); if (systemConfig.has_value()) { systemConfig->componentType = ComponentType::SYSTEM; @@ -601,7 +602,8 @@ void IoOveruseConfigs::get(std::vector<ResourceOveruseConfiguration>* resourceOv } std::optional<ResourceOveruseConfiguration> IoOveruseConfigs::get( - const ComponentSpecificConfig& componentSpecificConfig, const int32_t componentFilter) { + const ComponentSpecificConfig& componentSpecificConfig, + const int32_t componentFilter) const { if (componentSpecificConfig.mGeneric.name == kDefaultThresholdName) { return {}; } diff --git a/cpp/watchdog/server/src/IoOveruseConfigs.h b/cpp/watchdog/server/src/IoOveruseConfigs.h index 53ee9dd89c..7ae758b05c 100644 --- a/cpp/watchdog/server/src/IoOveruseConfigs.h +++ b/cpp/watchdog/server/src/IoOveruseConfigs.h @@ -68,7 +68,7 @@ class IoOveruseConfigsPeer; } // namespace internal -/* +/** * Defines the methods that the I/O overuse configs module should implement. */ class IIoOveruseConfigs : public android::RefBase { @@ -80,18 +80,18 @@ public: // Returns the existing configurations. virtual void get( std::vector<android::automotive::watchdog::internal::ResourceOveruseConfiguration>* - resourceOveruseConfigs) = 0; + resourceOveruseConfigs) const = 0; // Writes the cached configs to disk. virtual android::base::Result<void> writeToDisk() = 0; - /* + /** * Returns the list of vendor package prefixes. Any pre-installed package matching one of these * prefixes should be classified as a vendor package. */ virtual const std::unordered_set<std::string>& vendorPackagePrefixes() = 0; - /* + /** * Returns the package names to application category mappings. */ virtual const std::unordered_map< @@ -129,7 +129,7 @@ public: class IoOveruseConfigs; -/* +/** * ComponentSpecificConfig represents the I/O overuse config defined per component. */ class ComponentSpecificConfig final { @@ -141,32 +141,32 @@ protected: mSafeToKillPackages.clear(); } - /* + /** * Updates |mPerPackageThresholds|. */ android::base::Result<void> updatePerPackageThresholds( const std::vector<android::automotive::watchdog::internal::PerStateIoOveruseThreshold>& thresholds, const std::function<void(const std::string&)>& maybeAppendVendorPackagePrefixes); - /* + /** * Updates |mSafeToKillPackages|. */ android::base::Result<void> updateSafeToKillPackages( const std::vector<std::string>& packages, const std::function<void(const std::string&)>& maybeAppendVendorPackagePrefixes); - /* + /** * I/O overuse configurations for all packages under the component that are not covered by * |mPerPackageThresholds| or |IoOveruseConfigs.mPerCategoryThresholds|. */ android::automotive::watchdog::internal::PerStateIoOveruseThreshold mGeneric; - /* + /** * I/O overuse configurations for specific packages under the component. */ std::unordered_map<std::string, android::automotive::watchdog::internal::PerStateIoOveruseThreshold> mPerPackageThresholds; - /* + /** * List of safe to kill packages under the component in the event of I/O overuse. */ std::unordered_set<std::string> mSafeToKillPackages; @@ -175,7 +175,7 @@ private: friend class IoOveruseConfigs; }; -/* +/** * IoOveruseConfigs represents the I/O overuse configuration defined by system and vendor * applications. This class is not thread safe for performance purposes. The caller is responsible * for calling the methods in a thread safe manner. @@ -194,7 +194,7 @@ public: configs) override; void get(std::vector<android::automotive::watchdog::internal::ResourceOveruseConfiguration>* - resourceOveruseConfigs) override; + resourceOveruseConfigs) const override; android::base::Result<void> writeToDisk(); @@ -245,7 +245,8 @@ private: thresholds); std::optional<android::automotive::watchdog::internal::ResourceOveruseConfiguration> get( - const ComponentSpecificConfig& componentSpecificConfig, const int32_t componentFilter); + const ComponentSpecificConfig& componentSpecificConfig, + const int32_t componentFilter) const; // System component specific configuration. ComponentSpecificConfig mSystemConfig; diff --git a/cpp/watchdog/server/tests/IoOveruseConfigsTest.cpp b/cpp/watchdog/server/tests/IoOveruseConfigsTest.cpp index c03ad85eab..8eefeb4981 100644 --- a/cpp/watchdog/server/tests/IoOveruseConfigsTest.cpp +++ b/cpp/watchdog/server/tests/IoOveruseConfigsTest.cpp @@ -17,6 +17,7 @@ #include "IoOveruseConfigs.h" #include "OveruseConfigurationTestUtils.h" #include "OveruseConfigurationXmlHelper.h" +#include "PackageInfoTestUtils.h" #include <android-base/strings.h> #include <gmock/gmock.h> @@ -73,19 +74,6 @@ std::unordered_map<std::string, ApplicationCategoryType> toPackageToAppCategoryM return mappings; } -PackageInfo constructPackageInfo( - const char* packageName, const ComponentType componentType, - const ApplicationCategoryType appCategoryType = ApplicationCategoryType::OTHERS, - const std::vector<std::string>& sharedUidPackages = std::vector<std::string>()) { - PackageInfo packageInfo; - packageInfo.packageIdentifier.name = packageName; - packageInfo.uidType = UidType::APPLICATION; - packageInfo.componentType = componentType; - packageInfo.appCategoryType = appCategoryType; - packageInfo.sharedUidPackages = sharedUidPackages; - return packageInfo; -} - std::string toString(std::vector<ResourceOveruseConfiguration> configs) { std::string buffer; StringAppendF(&buffer, "["); @@ -99,9 +87,9 @@ std::string toString(std::vector<ResourceOveruseConfiguration> configs) { return buffer; } -std::vector<Matcher<const ResourceOveruseConfiguration>> ResourceOveruseConfigurationsMatchers( +std::vector<Matcher<const ResourceOveruseConfiguration&>> ResourceOveruseConfigurationsMatchers( const std::vector<ResourceOveruseConfiguration>& configs) { - std::vector<Matcher<const ResourceOveruseConfiguration>> matchers; + std::vector<Matcher<const ResourceOveruseConfiguration&>> matchers; for (const auto config : configs) { matchers.push_back(ResourceOveruseConfigurationMatcher(config)); } @@ -526,21 +514,21 @@ TEST_F(IoOveruseConfigsTest, TestDefaultConfigWithoutUpdate) { PerStateBytes defaultPerStateBytes = defaultThreshold().perStateWriteBytes; IoOveruseConfigs ioOveruseConfigs; - auto packageInfo = constructPackageInfo("systemPackage", ComponentType::SYSTEM); + auto packageInfo = constructAppPackageInfo("systemPackage", ComponentType::SYSTEM); EXPECT_THAT(ioOveruseConfigs.fetchThreshold(packageInfo), defaultPerStateBytes) << "System package should have default threshold"; EXPECT_FALSE(ioOveruseConfigs.isSafeToKill(packageInfo)) << "System package shouldn't be killed by default"; - packageInfo = constructPackageInfo("vendorPackage", ComponentType::VENDOR, - ApplicationCategoryType::MEDIA); + packageInfo = constructAppPackageInfo("vendorPackage", ComponentType::VENDOR, + ApplicationCategoryType::MEDIA); EXPECT_THAT(ioOveruseConfigs.fetchThreshold(packageInfo), defaultPerStateBytes) << "Vendor package should have default threshold"; EXPECT_FALSE(ioOveruseConfigs.isSafeToKill(packageInfo)) << "Vendor package shouldn't be killed by default"; - packageInfo = constructPackageInfo("3pPackage", ComponentType::THIRD_PARTY, - ApplicationCategoryType::MAPS); + packageInfo = constructAppPackageInfo("3pPackage", ComponentType::THIRD_PARTY, + ApplicationCategoryType::MAPS); EXPECT_THAT(ioOveruseConfigs.fetchThreshold(packageInfo), defaultPerStateBytes) << "Third-party package should have default threshold"; EXPECT_TRUE(ioOveruseConfigs.isSafeToKill(packageInfo)) @@ -810,25 +798,25 @@ TEST_F(IoOveruseConfigsTest, TestFetchThresholdForSystemPackages) { const auto ioOveruseConfigs = sampleIoOveruseConfigs(); auto actual = ioOveruseConfigs->fetchThreshold( - constructPackageInfo("systemPackageGeneric", ComponentType::SYSTEM)); + constructAppPackageInfo("systemPackageGeneric", ComponentType::SYSTEM)); EXPECT_THAT(actual, SYSTEM_COMPONENT_LEVEL_THRESHOLDS); actual = ioOveruseConfigs->fetchThreshold( - constructPackageInfo("systemPackageA", ComponentType::SYSTEM)); + constructAppPackageInfo("systemPackageA", ComponentType::SYSTEM)); EXPECT_THAT(actual, SYSTEM_PACKAGE_A_THRESHOLDS); - actual = ioOveruseConfigs->fetchThreshold(constructPackageInfo("systemPackageB", - ComponentType::SYSTEM, - ApplicationCategoryType::MEDIA)); + actual = ioOveruseConfigs->fetchThreshold( + constructAppPackageInfo("systemPackageB", ComponentType::SYSTEM, + ApplicationCategoryType::MEDIA)); // Package specific thresholds get priority over media category thresholds. EXPECT_THAT(actual, SYSTEM_PACKAGE_B_THRESHOLDS); - actual = ioOveruseConfigs->fetchThreshold(constructPackageInfo("systemPackageC", - ComponentType::SYSTEM, - ApplicationCategoryType::MEDIA)); + actual = ioOveruseConfigs->fetchThreshold( + constructAppPackageInfo("systemPackageC", ComponentType::SYSTEM, + ApplicationCategoryType::MEDIA)); // Media category thresholds as there is no package specific thresholds. EXPECT_THAT(actual, MEDIA_THRESHOLDS); @@ -846,12 +834,12 @@ TEST_F(IoOveruseConfigsTest, TestFetchThresholdForSharedSystemPackages) { ioOveruseConfigs->update({sampleSystemConfig}); auto actual = ioOveruseConfigs->fetchThreshold( - constructPackageInfo("shared:systemSharedPackage", ComponentType::SYSTEM)); + constructAppPackageInfo("shared:systemSharedPackage", ComponentType::SYSTEM)); EXPECT_THAT(actual, toPerStateBytes(100, 200, 300)); actual = ioOveruseConfigs->fetchThreshold( - constructPackageInfo("systemSharedPackage", ComponentType::SYSTEM)); + constructAppPackageInfo("systemSharedPackage", ComponentType::SYSTEM)); EXPECT_THAT(actual, SYSTEM_COMPONENT_LEVEL_THRESHOLDS); } @@ -860,18 +848,18 @@ TEST_F(IoOveruseConfigsTest, TestFetchThresholdForVendorPackages) { const auto ioOveruseConfigs = sampleIoOveruseConfigs(); auto actual = ioOveruseConfigs->fetchThreshold( - constructPackageInfo("vendorPackageGeneric", ComponentType::VENDOR)); + constructAppPackageInfo("vendorPackageGeneric", ComponentType::VENDOR)); EXPECT_THAT(actual, VENDOR_COMPONENT_LEVEL_THRESHOLDS); actual = ioOveruseConfigs->fetchThreshold( - constructPackageInfo("vendorPkgB", ComponentType::VENDOR)); + constructAppPackageInfo("vendorPkgB", ComponentType::VENDOR)); EXPECT_THAT(actual, VENDOR_PKG_B_THRESHOLDS); - actual = ioOveruseConfigs->fetchThreshold(constructPackageInfo("vendorPackageC", - ComponentType::VENDOR, - ApplicationCategoryType::MAPS)); + actual = ioOveruseConfigs->fetchThreshold( + constructAppPackageInfo("vendorPackageC", ComponentType::VENDOR, + ApplicationCategoryType::MAPS)); // Maps category thresholds as there is no package specific thresholds. EXPECT_THAT(actual, MAPS_THRESHOLDS); @@ -889,12 +877,12 @@ TEST_F(IoOveruseConfigsTest, TestFetchThresholdForSharedVendorPackages) { ioOveruseConfigs->update({sampleVendorConfig}); auto actual = ioOveruseConfigs->fetchThreshold( - constructPackageInfo("shared:vendorSharedPackage", ComponentType::VENDOR)); + constructAppPackageInfo("shared:vendorSharedPackage", ComponentType::VENDOR)); EXPECT_THAT(actual, toPerStateBytes(100, 200, 300)); actual = ioOveruseConfigs->fetchThreshold( - constructPackageInfo("vendorSharedPackage", ComponentType::VENDOR)); + constructAppPackageInfo("vendorSharedPackage", ComponentType::VENDOR)); EXPECT_THAT(actual, VENDOR_COMPONENT_LEVEL_THRESHOLDS); } @@ -903,19 +891,19 @@ TEST_F(IoOveruseConfigsTest, TestFetchThresholdForThirdPartyPackages) { const auto ioOveruseConfigs = sampleIoOveruseConfigs(); auto actual = ioOveruseConfigs->fetchThreshold( - constructPackageInfo("vendorPackageGenericImpostor", ComponentType::THIRD_PARTY)); + constructAppPackageInfo("vendorPackageGenericImpostor", ComponentType::THIRD_PARTY)); EXPECT_THAT(actual, THIRD_PARTY_COMPONENT_LEVEL_THRESHOLDS); - actual = ioOveruseConfigs->fetchThreshold(constructPackageInfo("3pMapsPackage", - ComponentType::THIRD_PARTY, - ApplicationCategoryType::MAPS)); + actual = ioOveruseConfigs->fetchThreshold( + constructAppPackageInfo("3pMapsPackage", ComponentType::THIRD_PARTY, + ApplicationCategoryType::MAPS)); EXPECT_THAT(actual, MAPS_THRESHOLDS); - actual = ioOveruseConfigs->fetchThreshold(constructPackageInfo("3pMediaPackage", - ComponentType::THIRD_PARTY, - ApplicationCategoryType::MEDIA)); + actual = ioOveruseConfigs->fetchThreshold( + constructAppPackageInfo("3pMediaPackage", ComponentType::THIRD_PARTY, + ApplicationCategoryType::MEDIA)); EXPECT_THAT(actual, MEDIA_THRESHOLDS); } @@ -923,10 +911,10 @@ TEST_F(IoOveruseConfigsTest, TestFetchThresholdForThirdPartyPackages) { TEST_F(IoOveruseConfigsTest, TestIsSafeToKillSystemPackages) { const auto ioOveruseConfigs = sampleIoOveruseConfigs(); EXPECT_FALSE(ioOveruseConfigs->isSafeToKill( - constructPackageInfo("systemPackageGeneric", ComponentType::SYSTEM))); + constructAppPackageInfo("systemPackageGeneric", ComponentType::SYSTEM))); EXPECT_TRUE(ioOveruseConfigs->isSafeToKill( - constructPackageInfo("systemPackageA", ComponentType::SYSTEM))); + constructAppPackageInfo("systemPackageA", ComponentType::SYSTEM))); } TEST_F(IoOveruseConfigsTest, TestIsSafeToKillSharedSystemPackages) { @@ -938,23 +926,23 @@ TEST_F(IoOveruseConfigsTest, TestIsSafeToKillSharedSystemPackages) { EXPECT_RESULT_OK(ioOveruseConfigs->update({sampleSystemConfig})); PackageInfo packageInfo = - constructPackageInfo("systemSharedPackage", ComponentType::SYSTEM, - ApplicationCategoryType::OTHERS, - {"sharedUidSystemPackageA", "sharedUidSystemPackageB", - "sharedUidSystemPackageC"}); + constructAppPackageInfo("systemSharedPackage", ComponentType::SYSTEM, + ApplicationCategoryType::OTHERS, + {"sharedUidSystemPackageA", "sharedUidSystemPackageB", + "sharedUidSystemPackageC"}); EXPECT_TRUE(ioOveruseConfigs->isSafeToKill(packageInfo)) << "Should be safe-to-kill when at least one package under shared UID is safe-to-kill"; packageInfo = - constructPackageInfo("shared:systemSharedPackageD", ComponentType::SYSTEM, - ApplicationCategoryType::OTHERS, {"sharedUidSystemPackageA"}); + constructAppPackageInfo("shared:systemSharedPackageD", ComponentType::SYSTEM, + ApplicationCategoryType::OTHERS, {"sharedUidSystemPackageA"}); EXPECT_TRUE(ioOveruseConfigs->isSafeToKill(packageInfo)) << "Should be safe-to-kill when shared package is safe-to-kill"; packageInfo = - constructPackageInfo("systemSharedPackageD", ComponentType::SYSTEM, - ApplicationCategoryType::OTHERS, {"sharedUidSystemPackageA"}); + constructAppPackageInfo("systemSharedPackageD", ComponentType::SYSTEM, + ApplicationCategoryType::OTHERS, {"sharedUidSystemPackageA"}); EXPECT_FALSE(ioOveruseConfigs->isSafeToKill(packageInfo)) << "Shouldn't be safe-to-kill when the 'shared:' prefix is missing"; } @@ -962,10 +950,10 @@ TEST_F(IoOveruseConfigsTest, TestIsSafeToKillSharedSystemPackages) { TEST_F(IoOveruseConfigsTest, TestIsSafeToKillVendorPackages) { const auto ioOveruseConfigs = sampleIoOveruseConfigs(); EXPECT_FALSE(ioOveruseConfigs->isSafeToKill( - constructPackageInfo("vendorPackageGeneric", ComponentType::VENDOR))); + constructAppPackageInfo("vendorPackageGeneric", ComponentType::VENDOR))); EXPECT_TRUE(ioOveruseConfigs->isSafeToKill( - constructPackageInfo("vendorPackageA", ComponentType::VENDOR))); + constructAppPackageInfo("vendorPackageA", ComponentType::VENDOR))); } TEST_F(IoOveruseConfigsTest, TestIsSafeToKillSharedVendorPackages) { @@ -981,23 +969,23 @@ TEST_F(IoOveruseConfigsTest, TestIsSafeToKillSharedVendorPackages) { EXPECT_RESULT_OK(ioOveruseConfigs->update({sampleSystemConfig, sampleVendorConfig})); PackageInfo packageInfo = - constructPackageInfo("vendorSharedPackage", ComponentType::VENDOR, - ApplicationCategoryType::OTHERS, - {"sharedUidVendorPackageA", "sharedUidVendorPackageB", - "sharedUidVendorPackageC"}); + constructAppPackageInfo("vendorSharedPackage", ComponentType::VENDOR, + ApplicationCategoryType::OTHERS, + {"sharedUidVendorPackageA", "sharedUidVendorPackageB", + "sharedUidVendorPackageC"}); EXPECT_TRUE(ioOveruseConfigs->isSafeToKill(packageInfo)) << "Should be safe-to-kill when at least one package under shared UID is safe-to-kill"; packageInfo = - constructPackageInfo("shared:vendorSharedPackageD", ComponentType::VENDOR, - ApplicationCategoryType::OTHERS, {"sharedUidVendorPackageA"}); + constructAppPackageInfo("shared:vendorSharedPackageD", ComponentType::VENDOR, + ApplicationCategoryType::OTHERS, {"sharedUidVendorPackageA"}); EXPECT_TRUE(ioOveruseConfigs->isSafeToKill(packageInfo)) << "Should be safe-to-kill when shared package is safe-to-kill"; packageInfo = - constructPackageInfo("shared:vendorSharedPackageE", ComponentType::VENDOR, - ApplicationCategoryType::OTHERS, {"sharedUidVendorPackageA"}); + constructAppPackageInfo("shared:vendorSharedPackageE", ComponentType::VENDOR, + ApplicationCategoryType::OTHERS, {"sharedUidVendorPackageA"}); EXPECT_FALSE(ioOveruseConfigs->isSafeToKill(packageInfo)) << "Shouldn't be safe-to-kill when the 'shared:' prefix is missing"; } @@ -1005,11 +993,11 @@ TEST_F(IoOveruseConfigsTest, TestIsSafeToKillSharedVendorPackages) { TEST_F(IoOveruseConfigsTest, TestIsSafeToKillThirdPartyPackages) { const auto ioOveruseConfigs = sampleIoOveruseConfigs(); EXPECT_TRUE(ioOveruseConfigs->isSafeToKill( - constructPackageInfo("vendorPackageGenericImpostor", ComponentType::THIRD_PARTY))); + constructAppPackageInfo("vendorPackageGenericImpostor", ComponentType::THIRD_PARTY))); EXPECT_TRUE(ioOveruseConfigs->isSafeToKill( - constructPackageInfo("3pMapsPackage", ComponentType::THIRD_PARTY, - ApplicationCategoryType::MAPS))); + constructAppPackageInfo("3pMapsPackage", ComponentType::THIRD_PARTY, + ApplicationCategoryType::MAPS))); } TEST_F(IoOveruseConfigsTest, TestIsSafeToKillNativePackages) { diff --git a/cpp/watchdog/server/tests/MockIoOveruseConfigs.h b/cpp/watchdog/server/tests/MockIoOveruseConfigs.h index 22c23f7f72..6859e18ff6 100644 --- a/cpp/watchdog/server/tests/MockIoOveruseConfigs.h +++ b/cpp/watchdog/server/tests/MockIoOveruseConfigs.h @@ -43,7 +43,7 @@ public: MOCK_METHOD( void, get, (std::vector<android::automotive::watchdog::internal::ResourceOveruseConfiguration>*), - (override)); + (const, override)); MOCK_METHOD(android::base::Result<void>, writeToDisk, (), (override)); diff --git a/cpp/watchdog/server/tests/OveruseConfigurationTestUtils.cpp b/cpp/watchdog/server/tests/OveruseConfigurationTestUtils.cpp index 1bf270d6ed..9b67cafc99 100644 --- a/cpp/watchdog/server/tests/OveruseConfigurationTestUtils.cpp +++ b/cpp/watchdog/server/tests/OveruseConfigurationTestUtils.cpp @@ -154,15 +154,15 @@ IoOveruseAlertThreshold toIoOveruseAlertThreshold(const int64_t durationInSecond return threshold; } -Matcher<const ResourceOveruseConfiguration> ResourceOveruseConfigurationMatcher( +Matcher<const ResourceOveruseConfiguration&> ResourceOveruseConfigurationMatcher( const ResourceOveruseConfiguration& config) { - std::vector<Matcher<const ResourceSpecificConfiguration>> resourceSpecificConfigMatchers; + std::vector<Matcher<const ResourceSpecificConfiguration&>> resourceSpecificConfigMatchers; for (const auto& resourceSpecificConfig : config.resourceSpecificConfigurations) { resourceSpecificConfigMatchers.push_back( IsResourceSpecificConfiguration(resourceSpecificConfig)); } - std::vector<Matcher<const PackageMetadata>> metadataMatchers; + std::vector<Matcher<const PackageMetadata&>> metadataMatchers; for (const auto& metadata : config.packageMetadata) { metadataMatchers.push_back(IsPackageMetadata(metadata)); } diff --git a/cpp/watchdog/server/tests/OveruseConfigurationTestUtils.h b/cpp/watchdog/server/tests/OveruseConfigurationTestUtils.h index 84c970ad2a..a8991c73ce 100644 --- a/cpp/watchdog/server/tests/OveruseConfigurationTestUtils.h +++ b/cpp/watchdog/server/tests/OveruseConfigurationTestUtils.h @@ -77,7 +77,7 @@ android::automotive::watchdog::internal::PackageMetadata toPackageMetadata( android::automotive::watchdog::internal::IoOveruseAlertThreshold toIoOveruseAlertThreshold( const int64_t durationInSeconds, const int64_t writtenBytesPerSecond); -testing::Matcher<const android::automotive::watchdog::internal::ResourceOveruseConfiguration> +testing::Matcher<const android::automotive::watchdog::internal::ResourceOveruseConfiguration&> ResourceOveruseConfigurationMatcher( const android::automotive::watchdog::internal::ResourceOveruseConfiguration& config); diff --git a/cpp/watchdog/server/tests/PackageInfoResolverTest.cpp b/cpp/watchdog/server/tests/PackageInfoResolverTest.cpp index cf282be5fb..cf68ddae50 100644 --- a/cpp/watchdog/server/tests/PackageInfoResolverTest.cpp +++ b/cpp/watchdog/server/tests/PackageInfoResolverTest.cpp @@ -16,6 +16,7 @@ #include "MockWatchdogServiceHelper.h" #include "PackageInfoResolver.h" +#include "PackageInfoTestUtils.h" #include <android-base/stringprintf.h> #include <android/automotive/watchdog/internal/ApplicationCategoryType.h> @@ -48,20 +49,6 @@ using PackageToAppCategoryMap = std::unordered_map<std::string, android::automotive::watchdog::internal::ApplicationCategoryType>; -PackageInfo constructPackageInfo(const char* packageName, int32_t uid, UidType uidType, - ComponentType componentType, - ApplicationCategoryType appCategoryType, - std::vector<std::string> sharedUidPackages = {}) { - PackageInfo packageInfo; - packageInfo.packageIdentifier.name = packageName; - packageInfo.packageIdentifier.uid = uid; - packageInfo.uidType = uidType; - packageInfo.componentType = componentType; - packageInfo.appCategoryType = appCategoryType; - packageInfo.sharedUidPackages = sharedUidPackages; - return packageInfo; -} - std::string toString(const std::unordered_map<uid_t, PackageInfo>& mappings) { std::string buffer = "{"; for (const auto& [uid, info] : mappings) { diff --git a/cpp/watchdog/server/tests/WatchdogServiceHelperTest.cpp b/cpp/watchdog/server/tests/WatchdogServiceHelperTest.cpp index 99b65df0cf..de0530095e 100644 --- a/cpp/watchdog/server/tests/WatchdogServiceHelperTest.cpp +++ b/cpp/watchdog/server/tests/WatchdogServiceHelperTest.cpp @@ -16,6 +16,7 @@ #include "MockCarWatchdogServiceForSystem.h" #include "MockWatchdogProcessService.h" +#include "PackageInfoTestUtils.h" #include "WatchdogServiceHelper.h" #include <binder/IBinder.h> @@ -69,22 +70,6 @@ private: } // namespace internal -namespace { - -PackageInfo constructPackageInfo(const char* packageName, int32_t uid, UidType uidType, - ComponentType componentType, - ApplicationCategoryType appCategoryType) { - PackageInfo packageInfo; - packageInfo.packageIdentifier.name = packageName; - packageInfo.packageIdentifier.uid = uid; - packageInfo.uidType = uidType; - packageInfo.componentType = componentType; - packageInfo.appCategoryType = appCategoryType; - return packageInfo; -} - -} // namespace - class WatchdogServiceHelperTest : public ::testing::Test { protected: virtual void SetUp() { |