aboutsummaryrefslogtreecommitdiff
path: root/tests/validation/fixtures/UNIT/QueueFixture.h
blob: bc93f5f12022a917269b018d8ad508446b77c998 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
 * Copyright (c) 2021 Arm Limited.
 *
 * SPDX-License-Identifier: MIT
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
#ifndef ARM_COMPUTE_TEST_UNIT_QUEUE_FIXTURE
#define ARM_COMPUTE_TEST_UNIT_QUEUE_FIXTURE

#include "arm_compute/Acl.hpp"
#include "tests/framework/Asserts.h"
#include "tests/framework/Fixture.h"
#include "tests/framework/Macros.h"
#include "tests/validation/Validation.h"

namespace arm_compute
{
namespace test
{
namespace validation
{
/** Test case for AclCreateQueue
 *
 * Validate that AclCreateQueue behaves as expected with invalid context
 *
 * Test Steps:
 *  - Call AclCreateQueue with an invalid context
 *  - Confirm that AclInvalidArgument is reported
 *  - Confirm that the queue is still nullptr
 */
class CreateQueueWithInvalidContextFixture : public framework::Fixture
{
public:
    void setup()
    {
        AclQueue queue = nullptr;
        ARM_COMPUTE_ASSERT(AclCreateQueue(&queue, nullptr, nullptr) == AclStatus::AclInvalidArgument);
        ARM_COMPUTE_ASSERT(queue == nullptr);
    };
};

/** Test-case for AclCreateQueue
 *
 * Validate that AclCreateQueue behaves as expected with invalid options
 *
 * Test Steps:
 *  - Call AclCreateQueue with valid context but invalid options
 *  - Confirm that AclInvalidArgument is reported
 *  - Confirm that queue is still nullptr
 */
template <acl::Target Target>
class CreateQueuerWithInvalidOptionsFixture : public framework::Fixture
{
public:
    void setup()
    {
        acl::Context ctx(Target);

        // Check invalid tuning mode
        AclQueueOptions invalid_queue_opts;
        invalid_queue_opts.mode = static_cast<AclTuningMode>(-1);

        AclQueue queue = nullptr;
        ARM_COMPUTE_ASSERT(AclCreateQueue(&queue, ctx.get(), &invalid_queue_opts) == AclStatus::AclInvalidArgument);
        ARM_COMPUTE_ASSERT(queue == nullptr);
    };
};

/** Test case for AclDestroyQueue
*
* Validate that AclDestroyQueue behaves as expected when an invalid queue is given
*
* Test Steps:
*  - Call AclDestroyQueue with null queue
*  - Confirm that AclInvalidArgument is reported
*  - Call AclDestroyQueue on empty array
*  - Confirm that AclInvalidArgument is reported
*  - Call AclDestroyQueue on an ACL object other than AclQueue
*  - Confirm that AclInvalidArgument is reported
*  - Confirm that queue is still nullptr
*/
template <acl::Target Target>
class DestroyInvalidQueueFixture : public framework::Fixture
{
public:
    void setup()
    {
        acl::Context ctx(Target);

        std::array<char, 256> empty_array{};
        AclQueue queue = nullptr;

        ARM_COMPUTE_ASSERT(AclDestroyQueue(queue) == AclStatus::AclInvalidArgument);
        ARM_COMPUTE_ASSERT(AclDestroyQueue(reinterpret_cast<AclQueue>(ctx.get())) == AclStatus::AclInvalidArgument);
        ARM_COMPUTE_ASSERT(AclDestroyQueue(reinterpret_cast<AclQueue>(empty_array.data())) == AclStatus::AclInvalidArgument);
        ARM_COMPUTE_ASSERT(queue == nullptr);
    };
};

/** Test case for AclCreateQueue
 *
 * Validate that a queue can be created successfully
 *
 * Test Steps:
 *  - Create a valid context
 *  - Create a valid queue
 *  - Confirm that AclSuccess is returned
 */
template <acl::Target Target>
class SimpleQueueFixture : public framework::Fixture
{
public:
    void setup()
    {
        acl::StatusCode err = acl::StatusCode::Success;

        acl::Context ctx(Target, &err);
        ARM_COMPUTE_ASSERT(err == acl::StatusCode::Success);

        acl::Queue queue(ctx, &err);
        ARM_COMPUTE_ASSERT(err == acl::StatusCode::Success);
    };
};
} // namespace validation
} // namespace test
} // namespace arm_compute
#endif /* ARM_COMPUTE_TEST_UNIT_QUEUE_FIXTURE */