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

Commit a80bf367 authored by Hang Yin's avatar Hang Yin Committed by Android (Google) Code Review
Browse files

Merge "Camera2 framework stress test suite"

parents b0f83b50 6d8fd0a2
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