martinpitt / umockdev

Mock hardware devices for creating unit tests and bug reporting
https://launchpad.net/umockdev
GNU Lesser General Public License v2.1
312 stars 57 forks source link

mock an USB block device and enable mount #227

Closed cmigliorini closed 8 months ago

cmigliorini commented 8 months ago

I would like to mock an USB block device with a partition and let the (C) test program mount the partition. I can definitely limit my tests to a read-only mount, but of course I would love to be able to have ability to read-write. Partition can be as small as a few kBytes, and I have already captured a script from a real-life USB key that I'm confident I can "shrink" to my needs.

I'm wondering what needs to be done to enable this. I found hints in the documentation that a/dev device could be (is?) backed by a file, and I can easily generate a file with an USB storage device content -- but found no example of this --. I also found in the test code usage of a N: line via umockdev_testbed_add_from_string().

Would the latter be the preferred way? Would this work?

There is an optional extra requirement: being able to pmount the partition (program being tested currently uses system(pmount). Would that make a difference?

Bonus question: can this run in a Docker container?

martinpitt commented 8 months ago

Sorry, this is way outside of what umockdev (or generically, an userspace mock implementation) can do. Mounting is a kernel API which doesn't work in terms of sysfs or ioctls. For that you should probably use scsi_debug or a RAM/loop/devmapper disk.

Unfortunately none of that works in an (unprivileged) container, for storage tests you need a VM.