blob: 08606850017ae5d1e1020a0643541b26f7f2d9c1 [file] [log] [blame]
Rickard Bolinbc6ee582022-11-04 08:24:29 +00001# SPDX-FileCopyrightText: Copyright 2020 Arm Limited and/or its affiliates <open-source-office@arm.com>
Louis Verhaard52078302020-11-18 13:35:06 +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:
18# Contains unit tests for npu_create_driver_payload API for an external consumer
19import random
20
21import pytest
22
23from ethosu.vela.api import npu_create_driver_payload
24from ethosu.vela.api import NpuAccelerator
25
26
27@pytest.mark.parametrize("accelerator", list(NpuAccelerator))
28def test_create_driver_payload(accelerator: NpuAccelerator):
29 """Tests npu_create_driver_payload"""
30 # Generate a random command stream with defined beginning and end
31 random.seed(0)
32 num_commands = 793
33 register_command_stream = random.choices(range(1 << 32), k=num_commands)
34 register_command_stream[0] = 0xFEDCBA98
35 register_command_stream[-1] = 0xA0B1C2D3
36 payload = npu_create_driver_payload(register_command_stream, accelerator)
37 header_size = 32 # expected driver header size in bytes
38 assert len(payload) == header_size + 4 * num_commands
39 # Check that the first register command is located directly after the header
40 assert list(payload[header_size : header_size + 4]) == [0x98, 0xBA, 0xDC, 0xFE]
41 # Check that the last register command is present in the payload
42 assert list(payload[-4:]) == [0xD3, 0xC2, 0xB1, 0xA0]