blob: 445693cafd71033fcc72b61989aaaa7d11900039 [file] [log] [blame]
Love Kumaraaf4a622024-01-19 20:07:13 +05301# SPDX-License-Identifier: GPL-2.0
2# (C) Copyright 2023, Advanced Micro Devices, Inc.
3
4import pytest
5
6"""
7Note: This test relies on boardenv_* containing configuration values to define
8the SCSI device number, type and capacity. This test will be automatically
9skipped without this.
10
11For example:
12
13# Setup env__scsi_device_test to set the SCSI device number/slot, the type of
14device, and the device capacity in MB.
15env__scsi_device_test = {
16 'dev_num': 0,
17 'device_type': 'Hard Disk',
18 'device_capacity': '476940.0 MB',
19}
20"""
21
22def scsi_setup(u_boot_console):
23 f = u_boot_console.config.env.get('env__scsi_device_test', None)
24 if not f:
25 pytest.skip('No SCSI device to test')
26
27 dev_num = f.get('dev_num', None)
28 if not isinstance(dev_num, int):
29 pytest.skip('No device number specified in env file to read')
30
31 dev_type = f.get('device_type')
32 if not dev_type:
33 pytest.skip('No device type specified in env file to read')
34
35 dev_size = f.get('device_capacity')
36 if not dev_size:
37 pytest.skip('No device capacity specified in env file to read')
38
39 return dev_num, dev_type, dev_size
40
41@pytest.mark.buildconfigspec('cmd_scsi')
42def test_scsi_reset(u_boot_console):
43 dev_num, dev_type, dev_size = scsi_setup(u_boot_console)
44 output = u_boot_console.run_command('scsi reset')
45 assert f'Device {dev_num}:' in output
46 assert f'Type: {dev_type}' in output
47 assert f'Capacity: {dev_size}' in output
48 output = u_boot_console.run_command('echo $?')
49 assert output.endswith('0')
50
51@pytest.mark.buildconfigspec('cmd_scsi')
52def test_scsi_info(u_boot_console):
53 dev_num, dev_type, dev_size = scsi_setup(u_boot_console)
54 output = u_boot_console.run_command('scsi info')
55 assert f'Device {dev_num}:' in output
56 assert f'Type: {dev_type}' in output
57 assert f'Capacity: {dev_size}' in output
58 output = u_boot_console.run_command('echo $?')
59 assert output.endswith('0')
60
61@pytest.mark.buildconfigspec('cmd_scsi')
62def test_scsi_scan(u_boot_console):
63 dev_num, dev_type, dev_size = scsi_setup(u_boot_console)
64 output = u_boot_console.run_command('scsi scan')
65 assert f'Device {dev_num}:' in output
66 assert f'Type: {dev_type}' in output
67 assert f'Capacity: {dev_size}' in output
68 output = u_boot_console.run_command('echo $?')
69 assert output.endswith('0')
70
71@pytest.mark.buildconfigspec('cmd_scsi')
72def test_scsi_dev(u_boot_console):
73 dev_num, dev_type, dev_size = scsi_setup(u_boot_console)
74 output = u_boot_console.run_command('scsi device')
75 assert 'no scsi devices available' not in output
76 assert f'device {dev_num}:' in output
77 assert f'Type: {dev_type}' in output
78 assert f'Capacity: {dev_size}' in output
79 output = u_boot_console.run_command('echo $?')
80 assert output.endswith('0')
81 output = u_boot_console.run_command('scsi device %d' % dev_num)
82 assert 'is now current device' in output
83 output = u_boot_console.run_command('echo $?')
84 assert output.endswith('0')
85
86@pytest.mark.buildconfigspec('cmd_scsi')
87def test_scsi_part(u_boot_console):
88 test_scsi_dev(u_boot_console)
89 output = u_boot_console.run_command('scsi part')
Heinrich Schuchardte4319112024-04-03 13:40:47 +020090 assert 'Partition Map for scsi device' in output
Love Kumaraaf4a622024-01-19 20:07:13 +053091 output = u_boot_console.run_command('echo $?')
92 assert output.endswith('0')