blob: 2f50f8ea542585c22f4cae813c018e3cb5cec17f [file] [log] [blame]
/*
* Copyright (C) 2023 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 License.
*/
package android.tools.device.flicker.legacy.runner
import android.tools.common.CrossPlatform
import android.tools.common.Timestamp
import android.tools.device.traces.io.IResultData
import com.google.common.truth.Truth
object TestUtils {
internal fun validateTransitionTime(result: IResultData) {
val startTime = result.transitionTimeRange.start
val endTime = result.transitionTimeRange.end
validateTimeGreaterThan(startTime, "Start time", CrossPlatform.timestamp.min())
validateTimeGreaterThan(endTime, "End time", CrossPlatform.timestamp.min())
validateTimeGreaterThan(CrossPlatform.timestamp.max(), "End time", endTime)
}
internal fun validateTransitionTimeIsEmpty(result: IResultData) {
val startTime = result.transitionTimeRange.start
val endTime = result.transitionTimeRange.end
validateEqualTo(startTime, "Start time", CrossPlatform.timestamp.min())
validateEqualTo(endTime, "End time", CrossPlatform.timestamp.max())
}
private fun validateEqualTo(time: Timestamp, name: String, expectedValue: Timestamp) {
Truth.assertWithMessage("$name - systemUptimeNanos")
.that(time.systemUptimeNanos)
.isEqualTo(expectedValue.systemUptimeNanos)
Truth.assertWithMessage("$name - unixNanos")
.that(time.unixNanos)
.isEqualTo(expectedValue.unixNanos)
Truth.assertWithMessage("$name - elapsedNanos")
.that(time.elapsedNanos)
.isEqualTo(expectedValue.elapsedNanos)
}
private fun validateTimeGreaterThan(time: Timestamp, name: String, minValue: Timestamp) {
Truth.assertWithMessage("$name - systemUptimeNanos")
.that(time.systemUptimeNanos)
.isGreaterThan(minValue.systemUptimeNanos)
Truth.assertWithMessage("$name - unixNanos")
.that(time.unixNanos)
.isGreaterThan(minValue.unixNanos)
Truth.assertWithMessage("$name - elapsedNanos")
.that(time.elapsedNanos)
.isGreaterThan(minValue.elapsedNanos)
}
}