summaryrefslogtreecommitdiff
path: root/nn/runtime/test/TestTrivialModel.cpp
diff options
context:
space:
mode:
authorMiao Wang <miaowang@google.com>2019-12-23 16:18:11 -0800
committerMiao Wang <miaowang@google.com>2020-01-22 12:25:47 -0800
commit688992b3e241dd8936d63c6a21977bfc6b6f0773 (patch)
treee74dc38ae874002c519bd1f075c55cdc2af063d3 /nn/runtime/test/TestTrivialModel.cpp
parent991050faa2101656eca61c3acf0c98f8aa8cf106 (diff)
downloadml-688992b3e241dd8936d63c6a21977bfc6b6f0773.tar.gz
Add tests for sync fence related API.
The following tests are added: - basic validation tests - generated tests for ANeuralNetworksExecution_startComputeWithDependencies. Bug: 142778241 Test: mm Change-Id: I5591db4583e8b752868d06e16874780800d4410e
Diffstat (limited to 'nn/runtime/test/TestTrivialModel.cpp')
-rw-r--r--nn/runtime/test/TestTrivialModel.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/nn/runtime/test/TestTrivialModel.cpp b/nn/runtime/test/TestTrivialModel.cpp
index 85da1d1f0..557b2aa62 100644
--- a/nn/runtime/test/TestTrivialModel.cpp
+++ b/nn/runtime/test/TestTrivialModel.cpp
@@ -150,6 +150,49 @@ TEST_F(TrivialTest, AddThree) {
ASSERT_EQ(CompareMatrices(expected3b, actual), 0);
}
+TEST_F(TrivialTest, FencedAddThree) {
+ Model modelAdd3;
+ CreateAddThreeTensorModel(&modelAdd3, matrix3);
+ Compilation compilation(&modelAdd3);
+ compilation.finish();
+
+ Matrix3x4 output1, output2;
+ memset(&output1, 0, sizeof(output1));
+ memset(&output2, 0, sizeof(output2));
+
+ // Start the first execution
+ Execution execution1(&compilation);
+ ASSERT_EQ(execution1.setInput(0, matrix1, sizeof(Matrix3x4)), Result::NO_ERROR);
+ ASSERT_EQ(execution1.setInput(1, matrix2, sizeof(Matrix3x4)), Result::NO_ERROR);
+ ASSERT_EQ(execution1.setOutput(0, output1, sizeof(Matrix3x4)), Result::NO_ERROR);
+ ANeuralNetworksEvent* event1;
+ ANeuralNetworksExecution* execution1_handle = execution1.getHandle();
+ ASSERT_EQ(ANeuralNetworksExecution_startComputeWithDependencies(execution1_handle, nullptr, 0,
+ &event1),
+ ANEURALNETWORKS_NO_ERROR);
+
+ // Start the second execution which will wait for the first one.
+ Execution execution2(&compilation);
+ ASSERT_EQ(execution2.setInput(0, matrix1, sizeof(Matrix3x4)), Result::NO_ERROR);
+ ASSERT_EQ(execution2.setInput(1, matrix1, sizeof(Matrix3x4)), Result::NO_ERROR);
+ ASSERT_EQ(execution2.setOutput(0, output2, sizeof(Matrix3x4)), Result::NO_ERROR);
+ ANeuralNetworksEvent* event2;
+ ANeuralNetworksExecution* execution2_handle = execution2.getHandle();
+ ASSERT_EQ(ANeuralNetworksExecution_startComputeWithDependencies(execution2_handle, &event1, 1,
+ &event2),
+ ANEURALNETWORKS_NO_ERROR);
+ // Wait for the second event.
+ ASSERT_EQ(ANeuralNetworksEvent_wait(event2), ANEURALNETWORKS_NO_ERROR);
+
+ // Check the results for both executions.
+ ASSERT_EQ(CompareMatrices(expected3, output1), 0);
+ ASSERT_EQ(CompareMatrices(expected3b, output2), 0);
+
+ // Free the event objects
+ ANeuralNetworksEvent_free(event1);
+ ANeuralNetworksEvent_free(event2);
+}
+
TEST_F(TrivialTest, BroadcastAddTwo) {
Model modelBroadcastAdd2;
OperandType scalarType(Type::INT32, {});