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 } 48 49 MATCHER(ProcessStatsByPidEq, "") { 50 const auto& actual = std::get<0>(arg); 51 const auto& expected = std::get<1>(arg); 52 return actual.first == expected.first && 53 ::testing::Value(actual.second, ProcessStatsEq(expected.second)); 54 } 55 56 MATCHER_P(UidProcStatsEq, expected, "") { 57 const auto& actual = arg; 58 return ::testing::Value(actual.cpuTimeMillis, ::testing::Eq(expected.cpuTimeMillis)) && 59 ::testing::Value(actual.cpuCycles, ::testing::Eq(expected.cpuCycles)) && 60 ::testing::Value(actual.totalMajorFaults, ::testing::Eq(expected.totalMajorFaults)) && 61 ::testing::Value(actual.totalTasksCount, ::testing::Eq(expected.totalTasksCount)) && 62 ::testing::Value(actual.ioBlockedTasksCount, 63 ::testing::Eq(expected.ioBlockedTasksCount)) && 64 ::testing::Value(actual.processStatsByPid, 65 ::testing::UnorderedPointwise(ProcessStatsByPidEq(), 66 expected.processStatsByPid)); 67 } 68 69 } // namespace watchdog 70 } // namespace automotive 71 } // namespace android 72 73 #endif // CPP_WATCHDOG_SERVER_TESTS_UIDPROCSTATSCOLLECTORTESTUTILS_H_ 74