Michael Butler | 7ed6135 | 2018-03-22 16:37:57 -0700 | [diff] [blame] | 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 | |
Slava Shklyaev | 73ee79d | 2019-05-14 14:15:14 +0100 | [diff] [blame] | 19 | #include "1.0/Callbacks.h" |
| 20 | #include "1.0/Utils.h" |
Xusong Wang | bcaa782 | 2019-08-23 16:10:54 -0700 | [diff] [blame] | 21 | #include "GeneratedTestHarness.h" |
Slava Shklyaev | 73ee79d | 2019-05-14 14:15:14 +0100 | [diff] [blame] | 22 | #include "VtsHalNeuralnetworks.h" |
| 23 | |
Michael Butler | 7ed6135 | 2018-03-22 16:37:57 -0700 | [diff] [blame] | 24 | namespace android { |
| 25 | namespace hardware { |
| 26 | namespace neuralnetworks { |
| 27 | namespace V1_1 { |
| 28 | namespace vts { |
| 29 | namespace functional { |
| 30 | |
Slava Shklyaev | 73ee79d | 2019-05-14 14:15:14 +0100 | [diff] [blame] | 31 | using ::android::hardware::neuralnetworks::V1_0::ErrorStatus; |
| 32 | using ::android::hardware::neuralnetworks::V1_0::Request; |
Slava Shklyaev | 73ee79d | 2019-05-14 14:15:14 +0100 | [diff] [blame] | 33 | using ::android::hardware::neuralnetworks::V1_0::implementation::ExecutionCallback; |
| 34 | using ::android::hardware::neuralnetworks::V1_1::IPreparedModel; |
Michael Butler | 7ed6135 | 2018-03-22 16:37:57 -0700 | [diff] [blame] | 35 | |
| 36 | ///////////////////////// UTILITY FUNCTIONS ///////////////////////// |
| 37 | |
Michael Butler | 7ed6135 | 2018-03-22 16:37:57 -0700 | [diff] [blame] | 38 | // Primary validation function. This function will take a valid request, apply a |
| 39 | // mutation to it to invalidate the request, then pass it to interface calls |
| 40 | // that use the request. Note that the request here is passed by value, and any |
| 41 | // mutation to the request does not leave this function. |
| 42 | static void validate(const sp<IPreparedModel>& preparedModel, const std::string& message, |
| 43 | Request request, const std::function<void(Request*)>& mutation) { |
| 44 | mutation(&request); |
| 45 | SCOPED_TRACE(message + " [execute]"); |
| 46 | |
| 47 | sp<ExecutionCallback> executionCallback = new ExecutionCallback(); |
| 48 | ASSERT_NE(nullptr, executionCallback.get()); |
| 49 | Return<ErrorStatus> executeLaunchStatus = preparedModel->execute(request, executionCallback); |
| 50 | ASSERT_TRUE(executeLaunchStatus.isOk()); |
| 51 | ASSERT_EQ(ErrorStatus::INVALID_ARGUMENT, static_cast<ErrorStatus>(executeLaunchStatus)); |
| 52 | |
| 53 | executionCallback->wait(); |
| 54 | ErrorStatus executionReturnStatus = executionCallback->getStatus(); |
| 55 | ASSERT_EQ(ErrorStatus::INVALID_ARGUMENT, executionReturnStatus); |
| 56 | } |
| 57 | |
Michael Butler | 7ed6135 | 2018-03-22 16:37:57 -0700 | [diff] [blame] | 58 | ///////////////////////// REMOVE INPUT //////////////////////////////////// |
| 59 | |
| 60 | static void removeInputTest(const sp<IPreparedModel>& preparedModel, const Request& request) { |
| 61 | for (size_t input = 0; input < request.inputs.size(); ++input) { |
| 62 | const std::string message = "removeInput: removed input " + std::to_string(input); |
| 63 | validate(preparedModel, message, request, |
| 64 | [input](Request* request) { hidl_vec_removeAt(&request->inputs, input); }); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | ///////////////////////// REMOVE OUTPUT //////////////////////////////////// |
| 69 | |
| 70 | static void removeOutputTest(const sp<IPreparedModel>& preparedModel, const Request& request) { |
| 71 | for (size_t output = 0; output < request.outputs.size(); ++output) { |
| 72 | const std::string message = "removeOutput: removed Output " + std::to_string(output); |
| 73 | validate(preparedModel, message, request, |
| 74 | [output](Request* request) { hidl_vec_removeAt(&request->outputs, output); }); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | ///////////////////////////// ENTRY POINT ////////////////////////////////// |
| 79 | |
Xusong Wang | 8161196 | 2019-08-09 16:41:16 -0700 | [diff] [blame] | 80 | void ValidationTest::validateRequest(const sp<IPreparedModel>& preparedModel, |
| 81 | const Request& request) { |
| 82 | removeInputTest(preparedModel, request); |
| 83 | removeOutputTest(preparedModel, request); |
Michael Butler | 7ed6135 | 2018-03-22 16:37:57 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | } // namespace functional |
| 87 | } // namespace vts |
| 88 | } // namespace V1_1 |
| 89 | } // namespace neuralnetworks |
| 90 | } // namespace hardware |
| 91 | } // namespace android |