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