[Concept,2/9] test: Write the SPI image to the persistent-data directory
Commit Message
From: Simon Glass <simon.glass@canonical.com>
It is annoying to have disk images in the source directory since it
clutters up the working space.
Move spi.bin (used by the SPI tests) into the persistent-data
directory, update the driver and add a comment.
Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---
drivers/mtd/spi/sandbox.c | 14 +++++++++++---
test/dm/sf.c | 4 +++-
test/py/tests/test_ut.py | 2 +-
3 files changed, 15 insertions(+), 5 deletions(-)
@@ -126,7 +126,9 @@ static int sandbox_sf_probe(struct udevice *dev)
struct dm_spi_slave_plat *slave_plat;
struct udevice *bus = dev->parent;
const char *spec = NULL;
+ const char *filename;
struct udevice *emul;
+ char buf[256];
int ret = 0;
int cs = -1;
@@ -170,10 +172,16 @@ static int sandbox_sf_probe(struct udevice *dev)
if (sandbox_sf_0xff[0] == 0x00)
memset(sandbox_sf_0xff, 0xff, sizeof(sandbox_sf_0xff));
- sbsf->fd = os_open(pdata->filename, 02);
+ /*
+ * Try persistent data directory first, then fall back to the
+ * filename as given (for absolute paths or current directory)
+ */
+ filename = pdata->filename;
+ if (!os_persistent_file(buf, sizeof(buf), pdata->filename))
+ filename = buf;
+ sbsf->fd = os_open(filename, 02);
if (sbsf->fd < 0) {
- printf("%s: unable to open file '%s'\n", __func__,
- pdata->filename);
+ log_err("Unable to open file '%s'\n", filename);
ret = -EIO;
goto error;
}
@@ -27,10 +27,12 @@ static int dm_test_spi_flash(struct unit_test_state *uts)
uint map_size;
ulong map_base;
uint offset;
+ char pathname[256];
int i;
src = map_sysmem(0x20000, full_size);
- ut_assertok(os_write_file("spi.bin", src, full_size));
+ ut_assertok(os_persistent_file(pathname, sizeof(pathname), "spi.bin"));
+ ut_assertok(os_write_file(pathname, src, full_size));
ut_assertok(uclass_first_device_err(UCLASS_SPI_FLASH, &dev));
dst = map_sysmem(0x20000 + full_size, full_size);
@@ -42,7 +42,7 @@ def test_ut_dm_init(ubman):
with open(fn, 'wb') as fh:
fh.write(data)
- fn = ubman.config.source_dir + '/spi.bin'
+ fn = ubman.config.persistent_data_dir + '/spi.bin'
if not os.path.exists(fn):
data = b'\x00' * (2 * 1024 * 1024)
with open(fn, 'wb') as fh: