blob: f631878c6fe2f4e4f121e90ab766bb1e3b6a64c6 [file] [log] [blame]
Kuan-Tung Panfbd59a02017-08-02 19:50:04 +00001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.media.tests;
18
Kuan-Tung Panfbd59a02017-08-02 19:50:04 +000019import com.android.tradefed.config.OptionClass;
20import com.android.tradefed.device.DeviceNotAvailableException;
21import com.android.tradefed.log.LogUtil.CLog;
22import com.android.tradefed.result.ITestInvocationListener;
jdesprez607ef1a2018-02-07 16:34:53 -080023import com.android.tradefed.result.TestDescription;
Kuan-Tung Panfbd59a02017-08-02 19:50:04 +000024
25import java.util.HashMap;
26import java.util.Map;
27import java.util.regex.Matcher;
28import java.util.regex.Pattern;
29
30/**
31 * Camera shot latency test
32 *
33 * Runs Camera device performance test to measure time from taking a shot to saving a file on disk
34 * and time from shutter to shutter in fully saturated case.
35 */
36@OptionClass(alias = "camera-shot-latency")
37public class CameraShotLatencyTest extends CameraTestBase {
38
39 private static final Pattern STATS_REGEX = Pattern.compile(
40 "^(?<average>[0-9.]+)\\|(?<values>[0-9 .-]+)");
41
42 public CameraShotLatencyTest() {
43 setTestPackage("com.google.android.camera");
44 setTestClass("com.android.camera.latency.CameraShotLatencyTest");
45 setTestRunner("android.test.InstrumentationTestRunner");
46 setRuKey("CameraShotLatency");
47 setTestTimeoutMs(60 * 60 * 1000); // 1 hour
48 }
49
50 /**
51 * {@inheritDoc}
52 */
53 @Override
54 public void run(ITestInvocationListener listener) throws DeviceNotAvailableException {
55 runInstrumentationTest(listener, new CollectingListener(listener));
56 }
57
58 /**
59 * A listener to collect the output from test run and fatal errors
60 */
61 private class CollectingListener extends DefaultCollectingListener {
62
63 public CollectingListener(ITestInvocationListener listener) {
64 super(listener);
65 }
66
67 @Override
jdesprez607ef1a2018-02-07 16:34:53 -080068 public void handleMetricsOnTestEnded(TestDescription test, Map<String, String> testMetrics) {
Kuan-Tung Panfbd59a02017-08-02 19:50:04 +000069 // Test metrics accumulated will be posted at the end of test run.
70 getAggregatedMetrics().putAll(parseResults(test.getTestName(), testMetrics));
71 }
72
73 public Map<String, String> parseResults(String testName, Map<String, String> testMetrics) {
74 // Parse shot latency stats from the instrumentation result.
75 // Format : <metric_key>=<average_of_latency>|<raw_data>
76 // Example:
77 // ElapsedTimeMs=1805|1725 1747 ... 2078
78 Map<String, String> parsed = new HashMap<String, String>();
79 for (Map.Entry<String, String> metric : testMetrics.entrySet()) {
80 Matcher matcher = STATS_REGEX.matcher(metric.getValue());
81 if (matcher.matches()) {
82 // Key name consists of a pair of test name and metric name.
83 String keyName = String.format("%s_%s", testName, metric.getKey());
84 parsed.put(keyName, matcher.group("average"));
85 } else {
86 CLog.w(String.format("Stats not in correct format: %s", metric.getValue()));
87 }
88 }
89 return parsed;
90 }
91 }
92}