Love Kumar | aaf4a62 | 2024-01-19 20:07:13 +0530 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
| 2 | # (C) Copyright 2023, Advanced Micro Devices, Inc. |
| 3 | |
| 4 | import pytest |
| 5 | |
| 6 | """ |
| 7 | Note: This test relies on boardenv_* containing configuration values to define |
| 8 | the SCSI device number, type and capacity. This test will be automatically |
| 9 | skipped without this. |
| 10 | |
| 11 | For example: |
| 12 | |
| 13 | # Setup env__scsi_device_test to set the SCSI device number/slot, the type of |
| 14 | device, and the device capacity in MB. |
| 15 | env__scsi_device_test = { |
| 16 | 'dev_num': 0, |
| 17 | 'device_type': 'Hard Disk', |
| 18 | 'device_capacity': '476940.0 MB', |
| 19 | } |
| 20 | """ |
| 21 | |
| 22 | def 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') |
| 42 | def 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') |
| 52 | def 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') |
| 62 | def 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') |
| 72 | def 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') |
| 87 | def test_scsi_part(u_boot_console): |
| 88 | test_scsi_dev(u_boot_console) |
| 89 | output = u_boot_console.run_command('scsi part') |
Heinrich Schuchardt | e431911 | 2024-04-03 13:40:47 +0200 | [diff] [blame] | 90 | assert 'Partition Map for scsi device' in output |
Love Kumar | aaf4a62 | 2024-01-19 20:07:13 +0530 | [diff] [blame] | 91 | output = u_boot_console.run_command('echo $?') |
| 92 | assert output.endswith('0') |