blob: bc14631936f2bb129dfff1e218a5f0077175a21b [file] [log] [blame]
Georgios Pinitas3f26ef42021-02-23 10:01:33 +00001/*
2 * Copyright (c) 2021 Arm Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
Georgios Pinitasc3c352e2021-03-18 10:59:40 +000024#ifndef ARM_COMPUTE_TEST_UNIT_TENSORPACK_FIXTURE
25#define ARM_COMPUTE_TEST_UNIT_TENSORPACK_FIXTURE
Georgios Pinitas3f26ef42021-02-23 10:01:33 +000026
27#include "arm_compute/Acl.hpp"
28#include "tests/framework/Asserts.h"
29#include "tests/framework/Fixture.h"
30#include "tests/framework/Macros.h"
31#include "tests/validation/Validation.h"
32
33namespace arm_compute
34{
35namespace test
36{
37namespace validation
38{
39/** Test case for AclCreateTensorPack
40 *
41 * Validate that AclCreateTensorPack behaves as expected with invalid context
42 *
43 * Test Steps:
44 * - Call AclCreateTensorPack with an invalid context
45 * - Confirm that AclInvalidArgument is reported
46 * - Confirm that the tensor pack is still nullptr
47 */
48class CreateTensorPackWithInvalidContextFixture : public framework::Fixture
49{
50public:
51 void setup()
52 {
53 AclTensorPack pack = nullptr;
54 ARM_COMPUTE_ASSERT(AclCreateTensorPack(&pack, nullptr) == AclStatus::AclInvalidArgument);
55 ARM_COMPUTE_ASSERT(pack == nullptr);
56 };
57};
58
59/** Test case for AclDestroyTensorPack
60 *
61 * Validate that AclDestroyTensorPack behaves as expected when an invalid tensor pack is given
62 *
63 * Test Steps:
64 * - Call AclDestroyTensorPack with null tensor pack
65 * - Confirm that AclInvalidArgument is reported
66 * - Call AclDestroyTensorPack on empty array
67 * - Confirm that AclInvalidArgument is reported
68 * - Call AclDestroyTensorPack on an ACL object other than AclTensorPack
69 * - Confirm that AclInvalidArgument is reported
70 * - Confirm that tensor pack is still nullptr
71 */
72template <acl::Target Target>
73class DestroyInvalidTensorPackFixture : public framework::Fixture
74{
75public:
76 void setup()
77 {
78 acl::Context ctx(Target);
79
80 std::array<char, 256> empty_array{};
81 AclTensorPack pack = nullptr;
82
83 ARM_COMPUTE_ASSERT(AclDestroyTensorPack(pack) == AclStatus::AclInvalidArgument);
84 ARM_COMPUTE_ASSERT(AclDestroyTensorPack(reinterpret_cast<AclTensorPack>(ctx.get())) == AclStatus::AclInvalidArgument);
85 ARM_COMPUTE_ASSERT(AclDestroyTensorPack(reinterpret_cast<AclTensorPack>(empty_array.data())) == AclStatus::AclInvalidArgument);
86 ARM_COMPUTE_ASSERT(pack == nullptr);
87 };
88};
89
90/** Test case for AclPackTensor
91 *
92 * Validate that AclPackTensor behaves as expected when an invalid is being passed for packing
93 *
94 * Test Steps:
95 * - Create a valid TensorPack
96 * - Try to pack an empty object
97 * - Confirm that AclInvalidArgument is reported
98 * - Try to pack another API object other than tensor
99 * - Confirm that AclInvalidArgument is reported
100 */
101template <acl::Target Target>
102class AddInvalidObjectToTensorPackFixture : public framework::Fixture
103{
104public:
105 void setup()
106 {
107 auto err = acl::StatusCode::Success;
108
109 acl::Context ctx(Target, &err);
110 ARM_COMPUTE_ASSERT(err == acl::StatusCode::Success);
111
112 acl::TensorPack pack(ctx, &err);
113 ARM_COMPUTE_ASSERT(err == acl::StatusCode::Success);
114
115 auto status = AclPackTensor(pack.get(),
116 reinterpret_cast<AclTensor>(ctx.get()),
117 AclTensorSlot::AclSrc);
118 ARM_COMPUTE_ASSERT(status == AclInvalidArgument);
119
120 status = AclPackTensor(pack.get(), nullptr, AclTensorSlot::AclSrc);
121 ARM_COMPUTE_ASSERT(status == AclInvalidArgument);
122 };
123};
124
125/** Test case for AclPackTensor
126 *
127 * Validate that a tensor can be added successfully to the TensorPack
128 *
129 * Test Steps:
130 * - Create a valid tensor pack
131 * - Create a valid tensor
132 * - Add tensor to the tensor pack
133 * - Confirm that AclSuccess is returned
134 */
135template <acl::Target Target>
136class SimpleTensorPackFixture : public framework::Fixture
137{
138public:
139 void setup()
140 {
141 acl::Context ctx(Target);
142 acl::TensorPack pack(ctx);
143 acl::Tensor t(ctx, acl::TensorDescriptor({ 3, 3, 5, 7 }, acl::DataType::Float32));
144
145 ARM_COMPUTE_ASSERT(pack.add(t, AclTensorSlot::AclSrc) == acl::StatusCode::Success);
146 };
147};
148
149/** Test case for AclPackTensor
150 *
151 * Validate that multiple tensor can be added successfully to the TensorPack
152 *
153 * Test Steps:
154 * - Create a valid tensor pack
155 * - Create a list of valid tensors
156 * - Add tensors to the tensor pack
157 * - Confirm that AclSuccess is returned
158 */
159template <acl::Target Target>
160class MultipleTensorsInPackFixture : public framework::Fixture
161{
162public:
163 void setup()
164 {
165 acl::Context ctx(Target);
166 acl::TensorPack pack(ctx);
167
168 const acl::TensorDescriptor desc(acl::TensorDescriptor({ 3, 3, 5, 7 }, acl::DataType::Float32));
169 const size_t num_tensors = 256;
170
171 std::vector<acl::Tensor> tensors;
172 for(unsigned int i = 0; i < num_tensors; ++i)
173 {
174 auto err = acl::StatusCode::Success;
175 tensors.emplace_back(acl::Tensor(ctx, desc, &err));
176 ARM_COMPUTE_ASSERT(err == acl::StatusCode::Success);
177 ARM_COMPUTE_ASSERT(pack.add(tensors.back(), static_cast<int32_t>(AclTensorSlot::AclSrcVec) + i) == acl::StatusCode::Success);
178 }
179 };
180};
181} // namespace validation
182} // namespace test
183} // namespace arm_compute
Georgios Pinitasc3c352e2021-03-18 10:59:40 +0000184#endif /* ARM_COMPUTE_TEST_UNIT_TENSORPACK_FIXTURE */