blob: 42247ba1da356cbfbc8c4414f239ee16d3a01e0d [file] [log] [blame]
Georgios Pinitas8a5146f2021-01-12 15:51:07 +00001/*
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 */
Georgios Pinitasc3c352e2021-03-18 10:59:40 +000024#include "tests/validation/fixtures/UNIT/ContextFixture.h"
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000025
26#include "src/cpu/CpuContext.h"
27
28namespace arm_compute
29{
30namespace test
31{
32namespace validation
33{
34TEST_SUITE(CPU)
35TEST_SUITE(UNIT)
36TEST_SUITE(Context)
37
38/** Test-case for AclCreateContext
39 *
40 * Validate that AclCreateContext behaves as expected on invalid target
41 *
42 * Test Steps:
43 * - Call AclCreateContext with invalid target
44 * - Confirm that AclUnsupportedTarget is reported
45 * - Confirm that context is still nullptr
46 */
47TEST_CASE(CreateContextWithInvalidTarget, framework::DatasetMode::ALL)
48{
49 AclTarget invalid_target = static_cast<AclTarget>(-1);
50 AclContext ctx = nullptr;
51 ARM_COMPUTE_ASSERT(AclCreateContext(&ctx, invalid_target, nullptr) == AclStatus::AclUnsupportedTarget);
52 ARM_COMPUTE_ASSERT(ctx == nullptr);
53}
54
55/** Test-case for AclCreateContext
56 *
57 * Validate that AclCreateContext behaves as expected on invalid context options
58 *
59 * Test Steps:
60 * - Call AclCreateContext with valid target but invalid context options
61 * - Confirm that AclInvalidArgument is reported
62 * - Confirm that context is still nullptr
63 */
64TEST_CASE(CreateContextWithInvalidOptions, framework::DatasetMode::ALL)
65{
66 AclContextOptions invalid_ctx_opts;
67 invalid_ctx_opts.mode = static_cast<AclExecutionMode>(-1);
68 invalid_ctx_opts.capabilities = AclCpuCapabilitiesAuto;
69 invalid_ctx_opts.max_compute_units = 0;
70 invalid_ctx_opts.enable_fast_math = false;
71 invalid_ctx_opts.kernel_config_file = "";
72 AclContext ctx = nullptr;
73 ARM_COMPUTE_ASSERT(AclCreateContext(&ctx, AclCpu, &invalid_ctx_opts) == AclStatus::AclInvalidArgument);
74 ARM_COMPUTE_ASSERT(ctx == nullptr);
75}
76
Georgios Pinitasc3c352e2021-03-18 10:59:40 +000077EMPTY_BODY_FIXTURE_TEST_CASE(DestroyInvalidContext, DestroyInvalidContextFixture<AclTarget::AclCpu>, framework::DatasetMode::ALL)
78EMPTY_BODY_FIXTURE_TEST_CASE(SimpleContextCApi, SimpleContextCApiFixture<AclTarget::AclCpu>, framework::DatasetMode::ALL)
79EMPTY_BODY_FIXTURE_TEST_CASE(SimpleContextCppApi, SimpleContextCppApiFixture<acl::Target::Cpu>, framework::DatasetMode::ALL)
80EMPTY_BODY_FIXTURE_TEST_CASE(MultipleContexts, MultipleContextsFixture<AclTarget::AclCpu>, framework::DatasetMode::ALL)
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000081
82/** Test-case for CpuCapabilities
83 *
84 * Validate that CpuCapabilities are set correctly
85 *
86 * Test Steps:
87 * - Create a context with a given list of capabilities
88 * - Confirm that AclSuccess is reported
89 * - Validate that all capabilities are set correctly
90 */
91TEST_CASE(CpuCapabilities, framework::DatasetMode::ALL)
92{
Georgios Pinitas3f26ef42021-02-23 10:01:33 +000093 acl::Context::Options opts;
94 opts.copts.capabilities = AclCpuCapabilitiesDot | AclCpuCapabilitiesMmlaInt8 | AclCpuCapabilitiesSve2;
95 arm_compute::cpu::CpuContext ctx(&opts.copts);
Georgios Pinitas8a5146f2021-01-12 15:51:07 +000096
Michalis Spyrou20fca522021-06-07 14:23:57 +010097 ARM_COMPUTE_ASSERT(ctx.capabilities().cpu_info.has_dotprod() == true);
98 ARM_COMPUTE_ASSERT(ctx.capabilities().cpu_info.has_i8mm() == true);
99 ARM_COMPUTE_ASSERT(ctx.capabilities().cpu_info.has_sve2() == true);
100 ARM_COMPUTE_ASSERT(ctx.capabilities().cpu_info.has_fp16() == false);
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000101
102 arm_compute::cpu::CpuContext ctx_legacy(nullptr);
Michalis Spyrou20fca522021-06-07 14:23:57 +0100103 ARM_COMPUTE_ASSERT(ctx_legacy.capabilities().cpu_info.has_neon() == true);
Georgios Pinitas8a5146f2021-01-12 15:51:07 +0000104}
105
106TEST_SUITE_END() // Context
107TEST_SUITE_END() // UNIT
108TEST_SUITE_END() // CPU
109} // namespace validation
110} // namespace test
111} // namespace arm_compute