1 /* 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 */ 24 #ifndef ARM_COMPUTE_TEST_UNIT_QUEUE_FIXTURE 25 #define ARM_COMPUTE_TEST_UNIT_QUEUE_FIXTURE 26 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 33 namespace arm_compute 34 { 35 namespace test 36 { 37 namespace validation 38 { 39 /** Test case for AclCreateQueue 40 * 41 * Validate that AclCreateQueue behaves as expected with invalid context 42 * 43 * Test Steps: 44 * - Call AclCreateQueue with an invalid context 45 * - Confirm that AclInvalidArgument is reported 46 * - Confirm that the queue is still nullptr 47 */ 48 class CreateQueueWithInvalidContextFixture : public framework::Fixture 49 { 50 public: setup()51 void setup() 52 { 53 AclQueue queue = nullptr; 54 ARM_COMPUTE_ASSERT(AclCreateQueue(&queue, nullptr, nullptr) == AclStatus::AclInvalidArgument); 55 ARM_COMPUTE_ASSERT(queue == nullptr); 56 }; 57 }; 58 59 /** Test-case for AclCreateQueue 60 * 61 * Validate that AclCreateQueue behaves as expected with invalid options 62 * 63 * Test Steps: 64 * - Call AclCreateQueue with valid context but invalid options 65 * - Confirm that AclInvalidArgument is reported 66 * - Confirm that queue is still nullptr 67 */ 68 template <acl::Target Target> 69 class CreateQueuerWithInvalidOptionsFixture : public framework::Fixture 70 { 71 public: setup()72 void setup() 73 { 74 acl::Context ctx(Target); 75 76 // Check invalid tuning mode 77 AclQueueOptions invalid_queue_opts; 78 invalid_queue_opts.mode = static_cast<AclTuningMode>(-1); 79 80 AclQueue queue = nullptr; 81 ARM_COMPUTE_ASSERT(AclCreateQueue(&queue, ctx.get(), &invalid_queue_opts) == AclStatus::AclInvalidArgument); 82 ARM_COMPUTE_ASSERT(queue == nullptr); 83 }; 84 }; 85 86 /** Test case for AclDestroyQueue 87 * 88 * Validate that AclDestroyQueue behaves as expected when an invalid queue is given 89 * 90 * Test Steps: 91 * - Call AclDestroyQueue with null queue 92 * - Confirm that AclInvalidArgument is reported 93 * - Call AclDestroyQueue on empty array 94 * - Confirm that AclInvalidArgument is reported 95 * - Call AclDestroyQueue on an ACL object other than AclQueue 96 * - Confirm that AclInvalidArgument is reported 97 * - Confirm that queue is still nullptr 98 */ 99 template <acl::Target Target> 100 class DestroyInvalidQueueFixture : public framework::Fixture 101 { 102 public: setup()103 void setup() 104 { 105 acl::Context ctx(Target); 106 107 std::array<char, 256> empty_array{}; 108 AclQueue queue = nullptr; 109 110 ARM_COMPUTE_ASSERT(AclDestroyQueue(queue) == AclStatus::AclInvalidArgument); 111 ARM_COMPUTE_ASSERT(AclDestroyQueue(reinterpret_cast<AclQueue>(ctx.get())) == AclStatus::AclInvalidArgument); 112 ARM_COMPUTE_ASSERT(AclDestroyQueue(reinterpret_cast<AclQueue>(empty_array.data())) == AclStatus::AclInvalidArgument); 113 ARM_COMPUTE_ASSERT(queue == nullptr); 114 }; 115 }; 116 117 /** Test case for AclCreateQueue 118 * 119 * Validate that a queue can be created successfully 120 * 121 * Test Steps: 122 * - Create a valid context 123 * - Create a valid queue 124 * - Confirm that AclSuccess is returned 125 */ 126 template <acl::Target Target> 127 class SimpleQueueFixture : public framework::Fixture 128 { 129 public: setup()130 void setup() 131 { 132 acl::StatusCode err = acl::StatusCode::Success; 133 134 acl::Context ctx(Target, &err); 135 ARM_COMPUTE_ASSERT(err == acl::StatusCode::Success); 136 137 acl::Queue queue(ctx, &err); 138 ARM_COMPUTE_ASSERT(err == acl::StatusCode::Success); 139 }; 140 }; 141 } // namespace validation 142 } // namespace test 143 } // namespace arm_compute 144 #endif /* ARM_COMPUTE_TEST_UNIT_QUEUE_FIXTURE */ 145