[PATCH-for-10.1 2/2] tests/functional: Test SPI-SD adapter without SD card connected

Philippe Mathieu-Daudé posted 2 patches 3 months, 1 week ago
Maintainers: "Philippe Mathieu-Daudé" <philmd@linaro.org>, Bin Meng <bmeng.cn@gmail.com>, Alistair Francis <Alistair.Francis@wdc.com>, Palmer Dabbelt <palmer@dabbelt.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <dbarboza@ventanamicro.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>
There is a newer version of this series
[PATCH-for-10.1 2/2] tests/functional: Test SPI-SD adapter without SD card connected
Posted by Philippe Mathieu-Daudé 3 months, 1 week ago
SPI-SD adapter should be usable, even without any SD card
wired. Refactor test_riscv64_sifive_u_mmc_spi() to make it
more generic and add another test, inspired by this report:
https://lore.kernel.org/qemu-devel/5b2dc427-f0db-4332-a997-fe0c82415acd@roeck-us.net/

Inspired-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 tests/functional/test_riscv64_sifive_u.py | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/tests/functional/test_riscv64_sifive_u.py b/tests/functional/test_riscv64_sifive_u.py
index dc4cb8a4a96..f7ab1abfd56 100755
--- a/tests/functional/test_riscv64_sifive_u.py
+++ b/tests/functional/test_riscv64_sifive_u.py
@@ -27,25 +27,37 @@ class SifiveU(LinuxKernelTest):
          'rootfs.ext2.gz'),
         'b6ed95610310b7956f9bf20c4c9c0c05fea647900df441da9dfe767d24e8b28b')
 
-    def test_riscv64_sifive_u_mmc_spi(self):
+    def do_test_riscv64_sifive_u_mmc_spi(self, connect_card):
         self.set_machine('sifive_u')
         kernel_path = self.ASSET_KERNEL.fetch()
         rootfs_path = self.uncompress(self.ASSET_ROOTFS)
 
         self.vm.set_console()
         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
-                               'root=/dev/mmcblk0 rootwait '
                                'earlycon=sbi console=ttySIF0 '
-                               'panic=-1 noreboot')
+                               'root=/dev/mmcblk0 ')
         self.vm.add_args('-kernel', kernel_path,
-                         '-drive', f'file={rootfs_path},if=sd,format=raw',
                          '-append', kernel_command_line,
                          '-no-reboot')
+        if connect_card:
+            self.vm.add_args('-drive', f'file={rootfs_path},if=sd,format=raw')
+            kernel_command_line += 'panic=-1 noreboot rootwait '
+            pattern = 'Boot successful.'
+        else:
+            kernel_command_line += 'panic=0 noreboot '
+            pattern = 'Cannot open root device "mmcblk0" or unknown-block(0,0)'
+
         self.vm.launch()
-        self.wait_for_console_pattern('Boot successful.')
+        self.wait_for_console_pattern(pattern)
 
         os.remove(rootfs_path)
 
+    def _test_riscv64_sifive_u_nommc_spi(self):
+        self.do_test_riscv64_sifive_u_mmc_spi(False)
+
+    def test_riscv64_sifive_u_mmc_spi(self):
+        self.do_test_riscv64_sifive_u_mmc_spi(True)
+
 
 if __name__ == '__main__':
     LinuxKernelTest.main()
-- 
2.49.0


Re: [PATCH-for-10.1 2/2] tests/functional: Test SPI-SD adapter without SD card connected
Posted by Alex Bennée 3 months ago
Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> SPI-SD adapter should be usable, even without any SD card
> wired. Refactor test_riscv64_sifive_u_mmc_spi() to make it
> more generic and add another test, inspired by this report:
> https://lore.kernel.org/qemu-devel/5b2dc427-f0db-4332-a997-fe0c82415acd@roeck-us.net/
>
> Inspired-by: Guenter Roeck <linux@roeck-us.net>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  tests/functional/test_riscv64_sifive_u.py | 22 +++++++++++++++++-----
>  1 file changed, 17 insertions(+), 5 deletions(-)
>
> diff --git a/tests/functional/test_riscv64_sifive_u.py b/tests/functional/test_riscv64_sifive_u.py
> index dc4cb8a4a96..f7ab1abfd56 100755
> --- a/tests/functional/test_riscv64_sifive_u.py
> +++ b/tests/functional/test_riscv64_sifive_u.py
> @@ -27,25 +27,37 @@ class SifiveU(LinuxKernelTest):
>           'rootfs.ext2.gz'),
>          'b6ed95610310b7956f9bf20c4c9c0c05fea647900df441da9dfe767d24e8b28b')
>  
> -    def test_riscv64_sifive_u_mmc_spi(self):
> +    def do_test_riscv64_sifive_u_mmc_spi(self, connect_card):
>          self.set_machine('sifive_u')
>          kernel_path = self.ASSET_KERNEL.fetch()
>          rootfs_path = self.uncompress(self.ASSET_ROOTFS)
>  
>          self.vm.set_console()
>          kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
> -                               'root=/dev/mmcblk0 rootwait '
>                                 'earlycon=sbi console=ttySIF0 '
> -                               'panic=-1 noreboot')
> +                               'root=/dev/mmcblk0 ')
>          self.vm.add_args('-kernel', kernel_path,
> -                         '-drive', f'file={rootfs_path},if=sd,format=raw',
>                           '-append', kernel_command_line,
>                           '-no-reboot')
> +        if connect_card:
> +            self.vm.add_args('-drive', f'file={rootfs_path},if=sd,format=raw')
> +            kernel_command_line += 'panic=-1 noreboot rootwait '
> +            pattern = 'Boot successful.'
> +        else:
> +            kernel_command_line += 'panic=0 noreboot '
> +            pattern = 'Cannot open root device "mmcblk0" or unknown-block(0,0)'
> +
>          self.vm.launch()
> -        self.wait_for_console_pattern('Boot successful.')
> +        self.wait_for_console_pattern(pattern)
>  
>          os.remove(rootfs_path)
>  
> +    def _test_riscv64_sifive_u_nommc_spi(self):
> +        self.do_test_riscv64_sifive_u_mmc_spi(False)

This test won't run because of the leading _

> +
> +    def test_riscv64_sifive_u_mmc_spi(self):
> +        self.do_test_riscv64_sifive_u_mmc_spi(True)
> +
>  
>  if __name__ == '__main__':
>      LinuxKernelTest.main()

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro
Re: [PATCH-for-10.1 2/2] tests/functional: Test SPI-SD adapter without SD card connected
Posted by Philippe Mathieu-Daudé 3 months ago
On 12/8/25 15:24, Alex Bennée wrote:
> Philippe Mathieu-Daudé <philmd@linaro.org> writes:
> 
>> SPI-SD adapter should be usable, even without any SD card
>> wired. Refactor test_riscv64_sifive_u_mmc_spi() to make it
>> more generic and add another test, inspired by this report:
>> https://lore.kernel.org/qemu-devel/5b2dc427-f0db-4332-a997-fe0c82415acd@roeck-us.net/
>>
>> Inspired-by: Guenter Roeck <linux@roeck-us.net>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>>   tests/functional/test_riscv64_sifive_u.py | 22 +++++++++++++++++-----
>>   1 file changed, 17 insertions(+), 5 deletions(-)
>>
>> diff --git a/tests/functional/test_riscv64_sifive_u.py b/tests/functional/test_riscv64_sifive_u.py
>> index dc4cb8a4a96..f7ab1abfd56 100755
>> --- a/tests/functional/test_riscv64_sifive_u.py
>> +++ b/tests/functional/test_riscv64_sifive_u.py
>> @@ -27,25 +27,37 @@ class SifiveU(LinuxKernelTest):
>>            'rootfs.ext2.gz'),
>>           'b6ed95610310b7956f9bf20c4c9c0c05fea647900df441da9dfe767d24e8b28b')
>>   
>> -    def test_riscv64_sifive_u_mmc_spi(self):
>> +    def do_test_riscv64_sifive_u_mmc_spi(self, connect_card):
>>           self.set_machine('sifive_u')
>>           kernel_path = self.ASSET_KERNEL.fetch()
>>           rootfs_path = self.uncompress(self.ASSET_ROOTFS)
>>   
>>           self.vm.set_console()
>>           kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
>> -                               'root=/dev/mmcblk0 rootwait '
>>                                  'earlycon=sbi console=ttySIF0 '
>> -                               'panic=-1 noreboot')
>> +                               'root=/dev/mmcblk0 ')
>>           self.vm.add_args('-kernel', kernel_path,
>> -                         '-drive', f'file={rootfs_path},if=sd,format=raw',
>>                            '-append', kernel_command_line,
>>                            '-no-reboot')
>> +        if connect_card:
>> +            self.vm.add_args('-drive', f'file={rootfs_path},if=sd,format=raw')
>> +            kernel_command_line += 'panic=-1 noreboot rootwait '
>> +            pattern = 'Boot successful.'
>> +        else:
>> +            kernel_command_line += 'panic=0 noreboot '
>> +            pattern = 'Cannot open root device "mmcblk0" or unknown-block(0,0)'
>> +
>>           self.vm.launch()
>> -        self.wait_for_console_pattern('Boot successful.')
>> +        self.wait_for_console_pattern(pattern)
>>   
>>           os.remove(rootfs_path)
>>   
>> +    def _test_riscv64_sifive_u_nommc_spi(self):
>> +        self.do_test_riscv64_sifive_u_mmc_spi(False)
> 
> This test won't run because of the leading _

Oops, I was carefully testing one case after each other and missed
to remove this leading char!

> 
>> +
>> +    def test_riscv64_sifive_u_mmc_spi(self):
>> +        self.do_test_riscv64_sifive_u_mmc_spi(True)
>> +
>>   
>>   if __name__ == '__main__':
>>       LinuxKernelTest.main()
>