<div id="geary-body" dir="auto"><div>Hi Laurent</div></div><div id="geary-quote" dir="auto"><br>On Thu, Apr 30, 2020 at 00:27, Laurent Pinchart <laurent.pinchart@ideasonboard.com> wrote:<br><blockquote type="cite"><div class="plaintext" style="white-space: pre-wrap;">Hi Umang,

On Wed, Apr 29, 2020 at 02:50:42AM +0000, Umang Jain wrote:
<blockquote> Hi all,
 
 Thanks for your comments on the approach, Laurent. 
 I have pushed a branch here : <a href="https://u15657259.ct.sendgrid.net/ls/click?upn=8H1KCc2bev8KdIveckpOEF8NFg9rbIgRS-2FA55EvKtHykb8IS-2Bk-2FOjvY70Cmox2SkeZGYPYqHL-2F3Ad3KLfA5jWg-3D-3DYu8K_C3wFy2Q4UgRsRLDAYieRZ5Z3EhAWyy0-2FkOzyYc6FPc1dn6ROcAJqKXb9hjP566uP5oG9z5GCp2cwpQcv6TdhSw0vjpd-2BHvBY27mDK0wogP5yc2dKwTLJOlGhoJUEeDhBP3MxtPuc6G8TnxNW8QVpEOL7oW-2FcLgbjfU-2BlaGYvGkS1G09vaxJGtCEEp8ix-2FXW-2FBoFR3nM8FX9XwkaYplHrrLOFg3DIyLWTM0vhzKA2awMxoNKOvtSZX4DJQq2yv-2BanmHCA6V4ivEhIcg2bOADFwQ-3D-3D">https://github.com/uajain/libcamera/tree/uajain/</a>
 hotplug
</blockquote>
Nice work !</div></blockquote><span style="white-space: pre-wrap;"><div><span style="white-space: pre-wrap;"><br></span></div>Thanks. Means a lot coming from you.<br></span><blockquote type="cite"><div class="plaintext" style="white-space: pre-wrap;">
<blockquote> I have tested with UVC devices (primarily a external webcam) and I had
 satisfactory results.
 I am now exploring ways to write unit tests around this. I, ideally, needs to
 run CameraManager and have a mock UDev
 device-connected event fired so that CameraManager can run/test the code path
 above. I came across <a href="https://u15657259.ct.sendgrid.net/ls/click?upn=8H1KCc2bev8KdIveckpOENWIe8wLJf27r55W-2FCbo39NIgkUTQYfWmAgVXccH3QLarCoK_C3wFy2Q4UgRsRLDAYieRZ5Z3EhAWyy0-2FkOzyYc6FPc1dn6ROcAJqKXb9hjP566uP5oG9z5GCp2cwpQcv6TdhSylV8qB-2FB0oRol3F2hLixR-2FD7T-2Bwe-2FsFVcoW3i3el6LrfOoBDuxEV8NzkePAt7psMlg5BWvyOHLgzowNE2VkMZ-2B1J3lmJ42MiXwFUn2Pt795emfyyRtSrWSD4FeO-2B4n68Dk4eOTgBMD6f138c9XmfPW2S2OoAicbifznlq9w7b1rWXKDBQc6-2BZFCKyuaN8TIrQ-3D-3D">https://github.com/martinpitt/umockdev</a>
 which seems relevant for this. Not sure how far can I get with this.
</blockquote>
That's an interesting project, I wasn't aware of it. If I understand the
documentation correctly, it emulates devices in userspace, with options
to record ioctls issues on a real device and then replaying them. The
emulation uses the LD_PRELOAD technique to intercept libc calls, and is
implemented in [1].

It seems that support for mmap() and ppoll(), which are pretty
fundamental operation for V4L2 devices, is missing. It wouldn't be
straightforward to add them, so I'm not sure if using umockdev will be a
feasible approach.</div></blockquote><span style="white-space: pre-wrap;"><div><span style="white-space: pre-wrap;"><br></span></div>I see. Thanks for the audit for this. I actually had no idea about the internals but</span><div><span style="white-space: pre-wrap;">I mentioned it here, as that was the goal I was looking for, until....</span></div><div><span style="white-space: pre-wrap;"><br></span><blockquote type="cite"><div class="plaintext" style="white-space: pre-wrap;">
I'm wondering if we shouldn't start simpler. Devices can be unbound from
drivers programmatically through sysfs. For instance running

echo 1-5:1.0 > /sys/module/uvcvideo/drivers/usb\:uvcvideo/unbind</div></blockquote><span style="white-space: pre-wrap;"><div><span style="white-space: pre-wrap;"><br></span></div>I learnt about this. I actually got a automated test case now, around this.</span></div><div><span style="white-space: pre-wrap;">However I uncovered a bug in libcamera which created a problem while</span></div><div><span style="white-space: pre-wrap;">rebinding the device itself. I have put a small workaround for that for now and will</span></div><div><span style="white-space: pre-wrap;">explain in the patchset itself.</span></div><div><span style="white-space: pre-wrap;"><br></span><blockquote type="cite"><div class="plaintext" style="white-space: pre-wrap;">
unbinds my integrated webcam from the uvcvideo driver. This has the same
effect, from a userspace point of view, as unplugging the device. You
can also simulate hotplug by re-binding the device to the driver if you
write the same string to the 'bind' file.

Maybe the test could be based on this ? Writing to these files requires
root , so the test should be skipped if it doesn't have the right
permissions, but it would be a good step forward in my opinion. It would
however require a UVC device being plugged into the system, but we could
in a second step port it to vimc (and I wouldn't be surprised if it then
could crash the kernel, requiring fixes in vimc :-)).

[1] <a href="https://u15657259.ct.sendgrid.net/ls/click?upn=8H1KCc2bev8KdIveckpOENWIe8wLJf27r55W-2FCbo39NPgHn5U3BwXeiNNqvgoaQbohYe7mkL4Q8KETGwINprZZ4J3Ijx-2FAUinHJu5B7AiRC7yXTDTfFehSYm0rsxvnDsxSWu_C3wFy2Q4UgRsRLDAYieRZ5Z3EhAWyy0-2FkOzyYc6FPc1dn6ROcAJqKXb9hjP566uP5oG9z5GCp2cwpQcv6TdhS4Q1FI6jBPEbBbSrvO4kmM57Lrbb9sVZYF1XhdnOfaREp-2FHnQteAStSpShdzJm-2BFt-2FO4jNo1NdQ0FfMMy6jtMq8ceMX7MQovGd-2FwO48FSn8fckLCUSqvJoYLtfENyLDUh-2Ff24PuMPQAVnI2pTxORgYq9SQYBFsKwJZhpgCo-2F1VknP-2F9-2FWblHe1j6qOlMtsSEXA-3D-3D">https://github.com/martinpitt/umockdev/blob/master/src/libumockdev-preload.c</a>

<div>-- 
</div>Regards,

Laurent Pinchart
</div></blockquote></div></div><img src="https://u15657259.ct.sendgrid.net/wf/open?upn=GCEip0g28ftA9O9fsCR2M7x08El53O4YVYtHuSI-2FrLwtytoSlmO-2FnSq-2B0q807R-2FEJlqKMdpF36DgsHbLG6Gr2eGL08kbpjCEksMP8w0MhhfJlHQvB3eyWmvdwWN4ANWMZoh4QuPwMkbgau99FhmWiA65voscRefO6oQtUGN7HOJtvFDXwVtBSMiA1TO2nJbfulxxO0-2FJR60ZPzIU4nhvtd-2Fz7BCceQ-2Br4K49xfFFbJ88ZZD4SdEqzdRx9KcEV8S6IvcadE6Q7xzsKvLkspHDZw-3D-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;"/>