1#!/usr/bin/env python3 2# 3# Copyright (c) 2023 KNS Group LLC (YADRO) 4# 5# SPDX-License-Identifier: Apache-2.0 6 7import logging 8import re 9 10from twister_harness import DeviceAdapter, Shell 11 12logger = logging.getLogger(__name__) 13 14 15def test_shell_perf(dut: DeviceAdapter, shell: Shell): 16 17 shell.base_timeout=10 18 19 logger.info('send "perf record 200 99" command') 20 lines = shell.exec_command('perf record 200 99') 21 assert 'Enabled perf' in lines, 'expected response not found' 22 lines = dut.readlines_until(regex='.*Perf done!', print_output=True) 23 logger.info('response is valid') 24 25 logger.info('send "perf printbuf" command') 26 lines = shell.exec_command('perf printbuf') 27 lines = lines[1:-1] 28 match = re.match(r"Perf buf length (\d+)", lines[0]) 29 assert match is not None, 'expected response not found' 30 length = int(match.group(1)) 31 lines = lines[1:] 32 assert length != 0, '0 length' 33 assert length == len(lines), 'length dose not match with count of lines' 34 35 i = 0 36 while i < length: 37 i += int(lines[i], 16) + 1 38 assert i <= length, 'one of the samples is not true to size' 39