1 /* 2 * Copyright (c) 2021, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef CPP_WATCHDOG_SERVER_TESTS_UIDPROCSTATSCOLLECTORTESTUTILS_H_ 18 #define CPP_WATCHDOG_SERVER_TESTS_UIDPROCSTATSCOLLECTORTESTUTILS_H_ 19 20 #include "UidProcStatsCollector.h" 21 22 #include <gmock/gmock.h> 23 24 namespace android { 25 namespace automotive { 26 namespace watchdog { 27 28 MATCHER(CpuCyclesByTidEq, "") { 29 const auto& actual = std::get<0>(arg); 30 const auto& expected = std::get<1>(arg); 31 return actual.first == expected.first && actual.second == expected.second; 32 } 33 34 MATCHER_P(ProcessStatsEq, expected, "") { 35 const auto& actual = arg; 36 return ::testing::Value(actual.comm, ::testing::Eq(expected.comm)) && 37 ::testing::Value(actual.startTimeMillis, ::testing::Eq(expected.startTimeMillis)) && 38 ::testing::Value(actual.cpuTimeMillis, ::testing::Eq(expected.cpuTimeMillis)) && 39 ::testing::Value(actual.totalCpuCycles, ::testing::Eq(expected.totalCpuCycles)) && 40 ::testing::Value(actual.totalMajorFaults, ::testing::Eq(expected.totalMajorFaults)) && 41 ::testing::Value(actual.totalTasksCount, ::testing::Eq(expected.totalTasksCount)) && 42 ::testing::Value(actual.ioBlockedTasksCount, 43 ::testing::Eq(expected.ioBlockedTasksCount)) && 44 ::testing::Value(actual.cpuCyclesByTid, 45 ::testing::UnorderedPointwise(CpuCyclesByTidEq(), 46 expected.cpuCyclesByTid)) && 47 ::testing::Value(actual.rssKb, ::testing::Eq(expected.rssKb)) && 48 ::testing::Value(actual.pssKb, ::testing::Eq(expected.pssKb)) && 49 ::testing::Value(actual.ussKb, ::testing::Eq(expected.ussKb)) && 50 ::testing::Value(actual.swapPssKb, ::testing::Eq(expected.swapPssKb)); 51 } 52 53 MATCHER(ProcessStatsByPidEq, "") { 54 const auto& actual = std::get<0>(arg); 55 const auto& expected = std::get<1>(arg); 56 return actual.first == expected.first && 57 ::testing::Value(actual.second, ProcessStatsEq(expected.second)); 58 } 59 60 MATCHER_P(UidProcStatsEq, expected, "") { 61 const auto& actual = arg; 62 return ::testing::Value(actual.cpuTimeMillis, ::testing::Eq(expected.cpuTimeMillis)) && 63 ::testing::Value(actual.cpuCycles, ::testing::Eq(expected.cpuCycles)) && 64 ::testing::Value(actual.totalMajorFaults, ::testing::Eq(expected.totalMajorFaults)) && 65 ::testing::Value(actual.totalTasksCount, ::testing::Eq(expected.totalTasksCount)) && 66 ::testing::Value(actual.ioBlockedTasksCount, 67 ::testing::Eq(expected.ioBlockedTasksCount)) && 68 ::testing::Value(actual.totalRssKb, ::testing::Eq(expected.totalRssKb)) && 69 ::testing::Value(actual.totalPssKb, ::testing::Eq(expected.totalPssKb)) && 70 ::testing::Value(actual.processStatsByPid, 71 ::testing::UnorderedPointwise(ProcessStatsByPidEq(), 72 expected.processStatsByPid)); 73 } 74 75 } // namespace watchdog 76 } // namespace automotive 77 } // namespace android 78 79 #endif // CPP_WATCHDOG_SERVER_TESTS_UIDPROCSTATSCOLLECTORTESTUTILS_H_ 80