Fix NNAPI QoS Deadline test
The Deadline test was directly loading into the field of a std::optional
instead of emplacing, which is undefined behavior. This has been
corrected to emplace.
Additionally, previously the deadline test always checked the tensor
results of the execution. This is changed to only check the results
when the driver reports that the execution completed successfully.
Finally, this CL merges similar switch case statements.
Bug: 149766387
Test: mma
Test: VtsHalNeuralnetworksV1_3TargetTest
Change-Id: I1068fe70e74a12006dea3cdf4ae9da50004ad24b
diff --git a/neuralnetworks/1.3/vts/functional/QualityOfServiceTests.cpp b/neuralnetworks/1.3/vts/functional/QualityOfServiceTests.cpp
index 2663500..879989e 100644
--- a/neuralnetworks/1.3/vts/functional/QualityOfServiceTests.cpp
+++ b/neuralnetworks/1.3/vts/functional/QualityOfServiceTests.cpp
@@ -134,10 +134,9 @@
} else {
switch (deadlineBound.value()) {
case DeadlineBoundType::NOW:
- // If the execution was launched with a deadline of NOW, the
- // deadline has already passed when the driver would launch the
- // execution. In this case, the driver must return
- // MISSED_DEADLINE_*.
+ case DeadlineBoundType::SHORT:
+ // Either the driver successfully completed the task or it
+ // aborted and returned MISSED_DEADLINE_*.
EXPECT_TRUE(prepareReturnStatus == ErrorStatus::NONE ||
prepareReturnStatus == ErrorStatus::MISSED_DEADLINE_TRANSIENT ||
prepareReturnStatus == ErrorStatus::MISSED_DEADLINE_PERSISTENT);
@@ -148,13 +147,6 @@
// of the switch statement.
EXPECT_EQ(ErrorStatus::NONE, prepareReturnStatus);
break;
- case DeadlineBoundType::SHORT:
- // Either the driver successfully completed the task in time or
- // it aborted within the compliance time.
- EXPECT_TRUE(prepareReturnStatus == ErrorStatus::NONE ||
- prepareReturnStatus == ErrorStatus::MISSED_DEADLINE_TRANSIENT ||
- prepareReturnStatus == ErrorStatus::MISSED_DEADLINE_PERSISTENT);
- break;
}
}
ASSERT_EQ(prepareReturnStatus == ErrorStatus::NONE, preparedModel.get() != nullptr);
@@ -206,7 +198,10 @@
// configure results callback
MaybeResults results;
- const auto cb = [&results](const auto&... args) { *results = {args...}; };
+ const auto cb = [&results](ErrorStatus status, const hidl_vec<OutputShape>& outputShapes,
+ const Timing& timing) {
+ results.emplace(status, outputShapes, timing);
+ };
// run execution
const Return<void> ret =
@@ -235,27 +230,19 @@
// Validate deadline information if applicable.
switch (deadlineBound) {
case DeadlineBoundType::NOW:
- // If the execution was launched with a deadline of NOW, the
- // deadline has already passed when the driver would launch the
- // execution. In this case, the driver must return
- // MISSED_DEADLINE_*.
+ case DeadlineBoundType::SHORT:
+ // Either the driver successfully completed the task or it
+ // aborted and returned MISSED_DEADLINE_*.
ASSERT_TRUE(status == ErrorStatus::NONE ||
status == ErrorStatus::MISSED_DEADLINE_TRANSIENT ||
status == ErrorStatus::MISSED_DEADLINE_PERSISTENT);
- return;
+ break;
case DeadlineBoundType::UNLIMITED:
// If an unlimited deadline is supplied, we expect the execution to
// proceed normally. In this case, check it normally by breaking out
// of the switch statement.
ASSERT_EQ(ErrorStatus::NONE, status);
break;
- case DeadlineBoundType::SHORT:
- // Either the driver successfully completed the task in time or
- // it aborted within the compliance time.
- EXPECT_TRUE(status == ErrorStatus::NONE ||
- status == ErrorStatus::MISSED_DEADLINE_TRANSIENT ||
- status == ErrorStatus::MISSED_DEADLINE_PERSISTENT);
- break;
}
// If the model output operands are fully specified, outputShapes must be either
@@ -277,7 +264,9 @@
const std::vector<TestBuffer> outputs = getOutputBuffers(request10);
// We want "close-enough" results.
- checkResults(testModel, outputs);
+ if (status == ErrorStatus::NONE) {
+ checkResults(testModel, outputs);
+ }
}
void runExecutionTests(const sp<IPreparedModel>& preparedModel, const TestModel& testModel,