Revert "Provide explicitly versioned NNAPI AIDL utils libs -- HAL."

Revert "Use explicitly versioned NNAPI HAL util libs in darwinn2."

Revert "Add neuralnetworks_utils_hal_aidl_v2 to allowed_deps.txt"

Revert "Provide explicitly version NNAPI AIDL utils lib -- runtime."

Revert submission 16007539-nnapi-experimental-aidl-feature

Reason for revert: The cherry-pick of this CL breaks the build
Reverted Changes:
Ieb2da3461:Add neuralnetworks_utils_hal_aidl_v2 to allowed_de...
I8ae01e3c6:Provide explicitly version NNAPI AIDL utils lib --...
I74f1798e8:Provide explicitly versioned NNAPI AIDL utils libs...
I2362464e8:Use explicitly versioned NNAPI HAL util libs in da...

Test: mma

Change-Id: I3d3ac4745fb707cbdceb2019f3c2fc7807183b71
Merged-In: I3d3ac4745fb707cbdceb2019f3c2fc7807183b71
(cherry picked from commit 932e82b0c3)
This commit is contained in:
Michael Butler 2021-10-26 03:29:13 +00:00
parent cb2c37f78f
commit c42a934ea8
16 changed files with 127 additions and 203 deletions

View file

@ -49,7 +49,7 @@ cc_test {
static_libs: [
"android.hardware.neuralnetworks@1.0",
"libgmock",
"libneuralnetworks_common_hidl",
"libneuralnetworks_common",
"neuralnetworks_types",
"neuralnetworks_utils_hal_common",
"neuralnetworks_utils_hal_1_0",

View file

@ -50,7 +50,7 @@ cc_library_static {
"libgmock",
"libhidlmemory",
"libneuralnetworks_generated_test_harness",
"libneuralnetworks_common_hidl",
"libneuralnetworks_utils",
],
header_libs: [
"libneuralnetworks_headers",
@ -81,7 +81,7 @@ cc_test {
"libgmock",
"libhidlmemory",
"libneuralnetworks_generated_test_harness",
"libneuralnetworks_common_hidl",
"libneuralnetworks_utils",
],
whole_static_libs: [
"neuralnetworks_generated_V1_0_example",

View file

@ -52,7 +52,7 @@ cc_test {
"android.hardware.neuralnetworks@1.0",
"android.hardware.neuralnetworks@1.1",
"libgmock",
"libneuralnetworks_common_hidl",
"libneuralnetworks_common",
"neuralnetworks_types",
"neuralnetworks_utils_hal_common",
"neuralnetworks_utils_hal_1_0",

View file

@ -48,7 +48,7 @@ cc_test {
"libgmock",
"libhidlmemory",
"libneuralnetworks_generated_test_harness",
"libneuralnetworks_common_hidl",
"libneuralnetworks_utils",
],
whole_static_libs: [
"neuralnetworks_generated_V1_0_example",

View file

@ -71,7 +71,7 @@ cc_test {
"android.hardware.neuralnetworks@1.1",
"android.hardware.neuralnetworks@1.2",
"libgmock",
"libneuralnetworks_common_hidl",
"libneuralnetworks_common",
"neuralnetworks_types",
"neuralnetworks_utils_hal_common",
"neuralnetworks_utils_hal_1_0",

View file

@ -71,7 +71,7 @@ cc_test {
"libgmock",
"libhidlmemory",
"libneuralnetworks_generated_test_harness",
"libneuralnetworks_common_hidl",
"libneuralnetworks_utils",
],
whole_static_libs: [
"neuralnetworks_generated_V1_0_example",

View file

@ -69,7 +69,7 @@ cc_test {
"android.hardware.neuralnetworks@1.2",
"android.hardware.neuralnetworks@1.3",
"libgmock",
"libneuralnetworks_common_hidl",
"libneuralnetworks_common",
"neuralnetworks_types",
"neuralnetworks_utils_hal_common",
"neuralnetworks_utils_hal_1_0",

View file

@ -66,6 +66,7 @@ cc_test {
"VtsHalNeuralNetworksV1_0_utils",
"VtsHalNeuralNetworksV1_2_utils",
"VtsHalNeuralNetworksV1_3_utils",
"android.hardware.neuralnetworks-V2-ndk",
"android.hardware.neuralnetworks@1.0",
"android.hardware.neuralnetworks@1.1",
"android.hardware.neuralnetworks@1.2",
@ -75,7 +76,7 @@ cc_test {
"libgmock",
"libhidlmemory",
"libneuralnetworks_generated_test_harness",
"libneuralnetworks_common_hidl",
"libneuralnetworks_utils",
"libsync",
],
whole_static_libs: [

View file

@ -23,8 +23,8 @@ package {
default_applicable_licenses: ["hardware_interfaces_license"],
}
cc_defaults {
name: "neuralnetworks_utils_hal_aidl_defaults",
cc_library_static {
name: "neuralnetworks_utils_hal_aidl",
defaults: ["neuralnetworks_utils_defaults"],
srcs: ["src/*"],
local_include_dirs: ["include/nnapi/hal/aidl/"],
@ -38,6 +38,7 @@ cc_defaults {
"neuralnetworks_utils_hal_common",
],
shared_libs: [
"android.hardware.neuralnetworks-V2-ndk",
"libbinder_ndk",
"libhidlbase",
],
@ -48,49 +49,21 @@ cc_defaults {
},
}
cc_library_static {
name: "neuralnetworks_utils_hal_aidl_v1",
defaults: ["neuralnetworks_utils_hal_aidl_defaults"],
shared_libs: [
"android.hardware.neuralnetworks-V1-ndk",
],
}
cc_library_static {
name: "neuralnetworks_utils_hal_aidl_v2",
defaults: ["neuralnetworks_utils_hal_aidl_defaults"],
shared_libs: [
"android.hardware.neuralnetworks-V2-ndk",
],
}
// A cc_defaults that includes the latest non-experimental AIDL utilities and other AIDL libraries
// that are commonly used together. Modules that always depend on the latest non-experimental
// AIDL features can include this cc_defaults to avoid managing dependency versions explicitly.
cc_defaults {
name: "neuralnetworks_use_latest_utils_hal_aidl",
static_libs: [
"android.hardware.common-V2-ndk",
"android.hardware.graphics.common-V2-ndk",
"android.hardware.neuralnetworks-V2-ndk",
"neuralnetworks_utils_hal_aidl_v2",
],
}
cc_test {
name: "neuralnetworks_utils_hal_aidl_test",
defaults: [
"neuralnetworks_use_latest_utils_hal_aidl",
"neuralnetworks_utils_defaults",
],
defaults: ["neuralnetworks_utils_defaults"],
srcs: [
"test/*.cpp",
],
static_libs: [
"android.hardware.common-V2-ndk",
"android.hardware.graphics.common-V2-ndk",
"android.hardware.neuralnetworks-V2-ndk",
"libaidlcommonsupport",
"libgmock",
"libneuralnetworks_common",
"neuralnetworks_types",
"neuralnetworks_utils_hal_aidl",
"neuralnetworks_utils_hal_common",
],
shared_libs: [

View file

@ -43,12 +43,11 @@ class Device final : public nn::IDevice {
public:
static nn::GeneralResult<std::shared_ptr<const Device>> create(
std::string name, std::shared_ptr<aidl_hal::IDevice> device, nn::Version featureLevel);
std::string name, std::shared_ptr<aidl_hal::IDevice> device);
Device(PrivateConstructorTag tag, std::string name, std::string versionString,
nn::Version featureLevel, nn::DeviceType deviceType,
std::vector<nn::Extension> extensions, nn::Capabilities capabilities,
std::pair<uint32_t, uint32_t> numberOfCacheFilesNeeded,
nn::DeviceType deviceType, std::vector<nn::Extension> extensions,
nn::Capabilities capabilities, std::pair<uint32_t, uint32_t> numberOfCacheFilesNeeded,
std::shared_ptr<aidl_hal::IDevice> device, DeathHandler deathHandler);
const std::string& getName() const override;
@ -85,7 +84,6 @@ class Device final : public nn::IDevice {
private:
const std::string kName;
const std::string kVersionString;
const nn::Version kFeatureLevel;
const nn::DeviceType kDeviceType;
const std::vector<nn::Extension> kExtensions;
const nn::Capabilities kCapabilities;

View file

@ -125,7 +125,7 @@ nn::GeneralResult<std::pair<uint32_t, uint32_t>> getNumberOfCacheFilesNeededFrom
} // namespace
nn::GeneralResult<std::shared_ptr<const Device>> Device::create(
std::string name, std::shared_ptr<aidl_hal::IDevice> device, nn::Version featureLevel) {
std::string name, std::shared_ptr<aidl_hal::IDevice> device) {
if (name.empty()) {
return NN_ERROR(nn::ErrorStatus::INVALID_ARGUMENT)
<< "aidl_hal::utils::Device::create must have non-empty name";
@ -143,19 +143,18 @@ nn::GeneralResult<std::shared_ptr<const Device>> Device::create(
auto deathHandler = NN_TRY(DeathHandler::create(device));
return std::make_shared<const Device>(
PrivateConstructorTag{}, std::move(name), std::move(versionString), featureLevel,
deviceType, std::move(extensions), std::move(capabilities), numberOfCacheFilesNeeded,
PrivateConstructorTag{}, std::move(name), std::move(versionString), deviceType,
std::move(extensions), std::move(capabilities), numberOfCacheFilesNeeded,
std::move(device), std::move(deathHandler));
}
Device::Device(PrivateConstructorTag /*tag*/, std::string name, std::string versionString,
nn::Version featureLevel, nn::DeviceType deviceType,
std::vector<nn::Extension> extensions, nn::Capabilities capabilities,
nn::DeviceType deviceType, std::vector<nn::Extension> extensions,
nn::Capabilities capabilities,
std::pair<uint32_t, uint32_t> numberOfCacheFilesNeeded,
std::shared_ptr<aidl_hal::IDevice> device, DeathHandler deathHandler)
: kName(std::move(name)),
kVersionString(std::move(versionString)),
kFeatureLevel(featureLevel),
kDeviceType(deviceType),
kExtensions(std::move(extensions)),
kCapabilities(std::move(capabilities)),
@ -172,7 +171,7 @@ const std::string& Device::getVersionString() const {
}
nn::Version Device::getFeatureLevel() const {
return kFeatureLevel;
return nn::Version::ANDROID_S;
}
nn::DeviceType Device::getType() const {

View file

@ -17,7 +17,6 @@
#include "Service.h"
#include <AndroidVersionUtil.h>
#include <aidl/android/hardware/neuralnetworks/IDevice.h>
#include <android/binder_auto_utils.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
@ -29,33 +28,8 @@
#include <string>
#include "Device.h"
#include "Utils.h"
namespace aidl::android::hardware::neuralnetworks::utils {
namespace {
// Map the AIDL version of an IDevice to NNAPI canonical feature level.
nn::GeneralResult<nn::Version> getAidlServiceFeatureLevel(IDevice* service) {
CHECK(service != nullptr);
int aidlVersion;
const auto ret = service->getInterfaceVersion(&aidlVersion);
HANDLE_ASTATUS(ret) << "getInterfaceVersion failed";
// For service AIDL versions greater than or equal to the AIDL library version that the runtime
// was built against, clamp it to the runtime AIDL library version.
aidlVersion = std::min(aidlVersion, IDevice::version);
// Map stable AIDL versions to canonical versions.
switch (aidlVersion) {
case 1:
return nn::Version::ANDROID_S;
case 2:
return nn::Version::FEATURE_LEVEL_6;
}
return NN_ERROR() << "Unknown AIDL service version: " << aidlVersion;
}
} // namespace
nn::GeneralResult<nn::SharedDevice> getDevice(const std::string& instanceName) {
auto fullName = std::string(IDevice::descriptor) + "/" + instanceName;
@ -81,8 +55,7 @@ nn::GeneralResult<nn::SharedDevice> getDevice(const std::string& instanceName) {
<< " returned nullptr";
}
ABinderProcess_startThreadPool();
const auto featureLevel = NN_TRY(getAidlServiceFeatureLevel(service.get()));
return Device::create(instanceName, std::move(service), featureLevel);
return Device::create(instanceName, std::move(service));
};
return hal::utils::ResilientDevice::create(std::move(makeDevice));

View file

@ -146,45 +146,28 @@ constexpr auto makeDeadObjectFailure = [] {
return ndk::ScopedAStatus::fromStatus(STATUS_DEAD_OBJECT);
};
class DeviceTest : public ::testing::TestWithParam<nn::Version> {
protected:
const nn::Version kVersion = GetParam();
};
std::string printDeviceTest(const testing::TestParamInfo<nn::Version>& info) {
switch (info.param) {
case nn::Version::ANDROID_S:
return "v1";
case nn::Version::FEATURE_LEVEL_6:
return "v2";
default:
LOG(FATAL) << "Invalid AIDL version: " << info.param;
return "invalid";
}
}
} // namespace
TEST_P(DeviceTest, invalidName) {
TEST(DeviceTest, invalidName) {
// run test
const auto device = MockDevice::create();
const auto result = Device::create(kInvalidName, device, kVersion);
const auto result = Device::create(kInvalidName, device);
// verify result
ASSERT_FALSE(result.has_value());
EXPECT_EQ(result.error().code, nn::ErrorStatus::INVALID_ARGUMENT);
}
TEST_P(DeviceTest, invalidDevice) {
TEST(DeviceTest, invalidDevice) {
// run test
const auto result = Device::create(kName, kInvalidDevice, kVersion);
const auto result = Device::create(kName, kInvalidDevice);
// verify result
ASSERT_FALSE(result.has_value());
EXPECT_EQ(result.error().code, nn::ErrorStatus::INVALID_ARGUMENT);
}
TEST_P(DeviceTest, getVersionStringError) {
TEST(DeviceTest, getVersionStringError) {
// setup call
const auto mockDevice = createMockDevice();
EXPECT_CALL(*mockDevice, getVersionString(_))
@ -192,14 +175,14 @@ TEST_P(DeviceTest, getVersionStringError) {
.WillOnce(InvokeWithoutArgs(makeGeneralFailure));
// run test
const auto result = Device::create(kName, mockDevice, kVersion);
const auto result = Device::create(kName, mockDevice);
// verify result
ASSERT_FALSE(result.has_value());
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, getVersionStringTransportFailure) {
TEST(DeviceTest, getVersionStringTransportFailure) {
// setup call
const auto mockDevice = createMockDevice();
EXPECT_CALL(*mockDevice, getVersionString(_))
@ -207,14 +190,14 @@ TEST_P(DeviceTest, getVersionStringTransportFailure) {
.WillOnce(InvokeWithoutArgs(makeGeneralTransportFailure));
// run test
const auto result = Device::create(kName, mockDevice, kVersion);
const auto result = Device::create(kName, mockDevice);
// verify result
ASSERT_FALSE(result.has_value());
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, getVersionStringDeadObject) {
TEST(DeviceTest, getVersionStringDeadObject) {
// setup call
const auto mockDevice = createMockDevice();
EXPECT_CALL(*mockDevice, getVersionString(_))
@ -222,27 +205,27 @@ TEST_P(DeviceTest, getVersionStringDeadObject) {
.WillOnce(InvokeWithoutArgs(makeDeadObjectFailure));
// run test
const auto result = Device::create(kName, mockDevice, kVersion);
const auto result = Device::create(kName, mockDevice);
// verify result
ASSERT_FALSE(result.has_value());
EXPECT_EQ(result.error().code, nn::ErrorStatus::DEAD_OBJECT);
}
TEST_P(DeviceTest, getTypeError) {
TEST(DeviceTest, getTypeError) {
// setup call
const auto mockDevice = createMockDevice();
EXPECT_CALL(*mockDevice, getType(_)).Times(1).WillOnce(InvokeWithoutArgs(makeGeneralFailure));
// run test
const auto result = Device::create(kName, mockDevice, kVersion);
const auto result = Device::create(kName, mockDevice);
// verify result
ASSERT_FALSE(result.has_value());
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, getTypeTransportFailure) {
TEST(DeviceTest, getTypeTransportFailure) {
// setup call
const auto mockDevice = createMockDevice();
EXPECT_CALL(*mockDevice, getType(_))
@ -250,14 +233,14 @@ TEST_P(DeviceTest, getTypeTransportFailure) {
.WillOnce(InvokeWithoutArgs(makeGeneralTransportFailure));
// run test
const auto result = Device::create(kName, mockDevice, kVersion);
const auto result = Device::create(kName, mockDevice);
// verify result
ASSERT_FALSE(result.has_value());
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, getTypeDeadObject) {
TEST(DeviceTest, getTypeDeadObject) {
// setup call
const auto mockDevice = createMockDevice();
EXPECT_CALL(*mockDevice, getType(_))
@ -265,14 +248,14 @@ TEST_P(DeviceTest, getTypeDeadObject) {
.WillOnce(InvokeWithoutArgs(makeDeadObjectFailure));
// run test
const auto result = Device::create(kName, mockDevice, kVersion);
const auto result = Device::create(kName, mockDevice);
// verify result
ASSERT_FALSE(result.has_value());
EXPECT_EQ(result.error().code, nn::ErrorStatus::DEAD_OBJECT);
}
TEST_P(DeviceTest, getSupportedExtensionsError) {
TEST(DeviceTest, getSupportedExtensionsError) {
// setup call
const auto mockDevice = createMockDevice();
EXPECT_CALL(*mockDevice, getSupportedExtensions(_))
@ -280,14 +263,14 @@ TEST_P(DeviceTest, getSupportedExtensionsError) {
.WillOnce(InvokeWithoutArgs(makeGeneralFailure));
// run test
const auto result = Device::create(kName, mockDevice, kVersion);
const auto result = Device::create(kName, mockDevice);
// verify result
ASSERT_FALSE(result.has_value());
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, getSupportedExtensionsTransportFailure) {
TEST(DeviceTest, getSupportedExtensionsTransportFailure) {
// setup call
const auto mockDevice = createMockDevice();
EXPECT_CALL(*mockDevice, getSupportedExtensions(_))
@ -295,14 +278,14 @@ TEST_P(DeviceTest, getSupportedExtensionsTransportFailure) {
.WillOnce(InvokeWithoutArgs(makeGeneralTransportFailure));
// run test
const auto result = Device::create(kName, mockDevice, kVersion);
const auto result = Device::create(kName, mockDevice);
// verify result
ASSERT_FALSE(result.has_value());
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, getSupportedExtensionsDeadObject) {
TEST(DeviceTest, getSupportedExtensionsDeadObject) {
// setup call
const auto mockDevice = createMockDevice();
EXPECT_CALL(*mockDevice, getSupportedExtensions(_))
@ -310,20 +293,20 @@ TEST_P(DeviceTest, getSupportedExtensionsDeadObject) {
.WillOnce(InvokeWithoutArgs(makeDeadObjectFailure));
// run test
const auto result = Device::create(kName, mockDevice, kVersion);
const auto result = Device::create(kName, mockDevice);
// verify result
ASSERT_FALSE(result.has_value());
EXPECT_EQ(result.error().code, nn::ErrorStatus::DEAD_OBJECT);
}
TEST_P(DeviceTest, getNumberOfCacheFilesNeeded) {
TEST(DeviceTest, getNumberOfCacheFilesNeeded) {
// setup call
const auto mockDevice = createMockDevice();
EXPECT_CALL(*mockDevice, getNumberOfCacheFilesNeeded(_)).Times(1);
// run test
const auto result = Device::create(kName, mockDevice, kVersion);
const auto result = Device::create(kName, mockDevice);
// verify result
ASSERT_TRUE(result.has_value());
@ -332,7 +315,7 @@ TEST_P(DeviceTest, getNumberOfCacheFilesNeeded) {
EXPECT_EQ(result.value()->getNumberOfCacheFilesNeeded(), kNumberOfCacheFilesPair);
}
TEST_P(DeviceTest, getNumberOfCacheFilesNeededError) {
TEST(DeviceTest, getNumberOfCacheFilesNeededError) {
// setup call
const auto mockDevice = createMockDevice();
EXPECT_CALL(*mockDevice, getNumberOfCacheFilesNeeded(_))
@ -340,14 +323,14 @@ TEST_P(DeviceTest, getNumberOfCacheFilesNeededError) {
.WillOnce(InvokeWithoutArgs(makeGeneralFailure));
// run test
const auto result = Device::create(kName, mockDevice, kVersion);
const auto result = Device::create(kName, mockDevice);
// verify result
ASSERT_FALSE(result.has_value());
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, dataCacheFilesExceedsSpecifiedMax) {
TEST(DeviceTest, dataCacheFilesExceedsSpecifiedMax) {
// setup test
const auto mockDevice = createMockDevice();
EXPECT_CALL(*mockDevice, getNumberOfCacheFilesNeeded(_))
@ -358,14 +341,14 @@ TEST_P(DeviceTest, dataCacheFilesExceedsSpecifiedMax) {
InvokeWithoutArgs(makeStatusOk)));
// run test
const auto result = Device::create(kName, mockDevice, kVersion);
const auto result = Device::create(kName, mockDevice);
// verify result
ASSERT_FALSE(result.has_value());
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, modelCacheFilesExceedsSpecifiedMax) {
TEST(DeviceTest, modelCacheFilesExceedsSpecifiedMax) {
// setup test
const auto mockDevice = createMockDevice();
EXPECT_CALL(*mockDevice, getNumberOfCacheFilesNeeded(_))
@ -376,14 +359,14 @@ TEST_P(DeviceTest, modelCacheFilesExceedsSpecifiedMax) {
InvokeWithoutArgs(makeStatusOk)));
// run test
const auto result = Device::create(kName, mockDevice, kVersion);
const auto result = Device::create(kName, mockDevice);
// verify result
ASSERT_FALSE(result.has_value());
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, getNumberOfCacheFilesNeededTransportFailure) {
TEST(DeviceTest, getNumberOfCacheFilesNeededTransportFailure) {
// setup call
const auto mockDevice = createMockDevice();
EXPECT_CALL(*mockDevice, getNumberOfCacheFilesNeeded(_))
@ -391,14 +374,14 @@ TEST_P(DeviceTest, getNumberOfCacheFilesNeededTransportFailure) {
.WillOnce(InvokeWithoutArgs(makeGeneralTransportFailure));
// run test
const auto result = Device::create(kName, mockDevice, kVersion);
const auto result = Device::create(kName, mockDevice);
// verify result
ASSERT_FALSE(result.has_value());
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, getNumberOfCacheFilesNeededDeadObject) {
TEST(DeviceTest, getNumberOfCacheFilesNeededDeadObject) {
// setup call
const auto mockDevice = createMockDevice();
EXPECT_CALL(*mockDevice, getNumberOfCacheFilesNeeded(_))
@ -406,14 +389,14 @@ TEST_P(DeviceTest, getNumberOfCacheFilesNeededDeadObject) {
.WillOnce(InvokeWithoutArgs(makeDeadObjectFailure));
// run test
const auto result = Device::create(kName, mockDevice, kVersion);
const auto result = Device::create(kName, mockDevice);
// verify result
ASSERT_FALSE(result.has_value());
EXPECT_EQ(result.error().code, nn::ErrorStatus::DEAD_OBJECT);
}
TEST_P(DeviceTest, getCapabilitiesError) {
TEST(DeviceTest, getCapabilitiesError) {
// setup call
const auto mockDevice = createMockDevice();
EXPECT_CALL(*mockDevice, getCapabilities(_))
@ -421,14 +404,14 @@ TEST_P(DeviceTest, getCapabilitiesError) {
.WillOnce(InvokeWithoutArgs(makeGeneralFailure));
// run test
const auto result = Device::create(kName, mockDevice, kVersion);
const auto result = Device::create(kName, mockDevice);
// verify result
ASSERT_FALSE(result.has_value());
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, getCapabilitiesTransportFailure) {
TEST(DeviceTest, getCapabilitiesTransportFailure) {
// setup call
const auto mockDevice = createMockDevice();
EXPECT_CALL(*mockDevice, getCapabilities(_))
@ -436,14 +419,14 @@ TEST_P(DeviceTest, getCapabilitiesTransportFailure) {
.WillOnce(InvokeWithoutArgs(makeGeneralTransportFailure));
// run test
const auto result = Device::create(kName, mockDevice, kVersion);
const auto result = Device::create(kName, mockDevice);
// verify result
ASSERT_FALSE(result.has_value());
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, getCapabilitiesDeadObject) {
TEST(DeviceTest, getCapabilitiesDeadObject) {
// setup call
const auto mockDevice = createMockDevice();
EXPECT_CALL(*mockDevice, getCapabilities(_))
@ -451,17 +434,17 @@ TEST_P(DeviceTest, getCapabilitiesDeadObject) {
.WillOnce(InvokeWithoutArgs(makeDeadObjectFailure));
// run test
const auto result = Device::create(kName, mockDevice, kVersion);
const auto result = Device::create(kName, mockDevice);
// verify result
ASSERT_FALSE(result.has_value());
EXPECT_EQ(result.error().code, nn::ErrorStatus::DEAD_OBJECT);
}
TEST_P(DeviceTest, getName) {
TEST(DeviceTest, getName) {
// setup call
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
// run test
const auto& name = device->getName();
@ -470,19 +453,19 @@ TEST_P(DeviceTest, getName) {
EXPECT_EQ(name, kName);
}
TEST_P(DeviceTest, getFeatureLevel) {
TEST(DeviceTest, getFeatureLevel) {
// setup call
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
// run test
const auto featureLevel = device->getFeatureLevel();
// verify result
EXPECT_EQ(featureLevel, kVersion);
EXPECT_EQ(featureLevel, nn::Version::ANDROID_S);
}
TEST_P(DeviceTest, getCachedData) {
TEST(DeviceTest, getCachedData) {
// setup call
const auto mockDevice = createMockDevice();
EXPECT_CALL(*mockDevice, getVersionString(_)).Times(1);
@ -491,7 +474,7 @@ TEST_P(DeviceTest, getCachedData) {
EXPECT_CALL(*mockDevice, getNumberOfCacheFilesNeeded(_)).Times(1);
EXPECT_CALL(*mockDevice, getCapabilities(_)).Times(1);
const auto result = Device::create(kName, mockDevice, kVersion);
const auto result = Device::create(kName, mockDevice);
ASSERT_TRUE(result.has_value())
<< "Failed with " << result.error().code << ": " << result.error().message;
const auto& device = result.value();
@ -504,10 +487,10 @@ TEST_P(DeviceTest, getCachedData) {
EXPECT_EQ(device->getCapabilities(), device->getCapabilities());
}
TEST_P(DeviceTest, getSupportedOperations) {
TEST(DeviceTest, getSupportedOperations) {
// setup call
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
EXPECT_CALL(*mockDevice, getSupportedOperations(_, _))
.Times(1)
.WillOnce(DoAll(
@ -525,10 +508,10 @@ TEST_P(DeviceTest, getSupportedOperations) {
EXPECT_THAT(supportedOperations, Each(testing::IsTrue()));
}
TEST_P(DeviceTest, getSupportedOperationsError) {
TEST(DeviceTest, getSupportedOperationsError) {
// setup call
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
EXPECT_CALL(*mockDevice, getSupportedOperations(_, _))
.Times(1)
.WillOnce(InvokeWithoutArgs(makeGeneralFailure));
@ -541,10 +524,10 @@ TEST_P(DeviceTest, getSupportedOperationsError) {
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, getSupportedOperationsTransportFailure) {
TEST(DeviceTest, getSupportedOperationsTransportFailure) {
// setup call
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
EXPECT_CALL(*mockDevice, getSupportedOperations(_, _))
.Times(1)
.WillOnce(InvokeWithoutArgs(makeGeneralTransportFailure));
@ -557,10 +540,10 @@ TEST_P(DeviceTest, getSupportedOperationsTransportFailure) {
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, getSupportedOperationsDeadObject) {
TEST(DeviceTest, getSupportedOperationsDeadObject) {
// setup call
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
EXPECT_CALL(*mockDevice, getSupportedOperations(_, _))
.Times(1)
.WillOnce(InvokeWithoutArgs(makeDeadObjectFailure));
@ -573,10 +556,10 @@ TEST_P(DeviceTest, getSupportedOperationsDeadObject) {
EXPECT_EQ(result.error().code, nn::ErrorStatus::DEAD_OBJECT);
}
TEST_P(DeviceTest, prepareModel) {
TEST(DeviceTest, prepareModel) {
// setup call
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
const auto mockPreparedModel = MockPreparedModel::create();
EXPECT_CALL(*mockDevice, prepareModel(_, _, _, _, _, _, _, _))
.Times(1)
@ -593,10 +576,10 @@ TEST_P(DeviceTest, prepareModel) {
EXPECT_NE(result.value(), nullptr);
}
TEST_P(DeviceTest, prepareModelLaunchError) {
TEST(DeviceTest, prepareModelLaunchError) {
// setup call
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
EXPECT_CALL(*mockDevice, prepareModel(_, _, _, _, _, _, _, _))
.Times(1)
.WillOnce(Invoke(makePreparedModelReturn(ErrorStatus::GENERAL_FAILURE,
@ -611,10 +594,10 @@ TEST_P(DeviceTest, prepareModelLaunchError) {
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, prepareModelReturnError) {
TEST(DeviceTest, prepareModelReturnError) {
// setup call
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
EXPECT_CALL(*mockDevice, prepareModel(_, _, _, _, _, _, _, _))
.Times(1)
.WillOnce(Invoke(makePreparedModelReturn(ErrorStatus::NONE,
@ -629,10 +612,10 @@ TEST_P(DeviceTest, prepareModelReturnError) {
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, prepareModelNullptrError) {
TEST(DeviceTest, prepareModelNullptrError) {
// setup call
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
EXPECT_CALL(*mockDevice, prepareModel(_, _, _, _, _, _, _, _))
.Times(1)
.WillOnce(
@ -647,10 +630,10 @@ TEST_P(DeviceTest, prepareModelNullptrError) {
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, prepareModelTransportFailure) {
TEST(DeviceTest, prepareModelTransportFailure) {
// setup call
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
EXPECT_CALL(*mockDevice, prepareModel(_, _, _, _, _, _, _, _))
.Times(1)
.WillOnce(InvokeWithoutArgs(makeGeneralTransportFailure));
@ -664,10 +647,10 @@ TEST_P(DeviceTest, prepareModelTransportFailure) {
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, prepareModelDeadObject) {
TEST(DeviceTest, prepareModelDeadObject) {
// setup call
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
EXPECT_CALL(*mockDevice, prepareModel(_, _, _, _, _, _, _, _))
.Times(1)
.WillOnce(InvokeWithoutArgs(makeDeadObjectFailure));
@ -681,10 +664,10 @@ TEST_P(DeviceTest, prepareModelDeadObject) {
EXPECT_EQ(result.error().code, nn::ErrorStatus::DEAD_OBJECT);
}
TEST_P(DeviceTest, prepareModelAsyncCrash) {
TEST(DeviceTest, prepareModelAsyncCrash) {
// setup test
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
const auto ret = [&device]() {
DeathMonitor::serviceDied(device->getDeathMonitor());
return ndk::ScopedAStatus::ok();
@ -702,10 +685,10 @@ TEST_P(DeviceTest, prepareModelAsyncCrash) {
EXPECT_EQ(result.error().code, nn::ErrorStatus::DEAD_OBJECT);
}
TEST_P(DeviceTest, prepareModelFromCache) {
TEST(DeviceTest, prepareModelFromCache) {
// setup call
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
const auto mockPreparedModel = MockPreparedModel::create();
EXPECT_CALL(*mockDevice, prepareModelFromCache(_, _, _, _, _))
.Times(1)
@ -721,10 +704,10 @@ TEST_P(DeviceTest, prepareModelFromCache) {
EXPECT_NE(result.value(), nullptr);
}
TEST_P(DeviceTest, prepareModelFromCacheLaunchError) {
TEST(DeviceTest, prepareModelFromCacheLaunchError) {
// setup call
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
EXPECT_CALL(*mockDevice, prepareModelFromCache(_, _, _, _, _))
.Times(1)
.WillOnce(Invoke(makePreparedModelFromCacheReturn(
@ -738,10 +721,10 @@ TEST_P(DeviceTest, prepareModelFromCacheLaunchError) {
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, prepareModelFromCacheReturnError) {
TEST(DeviceTest, prepareModelFromCacheReturnError) {
// setup call
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
EXPECT_CALL(*mockDevice, prepareModelFromCache(_, _, _, _, _))
.Times(1)
.WillOnce(Invoke(makePreparedModelFromCacheReturn(
@ -755,10 +738,10 @@ TEST_P(DeviceTest, prepareModelFromCacheReturnError) {
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, prepareModelFromCacheNullptrError) {
TEST(DeviceTest, prepareModelFromCacheNullptrError) {
// setup call
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
EXPECT_CALL(*mockDevice, prepareModelFromCache(_, _, _, _, _))
.Times(1)
.WillOnce(Invoke(makePreparedModelFromCacheReturn(ErrorStatus::NONE, ErrorStatus::NONE,
@ -772,10 +755,10 @@ TEST_P(DeviceTest, prepareModelFromCacheNullptrError) {
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, prepareModelFromCacheTransportFailure) {
TEST(DeviceTest, prepareModelFromCacheTransportFailure) {
// setup call
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
EXPECT_CALL(*mockDevice, prepareModelFromCache(_, _, _, _, _))
.Times(1)
.WillOnce(InvokeWithoutArgs(makeGeneralTransportFailure));
@ -788,10 +771,10 @@ TEST_P(DeviceTest, prepareModelFromCacheTransportFailure) {
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, prepareModelFromCacheDeadObject) {
TEST(DeviceTest, prepareModelFromCacheDeadObject) {
// setup call
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
EXPECT_CALL(*mockDevice, prepareModelFromCache(_, _, _, _, _))
.Times(1)
.WillOnce(InvokeWithoutArgs(makeDeadObjectFailure));
@ -804,10 +787,10 @@ TEST_P(DeviceTest, prepareModelFromCacheDeadObject) {
EXPECT_EQ(result.error().code, nn::ErrorStatus::DEAD_OBJECT);
}
TEST_P(DeviceTest, prepareModelFromCacheAsyncCrash) {
TEST(DeviceTest, prepareModelFromCacheAsyncCrash) {
// setup test
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
const auto ret = [&device]() {
DeathMonitor::serviceDied(device->getDeathMonitor());
return ndk::ScopedAStatus::ok();
@ -824,10 +807,10 @@ TEST_P(DeviceTest, prepareModelFromCacheAsyncCrash) {
EXPECT_EQ(result.error().code, nn::ErrorStatus::DEAD_OBJECT);
}
TEST_P(DeviceTest, allocate) {
TEST(DeviceTest, allocate) {
// setup call
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
const auto mockBuffer = DeviceBuffer{.buffer = MockBuffer::create(), .token = 1};
EXPECT_CALL(*mockDevice, allocate(_, _, _, _, _))
.Times(1)
@ -842,10 +825,10 @@ TEST_P(DeviceTest, allocate) {
EXPECT_NE(result.value(), nullptr);
}
TEST_P(DeviceTest, allocateError) {
TEST(DeviceTest, allocateError) {
// setup call
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
EXPECT_CALL(*mockDevice, allocate(_, _, _, _, _))
.Times(1)
.WillOnce(InvokeWithoutArgs(makeGeneralFailure));
@ -858,10 +841,10 @@ TEST_P(DeviceTest, allocateError) {
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, allocateTransportFailure) {
TEST(DeviceTest, allocateTransportFailure) {
// setup call
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
EXPECT_CALL(*mockDevice, allocate(_, _, _, _, _))
.Times(1)
.WillOnce(InvokeWithoutArgs(makeGeneralTransportFailure));
@ -874,10 +857,10 @@ TEST_P(DeviceTest, allocateTransportFailure) {
EXPECT_EQ(result.error().code, nn::ErrorStatus::GENERAL_FAILURE);
}
TEST_P(DeviceTest, allocateDeadObject) {
TEST(DeviceTest, allocateDeadObject) {
// setup call
const auto mockDevice = createMockDevice();
const auto device = Device::create(kName, mockDevice, kVersion).value();
const auto device = Device::create(kName, mockDevice).value();
EXPECT_CALL(*mockDevice, allocate(_, _, _, _, _))
.Times(1)
.WillOnce(InvokeWithoutArgs(makeDeadObjectFailure));
@ -890,8 +873,4 @@ TEST_P(DeviceTest, allocateDeadObject) {
EXPECT_EQ(result.error().code, nn::ErrorStatus::DEAD_OBJECT);
}
INSTANTIATE_TEST_SUITE_P(TestDevice, DeviceTest,
::testing::Values(nn::Version::ANDROID_S, nn::Version::FEATURE_LEVEL_6),
printDeviceTest);
} // namespace aidl::android::hardware::neuralnetworks::utils

View file

@ -26,7 +26,6 @@ package {
cc_test {
name: "VtsHalNeuralnetworksTargetTest",
defaults: [
"neuralnetworks_use_latest_utils_hal_aidl",
"neuralnetworks_vts_functional_defaults",
"use_libaidlvintf_gtest_helper_static",
],
@ -52,14 +51,16 @@ cc_test {
static_libs: [
"android.hardware.common-V2-ndk",
"android.hardware.graphics.common-V2-ndk",
"android.hardware.neuralnetworks-V2-ndk",
"android.hidl.allocator@1.0",
"android.hidl.memory@1.0",
"libaidlcommonsupport",
"libgmock",
"libhidlmemory",
"libneuralnetworks_common",
"libneuralnetworks_generated_test_harness",
"libneuralnetworks_utils",
"libsync",
"neuralnetworks_utils_hal_aidl",
],
whole_static_libs: [
"neuralnetworks_generated_V1_0_example",

View file

@ -35,6 +35,7 @@ cc_library_static {
"neuralnetworks_types",
],
shared_libs: [
"android.hardware.neuralnetworks-V2-ndk",
"libhidlbase",
"libbinder_ndk",
],
@ -52,7 +53,7 @@ cc_test {
static_libs: [
"android.hardware.neuralnetworks@1.0",
"libgmock",
"libneuralnetworks_common_hidl",
"libneuralnetworks_common",
"neuralnetworks_types",
"neuralnetworks_utils_hal_common",
],

View file

@ -25,10 +25,7 @@ package {
cc_library_static {
name: "neuralnetworks_utils_hal_service",
defaults: [
"neuralnetworks_use_latest_utils_hal_aidl",
"neuralnetworks_utils_defaults",
],
defaults: ["neuralnetworks_utils_defaults"],
srcs: ["src/*"],
local_include_dirs: ["include/nnapi/hal"],
export_include_dirs: ["include"],
@ -38,9 +35,11 @@ cc_library_static {
"neuralnetworks_utils_hal_1_1",
"neuralnetworks_utils_hal_1_2",
"neuralnetworks_utils_hal_1_3",
"neuralnetworks_utils_hal_aidl",
"neuralnetworks_utils_hal_common",
],
shared_libs: [
"android.hardware.neuralnetworks-V2-ndk",
"android.hardware.neuralnetworks@1.0",
"android.hardware.neuralnetworks@1.1",
"android.hardware.neuralnetworks@1.2",