blob: 521e524687bbd771e189c4cbf918f9c4cac22975 [file] [log] [blame]
Slava Shklyaev73ee79d2019-05-14 14:15:14 +01001/*
2 * Copyright (C) 2019 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#include "GeneratedTestHarness.h"
18#include "TestHarness.h"
19
20#include <android/hardware/neuralnetworks/1.0/types.h>
21
22#include <cstring>
23#include <map>
24#include <vector>
25
26namespace android {
27namespace hardware {
28namespace neuralnetworks {
29
30using ::android::hardware::neuralnetworks::V1_0::RequestArgument;
31using ::test_helper::for_each;
32using ::test_helper::MixedTyped;
33
34template <typename T>
35void copy_back_(std::map<int, std::vector<T>>* dst, const std::vector<RequestArgument>& ra,
36 char* src) {
37 for_each<T>(*dst, [&ra, src](int index, std::vector<T>& m) {
38 ASSERT_EQ(m.size(), ra[index].location.length / sizeof(T));
39 char* begin = src + ra[index].location.offset;
40 memcpy(m.data(), begin, ra[index].location.length);
41 });
42}
43
44void copy_back(MixedTyped* dst, const std::vector<RequestArgument>& ra, char* src) {
45 copy_back_(&dst->float32Operands, ra, src);
46 copy_back_(&dst->int32Operands, ra, src);
47 copy_back_(&dst->quant8AsymmOperands, ra, src);
48 copy_back_(&dst->quant16SymmOperands, ra, src);
49 copy_back_(&dst->float16Operands, ra, src);
50 copy_back_(&dst->bool8Operands, ra, src);
51 copy_back_(&dst->quant8ChannelOperands, ra, src);
52 copy_back_(&dst->quant16AsymmOperands, ra, src);
53 copy_back_(&dst->quant8SymmOperands, ra, src);
54 static_assert(9 == MixedTyped::kNumTypes,
55 "Number of types in MixedTyped changed, but copy_back function wasn't updated");
56}
57
58} // namespace neuralnetworks
59} // namespace hardware
60} // namespace android