diff options
author | Mark Salyzyn | 2016-03-09 16:58:16 -0600 |
---|---|---|
committer | Mark Salyzyn | 2016-03-31 15:52:54 -0500 |
commit | 13aca598f8e93548fef36d87136e85ce8c9d18de (patch) | |
tree | b166f4a950fefb3e8427ddc51cb1264da7a48aec /tests/unit | |
parent | f1b2785129b64a140764483901530f40716e53f5 (diff) | |
download | platform-bootable-recovery-13aca598f8e93548fef36d87136e85ce8c9d18de.tar.gz platform-bootable-recovery-13aca598f8e93548fef36d87136e85ce8c9d18de.tar.xz platform-bootable-recovery-13aca598f8e93548fef36d87136e85ce8c9d18de.zip |
recovery: use __android_log_pmsg_file_write for log files
(cherry-pick from commit a4f701af93a5a739f34823cde0c493dfbc63537a)
- Add call to __android_log_pmsg_file_write for recovery logging.
- Add call to refresh pmsg if we reboot back into recovery and then
allow overwrite of those logs.
- Add a new one-time executable recovery-refresh that refreshes pmsg
in post-fs phase of init. We rely on pmsg eventually scrolling off
to age the content after recovery-persist has done its job.
- Add a new one-time executable recovery-persist that transfers from
pmsg to /data/misc/recovery/ directory if /cache is not mounted
in post-fs-data phase of init.
- Build and appropriately trigger the above two as required if
BOARD_CACHEIMAGE_PARTITION_SIZE is undefined.
- Add some simple unit tests
NB: Test failure is expected on systems that do not deliver either
the recovery-persist or recovery-refresh executables, e.g. systems
with /cache. Tests also require a timely reboot sequence of test
to truly verify, tests provide guidance on stderr to direct.
Bug: 27176738
Change-Id: I17bb95980234984f6b2087fd5941b0a3126b706b
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/recovery_test.cpp | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/unit/recovery_test.cpp b/tests/unit/recovery_test.cpp new file mode 100644 index 00000000..f397f258 --- /dev/null +++ b/tests/unit/recovery_test.cpp | |||
@@ -0,0 +1,92 @@ | |||
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 <fcntl.h> | ||
18 | #include <string.h> | ||
19 | #include <sys/types.h> | ||
20 | #include <unistd.h> | ||
21 | |||
22 | #include <android/log.h> | ||
23 | #include <gtest/gtest.h> | ||
24 | #include <log/logger.h> | ||
25 | #include <private/android_logger.h> | ||
26 | |||
27 | static const char myFilename[] = "/data/misc/recovery/inject.txt"; | ||
28 | static const char myContent[] = "Hello World\nWelcome to my recovery\n"; | ||
29 | |||
30 | // Failure is expected on systems that do not deliver either the | ||
31 | // recovery-persist or recovery-refresh executables. Tests also require | ||
32 | // a reboot sequence of test to truly verify. | ||
33 | |||
34 | static ssize_t __pmsg_fn(log_id_t logId, char prio, const char *filename, | ||
35 | const char *buf, size_t len, void *arg) { | ||
36 | EXPECT_EQ(LOG_ID_SYSTEM, logId); | ||
37 | EXPECT_EQ(ANDROID_LOG_INFO, prio); | ||
38 | EXPECT_EQ(0, NULL == strstr(myFilename,filename)); | ||
39 | EXPECT_EQ(0, strcmp(myContent, buf)); | ||
40 | EXPECT_EQ(sizeof(myContent), len); | ||
41 | EXPECT_EQ(0, NULL != arg); | ||
42 | return len; | ||
43 | } | ||
44 | |||
45 | // recovery.refresh - May fail. Requires recovery.inject, two reboots, | ||
46 | // then expect success after second reboot. | ||
47 | TEST(recovery, refresh) { | ||
48 | EXPECT_EQ(0, access("/system/bin/recovery-refresh", F_OK)); | ||
49 | |||
50 | ssize_t ret = __android_log_pmsg_file_read( | ||
51 | LOG_ID_SYSTEM, ANDROID_LOG_INFO, "recovery/", __pmsg_fn, NULL); | ||
52 | if (ret == -ENOENT) { | ||
53 | EXPECT_LT(0, __android_log_pmsg_file_write( | ||
54 | LOG_ID_SYSTEM, ANDROID_LOG_INFO, | ||
55 | myFilename, myContent, sizeof(myContent))); | ||
56 | fprintf(stderr, "injected test data, " | ||
57 | "requires two intervening reboots " | ||
58 | "to check for replication\n"); | ||
59 | } | ||
60 | EXPECT_EQ((ssize_t)sizeof(myContent), ret); | ||
61 | } | ||
62 | |||
63 | // recovery.persist - Requires recovery.inject, then a reboot, then | ||
64 | // expect success after for this test on that boot. | ||
65 | TEST(recovery, persist) { | ||
66 | EXPECT_EQ(0, access("/system/bin/recovery-persist", F_OK)); | ||
67 | |||
68 | ssize_t ret = __android_log_pmsg_file_read( | ||
69 | LOG_ID_SYSTEM, ANDROID_LOG_INFO, "recovery/", __pmsg_fn, NULL); | ||
70 | if (ret == -ENOENT) { | ||
71 | EXPECT_LT(0, __android_log_pmsg_file_write( | ||
72 | LOG_ID_SYSTEM, ANDROID_LOG_INFO, | ||
73 | myFilename, myContent, sizeof(myContent))); | ||
74 | fprintf(stderr, "injected test data, " | ||
75 | "requires intervening reboot " | ||
76 | "to check for storage\n"); | ||
77 | } | ||
78 | |||
79 | int fd = open(myFilename, O_RDONLY); | ||
80 | EXPECT_LE(0, fd); | ||
81 | |||
82 | char buf[sizeof(myContent) + 32]; | ||
83 | ret = read(fd, buf, sizeof(buf)); | ||
84 | close(fd); | ||
85 | EXPECT_EQ(ret, (ssize_t)sizeof(myContent)); | ||
86 | EXPECT_EQ(0, strcmp(myContent, buf)); | ||
87 | if (fd >= 0) { | ||
88 | fprintf(stderr, "Removing persistent test data, " | ||
89 | "check if reconstructed on reboot\n"); | ||
90 | } | ||
91 | EXPECT_EQ(0, unlink(myFilename)); | ||
92 | } | ||