blob: ecdb7c8f53047da9bc7fad355c0ad525f2e057a5 [file] [log] [blame]
Sang-Hoon Park75eea332020-11-13 13:44:13 +00001/*
2 * Copyright (c) 2020 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 */
24#include "arm_compute/core/Types.h"
25#include "arm_compute/runtime/CL/functions/CLLogicalAnd.h"
26#include "arm_compute/runtime/CL/functions/CLLogicalNot.h"
27#include "arm_compute/runtime/CL/functions/CLLogicalOr.h"
28#include "arm_compute/runtime/Tensor.h"
29#include "arm_compute/runtime/TensorAllocator.h"
30#include "tests/CL/CLAccessor.h"
31#include "tests/PaddingCalculator.h"
32#include "tests/datasets/ShapeDatasets.h"
33#include "tests/framework/Asserts.h"
34#include "tests/framework/Macros.h"
35#include "tests/framework/datasets/Datasets.h"
36#include "tests/validation/Validation.h"
37#include "tests/validation/fixtures/LogicalFixture.h"
38
39namespace
40{
41using namespace arm_compute;
42
43const auto correct_shape = TensorShape(1, 2, 3, 4); // target shape to check against
44const auto wrong_shape = TensorShape(1, 2, 2, 4); // wrong shape to check validate logic
45const auto correct_dt = DataType::U8; // correct data type to check against
46const auto wrong_dt = DataType::F32; // wrong data type to check validate logic
47}
48
49namespace arm_compute
50{
51namespace test
52{
53namespace validation
54{
55TEST_SUITE(CL)
56TEST_SUITE(LogicalOr)
57TEST_SUITE(Validate)
58TEST_CASE(NullPtr, framework::DatasetMode::ALL)
59{
60 Status s = CLLogicalOr::validate(nullptr, nullptr, nullptr);
61 ARM_COMPUTE_EXPECT((bool)s == false, framework::LogLevel::ERRORS);
62}
63
64TEST_CASE(WrongDataType, framework::DatasetMode::ALL)
65{
66 TensorInfo in1{ correct_shape, 1, correct_dt };
67 TensorInfo in2{ correct_shape, 1, wrong_dt };
68 TensorInfo out{ correct_shape, 1, correct_dt };
69
70 Status s = CLLogicalOr::validate(&in1, &in2, &out);
71 ARM_COMPUTE_EXPECT((bool)s == false, framework::LogLevel::ERRORS);
72}
73TEST_SUITE_END() // Validate
74template <typename T>
75using CLLogicalOrFixture = LogicalOrValidationFixture<CLTensor, CLAccessor, CLLogicalOr, T>;
76
77FIXTURE_DATA_TEST_CASE(RunSmall, CLLogicalOrFixture<uint8_t>, framework::DatasetMode::ALL, zip(datasets::SmallShapes(), datasets::SmallShapes()))
78{
79 // Validate output
80 validate(CLAccessor(_target), _reference);
81}
82
83FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLLogicalOrFixture<uint8_t>, framework::DatasetMode::ALL, datasets::SmallShapesBroadcast())
84{
85 // Validate output
86 validate(CLAccessor(_target), _reference);
87}
88TEST_SUITE_END() // LogicalOr
89
90TEST_SUITE(LogicalAnd)
91TEST_SUITE(Validate)
92TEST_CASE(NullPtr, framework::DatasetMode::ALL)
93{
94 Status s = CLLogicalAnd::validate(nullptr, nullptr, nullptr);
95 ARM_COMPUTE_EXPECT((bool)s == false, framework::LogLevel::ERRORS);
96}
97
98TEST_CASE(WrongDataType, framework::DatasetMode::ALL)
99{
100 TensorInfo in1{ correct_shape, 1, correct_dt };
101 TensorInfo in2{ correct_shape, 1, wrong_dt };
102 TensorInfo out{ correct_shape, 1, correct_dt };
103
104 Status s = CLLogicalAnd::validate(&in1, &in2, &out);
105 ARM_COMPUTE_EXPECT((bool)s == false, framework::LogLevel::ERRORS);
106}
107TEST_SUITE_END() // Validate
108template <typename T>
109using CLLogicalAndFixture = LogicalAndValidationFixture<CLTensor, CLAccessor, CLLogicalAnd, T>;
110
111FIXTURE_DATA_TEST_CASE(RunSmall, CLLogicalAndFixture<uint8_t>, framework::DatasetMode::ALL, zip(datasets::SmallShapes(), datasets::SmallShapes()))
112{
113 // Validate output
114 validate(CLAccessor(_target), _reference);
115}
116
117FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLLogicalAndFixture<uint8_t>, framework::DatasetMode::ALL, datasets::SmallShapesBroadcast())
118{
119 // Validate output
120 validate(CLAccessor(_target), _reference);
121}
122TEST_SUITE_END() // LogicalAnd
123TEST_SUITE(LogicalNot)
124
125TEST_SUITE(Validate)
126TEST_CASE(NullPtr, framework::DatasetMode::ALL)
127{
128 Status s = CLLogicalNot::validate(nullptr, nullptr);
129 ARM_COMPUTE_EXPECT((bool)s == false, framework::LogLevel::ERRORS);
130}
131
132TEST_CASE(WrongDataType, framework::DatasetMode::ALL)
133{
134 TensorInfo in{ correct_shape, 1, correct_dt };
135 TensorInfo out{ correct_shape, 1, wrong_dt };
136
137 Status s = CLLogicalNot::validate(&in, &out);
138 ARM_COMPUTE_EXPECT((bool)s == false, framework::LogLevel::ERRORS);
139
140 in = TensorInfo{ correct_shape, 1, wrong_dt };
141 out = TensorInfo{ correct_shape, 1, correct_dt };
142
143 s = CLLogicalNot::validate(&in, &out);
144 ARM_COMPUTE_EXPECT((bool)s == false, framework::LogLevel::ERRORS);
145
146 in = TensorInfo{ correct_shape, 1, wrong_dt };
147 out = TensorInfo{ correct_shape, 1, wrong_dt };
148
149 s = CLLogicalNot::validate(&in, &out);
150 ARM_COMPUTE_EXPECT((bool)s == false, framework::LogLevel::ERRORS);
151}
152
153TEST_CASE(WrongShape, framework::DatasetMode::ALL)
154{
155 TensorInfo in{ correct_shape, 1, correct_dt };
156 TensorInfo out{ wrong_shape, 1, correct_dt };
157
158 Status s = CLLogicalNot::validate(&in, &out);
159 ARM_COMPUTE_EXPECT((bool)s == false, framework::LogLevel::ERRORS);
160}
161TEST_SUITE_END() // Validate
162
163template <typename T>
164using CLLogicalNotFixture = LogicalNotValidationFixture<CLTensor, CLAccessor, CLLogicalNot, T>;
165
166FIXTURE_DATA_TEST_CASE(RunSmall, CLLogicalNotFixture<uint8_t>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("DataType",
167 DataType::U8)))
168{
169 // Validate output
170 validate(CLAccessor(_target), _reference);
171}
172TEST_SUITE_END() // LogicalNot
173TEST_SUITE_END() // CL
174} // namespace validation
175} // namespace test
176} // namespace arm_compute