Home | History | Annotate | Download | only in functional
      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  */
     16 
     17 #define LOG_TAG "neuralnetworks_hidl_hal_test"
     18 
     19 #include "VtsHalNeuralnetworks.h"
     20 
     21 namespace android {
     22 namespace hardware {
     23 namespace neuralnetworks {
     24 namespace V1_0 {
     25 namespace vts {
     26 namespace functional {
     27 
     28 // A class for test environment setup
     29 NeuralnetworksHidlEnvironment::NeuralnetworksHidlEnvironment() {}
     30 
     31 NeuralnetworksHidlEnvironment::~NeuralnetworksHidlEnvironment() {}
     32 
     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 }
     39 
     40 void NeuralnetworksHidlEnvironment::registerTestServices() {
     41     registerTestService<IDevice>();
     42 }
     43 
     44 // The main test class for NEURALNETWORK HIDL HAL.
     45 NeuralnetworksHidlTest::NeuralnetworksHidlTest() {}
     46 
     47 NeuralnetworksHidlTest::~NeuralnetworksHidlTest() {}
     48 
     49 void NeuralnetworksHidlTest::SetUp() {
     50     ::testing::VtsHalHidlTargetTestBase::SetUp();
     51     device = ::testing::VtsHalHidlTargetTestBase::getService<IDevice>(
     52         NeuralnetworksHidlEnvironment::getInstance());
     53     ASSERT_NE(nullptr, device.get());
     54 }
     55 
     56 void NeuralnetworksHidlTest::TearDown() {
     57     device = nullptr;
     58     ::testing::VtsHalHidlTargetTestBase::TearDown();
     59 }
     60 
     61 }  // namespace functional
     62 }  // namespace vts
     63 
     64 ::std::ostream& operator<<(::std::ostream& os, ErrorStatus errorStatus) {
     65     return os << toString(errorStatus);
     66 }
     67 
     68 ::std::ostream& operator<<(::std::ostream& os, DeviceStatus deviceStatus) {
     69     return os << toString(deviceStatus);
     70 }
     71 
     72 }  // namespace V1_0
     73 }  // namespace neuralnetworks
     74 }  // namespace hardware
     75 }  // namespace android
     76 
     77 using android::hardware::neuralnetworks::V1_0::vts::functional::NeuralnetworksHidlEnvironment;
     78 
     79 int main(int argc, char** argv) {
     80     ::testing::AddGlobalTestEnvironment(NeuralnetworksHidlEnvironment::getInstance());
     81     ::testing::InitGoogleTest(&argc, argv);
     82     NeuralnetworksHidlEnvironment::getInstance()->init(&argc, argv);
     83 
     84     int status = RUN_ALL_TESTS();
     85     return status;
     86 }
     87