summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYu Shan Emily Lau <yslau@google.com>2010-12-16 18:34:48 -0800
committerYu Shan Emily Lau <yslau@google.com>2011-01-07 00:49:37 -0800
commitf6069b16aea54fa33976c1ee4bf8654fd4518fc6 (patch)
tree78111b310c2838347a90b8b06e343774922cc6be /tests
parent8c120ca9580660d54a932d91448fb1852599492f (diff)
downloadLegacyCamera-f6069b16aea54fa33976c1ee4bf8654fd4518fc6.zip
LegacyCamera-f6069b16aea54fa33976c1ee4bf8654fd4518fc6.tar.gz
LegacyCamera-f6069b16aea54fa33976c1ee4bf8654fd4518fc6.tar.bz2
Removed the flaky memory checking.
Added the image caputre and video recording stress test for the front facing camera. Change-Id: Ie9b3eebde5665f768bb1e950b8bb593feabb55ff
Diffstat (limited to 'tests')
-rw-r--r--tests/AndroidManifest.xml2
-rwxr-xr-xtests/src/com/android/camera/CameraStressTestRunner.java1
-rwxr-xr-xtests/src/com/android/camera/stress/ImageCapture.java244
-rw-r--r--tests/src/com/android/camera/stress/TestUtil.java57
-rwxr-xr-xtests/src/com/android/camera/stress/VideoCapture.java117
5 files changed, 220 insertions, 201 deletions
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index 7a0e9a8..7513ae2 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -17,6 +17,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.camera.tests">
+ <uses-permission android:name="android.permission.INJECT_EVENTS" />
+
<application>
<uses-library android:name="android.test.runner" />
</application>
diff --git a/tests/src/com/android/camera/CameraStressTestRunner.java b/tests/src/com/android/camera/CameraStressTestRunner.java
index 5c61c9b..5f1c485 100755
--- a/tests/src/com/android/camera/CameraStressTestRunner.java
+++ b/tests/src/com/android/camera/CameraStressTestRunner.java
@@ -34,6 +34,7 @@ public class CameraStressTestRunner extends InstrumentationTestRunner {
public TestSuite getAllTests() {
TestSuite suite = new InstrumentationTestSuite(this);
suite.addTestSuite(ImageCapture.class);
+ suite.addTestSuite(VideoCapture.class);
return suite;
}
diff --git a/tests/src/com/android/camera/stress/ImageCapture.java b/tests/src/com/android/camera/stress/ImageCapture.java
index f376487..328a878 100755
--- a/tests/src/com/android/camera/stress/ImageCapture.java
+++ b/tests/src/com/android/camera/stress/ImageCapture.java
@@ -18,22 +18,16 @@ package com.android.camera.stress;
import com.android.camera.Camera;
import com.android.camera.VideoCamera;
+import com.android.camera.stress.CameraStressTestRunner;
import android.app.Instrumentation;
import android.content.Intent;
-import android.os.Environment;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest;
import android.util.Log;
import android.view.KeyEvent;
+import android.app.Activity;
-import java.io.FileWriter;
-import java.io.Writer;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.BufferedWriter;
-import java.io.IOException;
-import java.io.InputStream;
/**
* Junit / Instrumentation test case for camera test
*
@@ -41,30 +35,21 @@ import java.io.InputStream;
*
* adb shell am instrument \
* -e class com.android.camera.stress.ImageCapture \
- * -w com.android.camera.tests/com.android.camera.CameraStressTestRunner
+ * -w com.google.android.camera.tests/android.test.InstrumentationTestRunner
*
*/
public class ImageCapture extends ActivityInstrumentationTestCase2 <Camera> {
private String TAG = "ImageCapture";
private static final int TOTAL_NUMBER_OF_IMAGECAPTURE = 100;
- private static final int TOTAL_NUMBER_OF_VIDEOCAPTURE = 100;
private static final long WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN = 1500; //1.5 sedconds
- private static final long WAIT_FOR_VIDEO_CAPTURE_TO_BE_TAKEN = 20000; //20seconds
- private static final long WAIT_FOR_PREVIEW = 1500; //1.5 seconds
- private static final long WAIT_FOR_STABLE_STATE = 2000; //2 seconds
- private static final int NO_OF_LOOPS_TAKE_MEMORY_SNAPSHOT = 10;
+ private static final long WAIT_FOR_SWITCH_CAMERA = 3000; //3 seconds
- //the tolerant memory leak
- private static final int MAX_ACCEPTED_MEMORY_LEAK_KB = 150;
+ private TestUtil testUtil = new TestUtil();
- private static int mStartMemory = 0;
- private static int mEndMemory = 0;
- private static int mStartPid = 0;
- private static int mEndPid = 0;
-
- private BufferedWriter mOut;
- private FileWriter mfstream;
+ // Private intent extras.
+ private final static String EXTRAS_CAMERA_FACING =
+ "android.intent.extras.CAMERA_FACING";
public ImageCapture() {
super(Camera.class);
@@ -72,210 +57,67 @@ public class ImageCapture extends ActivityInstrumentationTestCase2 <Camera> {
@Override
protected void setUp() throws Exception {
- getActivity();
- prepareOutputFile();
+ testUtil.prepareOutputFile();
super.setUp();
}
@Override
protected void tearDown() throws Exception {
- closeOutputFile();
+ testUtil.closeOutputFile();
super.tearDown();
}
- private void prepareOutputFile(){
- String camera_test_output_file =
- Environment.getExternalStorageDirectory().toString() + "/mediaStressOut.txt";
- try{
- mfstream = new FileWriter(camera_test_output_file, true);
- mOut = new BufferedWriter(mfstream);
- } catch (Exception e){
- assertTrue("ImageCapture open output",false);
- }
- }
-
- private void closeOutputFile() {
- try {
- mOut.write("\n");
- mOut.close();
- mfstream.close();
- } catch (Exception e) {
- assertTrue("ImageCapture close output", false);
- }
- }
-
- //Write the ps output to the file
- public void getMemoryWriteToLog(Writer output) {
- String memusage = null;
- memusage = captureMediaserverInfo();
- Log.v(TAG, memusage);
- try {
- //Write to file output
- output.write(memusage);
- } catch (Exception e) {
- Log.v(TAG, "Got exception", e);
- }
- }
-
- public String captureMediaserverInfo() {
- String cm = "ps mediaserver";
- String memoryUsage = null;
-
- int ch;
- try {
- Process p = Runtime.getRuntime().exec(cm);
- InputStream in = p.getInputStream();
- StringBuffer sb = new StringBuffer(512);
- while ((ch = in.read()) != -1) {
- sb.append((char) ch);
- }
- memoryUsage = sb.toString();
- } catch (IOException e) {
- Log.v(TAG, "Got exception", e);
- }
- String[] poList = memoryUsage.split("\r|\n|\r\n");
- String memusage = poList[1].concat("\n");
- return memusage;
- }
-
- public int getMediaserverPid(){
- String memoryUsage = null;
- int pidvalue = 0;
- memoryUsage = captureMediaserverInfo();
- String[] poList2 = memoryUsage.split("\t|\\s+");
- String pid = poList2[1];
- pidvalue = Integer.parseInt(pid);
- Log.v(TAG, "PID = " + pidvalue);
- return pidvalue;
- }
-
- public int getMediaserverVsize(){
- String memoryUsage = captureMediaserverInfo();
- String[] poList2 = memoryUsage.split("\t|\\s+");
- String vsize = poList2[3];
- int vsizevalue = Integer.parseInt(vsize);
- Log.v(TAG, "VSIZE = " + vsizevalue);
- return vsizevalue;
- }
-
- public boolean validateMemoryResult (int startPid, int startMemory, Writer output) throws Exception {
- Thread.sleep(20000);
- mEndPid = getMediaserverPid();
- mEndMemory = getMediaserverVsize();
- output.write("Start Memory = " + startMemory + "\n");
- output.write("End Memory = " + mEndMemory + "\n");
- Log.v(TAG, "End memory :" + mEndMemory);
- //Write the total memory different into the output file
- output.write("The total diff = " + (mEndMemory - startMemory));
- output.write("\n\n");
- //mediaserver crash
- if (startPid != mEndPid){
- output.write("mediaserver died. Test failed\n");
- return false;
- }
- //memory leak greter than the tolerant
- if ((mEndMemory - startMemory) > MAX_ACCEPTED_MEMORY_LEAK_KB )
- return false;
- return true;
- }
-
- @LargeTest
- public void testImageCapture() {
+ public void captureImages(String reportTag, Instrumentation inst) {
int total_num_of_images = CameraStressTestRunner.mImageIterations;
+ Log.v(TAG, "no of images = " + total_num_of_images);
//TODO(yslau): Need to integrate the outoput with the central dashboard,
//write to a txt file as a temp solution
- String camera_mem_out =
- Environment.getExternalStorageDirectory().toString() + "/ImageCaptureMemOut.txt";
boolean memoryResult = false;
- Instrumentation inst = getInstrumentation();
- File imageCaptureMemFile = new File(camera_mem_out);
-
- mStartPid = getMediaserverPid();
- mStartMemory = getMediaserverVsize();
- Log.v(TAG, "start memory : " + mStartMemory);
+ KeyEvent focusEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_FOCUS);
try {
- Writer output = new BufferedWriter(new FileWriter(imageCaptureMemFile, true));
- output.write("Camera Image capture\n");
- output.write("No of loops : " + total_num_of_images + "\n");
- getMemoryWriteToLog(output);
-
- mOut.write("Camera Image Capture\n");
- mOut.write("No of loops :" + total_num_of_images + "\n");
- mOut.write("loop: ");
- //Move the foucs to the image capture button
- inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
+ testUtil.writeReportHeader(reportTag, total_num_of_images);
for (int i = 0; i < total_num_of_images; i++) {
Thread.sleep(WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN);
- inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
+ inst.sendKeySync(focusEvent);
+ inst.sendCharacterSync(KeyEvent.KEYCODE_CAMERA);
Thread.sleep(WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN);
- if (( i % NO_OF_LOOPS_TAKE_MEMORY_SNAPSHOT) == 0){
- Log.v(TAG, "value of i :" + i);
- getMemoryWriteToLog(output);
- }
- mOut.write(" ," + i);
- mOut.flush();
+ testUtil.writeResult(i);
}
- Thread.sleep(WAIT_FOR_STABLE_STATE);
- memoryResult = validateMemoryResult(mStartPid, mStartMemory, output);
- Log.v(TAG, "End memory : " + getMediaserverVsize());
- output.close();
- assertTrue("Camera image capture memory test", memoryResult);
} catch (Exception e) {
- Log.v(TAG, "Got exception", e);
+ Log.v(TAG, "Got exception: " + e.toString());
assertTrue("testImageCapture", false);
}
}
@LargeTest
- public void testVideoCapture() {
- //TODO(yslau): Need to integrate the output with the central dashboard,
- //write to a txt file as a temp solution
- String camera_mem_out =
- Environment.getExternalStorageDirectory().toString() + "/ImageCaptureMemOut.txt";
- boolean memoryResult = false;
- int total_num_of_videos = CameraStressTestRunner.mVideoIterations;
- int video_duration = CameraStressTestRunner.mVideoDuration;
-
+ public void testBackImageCapture() throws Exception {
Instrumentation inst = getInstrumentation();
- File imageCaptureMemFile = new File(camera_mem_out);
- mStartPid = getMediaserverPid();
- mStartMemory = getMediaserverVsize();
- Log.v(TAG, "start memory : " + mStartMemory);
-
- try {
- Writer output = new BufferedWriter(new FileWriter(imageCaptureMemFile, true));
- output.write("Camera Video capture\n");
- output.write("No of loops : " + total_num_of_videos + "\n");
- getMemoryWriteToLog(output);
- mOut.write("Camera Video Capture\n");
- mOut.write("No of loops :" + total_num_of_videos + "\n");
- mOut.write("loop: ");
- // Switch to the video mode
- Intent intent = new Intent();
- intent.setClass(getInstrumentation().getTargetContext(),
- VideoCamera.class);
- getActivity().startActivity(intent);
- for (int i = 0; i < total_num_of_videos; i++) {
- Thread.sleep(WAIT_FOR_PREVIEW);
- // record a video
- inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
- Thread.sleep(video_duration);
- inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
- Thread.sleep(WAIT_FOR_PREVIEW);
- mOut.write(" ," + i);
- mOut.flush();
- }
- Thread.sleep(WAIT_FOR_STABLE_STATE);
- memoryResult = validateMemoryResult(mStartPid, mStartMemory, output);
- Log.v(TAG, "End memory : " + getMediaserverVsize());
- output.close();
- assertTrue("Camera video capture memory test", memoryResult);
- } catch (Exception e) {
- Log.v(TAG, "Got exception", e);
- fail("Fails to capture video");
- }
+ Intent intent = new Intent();
+
+ intent.setClass(getInstrumentation().getTargetContext(), Camera.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.putExtra(EXTRAS_CAMERA_FACING,
+ android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK);
+ Activity act = inst.startActivitySync(intent);
+ Thread.sleep(WAIT_FOR_SWITCH_CAMERA);
+ captureImages("Back Camera Image Capture\n", inst);
+ act.finish();
}
+ @LargeTest
+ public void testFrontImageCapture() throws Exception {
+ Instrumentation inst = getInstrumentation();
+ Intent intent = new Intent();
+
+ intent.setClass(getInstrumentation().getTargetContext(), Camera.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.putExtra(EXTRAS_CAMERA_FACING,
+ android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);
+ Activity act = inst.startActivitySync(intent);
+ Thread.sleep(WAIT_FOR_SWITCH_CAMERA);
+ captureImages("Front Camera Image Capture\n", inst);
+ act.finish();
+ }
}
diff --git a/tests/src/com/android/camera/stress/TestUtil.java b/tests/src/com/android/camera/stress/TestUtil.java
new file mode 100644
index 0000000..64e2039
--- /dev/null
+++ b/tests/src/com/android/camera/stress/TestUtil.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.camera.stress;
+
+import android.os.Environment;
+import java.io.FileWriter;
+import java.io.BufferedWriter;
+
+
+/**
+ * Collection of utility functions used for the test.
+ */
+public class TestUtil {
+ public BufferedWriter mOut;
+ public FileWriter mfstream;
+
+ public TestUtil() {
+ }
+
+ public void prepareOutputFile() throws Exception {
+ String camera_test_output_file =
+ Environment.getExternalStorageDirectory().toString() + "/mediaStressOut.txt";
+ mfstream = new FileWriter(camera_test_output_file, true);
+ mOut = new BufferedWriter(mfstream);
+ }
+
+ public void closeOutputFile() throws Exception {
+ mOut.write("\n");
+ mOut.close();
+ mfstream.close();
+ }
+
+ public void writeReportHeader(String reportTag, int iteration) throws Exception {
+ mOut.write(reportTag);
+ mOut.write("No of loops :" + iteration + "\n");
+ mOut.write("loop: ");
+ }
+
+ public void writeResult(int iteration) throws Exception {
+ mOut.write(" ," + iteration);
+ mOut.flush();
+ }
+}
diff --git a/tests/src/com/android/camera/stress/VideoCapture.java b/tests/src/com/android/camera/stress/VideoCapture.java
new file mode 100755
index 0000000..d0c4a10
--- /dev/null
+++ b/tests/src/com/android/camera/stress/VideoCapture.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.camera.stress;
+
+import com.android.camera.Camera;
+import com.android.camera.VideoCamera;
+import com.android.camera.stress.TestUtil;
+
+import android.app.Activity;
+import android.app.Instrumentation;
+import android.content.Intent;
+import android.test.ActivityInstrumentationTestCase2;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.util.Log;
+import android.view.KeyEvent;
+
+import com.android.camera.stress.ImageCapture;
+import com.android.camera.stress.CameraStressTestRunner;
+/**
+ * Junit / Instrumentation test case for camera test
+ *
+ * Running the test suite:
+ *
+ * adb shell am instrument \
+ * -e class com.android.camera.stress.VideoCapture \
+ * -w com.google.android.camera.tests/android.test.InstrumentationTestRunner
+ *
+ */
+
+public class VideoCapture extends ActivityInstrumentationTestCase2 <VideoCamera> {
+ private String TAG = "VideoCapture";
+ private static final long WAIT_FOR_PREVIEW = 1500; //1.5 seconds
+ private static final long WAIT_FOR_SWITCH_CAMERA = 3000; //2 seconds
+
+ // Private intent extras which control the camera facing.
+ private final static String EXTRAS_CAMERA_FACING =
+ "android.intent.extras.CAMERA_FACING";
+
+ private TestUtil testUtil = new TestUtil();
+
+ public VideoCapture() {
+ super(VideoCamera.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ testUtil.prepareOutputFile();
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ testUtil.closeOutputFile();
+ super.tearDown();
+ }
+
+ @LargeTest
+ public void captureVideos(String reportTag, Instrumentation inst) throws Exception{
+ boolean memoryResult = false;
+ int total_num_of_videos = CameraStressTestRunner.mVideoIterations;
+ int video_duration = CameraStressTestRunner.mVideoDuration;
+ testUtil.writeReportHeader(reportTag, total_num_of_videos);
+
+ for (int i = 0; i < total_num_of_videos; i++) {
+ Thread.sleep(WAIT_FOR_PREVIEW);
+ // record a video
+ inst.sendCharacterSync(KeyEvent.KEYCODE_CAMERA);
+ Thread.sleep(video_duration);
+ inst.sendCharacterSync(KeyEvent.KEYCODE_CAMERA);
+ testUtil.writeResult(i);
+ }
+ }
+
+ @LargeTest
+ public void testBackVideoCapture() throws Exception {
+ Instrumentation inst = getInstrumentation();
+ Intent intent = new Intent();
+
+ intent.setClass(getInstrumentation().getTargetContext(), VideoCamera.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.putExtra(EXTRAS_CAMERA_FACING,
+ android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK);
+ Activity act = inst.startActivitySync(intent);
+ Thread.sleep(WAIT_FOR_SWITCH_CAMERA);
+ captureVideos("Back Camera Video Capture\n", inst);
+ act.finish();
+ }
+
+ @LargeTest
+ public void testFrontVideoCapture() throws Exception {
+ Instrumentation inst = getInstrumentation();
+ Intent intent = new Intent();
+
+ intent.setClass(getInstrumentation().getTargetContext(), VideoCamera.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.putExtra(EXTRAS_CAMERA_FACING,
+ android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);
+ Activity act = inst.startActivitySync(intent);
+ Thread.sleep(WAIT_FOR_SWITCH_CAMERA);
+ captureVideos("Front Camera Video Capture\n", inst);
+ act.finish();
+ }
+}