blob: a4e4ade84fb8af7dbe91c0e8ec034f32b83c51d7 [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 Butler62749b92019-08-26 23:55:47 -070024namespace android::hardware::neuralnetworks::V1_1::vts::functional {
Michael Butler7ed61352018-03-22 16:37:57 -070025
Michael Butler62749b92019-08-26 23:55:47 -070026using V1_0::ErrorStatus;
27using V1_0::IPreparedModel;
28using V1_0::Request;
29using V1_0::implementation::ExecutionCallback;
Michael Butler7ed61352018-03-22 16:37:57 -070030
31///////////////////////// UTILITY FUNCTIONS /////////////////////////
32
Michael Butler7ed61352018-03-22 16:37:57 -070033// Primary validation function. This function will take a valid request, apply a
34// mutation to it to invalidate the request, then pass it to interface calls
35// that use the request. Note that the request here is passed by value, and any
36// mutation to the request does not leave this function.
37static void validate(const sp<IPreparedModel>& preparedModel, const std::string& message,
38 Request request, const std::function<void(Request*)>& mutation) {
39 mutation(&request);
40 SCOPED_TRACE(message + " [execute]");
41
42 sp<ExecutionCallback> executionCallback = new ExecutionCallback();
Michael Butler7ed61352018-03-22 16:37:57 -070043 Return<ErrorStatus> executeLaunchStatus = preparedModel->execute(request, executionCallback);
44 ASSERT_TRUE(executeLaunchStatus.isOk());
45 ASSERT_EQ(ErrorStatus::INVALID_ARGUMENT, static_cast<ErrorStatus>(executeLaunchStatus));
46
47 executionCallback->wait();
48 ErrorStatus executionReturnStatus = executionCallback->getStatus();
49 ASSERT_EQ(ErrorStatus::INVALID_ARGUMENT, executionReturnStatus);
50}
51
Michael Butler7ed61352018-03-22 16:37:57 -070052///////////////////////// REMOVE INPUT ////////////////////////////////////
53
54static void removeInputTest(const sp<IPreparedModel>& preparedModel, const Request& request) {
55 for (size_t input = 0; input < request.inputs.size(); ++input) {
56 const std::string message = "removeInput: removed input " + std::to_string(input);
57 validate(preparedModel, message, request,
58 [input](Request* request) { hidl_vec_removeAt(&request->inputs, input); });
59 }
60}
61
62///////////////////////// REMOVE OUTPUT ////////////////////////////////////
63
64static void removeOutputTest(const sp<IPreparedModel>& preparedModel, const Request& request) {
65 for (size_t output = 0; output < request.outputs.size(); ++output) {
66 const std::string message = "removeOutput: removed Output " + std::to_string(output);
67 validate(preparedModel, message, request,
68 [output](Request* request) { hidl_vec_removeAt(&request->outputs, output); });
69 }
70}
71
72///////////////////////////// ENTRY POINT //////////////////////////////////
73
Xusong Wang81611962019-08-09 16:41:16 -070074void ValidationTest::validateRequest(const sp<IPreparedModel>& preparedModel,
75 const Request& request) {
76 removeInputTest(preparedModel, request);
77 removeOutputTest(preparedModel, request);
Michael Butler7ed61352018-03-22 16:37:57 -070078}
79
Michael Butler62749b92019-08-26 23:55:47 -070080} // namespace android::hardware::neuralnetworks::V1_1::vts::functional