Louis Verhaard | d700252 | 2021-01-20 17:23:54 +0100 | [diff] [blame] | 1 | # Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved. |
Louis Verhaard | 9bfe0f8 | 2020-12-03 12:26:25 +0100 | [diff] [blame] | 2 | # |
| 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 Verhaard | d700252 | 2021-01-20 17:23:54 +0100 | [diff] [blame] | 18 | # Unit tests for hillclimb_allocator. |
Louis Verhaard | d4738e5 | 2021-01-21 13:16:18 +0100 | [diff] [blame] | 19 | import pytest |
| 20 | |
Louis Verhaard | d700252 | 2021-01-20 17:23:54 +0100 | [diff] [blame] | 21 | from ethosu.vela.hillclimb_allocation import allocate_live_ranges |
| 22 | from ethosu.vela.live_range import LiveRange |
| 23 | |
Louis Verhaard | 9bfe0f8 | 2020-12-03 12:26:25 +0100 | [diff] [blame] | 24 | |
Louis Verhaard | d4738e5 | 2021-01-21 13:16:18 +0100 | [diff] [blame] | 25 | test_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 Verhaard | 9bfe0f8 | 2020-12-03 12:26:25 +0100 | [diff] [blame] | 43 | |
Louis Verhaard | d4738e5 | 2021-01-21 13:16:18 +0100 | [diff] [blame] | 44 | |
Louis Verhaard | d700252 | 2021-01-20 17:23:54 +0100 | [diff] [blame] | 45 | def 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 Verhaard | d4738e5 | 2021-01-21 13:16:18 +0100 | [diff] [blame] | 53 | @pytest.mark.parametrize("lrs, expected_size", test_data) |
| 54 | def test_allocate(lrs, expected_size): |
Louis Verhaard | 9bfe0f8 | 2020-12-03 12:26:25 +0100 | [diff] [blame] | 55 | """Tests the search allocator""" |
Louis Verhaard | d700252 | 2021-01-20 17:23:54 +0100 | [diff] [blame] | 56 | lr_list = [live_range(start, end, size) for start, end, size in lrs] |
| 57 | res = allocate_live_ranges(lr_list) |
Louis Verhaard | 9bfe0f8 | 2020-12-03 12:26:25 +0100 | [diff] [blame] | 58 | assert len(res) == len(lrs) |
Louis Verhaard | d4738e5 | 2021-01-21 13:16:18 +0100 | [diff] [blame] | 59 | assert max(addr + lr[2] for addr, lr in zip(res, lrs)) == expected_size |
Louis Verhaard | 8af061a | 2021-01-22 14:03:11 +0100 | [diff] [blame] | 60 | |
| 61 | |
| 62 | def test_allocate_empty_input(): |
Louis Verhaard | d700252 | 2021-01-20 17:23:54 +0100 | [diff] [blame] | 63 | assert [] == allocate_live_ranges([]) |