blob: 84eeab39cab771c1f4def672e149ddd00e4e36c0 [file] [log] [blame]
Felipe Leme4c2d6632016-09-28 14:32:00 -07001/*
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
Felipe Leme75876a22016-10-27 16:31:27 -070017#define LOG_TAG "dumpstate"
18#include <cutils/log.h>
19
Felipe Lemef0292972016-11-22 13:57:05 -080020#include "DumpstateInternal.h"
Felipe Leme75876a22016-10-27 16:31:27 -070021#include "DumpstateService.h"
22#include "android/os/BnDumpstate.h"
Felipe Leme4c2d6632016-09-28 14:32:00 -070023#include "dumpstate.h"
24
25#include <gmock/gmock.h>
26#include <gtest/gtest.h>
27
Felipe Leme46b85da2016-11-21 17:40:45 -080028#include <fcntl.h>
Felipe Leme4c2d6632016-09-28 14:32:00 -070029#include <libgen.h>
Felipe Lemefd8affa2016-09-30 17:38:57 -070030#include <signal.h>
31#include <sys/types.h>
Felipe Leme4c2d6632016-09-28 14:32:00 -070032#include <unistd.h>
Felipe Lemefd8affa2016-09-30 17:38:57 -070033#include <thread>
Felipe Leme4c2d6632016-09-28 14:32:00 -070034
35#include <android-base/file.h>
Felipe Lemed80e6b62016-10-03 13:08:14 -070036#include <android-base/properties.h>
37#include <android-base/stringprintf.h>
Felipe Lemefd8affa2016-09-30 17:38:57 -070038#include <android-base/strings.h>
Abhijeet Kaur904e0e02018-12-05 14:03:01 +000039#include <cutils/properties.h>
Abhijeet Kaure370d682019-10-01 16:49:30 +010040#include <android-base/unique_fd.h>
Felipe Leme4c2d6632016-09-28 14:32:00 -070041
Felipe Leme47e9be22016-12-21 15:37:07 -080042namespace android {
43namespace os {
44namespace dumpstate {
Felipe Lemed80e6b62016-10-03 13:08:14 -070045
Felipe Leme4c2d6632016-09-28 14:32:00 -070046using ::testing::EndsWith;
Felipe Leme46b85da2016-11-21 17:40:45 -080047using ::testing::HasSubstr;
Felipe Leme009ecbb2016-11-07 10:18:44 -080048using ::testing::IsNull;
Felipe Leme4c2d6632016-09-28 14:32:00 -070049using ::testing::IsEmpty;
Felipe Leme009ecbb2016-11-07 10:18:44 -080050using ::testing::NotNull;
Felipe Leme4c2d6632016-09-28 14:32:00 -070051using ::testing::StrEq;
52using ::testing::StartsWith;
53using ::testing::Test;
54using ::testing::internal::CaptureStderr;
55using ::testing::internal::CaptureStdout;
56using ::testing::internal::GetCapturedStderr;
57using ::testing::internal::GetCapturedStdout;
58
Nandana Dutt3f8c7172018-09-25 12:01:54 +010059#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
60
Felipe Leme75876a22016-10-27 16:31:27 -070061class DumpstateListenerMock : public IDumpstateListener {
62 public:
Nandana Dutta6a28bd2019-01-14 16:54:38 +000063 MOCK_METHOD1(onProgress, binder::Status(int32_t progress));
64 MOCK_METHOD1(onError, binder::Status(int32_t error_code));
Nandana Duttcc4ead82019-01-23 08:29:23 +000065 MOCK_METHOD0(onFinished, binder::Status());
Felipe Leme75876a22016-10-27 16:31:27 -070066
67 protected:
68 MOCK_METHOD0(onAsBinder, IBinder*());
69};
70
Felipe Leme46b85da2016-11-21 17:40:45 -080071static int calls_;
72
Felipe Leme7447d7c2016-11-03 18:12:22 -070073// Base class for all tests in this file
74class DumpstateBaseTest : public Test {
Felipe Leme46b85da2016-11-21 17:40:45 -080075 public:
76 virtual void SetUp() override {
77 calls_++;
Felipe Lemef0292972016-11-22 13:57:05 -080078 SetDryRun(false);
Felipe Leme46b85da2016-11-21 17:40:45 -080079 }
80
Felipe Lemef0292972016-11-22 13:57:05 -080081 void SetDryRun(bool dry_run) const {
82 PropertiesHelper::dry_run_ = dry_run;
83 }
84
85 void SetBuildType(const std::string& build_type) const {
86 PropertiesHelper::build_type_ = build_type;
87 }
88
Nandana Dutt4b392be2018-11-02 16:17:05 +000089 void SetUnroot(bool unroot) const {
90 PropertiesHelper::unroot_ = unroot;
91 }
92
Felipe Lemef0292972016-11-22 13:57:05 -080093 bool IsStandalone() const {
Felipe Leme46b85da2016-11-21 17:40:45 -080094 return calls_ == 1;
95 }
96
Felipe Lemef0292972016-11-22 13:57:05 -080097 void DropRoot() const {
98 DropRootUser();
Felipe Leme46b85da2016-11-21 17:40:45 -080099 uid_t uid = getuid();
100 ASSERT_EQ(2000, (int)uid);
101 }
102
Felipe Leme7447d7c2016-11-03 18:12:22 -0700103 protected:
104 const std::string kTestPath = dirname(android::base::GetExecutablePath().c_str());
Dan Shie177e8e2019-06-20 11:08:14 -0700105 const std::string kTestDataPath = kTestPath + "/tests/testdata/";
106 const std::string kSimpleCommand = kTestPath + "/dumpstate_test_fixture";
Felipe Leme7447d7c2016-11-03 18:12:22 -0700107 const std::string kEchoCommand = "/system/bin/echo";
108
109 /*
110 * Copies a text file fixture to a temporary file, returning it's path.
111 *
112 * Useful in cases where the test case changes the content of the tile.
113 */
114 std::string CopyTextFileFixture(const std::string& relative_name) {
115 std::string from = kTestDataPath + relative_name;
116 // Not using TemporaryFile because it's deleted at the end, and it's useful to keep it
117 // around for poking when the test fails.
118 std::string to = kTestDataPath + relative_name + ".tmp";
119 ALOGD("CopyTextFileFixture: from %s to %s\n", from.c_str(), to.c_str());
120 android::base::RemoveFileIfExists(to);
121 CopyTextFile(from, to);
122 return to.c_str();
123 }
124
Felipe Leme46b85da2016-11-21 17:40:45 -0800125 // Need functions that returns void to use assertions -
Felipe Leme7447d7c2016-11-03 18:12:22 -0700126 // https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md#assertion-placement
Felipe Leme46b85da2016-11-21 17:40:45 -0800127 void ReadFileToString(const std::string& path, std::string* content) {
128 ASSERT_TRUE(android::base::ReadFileToString(path, content))
129 << "could not read contents from " << path;
130 }
131 void WriteStringToFile(const std::string& content, const std::string& path) {
132 ASSERT_TRUE(android::base::WriteStringToFile(content, path))
133 << "could not write contents to " << path;
134 }
135
136 private:
Felipe Leme7447d7c2016-11-03 18:12:22 -0700137 void CopyTextFile(const std::string& from, const std::string& to) {
138 std::string content;
Felipe Leme46b85da2016-11-21 17:40:45 -0800139 ReadFileToString(from, &content);
140 WriteStringToFile(content, to);
Felipe Leme7447d7c2016-11-03 18:12:22 -0700141 }
142};
143
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100144class DumpOptionsTest : public Test {
145 public:
146 virtual ~DumpOptionsTest() {
147 }
148 virtual void SetUp() {
149 options_ = Dumpstate::DumpOptions();
150 }
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000151 void TearDown() {
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000152 }
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100153 Dumpstate::DumpOptions options_;
Abhijeet Kaure370d682019-10-01 16:49:30 +0100154 android::base::unique_fd fd;
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100155};
156
157TEST_F(DumpOptionsTest, InitializeNone) {
158 // clang-format off
159 char* argv[] = {
160 const_cast<char*>("dumpstate")
161 };
162 // clang-format on
163
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100164 Dumpstate::RunStatus status = options_.Initialize(ARRAY_SIZE(argv), argv);
165
166 EXPECT_EQ(status, Dumpstate::RunStatus::OK);
Nandana Dutt58d72e22018-11-16 10:30:48 +0000167
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100168 EXPECT_FALSE(options_.do_add_date);
169 EXPECT_FALSE(options_.do_zip_file);
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100170 EXPECT_FALSE(options_.use_socket);
171 EXPECT_FALSE(options_.use_control_socket);
172 EXPECT_FALSE(options_.show_header_only);
173 EXPECT_TRUE(options_.do_vibrate);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000174 EXPECT_FALSE(options_.do_fb);
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100175 EXPECT_FALSE(options_.do_progress_updates);
176 EXPECT_FALSE(options_.is_remote_mode);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000177}
178
179TEST_F(DumpOptionsTest, InitializeAdbBugreport) {
180 // clang-format off
181 char* argv[] = {
182 const_cast<char*>("dumpstatez"),
183 const_cast<char*>("-S"),
184 const_cast<char*>("-d"),
185 const_cast<char*>("-z"),
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000186 };
187 // clang-format on
188
189 Dumpstate::RunStatus status = options_.Initialize(ARRAY_SIZE(argv), argv);
190
191 EXPECT_EQ(status, Dumpstate::RunStatus::OK);
192 EXPECT_TRUE(options_.do_add_date);
193 EXPECT_TRUE(options_.do_zip_file);
194 EXPECT_TRUE(options_.use_control_socket);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000195
196 // Other options retain default values
197 EXPECT_TRUE(options_.do_vibrate);
198 EXPECT_FALSE(options_.show_header_only);
199 EXPECT_FALSE(options_.do_fb);
200 EXPECT_FALSE(options_.do_progress_updates);
201 EXPECT_FALSE(options_.is_remote_mode);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000202 EXPECT_FALSE(options_.use_socket);
203}
204
205TEST_F(DumpOptionsTest, InitializeAdbShellBugreport) {
206 // clang-format off
207 char* argv[] = {
208 const_cast<char*>("dumpstate"),
209 const_cast<char*>("-s"),
210 };
211 // clang-format on
212
213 Dumpstate::RunStatus status = options_.Initialize(ARRAY_SIZE(argv), argv);
214
215 EXPECT_EQ(status, Dumpstate::RunStatus::OK);
216 EXPECT_TRUE(options_.use_socket);
217
218 // Other options retain default values
219 EXPECT_TRUE(options_.do_vibrate);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000220 EXPECT_FALSE(options_.do_add_date);
221 EXPECT_FALSE(options_.do_zip_file);
222 EXPECT_FALSE(options_.use_control_socket);
223 EXPECT_FALSE(options_.show_header_only);
224 EXPECT_FALSE(options_.do_fb);
225 EXPECT_FALSE(options_.do_progress_updates);
226 EXPECT_FALSE(options_.is_remote_mode);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000227}
228
229TEST_F(DumpOptionsTest, InitializeFullBugReport) {
Abhijeet Kaure370d682019-10-01 16:49:30 +0100230 options_.Initialize(Dumpstate::BugreportMode::BUGREPORT_FULL, fd, fd);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000231 EXPECT_TRUE(options_.do_add_date);
232 EXPECT_TRUE(options_.do_fb);
233 EXPECT_TRUE(options_.do_zip_file);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000234
235 // Other options retain default values
236 EXPECT_TRUE(options_.do_vibrate);
237 EXPECT_FALSE(options_.use_control_socket);
238 EXPECT_FALSE(options_.show_header_only);
239 EXPECT_FALSE(options_.do_progress_updates);
240 EXPECT_FALSE(options_.is_remote_mode);
241 EXPECT_FALSE(options_.use_socket);
242 EXPECT_FALSE(options_.do_start_service);
243}
244
245TEST_F(DumpOptionsTest, InitializeInteractiveBugReport) {
Abhijeet Kaure370d682019-10-01 16:49:30 +0100246 options_.Initialize(Dumpstate::BugreportMode::BUGREPORT_INTERACTIVE, fd, fd);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000247 EXPECT_TRUE(options_.do_add_date);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000248 EXPECT_TRUE(options_.do_zip_file);
249 EXPECT_TRUE(options_.do_progress_updates);
250 EXPECT_TRUE(options_.do_start_service);
251 EXPECT_FALSE(options_.do_fb);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000252
253 // Other options retain default values
254 EXPECT_TRUE(options_.do_vibrate);
255 EXPECT_FALSE(options_.use_control_socket);
256 EXPECT_FALSE(options_.show_header_only);
257 EXPECT_FALSE(options_.is_remote_mode);
258 EXPECT_FALSE(options_.use_socket);
259}
260
261TEST_F(DumpOptionsTest, InitializeRemoteBugReport) {
Abhijeet Kaure370d682019-10-01 16:49:30 +0100262 options_.Initialize(Dumpstate::BugreportMode::BUGREPORT_REMOTE, fd, fd);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000263 EXPECT_TRUE(options_.do_add_date);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000264 EXPECT_TRUE(options_.do_zip_file);
265 EXPECT_TRUE(options_.is_remote_mode);
266 EXPECT_FALSE(options_.do_vibrate);
267 EXPECT_FALSE(options_.do_fb);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000268
269 // Other options retain default values
270 EXPECT_FALSE(options_.use_control_socket);
271 EXPECT_FALSE(options_.show_header_only);
272 EXPECT_FALSE(options_.do_progress_updates);
273 EXPECT_FALSE(options_.use_socket);
274}
275
276TEST_F(DumpOptionsTest, InitializeWearBugReport) {
Abhijeet Kaure370d682019-10-01 16:49:30 +0100277 options_.Initialize(Dumpstate::BugreportMode::BUGREPORT_WEAR, fd, fd);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000278 EXPECT_TRUE(options_.do_add_date);
279 EXPECT_TRUE(options_.do_fb);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000280 EXPECT_TRUE(options_.do_zip_file);
281 EXPECT_TRUE(options_.do_progress_updates);
282 EXPECT_TRUE(options_.do_start_service);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000283
284 // Other options retain default values
285 EXPECT_TRUE(options_.do_vibrate);
286 EXPECT_FALSE(options_.use_control_socket);
287 EXPECT_FALSE(options_.show_header_only);
288 EXPECT_FALSE(options_.is_remote_mode);
289 EXPECT_FALSE(options_.use_socket);
290}
291
292TEST_F(DumpOptionsTest, InitializeTelephonyBugReport) {
Abhijeet Kaure370d682019-10-01 16:49:30 +0100293 options_.Initialize(Dumpstate::BugreportMode::BUGREPORT_TELEPHONY, fd, fd);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000294 EXPECT_TRUE(options_.do_add_date);
Abhijeet Kaurd3cca0d2019-03-25 12:04:16 +0000295 EXPECT_FALSE(options_.do_fb);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000296 EXPECT_TRUE(options_.do_zip_file);
297 EXPECT_TRUE(options_.telephony_only);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000298
299 // Other options retain default values
300 EXPECT_TRUE(options_.do_vibrate);
301 EXPECT_FALSE(options_.use_control_socket);
302 EXPECT_FALSE(options_.show_header_only);
303 EXPECT_FALSE(options_.do_progress_updates);
304 EXPECT_FALSE(options_.is_remote_mode);
305 EXPECT_FALSE(options_.use_socket);
306}
307
308TEST_F(DumpOptionsTest, InitializeWifiBugReport) {
Abhijeet Kaure370d682019-10-01 16:49:30 +0100309 options_.Initialize(Dumpstate::BugreportMode::BUGREPORT_WIFI, fd, fd);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000310 EXPECT_TRUE(options_.do_add_date);
Abhijeet Kaurd3cca0d2019-03-25 12:04:16 +0000311 EXPECT_FALSE(options_.do_fb);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000312 EXPECT_TRUE(options_.do_zip_file);
313 EXPECT_TRUE(options_.wifi_only);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000314
315 // Other options retain default values
316 EXPECT_TRUE(options_.do_vibrate);
317 EXPECT_FALSE(options_.use_control_socket);
318 EXPECT_FALSE(options_.show_header_only);
319 EXPECT_FALSE(options_.do_progress_updates);
320 EXPECT_FALSE(options_.is_remote_mode);
321 EXPECT_FALSE(options_.use_socket);
322}
323
324TEST_F(DumpOptionsTest, InitializeDefaultBugReport) {
325 // default: commandline options are not overridden
326 // clang-format off
327 char* argv[] = {
328 const_cast<char*>("bugreport"),
329 const_cast<char*>("-d"),
330 const_cast<char*>("-p"),
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000331 const_cast<char*>("-z"),
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000332 };
333 // clang-format on
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000334 Dumpstate::RunStatus status = options_.Initialize(ARRAY_SIZE(argv), argv);
335
336 EXPECT_EQ(status, Dumpstate::RunStatus::OK);
337 EXPECT_TRUE(options_.do_add_date);
338 EXPECT_TRUE(options_.do_fb);
339 EXPECT_TRUE(options_.do_zip_file);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000340
341 // Other options retain default values
342 EXPECT_TRUE(options_.do_vibrate);
343 EXPECT_FALSE(options_.use_control_socket);
344 EXPECT_FALSE(options_.show_header_only);
345 EXPECT_FALSE(options_.do_progress_updates);
346 EXPECT_FALSE(options_.is_remote_mode);
347 EXPECT_FALSE(options_.use_socket);
348 EXPECT_FALSE(options_.wifi_only);
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100349}
350
351TEST_F(DumpOptionsTest, InitializePartial1) {
352 // clang-format off
353 char* argv[] = {
354 const_cast<char*>("dumpstate"),
355 const_cast<char*>("-d"),
356 const_cast<char*>("-z"),
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100357 const_cast<char*>("-s"),
358 const_cast<char*>("-S"),
359
360 };
361 // clang-format on
362
363 Dumpstate::RunStatus status = options_.Initialize(ARRAY_SIZE(argv), argv);
364
365 EXPECT_EQ(status, Dumpstate::RunStatus::OK);
366 EXPECT_TRUE(options_.do_add_date);
367 EXPECT_TRUE(options_.do_zip_file);
368 // TODO: Maybe we should trim the filename
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100369 EXPECT_TRUE(options_.use_socket);
370 EXPECT_TRUE(options_.use_control_socket);
371
372 // Other options retain default values
373 EXPECT_FALSE(options_.show_header_only);
374 EXPECT_TRUE(options_.do_vibrate);
Abhijeet Kaur904e0e02018-12-05 14:03:01 +0000375 EXPECT_FALSE(options_.do_fb);
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100376 EXPECT_FALSE(options_.do_progress_updates);
377 EXPECT_FALSE(options_.is_remote_mode);
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100378}
379
380TEST_F(DumpOptionsTest, InitializePartial2) {
381 // clang-format off
382 char* argv[] = {
383 const_cast<char*>("dumpstate"),
384 const_cast<char*>("-v"),
385 const_cast<char*>("-q"),
386 const_cast<char*>("-p"),
387 const_cast<char*>("-P"),
388 const_cast<char*>("-R"),
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100389 };
390 // clang-format on
391
392 Dumpstate::RunStatus status = options_.Initialize(ARRAY_SIZE(argv), argv);
393
394 EXPECT_EQ(status, Dumpstate::RunStatus::OK);
395 EXPECT_TRUE(options_.show_header_only);
396 EXPECT_FALSE(options_.do_vibrate);
397 EXPECT_TRUE(options_.do_fb);
398 EXPECT_TRUE(options_.do_progress_updates);
399 EXPECT_TRUE(options_.is_remote_mode);
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100400
401 // Other options retain default values
402 EXPECT_FALSE(options_.do_add_date);
403 EXPECT_FALSE(options_.do_zip_file);
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100404 EXPECT_FALSE(options_.use_socket);
405 EXPECT_FALSE(options_.use_control_socket);
406}
407
408TEST_F(DumpOptionsTest, InitializeHelp) {
409 // clang-format off
410 char* argv[] = {
411 const_cast<char*>("dumpstate"),
412 const_cast<char*>("-h")
413 };
414 // clang-format on
415
416 Dumpstate::RunStatus status = options_.Initialize(ARRAY_SIZE(argv), argv);
417
418 // -h is for help.
419 EXPECT_EQ(status, Dumpstate::RunStatus::HELP);
420}
421
422TEST_F(DumpOptionsTest, InitializeUnknown) {
423 // clang-format off
424 char* argv[] = {
425 const_cast<char*>("dumpstate"),
426 const_cast<char*>("-u") // unknown flag
427 };
428 // clang-format on
429
430 Dumpstate::RunStatus status = options_.Initialize(ARRAY_SIZE(argv), argv);
431
432 // -u is unknown.
433 EXPECT_EQ(status, Dumpstate::RunStatus::INVALID_INPUT);
434}
435
436TEST_F(DumpOptionsTest, ValidateOptionsNeedOutfile1) {
437 options_.do_zip_file = true;
Nandana Dutt9a76d202019-01-21 15:56:48 +0000438 // Writing to socket = !writing to file.
439 options_.use_socket = true;
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100440 EXPECT_FALSE(options_.ValidateOptions());
Nandana Dutt9a76d202019-01-21 15:56:48 +0000441
442 options_.use_socket = false;
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100443 EXPECT_TRUE(options_.ValidateOptions());
444}
445
446TEST_F(DumpOptionsTest, ValidateOptionsNeedOutfile2) {
Abhijeet Kaure370d682019-10-01 16:49:30 +0100447 options_.do_progress_updates = true;
Nandana Dutt9a76d202019-01-21 15:56:48 +0000448 // Writing to socket = !writing to file.
449 options_.use_socket = true;
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100450 EXPECT_FALSE(options_.ValidateOptions());
Nandana Dutt9a76d202019-01-21 15:56:48 +0000451
452 options_.use_socket = false;
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100453 EXPECT_TRUE(options_.ValidateOptions());
454}
455
456TEST_F(DumpOptionsTest, ValidateOptionsNeedZipfile) {
457 options_.use_control_socket = true;
458 EXPECT_FALSE(options_.ValidateOptions());
459
460 options_.do_zip_file = true;
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100461 EXPECT_TRUE(options_.ValidateOptions());
462}
463
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100464TEST_F(DumpOptionsTest, ValidateOptionsRemoteMode) {
465 options_.is_remote_mode = true;
466 EXPECT_FALSE(options_.ValidateOptions());
467
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100468 options_.do_zip_file = true;
469 options_.do_add_date = true;
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100470 EXPECT_TRUE(options_.ValidateOptions());
471}
472
Felipe Leme7447d7c2016-11-03 18:12:22 -0700473class DumpstateTest : public DumpstateBaseTest {
Felipe Leme4c2d6632016-09-28 14:32:00 -0700474 public:
475 void SetUp() {
Felipe Leme46b85da2016-11-21 17:40:45 -0800476 DumpstateBaseTest::SetUp();
Felipe Leme4c2d6632016-09-28 14:32:00 -0700477 SetDryRun(false);
Felipe Lemed80e6b62016-10-03 13:08:14 -0700478 SetBuildType(android::base::GetProperty("ro.build.type", "(unknown)"));
Felipe Leme7447d7c2016-11-03 18:12:22 -0700479 ds.progress_.reset(new Progress());
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100480 ds.options_.reset(new Dumpstate::DumpOptions());
Felipe Leme4c2d6632016-09-28 14:32:00 -0700481 }
482
483 // Runs a command and capture `stdout` and `stderr`.
Felipe Leme9a523ae2016-10-20 15:10:33 -0700484 int RunCommand(const std::string& title, const std::vector<std::string>& full_command,
Felipe Leme4c2d6632016-09-28 14:32:00 -0700485 const CommandOptions& options = CommandOptions::DEFAULT) {
486 CaptureStdout();
487 CaptureStderr();
Felipe Leme9a523ae2016-10-20 15:10:33 -0700488 int status = ds.RunCommand(title, full_command, options);
Felipe Leme4c2d6632016-09-28 14:32:00 -0700489 out = GetCapturedStdout();
490 err = GetCapturedStderr();
491 return status;
492 }
493
Felipe Lemecef02982016-10-03 17:22:22 -0700494 // Dumps a file and capture `stdout` and `stderr`.
495 int DumpFile(const std::string& title, const std::string& path) {
496 CaptureStdout();
497 CaptureStderr();
498 int status = ds.DumpFile(title, path);
499 out = GetCapturedStdout();
500 err = GetCapturedStderr();
501 return status;
502 }
503
Nandana Dutt402a8392019-06-14 14:25:13 +0100504 void SetProgress(long progress, long initial_max) {
505 ds.last_reported_percent_progress_ = 0;
Nandana Dutt5fb117b2018-09-27 09:23:36 +0100506 ds.options_->do_progress_updates = true;
Felipe Leme7447d7c2016-11-03 18:12:22 -0700507 ds.progress_.reset(new Progress(initial_max, progress, 1.2));
508 }
509
Felipe Leme7447d7c2016-11-03 18:12:22 -0700510 std::string GetProgressMessage(const std::string& listener_name, int progress, int max,
Felipe Leme009ecbb2016-11-07 10:18:44 -0800511 int old_max = 0, bool update_progress = true) {
Felipe Leme7447d7c2016-11-03 18:12:22 -0700512 EXPECT_EQ(progress, ds.progress_->Get()) << "invalid progress";
513 EXPECT_EQ(max, ds.progress_->GetMax()) << "invalid max";
Felipe Leme75876a22016-10-27 16:31:27 -0700514
Felipe Leme7447d7c2016-11-03 18:12:22 -0700515 bool max_increased = old_max > 0;
Felipe Leme75876a22016-10-27 16:31:27 -0700516
Felipe Leme009ecbb2016-11-07 10:18:44 -0800517 std::string message = "";
Felipe Leme75876a22016-10-27 16:31:27 -0700518 if (max_increased) {
Felipe Leme009ecbb2016-11-07 10:18:44 -0800519 message =
Felipe Leme7447d7c2016-11-03 18:12:22 -0700520 android::base::StringPrintf("Adjusting max progress from %d to %d\n", old_max, max);
Felipe Leme75876a22016-10-27 16:31:27 -0700521 }
522
Felipe Leme009ecbb2016-11-07 10:18:44 -0800523 if (update_progress) {
Nandana Duttbabf6c72019-01-15 14:11:12 +0000524 message += android::base::StringPrintf("Setting progress (%s): %d/%d (%d%%)\n",
525 listener_name.c_str(), progress, max,
526 (100 * progress / max));
Felipe Leme009ecbb2016-11-07 10:18:44 -0800527 }
528
529 return message;
Felipe Lemed80e6b62016-10-03 13:08:14 -0700530 }
531
Felipe Leme4c2d6632016-09-28 14:32:00 -0700532 // `stdout` and `stderr` from the last command ran.
533 std::string out, err;
534
Felipe Lemefd8affa2016-09-30 17:38:57 -0700535 Dumpstate& ds = Dumpstate::GetInstance();
Felipe Leme4c2d6632016-09-28 14:32:00 -0700536};
537
538TEST_F(DumpstateTest, RunCommandNoArgs) {
539 EXPECT_EQ(-1, RunCommand("", {}));
540}
541
542TEST_F(DumpstateTest, RunCommandNoTitle) {
Felipe Leme7447d7c2016-11-03 18:12:22 -0700543 EXPECT_EQ(0, RunCommand("", {kSimpleCommand}));
Felipe Leme4c2d6632016-09-28 14:32:00 -0700544 EXPECT_THAT(out, StrEq("stdout\n"));
545 EXPECT_THAT(err, StrEq("stderr\n"));
546}
547
548TEST_F(DumpstateTest, RunCommandWithTitle) {
Felipe Leme7447d7c2016-11-03 18:12:22 -0700549 EXPECT_EQ(0, RunCommand("I AM GROOT", {kSimpleCommand}));
Felipe Leme4c2d6632016-09-28 14:32:00 -0700550 EXPECT_THAT(err, StrEq("stderr\n"));
Greg Kaiser3a811c12019-05-21 12:48:59 -0700551 // The duration may not get output, depending on how long it takes,
552 // so we just check the prefix.
Felipe Lemefd8affa2016-09-30 17:38:57 -0700553 EXPECT_THAT(out,
Nandana Dutt47527b52019-03-29 15:34:36 +0000554 StartsWith("------ I AM GROOT (" + kSimpleCommand + ") ------\nstdout\n"));
Felipe Leme4c2d6632016-09-28 14:32:00 -0700555}
556
Felipe Lemefd8affa2016-09-30 17:38:57 -0700557TEST_F(DumpstateTest, RunCommandWithLoggingMessage) {
Felipe Leme4c2d6632016-09-28 14:32:00 -0700558 EXPECT_EQ(
Felipe Leme7447d7c2016-11-03 18:12:22 -0700559 0, RunCommand("", {kSimpleCommand},
Felipe Lemefd8affa2016-09-30 17:38:57 -0700560 CommandOptions::WithTimeout(10).Log("COMMAND, Y U NO LOG FIRST?").Build()));
561 EXPECT_THAT(out, StrEq("stdout\n"));
562 EXPECT_THAT(err, StrEq("COMMAND, Y U NO LOG FIRST?stderr\n"));
563}
564
565TEST_F(DumpstateTest, RunCommandRedirectStderr) {
Felipe Leme7447d7c2016-11-03 18:12:22 -0700566 EXPECT_EQ(0, RunCommand("", {kSimpleCommand},
Felipe Lemefd8affa2016-09-30 17:38:57 -0700567 CommandOptions::WithTimeout(10).RedirectStderr().Build()));
Felipe Leme4c2d6632016-09-28 14:32:00 -0700568 EXPECT_THAT(out, IsEmpty());
Felipe Lemefd8affa2016-09-30 17:38:57 -0700569 EXPECT_THAT(err, StrEq("stdout\nstderr\n"));
Felipe Leme4c2d6632016-09-28 14:32:00 -0700570}
571
572TEST_F(DumpstateTest, RunCommandWithOneArg) {
Felipe Leme7447d7c2016-11-03 18:12:22 -0700573 EXPECT_EQ(0, RunCommand("", {kEchoCommand, "one"}));
Felipe Leme4c2d6632016-09-28 14:32:00 -0700574 EXPECT_THAT(err, IsEmpty());
575 EXPECT_THAT(out, StrEq("one\n"));
576}
577
Felipe Lemefd8affa2016-09-30 17:38:57 -0700578TEST_F(DumpstateTest, RunCommandWithMultipleArgs) {
Felipe Leme7447d7c2016-11-03 18:12:22 -0700579 EXPECT_EQ(0, RunCommand("", {kEchoCommand, "one", "is", "the", "loniest", "number"}));
Felipe Leme4c2d6632016-09-28 14:32:00 -0700580 EXPECT_THAT(err, IsEmpty());
581 EXPECT_THAT(out, StrEq("one is the loniest number\n"));
582}
583
584TEST_F(DumpstateTest, RunCommandDryRun) {
585 SetDryRun(true);
Felipe Leme7447d7c2016-11-03 18:12:22 -0700586 EXPECT_EQ(0, RunCommand("I AM GROOT", {kSimpleCommand}));
Greg Kaiser3a811c12019-05-21 12:48:59 -0700587 // The duration may not get output, depending on how long it takes,
588 // so we just check the prefix.
Felipe Leme7447d7c2016-11-03 18:12:22 -0700589 EXPECT_THAT(out, StartsWith("------ I AM GROOT (" + kSimpleCommand +
Nandana Dutt47527b52019-03-29 15:34:36 +0000590 ") ------\n\t(skipped on dry run)\n"));
Felipe Leme4c2d6632016-09-28 14:32:00 -0700591 EXPECT_THAT(err, IsEmpty());
592}
593
594TEST_F(DumpstateTest, RunCommandDryRunNoTitle) {
595 SetDryRun(true);
Felipe Leme7447d7c2016-11-03 18:12:22 -0700596 EXPECT_EQ(0, RunCommand("", {kSimpleCommand}));
Felipe Leme4c2d6632016-09-28 14:32:00 -0700597 EXPECT_THAT(out, IsEmpty());
598 EXPECT_THAT(err, IsEmpty());
599}
600
601TEST_F(DumpstateTest, RunCommandDryRunAlways) {
602 SetDryRun(true);
Felipe Leme7447d7c2016-11-03 18:12:22 -0700603 EXPECT_EQ(0, RunCommand("", {kSimpleCommand}, CommandOptions::WithTimeout(10).Always().Build()));
Felipe Leme4c2d6632016-09-28 14:32:00 -0700604 EXPECT_THAT(out, StrEq("stdout\n"));
605 EXPECT_THAT(err, StrEq("stderr\n"));
606}
607
Felipe Lemefd8affa2016-09-30 17:38:57 -0700608TEST_F(DumpstateTest, RunCommandNotFound) {
609 EXPECT_NE(0, RunCommand("", {"/there/cannot/be/such/command"}));
610 EXPECT_THAT(out, StartsWith("*** command '/there/cannot/be/such/command' failed: exit code"));
611 EXPECT_THAT(err, StartsWith("execvp on command '/there/cannot/be/such/command' failed"));
612}
613
614TEST_F(DumpstateTest, RunCommandFails) {
Felipe Leme7447d7c2016-11-03 18:12:22 -0700615 EXPECT_EQ(42, RunCommand("", {kSimpleCommand, "--exit", "42"}));
616 EXPECT_THAT(out, StrEq("stdout\n*** command '" + kSimpleCommand +
Felipe Leme9a523ae2016-10-20 15:10:33 -0700617 " --exit 42' failed: exit code 42\n"));
Felipe Leme7447d7c2016-11-03 18:12:22 -0700618 EXPECT_THAT(err, StrEq("stderr\n*** command '" + kSimpleCommand +
Felipe Leme9a523ae2016-10-20 15:10:33 -0700619 " --exit 42' failed: exit code 42\n"));
Felipe Lemefd8affa2016-09-30 17:38:57 -0700620}
621
622TEST_F(DumpstateTest, RunCommandCrashes) {
Felipe Leme7447d7c2016-11-03 18:12:22 -0700623 EXPECT_NE(0, RunCommand("", {kSimpleCommand, "--crash"}));
Felipe Lemefd8affa2016-09-30 17:38:57 -0700624 // We don't know the exit code, so check just the prefix.
625 EXPECT_THAT(
Felipe Leme7447d7c2016-11-03 18:12:22 -0700626 out, StartsWith("stdout\n*** command '" + kSimpleCommand + " --crash' failed: exit code"));
Felipe Lemefd8affa2016-09-30 17:38:57 -0700627 EXPECT_THAT(
Felipe Leme7447d7c2016-11-03 18:12:22 -0700628 err, StartsWith("stderr\n*** command '" + kSimpleCommand + " --crash' failed: exit code"));
Felipe Lemefd8affa2016-09-30 17:38:57 -0700629}
630
631TEST_F(DumpstateTest, RunCommandTimesout) {
Felipe Leme7447d7c2016-11-03 18:12:22 -0700632 EXPECT_EQ(-1, RunCommand("", {kSimpleCommand, "--sleep", "2"},
Felipe Lemefd8affa2016-09-30 17:38:57 -0700633 CommandOptions::WithTimeout(1).Build()));
Felipe Leme7447d7c2016-11-03 18:12:22 -0700634 EXPECT_THAT(out, StartsWith("stdout line1\n*** command '" + kSimpleCommand +
Felipe Lemefd8affa2016-09-30 17:38:57 -0700635 " --sleep 2' timed out after 1"));
Felipe Leme7447d7c2016-11-03 18:12:22 -0700636 EXPECT_THAT(err, StartsWith("sleeping for 2s\n*** command '" + kSimpleCommand +
Felipe Lemefd8affa2016-09-30 17:38:57 -0700637 " --sleep 2' timed out after 1"));
638}
639
640TEST_F(DumpstateTest, RunCommandIsKilled) {
641 CaptureStdout();
642 CaptureStderr();
643
644 std::thread t([=]() {
Felipe Leme7447d7c2016-11-03 18:12:22 -0700645 EXPECT_EQ(SIGTERM, ds.RunCommand("", {kSimpleCommand, "--pid", "--sleep", "20"},
Felipe Lemefd8affa2016-09-30 17:38:57 -0700646 CommandOptions::WithTimeout(100).Always().Build()));
647 });
648
649 // Capture pid and pre-sleep output.
650 sleep(1); // Wait a little bit to make sure pid and 1st line were printed.
651 std::string err = GetCapturedStderr();
652 EXPECT_THAT(err, StrEq("sleeping for 20s\n"));
653
654 std::string out = GetCapturedStdout();
655 std::vector<std::string> lines = android::base::Split(out, "\n");
656 ASSERT_EQ(3, (int)lines.size()) << "Invalid lines before sleep: " << out;
657
658 int pid = atoi(lines[0].c_str());
659 EXPECT_THAT(lines[1], StrEq("stdout line1"));
660 EXPECT_THAT(lines[2], IsEmpty()); // \n
661
662 // Then kill the process.
663 CaptureStdout();
664 CaptureStderr();
665 ASSERT_EQ(0, kill(pid, SIGTERM)) << "failed to kill pid " << pid;
666 t.join();
667
668 // Finally, check output after murder.
669 out = GetCapturedStdout();
670 err = GetCapturedStderr();
671
Felipe Leme7447d7c2016-11-03 18:12:22 -0700672 EXPECT_THAT(out, StrEq("*** command '" + kSimpleCommand +
Felipe Lemefd8affa2016-09-30 17:38:57 -0700673 " --pid --sleep 20' failed: killed by signal 15\n"));
Felipe Leme7447d7c2016-11-03 18:12:22 -0700674 EXPECT_THAT(err, StrEq("*** command '" + kSimpleCommand +
Felipe Lemefd8affa2016-09-30 17:38:57 -0700675 " --pid --sleep 20' failed: killed by signal 15\n"));
676}
677
Felipe Leme75876a22016-10-27 16:31:27 -0700678TEST_F(DumpstateTest, RunCommandProgress) {
679 sp<DumpstateListenerMock> listener(new DumpstateListenerMock());
680 ds.listener_ = listener;
681 ds.listener_name_ = "FoxMulder";
Felipe Leme7447d7c2016-11-03 18:12:22 -0700682 SetProgress(0, 30);
Felipe Leme75876a22016-10-27 16:31:27 -0700683
Nandana Duttbabf6c72019-01-15 14:11:12 +0000684 EXPECT_CALL(*listener, onProgress(66)); // 20/30 %
Felipe Leme7447d7c2016-11-03 18:12:22 -0700685 EXPECT_EQ(0, RunCommand("", {kSimpleCommand}, CommandOptions::WithTimeout(20).Build()));
Felipe Leme75876a22016-10-27 16:31:27 -0700686 std::string progress_message = GetProgressMessage(ds.listener_name_, 20, 30);
687 EXPECT_THAT(out, StrEq("stdout\n"));
688 EXPECT_THAT(err, StrEq("stderr\n" + progress_message));
689
Nandana Dutt402a8392019-06-14 14:25:13 +0100690 EXPECT_CALL(*listener, onProgress(80)); // 24/30 %
691 EXPECT_EQ(0, RunCommand("", {kSimpleCommand}, CommandOptions::WithTimeout(4).Build()));
692 progress_message = GetProgressMessage(ds.listener_name_, 24, 30);
Felipe Leme75876a22016-10-27 16:31:27 -0700693 EXPECT_THAT(out, StrEq("stdout\n"));
694 EXPECT_THAT(err, StrEq("stderr\n" + progress_message));
695
696 // Make sure command ran while in dry_run is counted.
697 SetDryRun(true);
Nandana Dutt402a8392019-06-14 14:25:13 +0100698 EXPECT_CALL(*listener, onProgress(90)); // 27/30 %
699 EXPECT_EQ(0, RunCommand("", {kSimpleCommand}, CommandOptions::WithTimeout(3).Build()));
700 progress_message = GetProgressMessage(ds.listener_name_, 27, 30);
Felipe Leme75876a22016-10-27 16:31:27 -0700701 EXPECT_THAT(out, IsEmpty());
702 EXPECT_THAT(err, StrEq(progress_message));
703
Nandana Dutt402a8392019-06-14 14:25:13 +0100704 SetDryRun(false);
705 EXPECT_CALL(*listener, onProgress(96)); // 29/30 %
706 EXPECT_EQ(0, RunCommand("", {kSimpleCommand}, CommandOptions::WithTimeout(2).Build()));
707 progress_message = GetProgressMessage(ds.listener_name_, 29, 30);
Felipe Leme009ecbb2016-11-07 10:18:44 -0800708 EXPECT_THAT(out, StrEq("stdout\n"));
709 EXPECT_THAT(err, StrEq("stderr\n" + progress_message));
710
Nandana Dutt402a8392019-06-14 14:25:13 +0100711 EXPECT_CALL(*listener, onProgress(100)); // 30/30 %
Felipe Leme009ecbb2016-11-07 10:18:44 -0800712 EXPECT_EQ(0, RunCommand("", {kSimpleCommand}, CommandOptions::WithTimeout(1).Build()));
Nandana Dutt402a8392019-06-14 14:25:13 +0100713 progress_message = GetProgressMessage(ds.listener_name_, 30, 30);
Felipe Leme009ecbb2016-11-07 10:18:44 -0800714 EXPECT_THAT(out, StrEq("stdout\n"));
715 EXPECT_THAT(err, StrEq("stderr\n" + progress_message));
716
717 ds.listener_.clear();
718}
719
Felipe Lemed80e6b62016-10-03 13:08:14 -0700720TEST_F(DumpstateTest, RunCommandDropRoot) {
Felipe Leme46b85da2016-11-21 17:40:45 -0800721 if (!IsStandalone()) {
722 // TODO: temporarily disabled because it might cause other tests to fail after dropping
723 // to Shell - need to refactor tests to avoid this problem)
724 MYLOGE("Skipping DumpstateTest.RunCommandDropRoot() on test suite\n")
725 return;
726 }
Felipe Lemed80e6b62016-10-03 13:08:14 -0700727 // First check root case - only available when running with 'adb root'.
728 uid_t uid = getuid();
729 if (uid == 0) {
Felipe Leme7447d7c2016-11-03 18:12:22 -0700730 EXPECT_EQ(0, RunCommand("", {kSimpleCommand, "--uid"}));
Felipe Lemed80e6b62016-10-03 13:08:14 -0700731 EXPECT_THAT(out, StrEq("0\nstdout\n"));
732 EXPECT_THAT(err, StrEq("stderr\n"));
733 return;
734 }
Felipe Leme7447d7c2016-11-03 18:12:22 -0700735 // Then run dropping root.
736 EXPECT_EQ(0, RunCommand("", {kSimpleCommand, "--uid"},
Felipe Lemed80e6b62016-10-03 13:08:14 -0700737 CommandOptions::WithTimeout(1).DropRoot().Build()));
738 EXPECT_THAT(out, StrEq("2000\nstdout\n"));
Felipe Leme26c41572016-10-06 14:34:43 -0700739 EXPECT_THAT(err, StrEq("drop_root_user(): already running as Shell\nstderr\n"));
Felipe Lemed80e6b62016-10-03 13:08:14 -0700740}
741
742TEST_F(DumpstateTest, RunCommandAsRootUserBuild) {
Felipe Leme46b85da2016-11-21 17:40:45 -0800743 if (!IsStandalone()) {
744 // TODO: temporarily disabled because it might cause other tests to fail after dropping
745 // to Shell - need to refactor tests to avoid this problem)
746 MYLOGE("Skipping DumpstateTest.RunCommandAsRootUserBuild() on test suite\n")
747 return;
748 }
Felipe Lemef0292972016-11-22 13:57:05 -0800749 if (!PropertiesHelper::IsUserBuild()) {
Felipe Lemed80e6b62016-10-03 13:08:14 -0700750 // Emulates user build if necessarily.
751 SetBuildType("user");
752 }
753
754 DropRoot();
755
Felipe Leme7447d7c2016-11-03 18:12:22 -0700756 EXPECT_EQ(0, RunCommand("", {kSimpleCommand}, CommandOptions::WithTimeout(1).AsRoot().Build()));
Felipe Lemed80e6b62016-10-03 13:08:14 -0700757
758 // We don't know the exact path of su, so we just check for the 'root ...' commands
759 EXPECT_THAT(out, StartsWith("Skipping"));
Felipe Leme7447d7c2016-11-03 18:12:22 -0700760 EXPECT_THAT(out, EndsWith("root " + kSimpleCommand + "' on user build.\n"));
Felipe Lemed80e6b62016-10-03 13:08:14 -0700761 EXPECT_THAT(err, IsEmpty());
762}
763
Felipe Leme46b85da2016-11-21 17:40:45 -0800764TEST_F(DumpstateTest, RunCommandAsRootNonUserBuild) {
765 if (!IsStandalone()) {
766 // TODO: temporarily disabled because it might cause other tests to fail after dropping
767 // to Shell - need to refactor tests to avoid this problem)
768 MYLOGE("Skipping DumpstateTest.RunCommandAsRootNonUserBuild() on test suite\n")
769 return;
770 }
Felipe Lemef0292972016-11-22 13:57:05 -0800771 if (PropertiesHelper::IsUserBuild()) {
Felipe Leme46b85da2016-11-21 17:40:45 -0800772 ALOGI("Skipping RunCommandAsRootNonUserBuild on user builds\n");
773 return;
774 }
775
776 DropRoot();
777
778 EXPECT_EQ(0, RunCommand("", {kSimpleCommand, "--uid"},
779 CommandOptions::WithTimeout(1).AsRoot().Build()));
780
781 EXPECT_THAT(out, StrEq("0\nstdout\n"));
782 EXPECT_THAT(err, StrEq("stderr\n"));
783}
784
Nandana Dutt4b392be2018-11-02 16:17:05 +0000785TEST_F(DumpstateTest, RunCommandAsRootNonUserBuild_withUnroot) {
786 if (!IsStandalone()) {
787 // TODO: temporarily disabled because it might cause other tests to fail after dropping
788 // to Shell - need to refactor tests to avoid this problem)
789 MYLOGE(
790 "Skipping DumpstateTest.RunCommandAsRootNonUserBuild_withUnroot() "
791 "on test suite\n")
792 return;
793 }
794 if (PropertiesHelper::IsUserBuild()) {
795 ALOGI("Skipping RunCommandAsRootNonUserBuild_withUnroot on user builds\n");
796 return;
797 }
798
799 // Same test as above, but with unroot property set, which will override su availability.
800 SetUnroot(true);
801 DropRoot();
802
803 EXPECT_EQ(0, RunCommand("", {kSimpleCommand, "--uid"},
804 CommandOptions::WithTimeout(1).AsRoot().Build()));
805
806 // AsRoot is ineffective.
807 EXPECT_THAT(out, StrEq("2000\nstdout\n"));
808 EXPECT_THAT(err, StrEq("drop_root_user(): already running as Shell\nstderr\n"));
809}
810
Yifan Hong48e83a12017-10-03 14:10:07 -0700811TEST_F(DumpstateTest, RunCommandAsRootIfAvailableOnUserBuild) {
812 if (!IsStandalone()) {
813 // TODO: temporarily disabled because it might cause other tests to fail after dropping
814 // to Shell - need to refactor tests to avoid this problem)
815 MYLOGE("Skipping DumpstateTest.RunCommandAsRootIfAvailableOnUserBuild() on test suite\n")
816 return;
817 }
818 if (!PropertiesHelper::IsUserBuild()) {
819 // Emulates user build if necessarily.
820 SetBuildType("user");
821 }
822
823 DropRoot();
824
825 EXPECT_EQ(0, RunCommand("", {kSimpleCommand, "--uid"},
826 CommandOptions::WithTimeout(1).AsRootIfAvailable().Build()));
827
828 EXPECT_THAT(out, StrEq("2000\nstdout\n"));
829 EXPECT_THAT(err, StrEq("stderr\n"));
830}
831
832TEST_F(DumpstateTest, RunCommandAsRootIfAvailableOnDebugBuild) {
833 if (!IsStandalone()) {
834 // TODO: temporarily disabled because it might cause other tests to fail after dropping
835 // to Shell - need to refactor tests to avoid this problem)
836 MYLOGE("Skipping DumpstateTest.RunCommandAsRootIfAvailableOnDebugBuild() on test suite\n")
837 return;
838 }
839 if (PropertiesHelper::IsUserBuild()) {
840 ALOGI("Skipping RunCommandAsRootNonUserBuild on user builds\n");
841 return;
842 }
843
844 DropRoot();
845
846 EXPECT_EQ(0, RunCommand("", {kSimpleCommand, "--uid"},
847 CommandOptions::WithTimeout(1).AsRootIfAvailable().Build()));
848
849 EXPECT_THAT(out, StrEq("0\nstdout\n"));
850 EXPECT_THAT(err, StrEq("stderr\n"));
851}
852
Nandana Dutt4b392be2018-11-02 16:17:05 +0000853TEST_F(DumpstateTest, RunCommandAsRootIfAvailableOnDebugBuild_withUnroot) {
854 if (!IsStandalone()) {
855 // TODO: temporarily disabled because it might cause other tests to fail after dropping
856 // to Shell - need to refactor tests to avoid this problem)
857 MYLOGE(
858 "Skipping DumpstateTest.RunCommandAsRootIfAvailableOnDebugBuild_withUnroot() "
859 "on test suite\n")
860 return;
861 }
862 if (PropertiesHelper::IsUserBuild()) {
863 ALOGI("Skipping RunCommandAsRootIfAvailableOnDebugBuild_withUnroot on user builds\n");
864 return;
865 }
866 // Same test as above, but with unroot property set, which will override su availability.
867 SetUnroot(true);
868
869 DropRoot();
870
871 EXPECT_EQ(0, RunCommand("", {kSimpleCommand, "--uid"},
872 CommandOptions::WithTimeout(1).AsRootIfAvailable().Build()));
873
874 // It's a userdebug build, so "su root" should be available, but unroot=true overrides it.
875 EXPECT_THAT(out, StrEq("2000\nstdout\n"));
876 EXPECT_THAT(err, StrEq("stderr\n"));
877}
878
Felipe Lemecef02982016-10-03 17:22:22 -0700879TEST_F(DumpstateTest, DumpFileNotFoundNoTitle) {
880 EXPECT_EQ(-1, DumpFile("", "/I/cant/believe/I/exist"));
881 EXPECT_THAT(out,
882 StrEq("*** Error dumping /I/cant/believe/I/exist: No such file or directory\n"));
883 EXPECT_THAT(err, IsEmpty());
884}
885
886TEST_F(DumpstateTest, DumpFileNotFoundWithTitle) {
887 EXPECT_EQ(-1, DumpFile("Y U NO EXIST?", "/I/cant/believe/I/exist"));
888 EXPECT_THAT(err, IsEmpty());
Greg Kaiser3a811c12019-05-21 12:48:59 -0700889 // The duration may not get output, depending on how long it takes,
890 // so we just check the prefix.
Felipe Lemecef02982016-10-03 17:22:22 -0700891 EXPECT_THAT(out, StartsWith("*** Error dumping /I/cant/believe/I/exist (Y U NO EXIST?): No "
892 "such file or directory\n"));
Felipe Lemecef02982016-10-03 17:22:22 -0700893}
894
895TEST_F(DumpstateTest, DumpFileSingleLine) {
Felipe Leme7447d7c2016-11-03 18:12:22 -0700896 EXPECT_EQ(0, DumpFile("", kTestDataPath + "single-line.txt"));
Felipe Lemecef02982016-10-03 17:22:22 -0700897 EXPECT_THAT(err, IsEmpty());
898 EXPECT_THAT(out, StrEq("I AM LINE1\n")); // dumpstate adds missing newline
899}
900
901TEST_F(DumpstateTest, DumpFileSingleLineWithNewLine) {
Felipe Leme7447d7c2016-11-03 18:12:22 -0700902 EXPECT_EQ(0, DumpFile("", kTestDataPath + "single-line-with-newline.txt"));
Felipe Lemecef02982016-10-03 17:22:22 -0700903 EXPECT_THAT(err, IsEmpty());
904 EXPECT_THAT(out, StrEq("I AM LINE1\n"));
905}
906
907TEST_F(DumpstateTest, DumpFileMultipleLines) {
Felipe Leme7447d7c2016-11-03 18:12:22 -0700908 EXPECT_EQ(0, DumpFile("", kTestDataPath + "multiple-lines.txt"));
Felipe Lemecef02982016-10-03 17:22:22 -0700909 EXPECT_THAT(err, IsEmpty());
910 EXPECT_THAT(out, StrEq("I AM LINE1\nI AM LINE2\nI AM LINE3\n"));
911}
912
913TEST_F(DumpstateTest, DumpFileMultipleLinesWithNewLine) {
Felipe Leme7447d7c2016-11-03 18:12:22 -0700914 EXPECT_EQ(0, DumpFile("", kTestDataPath + "multiple-lines-with-newline.txt"));
Felipe Lemecef02982016-10-03 17:22:22 -0700915 EXPECT_THAT(err, IsEmpty());
916 EXPECT_THAT(out, StrEq("I AM LINE1\nI AM LINE2\nI AM LINE3\n"));
917}
918
919TEST_F(DumpstateTest, DumpFileOnDryRunNoTitle) {
920 SetDryRun(true);
Felipe Leme7447d7c2016-11-03 18:12:22 -0700921 EXPECT_EQ(0, DumpFile("", kTestDataPath + "single-line.txt"));
Felipe Lemecef02982016-10-03 17:22:22 -0700922 EXPECT_THAT(err, IsEmpty());
923 EXPECT_THAT(out, IsEmpty());
924}
925
926TEST_F(DumpstateTest, DumpFileOnDryRun) {
927 SetDryRun(true);
Felipe Leme7447d7c2016-11-03 18:12:22 -0700928 EXPECT_EQ(0, DumpFile("Might as well dump. Dump!", kTestDataPath + "single-line.txt"));
Felipe Lemecef02982016-10-03 17:22:22 -0700929 EXPECT_THAT(err, IsEmpty());
Felipe Leme46b85da2016-11-21 17:40:45 -0800930 EXPECT_THAT(
931 out, StartsWith("------ Might as well dump. Dump! (" + kTestDataPath + "single-line.txt:"));
Nandana Dutt47527b52019-03-29 15:34:36 +0000932 EXPECT_THAT(out, HasSubstr("\n\t(skipped on dry run)\n"));
Felipe Lemecef02982016-10-03 17:22:22 -0700933}
934
Felipe Leme75876a22016-10-27 16:31:27 -0700935TEST_F(DumpstateTest, DumpFileUpdateProgress) {
936 sp<DumpstateListenerMock> listener(new DumpstateListenerMock());
937 ds.listener_ = listener;
938 ds.listener_name_ = "FoxMulder";
Felipe Leme7447d7c2016-11-03 18:12:22 -0700939 SetProgress(0, 30);
Felipe Leme75876a22016-10-27 16:31:27 -0700940
Nandana Duttbabf6c72019-01-15 14:11:12 +0000941 EXPECT_CALL(*listener, onProgress(16)); // 5/30 %
Felipe Leme7447d7c2016-11-03 18:12:22 -0700942 EXPECT_EQ(0, DumpFile("", kTestDataPath + "single-line.txt"));
Felipe Leme75876a22016-10-27 16:31:27 -0700943
944 std::string progress_message =
945 GetProgressMessage(ds.listener_name_, 5, 30); // TODO: unhardcode WEIGHT_FILE (5)?
946 EXPECT_THAT(err, StrEq(progress_message));
947 EXPECT_THAT(out, StrEq("I AM LINE1\n")); // dumpstate adds missing newline
948
949 ds.listener_.clear();
950}
951
Felipe Leme7447d7c2016-11-03 18:12:22 -0700952class DumpstateServiceTest : public DumpstateBaseTest {
Felipe Leme75876a22016-10-27 16:31:27 -0700953 public:
954 DumpstateService dss;
955};
956
957TEST_F(DumpstateServiceTest, SetListenerNoName) {
958 sp<DumpstateListenerMock> listener(new DumpstateListenerMock());
Felipe Leme009ecbb2016-11-07 10:18:44 -0800959 sp<IDumpstateToken> token;
Vishnu Nair20cf5032018-01-05 13:15:49 -0800960 EXPECT_TRUE(dss.setListener("", listener, /* getSectionDetails = */ false, &token).isOk());
Felipe Leme009ecbb2016-11-07 10:18:44 -0800961 ASSERT_THAT(token, IsNull());
Felipe Leme75876a22016-10-27 16:31:27 -0700962}
963
964TEST_F(DumpstateServiceTest, SetListenerNoPointer) {
Felipe Leme009ecbb2016-11-07 10:18:44 -0800965 sp<IDumpstateToken> token;
Vishnu Nair20cf5032018-01-05 13:15:49 -0800966 EXPECT_TRUE(
967 dss.setListener("whatever", nullptr, /* getSectionDetails = */ false, &token).isOk());
Felipe Leme009ecbb2016-11-07 10:18:44 -0800968 ASSERT_THAT(token, IsNull());
Felipe Leme75876a22016-10-27 16:31:27 -0700969}
970
971TEST_F(DumpstateServiceTest, SetListenerTwice) {
972 sp<DumpstateListenerMock> listener(new DumpstateListenerMock());
Felipe Leme009ecbb2016-11-07 10:18:44 -0800973 sp<IDumpstateToken> token;
Vishnu Nair20cf5032018-01-05 13:15:49 -0800974 EXPECT_TRUE(
975 dss.setListener("whatever", listener, /* getSectionDetails = */ false, &token).isOk());
Felipe Leme009ecbb2016-11-07 10:18:44 -0800976 ASSERT_THAT(token, NotNull());
Felipe Leme75876a22016-10-27 16:31:27 -0700977 EXPECT_THAT(Dumpstate::GetInstance().listener_name_, StrEq("whatever"));
Vishnu Nair20cf5032018-01-05 13:15:49 -0800978 EXPECT_FALSE(Dumpstate::GetInstance().report_section_);
Felipe Leme75876a22016-10-27 16:31:27 -0700979
Felipe Leme009ecbb2016-11-07 10:18:44 -0800980 token.clear();
Vishnu Nair20cf5032018-01-05 13:15:49 -0800981 EXPECT_TRUE(
982 dss.setListener("whatsoever", listener, /* getSectionDetails = */ false, &token).isOk());
Felipe Leme009ecbb2016-11-07 10:18:44 -0800983 ASSERT_THAT(token, IsNull());
984 EXPECT_THAT(Dumpstate::GetInstance().listener_name_, StrEq("whatever"));
Vishnu Nair20cf5032018-01-05 13:15:49 -0800985 EXPECT_FALSE(Dumpstate::GetInstance().report_section_);
986}
987
988TEST_F(DumpstateServiceTest, SetListenerWithSectionDetails) {
989 sp<DumpstateListenerMock> listener(new DumpstateListenerMock());
990 sp<IDumpstateToken> token;
991 Dumpstate::GetInstance().listener_ = nullptr;
992 EXPECT_TRUE(
993 dss.setListener("whatever", listener, /* getSectionDetails = */ true, &token).isOk());
994 ASSERT_THAT(token, NotNull());
995 EXPECT_THAT(Dumpstate::GetInstance().listener_name_, StrEq("whatever"));
996 EXPECT_TRUE(Dumpstate::GetInstance().report_section_);
Felipe Leme75876a22016-10-27 16:31:27 -0700997}
Felipe Leme7447d7c2016-11-03 18:12:22 -0700998
999class ProgressTest : public DumpstateBaseTest {
1000 public:
1001 Progress GetInstance(int32_t max, double growth_factor, const std::string& path = "") {
1002 return Progress(max, growth_factor, path);
1003 }
1004
1005 void AssertStats(const std::string& path, int32_t expected_runs, int32_t expected_average) {
1006 std::string expected_content =
1007 android::base::StringPrintf("%d %d\n", expected_runs, expected_average);
1008 std::string actual_content;
Felipe Leme46b85da2016-11-21 17:40:45 -08001009 ReadFileToString(path, &actual_content);
Felipe Leme7447d7c2016-11-03 18:12:22 -07001010 ASSERT_THAT(actual_content, StrEq(expected_content)) << "invalid stats on " << path;
1011 }
1012};
1013
1014TEST_F(ProgressTest, SimpleTest) {
1015 Progress progress;
1016 EXPECT_EQ(0, progress.Get());
1017 EXPECT_EQ(Progress::kDefaultMax, progress.GetInitialMax());
1018 EXPECT_EQ(Progress::kDefaultMax, progress.GetMax());
1019
1020 bool max_increased = progress.Inc(1);
1021 EXPECT_EQ(1, progress.Get());
1022 EXPECT_EQ(Progress::kDefaultMax, progress.GetInitialMax());
1023 EXPECT_EQ(Progress::kDefaultMax, progress.GetMax());
1024 EXPECT_FALSE(max_increased);
1025
1026 // Ignore negative increase.
1027 max_increased = progress.Inc(-1);
1028 EXPECT_EQ(1, progress.Get());
1029 EXPECT_EQ(Progress::kDefaultMax, progress.GetInitialMax());
1030 EXPECT_EQ(Progress::kDefaultMax, progress.GetMax());
1031 EXPECT_FALSE(max_increased);
1032}
1033
1034TEST_F(ProgressTest, MaxGrowsInsideNewRange) {
1035 Progress progress = GetInstance(10, 1.2); // 20% growth factor
1036 EXPECT_EQ(0, progress.Get());
1037 EXPECT_EQ(10, progress.GetInitialMax());
1038 EXPECT_EQ(10, progress.GetMax());
1039
1040 // No increase
1041 bool max_increased = progress.Inc(10);
1042 EXPECT_EQ(10, progress.Get());
1043 EXPECT_EQ(10, progress.GetMax());
1044 EXPECT_FALSE(max_increased);
1045
1046 // Increase, with new value < max*20%
1047 max_increased = progress.Inc(1);
1048 EXPECT_EQ(11, progress.Get());
1049 EXPECT_EQ(13, progress.GetMax()); // 11 average * 20% growth = 13.2 = 13
1050 EXPECT_TRUE(max_increased);
1051}
1052
1053TEST_F(ProgressTest, MaxGrowsOutsideNewRange) {
1054 Progress progress = GetInstance(10, 1.2); // 20% growth factor
1055 EXPECT_EQ(0, progress.Get());
1056 EXPECT_EQ(10, progress.GetInitialMax());
1057 EXPECT_EQ(10, progress.GetMax());
1058
1059 // No increase
1060 bool max_increased = progress.Inc(10);
1061 EXPECT_EQ(10, progress.Get());
1062 EXPECT_EQ(10, progress.GetMax());
1063 EXPECT_FALSE(max_increased);
1064
1065 // Increase, with new value > max*20%
1066 max_increased = progress.Inc(5);
1067 EXPECT_EQ(15, progress.Get());
1068 EXPECT_EQ(18, progress.GetMax()); // 15 average * 20% growth = 18
1069 EXPECT_TRUE(max_increased);
1070}
1071
1072TEST_F(ProgressTest, InvalidPath) {
1073 Progress progress("/devil/null");
1074 EXPECT_EQ(Progress::kDefaultMax, progress.GetMax());
1075}
1076
1077TEST_F(ProgressTest, EmptyFile) {
1078 Progress progress(CopyTextFileFixture("empty-file.txt"));
1079 EXPECT_EQ(Progress::kDefaultMax, progress.GetMax());
1080}
1081
1082TEST_F(ProgressTest, InvalidLine1stEntryNAN) {
1083 Progress progress(CopyTextFileFixture("stats-invalid-1st-NAN.txt"));
1084 EXPECT_EQ(Progress::kDefaultMax, progress.GetMax());
1085}
1086
1087TEST_F(ProgressTest, InvalidLine2ndEntryNAN) {
1088 Progress progress(CopyTextFileFixture("stats-invalid-2nd-NAN.txt"));
1089 EXPECT_EQ(Progress::kDefaultMax, progress.GetMax());
1090}
1091
1092TEST_F(ProgressTest, InvalidLineBothNAN) {
1093 Progress progress(CopyTextFileFixture("stats-invalid-both-NAN.txt"));
1094 EXPECT_EQ(Progress::kDefaultMax, progress.GetMax());
1095}
1096
1097TEST_F(ProgressTest, InvalidLine1stEntryNegative) {
1098 Progress progress(CopyTextFileFixture("stats-invalid-1st-negative.txt"));
1099 EXPECT_EQ(Progress::kDefaultMax, progress.GetMax());
1100}
1101
1102TEST_F(ProgressTest, InvalidLine2ndEntryNegative) {
1103 Progress progress(CopyTextFileFixture("stats-invalid-2nd-negative.txt"));
1104 EXPECT_EQ(Progress::kDefaultMax, progress.GetMax());
1105}
1106
1107TEST_F(ProgressTest, InvalidLine1stEntryTooBig) {
1108 Progress progress(CopyTextFileFixture("stats-invalid-1st-too-big.txt"));
1109 EXPECT_EQ(Progress::kDefaultMax, progress.GetMax());
1110}
1111
1112TEST_F(ProgressTest, InvalidLine2ndEntryTooBig) {
1113 Progress progress(CopyTextFileFixture("stats-invalid-2nd-too-big.txt"));
1114 EXPECT_EQ(Progress::kDefaultMax, progress.GetMax());
1115}
1116
1117// Tests stats are properly saved when the file does not exists.
1118TEST_F(ProgressTest, FirstTime) {
Felipe Leme46b85da2016-11-21 17:40:45 -08001119 if (!IsStandalone()) {
1120 // TODO: temporarily disabled because it's failing when running as suite
1121 MYLOGE("Skipping ProgressTest.FirstTime() on test suite\n")
1122 return;
1123 }
1124
Felipe Leme7447d7c2016-11-03 18:12:22 -07001125 std::string path = kTestDataPath + "FirstTime.txt";
1126 android::base::RemoveFileIfExists(path);
1127
1128 Progress run1(path);
1129 EXPECT_EQ(0, run1.Get());
1130 EXPECT_EQ(Progress::kDefaultMax, run1.GetInitialMax());
1131 EXPECT_EQ(Progress::kDefaultMax, run1.GetMax());
1132
1133 bool max_increased = run1.Inc(20);
1134 EXPECT_EQ(20, run1.Get());
1135 EXPECT_EQ(Progress::kDefaultMax, run1.GetMax());
1136 EXPECT_FALSE(max_increased);
1137
1138 run1.Save();
1139 AssertStats(path, 1, 20);
1140}
1141
1142// Tests what happens when the persistent settings contains the average duration of 1 run.
1143// Data on file is 1 run and 109 average.
1144TEST_F(ProgressTest, SecondTime) {
1145 std::string path = CopyTextFileFixture("stats-one-run-no-newline.txt");
1146
1147 Progress run1 = GetInstance(-42, 1.2, path);
1148 EXPECT_EQ(0, run1.Get());
1149 EXPECT_EQ(10, run1.GetInitialMax());
1150 EXPECT_EQ(10, run1.GetMax());
1151
1152 bool max_increased = run1.Inc(20);
1153 EXPECT_EQ(20, run1.Get());
1154 EXPECT_EQ(24, run1.GetMax());
1155 EXPECT_TRUE(max_increased);
1156
1157 // Average now is 2 runs and (10 + 20)/ 2 = 15
1158 run1.Save();
1159 AssertStats(path, 2, 15);
1160
1161 Progress run2 = GetInstance(-42, 1.2, path);
1162 EXPECT_EQ(0, run2.Get());
1163 EXPECT_EQ(15, run2.GetInitialMax());
1164 EXPECT_EQ(15, run2.GetMax());
1165
1166 max_increased = run2.Inc(25);
1167 EXPECT_EQ(25, run2.Get());
1168 EXPECT_EQ(30, run2.GetMax());
1169 EXPECT_TRUE(max_increased);
1170
1171 // Average now is 3 runs and (15 * 2 + 25)/ 3 = 18.33 = 18
1172 run2.Save();
1173 AssertStats(path, 3, 18);
1174
1175 Progress run3 = GetInstance(-42, 1.2, path);
1176 EXPECT_EQ(0, run3.Get());
1177 EXPECT_EQ(18, run3.GetInitialMax());
1178 EXPECT_EQ(18, run3.GetMax());
1179
1180 // Make sure average decreases as well
1181 max_increased = run3.Inc(5);
1182 EXPECT_EQ(5, run3.Get());
1183 EXPECT_EQ(18, run3.GetMax());
1184 EXPECT_FALSE(max_increased);
1185
1186 // Average now is 4 runs and (18 * 3 + 5)/ 4 = 14.75 = 14
1187 run3.Save();
1188 AssertStats(path, 4, 14);
1189}
1190
1191// Tests what happens when the persistent settings contains the average duration of 2 runs.
1192// Data on file is 2 runs and 15 average.
1193TEST_F(ProgressTest, ThirdTime) {
1194 std::string path = CopyTextFileFixture("stats-two-runs.txt");
1195 AssertStats(path, 2, 15); // Sanity check
1196
1197 Progress run1 = GetInstance(-42, 1.2, path);
1198 EXPECT_EQ(0, run1.Get());
1199 EXPECT_EQ(15, run1.GetInitialMax());
1200 EXPECT_EQ(15, run1.GetMax());
1201
1202 bool max_increased = run1.Inc(20);
1203 EXPECT_EQ(20, run1.Get());
1204 EXPECT_EQ(24, run1.GetMax());
1205 EXPECT_TRUE(max_increased);
1206
1207 // Average now is 3 runs and (15 * 2 + 20)/ 3 = 16.66 = 16
1208 run1.Save();
1209 AssertStats(path, 3, 16);
1210}
1211
Felipe Leme46b85da2016-11-21 17:40:45 -08001212class DumpstateUtilTest : public DumpstateBaseTest {
1213 public:
1214 void SetUp() {
1215 DumpstateBaseTest::SetUp();
1216 SetDryRun(false);
1217 }
1218
Felipe Leme46b85da2016-11-21 17:40:45 -08001219 void CaptureFdOut() {
Felipe Lemef0292972016-11-22 13:57:05 -08001220 ReadFileToString(path_, &out);
Felipe Leme46b85da2016-11-21 17:40:45 -08001221 }
1222
1223 void CreateFd(const std::string& name) {
1224 path_ = kTestDataPath + name;
1225 MYLOGD("Creating fd for file %s\n", path_.c_str());
1226
1227 fd = TEMP_FAILURE_RETRY(open(path_.c_str(),
1228 O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW,
1229 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH));
1230 ASSERT_GE(fd, 0) << "could not create FD for path " << path_;
1231 }
1232
1233 // Runs a command into the `fd` and capture `stderr`.
Felipe Lemef0292972016-11-22 13:57:05 -08001234 int RunCommand(const std::string& title, const std::vector<std::string>& full_command,
Felipe Leme46b85da2016-11-21 17:40:45 -08001235 const CommandOptions& options = CommandOptions::DEFAULT) {
1236 CaptureStderr();
Felipe Lemef0292972016-11-22 13:57:05 -08001237 int status = RunCommandToFd(fd, title, full_command, options);
Felipe Leme46b85da2016-11-21 17:40:45 -08001238 close(fd);
1239
1240 CaptureFdOut();
1241 err = GetCapturedStderr();
1242 return status;
1243 }
1244
1245 // Dumps a file and into the `fd` and `stderr`.
Felipe Lemef0292972016-11-22 13:57:05 -08001246 int DumpFile(const std::string& title, const std::string& path) {
Felipe Leme46b85da2016-11-21 17:40:45 -08001247 CaptureStderr();
Felipe Lemef0292972016-11-22 13:57:05 -08001248 int status = DumpFileToFd(fd, title, path);
Felipe Leme46b85da2016-11-21 17:40:45 -08001249 close(fd);
1250
1251 CaptureFdOut();
1252 err = GetCapturedStderr();
1253 return status;
1254 }
1255
1256 int fd;
1257
1258 // 'fd` output and `stderr` from the last command ran.
1259 std::string out, err;
1260
1261 private:
1262 std::string path_;
1263};
1264
1265TEST_F(DumpstateUtilTest, RunCommandNoArgs) {
Felipe Lemef0292972016-11-22 13:57:05 -08001266 CreateFd("RunCommandNoArgs.txt");
1267 EXPECT_EQ(-1, RunCommand("", {}));
Felipe Leme46b85da2016-11-21 17:40:45 -08001268}
1269
Felipe Lemef0292972016-11-22 13:57:05 -08001270TEST_F(DumpstateUtilTest, RunCommandNoTitle) {
Felipe Leme46b85da2016-11-21 17:40:45 -08001271 CreateFd("RunCommandWithNoArgs.txt");
Felipe Lemef0292972016-11-22 13:57:05 -08001272 EXPECT_EQ(0, RunCommand("", {kSimpleCommand}));
Felipe Leme46b85da2016-11-21 17:40:45 -08001273 EXPECT_THAT(out, StrEq("stdout\n"));
1274 EXPECT_THAT(err, StrEq("stderr\n"));
1275}
1276
Felipe Lemef0292972016-11-22 13:57:05 -08001277TEST_F(DumpstateUtilTest, RunCommandWithTitle) {
1278 CreateFd("RunCommandWithNoArgs.txt");
1279 EXPECT_EQ(0, RunCommand("I AM GROOT", {kSimpleCommand}));
1280 EXPECT_THAT(out, StrEq("------ I AM GROOT (" + kSimpleCommand + ") ------\nstdout\n"));
1281 EXPECT_THAT(err, StrEq("stderr\n"));
1282}
1283
Felipe Leme46b85da2016-11-21 17:40:45 -08001284TEST_F(DumpstateUtilTest, RunCommandWithOneArg) {
1285 CreateFd("RunCommandWithOneArg.txt");
Felipe Lemef0292972016-11-22 13:57:05 -08001286 EXPECT_EQ(0, RunCommand("", {kEchoCommand, "one"}));
Felipe Leme46b85da2016-11-21 17:40:45 -08001287 EXPECT_THAT(err, IsEmpty());
1288 EXPECT_THAT(out, StrEq("one\n"));
1289}
1290
1291TEST_F(DumpstateUtilTest, RunCommandWithMultipleArgs) {
1292 CreateFd("RunCommandWithMultipleArgs.txt");
Felipe Lemef0292972016-11-22 13:57:05 -08001293 EXPECT_EQ(0, RunCommand("", {kEchoCommand, "one", "is", "the", "loniest", "number"}));
Felipe Leme46b85da2016-11-21 17:40:45 -08001294 EXPECT_THAT(err, IsEmpty());
1295 EXPECT_THAT(out, StrEq("one is the loniest number\n"));
1296}
1297
1298TEST_F(DumpstateUtilTest, RunCommandWithLoggingMessage) {
1299 CreateFd("RunCommandWithLoggingMessage.txt");
1300 EXPECT_EQ(
Felipe Lemef0292972016-11-22 13:57:05 -08001301 0, RunCommand("", {kSimpleCommand},
Felipe Leme46b85da2016-11-21 17:40:45 -08001302 CommandOptions::WithTimeout(10).Log("COMMAND, Y U NO LOG FIRST?").Build()));
1303 EXPECT_THAT(out, StrEq("stdout\n"));
1304 EXPECT_THAT(err, StrEq("COMMAND, Y U NO LOG FIRST?stderr\n"));
1305}
1306
1307TEST_F(DumpstateUtilTest, RunCommandRedirectStderr) {
1308 CreateFd("RunCommandRedirectStderr.txt");
Felipe Lemef0292972016-11-22 13:57:05 -08001309 EXPECT_EQ(0, RunCommand("", {kSimpleCommand},
1310 CommandOptions::WithTimeout(10).RedirectStderr().Build()));
Felipe Leme46b85da2016-11-21 17:40:45 -08001311 EXPECT_THAT(out, IsEmpty());
1312 EXPECT_THAT(err, StrEq("stdout\nstderr\n"));
1313}
1314
1315TEST_F(DumpstateUtilTest, RunCommandDryRun) {
1316 CreateFd("RunCommandDryRun.txt");
1317 SetDryRun(true);
Felipe Lemef0292972016-11-22 13:57:05 -08001318 EXPECT_EQ(0, RunCommand("I AM GROOT", {kSimpleCommand}));
1319 EXPECT_THAT(out, StrEq(android::base::StringPrintf(
1320 "------ I AM GROOT (%s) ------\n\t(skipped on dry run)\n",
1321 kSimpleCommand.c_str())));
1322 EXPECT_THAT(err, IsEmpty());
1323}
1324
1325TEST_F(DumpstateUtilTest, RunCommandDryRunNoTitle) {
1326 CreateFd("RunCommandDryRun.txt");
1327 SetDryRun(true);
1328 EXPECT_EQ(0, RunCommand("", {kSimpleCommand}));
Felipe Leme46b85da2016-11-21 17:40:45 -08001329 EXPECT_THAT(
1330 out, StrEq(android::base::StringPrintf("%s: skipped on dry run\n", kSimpleCommand.c_str())));
1331 EXPECT_THAT(err, IsEmpty());
1332}
1333
1334TEST_F(DumpstateUtilTest, RunCommandDryRunAlways) {
1335 CreateFd("RunCommandDryRunAlways.txt");
1336 SetDryRun(true);
Felipe Lemef0292972016-11-22 13:57:05 -08001337 EXPECT_EQ(0, RunCommand("", {kSimpleCommand}, CommandOptions::WithTimeout(10).Always().Build()));
Felipe Leme46b85da2016-11-21 17:40:45 -08001338 EXPECT_THAT(out, StrEq("stdout\n"));
1339 EXPECT_THAT(err, StrEq("stderr\n"));
1340}
1341
1342TEST_F(DumpstateUtilTest, RunCommandNotFound) {
1343 CreateFd("RunCommandNotFound.txt");
Felipe Lemef0292972016-11-22 13:57:05 -08001344 EXPECT_NE(0, RunCommand("", {"/there/cannot/be/such/command"}));
Felipe Leme46b85da2016-11-21 17:40:45 -08001345 EXPECT_THAT(out, StartsWith("*** command '/there/cannot/be/such/command' failed: exit code"));
1346 EXPECT_THAT(err, StartsWith("execvp on command '/there/cannot/be/such/command' failed"));
1347}
1348
1349TEST_F(DumpstateUtilTest, RunCommandFails) {
1350 CreateFd("RunCommandFails.txt");
Felipe Lemef0292972016-11-22 13:57:05 -08001351 EXPECT_EQ(42, RunCommand("", {kSimpleCommand, "--exit", "42"}));
Felipe Leme46b85da2016-11-21 17:40:45 -08001352 EXPECT_THAT(out, StrEq("stdout\n*** command '" + kSimpleCommand +
1353 " --exit 42' failed: exit code 42\n"));
1354 EXPECT_THAT(err, StrEq("stderr\n*** command '" + kSimpleCommand +
1355 " --exit 42' failed: exit code 42\n"));
1356}
1357
1358TEST_F(DumpstateUtilTest, RunCommandCrashes) {
1359 CreateFd("RunCommandCrashes.txt");
Felipe Lemef0292972016-11-22 13:57:05 -08001360 EXPECT_NE(0, RunCommand("", {kSimpleCommand, "--crash"}));
Felipe Leme46b85da2016-11-21 17:40:45 -08001361 // We don't know the exit code, so check just the prefix.
1362 EXPECT_THAT(
1363 out, StartsWith("stdout\n*** command '" + kSimpleCommand + " --crash' failed: exit code"));
1364 EXPECT_THAT(
1365 err, StartsWith("stderr\n*** command '" + kSimpleCommand + " --crash' failed: exit code"));
1366}
1367
Vishnu Nair6921f802017-11-22 09:17:23 -08001368TEST_F(DumpstateUtilTest, RunCommandTimesoutWithSec) {
Felipe Leme46b85da2016-11-21 17:40:45 -08001369 CreateFd("RunCommandTimesout.txt");
Felipe Lemef0292972016-11-22 13:57:05 -08001370 EXPECT_EQ(-1, RunCommand("", {kSimpleCommand, "--sleep", "2"},
1371 CommandOptions::WithTimeout(1).Build()));
Felipe Leme46b85da2016-11-21 17:40:45 -08001372 EXPECT_THAT(out, StartsWith("stdout line1\n*** command '" + kSimpleCommand +
1373 " --sleep 2' timed out after 1"));
1374 EXPECT_THAT(err, StartsWith("sleeping for 2s\n*** command '" + kSimpleCommand +
1375 " --sleep 2' timed out after 1"));
1376}
1377
Vishnu Nair6921f802017-11-22 09:17:23 -08001378TEST_F(DumpstateUtilTest, RunCommandTimesoutWithMsec) {
1379 CreateFd("RunCommandTimesout.txt");
1380 EXPECT_EQ(-1, RunCommand("", {kSimpleCommand, "--sleep", "2"},
1381 CommandOptions::WithTimeoutInMs(1000).Build()));
1382 EXPECT_THAT(out, StartsWith("stdout line1\n*** command '" + kSimpleCommand +
1383 " --sleep 2' timed out after 1"));
1384 EXPECT_THAT(err, StartsWith("sleeping for 2s\n*** command '" + kSimpleCommand +
1385 " --sleep 2' timed out after 1"));
1386}
1387
1388
Felipe Leme46b85da2016-11-21 17:40:45 -08001389TEST_F(DumpstateUtilTest, RunCommandIsKilled) {
1390 CreateFd("RunCommandIsKilled.txt");
1391 CaptureStderr();
1392
1393 std::thread t([=]() {
Felipe Lemef0292972016-11-22 13:57:05 -08001394 EXPECT_EQ(SIGTERM, RunCommandToFd(fd, "", {kSimpleCommand, "--pid", "--sleep", "20"},
Felipe Leme46b85da2016-11-21 17:40:45 -08001395 CommandOptions::WithTimeout(100).Always().Build()));
1396 });
1397
1398 // Capture pid and pre-sleep output.
1399 sleep(1); // Wait a little bit to make sure pid and 1st line were printed.
1400 std::string err = GetCapturedStderr();
1401 EXPECT_THAT(err, StrEq("sleeping for 20s\n"));
1402
1403 CaptureFdOut();
1404 std::vector<std::string> lines = android::base::Split(out, "\n");
1405 ASSERT_EQ(3, (int)lines.size()) << "Invalid lines before sleep: " << out;
1406
1407 int pid = atoi(lines[0].c_str());
1408 EXPECT_THAT(lines[1], StrEq("stdout line1"));
1409 EXPECT_THAT(lines[2], IsEmpty()); // \n
1410
1411 // Then kill the process.
1412 CaptureFdOut();
1413 CaptureStderr();
1414 ASSERT_EQ(0, kill(pid, SIGTERM)) << "failed to kill pid " << pid;
1415 t.join();
1416
1417 // Finally, check output after murder.
1418 CaptureFdOut();
1419 err = GetCapturedStderr();
1420
1421 // out starts with the pid, which is an unknown
1422 EXPECT_THAT(out, EndsWith("stdout line1\n*** command '" + kSimpleCommand +
1423 " --pid --sleep 20' failed: killed by signal 15\n"));
1424 EXPECT_THAT(err, StrEq("*** command '" + kSimpleCommand +
1425 " --pid --sleep 20' failed: killed by signal 15\n"));
1426}
1427
1428TEST_F(DumpstateUtilTest, RunCommandAsRootUserBuild) {
1429 if (!IsStandalone()) {
1430 // TODO: temporarily disabled because it might cause other tests to fail after dropping
1431 // to Shell - need to refactor tests to avoid this problem)
1432 MYLOGE("Skipping DumpstateUtilTest.RunCommandAsRootUserBuild() on test suite\n")
1433 return;
1434 }
1435 CreateFd("RunCommandAsRootUserBuild.txt");
Felipe Lemef0292972016-11-22 13:57:05 -08001436 if (!PropertiesHelper::IsUserBuild()) {
Felipe Leme46b85da2016-11-21 17:40:45 -08001437 // Emulates user build if necessarily.
1438 SetBuildType("user");
1439 }
1440
1441 DropRoot();
1442
Felipe Lemef0292972016-11-22 13:57:05 -08001443 EXPECT_EQ(0, RunCommand("", {kSimpleCommand}, CommandOptions::WithTimeout(1).AsRoot().Build()));
Felipe Leme46b85da2016-11-21 17:40:45 -08001444
1445 // We don't know the exact path of su, so we just check for the 'root ...' commands
1446 EXPECT_THAT(out, StartsWith("Skipping"));
1447 EXPECT_THAT(out, EndsWith("root " + kSimpleCommand + "' on user build.\n"));
1448 EXPECT_THAT(err, IsEmpty());
1449}
1450
1451TEST_F(DumpstateUtilTest, RunCommandAsRootNonUserBuild) {
1452 if (!IsStandalone()) {
1453 // TODO: temporarily disabled because it might cause other tests to fail after dropping
1454 // to Shell - need to refactor tests to avoid this problem)
1455 MYLOGE("Skipping DumpstateUtilTest.RunCommandAsRootNonUserBuild() on test suite\n")
1456 return;
1457 }
1458 CreateFd("RunCommandAsRootNonUserBuild.txt");
Felipe Lemef0292972016-11-22 13:57:05 -08001459 if (PropertiesHelper::IsUserBuild()) {
Felipe Leme7447d7c2016-11-03 18:12:22 -07001460 ALOGI("Skipping RunCommandAsRootNonUserBuild on user builds\n");
1461 return;
1462 }
1463
1464 DropRoot();
1465
Felipe Lemef0292972016-11-22 13:57:05 -08001466 EXPECT_EQ(0, RunCommand("", {kSimpleCommand, "--uid"},
1467 CommandOptions::WithTimeout(1).AsRoot().Build()));
Felipe Leme7447d7c2016-11-03 18:12:22 -07001468
1469 EXPECT_THAT(out, StrEq("0\nstdout\n"));
1470 EXPECT_THAT(err, StrEq("stderr\n"));
1471}
Felipe Leme46b85da2016-11-21 17:40:45 -08001472
Yifan Hong48e83a12017-10-03 14:10:07 -07001473
1474TEST_F(DumpstateUtilTest, RunCommandAsRootIfAvailableOnUserBuild) {
1475 if (!IsStandalone()) {
1476 // TODO: temporarily disabled because it might cause other tests to fail after dropping
1477 // to Shell - need to refactor tests to avoid this problem)
1478 MYLOGE("Skipping DumpstateUtilTest.RunCommandAsRootIfAvailableOnUserBuild() on test suite\n")
1479 return;
1480 }
1481 CreateFd("RunCommandAsRootIfAvailableOnUserBuild.txt");
1482 if (!PropertiesHelper::IsUserBuild()) {
1483 // Emulates user build if necessarily.
1484 SetBuildType("user");
1485 }
1486
1487 DropRoot();
1488
1489 EXPECT_EQ(0, RunCommand("", {kSimpleCommand, "--uid"},
1490 CommandOptions::WithTimeout(1).AsRootIfAvailable().Build()));
1491
1492 EXPECT_THAT(out, StrEq("2000\nstdout\n"));
1493 EXPECT_THAT(err, StrEq("stderr\n"));
1494}
1495
1496TEST_F(DumpstateUtilTest, RunCommandAsRootIfAvailableOnDebugBuild) {
1497 if (!IsStandalone()) {
1498 // TODO: temporarily disabled because it might cause other tests to fail after dropping
1499 // to Shell - need to refactor tests to avoid this problem)
1500 MYLOGE("Skipping DumpstateUtilTest.RunCommandAsRootIfAvailableOnDebugBuild() on test suite\n")
1501 return;
1502 }
1503 CreateFd("RunCommandAsRootIfAvailableOnDebugBuild.txt");
1504 if (PropertiesHelper::IsUserBuild()) {
1505 ALOGI("Skipping RunCommandAsRootNonUserBuild on user builds\n");
1506 return;
1507 }
1508
1509 DropRoot();
1510
1511 EXPECT_EQ(0, RunCommand("", {kSimpleCommand, "--uid"},
1512 CommandOptions::WithTimeout(1).AsRootIfAvailable().Build()));
1513
1514 EXPECT_THAT(out, StrEq("0\nstdout\n"));
1515 EXPECT_THAT(err, StrEq("stderr\n"));
1516}
1517
Felipe Leme46b85da2016-11-21 17:40:45 -08001518TEST_F(DumpstateUtilTest, RunCommandDropRoot) {
1519 if (!IsStandalone()) {
1520 // TODO: temporarily disabled because it might cause other tests to fail after dropping
1521 // to Shell - need to refactor tests to avoid this problem)
1522 MYLOGE("Skipping DumpstateUtilTest.RunCommandDropRoot() on test suite\n")
1523 return;
1524 }
1525 CreateFd("RunCommandDropRoot.txt");
1526 // First check root case - only available when running with 'adb root'.
1527 uid_t uid = getuid();
1528 if (uid == 0) {
Felipe Lemef0292972016-11-22 13:57:05 -08001529 EXPECT_EQ(0, RunCommand("", {kSimpleCommand, "--uid"}));
Felipe Leme46b85da2016-11-21 17:40:45 -08001530 EXPECT_THAT(out, StrEq("0\nstdout\n"));
1531 EXPECT_THAT(err, StrEq("stderr\n"));
1532 return;
1533 }
1534 // Then run dropping root.
Felipe Lemef0292972016-11-22 13:57:05 -08001535 EXPECT_EQ(0, RunCommand("", {kSimpleCommand, "--uid"},
Felipe Leme46b85da2016-11-21 17:40:45 -08001536 CommandOptions::WithTimeout(1).DropRoot().Build()));
1537 EXPECT_THAT(out, StrEq("2000\nstdout\n"));
1538 EXPECT_THAT(err, StrEq("drop_root_user(): already running as Shell\nstderr\n"));
1539}
1540
Felipe Lemef0292972016-11-22 13:57:05 -08001541TEST_F(DumpstateUtilTest, DumpFileNotFoundNoTitle) {
Felipe Leme46b85da2016-11-21 17:40:45 -08001542 CreateFd("DumpFileNotFound.txt");
Felipe Lemef0292972016-11-22 13:57:05 -08001543 EXPECT_EQ(-1, DumpFile("", "/I/cant/believe/I/exist"));
Felipe Leme46b85da2016-11-21 17:40:45 -08001544 EXPECT_THAT(out,
1545 StrEq("*** Error dumping /I/cant/believe/I/exist: No such file or directory\n"));
1546 EXPECT_THAT(err, IsEmpty());
1547}
1548
Felipe Lemef0292972016-11-22 13:57:05 -08001549TEST_F(DumpstateUtilTest, DumpFileNotFoundWithTitle) {
1550 CreateFd("DumpFileNotFound.txt");
1551 EXPECT_EQ(-1, DumpFile("Y U NO EXIST?", "/I/cant/believe/I/exist"));
1552 EXPECT_THAT(out, StrEq("*** Error dumping /I/cant/believe/I/exist (Y U NO EXIST?): No such "
1553 "file or directory\n"));
1554 EXPECT_THAT(err, IsEmpty());
1555}
1556
Felipe Leme46b85da2016-11-21 17:40:45 -08001557TEST_F(DumpstateUtilTest, DumpFileSingleLine) {
1558 CreateFd("DumpFileSingleLine.txt");
Felipe Lemef0292972016-11-22 13:57:05 -08001559 EXPECT_EQ(0, DumpFile("", kTestDataPath + "single-line.txt"));
Felipe Leme46b85da2016-11-21 17:40:45 -08001560 EXPECT_THAT(err, IsEmpty());
1561 EXPECT_THAT(out, StrEq("I AM LINE1\n")); // dumpstate adds missing newline
1562}
1563
1564TEST_F(DumpstateUtilTest, DumpFileSingleLineWithNewLine) {
1565 CreateFd("DumpFileSingleLineWithNewLine.txt");
Felipe Lemef0292972016-11-22 13:57:05 -08001566 EXPECT_EQ(0, DumpFile("", kTestDataPath + "single-line-with-newline.txt"));
Felipe Leme46b85da2016-11-21 17:40:45 -08001567 EXPECT_THAT(err, IsEmpty());
1568 EXPECT_THAT(out, StrEq("I AM LINE1\n"));
1569}
1570
1571TEST_F(DumpstateUtilTest, DumpFileMultipleLines) {
1572 CreateFd("DumpFileMultipleLines.txt");
Felipe Lemef0292972016-11-22 13:57:05 -08001573 EXPECT_EQ(0, DumpFile("", kTestDataPath + "multiple-lines.txt"));
Felipe Leme46b85da2016-11-21 17:40:45 -08001574 EXPECT_THAT(err, IsEmpty());
1575 EXPECT_THAT(out, StrEq("I AM LINE1\nI AM LINE2\nI AM LINE3\n"));
1576}
1577
1578TEST_F(DumpstateUtilTest, DumpFileMultipleLinesWithNewLine) {
1579 CreateFd("DumpFileMultipleLinesWithNewLine.txt");
Felipe Lemef0292972016-11-22 13:57:05 -08001580 EXPECT_EQ(0, DumpFile("", kTestDataPath + "multiple-lines-with-newline.txt"));
Felipe Leme46b85da2016-11-21 17:40:45 -08001581 EXPECT_THAT(err, IsEmpty());
1582 EXPECT_THAT(out, StrEq("I AM LINE1\nI AM LINE2\nI AM LINE3\n"));
1583}
1584
Felipe Lemef0292972016-11-22 13:57:05 -08001585TEST_F(DumpstateUtilTest, DumpFileOnDryRunNoTitle) {
1586 CreateFd("DumpFileOnDryRun.txt");
1587 SetDryRun(true);
1588 std::string path = kTestDataPath + "single-line.txt";
1589 EXPECT_EQ(0, DumpFile("", kTestDataPath + "single-line.txt"));
1590 EXPECT_THAT(err, IsEmpty());
1591 EXPECT_THAT(out, StrEq(path + ": skipped on dry run\n"));
1592}
1593
Felipe Leme46b85da2016-11-21 17:40:45 -08001594TEST_F(DumpstateUtilTest, DumpFileOnDryRun) {
1595 CreateFd("DumpFileOnDryRun.txt");
1596 SetDryRun(true);
1597 std::string path = kTestDataPath + "single-line.txt";
Felipe Lemef0292972016-11-22 13:57:05 -08001598 EXPECT_EQ(0, DumpFile("Might as well dump. Dump!", kTestDataPath + "single-line.txt"));
Felipe Leme46b85da2016-11-21 17:40:45 -08001599 EXPECT_THAT(err, IsEmpty());
Felipe Lemef0292972016-11-22 13:57:05 -08001600 EXPECT_THAT(
1601 out, StartsWith("------ Might as well dump. Dump! (" + kTestDataPath + "single-line.txt:"));
1602 EXPECT_THAT(out, EndsWith("skipped on dry run\n"));
Felipe Leme46b85da2016-11-21 17:40:45 -08001603}
Ecco Park61ffcf72016-10-27 15:46:26 -07001604
Felipe Leme47e9be22016-12-21 15:37:07 -08001605} // namespace dumpstate
1606} // namespace os
1607} // namespace android