Bug 331744 - cannot open camera with OpenCV/v4l under valgrind
Summary: cannot open camera with OpenCV/v4l under valgrind
Status: RESOLVED DUPLICATE of bug 307103
Alias: None
Product: valgrind
Classification: Developer tools
Component: memcheck (show other bugs)
Version: 3.8.0
Platform: Mint (Ubuntu based) Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-04 20:04 UTC by João M. S. Silva
Modified: 2014-04-03 21:30 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
testcase (308 bytes, application/x-xz-compressed-tar)
2014-03-04 20:04 UTC, João M. S. Silva
Details
Valgrind's trace-syscalls log (140.67 KB, text/x-log)
2014-04-03 20:10 UTC, João M. S. Silva
Details
strace's log (88.43 KB, text/x-log)
2014-04-03 20:11 UTC, João M. S. Silva
Details

Note You need to log in before you can comment on or make changes to this bug.
Description João M. S. Silva 2014-03-04 20:04:23 UTC
Created attachment 85416 [details]
testcase

Under valgrind, opening a camera device with OpenCV (which uses v4l) does not work:

==1031== Warning: invalid file descriptor -100 in syscall openat()
==1031== Warning: invalid file descriptor -100 in syscall openat()

I'm adding a testcase which replicates the problem.
Comment 1 João M. S. Silva 2014-04-03 03:22:19 UTC
Any quick hints on this case?
Comment 2 Philippe Waroquiers 2014-04-03 19:40:09 UTC
(In reply to comment #1)
> Any quick hints on this case?
I guess special library and/or hardware to reproduce that, even with your small
reproducer.
maybe
   valgrind --trace-syscalls=yes your_test_case
(or when running the real application)
can help to see what is going wrong ?
You might compare the syscall done under valgrind with
the syscalls done when running natively (i.e. use strace your_test_case)
Comment 3 João M. S. Silva 2014-04-03 20:09:34 UTC
As to valgrind --trace-syscalls=yes, the relevant lines seem:

(...)
SYSCALL[10524,1](  2) sys_open ( 0x7fefffea0(/dev/video0), 0 ) --> [async] ... 
SYSCALL[10524,1](  2) ... [async] --> Success(0x0:0x7) 
SYSCALL[10524,1](  3) sys_close ( 7 )[sync] --> Success(0x0:0x0) 
(...)
SYSCALL[10524,1](257) sys_openat ( 4294967196, 0x7fefffea0(/dev/video0), 2050 )==10524== Warning: invalid file descriptor -100 in syscall openat()
 --> [pre-fail] Failure(0x9) 
SYSCALL[10524,1]( 16) sys_ioctl ( 4294967295, 0xffffffff80685600, 0x12d762d8 ) --> [async] ... 
SYSCALL[10524,1]( 16) ... [async] --> Failure(0x9) 
SYSCALL[10524,1](257) sys_openat ( 4294967196, 0x7fefffea0(/dev/video0), 2 )==10524== Warning: invalid file descriptor -100 in syscall openat()
 --> [pre-fail] Failure(0x9) 
SYSCALL[10524,1]( 16) sys_ioctl ( 4294967295, 0x803c7601, 0x12d7608c ) --> [async] ... 
SYSCALL[10524,1]( 16) ... [async] --> Failure(0x9) 

As for strace:

open("/dev/video0", O_RDONLY)           = 7
close(7)                                = 0
(...)
openat(AT_FDCWD, "/dev/video0", O_RDWR|O_NONBLOCK) = 7

I attach the logs.

It looks like open/close run OK under Valgrind, but openat doesn't. Does this help in identifying the problem or hinting at a workaround? Thanks.
Comment 4 João M. S. Silva 2014-04-03 20:10:40 UTC
Created attachment 85946 [details]
Valgrind's trace-syscalls log
Comment 5 João M. S. Silva 2014-04-03 20:11:24 UTC
Created attachment 85947 [details]
strace's log
Comment 6 Philippe Waroquiers 2014-04-03 20:23:43 UTC
(In reply to comment #3)
> It looks like open/close run OK under Valgrind, but openat doesn't. Does
> this help in identifying the problem or hinting at a workaround? Thanks.
Yes, it helps.

I believe this is bug 307103, which has been fixed in valgrind 3.9.0.
Please upgrade to 3.9.0 (or the SVN version), and see if that solves the problem.
Comment 7 João M. S. Silva 2014-04-03 21:01:03 UTC
Thanks, I compiled version 3.9.0, since it is not yet available from Mint and it solves the problem.

There are some errors in V4L functions, but I think this has to be reported to V4L which I did but there seems to be no easy follow up (they use a mailing list which is hard to follow).
Comment 8 Philippe Waroquiers 2014-04-03 21:30:43 UTC
Thanks for the feedback, closing as duplicate

*** This bug has been marked as a duplicate of bug 307103 ***