• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.car;
17 
18 
19 import android.test.AndroidTestCase;
20 import android.test.suitebuilder.annotation.SmallTest;
21 import android.util.MutableBoolean;
22 
23 import com.android.car.CarService.CrashTracker;
24 
25 @SmallTest
26 public class CrashTrackerTest extends AndroidTestCase {
27 
testCrashingTooManyTimes()28     public void testCrashingTooManyTimes() throws InterruptedException {
29         final int SLIDING_WINDOW = 100;
30         final MutableBoolean callbackTriggered = new MutableBoolean(false);
31 
32         CarService.CrashTracker crashTracker = new CrashTracker(3, SLIDING_WINDOW,
33                 () -> callbackTriggered.value = true);
34 
35 
36         crashTracker.crashDetected();
37         crashTracker.crashDetected();
38         Thread.sleep(SLIDING_WINDOW + 1);
39         crashTracker.crashDetected();
40 
41         assertFalse(callbackTriggered.value);
42 
43         crashTracker.crashDetected();
44         assertFalse(callbackTriggered.value);
45         crashTracker.crashDetected();
46         assertTrue(callbackTriggered.value);  // Last 3 crashes should be within SLIDING_WINDOW
47                                               // time frame.
48 
49     }
50 }
51