1 /*
2     Copyright (c) 2019-2022 Intel Corporation
3 
4     Licensed under the Apache License, Version 2.0 (the "License");
5     you may not use this file except in compliance with the License.
6     You may obtain a copy of the License at
7 
8         http://www.apache.org/licenses/LICENSE-2.0
9 
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
15 */
16 
17 //! \file conformance_arena_constraints.cpp
18 //! \brief Test for [info_namespace scheduler.task_arena] specifications
19 
20 #include "common/common_arena_constraints.h"
21 
22 #if __TBB_HWLOC_VALID_ENVIRONMENT
23 
24 //! Testing all NUMA aware arenas can successfully execute tasks
25 //! \brief \ref interface \ref requirement
26 TEST_CASE("NUMA aware arenas task execution test") {
27     system_info::initialize();
28     for(auto& numa_index: oneapi::tbb::info::numa_nodes()) {
29         oneapi::tbb::task_arena arena(oneapi::tbb::task_arena::constraints{numa_index});
30 
31         std::atomic<bool> task_done{false};
__anonb63cdda60102null32         arena.execute([&]{ task_done = true; });
33         REQUIRE_MESSAGE(task_done, "Execute was performed but task was not executed.");
34 
35         task_done = false;
__anonb63cdda60202null36         arena.enqueue([&]{ task_done = true; });
37         while(!task_done) { utils::yield(); }
38     }
39 }
40 
41 //! Testing NUMA topology traversal correctness
42 //! \brief \ref interface \ref requirement
43 TEST_CASE("Test NUMA topology traversal correctness") {
44     system_info::initialize();
45     std::vector<index_info> numa_nodes_info = system_info::get_numa_nodes_info();
46 
47     std::vector<oneapi::tbb::numa_node_id> numa_indexes = oneapi::tbb::info::numa_nodes();
48     for (const auto& numa_id: numa_indexes) {
49         auto pos = std::find_if(numa_nodes_info.begin(), numa_nodes_info.end(),
__anonb63cdda60302(const index_info& numa_info)50             [&](const index_info& numa_info){ return numa_info.index == numa_id; }
51         );
52 
53         REQUIRE_MESSAGE(pos != numa_nodes_info.end(), "Wrong, extra or repeated NUMA node index detected.");
54         numa_nodes_info.erase(pos);
55     }
56 
57     REQUIRE_MESSAGE(numa_nodes_info.empty(), "Some available NUMA nodes indexes were not detected.");
58 }
59 
60 #if __HYBRID_CPUS_TESTING
61 //! Testing NUMA topology traversal correctness
62 //! \brief \ref interface \ref requirement
63 TEST_CASE("Test core types topology traversal correctness") {
64     system_info::initialize();
65     std::vector<index_info> core_types_info = system_info::get_cpu_kinds_info();
66     std::vector<tbb::core_type_id> core_types = tbb::info::core_types();
67 
68     REQUIRE_MESSAGE(core_types_info.size() == core_types.size(), "Wrong core types number detected.");
69     for (unsigned i = 0; i < core_types.size(); ++i) {
70         REQUIRE_MESSAGE(core_types[i] == core_types_info[i].index, "Wrong core type index detected.");
71     }
72 }
73 #endif /*__HYBRID_CPUS_TESTING*/
74 
75 #else /*!__TBB_HWLOC_VALID_ENVIRONMENT*/
76 
77 //! Testing NUMA support interfaces validity when HWLOC is not presented on system
78 //! \brief \ref interface \ref requirement
79 TEST_CASE("Test validity of NUMA interfaces when HWLOC is not present on the system") {
80     std::vector<oneapi::tbb::numa_node_id> numa_indexes = oneapi::tbb::info::numa_nodes();
81 
82     REQUIRE_MESSAGE(numa_indexes.size() == 1,
83         "Number of NUMA nodes must be pinned to 1, if we have no HWLOC on the system.");
84     REQUIRE_MESSAGE(numa_indexes[0] == -1,
85         "Index of NUMA node must be pinned to -1, if we have no HWLOC on the system.");
86     REQUIRE_MESSAGE(oneapi::tbb::info::default_concurrency(numa_indexes[0]) == utils::get_platform_max_threads(),
87         "Concurrency for NUMA node must be equal to default_num_threads(), if we have no HWLOC on the system.");
88 }
89 
90 #endif /*__TBB_HWLOC_VALID_ENVIRONMENT*/
91