1 /*
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
39 namespace
40 {
41 using namespace arm_compute;
42
43 const auto correct_shape = TensorShape(1, 2, 3, 4); // target shape to check against
44 const auto wrong_shape = TensorShape(1, 2, 2, 4); // wrong shape to check validate logic
45 const auto correct_dt = DataType::U8; // correct data type to check against
46 const auto wrong_dt = DataType::F32; // wrong data type to check validate logic
47 }
48
49 namespace arm_compute
50 {
51 namespace test
52 {
53 namespace validation
54 {
55 TEST_SUITE(CL)
TEST_SUITE(LogicalOr)56 TEST_SUITE(LogicalOr)
57 TEST_SUITE(Validate)
58 TEST_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
TEST_CASE(WrongDataType,framework::DatasetMode::ALL)64 TEST_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 }
73 TEST_SUITE_END() // Validate
74 template <typename T>
75 using CLLogicalOrFixture = LogicalOrValidationFixture<CLTensor, CLAccessor, CLLogicalOr, T>;
76
FIXTURE_DATA_TEST_CASE(RunSmall,CLLogicalOrFixture<uint8_t>,framework::DatasetMode::ALL,zip (datasets::SmallShapes (),datasets::SmallShapes ()))77 FIXTURE_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
FIXTURE_DATA_TEST_CASE(RunSmallBroadcast,CLLogicalOrFixture<uint8_t>,framework::DatasetMode::ALL,datasets::SmallShapesBroadcast ())83 FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLLogicalOrFixture<uint8_t>, framework::DatasetMode::ALL, datasets::SmallShapesBroadcast())
84 {
85 // Validate output
86 validate(CLAccessor(_target), _reference);
87 }
88 TEST_SUITE_END() // LogicalOr
89
TEST_SUITE(LogicalAnd)90 TEST_SUITE(LogicalAnd)
91 TEST_SUITE(Validate)
92 TEST_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
TEST_CASE(WrongDataType,framework::DatasetMode::ALL)98 TEST_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 }
107 TEST_SUITE_END() // Validate
108 template <typename T>
109 using CLLogicalAndFixture = LogicalAndValidationFixture<CLTensor, CLAccessor, CLLogicalAnd, T>;
110
FIXTURE_DATA_TEST_CASE(RunSmall,CLLogicalAndFixture<uint8_t>,framework::DatasetMode::ALL,zip (datasets::SmallShapes (),datasets::SmallShapes ()))111 FIXTURE_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
FIXTURE_DATA_TEST_CASE(RunSmallBroadcast,CLLogicalAndFixture<uint8_t>,framework::DatasetMode::ALL,datasets::SmallShapesBroadcast ())117 FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLLogicalAndFixture<uint8_t>, framework::DatasetMode::ALL, datasets::SmallShapesBroadcast())
118 {
119 // Validate output
120 validate(CLAccessor(_target), _reference);
121 }
122 TEST_SUITE_END() // LogicalAnd
TEST_SUITE(LogicalNot)123 TEST_SUITE(LogicalNot)
124
125 TEST_SUITE(Validate)
126 TEST_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
TEST_CASE(WrongDataType,framework::DatasetMode::ALL)132 TEST_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
TEST_CASE(WrongShape,framework::DatasetMode::ALL)153 TEST_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 }
161 TEST_SUITE_END() // Validate
162
163 template <typename T>
164 using CLLogicalNotFixture = LogicalNotValidationFixture<CLTensor, CLAccessor, CLLogicalNot, T>;
165
166 FIXTURE_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 }
172 TEST_SUITE_END() // LogicalNot
173 TEST_SUITE_END() // CL
174 } // namespace validation
175 } // namespace test
176 } // namespace arm_compute
177