Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d0d9a7ab authored by Michael Butler's avatar Michael Butler
Browse files

Make VtsHalNeuralnetworksTargetTest run on the host

This change adds a host build of VtsHalNeuralnetworksTargetTest. In the
existing device build of VtsHalNeuralnetworksTargetTest, the drivers run
out-of-process. In the host build of VtsHalNeuralnetworkaTargetTest, the
driver runs in-process.

The in-process driver that runs on the host is the canonical sample
driver (which is just the CPU "driver", located in
packages/modules/NeuralNetworks/driver/sample) adapted to an AIDL
interface (by the adapter code in
hardware/interfaces/neuralnetworks/utils/adapter/aidl).

Bug: N/A
Test: mma
Test: VtsHalNeuralnetworksTargetTest on host
Change-Id: Ia30dd3a7db8e0592b9f13d69c9831f8ffe10c371
parent d3e413e7
Loading
Loading
Loading
Loading
+30 −8
Original line number Original line Diff line number Diff line
@@ -30,6 +30,7 @@ cc_test {
        "neuralnetworks_vts_functional_defaults",
        "neuralnetworks_vts_functional_defaults",
        "use_libaidlvintf_gtest_helper_static",
        "use_libaidlvintf_gtest_helper_static",
    ],
    ],
    host_supported: true,
    srcs: [
    srcs: [
        "BasicTests.cpp",
        "BasicTests.cpp",
        "Callbacks.cpp",
        "Callbacks.cpp",
@@ -46,18 +47,11 @@ cc_test {
    ],
    ],
    shared_libs: [
    shared_libs: [
        "libbinder_ndk",
        "libbinder_ndk",
        "libnativewindow",
        "libvndksupport",
    ],
    ],
    static_libs: [
    static_libs: [
        "android.hidl.allocator@1.0",
        "android.hidl.memory@1.0",
        "libaidlcommonsupport",
        "libaidlcommonsupport",
        "libgmock",
        "libhidlmemory",
        "libneuralnetworks_common",
        "libneuralnetworks_common",
        "libneuralnetworks_generated_test_harness",
        "libneuralnetworks_generated_test_harness",
        "libsync",
    ],
    ],
    whole_static_libs: [
    whole_static_libs: [
        "neuralnetworks_generated_AIDL_V3_example",
        "neuralnetworks_generated_AIDL_V3_example",
@@ -73,6 +67,34 @@ cc_test {
    ],
    ],
    test_suites: [
    test_suites: [
        "general-tests",
        "general-tests",
    ],
    target: {
        android: {
            shared_libs: [
                "libnativewindow",
                "libvndksupport",
            ],
            static_libs: [
                "libsync",
            ],
            test_suites: [
                "vts",
                "vts",
            ],
            ],
            test_config: "AndroidTestDevice.xml",
        },
        host: {
            shared_libs: [
                "libtextclassifier_hash",
            ],
            static_libs: [
                "neuralnetworks_canonical_sample_driver",
                "neuralnetworks_utils_hal_adapter_aidl",
            ],
            exclude_static_libs: [
                "VtsHalHidlTestUtils",
                "libaidlvintf_gtest_helper",
            ],
            test_config: "AndroidTestHost.xml",
        },
    },
}
}
+22 −0
Original line number Original line Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2022 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<configuration description="Runs VtsHalNeuralnetworksTargetTest.">
    <test class="com.android.tradefed.testtype.HostGTest" >
        <option name="module-name" value="VtsHalNeuralnetworksTargetTest" />
        <option name="native-test-timeout" value="15m" />
    </test>
</configuration>
+4 −2
Original line number Original line Diff line number Diff line
@@ -23,7 +23,6 @@
#include <fcntl.h>
#include <fcntl.h>
#include <ftw.h>
#include <ftw.h>
#include <gtest/gtest.h>
#include <gtest/gtest.h>
#include <hidlmemory/mapping.h>
#include <unistd.h>
#include <unistd.h>


#include <cstdio>
#include <cstdio>
@@ -34,7 +33,6 @@


#include "Callbacks.h"
#include "Callbacks.h"
#include "GeneratedTestHarness.h"
#include "GeneratedTestHarness.h"
#include "MemoryUtils.h"
#include "TestHarness.h"
#include "TestHarness.h"
#include "Utils.h"
#include "Utils.h"
#include "VtsHalNeuralnetworks.h"
#include "VtsHalNeuralnetworks.h"
@@ -229,7 +227,11 @@ class CompilationCachingTestBase : public testing::Test {


        // Create cache directory. The cache directory and a temporary cache file is always created
        // Create cache directory. The cache directory and a temporary cache file is always created
        // to test the behavior of prepareModelFromCache, even when caching is not supported.
        // to test the behavior of prepareModelFromCache, even when caching is not supported.
#ifdef __ANDROID__
        char cacheDirTemp[] = "/data/local/tmp/TestCompilationCachingXXXXXX";
        char cacheDirTemp[] = "/data/local/tmp/TestCompilationCachingXXXXXX";
#else   // __ANDROID__
        char cacheDirTemp[] = "/tmp/TestCompilationCachingXXXXXX";
#endif  // __ANDROID__
        char* cacheDir = mkdtemp(cacheDirTemp);
        char* cacheDir = mkdtemp(cacheDirTemp);
        ASSERT_NE(cacheDir, nullptr);
        ASSERT_NE(cacheDir, nullptr);
        mCacheDir = cacheDir;
        mCacheDir = cacheDir;
+13 −3
Original line number Original line Diff line number Diff line
@@ -20,7 +20,6 @@
#include <aidl/android/hardware/neuralnetworks/RequestMemoryPool.h>
#include <aidl/android/hardware/neuralnetworks/RequestMemoryPool.h>
#include <android-base/logging.h>
#include <android-base/logging.h>
#include <android/binder_auto_utils.h>
#include <android/binder_auto_utils.h>
#include <android/sync.h>
#include <gtest/gtest.h>
#include <gtest/gtest.h>


#include <algorithm>
#include <algorithm>
@@ -30,7 +29,6 @@
#include <numeric>
#include <numeric>
#include <vector>
#include <vector>


#include <MemoryUtils.h>
#include <android/binder_status.h>
#include <android/binder_status.h>
#include <nnapi/Result.h>
#include <nnapi/Result.h>
#include <nnapi/SharedMemory.h>
#include <nnapi/SharedMemory.h>
@@ -43,6 +41,10 @@
#include "Utils.h"
#include "Utils.h"
#include "VtsHalNeuralnetworks.h"
#include "VtsHalNeuralnetworks.h"


#ifdef __ANDROID__
#include <android/sync.h>
#endif  // __ANDROID__

namespace aidl::android::hardware::neuralnetworks::vts::functional {
namespace aidl::android::hardware::neuralnetworks::vts::functional {


namespace nn = ::android::nn;
namespace nn = ::android::nn;
@@ -281,10 +283,14 @@ void copyTestBuffers(const std::vector<const TestBuffer*>& buffers, uint8_t* out
}  // namespace
}  // namespace


void waitForSyncFence(int syncFd) {
void waitForSyncFence(int syncFd) {
    constexpr int kInfiniteTimeout = -1;
    ASSERT_GT(syncFd, 0);
    ASSERT_GT(syncFd, 0);
#ifdef __ANDROID__
    constexpr int kInfiniteTimeout = -1;
    int r = sync_wait(syncFd, kInfiniteTimeout);
    int r = sync_wait(syncFd, kInfiniteTimeout);
    ASSERT_GE(r, 0);
    ASSERT_GE(r, 0);
#else   // __ANDROID__
    LOG(FATAL) << "waitForSyncFence not supported on host";
#endif  // __ANDROID__
}
}


Model createModel(const TestModel& testModel) {
Model createModel(const TestModel& testModel) {
@@ -895,7 +901,11 @@ void EvaluatePreparedModel(const std::shared_ptr<IDevice>& device,
            outputTypesList = {OutputType::FULLY_SPECIFIED};
            outputTypesList = {OutputType::FULLY_SPECIFIED};
            measureTimingList = {false};
            measureTimingList = {false};
            executorList = {Executor::SYNC, Executor::BURST, Executor::FENCED};
            executorList = {Executor::SYNC, Executor::BURST, Executor::FENCED};
#ifdef __ANDROID__
            memoryTypeList = {MemoryType::BLOB_AHWB, MemoryType::DEVICE};
            memoryTypeList = {MemoryType::BLOB_AHWB, MemoryType::DEVICE};
#else   // __ANDROID__
            memoryTypeList = {MemoryType::DEVICE};  // BLOB_AHWB is not supported on the host.
#endif  // __ANDROID__
        } break;
        } break;
        case TestKind::FENCED_COMPUTE: {
        case TestKind::FENCED_COMPUTE: {
            outputTypesList = {OutputType::FULLY_SPECIFIED};
            outputTypesList = {OutputType::FULLY_SPECIFIED};
Loading