/* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef HARDWARE_GOOGLE_PIXEL_PIXELSTATS_TEST_MOCKMMMETRICS_H #define HARDWARE_GOOGLE_PIXEL_PIXELSTATS_TEST_MOCKMMMETRICS_H #include #include #include #include #include #include "pixelstats/MmMetricsReporter.h" namespace android { namespace hardware { namespace google { namespace pixel { using aidl::android::frameworks::stats::IStats; using android::hardware::google::pixel::PixelAtoms::VendorSlowIo; /** * mock version of MmMetricsReporter class * Testing on the mock version only */ class MockMmMetricsReporter : public MmMetricsReporter { public: MockMmMetricsReporter() : MmMetricsReporter() {} virtual ~MockMmMetricsReporter() {} void setBasePath(const std::string &path) { base_path_ = path; } private: /** * This is the base path of the following map (see getSysfsPath() below). * * The test code can modify this path (by setBasePath()) for redirecting * the sysfs read to a set test data files. Since one sysfs node could * be read multiple times (e.g. create and the diff), the test * code can use this base_path_ to select which set of test data files * to read. */ std::string base_path_; /** * map (redirect) the sysfs node read path to the test data file * for test data injection. */ const std::map mock_path_map = { {"/sys/kernel/pixel_stat/mm/compaction/mm_compaction_duration", "compaction_duration"}, {"/sys/kernel/pixel_stat/mm/vmscan/direct_reclaim/native/latency_stat", "direct_reclaim_native_latency_stat"}, {"/sys/kernel/pixel_stat/mm/vmscan/direct_reclaim/other/latency_stat", "direct_reclaim_other_latency_stat"}, {"/sys/kernel/pixel_stat/mm/vmscan/direct_reclaim/top/latency_stat", "direct_reclaim_top_latency_stat"}, {"/sys/kernel/pixel_stat/mm/vmscan/direct_reclaim/visible/latency_stat", "direct_reclaim_visible_latency_stat"}, {"/sys/kernel/dma_heap/total_pools_kb", "dma_heap_total_pools"}, {"/sys/kernel/pixel_stat/gpu/mem/total_page_count", "gpu_pages"}, {"/sys/kernel/ion/total_pools_kb", "ion_total_pools"}, {"/sys/kernel/pixel_stat/mm/vmstat", "pixel_vmstat"}, {"/proc/meminfo", "proc_meminfo"}, {"/proc/stat", "proc_stat"}, {"/proc/vmstat", "proc_vmstat"}, {"/proc/pressure/cpu", "psi_cpu"}, {"/proc/pressure/io", "psi_io"}, {"/proc/pressure/memory", "psi_memory"}, {"kswapd0", "kswapd0_stat"}, {"kcompactd0", "kcompactd0_stat"}, {"/proc/vendor_mm/memory_usage_by_oom_score", "oom_mm_usage"}, {"/sys/kernel/vendor_mm/gcma/cached", "gcma_cached"}, {"/sys/kernel/vendor_mm/gcma/discarded", "gcma_discarded"}, {"/sys/kernel/vendor_mm/gcma/evicted", "gcma_evicted"}, {"/sys/kernel/vendor_mm/gcma/loaded", "gcma_loaded"}, {"/sys/kernel/vendor_mm/gcma/stored", "gcma_stored"}, {"/sys/kernel/vendor_mm/gcma/latency_low", "gcma_latency_low"}, {"/sys/kernel/vendor_mm/gcma/latency_mid", "gcma_latency_mid"}, {"/sys/kernel/vendor_mm/gcma/latency_high", "gcma_latency_high"}, {"/sys/kernel/vendor_mm/gcma/latency_extreme_high", "gcma_latency_extreme_high"}, }; virtual std::string getSysfsPath(const std::string &path) { std::string ret(base_path_ + '/'); if (mock_path_map.find(path) == mock_path_map.end()) { /* * This mapped file won't exist in the test directory, * so this effectively emulates a 'file-not-found' condition * for testing the failed cases. */ return ret + "not_found"; } else { return ret + mock_path_map.at(path); } } virtual std::string getProcessStatPath(const std::string &name, int *prev_pid) { (void)(prev_pid); // unused parameter return getSysfsPath(name); } }; } // namespace pixel } // namespace google } // namespace hardware } // namespace android #endif // HARDWARE_GOOGLE_PIXEL_PIXELSTATS_TEST_MOCKMMMETRICS_H