1 /* 2 * Copyright (C) 2022 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.mediapc.cts.common; 18 19 import android.hardware.camera2.cts.helpers.StaticMetadata; 20 21 import java.util.function.BiPredicate; 22 23 /** 24 * Stores constants used by PerformanceClassEvaluator. Constants relating to requirement number are 25 * stored in order as they appear in the Android CDD. Constants relating to measurements are stored 26 * alphabetically. 27 */ 28 public class RequirementConstants { 29 private static final String TAG = RequirementConstants.class.getSimpleName(); 30 31 public static final String REPORT_LOG_NAME = "MediaPerformanceClassTestCases"; 32 public static final String TN_FIELD_NAME = "test_name"; 33 public static final String PC_FIELD_NAME = "performance_class"; 34 35 public enum Result { 36 NA, MET, UNMET 37 } 38 39 public static final BiPredicate<Long, Long> LONG_INFO = RequirementConstants.info(); 40 public static final BiPredicate<Long, Long> LONG_GT = RequirementConstants.gt(); 41 public static final BiPredicate<Long, Long> LONG_LT = RequirementConstants.lt(); 42 public static final BiPredicate<Long, Long> LONG_GTE = RequirementConstants.gte(); 43 public static final BiPredicate<Long, Long> LONG_LTE = RequirementConstants.lte(); 44 public static final BiPredicate<Long, Long> LONG_EQ = RequirementConstants.eq(); 45 46 public static final BiPredicate<Integer, Integer> INTEGER_INFO = RequirementConstants.info(); 47 public static final BiPredicate<Integer, Integer> INTEGER_GT = RequirementConstants.gt(); 48 public static final BiPredicate<Integer, Integer> INTEGER_LT = RequirementConstants.lt(); 49 public static final BiPredicate<Integer, Integer> INTEGER_GTE = RequirementConstants.gte(); 50 public static final BiPredicate<Integer, Integer> INTEGER_LTE = RequirementConstants.lte(); 51 public static final BiPredicate<Integer, Integer> INTEGER_EQ = RequirementConstants.eq(); 52 public static final BiPredicate<Integer, Integer> INTEGER_CAM_HW_LEVEL_GTE = 53 RequirementConstants.camHwLevelGte(); 54 55 public static final BiPredicate<Double, Double> DOUBLE_INFO = RequirementConstants.info(); 56 public static final BiPredicate<Double, Double> DOUBLE_GT = RequirementConstants.gt(); 57 public static final BiPredicate<Double, Double> DOUBLE_LT = RequirementConstants.lt(); 58 public static final BiPredicate<Double, Double> DOUBLE_GTE = RequirementConstants.gte(); 59 public static final BiPredicate<Double, Double> DOUBLE_LTE = RequirementConstants.lte(); 60 public static final BiPredicate<Double, Double> DOUBLE_EQ = RequirementConstants.eq(); 61 62 public static final BiPredicate<Float, Float> FLOAT_INFO = RequirementConstants.info(); 63 public static final BiPredicate<Float, Float> FLOAT_GT = RequirementConstants.gt(); 64 public static final BiPredicate<Float, Float> FLOAT_LT = RequirementConstants.lt(); 65 public static final BiPredicate<Float, Float> FLOAT_GTE = RequirementConstants.gte(); 66 public static final BiPredicate<Float, Float> FLOAT_LTE = RequirementConstants.lte(); 67 public static final BiPredicate<Float, Float> FLOAT_EQ = RequirementConstants.eq(); 68 69 public static final BiPredicate<Boolean, Boolean> BOOLEAN_EQ = RequirementConstants.eq(); 70 public static final BiPredicate<Boolean, Boolean> BOOLEAN_INFO = RequirementConstants.info(); 71 72 public static final BiPredicate<String, String> STRING_INFO = RequirementConstants.info(); 73 74 /** 75 * Creates a >= predicate. 76 * 77 * This is convenience method to get the types right. 78 */ gte()79 private static <T, S extends Comparable<T>> BiPredicate<S, T> gte() { 80 return new BiPredicate<S, T>() { 81 @Override 82 public boolean test(S actual, T expected) { 83 return actual.compareTo(expected) >= 0; 84 } 85 86 @Override 87 public String toString() { 88 return "Greater than or equal to"; 89 } 90 }; 91 } 92 93 /** 94 * Creates a <= predicate. 95 */ 96 private static <T, S extends Comparable<T>> BiPredicate<S, T> lte() { 97 return new BiPredicate<S, T>() { 98 @Override 99 public boolean test(S actual, T expected) { 100 return actual.compareTo(expected) <= 0; 101 } 102 103 @Override 104 public String toString() { 105 return "Less than or equal to"; 106 } 107 }; 108 } 109 110 /** 111 * Creates an == predicate. 112 */ 113 private static <T, S extends Comparable<T>> BiPredicate<S, T> eq() { 114 return new BiPredicate<S, T>() { 115 @Override 116 public boolean test(S actual, T expected) { 117 return actual.compareTo(expected) == 0; 118 } 119 120 @Override 121 public String toString() { 122 return "Equal to"; 123 } 124 }; 125 } 126 127 /** 128 * Creates a > predicate. 129 */ 130 private static <T, S extends Comparable<T>> BiPredicate<S, T> gt() { 131 return RequirementConstants.<T, S>lte().negate(); 132 } 133 134 /** 135 * Creates a < predicate. 136 */ 137 private static <T, S extends Comparable<T>> BiPredicate<S, T> lt() { 138 return RequirementConstants.<T, S>gte().negate(); 139 } 140 141 /** 142 * Creates a bi predicate that always returns true because the measurements is for info only. 143 */ 144 private static <T> BiPredicate<T, T> info() { 145 return new BiPredicate<T, T>() { 146 @Override 147 public boolean test(T actual, T expected) { 148 return true; 149 } 150 151 @Override 152 public String toString() { 153 return "True. For info only"; 154 } 155 }; 156 } 157 158 /** 159 * Creates a >= predicate for camera hardware level 160 */ 161 private static BiPredicate<Integer, Integer> camHwLevelGte() { 162 return new BiPredicate<Integer, Integer>() { 163 @Override 164 public boolean test(Integer actual, Integer expected) { 165 return StaticMetadata.hardwareLevelPredicate(actual, expected); 166 } 167 168 @Override 169 public String toString() { 170 return "Camera Hardware Level Greater than or equal to"; 171 } 172 }; 173 } 174 175 private RequirementConstants() {} // class should not be instantiated 176 } 177