#include <blk.h>
#include <dm.h>
#include <fs.h>
+#include <os.h>
#include <sandbox_host.h>
#include <asm/test.h>
#include <dm/device-internal.h>
#include <test/test.h>
#include <test/ut.h>
-static const char filename[] = "2MB.ext2.img";
-static const char filename2[] = "1MB.fat32.img";
-
/* Basic test of host interface */
static int dm_test_host(struct unit_test_state *uts)
{
struct udevice *dev, *part, *chk, *blk;
struct host_sb_plat *plat;
struct blk_desc *desc;
+ char fname[256];
ulong mem_start;
loff_t actwrite;
ut_assert(label != plat->label);
ut_asserteq(0, plat->fd);
- /* Attach a file created in test_host.py */
- ut_assertok(host_attach_file(dev, filename));
+ /* Attach a file created in test_ut_dm_init */
+ ut_assertok(os_persistent_file(fname, sizeof(fname), "2MB.ext2.img"));
+
+ ut_assertok(host_attach_file(dev, fname));
ut_assertok(uclass_first_device_err(UCLASS_HOST, &chk));
ut_asserteq_ptr(chk, dev);
- ut_asserteq_str(filename, plat->filename);
- ut_assert(filename != plat->filename);
+ ut_asserteq_str(fname, plat->filename);
+ ut_assert(fname != plat->filename);
ut_assert(plat->fd != 0);
/* Get the block device */
{
static char label[] = "test";
struct udevice *dev, *chk;
+ char fname[256];
ut_asserteq(0, uclass_id_count(UCLASS_HOST));
ut_assertok(host_create_device(label, true, &dev));
- /* Attach a file created in test_host.py */
- ut_assertok(host_attach_file(dev, filename));
+ /* Attach a file created in test_ut_dm_init */
+ ut_assertok(os_persistent_file(fname, sizeof(fname), "2MB.ext2.img"));
+ ut_assertok(host_attach_file(dev, fname));
ut_assertok(uclass_first_device_err(UCLASS_HOST, &chk));
ut_asserteq_ptr(chk, dev);
ut_asserteq(1, uclass_id_count(UCLASS_HOST));
/* Create another device with the same label (should remove old one) */
ut_assertok(host_create_device(label, true, &dev));
- /* Attach a different file created in test_host.py */
- ut_assertok(host_attach_file(dev, filename2));
+ /* Attach a different file created in test_ut_dm_init */
+ ut_assertok(os_persistent_file(fname, sizeof(fname), "1MB.fat32.img"));
+ ut_assertok(host_attach_file(dev, fname));
+
ut_assertok(uclass_first_device_err(UCLASS_HOST, &chk));
ut_asserteq_ptr(chk, dev);
{
struct udevice *dev, *blk;
struct blk_desc *desc;
+ char fname[256];
console_record_reset();
ut_assert_nextline("dev blocks label path");
ut_assert_console_end();
- ut_assertok(run_commandf("host bind -r test2 %s", filename));
+ ut_assertok(os_persistent_file(fname, sizeof(fname), "2MB.ext2.img"));
+ ut_assertok(run_commandf("host bind -r test2 %s", fname));
/* Check the -r flag worked */
ut_assertok(uclass_first_device_err(UCLASS_HOST, &dev));
ut_assertok(run_command("host info", 0));
ut_assert_nextline("dev blocks label path");
- ut_assert_nextline(" 0 4096 test2 2MB.ext2.img");
+ ut_assert_nextlinen(" 0 4096 test2");
ut_assert_console_end();
- ut_assertok(run_commandf("host bind fat %s", filename2));
+ ut_assertok(os_persistent_file(fname, sizeof(fname), "1MB.fat32.img"));
+ ut_assertok(run_commandf("host bind fat %s", fname));
/* Check it is not removable (no '-r') */
ut_assertok(uclass_next_device_err(&dev));
ut_assertok(run_command("host info", 0));
ut_assert_nextline("dev blocks label path");
- ut_assert_nextline(" 0 4096 test2 2MB.ext2.img");
- ut_assert_nextline(" 1 2048 fat 1MB.fat32.img");
+ ut_assert_nextlinen(" 0 4096 test2");
+ ut_assert_nextlinen(" 1 2048 fat");
ut_assert_console_end();
ut_asserteq(1, run_command("host info test", 0));
ut_assertok(run_command("host info fat", 0));
ut_assert_nextline("dev blocks label path");
- ut_assert_nextline(" 1 2048 fat 1MB.fat32.img");
+ ut_assert_nextlinen(" 1 2048 fat");
ut_assert_console_end();
/* check 'host dev' */
ut_assertok(run_command("host info", 0));
ut_assert_nextline("dev blocks label path");
- ut_assert_nextline(" 1 2048 fat 1MB.fat32.img");
+ ut_assert_nextlinen(" 1 2048 fat");
ut_assert_console_end();
return 0;
import os
from subprocess import call, check_call, check_output, CalledProcessError
-def mk_fs(config, fs_type, size, prefix, use_src_dir=False):
+def mk_fs(config, fs_type, size, prefix):
"""Create a file system volume
Args:
fs_type (str): File system type, e.g. 'ext4'
size (int): Size of file system in bytes
prefix (str): Prefix string of volume's file name
- use_src_dir (bool): true to put the file in the source directory
Raises:
CalledProcessError: if any error occurs when creating the filesystem
"""
fs_img = f'{prefix}.{fs_type}.img'
- fs_img = os.path.join(config.source_dir if use_src_dir
- else config.persistent_data_dir, fs_img)
+ fs_img = os.path.join(config.persistent_data_dir, fs_img)
if fs_type == 'fat16':
mkfs_opt = '-F 16'