1 /* 2 * Copyright (C) 2018 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.ahat; 18 19 import com.android.ahat.heapdump.AhatInstance; 20 import com.android.ahat.heapdump.Reachability; 21 import java.io.IOException; 22 import org.junit.Test; 23 import static org.junit.Assert.assertEquals; 24 import static org.junit.Assert.assertNotNull; 25 26 public class RiTest { 27 @Test loadRi()28 public void loadRi() throws IOException { 29 // Verify we can load a heap dump generated from the RI. 30 TestDump.getTestDump("ri-test-dump.hprof", null, null, Reachability.STRONG); 31 } 32 33 @Test finalizable()34 public void finalizable() throws IOException { 35 // Verify we can recognize finalizer references in the RI. 36 TestDump dump = TestDump.getTestDump("ri-test-dump.hprof", null, null, Reachability.STRONG); 37 AhatInstance ref = dump.getDumpedAhatInstance("aWeakRefToFinalizable"); 38 39 // Hopefully the referent hasn't been cleared yet. 40 AhatInstance referent = ref.getReferent(); 41 assertNotNull(referent); 42 assertEquals(Reachability.FINALIZER, referent.getReachability()); 43 } 44 } 45 46