blob: 1011279c8cf3839f938f97a9ebc82ec46794f3e9 [file] [log] [blame]
Louis Verhaard9bfe0f82020-12-03 12:26:25 +01001# Copyright (C) 2020 Arm Limited or its affiliates. All rights reserved.
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:
18# Unit tests for tensor_allocator.
Louis Verhaardd4738e52021-01-21 13:16:18 +010019import pytest
20
Louis Verhaard9bfe0f82020-12-03 12:26:25 +010021from ethosu import tensor_allocator
22
Louis Verhaardd4738e52021-01-21 13:16:18 +010023test_data = [
24 ([(0, 100, 8000), (0, 1, 8016), (100, 110, 2000), (108, 110, 4000), (109, 110, 6000)], 16016),
25 (
26 [
27 (0, 23, 131072),
28 (4, 5, 65568),
29 (4, 9, 8192),
30 (8, 30, 15360),
31 (10, 11, 65568),
32 (10, 15, 4096),
33 (16, 17, 65552),
34 (16, 21, 2048),
35 (22, 23, 32784),
36 (22, 27, 1024),
37 ],
38 216096,
39 ),
40]
Louis Verhaard9bfe0f82020-12-03 12:26:25 +010041
Louis Verhaardd4738e52021-01-21 13:16:18 +010042
43@pytest.mark.parametrize("lrs, expected_size", test_data)
44def test_allocate(lrs, expected_size):
Louis Verhaard9bfe0f82020-12-03 12:26:25 +010045 """Tests the search allocator"""
Louis Verhaard9bfe0f82020-12-03 12:26:25 +010046 input = [x for lr in lrs for x in lr]
47 res = tensor_allocator.allocate(input, 0)
48 assert len(res) == len(lrs)
Louis Verhaardd4738e52021-01-21 13:16:18 +010049 assert max(addr + lr[2] for addr, lr in zip(res, lrs)) == expected_size
Louis Verhaard8af061a2021-01-22 14:03:11 +010050
51
52def test_allocate_empty_input():
53 assert [] == tensor_allocator.allocate([], 0)
54
55
56invalid_input_test_data = [None, 3, [1, 2, 16, 9, 15], [1, 5, None], [-1, 0, 16], [1, 2, 10000000000]]
57
58
59@pytest.mark.parametrize("input", invalid_input_test_data)
60def test_allocate_invalid_input(input):
61 """Tests the search allocator with invalid input data"""
62 with pytest.raises(Exception):
63 tensor_allocator.allocate(input, 0)