Home | History | Annotate | Download | only in server
      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
     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, 0x5, 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, 0x1, 0, logs.length);
     61         doTestFsckFsStat(doubleLogs, 0x402, 0x2, logs.length, logs.length * 2);
     62     }
     63 
     64     @Test
     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         // quota fix without tree optimization is an error.
     83         doTestFsckFsStat(logs, 0x405, 0x405, 0, logs.length);
     84     }
     85 
     86     @Test
     87     public void testOrphaned() {
     88         final String[] logs = {
     89                 "e2fsck 1.43.3 (04-Sep-2016)",
     90                 "Pass 1: Checking inodes, blocks, and sizes",
     91                 "Inodes that were part of a corrupted orphan linked list found.  Fix? yes",
     92                 " ",
     93                 "Inode 589877 was part of the orphaned inode list.  FIXED.",
     94                 " ",
     95                 "Inode 589878 was part of the orphaned inode list.  FIXED.",
     96                 " ",
     97                 "Pass 2: Checking directory structure",
     98                 "Pass 3: Checking directory connectivity",
     99                 "Pass 4: Checking reference counts",
    100                 "Pass 5: Checking group summary information",
    101                 " ",
    102                 "/dev/block/platform/soc/624000.ufshc/by-name/userdata: ***** FILE SYSTEM WAS MODIFIED *****"
    103         };
    104         doTestFsckFsStat(logs, 0x405, 0x405, 0, logs.length);
    105     }
    106 
    107     @Test
    108     public void testTimestampAdjustment() {
    109         final String[] logs = {
    110                 "e2fsck 1.43.3 (04-Sep-2016)",
    111                 "Pass 1: Checking inodes, blocks, and sizes",
    112                 "Timestamp(s) on inode 508580 beyond 2310-04-04 are likely pre-1970.",
    113                 "Fix? yes",
    114                 " ",
    115                 "Pass 1E: Optimizing extent trees",
    116                 "Pass 2: Checking directory structure",
    117                 "Pass 3: Checking directory connectivity",
    118                 "Pass 4: Checking reference counts",
    119                 "Pass 5: Checking group summary information",
    120                 " ",
    121                 "/dev/block/platform/soc/624000.ufshc/by-name/userdata: ***** FILE SYSTEM WAS MODIFIED *****"
    122         };
    123         doTestFsckFsStat(logs, 0x405, 0x5, 0, logs.length);
    124     }
    125 
    126     @Test
    127     public void testTimestampAdjustmentNoFixLine() {
    128         final String[] logs = {
    129                 "e2fsck 1.43.3 (04-Sep-2016)",
    130                 "Pass 1: Checking inodes, blocks, and sizes",
    131                 "Timestamp(s) on inode 508580 beyond 2310-04-04 are likely pre-1970.",
    132                 " ",
    133                 "Pass 1E: Optimizing extent trees",
    134                 "Pass 2: Checking directory structure",
    135                 "Pass 3: Checking directory connectivity",
    136                 "Pass 4: Checking reference counts",
    137                 "Pass 5: Checking group summary information",
    138                 " ",
    139                 "/dev/block/platform/soc/624000.ufshc/by-name/userdata: ***** FILE SYSTEM WAS MODIFIED *****"
    140         };
    141         doTestFsckFsStat(logs, 0x405, 0x5, 0, logs.length);
    142     }
    143 
    144     @Test
    145     public void testTimestampAdjustmentWithQuotaFix() {
    146         final String[] logs = {
    147                 "e2fsck 1.43.3 (04-Sep-2016)",
    148                 "Pass 1: Checking inodes, blocks, and sizes",
    149                 "Timestamp(s) on inode 508580 beyond 2310-04-04 are likely pre-1970.",
    150                 "Fix? yes",
    151                 " ",
    152                 "Pass 1E: Optimizing extent trees",
    153                 "Pass 2: Checking directory structure",
    154                 "Pass 3: Checking directory connectivity",
    155                 "Pass 4: Checking reference counts",
    156                 "Pass 5: Checking group summary information",
    157                 "[QUOTA WARNING] Usage inconsistent for ID 10038:actual (71667712, 1000) != expected (71671808, 1000)",
    158                 "Update quota info for quota type 0? yes",
    159                 " ",
    160                 "[QUOTA WARNING] Usage inconsistent for ID 10038:actual (59555840, 953) != expected (59559936, 953)",
    161                 "Update quota info for quota type 1? yes",
    162                 " ",
    163                 "/dev/block/platform/soc/624000.ufshc/by-name/userdata: ***** FILE SYSTEM WAS MODIFIED *****"
    164         };
    165         doTestFsckFsStat(logs, 0x405, 0x405, 0, logs.length);
    166     }
    167 
    168     @Test
    169     public void testAllNonFixes() {
    170         final String[] logs = {
    171                 "e2fsck 1.43.3 (04-Sep-2016)",
    172                 "Pass 1: Checking inodes, blocks, and sizes",
    173                 "Timestamp(s) on inode 508580 beyond 2310-04-04 are likely pre-1970.",
    174                 "Fix? yes",
    175                 "Inode 877141 extent tree (at level 1) could be shorter.  Fix? yes",
    176                 " ",
    177                 "Pass 1E: Optimizing extent trees",
    178                 "Pass 2: Checking directory structure",
    179                 "Pass 3: Checking directory connectivity",
    180                 "Pass 4: Checking reference counts",
    181                 "Pass 5: Checking group summary information",
    182                 "[QUOTA WARNING] Usage inconsistent for ID 10038:actual (71667712, 1000) != expected (71671808, 1000)",
    183                 "Update quota info for quota type 0? yes",
    184                 " ",
    185                 "[QUOTA WARNING] Usage inconsistent for ID 10038:actual (59555840, 953) != expected (59559936, 953)",
    186                 "Update quota info for quota type 1? yes",
    187                 " ",
    188                 "/dev/block/platform/soc/624000.ufshc/by-name/userdata: ***** FILE SYSTEM WAS MODIFIED *****"
    189         };
    190         doTestFsckFsStat(logs, 0x405, 0x5, 0, logs.length);
    191     }
    192 
    193     private void doTestFsckFsStat(String[] lines, int statOrg, int statUpdated, int startLineNumber,
    194             int endLineNumber) {
    195         assertEquals(statUpdated, BootReceiver.fixFsckFsStat(PARTITION, statOrg, lines,
    196                 startLineNumber, endLineNumber));
    197     }
    198 }
    199