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_P(ProcessStatsEq, expected, "") { 29 const auto& actual = arg; 30 return ::testing::Value(actual.comm, ::testing::Eq(expected.comm)) && 31 ::testing::Value(actual.startTime, ::testing::Eq(expected.startTime)) && 32 ::testing::Value(actual.totalMajorFaults, ::testing::Eq(expected.totalMajorFaults)) && 33 ::testing::Value(actual.totalTasksCount, ::testing::Eq(expected.totalTasksCount)) && 34 ::testing::Value(actual.ioBlockedTasksCount, 35 ::testing::Eq(expected.ioBlockedTasksCount)); 36 } 37 38 MATCHER(ProcessStatsByPidEq, "") { 39 const auto& actual = std::get<0>(arg); 40 const auto& expected = std::get<1>(arg); 41 return actual.first == expected.first && 42 ::testing::Value(actual.second, ProcessStatsEq(expected.second)); 43 } 44 45 MATCHER_P(UidProcStatsEq, expected, "") { 46 const auto& actual = arg; 47 return ::testing::Value(actual.totalMajorFaults, ::testing::Eq(expected.totalMajorFaults)) && 48 ::testing::Value(actual.totalTasksCount, ::testing::Eq(expected.totalTasksCount)) && 49 ::testing::Value(actual.ioBlockedTasksCount, 50 ::testing::Eq(expected.ioBlockedTasksCount)) && 51 ::testing::Value(actual.processStatsByPid, 52 ::testing::UnorderedPointwise(ProcessStatsByPidEq(), 53 expected.processStatsByPid)); 54 } 55 56 } // namespace watchdog 57 } // namespace automotive 58 } // namespace android 59 60 #endif // CPP_WATCHDOG_SERVER_TESTS_UIDPROCSTATSCOLLECTORTESTUTILS_H_ 61