1{{- /* 2 * CompMethod generates comparison method constant from a RequiredMeasurement 3 */}} 4{{- define "CompMethod" -}} 5 {{- $c :=.GetComparison }} 6 {{- $mt :=.GetMeasurementType }} 7 {{- if eq $mt.String "MEASUREMENT_TYPE_BOOL" -}}BOOLEAN 8 {{- else if eq $mt.String "MEASUREMENT_TYPE_DOUBLE" -}}DOUBLE 9 {{- else if eq $mt.String "MEASUREMENT_TYPE_INT" -}}INTEGER 10 {{- else if eq $mt.String "MEASUREMENT_TYPE_STRING" -}}STRING 11 {{- else if eq $mt.String "MEASUREMENT_TYPE_LONG" -}}LONG 12 {{- else if eq $mt.String "MEASUREMENT_TYPE_FLOAT" -}}FLOAT 13 {{- else }}{{$mt}} 14 {{- end }}_ 15 {{- if eq $c.String "COMPARISON_EQUAL" -}}EQ 16 {{- else if eq $c.String "COMPARISON_LESS_THAN" -}}LT 17 {{- else if eq $c.String "COMPARISON_LESS_THAN_OR_EQUAL" -}}LTE 18 {{- else if eq $c.String "COMPARISON_GREATER_THAN" -}}GT 19 {{- else if eq $c.String "COMPARISON_GREATER_THAN_OR_EQUAL" -}}GTE 20 {{- else if eq $c.String "COMPARISON_INFO_ONLY" -}}INFO 21 {{- else if eq $c.String "COMPARISON_CONFIG" -}}INFO 22 {{- else if eq $c.String "COMPARISON_CAMERA_HARDWARE_LEVEL_GREATER_THAN_OR_EQUAL" -}}CAM_HW_LEVEL_GTE 23 {{- else }}{{$c}} 24 {{- end }} 25{{- end -}} 26 27 28{{- /* 29 * JavaClass generates Java class name from a MeasurementType 30 */}} 31{{- define "JavaClass" -}} 32 {{- if eq .String "MEASUREMENT_TYPE_BOOL" -}}Boolean 33 {{- else if eq .String "MEASUREMENT_TYPE_DOUBLE" -}}Double 34 {{- else if eq .String "MEASUREMENT_TYPE_INT" -}}Integer 35 {{- else if eq .String "MEASUREMENT_TYPE_STRING" -}}String 36 {{- else if eq .String "MEASUREMENT_TYPE_LONG" -}}Long 37 {{- else if eq .String "MEASUREMENT_TYPE_FLOAT" -}}Float 38 {{- else }}{{.}} 39 {{- end }} 40{{- end -}} 41 42{{- /* 43 * JavaClass generates Java type from a MeasurementType 44 */}} 45{{- define "JavaType" -}} 46 {{- if eq .String "MEASUREMENT_TYPE_BOOL" -}}boolean 47 {{- else if eq .String "MEASUREMENT_TYPE_DOUBLE" -}}double 48 {{- else if eq .String "MEASUREMENT_TYPE_INT" -}}int 49 {{- else if eq .String "MEASUREMENT_TYPE_STRING" -}}String 50 {{- else if eq .String "MEASUREMENT_TYPE_LONG" -}}long 51 {{- else if eq .String "MEASUREMENT_TYPE_FLOAT" -}}float 52 {{- else }}{{.}} 53 {{- end }} 54{{- end -}} 55 56{{- /* 57 * VersionCode generates the android.Build VersionCode constant from an mpc value. 58 * It is an error if the mpc value listed here. 59 */}} 60{{- define "VersionCode" -}} 61 VERSION_CODES. 62 {{- if eq . 30}}R 63 {{- else if eq . 31}}S 64 {{- else if eq . 33}}TIRAMISU 65 {{- else if eq . 34}}UPSIDE_DOWN_CAKE 66 {{- else if eq . 35}}VANILLA_ICE_CREAM 67 {{- else }}{{.}} 68 {{- end }} 69{{- end -}} 70 71 72{{- /* 73 * MeasurementValue gets value from RequiredValue base on the MeasurementType 74 * It is an error if the MeasurementType is not listed here. 75 */}} 76{{- define "MeasurementValue" -}} 77 {{- if eq .MeasurementType.String "MEASUREMENT_TYPE_BOOL" -}}{{.RequiredValue.GetBoolValue}} 78 {{- else if eq .MeasurementType.String "MEASUREMENT_TYPE_DOUBLE" -}}{{printf "%f" .RequiredValue.GetDoubleValue}} 79 {{- else if eq .MeasurementType.String "MEASUREMENT_TYPE_INT" -}}{{.RequiredValue.GetIntValue}} 80 {{- else if eq .MeasurementType.String "MEASUREMENT_TYPE_STRING" -}}"{{.RequiredValue.GetStringValue}}" 81 {{- else if eq .MeasurementType.String "MEASUREMENT_TYPE_LONG" -}}{{.RequiredValue.GetLongValue}}L 82 {{- else if eq .MeasurementType.String "MEASUREMENT_TYPE_FLOAT" -}}{{printf "%f" .RequiredValue.GetFloatValue}}f 83 {{- else }}{{.MeasurementType}} 84 {{- end }} 85{{- end -}} 86 87/* 88 * Copyright (C) 2024 The Android Open Source Project 89 * 90 * Licensed under the Apache License, Version 2.0 (the "License"); 91 * you may not use this file except in compliance with the License. 92 * You may obtain a copy of the License at 93 * 94 * http://www.apache.org/licenses/LICENSE-2.0 95 * 96 * Unless required by applicable law or agreed to in writing, software 97 * distributed under the License is distributed on an "AS IS" BASIS, 98 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 99 * See the License for the specific language governing permissions and 100 * limitations under the License. 101 */ 102 103package android.mediapc.cts.common; 104 105import android.os.Build.VERSION_CODES; 106 107/** 108 * Requirements Classes. 109 */ 110public final class Requirements { 111 112{{- range $r := .ReqList.GetRequirements }} 113{{- if $r.GetName }} 114 115 /** 116 * Add a new {{UpperCamelCase $r.GetName}}Requirement for requirement {{ $r.GetId }} to a 117 * {@code PerformanceClassEvaluator} instance. 118 {{- with $r.GetDescription}} 119 * 120 * {{.}}{{end}} 121 */ 122 public static {{UpperCamelCase $r.GetName}}Requirement.With add{{ SafeReqID $r.GetId | UpperCase}}() { 123 return new {{UpperCamelCase $r.GetName}}Requirement.With(); 124 } 125 126 /** 127 * {{ $r.GetId }} {{$r.GetName}} 128 {{- with $r.GetDescription}} 129 * 130 * {{.}}{{end}} 131 */ 132 public static final class {{UpperCamelCase $r.GetName}}Requirement extends Requirement { 133 134 public static final class With { 135 private With() {} 136 {{- range $t_id, $t := $r.GetTestConfigs }} 137 {{- if ne $t_id "" }} 138 public static final class Config{{ SafeTestConfigID $t_id | UpperCamelCase}} { 139 private Config{{ SafeTestConfigID $t_id | UpperCamelCase}}() {} 140 public {{UpperCamelCase $r.GetName}}Requirement to(PerformanceClassEvaluator pce) { 141 return pce.addRequirement({{UpperCamelCase $r.GetName}}Requirement.create 142 {{- SafeTestConfigID $t_id | UpperCamelCase}}()); 143 } 144 {{- range $v_id, $v := $r.GetVariants }} 145 {{- if HasConfigVariant $r $t_id $v_id }} 146 public Config{{ SafeTestConfigID $t_id | UpperCamelCase}}AndVariant 147 {{- UpperCamelCase $v_id}} withVariant{{- UpperCamelCase $v_id}}() { 148 return new Config{{SafeTestConfigID $t_id | UpperCamelCase}}AndVariant 149 {{- UpperCamelCase $v_id}}(); 150 } 151 {{- end }}{{/* if HasConfigVariant */}} 152 {{- end }}{{/* range $v_id, $v */}} 153 } 154 {{- end }} 155 {{- end }}{{/* range $t_id, $t */}} 156 157 {{- range $v_id, $v := $r.GetVariants }} 158 public static final class Variant{{UpperCamelCase $v_id}} { 159 private Variant{{UpperCamelCase $v_id}}() {} 160 {{- range $t_id, $t := $r.GetTestConfigs }} 161 {{- if HasConfigVariant $r $t_id $v_id }} 162 {{- if eq $t_id "" }} 163 public {{UpperCamelCase $r.GetName}}Requirement to(PerformanceClassEvaluator pce) { 164 return pce.addRequirement({{UpperCamelCase $r.GetName}}Requirement.create 165 {{- UpperCamelCase $v_id}}()); 166 } 167 {{- else }} 168 public Config{{ SafeTestConfigID $t_id | UpperCamelCase}}AndVariant 169 {{- UpperCamelCase $v_id}} withConfig 170 {{- SafeTestConfigID $t_id | UpperCamelCase}}() { 171 return new Config{{SafeTestConfigID $t_id | UpperCamelCase}}AndVariant 172 {{- UpperCamelCase $v_id}}(); 173 } 174 {{- end }} 175 {{- end }}{{/* if HasConfigVariant */}} 176 {{- end }}{{/* range $t_id, $t */}} 177 } 178 {{- end }}{{/* range $v_id, $v */}} 179 180 {{- range $t_id, $t := $r.GetTestConfigs }} 181 {{- if ne $t_id "" }} 182 {{- range $v_id, $v := $r.GetVariants }} 183 {{- if HasConfigVariant $r $t_id $v_id }} 184 public static final class Config{{SafeTestConfigID $t_id | UpperCamelCase}}AndVariant 185 {{- UpperCamelCase $v_id}} { 186 private Config{{ SafeTestConfigID $t_id | UpperCamelCase}}AndVariant 187 {{- UpperCamelCase $v_id}}() {} 188 public {{UpperCamelCase $r.GetName}}Requirement to(PerformanceClassEvaluator pce) { 189 return pce.addRequirement({{UpperCamelCase $r.GetName}}Requirement.create 190 {{- SafeTestConfigID $t_id | UpperCamelCase}} 191 {{- UpperCamelCase $v_id}}()); 192 } 193 } 194 {{- end }}{{/* if HasConfigVariant */}} 195 {{- end }}{{/* range $v_id, $v */}} 196 {{- end }} 197 {{- end }}{{/* range $t_id, $t */}} 198 199 {{- range $t_id, $t := $r.GetTestConfigs }} 200 {{- if eq $t_id "" }} 201 public {{UpperCamelCase $r.GetName}}Requirement to(PerformanceClassEvaluator pce) { 202 return pce.addRequirement({{UpperCamelCase $r.GetName}}Requirement.create()); 203 } 204 {{- else }} 205 public Config{{ SafeTestConfigID $t_id | UpperCamelCase}} withConfig 206 {{- SafeTestConfigID $t_id | UpperCamelCase}}() { 207 return new Config{{ SafeTestConfigID $t_id | UpperCamelCase}}(); 208 } 209 {{- end }} 210 {{- end }}{{/* range $t_id, $t */}} 211 212 {{- range $v_id, $v := $r.GetVariants }} 213 public Variant{{UpperCamelCase $v_id}} withVariant{{UpperCamelCase $v_id}}() { 214 return new Variant{{UpperCamelCase $v_id}}(); 215 } 216 {{- end }}{{/* range $v_id, $v */}} 217 } 218 219 220 {{- range $t_id, $t := $r.GetTestConfigs }} 221 222 /** 223 * {{ $r.GetId }} {{$r.GetName}} 224 {{- with $r.GetDescription}} 225 * 226 * {{.}}{{end}} 227 */ 228 private static {{UpperCamelCase $r.GetName}}Requirement create 229 {{- SafeTestConfigID $t_id | UpperCamelCase}}() { 230 {{- range $m_id, $m := $r.GetMeasurements }} 231 {{- $mt := $m.GetMeasurementType}} 232 {{- $c := $m.GetComparison}} 233 var {{LowerCamelCase $m_id}} = 234 RequiredMeasurement.<{{template "JavaClass" $mt}}>builder() 235 .setId("{{$m_id}}") 236 .setPredicate(RequirementConstants.{{template "CompMethod" $m}}) 237 {{- range $mpc, $s := $r.GetSpecs }} 238 {{- if eq $s.GetTestConfigId $t_id }} 239 {{- with index $s.GetRequiredValues $m_id}} 240 .addRequiredValue({{template "VersionCode" $mpc}}, {{template 241 "MeasurementValue" Dict "RequiredValue" . "MeasurementType" $mt}}) 242 {{- end}} 243 {{- end}} 244 {{- end}} 245 .build(); 246 {{- end }} 247 248 {{UpperCamelCase $r.GetName}}Requirement req = 249 new {{UpperCamelCase $r.GetName}}Requirement( 250 "{{ SafeReqID $r.GetId }}{{ SafeTestConfigID $t_id }}" 251 {{- range $m_id, $m := $r.GetMeasurements }}, 252 {{LowerCamelCase $m_id}} 253 {{- end}}); 254 {{- range $m_id, $m := $r.GetMeasurements }} 255 {{- $mt := $m.GetMeasurementType}} 256 {{- $c := $m.GetComparison}} 257 {{- if eq $c.String "COMPARISON_CONFIG" }} 258 {{- range $s := $r.GetSpecs }} 259 {{- if eq $s.GetTestConfigId $t_id }} 260 {{- with index $s.GetRequiredValues $m_id}} 261 req.setMeasuredValue("{{$m_id}}", 262 {{- template "MeasurementValue" Dict "RequiredValue" . "MeasurementType" $mt}}); 263 {{- break }} 264 {{- end }} 265 {{- end }} 266 {{- end }} 267 {{- end }} 268 {{- end }} 269 return req; 270 } 271 {{- end }}{{/* range $t_id, $t */}} 272 273 {{- range $t_id, $t := $r.GetTestConfigs }} 274 {{- range $v_id, $v := $r.GetVariants }} 275 {{- if HasConfigVariant $r $t_id $v_id }} 276 277 /** 278 * {{ $r.GetId }} {{$r.GetName}}{{- with $v.GetDescription}} {{.}}{{end}} 279 {{- with $r.GetDescription}} 280 * 281 * {{.}}{{end}} 282 */ 283 private static {{UpperCamelCase $r.GetName}}Requirement create 284 {{- SafeTestConfigID $t_id | UpperCamelCase }}{{UpperCamelCase $v_id}}() { 285 {{- range $m_id, $m := $r.GetMeasurements }} 286 {{- $mt := $m.GetMeasurementType}} 287 {{- $c := $m.GetComparison}} 288 var {{LowerCamelCase $m_id}} = RequiredMeasurement 289 .<{{template "JavaClass" $mt}}>builder() 290 .setId("{{$m_id}}") 291 .setPredicate(RequirementConstants.{{template "CompMethod" $m}}) 292 {{- range $mpc, $s := $r.GetSpecs }} 293 {{- if eq $s.GetTestConfigId $t_id }} 294 {{- $vs := index $s.GetVariantSpecs $v_id}} 295 {{- if $vs }} 296 {{- with index $vs.GetRequiredValues $m_id}} 297 .addRequiredValue({{template "VersionCode" $mpc}}, {{template 298 "MeasurementValue" Dict "RequiredValue" . "MeasurementType" $mt}}) 299 {{- end}}{{/* if $vs */}} 300 {{- end}}{{/* with rv */}} 301 {{- end }}{{/* with t */}} 302 {{- end}}{{/* range $mpc, $s */}} 303 .build(); 304 {{- end}}{{/* range $m_id, $m */}} 305 {{UpperCamelCase $r.GetName}}Requirement req = 306 new {{UpperCamelCase $r.GetName}}Requirement( 307 "{{ SafeReqID $r.GetId }}{{ SafeTestConfigID $t_id }}" 308 {{- range $m_id, $m := $r.GetMeasurements }}, 309 {{LowerCamelCase $m_id}} 310 {{- end}}); 311 {{- range $m_id, $m := $r.GetMeasurements }} 312 {{- $mt := $m.GetMeasurementType}} 313 {{- $c := $m.GetComparison}} 314 {{- if eq $c.String "COMPARISON_CONFIG" }} 315 {{- range $s := $r.GetSpecs }} 316 {{- if eq $s.GetTestConfigId $t_id }} 317 {{- with index $s.GetRequiredValues $m_id}} 318 req.setMeasuredValue("{{$m_id}}", 319 {{- template "MeasurementValue" Dict "RequiredValue" . "MeasurementType" $mt}}); 320 {{- break }} 321 {{- end }} 322 {{- end }} 323 {{- end }} 324 {{- end }} 325 {{- end }} 326 return req; 327 } 328 {{- end }}{{/* if HasConfigVariant */}} 329 {{- end }}{{/* range $v_id, $v */}} 330 {{- end }}{{/* range $t_id, $t */}} 331 332 {{- range $m_id, $m := $r.GetMeasurements }} 333 {{- $mt := $m.GetMeasurementType}} 334 {{- $c := $m.GetComparison}} 335 {{- if eq $c.String "COMPARISON_CONFIG" }} 336 337 /** {{$m.GetDescription}} */ 338 public {{template "JavaType" $mt}} get{{UpperCamelCase $m_id}}() { 339 return this.getMeasuredValue("{{$m_id}}", {{template "JavaClass" $mt}}.class); 340 } 341 {{- else }} 342 343 /** {{$m.GetDescription}} */ 344 public void set{{UpperCamelCase $m_id}}({{template "JavaType" $mt}} v) { 345 this.setMeasuredValue("{{$m_id}}", v); 346 } 347 {{- end }}{{/* if eq */}} 348 {{- end }}{{/* range $m_id, $m */}} 349 350 private {{UpperCamelCase $r.GetName}}Requirement(String id, RequiredMeasurement<?>... reqs) { 351 super(id, reqs); 352 } 353 } 354{{- end }} {{/* if $r.GetName */}} 355{{- end }} {{/* range $r */}} 356 357 private Requirements () {} 358} 359