1 /* 2 * Copyright (C) 2020 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 17 package android.platform.test.scenario.sample; 18 19 import android.platform.test.microbenchmark.Microbenchmark; 20 import android.platform.test.microbenchmark.Microbenchmark.NoMetricAfter; 21 import android.platform.test.microbenchmark.Microbenchmark.NoMetricBefore; 22 import android.platform.test.option.BooleanOption; 23 import android.util.Log; 24 25 import org.junit.ClassRule; 26 import org.junit.runner.RunWith; 27 28 /** 29 * A test showcasing the order of execution for different components of a microbenchmark. 30 * 31 * <p>Run this test with the listener alongside, {@link PrintListener}, to see how they interact. 32 */ 33 @RunWith(Microbenchmark.class) 34 public class SampleMicrobenchmark extends SampleTest { 35 36 @ClassRule 37 public static BooleanOption failNoMetricBefore = 38 new BooleanOption("fail-no-metric-before").setRequired(false).setDefault(false); 39 40 @ClassRule 41 public static BooleanOption failNoMetricAfter = 42 new BooleanOption("fail-no-metric-after").setRequired(false).setDefault(false); 43 44 @NoMetricBefore noMetricBefore()45 public void noMetricBefore() { 46 SampleTest.failIfRequested(failNoMetricBefore, "@NoMetricBefore"); 47 Log.d(SampleTest.LOG_TAG, "@NoMetricBefore"); 48 } 49 50 @NoMetricAfter noMetricAfter()51 public void noMetricAfter() { 52 SampleTest.failIfRequested(failNoMetricAfter, "@NoMetricAfter"); 53 Log.d(SampleTest.LOG_TAG, "@NoMetricAfter"); 54 } 55 } 56