diff --git a/playbacktests/src/main/java/com/google/android/exoplayer/playbacktests/gts/DashTest.java b/playbacktests/src/main/java/com/google/android/exoplayer/playbacktests/gts/DashTest.java index 4323e86a9e..f4f7f7eff0 100644 --- a/playbacktests/src/main/java/com/google/android/exoplayer/playbacktests/gts/DashTest.java +++ b/playbacktests/src/main/java/com/google/android/exoplayer/playbacktests/gts/DashTest.java @@ -39,6 +39,7 @@ import com.google.android.exoplayer.playbacktests.util.CodecCountersUtil; import com.google.android.exoplayer.playbacktests.util.ExoHostedTest; import com.google.android.exoplayer.playbacktests.util.HostActivity; import com.google.android.exoplayer.playbacktests.util.LogcatLogger; +import com.google.android.exoplayer.playbacktests.util.MetricsLogger; import com.google.android.exoplayer.playbacktests.util.TestUtil; import com.google.android.exoplayer.upstream.DataSource; import com.google.android.exoplayer.upstream.DefaultAllocator; @@ -48,6 +49,7 @@ import com.google.android.exoplayer.util.Util; import android.annotation.TargetApi; import android.media.MediaCodec; +import android.os.Bundle; import android.os.Handler; import android.test.ActivityInstrumentationTestCase2; import android.util.Log; @@ -162,7 +164,8 @@ public final class DashTest extends ActivityInstrumentationTestCase2 - * Called on the test thread once the test has reported that it's finished and after the test - * has been released. + * Called on the test thread. */ - void assertPassed(); + void onFinished(); } @@ -120,7 +120,7 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba if (hostedTestReleasedCondition.block(timeoutMs)) { if (hostedTestFinished) { Log.d(TAG, "Test finished. Checking pass conditions."); - hostedTest.assertPassed(); + hostedTest.onFinished(); Log.d(TAG, "Pass conditions checked."); } else { Log.e(TAG, "Test released before it finished. Activity may have been paused whilst test " diff --git a/playbacktests/src/main/java/com/google/android/exoplayer/playbacktests/util/LogcatMetricsLogger.java b/playbacktests/src/main/java/com/google/android/exoplayer/playbacktests/util/LogcatMetricsLogger.java new file mode 100644 index 0000000000..07a9524d6c --- /dev/null +++ b/playbacktests/src/main/java/com/google/android/exoplayer/playbacktests/util/LogcatMetricsLogger.java @@ -0,0 +1,41 @@ +/* + * 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. + */ +package com.google.android.exoplayer.playbacktests.util; + +import android.os.Bundle; +import android.util.Log; + +/** + * Implementation of {@link MetricsLogger} that prints the metrics to logcat. + */ +public final class LogcatMetricsLogger implements MetricsLogger { + + private final String tag; + + public LogcatMetricsLogger(String tag) { + this.tag = tag; + } + + @Override + public void logMetrics(Bundle metrics) { + if (metrics != null) { + for (String key : metrics.keySet()) { + Log.v(tag, key + ": " + metrics.get(key).toString()); + } + } + } + +} diff --git a/playbacktests/src/main/java/com/google/android/exoplayer/playbacktests/util/MetricsLogger.java b/playbacktests/src/main/java/com/google/android/exoplayer/playbacktests/util/MetricsLogger.java new file mode 100644 index 0000000000..1fb2635a33 --- /dev/null +++ b/playbacktests/src/main/java/com/google/android/exoplayer/playbacktests/util/MetricsLogger.java @@ -0,0 +1,58 @@ +/* + * 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. + */ +package com.google.android.exoplayer.playbacktests.util; + +import android.app.Instrumentation; +import android.os.Bundle; + +/** + * Metric Logging interface for ExoPlayer playback tests. + */ +public interface MetricsLogger { + + String KEY_FRAMES_DROPPED_COUNT = "Frames Dropped (Count)"; + String KEY_FRAMES_RENDERED_COUNT = "Frames Rendered (Count)"; + String KEY_FRAMES_SKIPPED_COUNT = "Frames Skipped (Count)"; + String KEY_MAX_CONSECUTIVE_FRAMES_DROPPED_COUNT = + "Maximum Consecutive Frames Skipped"; + String KEY_TEST_NAME = "Test Name"; + + /** + * Logs the metrics provided from a test. + * + * @param metrics The {@link Bundle} of metrics to be logged. + */ + void logMetrics(Bundle metrics); + + /** + * A factory for instantiating MetricsLogger instances. + */ + final class Factory { + + private Factory() {} + + /** + * Obtains a new instance of MetricsLogger. + * + * @param instrumentation The test instrumentation. + * @param tag The tag to be used for logcat logs. + */ + public static MetricsLogger createDefault(Instrumentation instrumentation, String tag) { + return new LogcatMetricsLogger(tag); + } + } + +}