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_CONTEXT_FIXTURE 25 #define ARM_COMPUTE_TEST_UNIT_CONTEXT_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 AclDestroyContext 40 * 41 * Validate that AclDestroyContext behaves as expected when invalid inputs as context are given 42 * 43 * Test Steps: 44 * - Call AclDestroyContext with null context 45 * - Confirm that AclInvalidArgument is reported 46 * - Call AclDestroyContext on empty array 47 * - Confirm that AclInvalidArgument is reported 48 * - Call AclDestroyContext on an ACL object other than AclContext 49 * - Confirm that AclInvalidArgument is reported 50 * - Confirm that context is still nullptr 51 */ 52 template <AclTarget Target> 53 class DestroyInvalidContextFixture : public framework::Fixture 54 { 55 public: setup()56 void setup() 57 { 58 AclContext ctx = nullptr; 59 std::array<char, 256> empty_array{}; 60 AclContext valid_ctx = nullptr; 61 ARM_COMPUTE_ASSERT(AclCreateContext(&valid_ctx, Target, nullptr) == AclStatus::AclSuccess); 62 ARM_COMPUTE_ASSERT(AclDestroyContext(ctx) == AclStatus::AclInvalidArgument); 63 ARM_COMPUTE_ASSERT(AclDestroyContext(reinterpret_cast<AclContext>(empty_array.data())) == AclStatus::AclInvalidArgument); 64 ARM_COMPUTE_ASSERT(ctx == nullptr); 65 ARM_COMPUTE_ASSERT(AclDestroyContext(valid_ctx) == AclStatus::AclSuccess); 66 }; 67 }; 68 69 /** Test-case for AclCreateContext and AclDestroyContext 70 * 71 * Validate that AclCreateContext can create and destroy a context through the C API 72 * 73 * Test Steps: 74 * - Call AclCreateContext with valid target 75 * - Confirm that context is not nullptr and error code is AclSuccess 76 * - Destroy context 77 * - Confirm that AclSuccess is reported 78 */ 79 template <AclTarget Target> 80 class SimpleContextCApiFixture : public framework::Fixture 81 { 82 public: setup()83 void setup() 84 { 85 AclContext ctx = nullptr; 86 ARM_COMPUTE_ASSERT(AclCreateContext(&ctx, Target, nullptr) == AclStatus::AclSuccess); 87 ARM_COMPUTE_ASSERT(ctx != nullptr); 88 ARM_COMPUTE_ASSERT(AclDestroyContext(ctx) == AclStatus::AclSuccess); 89 }; 90 }; 91 92 /** Test-case for Context from the C++ interface 93 * 94 * Test Steps: 95 * - Create a Context obejct 96 * - Confirm that StatusCode::Success is reported 97 * - Confirm that equality operator works 98 * - Confirm that inequality operator works 99 */ 100 template <acl::Target Target> 101 class SimpleContextCppApiFixture : public framework::Fixture 102 { 103 public: setup()104 void setup() 105 { 106 acl::StatusCode status = acl::StatusCode::Success; 107 acl::Context ctx(Target, &status); 108 ARM_COMPUTE_ASSERT(status == acl::StatusCode::Success); 109 110 auto ctx_eq = ctx; 111 ARM_COMPUTE_ASSERT(ctx_eq == ctx); 112 113 acl::Context ctx_ienq(Target, &status); 114 ARM_COMPUTE_ASSERT(status == acl::StatusCode::Success); 115 ARM_COMPUTE_ASSERT(ctx_ienq != ctx); 116 }; 117 }; 118 119 /** Test-case for multiple contexes 120 * 121 * Validate that AclCreateContext can create/destroy multiple contexts with different options 122 * 123 * Test Steps: 124 * - Call AclCreateContext with different targets 125 * - Confirm that AclSuccess is reported 126 * - Destroy all contexts 127 * - Confirm that AclSuccess is reported 128 */ 129 template <AclTarget Target> 130 class MultipleContextsFixture : public framework::Fixture 131 { 132 public: setup()133 void setup() 134 { 135 const unsigned int num_tests = 5; 136 std::array<AclContext, num_tests> ctxs{}; 137 for(unsigned int i = 0; i < num_tests; ++i) 138 { 139 ARM_COMPUTE_ASSERT(AclCreateContext(&ctxs[i], Target, nullptr) == AclStatus::AclSuccess); 140 ARM_COMPUTE_ASSERT(ctxs[i] != nullptr); 141 ARM_COMPUTE_ASSERT(AclDestroyContext(ctxs[i]) == AclStatus::AclSuccess); 142 } 143 }; 144 }; 145 } // namespace validation 146 } // namespace test 147 } // namespace arm_compute 148 #endif /* ARM_COMPUTE_TEST_UNIT_CONTEXT_FIXTURE */ 149