]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
sandbox: Add a test for SCSI
authorSimon Glass <sjg@chromium.org>
Wed, 21 Sep 2022 14:21:47 +0000 (16:21 +0200)
committerSimon Glass <sjg@chromium.org>
Sun, 25 Sep 2022 19:59:56 +0000 (13:59 -0600)
Add a simple uclass test for SCSI. It reads the partition table from a
disk image and checks that it looks correct.

Signed-off-by: Simon Glass <sjg@chromium.org>
arch/sandbox/dts/sandbox.dtsi
arch/sandbox/dts/test.dts
test/dm/Makefile
test/dm/scsi.c [new file with mode: 0644]
test/py/tests/test_ut.py

index 56e6b38bfa786f27eeacd08c129bbc00d3e25220..de7a218f4574ab90ee75b8ecd577fdddccd15527 100644 (file)
                compatible = "sandbox,sandbox-rng";
        };
 
+       scsi {
+               compatible = "sandbox,scsi";
+       };
+
        sound {
                compatible = "sandbox,sound";
                cpu {
index c7fffa2da2715b180867a9ab53a2f140eb5fe2f3..4ee471238eebe99c7c31e7b26c4931b69cea8363 100644 (file)
                backlight = <&backlight 0 100>;
        };
 
+       scsi {
+               compatible = "sandbox,scsi";
+               sandbox,filepath = "scsi.img";
+       };
+
        smem@0 {
                compatible = "sandbox,smem";
        };
index 7543df8823caf967ea15a333e82bdf080a937dc8..5178daa7cf0dae1d871091f5e0096aa24feafd5b 100644 (file)
@@ -91,6 +91,7 @@ obj-$(CONFIG_DM_REGULATOR) += regulator.o
 obj-$(CONFIG_DM_RNG) += rng.o
 obj-$(CONFIG_DM_RTC) += rtc.o
 obj-$(CONFIG_SCMI_FIRMWARE) += scmi.o
+obj-$(CONFIG_SCSI) += scsi.o
 obj-$(CONFIG_DM_SERIAL) += serial.o
 obj-$(CONFIG_DM_SPI_FLASH) += sf.o
 obj-$(CONFIG_SIMPLE_BUS) += simple-bus.o
diff --git a/test/dm/scsi.c b/test/dm/scsi.c
new file mode 100644 (file)
index 0000000..380cfc8
--- /dev/null
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2015 Google, Inc
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <part.h>
+#include <scsi.h>
+#include <dm/test.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+/* Test that sandbox SCSI works correctly */
+static int dm_test_scsi_base(struct unit_test_state *uts)
+{
+       const struct disk_partition *info;
+       const struct disk_part *part;
+       struct udevice *dev;
+
+       ut_assertok(scsi_scan(false));
+
+       /*
+        * We expect some sort of partition on the disk image, created by
+        * test_ut_dm_init()
+        */
+       ut_assertok(uclass_first_device_err(UCLASS_PARTITION, &dev));
+
+       part = dev_get_uclass_plat(dev);
+       ut_asserteq(1, part->partnum);
+
+       info = &part->gpt_part_info;
+       ut_asserteq_str("sda1", info->name);
+       ut_asserteq_str("U-Boot", info->type);
+       ut_asserteq(0x83 /* linux */, info->sys_ind);
+
+       return 0;
+}
+DM_TEST(dm_test_scsi_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
index 35fb393c1ff4ea5f3d9da5c078c79f383d84f2ce..9d423903736d6d7e292a6079c0dd4af7ae4ac083 100644 (file)
@@ -114,6 +114,15 @@ def test_ut_dm_init(u_boot_console):
         with open(fn, 'wb') as fh:
             fh.write(data)
 
+    # Create a file with a single partition
+    fn = u_boot_console.config.source_dir + '/scsi.img'
+    if not os.path.exists(fn):
+        data = b'\x00' * (2 * 1024 * 1024)
+        with open(fn, 'wb') as fh:
+            fh.write(data)
+        u_boot_utils.run_and_log(
+            u_boot_console, f'sfdisk {fn}', stdin=b'type=83')
+
 @pytest.mark.buildconfigspec('cmd_bootflow')
 def test_ut_dm_init_bootstd(u_boot_console):
     """Initialise data for bootflow tests"""