xref: /aosp_15_r20/external/android-nn-driver/test/Tests.cpp (revision 3e777be0405cee09af5d5785ff37f7cfb5bee59a)
1 //
2 // Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #define LOG_TAG "ArmnnDriverTests"
7 #include <log/log.h>
8 
9 #ifndef DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
10 #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
11 #endif
12 
13 #include "DriverTestHelpers.hpp"
14 
15 using namespace android::hardware;
16 using namespace driverTestHelpers;
17 using namespace armnn_driver;
18 
19 DOCTEST_TEST_SUITE("DriverTests")
20 {
21 
22 DOCTEST_TEST_CASE("Init")
23 {
24     // Making the driver object on the stack causes a weird libc error, so make it on the heap instead
25     auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef));
26 
27     V1_0::DeviceStatus status = driver->getStatus();
28     // Note double-parentheses to avoid compile error from doctest trying to printf the DeviceStatus
29     DOCTEST_CHECK((status == V1_0::DeviceStatus::AVAILABLE));
30 }
31 
32 DOCTEST_TEST_CASE("TestCapabilities")
33 {
34     // Making the driver object on the stack causes a weird libc error, so make it on the heap instead
35     auto driver = std::make_unique<ArmnnDriver>(DriverOptions(armnn::Compute::CpuRef));
36 
37     V1_0::ErrorStatus error;
38     V1_0::Capabilities cap;
39 
40     auto cb = [&](V1_0::ErrorStatus status, const V1_0::Capabilities& capabilities)
__anon3bea8d8c0102(V1_0::ErrorStatus status, const V1_0::Capabilities& capabilities) 41     {
42         error = status;
43         cap = capabilities;
44     };
45 
46     driver->getCapabilities(cb);
47 
48     DOCTEST_CHECK((int)error == (int)V1_0::ErrorStatus::NONE);
49     DOCTEST_CHECK(cap.float32Performance.execTime > 0.f);
50     DOCTEST_CHECK(cap.float32Performance.powerUsage > 0.f);
51     DOCTEST_CHECK(cap.quantized8Performance.execTime > 0.f);
52     DOCTEST_CHECK(cap.quantized8Performance.powerUsage > 0.f);
53 }
54 
55 }
56