Keun-young Park | 6bea235 | 2017-04-17 16:17:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | package com.android.server; |
| 18 | |
| 19 | import static junit.framework.Assert.*; |
| 20 | |
Brett Chabot | a26eda9 | 2018-07-23 13:08:30 -0700 | [diff] [blame] | 21 | import androidx.test.filters.SmallTest; |
| 22 | import androidx.test.runner.AndroidJUnit4; |
Keun-young Park | 6bea235 | 2017-04-17 16:17:28 -0700 | [diff] [blame] | 23 | |
| 24 | import org.junit.Test; |
| 25 | import org.junit.runner.RunWith; |
| 26 | |
| 27 | @SmallTest |
| 28 | @RunWith(AndroidJUnit4.class) |
| 29 | public class BootReceiverFixFsckFsStatTest { |
| 30 | |
| 31 | private static final String PARTITION = "userdata"; |
| 32 | |
| 33 | @Test |
| 34 | public void testTreeOptimization() { |
| 35 | final String[] logs = { |
| 36 | "e2fsck 1.43.3 (04-Sep-2016)", |
| 37 | "Pass 1: Checking inodes, blocks, and sizes", |
| 38 | "Inode 877141 extent tree (at level 1) could be shorter. Fix? yes", |
| 39 | " ", |
| 40 | "Pass 1E: Optimizing extent trees", |
| 41 | "Pass 2: Checking directory structure", |
| 42 | "Pass 3: Checking directory connectivity", |
| 43 | "Pass 4: Checking reference counts", |
| 44 | "Pass 5: Checking group summary information", |
| 45 | "[QUOTA WARNING] Usage inconsistent for ID 10038:actual (71667712, 1000) != expected (71671808, 1000)", |
| 46 | "Update quota info for quota type 0? yes", |
| 47 | " ", |
| 48 | "[QUOTA WARNING] Usage inconsistent for ID 10038:actual (59555840, 953) != expected (59559936, 953)", |
| 49 | "Update quota info for quota type 1? yes", |
| 50 | " ", |
| 51 | "/dev/block/platform/soc/624000.ufshc/by-name/userdata: ***** FILE SYSTEM WAS MODIFIED *****" |
| 52 | }; |
Keun-young Park | 12a2705 | 2017-05-23 14:39:41 -0700 | [diff] [blame] | 53 | doTestFsckFsStat(logs, 0x405, 0x5, 0, logs.length); |
Keun-young Park | 6bea235 | 2017-04-17 16:17:28 -0700 | [diff] [blame] | 54 | |
| 55 | final String[] doubleLogs = new String[logs.length * 2]; |
| 56 | System.arraycopy(logs, 0, doubleLogs, 0, logs.length); |
| 57 | System.arraycopy(logs, 0, doubleLogs, logs.length, logs.length); |
Keun-young Park | 12a2705 | 2017-05-23 14:39:41 -0700 | [diff] [blame] | 58 | doTestFsckFsStat(doubleLogs, 0x401, 0x1, 0, logs.length); |
| 59 | doTestFsckFsStat(doubleLogs, 0x402, 0x2, logs.length, logs.length * 2); |
Keun-young Park | 6bea235 | 2017-04-17 16:17:28 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | @Test |
| 63 | public void testQuotaOnly() { |
| 64 | final String[] logs = { |
| 65 | "e2fsck 1.43.3 (04-Sep-2016)", |
| 66 | "Pass 1: Checking inodes, blocks, and sizes", |
| 67 | "Pass 1E: Optimizing extent trees", |
| 68 | "Pass 2: Checking directory structure", |
| 69 | "Pass 3: Checking directory connectivity", |
| 70 | "Pass 4: Checking reference counts", |
| 71 | "Pass 5: Checking group summary information", |
| 72 | "[QUOTA WARNING] Usage inconsistent for ID 10038:actual (71667712, 1000) != expected (71671808, 1000)", |
| 73 | "Update quota info for quota type 0? yes", |
| 74 | " ", |
| 75 | "[QUOTA WARNING] Usage inconsistent for ID 10038:actual (59555840, 953) != expected (59559936, 953)", |
| 76 | "Update quota info for quota type 1? yes", |
| 77 | " ", |
| 78 | "/dev/block/platform/soc/624000.ufshc/by-name/userdata: ***** FILE SYSTEM WAS MODIFIED *****" |
| 79 | }; |
Keun-young Park | 12a2705 | 2017-05-23 14:39:41 -0700 | [diff] [blame] | 80 | // quota fix without tree optimization is an error. |
Keun-young Park | 6bea235 | 2017-04-17 16:17:28 -0700 | [diff] [blame] | 81 | doTestFsckFsStat(logs, 0x405, 0x405, 0, logs.length); |
| 82 | } |
| 83 | |
| 84 | @Test |
| 85 | public void testOrphaned() { |
| 86 | final String[] logs = { |
| 87 | "e2fsck 1.43.3 (04-Sep-2016)", |
| 88 | "Pass 1: Checking inodes, blocks, and sizes", |
| 89 | "Inodes that were part of a corrupted orphan linked list found. Fix? yes", |
| 90 | " ", |
| 91 | "Inode 589877 was part of the orphaned inode list. FIXED.", |
| 92 | " ", |
| 93 | "Inode 589878 was part of the orphaned inode list. FIXED.", |
| 94 | " ", |
| 95 | "Pass 2: Checking directory structure", |
| 96 | "Pass 3: Checking directory connectivity", |
| 97 | "Pass 4: Checking reference counts", |
| 98 | "Pass 5: Checking group summary information", |
| 99 | " ", |
| 100 | "/dev/block/platform/soc/624000.ufshc/by-name/userdata: ***** FILE SYSTEM WAS MODIFIED *****" |
| 101 | }; |
| 102 | doTestFsckFsStat(logs, 0x405, 0x405, 0, logs.length); |
| 103 | } |
| 104 | |
Keun-young Park | 12a2705 | 2017-05-23 14:39:41 -0700 | [diff] [blame] | 105 | @Test |
| 106 | public void testTimestampAdjustment() { |
| 107 | final String[] logs = { |
| 108 | "e2fsck 1.43.3 (04-Sep-2016)", |
| 109 | "Pass 1: Checking inodes, blocks, and sizes", |
| 110 | "Timestamp(s) on inode 508580 beyond 2310-04-04 are likely pre-1970.", |
| 111 | "Fix? yes", |
| 112 | " ", |
| 113 | "Pass 1E: Optimizing extent trees", |
| 114 | "Pass 2: Checking directory structure", |
| 115 | "Pass 3: Checking directory connectivity", |
| 116 | "Pass 4: Checking reference counts", |
| 117 | "Pass 5: Checking group summary information", |
| 118 | " ", |
| 119 | "/dev/block/platform/soc/624000.ufshc/by-name/userdata: ***** FILE SYSTEM WAS MODIFIED *****" |
| 120 | }; |
| 121 | doTestFsckFsStat(logs, 0x405, 0x5, 0, logs.length); |
| 122 | } |
| 123 | |
| 124 | @Test |
| 125 | public void testTimestampAdjustmentNoFixLine() { |
| 126 | final String[] logs = { |
| 127 | "e2fsck 1.43.3 (04-Sep-2016)", |
| 128 | "Pass 1: Checking inodes, blocks, and sizes", |
| 129 | "Timestamp(s) on inode 508580 beyond 2310-04-04 are likely pre-1970.", |
| 130 | " ", |
| 131 | "Pass 1E: Optimizing extent trees", |
| 132 | "Pass 2: Checking directory structure", |
| 133 | "Pass 3: Checking directory connectivity", |
| 134 | "Pass 4: Checking reference counts", |
| 135 | "Pass 5: Checking group summary information", |
| 136 | " ", |
| 137 | "/dev/block/platform/soc/624000.ufshc/by-name/userdata: ***** FILE SYSTEM WAS MODIFIED *****" |
| 138 | }; |
| 139 | doTestFsckFsStat(logs, 0x405, 0x5, 0, logs.length); |
| 140 | } |
| 141 | |
| 142 | @Test |
| 143 | public void testTimestampAdjustmentWithQuotaFix() { |
| 144 | final String[] logs = { |
| 145 | "e2fsck 1.43.3 (04-Sep-2016)", |
| 146 | "Pass 1: Checking inodes, blocks, and sizes", |
| 147 | "Timestamp(s) on inode 508580 beyond 2310-04-04 are likely pre-1970.", |
| 148 | "Fix? yes", |
| 149 | " ", |
| 150 | "Pass 1E: Optimizing extent trees", |
| 151 | "Pass 2: Checking directory structure", |
| 152 | "Pass 3: Checking directory connectivity", |
| 153 | "Pass 4: Checking reference counts", |
| 154 | "Pass 5: Checking group summary information", |
| 155 | "[QUOTA WARNING] Usage inconsistent for ID 10038:actual (71667712, 1000) != expected (71671808, 1000)", |
| 156 | "Update quota info for quota type 0? yes", |
| 157 | " ", |
| 158 | "[QUOTA WARNING] Usage inconsistent for ID 10038:actual (59555840, 953) != expected (59559936, 953)", |
| 159 | "Update quota info for quota type 1? yes", |
| 160 | " ", |
| 161 | "/dev/block/platform/soc/624000.ufshc/by-name/userdata: ***** FILE SYSTEM WAS MODIFIED *****" |
| 162 | }; |
| 163 | doTestFsckFsStat(logs, 0x405, 0x405, 0, logs.length); |
| 164 | } |
| 165 | |
| 166 | @Test |
| 167 | public void testAllNonFixes() { |
| 168 | final String[] logs = { |
| 169 | "e2fsck 1.43.3 (04-Sep-2016)", |
| 170 | "Pass 1: Checking inodes, blocks, and sizes", |
| 171 | "Timestamp(s) on inode 508580 beyond 2310-04-04 are likely pre-1970.", |
| 172 | "Fix? yes", |
| 173 | "Inode 877141 extent tree (at level 1) could be shorter. Fix? yes", |
| 174 | " ", |
| 175 | "Pass 1E: Optimizing extent trees", |
| 176 | "Pass 2: Checking directory structure", |
| 177 | "Pass 3: Checking directory connectivity", |
| 178 | "Pass 4: Checking reference counts", |
| 179 | "Pass 5: Checking group summary information", |
| 180 | "[QUOTA WARNING] Usage inconsistent for ID 10038:actual (71667712, 1000) != expected (71671808, 1000)", |
| 181 | "Update quota info for quota type 0? yes", |
| 182 | " ", |
| 183 | "[QUOTA WARNING] Usage inconsistent for ID 10038:actual (59555840, 953) != expected (59559936, 953)", |
| 184 | "Update quota info for quota type 1? yes", |
| 185 | " ", |
| 186 | "/dev/block/platform/soc/624000.ufshc/by-name/userdata: ***** FILE SYSTEM WAS MODIFIED *****" |
| 187 | }; |
| 188 | doTestFsckFsStat(logs, 0x405, 0x5, 0, logs.length); |
| 189 | } |
| 190 | |
Keun-young Park | 6bea235 | 2017-04-17 16:17:28 -0700 | [diff] [blame] | 191 | private void doTestFsckFsStat(String[] lines, int statOrg, int statUpdated, int startLineNumber, |
| 192 | int endLineNumber) { |
| 193 | assertEquals(statUpdated, BootReceiver.fixFsckFsStat(PARTITION, statOrg, lines, |
| 194 | startLineNumber, endLineNumber)); |
| 195 | } |
| 196 | } |