blob: 8a56c3f2e12dffd5c69eb97f6b70b55280e1107e [file] [log] [blame]
Louis Verhaardd7002522021-01-20 17:23:54 +01001# Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved.
Louis Verhaard9bfe0f82020-12-03 12:26:25 +01002#
3# SPDX-License-Identifier: Apache-2.0
4#
5# Licensed under the Apache License, Version 2.0 (the License); you may
6# not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an AS IS BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17# Description:
Louis Verhaardd7002522021-01-20 17:23:54 +010018# Unit tests for hillclimb_allocator.
Louis Verhaardd4738e52021-01-21 13:16:18 +010019import pytest
20
Louis Verhaardd7002522021-01-20 17:23:54 +010021from ethosu.vela.hillclimb_allocation import allocate_live_ranges
22from ethosu.vela.live_range import LiveRange
23
Louis Verhaard9bfe0f82020-12-03 12:26:25 +010024
Louis Verhaardd4738e52021-01-21 13:16:18 +010025test_data = [
26 ([(0, 100, 8000), (0, 1, 8016), (100, 110, 2000), (108, 110, 4000), (109, 110, 6000)], 16016),
27 (
28 [
29 (0, 23, 131072),
30 (4, 5, 65568),
31 (4, 9, 8192),
32 (8, 30, 15360),
33 (10, 11, 65568),
34 (10, 15, 4096),
35 (16, 17, 65552),
36 (16, 21, 2048),
37 (22, 23, 32784),
38 (22, 27, 1024),
39 ],
40 216096,
41 ),
42]
Louis Verhaard9bfe0f82020-12-03 12:26:25 +010043
Louis Verhaardd4738e52021-01-21 13:16:18 +010044
Louis Verhaardd7002522021-01-20 17:23:54 +010045def live_range(start_time, end_time, size):
46 lr = LiveRange(None, 1)
47 lr.start_time = start_time
48 lr.end_time = end_time
49 lr.size = size
50 return lr
51
52
Louis Verhaardd4738e52021-01-21 13:16:18 +010053@pytest.mark.parametrize("lrs, expected_size", test_data)
54def test_allocate(lrs, expected_size):
Louis Verhaard9bfe0f82020-12-03 12:26:25 +010055 """Tests the search allocator"""
Louis Verhaardd7002522021-01-20 17:23:54 +010056 lr_list = [live_range(start, end, size) for start, end, size in lrs]
57 res = allocate_live_ranges(lr_list)
Louis Verhaard9bfe0f82020-12-03 12:26:25 +010058 assert len(res) == len(lrs)
Louis Verhaardd4738e52021-01-21 13:16:18 +010059 assert max(addr + lr[2] for addr, lr in zip(res, lrs)) == expected_size
Louis Verhaard8af061a2021-01-22 14:03:11 +010060
61
62def test_allocate_empty_input():
Louis Verhaardd7002522021-01-20 17:23:54 +010063 assert [] == allocate_live_ranges([])