Felipe Leme | 343175a | 2016-08-02 18:57:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | #include "../dumpsys.h" |
| 18 | |
| 19 | #include <vector> |
| 20 | |
| 21 | #include <gmock/gmock.h> |
| 22 | #include <gtest/gtest.h> |
| 23 | |
| 24 | #include <android-base/file.h> |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 25 | #include <serviceutils/PriorityDumper.h> |
Felipe Leme | 343175a | 2016-08-02 18:57:37 -0700 | [diff] [blame] | 26 | #include <utils/String16.h> |
Steven Moreland | a0f7f2d | 2017-03-09 22:59:32 -0800 | [diff] [blame] | 27 | #include <utils/String8.h> |
Felipe Leme | 343175a | 2016-08-02 18:57:37 -0700 | [diff] [blame] | 28 | #include <utils/Vector.h> |
| 29 | |
| 30 | using namespace android; |
| 31 | |
| 32 | using ::testing::_; |
| 33 | using ::testing::Action; |
| 34 | using ::testing::ActionInterface; |
| 35 | using ::testing::DoAll; |
| 36 | using ::testing::Eq; |
| 37 | using ::testing::HasSubstr; |
| 38 | using ::testing::MakeAction; |
Felipe Leme | 5c8a98f | 2017-08-25 13:39:04 -0700 | [diff] [blame] | 39 | using ::testing::Mock; |
Felipe Leme | 343175a | 2016-08-02 18:57:37 -0700 | [diff] [blame] | 40 | using ::testing::Not; |
| 41 | using ::testing::Return; |
| 42 | using ::testing::StrEq; |
| 43 | using ::testing::Test; |
| 44 | using ::testing::WithArg; |
| 45 | using ::testing::internal::CaptureStderr; |
| 46 | using ::testing::internal::CaptureStdout; |
| 47 | using ::testing::internal::GetCapturedStderr; |
| 48 | using ::testing::internal::GetCapturedStdout; |
| 49 | |
| 50 | class ServiceManagerMock : public IServiceManager { |
| 51 | public: |
| 52 | MOCK_CONST_METHOD1(getService, sp<IBinder>(const String16&)); |
| 53 | MOCK_CONST_METHOD1(checkService, sp<IBinder>(const String16&)); |
Vishnu Nair | f56042d | 2017-09-19 15:25:10 -0700 | [diff] [blame] | 54 | MOCK_METHOD4(addService, status_t(const String16&, const sp<IBinder>&, bool, int)); |
| 55 | MOCK_METHOD1(listServices, Vector<String16>(int)); |
Felipe Leme | 343175a | 2016-08-02 18:57:37 -0700 | [diff] [blame] | 56 | |
| 57 | protected: |
| 58 | MOCK_METHOD0(onAsBinder, IBinder*()); |
| 59 | }; |
| 60 | |
| 61 | class BinderMock : public BBinder { |
| 62 | public: |
| 63 | BinderMock() { |
| 64 | } |
| 65 | |
| 66 | MOCK_METHOD2(dump, status_t(int, const Vector<String16>&)); |
| 67 | }; |
| 68 | |
| 69 | // gmock black magic to provide a WithArg<0>(WriteOnFd(output)) matcher |
| 70 | typedef void WriteOnFdFunction(int); |
| 71 | |
| 72 | class WriteOnFdAction : public ActionInterface<WriteOnFdFunction> { |
| 73 | public: |
| 74 | explicit WriteOnFdAction(const std::string& output) : output_(output) { |
| 75 | } |
| 76 | virtual Result Perform(const ArgumentTuple& args) { |
| 77 | int fd = ::std::tr1::get<0>(args); |
| 78 | android::base::WriteStringToFd(output_, fd); |
| 79 | } |
| 80 | |
| 81 | private: |
| 82 | std::string output_; |
| 83 | }; |
| 84 | |
| 85 | // Matcher used to emulate dump() by writing on its file descriptor. |
| 86 | Action<WriteOnFdFunction> WriteOnFd(const std::string& output) { |
| 87 | return MakeAction(new WriteOnFdAction(output)); |
| 88 | } |
| 89 | |
| 90 | // Matcher for args using Android's Vector<String16> format |
| 91 | // TODO: move it to some common testing library |
| 92 | MATCHER_P(AndroidElementsAre, expected, "") { |
| 93 | std::ostringstream errors; |
| 94 | if (arg.size() != expected.size()) { |
| 95 | errors << " sizes do not match (expected " << expected.size() << ", got " << arg.size() |
| 96 | << ")\n"; |
| 97 | } |
| 98 | int i = 0; |
| 99 | std::ostringstream actual_stream, expected_stream; |
Chih-Hung Hsieh | cb057c2 | 2017-08-03 15:48:25 -0700 | [diff] [blame] | 100 | for (const String16& actual : arg) { |
Steven Moreland | a0f7f2d | 2017-03-09 22:59:32 -0800 | [diff] [blame] | 101 | std::string actual_str = String8(actual).c_str(); |
Felipe Leme | 343175a | 2016-08-02 18:57:37 -0700 | [diff] [blame] | 102 | std::string expected_str = expected[i]; |
| 103 | actual_stream << "'" << actual_str << "' "; |
| 104 | expected_stream << "'" << expected_str << "' "; |
| 105 | if (actual_str != expected_str) { |
| 106 | errors << " element mismatch at index " << i << "\n"; |
| 107 | } |
| 108 | i++; |
| 109 | } |
| 110 | |
| 111 | if (!errors.str().empty()) { |
| 112 | errors << "\nExpected args: " << expected_stream.str() |
| 113 | << "\nActual args: " << actual_stream.str(); |
| 114 | *result_listener << errors.str(); |
| 115 | return false; |
| 116 | } |
| 117 | return true; |
| 118 | } |
| 119 | |
| 120 | // Custom action to sleep for timeout seconds |
| 121 | ACTION_P(Sleep, timeout) { |
| 122 | sleep(timeout); |
| 123 | } |
| 124 | |
| 125 | class DumpsysTest : public Test { |
| 126 | public: |
Steven Moreland | 2c3cd83 | 2017-02-13 23:44:17 +0000 | [diff] [blame] | 127 | DumpsysTest() : sm_(), dump_(&sm_), stdout_(), stderr_() { |
Felipe Leme | 343175a | 2016-08-02 18:57:37 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | void ExpectListServices(std::vector<std::string> services) { |
| 131 | Vector<String16> services16; |
| 132 | for (auto& service : services) { |
| 133 | services16.add(String16(service.c_str())); |
| 134 | } |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 135 | EXPECT_CALL(sm_, listServices(IServiceManager::DUMP_FLAG_PRIORITY_ALL)) |
Vishnu Nair | f56042d | 2017-09-19 15:25:10 -0700 | [diff] [blame] | 136 | .WillRepeatedly(Return(services16)); |
| 137 | } |
| 138 | |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 139 | void ExpectListServicesWithPriority(std::vector<std::string> services, int dumpFlags) { |
Vishnu Nair | f56042d | 2017-09-19 15:25:10 -0700 | [diff] [blame] | 140 | Vector<String16> services16; |
| 141 | for (auto& service : services) { |
| 142 | services16.add(String16(service.c_str())); |
| 143 | } |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 144 | EXPECT_CALL(sm_, listServices(dumpFlags)).WillRepeatedly(Return(services16)); |
Felipe Leme | 343175a | 2016-08-02 18:57:37 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | sp<BinderMock> ExpectCheckService(const char* name, bool running = true) { |
| 148 | sp<BinderMock> binder_mock; |
| 149 | if (running) { |
| 150 | binder_mock = new BinderMock; |
| 151 | } |
| 152 | EXPECT_CALL(sm_, checkService(String16(name))).WillRepeatedly(Return(binder_mock)); |
| 153 | return binder_mock; |
| 154 | } |
| 155 | |
| 156 | void ExpectDump(const char* name, const std::string& output) { |
| 157 | sp<BinderMock> binder_mock = ExpectCheckService(name); |
| 158 | EXPECT_CALL(*binder_mock, dump(_, _)) |
| 159 | .WillRepeatedly(DoAll(WithArg<0>(WriteOnFd(output)), Return(0))); |
| 160 | } |
| 161 | |
| 162 | void ExpectDumpWithArgs(const char* name, std::vector<std::string> args, |
| 163 | const std::string& output) { |
| 164 | sp<BinderMock> binder_mock = ExpectCheckService(name); |
| 165 | EXPECT_CALL(*binder_mock, dump(_, AndroidElementsAre(args))) |
| 166 | .WillRepeatedly(DoAll(WithArg<0>(WriteOnFd(output)), Return(0))); |
| 167 | } |
| 168 | |
Felipe Leme | 5c8a98f | 2017-08-25 13:39:04 -0700 | [diff] [blame] | 169 | sp<BinderMock> ExpectDumpAndHang(const char* name, int timeout_s, const std::string& output) { |
Felipe Leme | 343175a | 2016-08-02 18:57:37 -0700 | [diff] [blame] | 170 | sp<BinderMock> binder_mock = ExpectCheckService(name); |
| 171 | EXPECT_CALL(*binder_mock, dump(_, _)) |
| 172 | .WillRepeatedly(DoAll(Sleep(timeout_s), WithArg<0>(WriteOnFd(output)), Return(0))); |
Felipe Leme | 5c8a98f | 2017-08-25 13:39:04 -0700 | [diff] [blame] | 173 | return binder_mock; |
Felipe Leme | 343175a | 2016-08-02 18:57:37 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | void CallMain(const std::vector<std::string>& args) { |
| 177 | const char* argv[1024] = {"/some/virtual/dir/dumpsys"}; |
| 178 | int argc = (int)args.size() + 1; |
| 179 | int i = 1; |
| 180 | for (const std::string& arg : args) { |
| 181 | argv[i++] = arg.c_str(); |
| 182 | } |
| 183 | CaptureStdout(); |
| 184 | CaptureStderr(); |
| 185 | int status = dump_.main(argc, const_cast<char**>(argv)); |
| 186 | stdout_ = GetCapturedStdout(); |
| 187 | stderr_ = GetCapturedStderr(); |
| 188 | EXPECT_THAT(status, Eq(0)); |
| 189 | } |
| 190 | |
Steven Moreland | 2c3cd83 | 2017-02-13 23:44:17 +0000 | [diff] [blame] | 191 | void AssertRunningServices(const std::vector<std::string>& services) { |
Vishnu Nair | f56042d | 2017-09-19 15:25:10 -0700 | [diff] [blame] | 192 | std::string expected; |
| 193 | if (services.size() > 1) { |
| 194 | expected.append("Currently running services:\n"); |
| 195 | } |
Felipe Leme | 343175a | 2016-08-02 18:57:37 -0700 | [diff] [blame] | 196 | for (const std::string& service : services) { |
| 197 | expected.append(" ").append(service).append("\n"); |
| 198 | } |
| 199 | EXPECT_THAT(stdout_, HasSubstr(expected)); |
| 200 | } |
| 201 | |
| 202 | void AssertOutput(const std::string& expected) { |
| 203 | EXPECT_THAT(stdout_, StrEq(expected)); |
| 204 | } |
| 205 | |
| 206 | void AssertOutputContains(const std::string& expected) { |
| 207 | EXPECT_THAT(stdout_, HasSubstr(expected)); |
| 208 | } |
| 209 | |
| 210 | void AssertDumped(const std::string& service, const std::string& dump) { |
| 211 | EXPECT_THAT(stdout_, HasSubstr("DUMP OF SERVICE " + service + ":\n" + dump)); |
| 212 | } |
| 213 | |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 214 | void AssertDumpedWithPriority(const std::string& service, const std::string& dump, |
| 215 | const char16_t* priorityType) { |
| 216 | std::string priority = String8(priorityType).c_str(); |
| 217 | EXPECT_THAT(stdout_, |
| 218 | HasSubstr("DUMP OF SERVICE " + priority + " " + service + ":\n" + dump)); |
| 219 | } |
| 220 | |
Felipe Leme | 343175a | 2016-08-02 18:57:37 -0700 | [diff] [blame] | 221 | void AssertNotDumped(const std::string& dump) { |
| 222 | EXPECT_THAT(stdout_, Not(HasSubstr(dump))); |
| 223 | } |
| 224 | |
| 225 | void AssertStopped(const std::string& service) { |
| 226 | EXPECT_THAT(stderr_, HasSubstr("Can't find service: " + service + "\n")); |
| 227 | } |
| 228 | |
| 229 | ServiceManagerMock sm_; |
| 230 | Dumpsys dump_; |
| 231 | |
| 232 | private: |
| 233 | std::string stdout_, stderr_; |
| 234 | }; |
| 235 | |
Felipe Leme | 343175a | 2016-08-02 18:57:37 -0700 | [diff] [blame] | 236 | // Tests 'dumpsys -l' when all services are running |
| 237 | TEST_F(DumpsysTest, ListAllServices) { |
| 238 | ExpectListServices({"Locksmith", "Valet"}); |
| 239 | ExpectCheckService("Locksmith"); |
| 240 | ExpectCheckService("Valet"); |
| 241 | |
| 242 | CallMain({"-l"}); |
| 243 | |
| 244 | AssertRunningServices({"Locksmith", "Valet"}); |
| 245 | } |
| 246 | |
| 247 | // Tests 'dumpsys -l' when a service is not running |
| 248 | TEST_F(DumpsysTest, ListRunningServices) { |
| 249 | ExpectListServices({"Locksmith", "Valet"}); |
| 250 | ExpectCheckService("Locksmith"); |
| 251 | ExpectCheckService("Valet", false); |
| 252 | |
| 253 | CallMain({"-l"}); |
| 254 | |
| 255 | AssertRunningServices({"Locksmith"}); |
| 256 | AssertNotDumped({"Valet"}); |
| 257 | } |
| 258 | |
Vishnu Nair | f56042d | 2017-09-19 15:25:10 -0700 | [diff] [blame] | 259 | // Tests 'dumpsys -l --priority HIGH' |
| 260 | TEST_F(DumpsysTest, ListAllServicesWithPriority) { |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 261 | ExpectListServicesWithPriority({"Locksmith", "Valet"}, IServiceManager::DUMP_FLAG_PRIORITY_HIGH); |
Vishnu Nair | f56042d | 2017-09-19 15:25:10 -0700 | [diff] [blame] | 262 | ExpectCheckService("Locksmith"); |
| 263 | ExpectCheckService("Valet"); |
| 264 | |
| 265 | CallMain({"-l", "--priority", "HIGH"}); |
| 266 | |
| 267 | AssertRunningServices({"Locksmith", "Valet"}); |
| 268 | } |
| 269 | |
| 270 | // Tests 'dumpsys -l --priority HIGH' with and empty list |
| 271 | TEST_F(DumpsysTest, ListEmptyServicesWithPriority) { |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 272 | ExpectListServicesWithPriority({}, IServiceManager::DUMP_FLAG_PRIORITY_HIGH); |
Vishnu Nair | f56042d | 2017-09-19 15:25:10 -0700 | [diff] [blame] | 273 | |
| 274 | CallMain({"-l", "--priority", "HIGH"}); |
| 275 | |
| 276 | AssertRunningServices({}); |
| 277 | } |
| 278 | |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 279 | // Tests 'dumpsys -l --proto' |
| 280 | TEST_F(DumpsysTest, ListAllServicesWithProto) { |
| 281 | ExpectListServicesWithPriority({"Locksmith", "Valet", "Car"}, |
| 282 | IServiceManager::DUMP_FLAG_PRIORITY_ALL); |
| 283 | ExpectListServicesWithPriority({"Valet", "Car"}, IServiceManager::DUMP_FLAG_PROTO); |
| 284 | ExpectCheckService("Car"); |
| 285 | ExpectCheckService("Valet"); |
| 286 | |
| 287 | CallMain({"-l", "--proto"}); |
| 288 | |
| 289 | AssertRunningServices({"Car", "Valet"}); |
| 290 | } |
| 291 | |
Felipe Leme | 343175a | 2016-08-02 18:57:37 -0700 | [diff] [blame] | 292 | // Tests 'dumpsys service_name' on a service is running |
| 293 | TEST_F(DumpsysTest, DumpRunningService) { |
| 294 | ExpectDump("Valet", "Here's your car"); |
| 295 | |
| 296 | CallMain({"Valet"}); |
| 297 | |
| 298 | AssertOutput("Here's your car"); |
| 299 | } |
| 300 | |
| 301 | // Tests 'dumpsys -t 1 service_name' on a service that times out after 2s |
| 302 | TEST_F(DumpsysTest, DumpRunningServiceTimeout) { |
Felipe Leme | 5c8a98f | 2017-08-25 13:39:04 -0700 | [diff] [blame] | 303 | sp<BinderMock> binder_mock = ExpectDumpAndHang("Valet", 2, "Here's your car"); |
Felipe Leme | 343175a | 2016-08-02 18:57:37 -0700 | [diff] [blame] | 304 | |
| 305 | CallMain({"-t", "1", "Valet"}); |
| 306 | |
| 307 | AssertOutputContains("SERVICE 'Valet' DUMP TIMEOUT (1s) EXPIRED"); |
| 308 | AssertNotDumped("Here's your car"); |
| 309 | |
Felipe Leme | 5c8a98f | 2017-08-25 13:39:04 -0700 | [diff] [blame] | 310 | // TODO(b/65056227): BinderMock is not destructed because thread is detached on dumpsys.cpp |
| 311 | Mock::AllowLeak(binder_mock.get()); |
Felipe Leme | 343175a | 2016-08-02 18:57:37 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | // Tests 'dumpsys service_name Y U NO HAVE ARGS' on a service that is running |
| 315 | TEST_F(DumpsysTest, DumpWithArgsRunningService) { |
| 316 | ExpectDumpWithArgs("SERVICE", {"Y", "U", "NO", "HANDLE", "ARGS"}, "I DO!"); |
| 317 | |
| 318 | CallMain({"SERVICE", "Y", "U", "NO", "HANDLE", "ARGS"}); |
| 319 | |
| 320 | AssertOutput("I DO!"); |
| 321 | } |
| 322 | |
| 323 | // Tests 'dumpsys' with no arguments |
| 324 | TEST_F(DumpsysTest, DumpMultipleServices) { |
| 325 | ExpectListServices({"running1", "stopped2", "running3"}); |
| 326 | ExpectDump("running1", "dump1"); |
| 327 | ExpectCheckService("stopped2", false); |
| 328 | ExpectDump("running3", "dump3"); |
| 329 | |
| 330 | CallMain({}); |
| 331 | |
| 332 | AssertRunningServices({"running1", "running3"}); |
| 333 | AssertDumped("running1", "dump1"); |
| 334 | AssertStopped("stopped2"); |
| 335 | AssertDumped("running3", "dump3"); |
| 336 | } |
| 337 | |
| 338 | // Tests 'dumpsys --skip skipped3 skipped5', which should skip these services |
| 339 | TEST_F(DumpsysTest, DumpWithSkip) { |
| 340 | ExpectListServices({"running1", "stopped2", "skipped3", "running4", "skipped5"}); |
| 341 | ExpectDump("running1", "dump1"); |
| 342 | ExpectCheckService("stopped2", false); |
| 343 | ExpectDump("skipped3", "dump3"); |
| 344 | ExpectDump("running4", "dump4"); |
| 345 | ExpectDump("skipped5", "dump5"); |
| 346 | |
| 347 | CallMain({"--skip", "skipped3", "skipped5"}); |
| 348 | |
| 349 | AssertRunningServices({"running1", "running4", "skipped3 (skipped)", "skipped5 (skipped)"}); |
| 350 | AssertDumped("running1", "dump1"); |
| 351 | AssertDumped("running4", "dump4"); |
| 352 | AssertStopped("stopped2"); |
| 353 | AssertNotDumped("dump3"); |
| 354 | AssertNotDumped("dump5"); |
| 355 | } |
Vishnu Nair | f56042d | 2017-09-19 15:25:10 -0700 | [diff] [blame] | 356 | |
| 357 | // Tests 'dumpsys --skip skipped3 skipped5 --priority CRITICAL', which should skip these services |
| 358 | TEST_F(DumpsysTest, DumpWithSkipAndPriority) { |
| 359 | ExpectListServicesWithPriority({"running1", "stopped2", "skipped3", "running4", "skipped5"}, |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 360 | IServiceManager::DUMP_FLAG_PRIORITY_CRITICAL); |
Vishnu Nair | f56042d | 2017-09-19 15:25:10 -0700 | [diff] [blame] | 361 | ExpectDump("running1", "dump1"); |
| 362 | ExpectCheckService("stopped2", false); |
| 363 | ExpectDump("skipped3", "dump3"); |
| 364 | ExpectDump("running4", "dump4"); |
| 365 | ExpectDump("skipped5", "dump5"); |
| 366 | |
| 367 | CallMain({"--priority", "CRITICAL", "--skip", "skipped3", "skipped5"}); |
| 368 | |
| 369 | AssertRunningServices({"running1", "running4", "skipped3 (skipped)", "skipped5 (skipped)"}); |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 370 | AssertDumpedWithPriority("running1", "dump1", PriorityDumper::PRIORITY_ARG_CRITICAL); |
| 371 | AssertDumpedWithPriority("running4", "dump4", PriorityDumper::PRIORITY_ARG_CRITICAL); |
Vishnu Nair | f56042d | 2017-09-19 15:25:10 -0700 | [diff] [blame] | 372 | AssertStopped("stopped2"); |
| 373 | AssertNotDumped("dump3"); |
| 374 | AssertNotDumped("dump5"); |
| 375 | } |
| 376 | |
| 377 | // Tests 'dumpsys --priority CRITICAL' |
| 378 | TEST_F(DumpsysTest, DumpWithPriorityCritical) { |
| 379 | ExpectListServicesWithPriority({"runningcritical1", "runningcritical2"}, |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 380 | IServiceManager::DUMP_FLAG_PRIORITY_CRITICAL); |
Vishnu Nair | f56042d | 2017-09-19 15:25:10 -0700 | [diff] [blame] | 381 | ExpectDump("runningcritical1", "dump1"); |
| 382 | ExpectDump("runningcritical2", "dump2"); |
| 383 | |
| 384 | CallMain({"--priority", "CRITICAL"}); |
| 385 | |
| 386 | AssertRunningServices({"runningcritical1", "runningcritical2"}); |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 387 | AssertDumpedWithPriority("runningcritical1", "dump1", PriorityDumper::PRIORITY_ARG_CRITICAL); |
| 388 | AssertDumpedWithPriority("runningcritical2", "dump2", PriorityDumper::PRIORITY_ARG_CRITICAL); |
Vishnu Nair | f56042d | 2017-09-19 15:25:10 -0700 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | // Tests 'dumpsys --priority HIGH' |
| 392 | TEST_F(DumpsysTest, DumpWithPriorityHigh) { |
| 393 | ExpectListServicesWithPriority({"runninghigh1", "runninghigh2"}, |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 394 | IServiceManager::DUMP_FLAG_PRIORITY_HIGH); |
Vishnu Nair | f56042d | 2017-09-19 15:25:10 -0700 | [diff] [blame] | 395 | ExpectDump("runninghigh1", "dump1"); |
| 396 | ExpectDump("runninghigh2", "dump2"); |
| 397 | |
| 398 | CallMain({"--priority", "HIGH"}); |
| 399 | |
| 400 | AssertRunningServices({"runninghigh1", "runninghigh2"}); |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 401 | AssertDumpedWithPriority("runninghigh1", "dump1", PriorityDumper::PRIORITY_ARG_HIGH); |
| 402 | AssertDumpedWithPriority("runninghigh2", "dump2", PriorityDumper::PRIORITY_ARG_HIGH); |
Vishnu Nair | f56042d | 2017-09-19 15:25:10 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | // Tests 'dumpsys --priority NORMAL' |
| 406 | TEST_F(DumpsysTest, DumpWithPriorityNormal) { |
| 407 | ExpectListServicesWithPriority({"runningnormal1", "runningnormal2"}, |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 408 | IServiceManager::DUMP_FLAG_PRIORITY_NORMAL); |
Vishnu Nair | f56042d | 2017-09-19 15:25:10 -0700 | [diff] [blame] | 409 | ExpectDump("runningnormal1", "dump1"); |
| 410 | ExpectDump("runningnormal2", "dump2"); |
| 411 | |
| 412 | CallMain({"--priority", "NORMAL"}); |
| 413 | |
| 414 | AssertRunningServices({"runningnormal1", "runningnormal2"}); |
Vishnu Nair | 6a40853 | 2017-10-24 09:11:27 -0700 | [diff] [blame] | 415 | AssertDumpedWithPriority("runningnormal1", "dump1", PriorityDumper::PRIORITY_ARG_NORMAL); |
| 416 | AssertDumpedWithPriority("runningnormal2", "dump2", PriorityDumper::PRIORITY_ARG_NORMAL); |
| 417 | } |
| 418 | |
| 419 | // Tests 'dumpsys --proto' |
| 420 | TEST_F(DumpsysTest, DumpWithProto) { |
| 421 | ExpectListServicesWithPriority({"run8", "run1", "run2", "run5"}, |
| 422 | IServiceManager::DUMP_FLAG_PRIORITY_ALL); |
| 423 | ExpectListServicesWithPriority({"run3", "run2", "run4", "run8"}, |
| 424 | IServiceManager::DUMP_FLAG_PROTO); |
| 425 | ExpectDump("run2", "dump1"); |
| 426 | ExpectDump("run8", "dump2"); |
| 427 | |
| 428 | CallMain({"--proto"}); |
| 429 | |
| 430 | AssertRunningServices({"run2", "run8"}); |
| 431 | AssertDumped("run2", "dump1"); |
| 432 | AssertDumped("run8", "dump2"); |
| 433 | } |
| 434 | |
| 435 | // Tests 'dumpsys --priority HIGH --proto' |
| 436 | TEST_F(DumpsysTest, DumpWithPriorityHighAndProto) { |
| 437 | ExpectListServicesWithPriority({"runninghigh1", "runninghigh2"}, |
| 438 | IServiceManager::DUMP_FLAG_PRIORITY_HIGH); |
| 439 | ExpectListServicesWithPriority({"runninghigh1", "runninghigh2", "runninghigh3"}, |
| 440 | IServiceManager::DUMP_FLAG_PROTO); |
| 441 | |
| 442 | ExpectDump("runninghigh1", "dump1"); |
| 443 | ExpectDump("runninghigh2", "dump2"); |
| 444 | |
| 445 | CallMain({"--priority", "HIGH", "--proto"}); |
| 446 | |
| 447 | AssertRunningServices({"runninghigh1", "runninghigh2"}); |
| 448 | AssertDumpedWithPriority("runninghigh1", "dump1", PriorityDumper::PRIORITY_ARG_HIGH); |
| 449 | AssertDumpedWithPriority("runninghigh2", "dump2", PriorityDumper::PRIORITY_ARG_HIGH); |
Vishnu Nair | f56042d | 2017-09-19 15:25:10 -0700 | [diff] [blame] | 450 | } |