• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
21 import android.support.test.filters.SmallTest;
22 import android.support.test.runner.AndroidJUnit4;
23 
24 import junit.framework.Assert;
25 
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 
29 @SmallTest
30 @RunWith(AndroidJUnit4.class)
31 public class BootReceiverFixFsckFsStatTest {
32 
33     private static final String PARTITION = "userdata";
34 
35     @Test
testTreeOptimization()36     public void testTreeOptimization() {
37         final String[] logs = {
38                 "e2fsck 1.43.3 (04-Sep-2016)",
39                 "Pass 1: Checking inodes, blocks, and sizes",
40                 "Inode 877141 extent tree (at level 1) could be shorter.  Fix? yes",
41                 " ",
42                 "Pass 1E: Optimizing extent trees",
43                 "Pass 2: Checking directory structure",
44                 "Pass 3: Checking directory connectivity",
45                 "Pass 4: Checking reference counts",
46                 "Pass 5: Checking group summary information",
47                 "[QUOTA WARNING] Usage inconsistent for ID 10038:actual (71667712, 1000) != expected (71671808, 1000)",
48                 "Update quota info for quota type 0? yes",
49                 " ",
50                 "[QUOTA WARNING] Usage inconsistent for ID 10038:actual (59555840, 953) != expected (59559936, 953)",
51                 "Update quota info for quota type 1? yes",
52                 " ",
53                 "/dev/block/platform/soc/624000.ufshc/by-name/userdata: ***** FILE SYSTEM WAS MODIFIED *****"
54         };
55         doTestFsckFsStat(logs, 0x405, 5, 0, logs.length);
56 
57         final String[] doubleLogs = new String[logs.length * 2];
58         System.arraycopy(logs, 0, doubleLogs, 0, logs.length);
59         System.arraycopy(logs, 0, doubleLogs, logs.length, logs.length);
60         doTestFsckFsStat(doubleLogs, 0x401, 1, 0, logs.length);
61         doTestFsckFsStat(doubleLogs, 0x402, 2, logs.length, logs.length * 2);
62     }
63 
64     @Test
testQuotaOnly()65     public void testQuotaOnly() {
66         final String[] logs = {
67                 "e2fsck 1.43.3 (04-Sep-2016)",
68                 "Pass 1: Checking inodes, blocks, and sizes",
69                 "Pass 1E: Optimizing extent trees",
70                 "Pass 2: Checking directory structure",
71                 "Pass 3: Checking directory connectivity",
72                 "Pass 4: Checking reference counts",
73                 "Pass 5: Checking group summary information",
74                 "[QUOTA WARNING] Usage inconsistent for ID 10038:actual (71667712, 1000) != expected (71671808, 1000)",
75                 "Update quota info for quota type 0? yes",
76                 " ",
77                 "[QUOTA WARNING] Usage inconsistent for ID 10038:actual (59555840, 953) != expected (59559936, 953)",
78                 "Update quota info for quota type 1? yes",
79                 " ",
80                 "/dev/block/platform/soc/624000.ufshc/by-name/userdata: ***** FILE SYSTEM WAS MODIFIED *****"
81         };
82         doTestFsckFsStat(logs, 0x405, 0x405, 0, logs.length);
83     }
84 
85     @Test
testOrphaned()86     public void testOrphaned() {
87         final String[] logs = {
88                 "e2fsck 1.43.3 (04-Sep-2016)",
89                 "Pass 1: Checking inodes, blocks, and sizes",
90                 "Inodes that were part of a corrupted orphan linked list found.  Fix? yes",
91                 " ",
92                 "Inode 589877 was part of the orphaned inode list.  FIXED.",
93                 " ",
94                 "Inode 589878 was part of the orphaned inode list.  FIXED.",
95                 " ",
96                 "Pass 2: Checking directory structure",
97                 "Pass 3: Checking directory connectivity",
98                 "Pass 4: Checking reference counts",
99                 "Pass 5: Checking group summary information",
100                 " ",
101                 "/dev/block/platform/soc/624000.ufshc/by-name/userdata: ***** FILE SYSTEM WAS MODIFIED *****"
102         };
103         doTestFsckFsStat(logs, 0x405, 0x405, 0, logs.length);
104     }
105 
doTestFsckFsStat(String[] lines, int statOrg, int statUpdated, int startLineNumber, int endLineNumber)106     private void doTestFsckFsStat(String[] lines, int statOrg, int statUpdated, int startLineNumber,
107             int endLineNumber) {
108         assertEquals(statUpdated, BootReceiver.fixFsckFsStat(PARTITION, statOrg, lines,
109                 startLineNumber, endLineNumber));
110     }
111 }
112