Skip to content

Commit

Permalink
record: Record SPI devices using the SPI recorder
Browse files Browse the repository at this point in the history
Dynamically select the SPI recorder if we are passed an SPI device
instead of using the generic ioctl tree recorder.

Closes: martinpitt#121
  • Loading branch information
Benjamin Berg committed Jun 15, 2021
1 parent 98f2a05 commit 6ecc4d9
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/umockdev-record.vala
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ dump_devices(string[] devices)

// split a devname=filename argument into a device number and a file name
static void
split_devfile_arg(string arg, out string dev, out string devnum, out string fname)
split_devfile_arg(string arg, out string dev, out string devnum, out bool is_block, out string fname)
{
string[] parts = arg.split ("=", 2); // devname, ioctlfilename
if (parts.length != 2)
Expand All @@ -297,6 +297,7 @@ split_devfile_arg(string arg, out string dev, out string devnum, out string fnam
if (Posix.stat(dev, out st) != 0)
exit_error("Cannot access device %s: %s", dev, strerror(errno));

is_block = Posix.S_ISBLK(st.st_mode);
if (Posix.S_ISCHR(st.st_mode) || Posix.S_ISBLK(st.st_mode)) {
// if we have a device node, get devnum from stat
devnum = Posix.major(st.st_rdev).to_string() + ":" + Posix.minor(st.st_rdev).to_string();
Expand All @@ -319,9 +320,14 @@ record_ioctl(string root_dir, string arg)
{
UMockdev.IoctlBase handler;
string dev, devnum, outfile;
split_devfile_arg(arg, out dev, out devnum, out outfile);
bool is_block;
split_devfile_arg(arg, out dev, out devnum, out is_block, out outfile);

handler = new UMockdev.IoctlTreeRecorder(null, dev, outfile);
/* SPI: major 153, character device */
if (!is_block && devnum.has_prefix("153:"))
handler = new UMockdev.IoctlSpiRecorder(null, dev, outfile);
else
handler = new UMockdev.IoctlTreeRecorder(null, dev, outfile);

string sockpath = Path.build_filename(root_dir, "ioctl", dev);
handler.register_path(dev, sockpath);
Expand All @@ -335,7 +341,8 @@ static void
record_script(string arg, string format)
{
string dev, devnum, outfile;
split_devfile_arg(arg, out dev, out devnum, out outfile);
bool is_block;
split_devfile_arg(arg, out dev, out devnum, out is_block, out outfile);
string c = record_script_counter.to_string();

Environment.set_variable("UMOCKDEV_SCRIPT_RECORD_FILE_" + c, outfile, true);
Expand Down

0 comments on commit 6ecc4d9

Please sign in to comment.