1 /* 2 * Copyright (C) 2023 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 android.os.test; 18 19 import android.os.DdmSyncState; 20 import android.os.DdmSyncState.Stage; 21 22 import org.junit.Assert; 23 import org.junit.Test; 24 25 /** 26 * Test DdmSyncState, the Android app stage boot sync system for DDM Client. 27 */ 28 29 public class DdmSyncStateTest { 30 31 @Test testNoCycle()32 public void testNoCycle() { 33 DdmSyncState.reset(); 34 try { 35 DdmSyncState.next(Stage.Attach); 36 DdmSyncState.next(Stage.Bind); 37 DdmSyncState.next(Stage.Named); 38 DdmSyncState.next(Stage.Debugger); 39 DdmSyncState.next(Stage.Running); 40 41 // Cycling back here which is not allowed 42 DdmSyncState.next(Stage.Attach); 43 Assert.fail("Going back to attach should have failed"); 44 } catch (IllegalStateException ignored) { 45 46 } 47 } 48 49 @Test testDebuggerFlow()50 public void testDebuggerFlow() { 51 DdmSyncState.reset(); 52 DdmSyncState.next(Stage.Attach); 53 DdmSyncState.next(Stage.Bind); 54 DdmSyncState.next(Stage.Named); 55 DdmSyncState.next(Stage.Debugger); 56 DdmSyncState.next(Stage.Running); 57 Assert.assertEquals(Stage.Running, DdmSyncState.getStage()); 58 59 } 60 61 @Test testNoDebugFlow()62 public void testNoDebugFlow() { 63 DdmSyncState.reset(); 64 DdmSyncState.next(Stage.Attach); 65 DdmSyncState.next(Stage.Bind); 66 DdmSyncState.next(Stage.Named); 67 // Notice how Stage.Debugger stage is skipped 68 DdmSyncState.next(Stage.Running); 69 Assert.assertEquals(Stage.Running, DdmSyncState.getStage()); 70 } 71 } 72