summaryrefslogtreecommitdiffstats
path: root/media/tests/MediaFrameworkTest
diff options
context:
space:
mode:
authorYu Shan Emily Lau <yslau@google.com>2011-03-21 17:32:17 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-03-21 17:32:17 -0700
commit0210997218fc22b77c71a43a2396419cd0a39166 (patch)
tree5c09f3eab4b4c99eff9d219787311033ba70e254 /media/tests/MediaFrameworkTest
parent7abedd0cdefdcd6d3b62808724e721bb1b92b185 (diff)
parent75afb97c4d46e1c001986faca8a5ee7e68d7b82b (diff)
downloadframeworks_base-0210997218fc22b77c71a43a2396419cd0a39166.zip
frameworks_base-0210997218fc22b77c71a43a2396419cd0a39166.tar.gz
frameworks_base-0210997218fc22b77c71a43a2396419cd0a39166.tar.bz2
Merge "Add the mem logging into test utility. Bug# 4108259" into honeycomb-mr1
Diffstat (limited to 'media/tests/MediaFrameworkTest')
-rwxr-xr-xmedia/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaTestUtil.java135
1 files changed, 68 insertions, 67 deletions
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaTestUtil.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaTestUtil.java
index beb2927..a80fc13 100755
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaTestUtil.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaTestUtil.java
@@ -16,7 +16,10 @@
package com.android.mediaframeworktest;
+import java.io.BufferedWriter;
+import java.io.File;
import java.io.FileOutputStream;
+import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
@@ -31,28 +34,58 @@ import android.util.Log;
*
*/
public class MediaTestUtil {
- private MediaTestUtil(){
- }
private static String TAG = "MediaTestUtil";
- private static final String STORAGE_PATH =
- Environment.getExternalStorageDirectory().toString();
- private static int mMediaStartMemory = 0;
- private static int mDrmStartMemory = 0;
+ private static final String STORAGE_PATH = Environment.getExternalStorageDirectory().toString();
+ private int mStartMemory = 0;
+ private int mStartPid = 0;
+ private Writer mOutput = null;
+ private String mTestName = null;
+ private String mProcessName = null;
+
+ public MediaTestUtil(String memoryOutFileName, String testName, String processName)
+ throws Exception {
+ File memoryOut = new File(memoryOutFileName);
+ mOutput = new BufferedWriter(new FileWriter(memoryOut, true));
+ mProcessName = processName;
+ mTestName = testName;
+ mStartPid = getPid();
+ mStartMemory = getVsize();
+ }
- //Catpure the heapdump for memory leaksage analysis
- public static void getNativeHeapDump (String name) throws Exception {
+ // Catpure the heapdump for memory leaksage analysis
+ public static void getNativeHeapDump(String name) throws Exception {
System.gc();
System.runFinalization();
Thread.sleep(1000);
- FileOutputStream o = new FileOutputStream(STORAGE_PATH + '/' +name + ".dump");
+ FileOutputStream o = new FileOutputStream(STORAGE_PATH + '/' + name + ".dump");
Debug.dumpNativeHeap(o.getFD());
o.close();
}
- public static String captureMemInfo(String type) {
+ private void validateProcessStatus() throws Exception {
+ int currentPid = getPid();
+ //Process crash
+ if (mStartPid != currentPid) {
+ mOutput.write(mProcessName + " died. Test failed\n");
+ }
+ }
+
+ private int getPid() {
+ String memoryUsage = null;
+ int pidvalue = 0;
+ memoryUsage = captureMemInfo();
+ String[] poList2 = memoryUsage.split("\t|\\s+");
+ String pid = poList2[1];
+ pidvalue = Integer.parseInt(pid);
+ Log.v(TAG, "PID = " + pidvalue);
+ return pidvalue;
+ }
+
+ private String captureMemInfo() {
String cm = "ps ";
- cm += type;
+ cm += mProcessName;
+ Log.v(TAG, cm);
String memoryUsage = null;
int ch;
@@ -72,17 +105,8 @@ public class MediaTestUtil {
return memusage;
}
- public static int getMediaServerVsize() {
- String memoryUsage = captureMemInfo("mediaserver");
- String[] poList2 = memoryUsage.split("\t|\\s+");
- String vsize = poList2[3];
- int vsizevalue = Integer.parseInt(vsize);
- Log.v(TAG, "VSIZE = " + vsizevalue);
- return vsizevalue;
- }
-
- public static int getDrmServerVsize() {
- String memoryUsage = captureMemInfo("drmserver");
+ private int getVsize() {
+ String memoryUsage = captureMemInfo();
String[] poList2 = memoryUsage.split("\t|\\s+");
String vsize = poList2[3];
int vsizevalue = Integer.parseInt(vsize);
@@ -90,62 +114,39 @@ public class MediaTestUtil {
return vsizevalue;
}
- // Write the ps mediaserver output to the file
- public static void getMediaServerMemoryLog(Writer output, int writeCount, int totalCount)
- throws Exception {
+ // Write the startup media memory mOutput to the file
+ public void getStartMemoryLog() throws Exception {
String memusage = null;
-
- if (writeCount == 0) {
- mMediaStartMemory = getMediaServerVsize();
- output.write("Start memory : " + mMediaStartMemory + "\n");
- }
- memusage = captureMemInfo("mediaserver");
- output.write(memusage);
+ mStartMemory = getVsize();
+ mOutput.write(mTestName + '\n');
+ mOutput.write("Start memory : " + mStartMemory + "\n");
+ memusage = captureMemInfo();
+ mOutput.write(memusage);
}
- // Write the ps drmserver output to the file
- public static void getDrmServerMemoryLog(Writer output, int writeCount, int totalCount)
- throws Exception {
+ // Write the ps mediaserver mOutput to the file
+ public void getMemoryLog() throws Exception {
String memusage = null;
-
- if (writeCount == 0) {
- mDrmStartMemory = getDrmServerVsize();
- output.write("Start memory : " + mDrmStartMemory + "\n");
- }
- memusage = captureMemInfo("drmserver");
- output.write(memusage);
- }
-
- // Write the ps drmserver output to the file
- public static void getDrmServerMemorySummary(Writer output, String tag) throws Exception {
-
- getTestMemorySummary(output, tag, "drmMem");
- }
-
- // Write the ps drmserver output to the file
- public static void getMediaServerMemorySummary(Writer output, String tag) throws Exception {
-
- getTestMemorySummary(output, tag, "mediaMem");
+ memusage = captureMemInfo();
+ mOutput.write(memusage);
+ mOutput.flush();
}
- public static void getTestMemorySummary(Writer output, String tag, String type)
- throws Exception {
-
+ public void getMemorySummary() throws Exception {
int endMemory = 0;
int memDiff = 0;
- if (type == "mediaMem") {
- endMemory = getMediaServerVsize();
- memDiff = endMemory - mMediaStartMemory;
- } else if (type == "drmMem") {
- endMemory = getDrmServerVsize();
- memDiff = endMemory - mDrmStartMemory;
- }
- output.write("End Memory :" + endMemory + "\n");
+ endMemory = getVsize();
+ memDiff = endMemory - mStartMemory;
+
+ mOutput.write("End Memory :" + endMemory + "\n");
if (memDiff < 0) {
memDiff = 0;
}
- output.write(tag + " total diff = " + memDiff);
- output.write("\n\n");
+ mOutput.write(mTestName + " total diff = " + memDiff);
+ mOutput.write("\n\n");
+ validateProcessStatus();
+ mOutput.flush();
+ mOutput.close();
}
}