Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6d8fd0a2 authored by Hyungtae Tim Kim's avatar Hyungtae Tim Kim Committed by Hang Yin
Browse files

Camera2 framework stress test suite

Added a new Camera2 framework stress test to put stress in
the common use cases in exercising Camera2 APIs.

Note that this stress test differs from Camera CTS in that
it focus on ensuring stability rather than functionality.
It could also provide the flexibility to get integrated with
test tools if needed.

For the initial run, most test codes are taken from CTS package
except for test fixtures to handle arguments and results for
stress test. However test implementation could be differentiated
to meet needs in stress testing over time.

Change-Id: Ie36594de3904e41f6175b8d5072b91941975d091
parent 369a94a4
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -7,7 +7,11 @@ LOCAL_SRC_FILES := $(call all-subdir-java-files)

LOCAL_JAVA_LIBRARIES := android.test.runner

LOCAL_STATIC_JAVA_LIBRARIES := easymocklib mockito-target core-tests android-support-test
LOCAL_STATIC_JAVA_LIBRARIES := easymocklib \
    mockito-target \
    core-tests \
    android-support-test \
    android-ex-camera2

LOCAL_PACKAGE_NAME := mediaframeworktest

+47 −36
Original line number Diff line number Diff line
@@ -34,6 +34,11 @@
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:label="Camera2CtsActivity"
                android:name="Camera2SurfaceViewActivity"
                android:screenOrientation="landscape"
                android:configChanges="keyboardHidden|orientation|screenSize">
        </activity>
    </application>

    <instrumentation android:name=".CameraStressTestRunner"
@@ -41,6 +46,11 @@
            android:label="Camera stress tests InstrumentationRunner">
    </instrumentation>

    <instrumentation android:name=".Camera2InstrumentationTestRunner"
            android:targetPackage="com.android.mediaframeworktest"
            android:label="Camera2 InstrumentationTestRunner">
    </instrumentation>

    <instrumentation android:name=".MediaFrameworkTestRunner"
            android:targetPackage="com.android.mediaframeworktest"
            android:label="MediaFramework tests InstrumentationRunner">
@@ -78,6 +88,7 @@

    <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
            android:targetPackage="com.android.mediaframeworktest"
         android:label="media framework tests"/>
            android:label="media framework tests">
    </instrumentation>

</manifest>
+28 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<!--
     Copyright (C) 2014 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.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <SurfaceView
        android:id="@+id/surface_view"
        android:layout_width="320dp"
        android:layout_height="240dp"/>

</LinearLayout>
+50 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 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.mediaframeworktest;

import com.android.mediaframeworktest.stress.Camera2CaptureRequestTest;
import com.android.mediaframeworktest.stress.Camera2RecordingTest;
import com.android.mediaframeworktest.stress.Camera2ReprocessCaptureTest;
import com.android.mediaframeworktest.stress.Camera2StillCaptureTest;

import junit.framework.TestSuite;

import android.test.InstrumentationTestRunner;
import android.test.InstrumentationTestSuite;

/**
 * This is Camera2 framework test runner to execute the specified test classes if no target class
 * is defined in the meta-data or command line argument parameters.
 */
public class Camera2InstrumentationTestRunner extends InstrumentationTestRunner {

    @Override
    public TestSuite getAllTests() {
        TestSuite suite = new InstrumentationTestSuite(this);
        // Note the following test cases are compatible with Camera API2
        suite.addTestSuite(Camera2StillCaptureTest.class);
        suite.addTestSuite(Camera2RecordingTest.class);
        suite.addTestSuite(Camera2ReprocessCaptureTest.class);
        suite.addTestSuite(Camera2CaptureRequestTest.class);
        return suite;
    }

    @Override
    public ClassLoader getLoader() {
        return Camera2InstrumentationTestRunner.class.getClassLoader();
    }
}
+114 −0
Original line number Diff line number Diff line
/*
 * Copyright 2016 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.mediaframeworktest;

import android.app.Activity;
import android.os.Bundle;
import android.os.ConditionVariable;
import android.os.SystemClock;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.WindowManager;

/**
 * (non-Javadoc)
 * @see android.hardware.camera2.cts.Camera2SurfaceViewCtsActivity
 */
public class Camera2SurfaceViewActivity extends Activity implements SurfaceHolder.Callback {
    private static final String TAG = "SurfaceViewActivity";
    private final ConditionVariable surfaceChangedDone = new ConditionVariable();

    private SurfaceView mSurfaceView;
    private int currentWidth = 0;
    private int currentHeight = 0;
    private final Object sizeLock = new Object();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.surface_view_2);
        mSurfaceView = (SurfaceView) findViewById(R.id.surface_view);
        mSurfaceView.getHolder().addCallback(this);

        //Acquire the full wake lock to keep the device up
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }

    public SurfaceView getSurfaceView() {
        return mSurfaceView;
    }

    public boolean waitForSurfaceSizeChanged(int timeOutMs, int expectWidth, int expectHeight) {
        if (timeOutMs <= 0 || expectWidth <= 0 || expectHeight <= 0) {
            throw new IllegalArgumentException(
                    String.format(
                            "timeout(%d), expectWidth(%d), and expectHeight(%d) " +
                            "should all be positive numbers",
                            timeOutMs, expectWidth, expectHeight));
        }

        synchronized(sizeLock) {
            if (expectWidth == currentWidth && expectHeight == currentHeight) {
                return true;
            }
        }

        int waitTimeMs = timeOutMs;
        boolean changeSucceeded = false;
        while (!changeSucceeded && waitTimeMs > 0) {
            long startTimeMs = SystemClock.elapsedRealtime();
            changeSucceeded = surfaceChangedDone.block(waitTimeMs);
            if (!changeSucceeded) {
                Log.e(TAG, "Wait for surface change timed out after " + timeOutMs + " ms");
                return changeSucceeded;
            } else {
                // Get a surface change callback, need to check if the size is expected.
                surfaceChangedDone.close();
                if (currentWidth == expectWidth && currentHeight == expectHeight) {
                    return changeSucceeded;
                }
                // Do a further iteration surface change check as surfaceChanged could be called
                // again.
                changeSucceeded = false;
            }
            waitTimeMs -= (SystemClock.elapsedRealtime() - startTimeMs);
        }

        // Couldn't get expected surface size change.
        return false;
     }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        Log.i(TAG, "Surface Changed to: " + width + "x" + height);
        synchronized (sizeLock) {
            currentWidth = width;
            currentHeight = height;
        }
        surfaceChangedDone.open();
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
    }
}
Loading