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 | 62749b9 | 2019-08-26 23:55:47 -0700 | [diff] [blame] | 24 | namespace android::hardware::neuralnetworks::V1_1::vts::functional { |
Michael Butler | 7ed6135 | 2018-03-22 16:37:57 -0700 | [diff] [blame] | 25 | |
Michael Butler | 62749b9 | 2019-08-26 23:55:47 -0700 | [diff] [blame] | 26 | using V1_0::ErrorStatus; |
| 27 | using V1_0::IPreparedModel; |
| 28 | using V1_0::Request; |
| 29 | using V1_0::implementation::ExecutionCallback; |
Michael Butler | 7ed6135 | 2018-03-22 16:37:57 -0700 | [diff] [blame] | 30 | |
Michael Butler | 68a6de7 | 2020-03-11 18:45:45 -0700 | [diff] [blame] | 31 | using ExecutionMutation = std::function<void(Request*)>; |
| 32 | |
Michael Butler | 7ed6135 | 2018-03-22 16:37:57 -0700 | [diff] [blame] | 33 | ///////////////////////// UTILITY FUNCTIONS ///////////////////////// |
| 34 | |
Michael Butler | 7ed6135 | 2018-03-22 16:37:57 -0700 | [diff] [blame] | 35 | // Primary validation function. This function will take a valid request, apply a |
| 36 | // mutation to it to invalidate the request, then pass it to interface calls |
Michael Butler | 68a6de7 | 2020-03-11 18:45:45 -0700 | [diff] [blame] | 37 | // that use the request. |
Michael Butler | 7ed6135 | 2018-03-22 16:37:57 -0700 | [diff] [blame] | 38 | static void validate(const sp<IPreparedModel>& preparedModel, const std::string& message, |
Michael Butler | 68a6de7 | 2020-03-11 18:45:45 -0700 | [diff] [blame] | 39 | const Request& originalRequest, const ExecutionMutation& mutate) { |
| 40 | Request request = originalRequest; |
| 41 | mutate(&request); |
Michael Butler | 7ed6135 | 2018-03-22 16:37:57 -0700 | [diff] [blame] | 42 | SCOPED_TRACE(message + " [execute]"); |
| 43 | |
| 44 | sp<ExecutionCallback> executionCallback = new ExecutionCallback(); |
Michael Butler | 7ed6135 | 2018-03-22 16:37:57 -0700 | [diff] [blame] | 45 | Return<ErrorStatus> executeLaunchStatus = preparedModel->execute(request, executionCallback); |
| 46 | ASSERT_TRUE(executeLaunchStatus.isOk()); |
| 47 | ASSERT_EQ(ErrorStatus::INVALID_ARGUMENT, static_cast<ErrorStatus>(executeLaunchStatus)); |
| 48 | |
| 49 | executionCallback->wait(); |
| 50 | ErrorStatus executionReturnStatus = executionCallback->getStatus(); |
| 51 | ASSERT_EQ(ErrorStatus::INVALID_ARGUMENT, executionReturnStatus); |
| 52 | } |
| 53 | |
Michael Butler | 7ed6135 | 2018-03-22 16:37:57 -0700 | [diff] [blame] | 54 | ///////////////////////// REMOVE INPUT //////////////////////////////////// |
| 55 | |
| 56 | static void removeInputTest(const sp<IPreparedModel>& preparedModel, const Request& request) { |
| 57 | for (size_t input = 0; input < request.inputs.size(); ++input) { |
| 58 | const std::string message = "removeInput: removed input " + std::to_string(input); |
| 59 | validate(preparedModel, message, request, |
| 60 | [input](Request* request) { hidl_vec_removeAt(&request->inputs, input); }); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | ///////////////////////// REMOVE OUTPUT //////////////////////////////////// |
| 65 | |
| 66 | static void removeOutputTest(const sp<IPreparedModel>& preparedModel, const Request& request) { |
| 67 | for (size_t output = 0; output < request.outputs.size(); ++output) { |
| 68 | const std::string message = "removeOutput: removed Output " + std::to_string(output); |
| 69 | validate(preparedModel, message, request, |
| 70 | [output](Request* request) { hidl_vec_removeAt(&request->outputs, output); }); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | ///////////////////////////// ENTRY POINT ////////////////////////////////// |
| 75 | |
Michael Butler | 13b0516 | 2019-08-29 22:17:24 -0700 | [diff] [blame] | 76 | void validateRequest(const sp<IPreparedModel>& preparedModel, const Request& request) { |
Xusong Wang | 8161196 | 2019-08-09 16:41:16 -0700 | [diff] [blame] | 77 | removeInputTest(preparedModel, request); |
| 78 | removeOutputTest(preparedModel, request); |
Michael Butler | 7ed6135 | 2018-03-22 16:37:57 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Michael Butler | 62749b9 | 2019-08-26 23:55:47 -0700 | [diff] [blame] | 81 | } // namespace android::hardware::neuralnetworks::V1_1::vts::functional |