Cleanup NNAPI VTS tests

This CL includes the following cleanups:
* namespace compression
* remove "using" from header files
* remove no-op code, default no-op constructors
* clang-formats the code

Bug: N/A
Test: mma
Test: VtsHalNeuralnetworksV1_*TargetTest
Change-Id: I023997d8686ca65223858eed3a0881f5444ed2d6
Merged-In: I023997d8686ca65223858eed3a0881f5444ed2d6
(cherry picked from commit bbe5dad266)
This commit is contained in:
Michael Butler 2019-08-26 23:55:47 -07:00
parent 15b826ad6a
commit 62749b917e
27 changed files with 220 additions and 529 deletions

View file

@ -18,12 +18,7 @@
#include "VtsHalNeuralnetworks.h" #include "VtsHalNeuralnetworks.h"
namespace android { namespace android::hardware::neuralnetworks::V1_0::vts::functional {
namespace hardware {
namespace neuralnetworks {
namespace V1_0 {
namespace vts {
namespace functional {
// create device test // create device test
TEST_F(NeuralnetworksHidlTest, CreateDevice) {} TEST_F(NeuralnetworksHidlTest, CreateDevice) {}
@ -38,19 +33,14 @@ TEST_F(NeuralnetworksHidlTest, StatusTest) {
// initialization // initialization
TEST_F(NeuralnetworksHidlTest, GetCapabilitiesTest) { TEST_F(NeuralnetworksHidlTest, GetCapabilitiesTest) {
Return<void> ret = Return<void> ret =
device->getCapabilities([](ErrorStatus status, const Capabilities& capabilities) { device->getCapabilities([](ErrorStatus status, const Capabilities& capabilities) {
EXPECT_EQ(ErrorStatus::NONE, status); EXPECT_EQ(ErrorStatus::NONE, status);
EXPECT_LT(0.0f, capabilities.float32Performance.execTime); EXPECT_LT(0.0f, capabilities.float32Performance.execTime);
EXPECT_LT(0.0f, capabilities.float32Performance.powerUsage); EXPECT_LT(0.0f, capabilities.float32Performance.powerUsage);
EXPECT_LT(0.0f, capabilities.quantized8Performance.execTime); EXPECT_LT(0.0f, capabilities.quantized8Performance.execTime);
EXPECT_LT(0.0f, capabilities.quantized8Performance.powerUsage); EXPECT_LT(0.0f, capabilities.quantized8Performance.powerUsage);
}); });
EXPECT_TRUE(ret.isOk()); EXPECT_TRUE(ret.isOk());
} }
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_0::vts::functional
} // namespace vts
} // namespace V1_0
} // namespace neuralnetworks
} // namespace hardware
} // namespace android

View file

@ -33,23 +33,12 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <iostream> #include <iostream>
namespace android { namespace android::hardware::neuralnetworks::V1_0::vts::functional {
namespace hardware {
namespace neuralnetworks {
namespace V1_0 {
namespace vts {
namespace functional {
using namespace test_helper; using namespace test_helper;
using ::android::hardware::neuralnetworks::V1_0::ErrorStatus; using hidl::memory::V1_0::IMemory;
using ::android::hardware::neuralnetworks::V1_0::IDevice; using implementation::ExecutionCallback;
using ::android::hardware::neuralnetworks::V1_0::IPreparedModel; using implementation::PreparedModelCallback;
using ::android::hardware::neuralnetworks::V1_0::Model;
using ::android::hardware::neuralnetworks::V1_0::Request;
using ::android::hardware::neuralnetworks::V1_0::RequestArgument;
using ::android::hardware::neuralnetworks::V1_0::implementation::ExecutionCallback;
using ::android::hardware::neuralnetworks::V1_0::implementation::PreparedModelCallback;
using ::android::hidl::memory::V1_0::IMemory;
Model createModel(const TestModel& testModel) { Model createModel(const TestModel& testModel) {
// Model operands. // Model operands.
@ -206,9 +195,4 @@ TEST_P(GeneratedTest, Test) {
INSTANTIATE_GENERATED_TEST(GeneratedTest, INSTANTIATE_GENERATED_TEST(GeneratedTest,
[](const TestModel& testModel) { return !testModel.expectFailure; }); [](const TestModel& testModel) { return !testModel.expectFailure; });
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_0::vts::functional
} // namespace vts
} // namespace V1_0
} // namespace neuralnetworks
} // namespace hardware
} // namespace android

View file

@ -21,12 +21,7 @@
#include "TestHarness.h" #include "TestHarness.h"
#include "VtsHalNeuralnetworks.h" #include "VtsHalNeuralnetworks.h"
namespace android { namespace android::hardware::neuralnetworks::V1_0::vts::functional {
namespace hardware {
namespace neuralnetworks {
namespace V1_0 {
namespace vts {
namespace functional {
class GeneratedTestBase class GeneratedTestBase
: public NeuralnetworksHidlTest, : public NeuralnetworksHidlTest,
@ -59,11 +54,6 @@ class ValidationTest : public GeneratedTestBase {
Model createModel(const ::test_helper::TestModel& testModel); Model createModel(const ::test_helper::TestModel& testModel);
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_0::vts::functional
} // namespace vts
} // namespace V1_0
} // namespace neuralnetworks
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_NEURALNETWORKS_V1_0_GENERATED_TEST_HARNESS_H #endif // ANDROID_HARDWARE_NEURALNETWORKS_V1_0_GENERATED_TEST_HARNESS_H

View file

@ -28,15 +28,13 @@
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
namespace android { namespace android::hardware::neuralnetworks {
namespace hardware {
namespace neuralnetworks {
using namespace test_helper; using namespace test_helper;
using ::android::hardware::neuralnetworks::V1_0::DataLocation; using hidl::memory::V1_0::IMemory;
using ::android::hardware::neuralnetworks::V1_0::Request; using V1_0::DataLocation;
using ::android::hardware::neuralnetworks::V1_0::RequestArgument; using V1_0::Request;
using ::android::hidl::memory::V1_0::IMemory; using V1_0::RequestArgument;
constexpr uint32_t kInputPoolIndex = 0; constexpr uint32_t kInputPoolIndex = 0;
constexpr uint32_t kOutputPoolIndex = 1; constexpr uint32_t kOutputPoolIndex = 1;
@ -118,6 +116,4 @@ std::vector<TestBuffer> getOutputBuffers(const Request& request) {
return outputBuffers; return outputBuffers;
} }
} // namespace neuralnetworks } // namespace android::hardware::neuralnetworks
} // namespace hardware
} // namespace android

View file

@ -20,15 +20,9 @@
#include "GeneratedTestHarness.h" #include "GeneratedTestHarness.h"
#include "VtsHalNeuralnetworks.h" #include "VtsHalNeuralnetworks.h"
namespace android { namespace android::hardware::neuralnetworks::V1_0::vts::functional {
namespace hardware {
namespace neuralnetworks {
namespace V1_0 {
namespace vts {
namespace functional {
using ::android::hardware::neuralnetworks::V1_0::implementation::ExecutionCallback; using implementation::PreparedModelCallback;
using ::android::hardware::neuralnetworks::V1_0::implementation::PreparedModelCallback;
///////////////////////// UTILITY FUNCTIONS ///////////////////////// ///////////////////////// UTILITY FUNCTIONS /////////////////////////
@ -37,9 +31,9 @@ static void validateGetSupportedOperations(const sp<IDevice>& device, const std:
SCOPED_TRACE(message + " [getSupportedOperations]"); SCOPED_TRACE(message + " [getSupportedOperations]");
Return<void> ret = Return<void> ret =
device->getSupportedOperations(model, [&](ErrorStatus status, const hidl_vec<bool>&) { device->getSupportedOperations(model, [&](ErrorStatus status, const hidl_vec<bool>&) {
EXPECT_EQ(ErrorStatus::INVALID_ARGUMENT, status); EXPECT_EQ(ErrorStatus::INVALID_ARGUMENT, status);
}); });
EXPECT_TRUE(ret.isOk()); EXPECT_TRUE(ret.isOk());
} }
@ -48,7 +42,6 @@ static void validatePrepareModel(const sp<IDevice>& device, const std::string& m
SCOPED_TRACE(message + " [prepareModel]"); SCOPED_TRACE(message + " [prepareModel]");
sp<PreparedModelCallback> preparedModelCallback = new PreparedModelCallback(); sp<PreparedModelCallback> preparedModelCallback = new PreparedModelCallback();
ASSERT_NE(nullptr, preparedModelCallback.get());
Return<ErrorStatus> prepareLaunchStatus = device->prepareModel(model, preparedModelCallback); Return<ErrorStatus> prepareLaunchStatus = device->prepareModel(model, preparedModelCallback);
ASSERT_TRUE(prepareLaunchStatus.isOk()); ASSERT_TRUE(prepareLaunchStatus.isOk());
ASSERT_EQ(ErrorStatus::INVALID_ARGUMENT, static_cast<ErrorStatus>(prepareLaunchStatus)); ASSERT_EQ(ErrorStatus::INVALID_ARGUMENT, static_cast<ErrorStatus>(prepareLaunchStatus));
@ -94,13 +87,13 @@ static uint32_t hidl_vec_push_back(hidl_vec<Type>* vec, const Type& value) {
static uint32_t addOperand(Model* model) { static uint32_t addOperand(Model* model) {
return hidl_vec_push_back(&model->operands, return hidl_vec_push_back(&model->operands,
{ {
.type = OperandType::INT32, .type = OperandType::INT32,
.dimensions = {}, .dimensions = {},
.numberOfConsumers = 0, .numberOfConsumers = 0,
.scale = 0.0f, .scale = 0.0f,
.zeroPoint = 0, .zeroPoint = 0,
.lifetime = OperandLifeTime::MODEL_INPUT, .lifetime = OperandLifeTime::MODEL_INPUT,
.location = {.poolIndex = 0, .offset = 0, .length = 0}, .location = {.poolIndex = 0, .offset = 0, .length = 0},
}); });
} }
@ -114,10 +107,10 @@ static uint32_t addOperand(Model* model, OperandLifeTime lifetime) {
///////////////////////// VALIDATE MODEL OPERAND TYPE ///////////////////////// ///////////////////////// VALIDATE MODEL OPERAND TYPE /////////////////////////
static const int32_t invalidOperandTypes[] = { static const int32_t invalidOperandTypes[] = {
static_cast<int32_t>(OperandType::FLOAT32) - 1, // lower bound fundamental static_cast<int32_t>(OperandType::FLOAT32) - 1, // lower bound fundamental
static_cast<int32_t>(OperandType::TENSOR_QUANT8_ASYMM) + 1, // upper bound fundamental static_cast<int32_t>(OperandType::TENSOR_QUANT8_ASYMM) + 1, // upper bound fundamental
static_cast<int32_t>(OperandType::OEM) - 1, // lower bound OEM static_cast<int32_t>(OperandType::OEM) - 1, // lower bound OEM
static_cast<int32_t>(OperandType::TENSOR_OEM_BYTE) + 1, // upper bound OEM static_cast<int32_t>(OperandType::TENSOR_OEM_BYTE) + 1, // upper bound OEM
}; };
static void mutateOperandTypeTest(const sp<IDevice>& device, const V1_0::Model& model) { static void mutateOperandTypeTest(const sp<IDevice>& device, const V1_0::Model& model) {
@ -210,7 +203,7 @@ static std::vector<int32_t> getInvalidZeroPoints(OperandType type) {
static void mutateOperandZeroPointTest(const sp<IDevice>& device, const V1_0::Model& model) { static void mutateOperandZeroPointTest(const sp<IDevice>& device, const V1_0::Model& model) {
for (size_t operand = 0; operand < model.operands.size(); ++operand) { for (size_t operand = 0; operand < model.operands.size(); ++operand) {
const std::vector<int32_t> invalidZeroPoints = const std::vector<int32_t> invalidZeroPoints =
getInvalidZeroPoints(model.operands[operand].type); getInvalidZeroPoints(model.operands[operand].type);
for (int32_t invalidZeroPoint : invalidZeroPoints) { for (int32_t invalidZeroPoint : invalidZeroPoints) {
const std::string message = "mutateOperandZeroPointTest: operand " + const std::string message = "mutateOperandZeroPointTest: operand " +
std::to_string(operand) + " has zero point of " + std::to_string(operand) + " has zero point of " +
@ -242,18 +235,18 @@ static void mutateOperand(Operand* operand, OperandType type) {
break; break;
case OperandType::TENSOR_FLOAT32: case OperandType::TENSOR_FLOAT32:
newOperand.dimensions = newOperand.dimensions =
operand->dimensions.size() > 0 ? operand->dimensions : hidl_vec<uint32_t>({1}); operand->dimensions.size() > 0 ? operand->dimensions : hidl_vec<uint32_t>({1});
newOperand.scale = 0.0f; newOperand.scale = 0.0f;
newOperand.zeroPoint = 0; newOperand.zeroPoint = 0;
break; break;
case OperandType::TENSOR_INT32: case OperandType::TENSOR_INT32:
newOperand.dimensions = newOperand.dimensions =
operand->dimensions.size() > 0 ? operand->dimensions : hidl_vec<uint32_t>({1}); operand->dimensions.size() > 0 ? operand->dimensions : hidl_vec<uint32_t>({1});
newOperand.zeroPoint = 0; newOperand.zeroPoint = 0;
break; break;
case OperandType::TENSOR_QUANT8_ASYMM: case OperandType::TENSOR_QUANT8_ASYMM:
newOperand.dimensions = newOperand.dimensions =
operand->dimensions.size() > 0 ? operand->dimensions : hidl_vec<uint32_t>({1}); operand->dimensions.size() > 0 ? operand->dimensions : hidl_vec<uint32_t>({1});
newOperand.scale = operand->scale != 0.0f ? operand->scale : 1.0f; newOperand.scale = operand->scale != 0.0f ? operand->scale : 1.0f;
break; break;
case OperandType::OEM: case OperandType::OEM:
@ -303,10 +296,10 @@ static void mutateOperationOperandTypeTest(const sp<IDevice>& device, const V1_0
///////////////////////// VALIDATE MODEL OPERATION TYPE ///////////////////////// ///////////////////////// VALIDATE MODEL OPERATION TYPE /////////////////////////
static const int32_t invalidOperationTypes[] = { static const int32_t invalidOperationTypes[] = {
static_cast<int32_t>(OperationType::ADD) - 1, // lower bound fundamental static_cast<int32_t>(OperationType::ADD) - 1, // lower bound fundamental
static_cast<int32_t>(OperationType::TANH) + 1, // upper bound fundamental static_cast<int32_t>(OperationType::TANH) + 1, // upper bound fundamental
static_cast<int32_t>(OperationType::OEM_OPERATION) - 1, // lower bound OEM static_cast<int32_t>(OperationType::OEM_OPERATION) - 1, // lower bound OEM
static_cast<int32_t>(OperationType::OEM_OPERATION) + 1, // upper bound OEM static_cast<int32_t>(OperationType::OEM_OPERATION) + 1, // upper bound OEM
}; };
static void mutateOperationTypeTest(const sp<IDevice>& device, const V1_0::Model& model) { static void mutateOperationTypeTest(const sp<IDevice>& device, const V1_0::Model& model) {
@ -317,7 +310,7 @@ static void mutateOperationTypeTest(const sp<IDevice>& device, const V1_0::Model
std::to_string(invalidOperationType); std::to_string(invalidOperationType);
validate(device, message, model, [operation, invalidOperationType](Model* model) { validate(device, message, model, [operation, invalidOperationType](Model* model) {
model->operations[operation].type = model->operations[operation].type =
static_cast<OperationType>(invalidOperationType); static_cast<OperationType>(invalidOperationType);
}); });
} }
} }
@ -470,7 +463,7 @@ static void addOperationInputTest(const sp<IDevice>& device, const V1_0::Model&
static void addOperationOutputTest(const sp<IDevice>& device, const V1_0::Model& model) { static void addOperationOutputTest(const sp<IDevice>& device, const V1_0::Model& model) {
for (size_t operation = 0; operation < model.operations.size(); ++operation) { for (size_t operation = 0; operation < model.operations.size(); ++operation) {
const std::string message = const std::string message =
"addOperationOutputTest: operation " + std::to_string(operation); "addOperationOutputTest: operation " + std::to_string(operation);
validate(device, message, model, [operation](Model* model) { validate(device, message, model, [operation](Model* model) {
uint32_t index = addOperand(model, OperandLifeTime::MODEL_OUTPUT); uint32_t index = addOperand(model, OperandLifeTime::MODEL_OUTPUT);
hidl_vec_push_back(&model->operations[operation].outputs, index); hidl_vec_push_back(&model->operations[operation].outputs, index);
@ -498,9 +491,4 @@ void ValidationTest::validateModel(const V1_0::Model& model) {
addOperationOutputTest(device, model); addOperationOutputTest(device, model);
} }
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_0::vts::functional
} // namespace vts
} // namespace V1_0
} // namespace neuralnetworks
} // namespace hardware
} // namespace android

View file

@ -20,14 +20,9 @@
#include "GeneratedTestHarness.h" #include "GeneratedTestHarness.h"
#include "VtsHalNeuralnetworks.h" #include "VtsHalNeuralnetworks.h"
namespace android { namespace android::hardware::neuralnetworks::V1_0::vts::functional {
namespace hardware {
namespace neuralnetworks {
namespace V1_0 {
namespace vts {
namespace functional {
using ::android::hardware::neuralnetworks::V1_0::implementation::ExecutionCallback; using implementation::ExecutionCallback;
///////////////////////// UTILITY FUNCTIONS ///////////////////////// ///////////////////////// UTILITY FUNCTIONS /////////////////////////
@ -41,7 +36,6 @@ static void validate(const sp<IPreparedModel>& preparedModel, const std::string&
SCOPED_TRACE(message + " [execute]"); SCOPED_TRACE(message + " [execute]");
sp<ExecutionCallback> executionCallback = new ExecutionCallback(); sp<ExecutionCallback> executionCallback = new ExecutionCallback();
ASSERT_NE(nullptr, executionCallback.get());
Return<ErrorStatus> executeLaunchStatus = preparedModel->execute(request, executionCallback); Return<ErrorStatus> executeLaunchStatus = preparedModel->execute(request, executionCallback);
ASSERT_TRUE(executeLaunchStatus.isOk()); ASSERT_TRUE(executeLaunchStatus.isOk());
ASSERT_EQ(ErrorStatus::INVALID_ARGUMENT, static_cast<ErrorStatus>(executeLaunchStatus)); ASSERT_EQ(ErrorStatus::INVALID_ARGUMENT, static_cast<ErrorStatus>(executeLaunchStatus));
@ -99,9 +93,4 @@ void ValidationTest::validateRequest(const sp<IPreparedModel>& preparedModel,
removeOutputTest(preparedModel, request); removeOutputTest(preparedModel, request);
} }
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_0::vts::functional
} // namespace vts
} // namespace V1_0
} // namespace neuralnetworks
} // namespace hardware
} // namespace android

View file

@ -24,16 +24,11 @@
#include <android-base/logging.h> #include <android-base/logging.h>
namespace android { namespace android::hardware::neuralnetworks::V1_0::vts::functional {
namespace hardware {
namespace neuralnetworks {
namespace V1_0 {
namespace vts {
namespace functional {
using ::android::hardware::neuralnetworks::V1_0::implementation::PreparedModelCallback; using implementation::PreparedModelCallback;
static void createPreparedModel(const sp<IDevice>& device, const V1_0::Model& model, static void createPreparedModel(const sp<IDevice>& device, const Model& model,
sp<IPreparedModel>* preparedModel) { sp<IPreparedModel>* preparedModel) {
ASSERT_NE(nullptr, preparedModel); ASSERT_NE(nullptr, preparedModel);
@ -50,7 +45,6 @@ static void createPreparedModel(const sp<IDevice>& device, const V1_0::Model& mo
// launch prepare model // launch prepare model
sp<PreparedModelCallback> preparedModelCallback = new PreparedModelCallback(); sp<PreparedModelCallback> preparedModelCallback = new PreparedModelCallback();
ASSERT_NE(nullptr, preparedModelCallback.get());
Return<ErrorStatus> prepareLaunchStatus = device->prepareModel(model, preparedModelCallback); Return<ErrorStatus> prepareLaunchStatus = device->prepareModel(model, preparedModelCallback);
ASSERT_TRUE(prepareLaunchStatus.isOk()); ASSERT_TRUE(prepareLaunchStatus.isOk());
ASSERT_EQ(ErrorStatus::NONE, static_cast<ErrorStatus>(prepareLaunchStatus)); ASSERT_EQ(ErrorStatus::NONE, static_cast<ErrorStatus>(prepareLaunchStatus));
@ -81,10 +75,6 @@ static void createPreparedModel(const sp<IDevice>& device, const V1_0::Model& mo
} }
// A class for test environment setup // A class for test environment setup
NeuralnetworksHidlEnvironment::NeuralnetworksHidlEnvironment() {}
NeuralnetworksHidlEnvironment::~NeuralnetworksHidlEnvironment() {}
NeuralnetworksHidlEnvironment* NeuralnetworksHidlEnvironment::getInstance() { NeuralnetworksHidlEnvironment* NeuralnetworksHidlEnvironment::getInstance() {
// This has to return a "new" object because it is freed inside // This has to return a "new" object because it is freed inside
// ::testing::AddGlobalTestEnvironment when the gtest is being torn down // ::testing::AddGlobalTestEnvironment when the gtest is being torn down
@ -97,14 +87,8 @@ void NeuralnetworksHidlEnvironment::registerTestServices() {
} }
// The main test class for NEURALNETWORK HIDL HAL. // The main test class for NEURALNETWORK HIDL HAL.
NeuralnetworksHidlTest::NeuralnetworksHidlTest() {}
NeuralnetworksHidlTest::~NeuralnetworksHidlTest() {}
void NeuralnetworksHidlTest::SetUp() { void NeuralnetworksHidlTest::SetUp() {
::testing::VtsHalHidlTargetTestBase::SetUp(); ::testing::VtsHalHidlTargetTestBase::SetUp();
device = ::testing::VtsHalHidlTargetTestBase::getService<IDevice>(
NeuralnetworksHidlEnvironment::getInstance());
#ifdef PRESUBMIT_NOT_VTS #ifdef PRESUBMIT_NOT_VTS
const std::string name = const std::string name =
@ -119,7 +103,6 @@ void NeuralnetworksHidlTest::SetUp() {
} }
void NeuralnetworksHidlTest::TearDown() { void NeuralnetworksHidlTest::TearDown() {
device = nullptr;
::testing::VtsHalHidlTargetTestBase::TearDown(); ::testing::VtsHalHidlTargetTestBase::TearDown();
} }
@ -128,10 +111,8 @@ void ValidationTest::validateEverything(const Model& model, const Request& reque
// create IPreparedModel // create IPreparedModel
sp<IPreparedModel> preparedModel; sp<IPreparedModel> preparedModel;
ASSERT_NO_FATAL_FAILURE(createPreparedModel(device, model, &preparedModel)); createPreparedModel(device, model, &preparedModel);
if (preparedModel == nullptr) { if (preparedModel == nullptr) return;
return;
}
validateRequest(preparedModel, request); validateRequest(preparedModel, request);
} }
@ -145,12 +126,7 @@ TEST_P(ValidationTest, Test) {
INSTANTIATE_GENERATED_TEST(ValidationTest, [](const test_helper::TestModel&) { return true; }); INSTANTIATE_GENERATED_TEST(ValidationTest, [](const test_helper::TestModel&) { return true; });
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_0::vts::functional
} // namespace vts
} // namespace V1_0
} // namespace neuralnetworks
} // namespace hardware
} // namespace android
namespace android::hardware::neuralnetworks::V1_0 { namespace android::hardware::neuralnetworks::V1_0 {

View file

@ -30,20 +30,14 @@
#include "TestHarness.h" #include "TestHarness.h"
namespace android { namespace android::hardware::neuralnetworks::V1_0::vts::functional {
namespace hardware {
namespace neuralnetworks {
namespace V1_0 {
namespace vts {
namespace functional {
// A class for test environment setup // A class for test environment setup
class NeuralnetworksHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { class NeuralnetworksHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
DISALLOW_COPY_AND_ASSIGN(NeuralnetworksHidlEnvironment); DISALLOW_COPY_AND_ASSIGN(NeuralnetworksHidlEnvironment);
NeuralnetworksHidlEnvironment(); NeuralnetworksHidlEnvironment() = default;
~NeuralnetworksHidlEnvironment() override;
public: public:
static NeuralnetworksHidlEnvironment* getInstance(); static NeuralnetworksHidlEnvironment* getInstance();
void registerTestServices() override; void registerTestServices() override;
}; };
@ -52,22 +46,17 @@ class NeuralnetworksHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvB
class NeuralnetworksHidlTest : public ::testing::VtsHalHidlTargetTestBase { class NeuralnetworksHidlTest : public ::testing::VtsHalHidlTargetTestBase {
DISALLOW_COPY_AND_ASSIGN(NeuralnetworksHidlTest); DISALLOW_COPY_AND_ASSIGN(NeuralnetworksHidlTest);
public: public:
NeuralnetworksHidlTest(); NeuralnetworksHidlTest() = default;
~NeuralnetworksHidlTest() override;
void SetUp() override; void SetUp() override;
void TearDown() override; void TearDown() override;
protected: protected:
sp<IDevice> device; const sp<IDevice> device = ::testing::VtsHalHidlTargetTestBase::getService<IDevice>(
NeuralnetworksHidlEnvironment::getInstance());
}; };
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_0::vts::functional
} // namespace vts
} // namespace V1_0
} // namespace neuralnetworks
} // namespace hardware
} // namespace android
namespace android::hardware::neuralnetworks::V1_0 { namespace android::hardware::neuralnetworks::V1_0 {

View file

@ -17,14 +17,13 @@
#ifndef ANDROID_HARDWARE_NEURALNETWORKS_V1_0_UTILS_H #ifndef ANDROID_HARDWARE_NEURALNETWORKS_V1_0_UTILS_H
#define ANDROID_HARDWARE_NEURALNETWORKS_V1_0_UTILS_H #define ANDROID_HARDWARE_NEURALNETWORKS_V1_0_UTILS_H
#include <android-base/logging.h>
#include <android/hardware/neuralnetworks/1.0/types.h> #include <android/hardware/neuralnetworks/1.0/types.h>
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
#include "TestHarness.h" #include "TestHarness.h"
namespace android { namespace android::hardware::neuralnetworks {
namespace hardware {
namespace neuralnetworks {
// Create HIDL Request from the TestModel struct. // Create HIDL Request from the TestModel struct.
V1_0::Request createRequest(const ::test_helper::TestModel& testModel); V1_0::Request createRequest(const ::test_helper::TestModel& testModel);
@ -37,23 +36,20 @@ std::vector<::test_helper::TestBuffer> getOutputBuffers(const V1_0::Request& req
// resizing the hidl_vec to one less. // resizing the hidl_vec to one less.
template <typename Type> template <typename Type>
inline void hidl_vec_removeAt(hidl_vec<Type>* vec, uint32_t index) { inline void hidl_vec_removeAt(hidl_vec<Type>* vec, uint32_t index) {
if (vec) { CHECK(vec != nullptr);
std::rotate(vec->begin() + index, vec->begin() + index + 1, vec->end()); std::rotate(vec->begin() + index, vec->begin() + index + 1, vec->end());
vec->resize(vec->size() - 1); vec->resize(vec->size() - 1);
}
} }
template <typename Type> template <typename Type>
inline uint32_t hidl_vec_push_back(hidl_vec<Type>* vec, const Type& value) { inline uint32_t hidl_vec_push_back(hidl_vec<Type>* vec, const Type& value) {
// assume vec is valid CHECK(vec != nullptr);
const uint32_t index = vec->size(); const uint32_t index = vec->size();
vec->resize(index + 1); vec->resize(index + 1);
(*vec)[index] = value; (*vec)[index] = value;
return index; return index;
} }
} // namespace neuralnetworks } // namespace android::hardware::neuralnetworks
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_NEURALNETWORKS_V1_0_UTILS_H #endif // ANDROID_HARDWARE_NEURALNETWORKS_V1_0_UTILS_H

View file

@ -18,12 +18,10 @@
#include "VtsHalNeuralnetworks.h" #include "VtsHalNeuralnetworks.h"
namespace android { namespace android::hardware::neuralnetworks::V1_1::vts::functional {
namespace hardware {
namespace neuralnetworks { using V1_0::DeviceStatus;
namespace V1_1 { using V1_0::ErrorStatus;
namespace vts {
namespace functional {
// create device test // create device test
TEST_F(NeuralnetworksHidlTest, CreateDevice) {} TEST_F(NeuralnetworksHidlTest, CreateDevice) {}
@ -38,21 +36,16 @@ TEST_F(NeuralnetworksHidlTest, StatusTest) {
// initialization // initialization
TEST_F(NeuralnetworksHidlTest, GetCapabilitiesTest) { TEST_F(NeuralnetworksHidlTest, GetCapabilitiesTest) {
Return<void> ret = Return<void> ret =
device->getCapabilities_1_1([](ErrorStatus status, const Capabilities& capabilities) { device->getCapabilities_1_1([](ErrorStatus status, const Capabilities& capabilities) {
EXPECT_EQ(ErrorStatus::NONE, status); EXPECT_EQ(ErrorStatus::NONE, status);
EXPECT_LT(0.0f, capabilities.float32Performance.execTime); EXPECT_LT(0.0f, capabilities.float32Performance.execTime);
EXPECT_LT(0.0f, capabilities.float32Performance.powerUsage); EXPECT_LT(0.0f, capabilities.float32Performance.powerUsage);
EXPECT_LT(0.0f, capabilities.quantized8Performance.execTime); EXPECT_LT(0.0f, capabilities.quantized8Performance.execTime);
EXPECT_LT(0.0f, capabilities.quantized8Performance.powerUsage); EXPECT_LT(0.0f, capabilities.quantized8Performance.powerUsage);
EXPECT_LT(0.0f, capabilities.relaxedFloat32toFloat16Performance.execTime); EXPECT_LT(0.0f, capabilities.relaxedFloat32toFloat16Performance.execTime);
EXPECT_LT(0.0f, capabilities.relaxedFloat32toFloat16Performance.powerUsage); EXPECT_LT(0.0f, capabilities.relaxedFloat32toFloat16Performance.powerUsage);
}); });
EXPECT_TRUE(ret.isOk()); EXPECT_TRUE(ret.isOk());
} }
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_1::vts::functional
} // namespace vts
} // namespace V1_1
} // namespace neuralnetworks
} // namespace hardware
} // namespace android

View file

@ -33,28 +33,19 @@
#include "TestHarness.h" #include "TestHarness.h"
#include "VtsHalNeuralnetworks.h" #include "VtsHalNeuralnetworks.h"
namespace android { namespace android::hardware::neuralnetworks::V1_1::vts::functional {
namespace hardware {
namespace neuralnetworks {
namespace V1_1 {
namespace vts {
namespace functional {
using namespace test_helper; using namespace test_helper;
using ::android::hardware::neuralnetworks::V1_0::DataLocation; using hidl::memory::V1_0::IMemory;
using ::android::hardware::neuralnetworks::V1_0::ErrorStatus; using V1_0::DataLocation;
using ::android::hardware::neuralnetworks::V1_0::IPreparedModel; using V1_0::ErrorStatus;
using ::android::hardware::neuralnetworks::V1_0::Operand; using V1_0::IPreparedModel;
using ::android::hardware::neuralnetworks::V1_0::OperandLifeTime; using V1_0::Operand;
using ::android::hardware::neuralnetworks::V1_0::OperandType; using V1_0::OperandLifeTime;
using ::android::hardware::neuralnetworks::V1_0::Request; using V1_0::OperandType;
using ::android::hardware::neuralnetworks::V1_0::RequestArgument; using V1_0::Request;
using ::android::hardware::neuralnetworks::V1_0::implementation::ExecutionCallback; using V1_0::implementation::ExecutionCallback;
using ::android::hardware::neuralnetworks::V1_0::implementation::PreparedModelCallback; using V1_0::implementation::PreparedModelCallback;
using ::android::hardware::neuralnetworks::V1_1::ExecutionPreference;
using ::android::hardware::neuralnetworks::V1_1::IDevice;
using ::android::hardware::neuralnetworks::V1_1::Model;
using ::android::hidl::memory::V1_0::IMemory;
Model createModel(const TestModel& testModel) { Model createModel(const TestModel& testModel) {
// Model operands. // Model operands.
@ -212,9 +203,4 @@ TEST_P(GeneratedTest, Test) {
INSTANTIATE_GENERATED_TEST(GeneratedTest, INSTANTIATE_GENERATED_TEST(GeneratedTest,
[](const TestModel& testModel) { return !testModel.expectFailure; }); [](const TestModel& testModel) { return !testModel.expectFailure; });
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_1::vts::functional
} // namespace vts
} // namespace V1_1
} // namespace neuralnetworks
} // namespace hardware
} // namespace android

View file

@ -21,12 +21,7 @@
#include "TestHarness.h" #include "TestHarness.h"
#include "VtsHalNeuralnetworks.h" #include "VtsHalNeuralnetworks.h"
namespace android { namespace android::hardware::neuralnetworks::V1_1::vts::functional {
namespace hardware {
namespace neuralnetworks {
namespace V1_1 {
namespace vts {
namespace functional {
class GeneratedTestBase class GeneratedTestBase
: public NeuralnetworksHidlTest, : public NeuralnetworksHidlTest,
@ -50,20 +45,16 @@ class GeneratedTestBase
// TODO: Clean up the hierarchy for ValidationTest. // TODO: Clean up the hierarchy for ValidationTest.
class ValidationTest : public GeneratedTestBase { class ValidationTest : public GeneratedTestBase {
protected: protected:
void validateEverything(const Model& model, const Request& request); void validateEverything(const Model& model, const V1_0::Request& request);
private: private:
void validateModel(const Model& model); void validateModel(const Model& model);
void validateRequest(const sp<IPreparedModel>& preparedModel, const Request& request); void validateRequest(const sp<V1_0::IPreparedModel>& preparedModel,
const V1_0::Request& request);
}; };
Model createModel(const ::test_helper::TestModel& testModel); Model createModel(const ::test_helper::TestModel& testModel);
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_1::vts::functional
} // namespace vts
} // namespace V1_1
} // namespace neuralnetworks
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_NEURALNETWORKS_V1_1_GENERATED_TEST_HARNESS_H #endif // ANDROID_HARDWARE_NEURALNETWORKS_V1_1_GENERATED_TEST_HARNESS_H

View file

@ -21,18 +21,14 @@
#include "GeneratedTestHarness.h" #include "GeneratedTestHarness.h"
#include "VtsHalNeuralnetworks.h" #include "VtsHalNeuralnetworks.h"
namespace android { namespace android::hardware::neuralnetworks::V1_1::vts::functional {
namespace hardware {
namespace neuralnetworks {
namespace V1_1 {
namespace vts {
namespace functional {
using ::android::hardware::neuralnetworks::V1_0::IPreparedModel; using V1_0::ErrorStatus;
using ::android::hardware::neuralnetworks::V1_0::Operand; using V1_0::IPreparedModel;
using ::android::hardware::neuralnetworks::V1_0::OperandLifeTime; using V1_0::Operand;
using ::android::hardware::neuralnetworks::V1_0::OperandType; using V1_0::OperandLifeTime;
using ::android::hardware::neuralnetworks::V1_0::implementation::PreparedModelCallback; using V1_0::OperandType;
using V1_0::implementation::PreparedModelCallback;
///////////////////////// UTILITY FUNCTIONS ///////////////////////// ///////////////////////// UTILITY FUNCTIONS /////////////////////////
@ -52,7 +48,6 @@ static void validatePrepareModel(const sp<IDevice>& device, const std::string& m
SCOPED_TRACE(message + " [prepareModel_1_1]"); SCOPED_TRACE(message + " [prepareModel_1_1]");
sp<PreparedModelCallback> preparedModelCallback = new PreparedModelCallback(); sp<PreparedModelCallback> preparedModelCallback = new PreparedModelCallback();
ASSERT_NE(nullptr, preparedModelCallback.get());
Return<ErrorStatus> prepareLaunchStatus = Return<ErrorStatus> prepareLaunchStatus =
device->prepareModel_1_1(model, preference, preparedModelCallback); device->prepareModel_1_1(model, preference, preparedModelCallback);
ASSERT_TRUE(prepareLaunchStatus.isOk()); ASSERT_TRUE(prepareLaunchStatus.isOk());
@ -484,8 +479,9 @@ static void mutateExecutionPreferenceTest(const sp<IDevice>& device, const V1_1:
for (int32_t preference : invalidExecutionPreferences) { for (int32_t preference : invalidExecutionPreferences) {
const std::string message = const std::string message =
"mutateExecutionPreferenceTest: preference " + std::to_string(preference); "mutateExecutionPreferenceTest: preference " + std::to_string(preference);
validate(device, message, model, [](Model*) {}, validate(
static_cast<ExecutionPreference>(preference)); device, message, model, [](Model*) {},
static_cast<ExecutionPreference>(preference));
} }
} }
@ -509,9 +505,4 @@ void ValidationTest::validateModel(const V1_1::Model& model) {
mutateExecutionPreferenceTest(device, model); mutateExecutionPreferenceTest(device, model);
} }
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_1::vts::functional
} // namespace vts
} // namespace V1_1
} // namespace neuralnetworks
} // namespace hardware
} // namespace android

View file

@ -21,17 +21,12 @@
#include "GeneratedTestHarness.h" #include "GeneratedTestHarness.h"
#include "VtsHalNeuralnetworks.h" #include "VtsHalNeuralnetworks.h"
namespace android { namespace android::hardware::neuralnetworks::V1_1::vts::functional {
namespace hardware {
namespace neuralnetworks {
namespace V1_1 {
namespace vts {
namespace functional {
using ::android::hardware::neuralnetworks::V1_0::ErrorStatus; using V1_0::ErrorStatus;
using ::android::hardware::neuralnetworks::V1_0::Request; using V1_0::IPreparedModel;
using ::android::hardware::neuralnetworks::V1_0::implementation::ExecutionCallback; using V1_0::Request;
using ::android::hardware::neuralnetworks::V1_1::IPreparedModel; using V1_0::implementation::ExecutionCallback;
///////////////////////// UTILITY FUNCTIONS ///////////////////////// ///////////////////////// UTILITY FUNCTIONS /////////////////////////
@ -45,7 +40,6 @@ static void validate(const sp<IPreparedModel>& preparedModel, const std::string&
SCOPED_TRACE(message + " [execute]"); SCOPED_TRACE(message + " [execute]");
sp<ExecutionCallback> executionCallback = new ExecutionCallback(); sp<ExecutionCallback> executionCallback = new ExecutionCallback();
ASSERT_NE(nullptr, executionCallback.get());
Return<ErrorStatus> executeLaunchStatus = preparedModel->execute(request, executionCallback); Return<ErrorStatus> executeLaunchStatus = preparedModel->execute(request, executionCallback);
ASSERT_TRUE(executeLaunchStatus.isOk()); ASSERT_TRUE(executeLaunchStatus.isOk());
ASSERT_EQ(ErrorStatus::INVALID_ARGUMENT, static_cast<ErrorStatus>(executeLaunchStatus)); ASSERT_EQ(ErrorStatus::INVALID_ARGUMENT, static_cast<ErrorStatus>(executeLaunchStatus));
@ -83,9 +77,4 @@ void ValidationTest::validateRequest(const sp<IPreparedModel>& preparedModel,
removeOutputTest(preparedModel, request); removeOutputTest(preparedModel, request);
} }
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_1::vts::functional
} // namespace vts
} // namespace V1_1
} // namespace neuralnetworks
} // namespace hardware
} // namespace android

View file

@ -24,16 +24,14 @@
#include <android-base/logging.h> #include <android-base/logging.h>
namespace android { namespace android::hardware::neuralnetworks::V1_1::vts::functional {
namespace hardware {
namespace neuralnetworks {
namespace V1_1 {
namespace vts {
namespace functional {
using ::android::hardware::neuralnetworks::V1_0::implementation::PreparedModelCallback; using V1_0::ErrorStatus;
using V1_0::IPreparedModel;
using V1_0::Request;
using V1_0::implementation::PreparedModelCallback;
static void createPreparedModel(const sp<IDevice>& device, const V1_1::Model& model, static void createPreparedModel(const sp<IDevice>& device, const Model& model,
sp<IPreparedModel>* preparedModel) { sp<IPreparedModel>* preparedModel) {
ASSERT_NE(nullptr, preparedModel); ASSERT_NE(nullptr, preparedModel);
@ -50,7 +48,6 @@ static void createPreparedModel(const sp<IDevice>& device, const V1_1::Model& mo
// launch prepare model // launch prepare model
sp<PreparedModelCallback> preparedModelCallback = new PreparedModelCallback(); sp<PreparedModelCallback> preparedModelCallback = new PreparedModelCallback();
ASSERT_NE(nullptr, preparedModelCallback.get());
Return<ErrorStatus> prepareLaunchStatus = device->prepareModel_1_1( Return<ErrorStatus> prepareLaunchStatus = device->prepareModel_1_1(
model, ExecutionPreference::FAST_SINGLE_ANSWER, preparedModelCallback); model, ExecutionPreference::FAST_SINGLE_ANSWER, preparedModelCallback);
ASSERT_TRUE(prepareLaunchStatus.isOk()); ASSERT_TRUE(prepareLaunchStatus.isOk());
@ -82,10 +79,6 @@ static void createPreparedModel(const sp<IDevice>& device, const V1_1::Model& mo
} }
// A class for test environment setup // A class for test environment setup
NeuralnetworksHidlEnvironment::NeuralnetworksHidlEnvironment() {}
NeuralnetworksHidlEnvironment::~NeuralnetworksHidlEnvironment() {}
NeuralnetworksHidlEnvironment* NeuralnetworksHidlEnvironment::getInstance() { NeuralnetworksHidlEnvironment* NeuralnetworksHidlEnvironment::getInstance() {
// This has to return a "new" object because it is freed inside // This has to return a "new" object because it is freed inside
// ::testing::AddGlobalTestEnvironment when the gtest is being torn down // ::testing::AddGlobalTestEnvironment when the gtest is being torn down
@ -98,14 +91,8 @@ void NeuralnetworksHidlEnvironment::registerTestServices() {
} }
// The main test class for NEURALNETWORK HIDL HAL. // The main test class for NEURALNETWORK HIDL HAL.
NeuralnetworksHidlTest::NeuralnetworksHidlTest() {}
NeuralnetworksHidlTest::~NeuralnetworksHidlTest() {}
void NeuralnetworksHidlTest::SetUp() { void NeuralnetworksHidlTest::SetUp() {
::testing::VtsHalHidlTargetTestBase::SetUp(); ::testing::VtsHalHidlTargetTestBase::SetUp();
device = ::testing::VtsHalHidlTargetTestBase::getService<IDevice>(
NeuralnetworksHidlEnvironment::getInstance());
#ifdef PRESUBMIT_NOT_VTS #ifdef PRESUBMIT_NOT_VTS
const std::string name = const std::string name =
@ -120,7 +107,6 @@ void NeuralnetworksHidlTest::SetUp() {
} }
void NeuralnetworksHidlTest::TearDown() { void NeuralnetworksHidlTest::TearDown() {
device = nullptr;
::testing::VtsHalHidlTargetTestBase::TearDown(); ::testing::VtsHalHidlTargetTestBase::TearDown();
} }
@ -146,12 +132,7 @@ TEST_P(ValidationTest, Test) {
INSTANTIATE_GENERATED_TEST(ValidationTest, [](const test_helper::TestModel&) { return true; }); INSTANTIATE_GENERATED_TEST(ValidationTest, [](const test_helper::TestModel&) { return true; });
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_1::vts::functional
} // namespace vts
} // namespace V1_1
} // namespace neuralnetworks
} // namespace hardware
} // namespace android
namespace android::hardware::neuralnetworks::V1_0 { namespace android::hardware::neuralnetworks::V1_0 {

View file

@ -31,28 +31,14 @@
#include "TestHarness.h" #include "TestHarness.h"
namespace android { namespace android::hardware::neuralnetworks::V1_1::vts::functional {
namespace hardware {
namespace neuralnetworks {
namespace V1_1 {
using V1_0::DeviceStatus;
using V1_0::ErrorStatus;
using V1_0::IPreparedModel;
using V1_0::Operand;
using V1_0::OperandType;
using V1_0::Request;
namespace vts {
namespace functional {
// A class for test environment setup // A class for test environment setup
class NeuralnetworksHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { class NeuralnetworksHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
DISALLOW_COPY_AND_ASSIGN(NeuralnetworksHidlEnvironment); DISALLOW_COPY_AND_ASSIGN(NeuralnetworksHidlEnvironment);
NeuralnetworksHidlEnvironment(); NeuralnetworksHidlEnvironment() = default;
~NeuralnetworksHidlEnvironment() override;
public: public:
static NeuralnetworksHidlEnvironment* getInstance(); static NeuralnetworksHidlEnvironment* getInstance();
void registerTestServices() override; void registerTestServices() override;
}; };
@ -61,22 +47,17 @@ class NeuralnetworksHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvB
class NeuralnetworksHidlTest : public ::testing::VtsHalHidlTargetTestBase { class NeuralnetworksHidlTest : public ::testing::VtsHalHidlTargetTestBase {
DISALLOW_COPY_AND_ASSIGN(NeuralnetworksHidlTest); DISALLOW_COPY_AND_ASSIGN(NeuralnetworksHidlTest);
public: public:
NeuralnetworksHidlTest(); NeuralnetworksHidlTest() = default;
~NeuralnetworksHidlTest() override;
void SetUp() override; void SetUp() override;
void TearDown() override; void TearDown() override;
protected: protected:
sp<IDevice> device; const sp<IDevice> device = ::testing::VtsHalHidlTargetTestBase::getService<IDevice>(
NeuralnetworksHidlEnvironment::getInstance());
}; };
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_1::vts::functional
} // namespace vts
} // namespace V1_1
} // namespace neuralnetworks
} // namespace hardware
} // namespace android
namespace android::hardware::neuralnetworks::V1_0 { namespace android::hardware::neuralnetworks::V1_0 {

View file

@ -18,13 +18,10 @@
#include "VtsHalNeuralnetworks.h" #include "VtsHalNeuralnetworks.h"
namespace android { namespace android::hardware::neuralnetworks::V1_2::vts::functional {
namespace hardware {
namespace neuralnetworks {
namespace V1_2 {
namespace vts {
namespace functional {
using V1_0::DeviceStatus;
using V1_0::ErrorStatus;
using V1_0::PerformanceInfo; using V1_0::PerformanceInfo;
// create device test // create device test
@ -113,9 +110,4 @@ TEST_F(NeuralnetworksHidlTest, getNumberOfCacheFilesNeeded) {
}); });
EXPECT_TRUE(ret.isOk()); EXPECT_TRUE(ret.isOk());
} }
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_2::vts::functional
} // namespace vts
} // namespace V1_2
} // namespace neuralnetworks
} // namespace hardware
} // namespace android

View file

@ -24,6 +24,8 @@
namespace android::hardware::neuralnetworks::V1_2::implementation { namespace android::hardware::neuralnetworks::V1_2::implementation {
using V1_0::ErrorStatus;
constexpr Timing kNoTiming = {.timeOnDevice = std::numeric_limits<uint64_t>::max(), constexpr Timing kNoTiming = {.timeOnDevice = std::numeric_limits<uint64_t>::max(),
.timeInDriver = std::numeric_limits<uint64_t>::max()}; .timeInDriver = std::numeric_limits<uint64_t>::max()};

View file

@ -17,7 +17,6 @@
#define LOG_TAG "neuralnetworks_hidl_hal_test" #define LOG_TAG "neuralnetworks_hidl_hal_test"
#include <android-base/logging.h> #include <android-base/logging.h>
#include <android/hidl/memory/1.0/IMemory.h>
#include <ftw.h> #include <ftw.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <hidlmemory/mapping.h> #include <hidlmemory/mapping.h>
@ -45,20 +44,12 @@ namespace generated_tests::mobilenet_quantized {
const ::test_helper::TestModel& get_test_model(); const ::test_helper::TestModel& get_test_model();
} // namespace generated_tests::mobilenet_quantized } // namespace generated_tests::mobilenet_quantized
namespace android { namespace android::hardware::neuralnetworks::V1_2::vts::functional {
namespace hardware {
namespace neuralnetworks {
namespace V1_2 {
namespace vts {
namespace functional {
using namespace test_helper; using namespace test_helper;
using ::android::hardware::neuralnetworks::V1_0::OperandLifeTime; using implementation::PreparedModelCallback;
using ::android::hardware::neuralnetworks::V1_1::ExecutionPreference; using V1_0::ErrorStatus;
using ::android::hardware::neuralnetworks::V1_2::implementation::ExecutionCallback; using V1_1::ExecutionPreference;
using ::android::hardware::neuralnetworks::V1_2::implementation::PreparedModelCallback;
using ::android::hidl::memory::V1_0::IMemory;
using ::android::nn::allocateSharedMemory;
namespace float32_model { namespace float32_model {
@ -307,7 +298,7 @@ class CompilationCachingTestBase : public NeuralnetworksHidlTest {
} }
// See if the service can handle the model. // See if the service can handle the model.
bool isModelFullySupported(const V1_2::Model& model) { bool isModelFullySupported(const Model& model) {
bool fullySupportsModel = false; bool fullySupportsModel = false;
Return<void> supportedCall = device->getSupportedOperations_1_2( Return<void> supportedCall = device->getSupportedOperations_1_2(
model, model,
@ -321,14 +312,13 @@ class CompilationCachingTestBase : public NeuralnetworksHidlTest {
return fullySupportsModel; return fullySupportsModel;
} }
void saveModelToCache(const V1_2::Model& model, const hidl_vec<hidl_handle>& modelCache, void saveModelToCache(const Model& model, const hidl_vec<hidl_handle>& modelCache,
const hidl_vec<hidl_handle>& dataCache, const hidl_vec<hidl_handle>& dataCache,
sp<IPreparedModel>* preparedModel = nullptr) { sp<IPreparedModel>* preparedModel = nullptr) {
if (preparedModel != nullptr) *preparedModel = nullptr; if (preparedModel != nullptr) *preparedModel = nullptr;
// Launch prepare model. // Launch prepare model.
sp<PreparedModelCallback> preparedModelCallback = new PreparedModelCallback(); sp<PreparedModelCallback> preparedModelCallback = new PreparedModelCallback();
ASSERT_NE(nullptr, preparedModelCallback.get());
hidl_array<uint8_t, sizeof(mToken)> cacheToken(mToken); hidl_array<uint8_t, sizeof(mToken)> cacheToken(mToken);
Return<ErrorStatus> prepareLaunchStatus = Return<ErrorStatus> prepareLaunchStatus =
device->prepareModel_1_2(model, ExecutionPreference::FAST_SINGLE_ANSWER, modelCache, device->prepareModel_1_2(model, ExecutionPreference::FAST_SINGLE_ANSWER, modelCache,
@ -340,9 +330,8 @@ class CompilationCachingTestBase : public NeuralnetworksHidlTest {
preparedModelCallback->wait(); preparedModelCallback->wait();
ASSERT_EQ(preparedModelCallback->getStatus(), ErrorStatus::NONE); ASSERT_EQ(preparedModelCallback->getStatus(), ErrorStatus::NONE);
if (preparedModel != nullptr) { if (preparedModel != nullptr) {
*preparedModel = *preparedModel = IPreparedModel::castFrom(preparedModelCallback->getPreparedModel())
V1_2::IPreparedModel::castFrom(preparedModelCallback->getPreparedModel()) .withDefault(nullptr);
.withDefault(nullptr);
} }
} }
@ -358,7 +347,7 @@ class CompilationCachingTestBase : public NeuralnetworksHidlTest {
return false; return false;
} }
bool checkEarlyTermination(const V1_2::Model& model) { bool checkEarlyTermination(const Model& model) {
if (!isModelFullySupported(model)) { if (!isModelFullySupported(model)) {
LOG(INFO) << "NN VTS: Early termination of test because vendor service cannot " LOG(INFO) << "NN VTS: Early termination of test because vendor service cannot "
"prepare model that it does not support."; "prepare model that it does not support.";
@ -375,7 +364,6 @@ class CompilationCachingTestBase : public NeuralnetworksHidlTest {
sp<IPreparedModel>* preparedModel, ErrorStatus* status) { sp<IPreparedModel>* preparedModel, ErrorStatus* status) {
// Launch prepare model from cache. // Launch prepare model from cache.
sp<PreparedModelCallback> preparedModelCallback = new PreparedModelCallback(); sp<PreparedModelCallback> preparedModelCallback = new PreparedModelCallback();
ASSERT_NE(nullptr, preparedModelCallback.get());
hidl_array<uint8_t, sizeof(mToken)> cacheToken(mToken); hidl_array<uint8_t, sizeof(mToken)> cacheToken(mToken);
Return<ErrorStatus> prepareLaunchStatus = device->prepareModelFromCache( Return<ErrorStatus> prepareLaunchStatus = device->prepareModelFromCache(
modelCache, dataCache, cacheToken, preparedModelCallback); modelCache, dataCache, cacheToken, preparedModelCallback);
@ -389,7 +377,7 @@ class CompilationCachingTestBase : public NeuralnetworksHidlTest {
// Retrieve prepared model. // Retrieve prepared model.
preparedModelCallback->wait(); preparedModelCallback->wait();
*status = preparedModelCallback->getStatus(); *status = preparedModelCallback->getStatus();
*preparedModel = V1_2::IPreparedModel::castFrom(preparedModelCallback->getPreparedModel()) *preparedModel = IPreparedModel::castFrom(preparedModelCallback->getPreparedModel())
.withDefault(nullptr); .withDefault(nullptr);
} }
@ -1353,9 +1341,4 @@ TEST_P(CompilationCachingSecurityTest, WrongToken) {
INSTANTIATE_TEST_CASE_P(TestCompilationCaching, CompilationCachingSecurityTest, INSTANTIATE_TEST_CASE_P(TestCompilationCaching, CompilationCachingSecurityTest,
::testing::Combine(kOperandTypeChoices, ::testing::Range(0U, 10U))); ::testing::Combine(kOperandTypeChoices, ::testing::Range(0U, 10U)));
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_2::vts::functional
} // namespace vts
} // namespace V1_2
} // namespace neuralnetworks
} // namespace hardware
} // namespace android

View file

@ -44,30 +44,17 @@
#include "Utils.h" #include "Utils.h"
#include "VtsHalNeuralnetworks.h" #include "VtsHalNeuralnetworks.h"
namespace android { namespace android::hardware::neuralnetworks::V1_2::vts::functional {
namespace hardware {
namespace neuralnetworks {
namespace V1_2 {
namespace vts {
namespace functional {
using namespace test_helper; using namespace test_helper;
using ::android::hardware::neuralnetworks::V1_0::DataLocation; using hidl::memory::V1_0::IMemory;
using ::android::hardware::neuralnetworks::V1_0::ErrorStatus; using implementation::ExecutionCallback;
using ::android::hardware::neuralnetworks::V1_0::OperandLifeTime; using implementation::PreparedModelCallback;
using ::android::hardware::neuralnetworks::V1_0::Request; using V1_0::DataLocation;
using ::android::hardware::neuralnetworks::V1_0::RequestArgument; using V1_0::ErrorStatus;
using ::android::hardware::neuralnetworks::V1_1::ExecutionPreference; using V1_0::OperandLifeTime;
using ::android::hardware::neuralnetworks::V1_2::Constant; using V1_0::Request;
using ::android::hardware::neuralnetworks::V1_2::IDevice; using V1_1::ExecutionPreference;
using ::android::hardware::neuralnetworks::V1_2::IPreparedModel;
using ::android::hardware::neuralnetworks::V1_2::MeasureTiming;
using ::android::hardware::neuralnetworks::V1_2::Model;
using ::android::hardware::neuralnetworks::V1_2::OutputShape;
using ::android::hardware::neuralnetworks::V1_2::Timing;
using ::android::hardware::neuralnetworks::V1_2::implementation::ExecutionCallback;
using ::android::hardware::neuralnetworks::V1_2::implementation::PreparedModelCallback;
using ::android::hidl::memory::V1_0::IMemory;
using HidlToken = hidl_array<uint8_t, static_cast<uint32_t>(Constant::BYTE_SIZE_OF_CACHE_TOKEN)>; using HidlToken = hidl_array<uint8_t, static_cast<uint32_t>(Constant::BYTE_SIZE_OF_CACHE_TOKEN)>;
enum class OutputType { FULLY_SPECIFIED, UNSPECIFIED, INSUFFICIENT }; enum class OutputType { FULLY_SPECIFIED, UNSPECIFIED, INSUFFICIENT };
@ -447,9 +434,4 @@ INSTANTIATE_GENERATED_TEST(GeneratedTest,
INSTANTIATE_GENERATED_TEST(DynamicOutputShapeTest, INSTANTIATE_GENERATED_TEST(DynamicOutputShapeTest,
[](const TestModel& testModel) { return !testModel.expectFailure; }); [](const TestModel& testModel) { return !testModel.expectFailure; });
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_2::vts::functional
} // namespace vts
} // namespace V1_2
} // namespace neuralnetworks
} // namespace hardware
} // namespace android

View file

@ -25,12 +25,7 @@
#include "TestHarness.h" #include "TestHarness.h"
#include "VtsHalNeuralnetworks.h" #include "VtsHalNeuralnetworks.h"
namespace android { namespace android::hardware::neuralnetworks::V1_2::vts::functional {
namespace hardware {
namespace neuralnetworks {
namespace V1_2 {
namespace vts {
namespace functional {
class GeneratedTestBase class GeneratedTestBase
: public NeuralnetworksHidlTest, : public NeuralnetworksHidlTest,
@ -54,29 +49,24 @@ class GeneratedTestBase
// TODO: Clean up the hierarchy for ValidationTest. // TODO: Clean up the hierarchy for ValidationTest.
class ValidationTest : public GeneratedTestBase { class ValidationTest : public GeneratedTestBase {
protected: protected:
void validateEverything(const Model& model, const Request& request); void validateEverything(const Model& model, const V1_0::Request& request);
void validateFailure(const Model& model, const Request& request); void validateFailure(const Model& model, const V1_0::Request& request);
private: private:
void validateModel(const Model& model); void validateModel(const Model& model);
void validateRequest(const sp<IPreparedModel>& preparedModel, const Request& request); void validateRequest(const sp<IPreparedModel>& preparedModel, const V1_0::Request& request);
void validateRequestFailure(const sp<IPreparedModel>& preparedModel, const Request& request); void validateRequestFailure(const sp<IPreparedModel>& preparedModel,
void validateBurst(const sp<IPreparedModel>& preparedModel, const Request& request); const V1_0::Request& request);
void validateBurst(const sp<IPreparedModel>& preparedModel, const V1_0::Request& request);
}; };
Model createModel(const ::test_helper::TestModel& testModel); Model createModel(const ::test_helper::TestModel& testModel);
void PrepareModel(const sp<V1_2::IDevice>& device, const V1_2::Model& model, void PrepareModel(const sp<IDevice>& device, const Model& model, sp<IPreparedModel>* preparedModel);
sp<V1_2::IPreparedModel>* preparedModel);
void EvaluatePreparedModel(const sp<V1_2::IPreparedModel>& preparedModel, void EvaluatePreparedModel(const sp<IPreparedModel>& preparedModel,
const ::test_helper::TestModel& testModel, bool testDynamicOutputShape); const ::test_helper::TestModel& testModel, bool testDynamicOutputShape);
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_2::vts::functional
} // namespace vts
} // namespace V1_2
} // namespace neuralnetworks
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_NEURALNETWORKS_V1_2_GENERATED_TEST_HARNESS_H #endif // ANDROID_HARDWARE_NEURALNETWORKS_V1_2_GENERATED_TEST_HARNESS_H

View file

@ -27,17 +27,14 @@
#include <android-base/logging.h> #include <android-base/logging.h>
namespace android { namespace android::hardware::neuralnetworks::V1_2::vts::functional {
namespace hardware {
namespace neuralnetworks {
namespace V1_2 {
namespace vts {
namespace functional {
using ::android::nn::ExecutionBurstController; using nn::ExecutionBurstController;
using ::android::nn::RequestChannelSender; using nn::RequestChannelSender;
using ::android::nn::ResultChannelReceiver; using nn::ResultChannelReceiver;
using ExecutionBurstCallback = ::android::nn::ExecutionBurstController::ExecutionBurstCallback; using V1_0::ErrorStatus;
using V1_0::Request;
using ExecutionBurstCallback = ExecutionBurstController::ExecutionBurstCallback;
// This constant value represents the length of an FMQ that is large enough to // This constant value represents the length of an FMQ that is large enough to
// return a result from a burst execution for all of the generated test cases. // return a result from a burst execution for all of the generated test cases.
@ -324,9 +321,4 @@ void ValidationTest::validateBurst(const sp<IPreparedModel>& preparedModel,
ASSERT_NO_FATAL_FAILURE(validateBurstFmqLength(preparedModel, request)); ASSERT_NO_FATAL_FAILURE(validateBurstFmqLength(preparedModel, request));
} }
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_2::vts::functional
} // namespace vts
} // namespace V1_2
} // namespace neuralnetworks
} // namespace hardware
} // namespace android

View file

@ -21,19 +21,12 @@
#include "GeneratedTestHarness.h" #include "GeneratedTestHarness.h"
#include "VtsHalNeuralnetworks.h" #include "VtsHalNeuralnetworks.h"
namespace android { namespace android::hardware::neuralnetworks::V1_2::vts::functional {
namespace hardware {
namespace neuralnetworks {
namespace V1_2 {
using implementation::PreparedModelCallback;
using V1_0::ErrorStatus;
using V1_0::OperandLifeTime; using V1_0::OperandLifeTime;
using V1_1::ExecutionPreference; using V1_1::ExecutionPreference;
namespace vts {
namespace functional {
using ::android::hardware::neuralnetworks::V1_2::implementation::ExecutionCallback;
using ::android::hardware::neuralnetworks::V1_2::implementation::PreparedModelCallback;
using HidlToken = hidl_array<uint8_t, static_cast<uint32_t>(Constant::BYTE_SIZE_OF_CACHE_TOKEN)>; using HidlToken = hidl_array<uint8_t, static_cast<uint32_t>(Constant::BYTE_SIZE_OF_CACHE_TOKEN)>;
///////////////////////// UTILITY FUNCTIONS ///////////////////////// ///////////////////////// UTILITY FUNCTIONS /////////////////////////
@ -54,7 +47,6 @@ static void validatePrepareModel(const sp<IDevice>& device, const std::string& m
SCOPED_TRACE(message + " [prepareModel_1_2]"); SCOPED_TRACE(message + " [prepareModel_1_2]");
sp<PreparedModelCallback> preparedModelCallback = new PreparedModelCallback(); sp<PreparedModelCallback> preparedModelCallback = new PreparedModelCallback();
ASSERT_NE(nullptr, preparedModelCallback.get());
Return<ErrorStatus> prepareLaunchStatus = Return<ErrorStatus> prepareLaunchStatus =
device->prepareModel_1_2(model, preference, hidl_vec<hidl_handle>(), device->prepareModel_1_2(model, preference, hidl_vec<hidl_handle>(),
hidl_vec<hidl_handle>(), HidlToken(), preparedModelCallback); hidl_vec<hidl_handle>(), HidlToken(), preparedModelCallback);
@ -692,8 +684,9 @@ static void mutateExecutionPreferenceTest(const sp<IDevice>& device, const Model
for (int32_t preference : invalidExecutionPreferences) { for (int32_t preference : invalidExecutionPreferences) {
const std::string message = const std::string message =
"mutateExecutionPreferenceTest: preference " + std::to_string(preference); "mutateExecutionPreferenceTest: preference " + std::to_string(preference);
validate(device, message, model, [](Model*) {}, validate(
static_cast<ExecutionPreference>(preference)); device, message, model, [](Model*) {},
static_cast<ExecutionPreference>(preference));
} }
} }
@ -717,9 +710,4 @@ void ValidationTest::validateModel(const Model& model) {
mutateExecutionPreferenceTest(device, model); mutateExecutionPreferenceTest(device, model);
} }
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_2::vts::functional
} // namespace vts
} // namespace V1_2
} // namespace neuralnetworks
} // namespace hardware
} // namespace android

View file

@ -24,14 +24,11 @@
#include "Utils.h" #include "Utils.h"
#include "VtsHalNeuralnetworks.h" #include "VtsHalNeuralnetworks.h"
namespace android { namespace android::hardware::neuralnetworks::V1_2::vts::functional {
namespace hardware {
namespace neuralnetworks {
namespace V1_2 {
namespace vts {
namespace functional {
using ::android::hardware::neuralnetworks::V1_2::implementation::ExecutionCallback; using implementation::ExecutionCallback;
using V1_0::ErrorStatus;
using V1_0::Request;
///////////////////////// UTILITY FUNCTIONS ///////////////////////// ///////////////////////// UTILITY FUNCTIONS /////////////////////////
@ -62,7 +59,6 @@ static void validate(const sp<IPreparedModel>& preparedModel, const std::string&
SCOPED_TRACE(message + " [execute_1_2]"); SCOPED_TRACE(message + " [execute_1_2]");
sp<ExecutionCallback> executionCallback = new ExecutionCallback(); sp<ExecutionCallback> executionCallback = new ExecutionCallback();
ASSERT_NE(nullptr, executionCallback.get());
Return<ErrorStatus> executeLaunchStatus = Return<ErrorStatus> executeLaunchStatus =
preparedModel->execute_1_2(request, measure, executionCallback); preparedModel->execute_1_2(request, measure, executionCallback);
ASSERT_TRUE(executeLaunchStatus.isOk()); ASSERT_TRUE(executeLaunchStatus.isOk());
@ -171,9 +167,4 @@ void ValidationTest::validateRequestFailure(const sp<IPreparedModel>& preparedMo
ASSERT_TRUE(executeStatus.isOk()); ASSERT_TRUE(executeStatus.isOk());
} }
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_2::vts::functional
} // namespace vts
} // namespace V1_2
} // namespace neuralnetworks
} // namespace hardware
} // namespace android

View file

@ -24,15 +24,12 @@
#include <android-base/logging.h> #include <android-base/logging.h>
namespace android { namespace android::hardware::neuralnetworks::V1_2::vts::functional {
namespace hardware {
namespace neuralnetworks {
namespace V1_2 {
namespace vts {
namespace functional {
using ::android::hardware::neuralnetworks::V1_2::implementation::PreparedModelCallback; using implementation::PreparedModelCallback;
using HidlToken = hidl_array<uint8_t, static_cast<uint32_t>(Constant::BYTE_SIZE_OF_CACHE_TOKEN)>; using HidlToken = hidl_array<uint8_t, static_cast<uint32_t>(Constant::BYTE_SIZE_OF_CACHE_TOKEN)>;
using V1_0::ErrorStatus;
using V1_0::Request;
using V1_1::ExecutionPreference; using V1_1::ExecutionPreference;
// internal helper function // internal helper function
@ -53,7 +50,6 @@ static void createPreparedModel(const sp<IDevice>& device, const Model& model,
// launch prepare model // launch prepare model
sp<PreparedModelCallback> preparedModelCallback = new PreparedModelCallback(); sp<PreparedModelCallback> preparedModelCallback = new PreparedModelCallback();
ASSERT_NE(nullptr, preparedModelCallback.get());
Return<ErrorStatus> prepareLaunchStatus = device->prepareModel_1_2( Return<ErrorStatus> prepareLaunchStatus = device->prepareModel_1_2(
model, ExecutionPreference::FAST_SINGLE_ANSWER, hidl_vec<hidl_handle>(), model, ExecutionPreference::FAST_SINGLE_ANSWER, hidl_vec<hidl_handle>(),
hidl_vec<hidl_handle>(), HidlToken(), preparedModelCallback); hidl_vec<hidl_handle>(), HidlToken(), preparedModelCallback);
@ -86,10 +82,6 @@ static void createPreparedModel(const sp<IDevice>& device, const Model& model,
} }
// A class for test environment setup // A class for test environment setup
NeuralnetworksHidlEnvironment::NeuralnetworksHidlEnvironment() {}
NeuralnetworksHidlEnvironment::~NeuralnetworksHidlEnvironment() {}
NeuralnetworksHidlEnvironment* NeuralnetworksHidlEnvironment::getInstance() { NeuralnetworksHidlEnvironment* NeuralnetworksHidlEnvironment::getInstance() {
// This has to return a "new" object because it is freed inside // This has to return a "new" object because it is freed inside
// ::testing::AddGlobalTestEnvironment when the gtest is being torn down // ::testing::AddGlobalTestEnvironment when the gtest is being torn down
@ -102,14 +94,8 @@ void NeuralnetworksHidlEnvironment::registerTestServices() {
} }
// The main test class for NEURALNETWORK HIDL HAL. // The main test class for NEURALNETWORK HIDL HAL.
NeuralnetworksHidlTest::NeuralnetworksHidlTest() {}
NeuralnetworksHidlTest::~NeuralnetworksHidlTest() {}
void NeuralnetworksHidlTest::SetUp() { void NeuralnetworksHidlTest::SetUp() {
::testing::VtsHalHidlTargetTestBase::SetUp(); ::testing::VtsHalHidlTargetTestBase::SetUp();
device = ::testing::VtsHalHidlTargetTestBase::getService<IDevice>(
NeuralnetworksHidlEnvironment::getInstance());
#ifdef PRESUBMIT_NOT_VTS #ifdef PRESUBMIT_NOT_VTS
const std::string name = const std::string name =
@ -124,7 +110,6 @@ void NeuralnetworksHidlTest::SetUp() {
} }
void NeuralnetworksHidlTest::TearDown() { void NeuralnetworksHidlTest::TearDown() {
device = nullptr;
::testing::VtsHalHidlTargetTestBase::TearDown(); ::testing::VtsHalHidlTargetTestBase::TearDown();
} }
@ -168,18 +153,12 @@ TEST_P(ValidationTest, Test) {
INSTANTIATE_GENERATED_TEST(ValidationTest, [](const test_helper::TestModel&) { return true; }); INSTANTIATE_GENERATED_TEST(ValidationTest, [](const test_helper::TestModel&) { return true; });
sp<IPreparedModel> getPreparedModel_1_2( sp<IPreparedModel> getPreparedModel_1_2(const sp<implementation::PreparedModelCallback>& callback) {
const sp<V1_2::implementation::PreparedModelCallback>& callback) {
sp<V1_0::IPreparedModel> preparedModelV1_0 = callback->getPreparedModel(); sp<V1_0::IPreparedModel> preparedModelV1_0 = callback->getPreparedModel();
return V1_2::IPreparedModel::castFrom(preparedModelV1_0).withDefault(nullptr); return IPreparedModel::castFrom(preparedModelV1_0).withDefault(nullptr);
} }
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_2::vts::functional
} // namespace vts
} // namespace V1_2
} // namespace neuralnetworks
} // namespace hardware
} // namespace android
namespace android::hardware::neuralnetworks::V1_0 { namespace android::hardware::neuralnetworks::V1_0 {

View file

@ -32,23 +32,12 @@
#include "1.2/Callbacks.h" #include "1.2/Callbacks.h"
#include "TestHarness.h" #include "TestHarness.h"
namespace android { namespace android::hardware::neuralnetworks::V1_2::vts::functional {
namespace hardware {
namespace neuralnetworks {
namespace V1_2 {
using V1_0::DeviceStatus;
using V1_0::ErrorStatus;
using V1_0::Request;
namespace vts {
namespace functional {
// A class for test environment setup // A class for test environment setup
class NeuralnetworksHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { class NeuralnetworksHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
DISALLOW_COPY_AND_ASSIGN(NeuralnetworksHidlEnvironment); DISALLOW_COPY_AND_ASSIGN(NeuralnetworksHidlEnvironment);
NeuralnetworksHidlEnvironment(); NeuralnetworksHidlEnvironment() = default;
~NeuralnetworksHidlEnvironment() override;
public: public:
static NeuralnetworksHidlEnvironment* getInstance(); static NeuralnetworksHidlEnvironment* getInstance();
@ -60,25 +49,19 @@ class NeuralnetworksHidlTest : public ::testing::VtsHalHidlTargetTestBase {
DISALLOW_COPY_AND_ASSIGN(NeuralnetworksHidlTest); DISALLOW_COPY_AND_ASSIGN(NeuralnetworksHidlTest);
public: public:
NeuralnetworksHidlTest(); NeuralnetworksHidlTest() = default;
~NeuralnetworksHidlTest() override;
void SetUp() override; void SetUp() override;
void TearDown() override; void TearDown() override;
protected: protected:
sp<IDevice> device; const sp<IDevice> device = ::testing::VtsHalHidlTargetTestBase::getService<IDevice>(
NeuralnetworksHidlEnvironment::getInstance());
}; };
// Utility function to get PreparedModel from callback and downcast to V1_2. // Utility function to get PreparedModel from callback and downcast to V1_2.
sp<IPreparedModel> getPreparedModel_1_2( sp<IPreparedModel> getPreparedModel_1_2(const sp<implementation::PreparedModelCallback>& callback);
const sp<V1_2::implementation::PreparedModelCallback>& callback);
} // namespace functional } // namespace android::hardware::neuralnetworks::V1_2::vts::functional
} // namespace vts
} // namespace V1_2
} // namespace neuralnetworks
} // namespace hardware
} // namespace android
namespace android::hardware::neuralnetworks::V1_0 { namespace android::hardware::neuralnetworks::V1_0 {

View file

@ -46,8 +46,6 @@
namespace android::hardware::neuralnetworks::V1_2::implementation { namespace android::hardware::neuralnetworks::V1_2::implementation {
using V1_0::ErrorStatus;
/** /**
* The PreparedModelCallback class is used to receive the error status of * The PreparedModelCallback class is used to receive the error status of
* preparing a model as well as the prepared model from a task executing * preparing a model as well as the prepared model from a task executing
@ -87,7 +85,8 @@ class PreparedModelCallback : public IPreparedModelCallback {
* @param preparedModel Returned model that has been prepared for execution, * @param preparedModel Returned model that has been prepared for execution,
* nullptr if the model was unable to be prepared. * nullptr if the model was unable to be prepared.
*/ */
Return<void> notify(ErrorStatus status, const sp<V1_0::IPreparedModel>& preparedModel) override; Return<void> notify(V1_0::ErrorStatus status,
const sp<V1_0::IPreparedModel>& preparedModel) override;
/** /**
* IPreparedModelCallback::notify_1_2 marks the callback object with the * IPreparedModelCallback::notify_1_2 marks the callback object with the
@ -112,7 +111,7 @@ class PreparedModelCallback : public IPreparedModelCallback {
* @param preparedModel Returned model that has been prepared for execution, * @param preparedModel Returned model that has been prepared for execution,
* nullptr if the model was unable to be prepared. * nullptr if the model was unable to be prepared.
*/ */
Return<void> notify_1_2(ErrorStatus status, Return<void> notify_1_2(V1_0::ErrorStatus status,
const sp<V1_2::IPreparedModel>& preparedModel) override; const sp<V1_2::IPreparedModel>& preparedModel) override;
/** /**
@ -134,7 +133,7 @@ class PreparedModelCallback : public IPreparedModelCallback {
* - GENERAL_FAILURE if there is an unspecified error * - GENERAL_FAILURE if there is an unspecified error
* - INVALID_ARGUMENT if the input model is invalid * - INVALID_ARGUMENT if the input model is invalid
*/ */
ErrorStatus getStatus() const; V1_0::ErrorStatus getStatus() const;
/** /**
* Retrieves the model that has been prepared for execution from the * Retrieves the model that has been prepared for execution from the
@ -152,7 +151,7 @@ class PreparedModelCallback : public IPreparedModelCallback {
mutable std::mutex mMutex; mutable std::mutex mMutex;
mutable std::condition_variable mCondition; mutable std::condition_variable mCondition;
bool mNotified GUARDED_BY(mMutex) = false; bool mNotified GUARDED_BY(mMutex) = false;
ErrorStatus mErrorStatus = ErrorStatus::GENERAL_FAILURE; V1_0::ErrorStatus mErrorStatus = V1_0::ErrorStatus::GENERAL_FAILURE;
sp<V1_0::IPreparedModel> mPreparedModel; sp<V1_0::IPreparedModel> mPreparedModel;
}; };
@ -195,7 +194,7 @@ class ExecutionCallback : public IExecutionCallback {
* enough to store the resultant values * enough to store the resultant values
* - INVALID_ARGUMENT if the input request is invalid * - INVALID_ARGUMENT if the input request is invalid
*/ */
Return<void> notify(ErrorStatus status) override; Return<void> notify(V1_0::ErrorStatus status) override;
/** /**
* IExecutionCallback::notify_1_2 marks the callback object with the results * IExecutionCallback::notify_1_2 marks the callback object with the results
@ -230,11 +229,11 @@ class ExecutionCallback : public IExecutionCallback {
* reported as UINT64_MAX. A driver may choose to report any time as * reported as UINT64_MAX. A driver may choose to report any time as
* UINT64_MAX, indicating that particular measurement is not available. * UINT64_MAX, indicating that particular measurement is not available.
*/ */
Return<void> notify_1_2(ErrorStatus status, const hidl_vec<OutputShape>& outputShapes, Return<void> notify_1_2(V1_0::ErrorStatus status, const hidl_vec<OutputShape>& outputShapes,
const Timing& timing) override; const Timing& timing) override;
// An overload of the latest notify interface to hide the version from ExecutionBuilder. // An overload of the latest notify interface to hide the version from ExecutionBuilder.
Return<void> notify(ErrorStatus status, const hidl_vec<OutputShape>& outputShapes, Return<void> notify(V1_0::ErrorStatus status, const hidl_vec<OutputShape>& outputShapes,
const Timing& timing) { const Timing& timing) {
return notify_1_2(status, outputShapes, timing); return notify_1_2(status, outputShapes, timing);
} }
@ -264,7 +263,7 @@ class ExecutionCallback : public IExecutionCallback {
* - INVALID_ARGUMENT if one of the input arguments to prepareModel is * - INVALID_ARGUMENT if one of the input arguments to prepareModel is
* invalid * invalid
*/ */
ErrorStatus getStatus() const; V1_0::ErrorStatus getStatus() const;
/** /**
* Retrieves the output shapes returned from the asynchronous task launched * Retrieves the output shapes returned from the asynchronous task launched
@ -309,14 +308,14 @@ class ExecutionCallback : public IExecutionCallback {
* object before any call to wait or get* return. It then enables all prior * object before any call to wait or get* return. It then enables all prior
* and future wait calls on the ExecutionCallback object to proceed. * and future wait calls on the ExecutionCallback object to proceed.
*/ */
void notifyInternal(ErrorStatus errorStatus, const hidl_vec<OutputShape>& outputShapes, void notifyInternal(V1_0::ErrorStatus errorStatus, const hidl_vec<OutputShape>& outputShapes,
const Timing& timing); const Timing& timing);
// members // members
mutable std::mutex mMutex; mutable std::mutex mMutex;
mutable std::condition_variable mCondition; mutable std::condition_variable mCondition;
bool mNotified GUARDED_BY(mMutex) = false; bool mNotified GUARDED_BY(mMutex) = false;
ErrorStatus mErrorStatus = ErrorStatus::GENERAL_FAILURE; V1_0::ErrorStatus mErrorStatus = V1_0::ErrorStatus::GENERAL_FAILURE;
std::vector<OutputShape> mOutputShapes = {}; std::vector<OutputShape> mOutputShapes = {};
Timing mTiming = {}; Timing mTiming = {};
}; };