diff options
author | Yu Shan Emily Lau <yslau@google.com> | 2009-06-15 21:26:30 -0700 |
---|---|---|
committer | Yu Shan Emily Lau <yslau@google.com> | 2009-06-16 14:12:31 -0700 |
commit | 487f28c139588b69963eb6374228e7e8cf346ca3 (patch) | |
tree | b037d82dbecf62939cc3a7a2838a94f0503bc689 /tests/src/com | |
parent | 2e257ee4a178226f019bb173d78582536cf022d3 (diff) | |
download | packages_apps_LegacyCamera-487f28c139588b69963eb6374228e7e8cf346ca3.zip packages_apps_LegacyCamera-487f28c139588b69963eb6374228e7e8cf346ca3.tar.gz packages_apps_LegacyCamera-487f28c139588b69963eb6374228e7e8cf346ca3.tar.bz2 |
Added the cameraStartup measurement test case.
Modified the ImageCatpure stress test and capture the output to a log file.
Diffstat (limited to 'tests/src/com')
-rwxr-xr-x | tests/src/com/android/camera/StressTests.java | 2 | ||||
-rw-r--r-- | tests/src/com/android/camera/stress/CameraStartUp.java | 108 | ||||
-rwxr-xr-x | tests/src/com/android/camera/stress/ImageCapture.java | 58 |
3 files changed, 160 insertions, 8 deletions
diff --git a/tests/src/com/android/camera/StressTests.java b/tests/src/com/android/camera/StressTests.java index 1d83728..60120a9 100755 --- a/tests/src/com/android/camera/StressTests.java +++ b/tests/src/com/android/camera/StressTests.java @@ -19,6 +19,7 @@ package com.android.camera; import com.android.camera.stress.ImageCapture; import com.android.camera.stress.SwitchPreview; import com.android.camera.stress.CameraLatency; +import com.android.camera.stress.CameraStartUp; import junit.framework.Test; import junit.framework.TestSuite; @@ -39,6 +40,7 @@ public class StressTests extends TestSuite { result.addTestSuite(SwitchPreview.class); result.addTestSuite(ImageCapture.class); result.addTestSuite(CameraLatency.class); + result.addTestSuite(CameraStartUp.class); return result; } } diff --git a/tests/src/com/android/camera/stress/CameraStartUp.java b/tests/src/com/android/camera/stress/CameraStartUp.java new file mode 100644 index 0000000..95bca31 --- /dev/null +++ b/tests/src/com/android/camera/stress/CameraStartUp.java @@ -0,0 +1,108 @@ +package com.android.camera.stress; + +import android.app.Instrumentation; +import android.content.Intent; +import android.os.Debug; +import android.test.InstrumentationTestCase; +import android.test.suitebuilder.annotation.LargeTest; +import android.app.Activity; +import android.util.Log; +import java.io.FileWriter; +import java.io.BufferedWriter; + +/** + * Test cases to measure the camera and video recorder startup time. + */ +public class CameraStartUp extends InstrumentationTestCase { + + private static final int TOTAL_NUMBER_OF_STARTUP = 20; + + private String TAG = "CameraStartUp"; + private static final String CAMERA_TEST_OUTPUT_FILE = "/sdcard/mediaStressOut.txt"; + private static final String CAMERA_PACKAGE_NAME = "com.android.camera"; + private static final String CAMERA_ACTIVITY_NAME = "com.android.camera.Camera"; + private static final String VIDEORECORDER_ACTIVITY_NAME = "com.android.camera.VideoCamera"; + private static int WAIT_TIME_FOR_PREVIEW = 1500; //1.5 second + + private long launchCamera() { + long startupTime = 0; + try { + Intent intent = new Intent(Intent.ACTION_MAIN); + intent.setClassName(CAMERA_PACKAGE_NAME, CAMERA_ACTIVITY_NAME); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + long beforeStart = System.currentTimeMillis(); + Instrumentation inst = getInstrumentation(); + Activity cameraActivity = inst.startActivitySync(intent); + long cameraStarted = System.currentTimeMillis(); + cameraActivity.finish(); + startupTime = cameraStarted - beforeStart; + Thread.sleep(1000); + Log.v(TAG, "camera startup time: " + startupTime); + } catch (Exception e) { + Log.v(TAG, e.toString()); + fail("Fails to get the output file"); + } + return startupTime; + } + + private long launchVideo() { + long startupTime = 0; + + try { + Intent intent = new Intent(Intent.ACTION_MAIN); + intent.setClassName(CAMERA_PACKAGE_NAME, VIDEORECORDER_ACTIVITY_NAME); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + long beforeStart = System.currentTimeMillis(); + Instrumentation inst = getInstrumentation(); + Activity recorderActivity = inst.startActivitySync(intent); + long cameraStarted = System.currentTimeMillis(); + recorderActivity.finish(); + startupTime = cameraStarted - beforeStart; + Log.v(TAG, "Video Startup Time = " + startupTime); + // wait for 1s to make sure it reach a clean stage + Thread.sleep(WAIT_TIME_FOR_PREVIEW); + Log.v(TAG, "video startup time: " + startupTime); + } catch (Exception e) { + Log.v(TAG, e.toString()); + fail("Fails to launch video output file"); + } + return startupTime; + } + + private void writeToOutputFile(String startupTag, long totalStartupTime) throws Exception { + //TODO (yslau) : Need to integrate the output data with central dashboard + try { + FileWriter fstream = null; + fstream = new FileWriter(CAMERA_TEST_OUTPUT_FILE, true); + long averageStartupTime = totalStartupTime / TOTAL_NUMBER_OF_STARTUP; + BufferedWriter out = new BufferedWriter(fstream); + out.write(startupTag + "\n"); + out.write("Number of loop: " + TOTAL_NUMBER_OF_STARTUP + "\n"); + out.write("Average startup time :" + averageStartupTime + " ms\n\n"); + out.close(); + fstream.close(); + } catch (Exception e) { + fail("Camera write output to file"); + } + } + + @LargeTest + public void testLaunchVideo() throws Exception { + long totalStartupTime =0; + for ( int i =0; i< TOTAL_NUMBER_OF_STARTUP; i++){ + totalStartupTime += launchVideo(); + } + Log.v(TAG, "totalStartupTime =" + totalStartupTime); + writeToOutputFile("Video Recorder Startup Time: ", totalStartupTime); + } + + @LargeTest + public void testLaunchCamera() throws Exception { + long totalStartupTime =0; + for ( int i =0; i< TOTAL_NUMBER_OF_STARTUP; i++){ + totalStartupTime += launchCamera(); + } + Log.v(TAG, "totalStartupTime =" + totalStartupTime); + writeToOutputFile("Camera Startup Time: ", totalStartupTime); + } +}
\ No newline at end of file diff --git a/tests/src/com/android/camera/stress/ImageCapture.java b/tests/src/com/android/camera/stress/ImageCapture.java index b809e73..9cb960e 100755 --- a/tests/src/com/android/camera/stress/ImageCapture.java +++ b/tests/src/com/android/camera/stress/ImageCapture.java @@ -23,6 +23,8 @@ import android.test.ActivityInstrumentationTestCase2; import android.test.suitebuilder.annotation.LargeTest; import android.util.Log; import android.view.KeyEvent; +import java.io.FileWriter; +import java.io.BufferedWriter; /** * Junit / Instrumentation test case for camera test @@ -43,6 +45,10 @@ public class ImageCapture extends ActivityInstrumentationTestCase2 <Camera> { private static final long WAIT_FOR_VIDEO_CAPTURE_TO_BE_TAKEN = 50000; //50seconds private static final long WAIT_FOR_PREVIEW = 1000; //1 seconds + private static final String CAMERA_TEST_OUTPUT_FILE = "/sdcard/mediaStressOut.txt"; + private BufferedWriter mOut; + private FileWriter mfstream; + public ImageCapture() { super("com.android.camera", Camera.class); } @@ -50,51 +56,87 @@ public class ImageCapture extends ActivityInstrumentationTestCase2 <Camera> { @Override protected void setUp() throws Exception { getActivity(); + prepareOutputFile(); super.setUp(); } @Override protected void tearDown() throws Exception { + closeOutputFile(); super.tearDown(); } + private void prepareOutputFile(){ + 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); + } + } + @LargeTest public void testImageCapture() { + //TODO(yslau): Need to integrate the outoput with the central dashboard, + //write to a txt file as a temp solution Instrumentation inst = getInstrumentation(); + try { + mOut.write("Video Camera Capture\n"); + mOut.write("No of loops :" + TOTAL_NUMBER_OF_VIDEOCAPTURE + "\n"); + mOut.write("loop: "); + for (int i = 0; i < TOTAL_NUMBER_OF_IMAGECAPTURE; i++) { Thread.sleep(WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN); inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_UP); inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER); Thread.sleep(WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN); + mOut.write(" ," + i); } } catch (Exception e) { Log.v(TAG, e.toString()); + assertTrue("testImageCapture", false); } - assertTrue("testImageCapture", true); + assertTrue("testImageCapture", true); } @LargeTest public void testVideoCapture() { + //TODO(yslau): Need to integrate the output with the central dashboard, + //write to a txt file as a temp solution Instrumentation inst = getInstrumentation(); - //Switch to the video mode - inst.sendKeyDownUpSync(KeyEvent.KEYCODE_MENU); - inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER); + try { + mOut.write("Video Camera Capture\n"); + mOut.write("No of loops :" + TOTAL_NUMBER_OF_VIDEOCAPTURE + "\n"); + mOut.write("loop: "); + // Switch to the video mode + inst.sendKeyDownUpSync(KeyEvent.KEYCODE_MENU); + inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER); + for (int i = 0; i < TOTAL_NUMBER_OF_VIDEOCAPTURE; i++) { Thread.sleep(WAIT_FOR_PREVIEW); - inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_UP); - //record an video + // record a video inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER); Thread.sleep(WAIT_FOR_VIDEO_CAPTURE_TO_BE_TAKEN); inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER); Thread.sleep(WAIT_FOR_PREVIEW); - inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER); + mOut.write(" ," + i); } } catch (Exception e) { Log.v(TAG, e.toString()); + fail("Fails to capture video"); } - assertTrue("testVideoCapture", true); } } |