blob: f4b6d8ba674599eded0add93297940942957e12a [file] [log] [blame]
/*
* Copyright (C) 2022 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 Licnse.
*/
package android.mediapc.cts.common;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assume.assumeTrue;
import android.os.Build;
import androidx.test.filters.SmallTest;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import org.junit.rules.TestName;
import org.junit.Test;
import java.util.HashSet;
import java.util.Set;
import java.util.HashMap;
import java.util.Map;
/**
* Logs a set of measurements and results for defined performance class requirements.
*/
public class PerformanceClassEvaluator {
private static final String TAG = PerformanceClassEvaluator.class.getSimpleName();
private final String mTestName;
private Set<Requirement> mRequirements;
public PerformanceClassEvaluator(TestName testName) {
Preconditions.checkNotNull(testName);
this.mTestName = testName.getMethodName();
this.mRequirements = new HashSet<Requirement>();
}
private <R extends Requirement> R addRequirement(R req) {
if (!this.mRequirements.add(req)) {
throw new IllegalStateException("Requirement " + req.id() + " already added");
}
return req;
}
public void submitAndCheck() {
boolean perfClassMet = true;
for (Requirement req: this.mRequirements) {
perfClassMet &= req.writeLogAndCheck(this.mTestName);
}
// check performance class
assumeTrue("Build.VERSION.MEDIA_PERFORMANCE_CLASS is not declared", Utils.isPerfClass());
assertThat(perfClassMet).isTrue();
this.mRequirements.clear(); // makes sure report isn't submitted twice
}
}