1 /* 2 * Copyright (C) 2012 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.renderscriptlegacy.cts; 18 19 import android.app.ActivityManager; 20 import android.renderscript.Allocation; 21 import android.renderscript.Element; 22 import android.renderscript.Type; 23 import android.util.Log; 24 import android.content.Context; 25 26 /* 27 // -target-api 11 28 29 #pragma version(1) 30 #pragma rs java_package_name(android.renderscript.cts) 31 32 rs_allocation a; 33 34 void print() { 35 rsDebug("unused", rsGetElementAt_int(a, 0, 0)); 36 } 37 */ 38 39 /** 40 * Test for memory leaks due to missing object slot information. 41 * 42 * The code to generate leak.bc is in the previous comment block. 43 * Note that you need to modify llvm-rs-cc to skip emitting the 44 * .rs.dtor() function, since it will also do the proper cleanup 45 * (but not trigger the original bug). Old HC code can trigger this 46 * bug, since it may have been compiled without .rs.dtor() support. 47 */ 48 public class LeakTest extends RSBaseCompute { 49 private static final String TAG = "LeakTest"; 50 testForLeaks()51 public void testForLeaks() { 52 ActivityManager am = (ActivityManager) getContext().getSystemService("activity"); 53 int mc = am.getLargeMemoryClass() / 32; 54 if (mc < 1) { 55 mc = 1; 56 } 57 int x = mc * 1024 * 1024; 58 59 for (int i = 0; i < 100; i++) { 60 Log.w(TAG, "Leak test iteration " + i); 61 ScriptC_leak leak = new ScriptC_leak(mRS); 62 Type t = new Type.Builder(mRS, Element.I32(mRS)).setX(x).create(); 63 Allocation A = Allocation.createTyped(mRS, t); 64 leak.set_a(A); 65 A = null; 66 //System.gc(); 67 leak.destroy(); 68 mRS.finish(); 69 } 70 mRS.finish(); 71 checkForErrors(); 72 } 73 } 74