[android/platform-hardware-interfaces.git] / neuralnetworks / 1.2 / vts / functional / VtsHalNeuralnetworks.cpp
1 /*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
17 #define LOG_TAG "neuralnetworks_hidl_hal_test"
19 #include "VtsHalNeuralnetworks.h"
21 namespace android {
22 namespace hardware {
23 namespace neuralnetworks {
24 namespace V1_2 {
25 namespace vts {
26 namespace functional {
28 // A class for test environment setup
29 NeuralnetworksHidlEnvironment::NeuralnetworksHidlEnvironment() {}
31 NeuralnetworksHidlEnvironment::~NeuralnetworksHidlEnvironment() {}
33 NeuralnetworksHidlEnvironment* NeuralnetworksHidlEnvironment::getInstance() {
34 // This has to return a "new" object because it is freed inside
35 // ::testing::AddGlobalTestEnvironment when the gtest is being torn down
36 static NeuralnetworksHidlEnvironment* instance = new NeuralnetworksHidlEnvironment();
37 return instance;
38 }
40 void NeuralnetworksHidlEnvironment::registerTestServices() {
41 registerTestService<IDevice>();
42 }
44 // The main test class for NEURALNETWORK HIDL HAL.
45 NeuralnetworksHidlTest::NeuralnetworksHidlTest() {}
47 NeuralnetworksHidlTest::~NeuralnetworksHidlTest() {}
49 void NeuralnetworksHidlTest::SetUp() {
50 ::testing::VtsHalHidlTargetTestBase::SetUp();
51 device = ::testing::VtsHalHidlTargetTestBase::getService<IDevice>(
52 NeuralnetworksHidlEnvironment::getInstance());
53 ASSERT_NE(nullptr, device.get());
54 }
56 void NeuralnetworksHidlTest::TearDown() {
57 device = nullptr;
58 ::testing::VtsHalHidlTargetTestBase::TearDown();
59 }
61 } // namespace functional
62 } // namespace vts
64 ::std::ostream& operator<<(::std::ostream& os, ErrorStatus errorStatus) {
65 return os << toString(errorStatus);
66 }
68 ::std::ostream& operator<<(::std::ostream& os, DeviceStatus deviceStatus) {
69 return os << toString(deviceStatus);
70 }
72 } // namespace V1_2
73 } // namespace neuralnetworks
74 } // namespace hardware
75 } // namespace android
77 using android::hardware::neuralnetworks::V1_2::vts::functional::NeuralnetworksHidlEnvironment;
79 int main(int argc, char** argv) {
80 ::testing::AddGlobalTestEnvironment(NeuralnetworksHidlEnvironment::getInstance());
81 ::testing::InitGoogleTest(&argc, argv);
82 NeuralnetworksHidlEnvironment::getInstance()->init(&argc, argv);
84 int status = RUN_ALL_TESTS();
85 return status;
86 }