summaryrefslogtreecommitdiff
path: root/nn/runtime/test/TestValidation.cpp
diff options
context:
space:
mode:
authorMichael Butler <butlermichael@google.com>2019-01-28 23:41:10 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-01-28 23:41:10 +0000
commit955fe47af7fb9abfd6242d71f4bf4fbd05d31f6b (patch)
tree056311b7bba6ba41453d97e26650a364fcb2988e /nn/runtime/test/TestValidation.cpp
parent83ac010e917baee8871ac6b81a22ba81b84b9323 (diff)
parent89e99ba1e6337459b4e821fc93f3adcd6decb684 (diff)
downloadml-955fe47af7fb9abfd6242d71f4bf4fbd05d31f6b.tar.gz
Merge "NNAPI Burst -- runtime and CTS"
Diffstat (limited to 'nn/runtime/test/TestValidation.cpp')
-rw-r--r--nn/runtime/test/TestValidation.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/nn/runtime/test/TestValidation.cpp b/nn/runtime/test/TestValidation.cpp
index 55e0fbb72..2f181f429 100644
--- a/nn/runtime/test/TestValidation.cpp
+++ b/nn/runtime/test/TestValidation.cpp
@@ -20,6 +20,7 @@
#include <android/sharedmem.h>
#include <gtest/gtest.h>
#include <sys/mman.h>
+#include <future>
#include <string>
// This file tests all the validations done by the Neural Networks API.
@@ -125,6 +126,20 @@ class ValidationTestExecution : public ValidationTestCompilation {
ANeuralNetworksExecution* mExecution = nullptr;
};
+class ValidationTestBurst : public ValidationTestExecution {
+ protected:
+ virtual void SetUp() {
+ ValidationTestExecution::SetUp();
+
+ ASSERT_EQ(ANeuralNetworksBurst_create(mCompilation, &mBurst), ANEURALNETWORKS_NO_ERROR);
+ }
+ virtual void TearDown() {
+ ANeuralNetworksBurst_free(mBurst);
+ ValidationTestExecution::TearDown();
+ }
+ ANeuralNetworksBurst* mBurst = nullptr;
+};
+
TEST_F(ValidationTest, CreateModel) {
EXPECT_EQ(ANeuralNetworksModel_create(nullptr), ANEURALNETWORKS_UNEXPECTED_NULL);
}
@@ -885,6 +900,72 @@ TEST_F(ValidationTestExecution, GetOutputOperandRankAndDimensions) {
EXPECT_EQ(dims[0], expectedDims);
}
+TEST_F(ValidationTestBurst, BurstComputeNull) {
+ EXPECT_EQ(ANeuralNetworksExecution_burstCompute(mExecution, nullptr),
+ ANEURALNETWORKS_UNEXPECTED_NULL);
+ EXPECT_EQ(ANeuralNetworksExecution_burstCompute(nullptr, mBurst),
+ ANEURALNETWORKS_UNEXPECTED_NULL);
+}
+
+TEST_F(ValidationTestBurst, BurstComputeDifferentCompilations) {
+ ANeuralNetworksCompilation* secondCompilation;
+ ASSERT_EQ(ANeuralNetworksCompilation_create(mModel, &secondCompilation),
+ ANEURALNETWORKS_NO_ERROR);
+ ASSERT_EQ(ANeuralNetworksCompilation_finish(secondCompilation), ANEURALNETWORKS_NO_ERROR);
+
+ ANeuralNetworksBurst* burst;
+ EXPECT_EQ(ANeuralNetworksBurst_create(secondCompilation, &burst), ANEURALNETWORKS_NO_ERROR);
+
+ EXPECT_EQ(ANeuralNetworksExecution_burstCompute(mExecution, burst), ANEURALNETWORKS_BAD_DATA);
+
+ ANeuralNetworksBurst_free(burst);
+ ANeuralNetworksCompilation_free(secondCompilation);
+}
+
+TEST_F(ValidationTestBurst, BurstComputeConcurrent) {
+ ANeuralNetworksExecution* secondExecution;
+ EXPECT_EQ(ANeuralNetworksExecution_create(mCompilation, &secondExecution),
+ ANEURALNETWORKS_NO_ERROR);
+
+ // set inputs of first execution
+ float inputA0 = 1.0f, inputA1 = 2.0f, outputA0;
+ int32_t inputA2 = 0;
+ EXPECT_EQ(ANeuralNetworksExecution_setInput(mExecution, 0, nullptr, &inputA0, sizeof(float)),
+ ANEURALNETWORKS_NO_ERROR);
+ EXPECT_EQ(ANeuralNetworksExecution_setInput(mExecution, 1, nullptr, &inputA1, sizeof(float)),
+ ANEURALNETWORKS_NO_ERROR);
+ EXPECT_EQ(ANeuralNetworksExecution_setInput(mExecution, 2, nullptr, &inputA2, sizeof(int32_t)),
+ ANEURALNETWORKS_NO_ERROR);
+ EXPECT_EQ(ANeuralNetworksExecution_setOutput(mExecution, 0, nullptr, &outputA0, sizeof(float)),
+ ANEURALNETWORKS_NO_ERROR);
+
+ // set inputs of second execution
+ float inputB0 = 1.0f, inputB1 = 2.0f, outputB0;
+ int32_t inputB2 = 0;
+ EXPECT_EQ(
+ ANeuralNetworksExecution_setInput(secondExecution, 0, nullptr, &inputB0, sizeof(float)),
+ ANEURALNETWORKS_NO_ERROR);
+ EXPECT_EQ(
+ ANeuralNetworksExecution_setInput(secondExecution, 1, nullptr, &inputB1, sizeof(float)),
+ ANEURALNETWORKS_NO_ERROR);
+ EXPECT_EQ(ANeuralNetworksExecution_setInput(secondExecution, 2, nullptr, &inputB2,
+ sizeof(int32_t)),
+ ANEURALNETWORKS_NO_ERROR);
+ EXPECT_EQ(ANeuralNetworksExecution_setOutput(secondExecution, 0, nullptr, &outputB0,
+ sizeof(float)),
+ ANEURALNETWORKS_NO_ERROR);
+
+ // execute on the same burst concurrently
+ auto first = std::async(std::launch::async, [this] {
+ const int result = ANeuralNetworksExecution_burstCompute(mExecution, mBurst);
+ EXPECT_TRUE(result == ANEURALNETWORKS_BAD_STATE || result == ANEURALNETWORKS_NO_ERROR);
+ });
+ auto second = std::async(std::launch::async, [this, secondExecution] {
+ const int result = ANeuralNetworksExecution_burstCompute(secondExecution, mBurst);
+ EXPECT_TRUE(result == ANEURALNETWORKS_BAD_STATE || result == ANEURALNETWORKS_NO_ERROR);
+ });
+}
+
TEST(ValidationTestIntrospection, GetNumDevices) {
uint32_t numDevices = 0;
EXPECT_EQ(ANeuralNetworks_getDeviceCount(&numDevices), ANEURALNETWORKS_NO_ERROR);