blob: e0710f119e0dbb758c7395c9ca6df264a1c551de [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"
Xusong Wangbcaa7822019-08-23 16:10:54 -070021#include "GeneratedTestHarness.h"
Slava Shklyaev73ee79d2019-05-14 14:15:14 +010022#include "VtsHalNeuralnetworks.h"
23
Michael Butler7ed61352018-03-22 16:37:57 -070024namespace android {
25namespace hardware {
26namespace neuralnetworks {
27namespace V1_1 {
28namespace vts {
29namespace functional {
30
Slava Shklyaev73ee79d2019-05-14 14:15:14 +010031using ::android::hardware::neuralnetworks::V1_0::ErrorStatus;
32using ::android::hardware::neuralnetworks::V1_0::Request;
Slava Shklyaev73ee79d2019-05-14 14:15:14 +010033using ::android::hardware::neuralnetworks::V1_0::implementation::ExecutionCallback;
34using ::android::hardware::neuralnetworks::V1_1::IPreparedModel;
Michael Butler7ed61352018-03-22 16:37:57 -070035
36///////////////////////// UTILITY FUNCTIONS /////////////////////////
37
Michael Butler7ed61352018-03-22 16:37:57 -070038// 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.
42static 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 Butler7ed61352018-03-22 16:37:57 -070058///////////////////////// REMOVE INPUT ////////////////////////////////////
59
60static 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
70static 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 Wang81611962019-08-09 16:41:16 -070080void ValidationTest::validateRequest(const sp<IPreparedModel>& preparedModel,
81 const Request& request) {
82 removeInputTest(preparedModel, request);
83 removeOutputTest(preparedModel, request);
Michael Butler7ed61352018-03-22 16:37:57 -070084}
85
86} // namespace functional
87} // namespace vts
88} // namespace V1_1
89} // namespace neuralnetworks
90} // namespace hardware
91} // namespace android