2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <gtest/gtest.h>
19 #include "MemoryPlanner.h"
22 TEST(Allocator, allocate_test)
24 ::onert::backend::cpu_common::Allocator allocator(1024);
25 ASSERT_NE(allocator.base(), nullptr);
28 TEST(BumpPlanner, claim_test)
30 ::onert::backend::cpu_common::BumpPlanner planner;
32 auto claim = [&planner](uint32_t index, size_t size, uint32_t expected_offset) {
33 onert::ir::OperandIndex mem_idx(index);
34 planner.claim(mem_idx, size);
35 auto mem_blk = planner.memory_plans()[mem_idx];
36 ASSERT_EQ(mem_blk.offset, expected_offset);
37 ASSERT_EQ(mem_blk.size, size);
45 TEST(FirstFitPlanner, claim_release_test)
47 ::onert::backend::cpu_common::FirstFitPlanner planner;
49 auto claim = [&planner](uint32_t index, size_t size, uint32_t expected_offset) {
50 onert::ir::OperandIndex mem_idx(index);
51 planner.claim(mem_idx, size);
52 auto mem_blk = planner.memory_plans()[mem_idx];
53 ASSERT_EQ(mem_blk.offset, expected_offset);
54 ASSERT_EQ(mem_blk.size, size);
57 auto release = [&planner](uint32_t index) {
58 onert::ir::OperandIndex mem_idx(index);
59 planner.release(mem_idx);
129 TEST(WICPlanner, claim_release_test)
131 ::onert::backend::cpu_common::WICPlanner planner;
133 auto claim = [&planner](uint32_t index, size_t size) {
134 onert::ir::OperandIndex mem_idx(index);
135 planner.claim(mem_idx, size);
138 auto release = [&planner](uint32_t index) {
139 onert::ir::OperandIndex mem_idx(index);
140 planner.release(mem_idx);
143 auto verify = [&planner](uint32_t index, uint32_t size, uint32_t expected_offset) {
144 onert::ir::OperandIndex mem_idx(index);
145 auto mem_blk = planner.memory_plans()[mem_idx];
146 ASSERT_EQ(mem_blk.offset, expected_offset);
147 ASSERT_EQ(mem_blk.size, size);
150 auto capacity = [&planner](uint32_t expected_capacity) {
151 auto actual_capacity = planner.capacity();
152 ASSERT_EQ(actual_capacity, expected_capacity);